src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

support.go (697B)


      1 // Copyright 2024 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package gcimporter
      6 
      7 import (
      8 	"bufio"
      9 	"io"
     10 	"strconv"
     11 	"strings"
     12 )
     13 
     14 // Copy of $GOROOT/src/cmd/internal/archive.ReadHeader.
     15 func readArchiveHeader(b *bufio.Reader, name string) int {
     16 	// architecture-independent object file output
     17 	const HeaderSize = 60
     18 
     19 	var buf [HeaderSize]byte
     20 	if _, err := io.ReadFull(b, buf[:]); err != nil {
     21 		return -1
     22 	}
     23 	aname := strings.Trim(string(buf[0:16]), " ")
     24 	if !strings.HasPrefix(aname, name) {
     25 		return -1
     26 	}
     27 	asize := strings.Trim(string(buf[48:58]), " ")
     28 	i, _ := strconv.Atoi(asize)
     29 	return i
     30 }