support.mx raw
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 // This file contains support functions for exportdata.
6
7 package exportdata
8
9 import (
10 "bufio"
11 "io"
12 "strconv"
13 "bytes"
14 )
15
16 // Copy of cmd/internal/archive.ReadHeader.
17 func readArchiveHeader(b *bufio.Reader, name []byte) int {
18 // architecture-independent object file output
19 const HeaderSize = 60
20
21 var buf [HeaderSize]byte
22 if _, err := io.ReadFull(b, buf[:]); err != nil {
23 return -1
24 }
25 aname := bytes.Trim([]byte(buf[0:16]), " ")
26 if !bytes.HasPrefix(aname, name) {
27 return -1
28 }
29 asize := bytes.Trim([]byte(buf[48:58]), " ")
30 i, _ := strconv.Atoi(asize)
31 return i
32 }
33