Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / archive / tar / common.go
blob5b781ff3d7d944243bd20bbfed1bf06d7d745184
1 // Copyright 2009 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.
5 // The tar package implements access to tar archives.
6 // It aims to cover most of the variations, including those produced
7 // by GNU and BSD tars.
8 //
9 // References:
10 // http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5
11 // http://www.gnu.org/software/tar/manual/html_node/Standard.html
12 package tar
14 const (
15 blockSize = 512
17 // Types
18 TypeReg = '0'
19 TypeRegA = '\x00'
20 TypeLink = '1'
21 TypeSymlink = '2'
22 TypeChar = '3'
23 TypeBlock = '4'
24 TypeDir = '5'
25 TypeFifo = '6'
26 TypeCont = '7'
27 TypeXHeader = 'x'
28 TypeXGlobalHeader = 'g'
31 // A Header represents a single header in a tar archive.
32 // Some fields may not be populated.
33 type Header struct {
34 Name string
35 Mode int64
36 Uid int
37 Gid int
38 Size int64
39 Mtime int64
40 Typeflag byte
41 Linkname string
42 Uname string
43 Gname string
44 Devmajor int64
45 Devminor int64
46 Atime int64
47 Ctime int64
50 var zeroBlock = make([]byte, blockSize)
52 // POSIX specifies a sum of the unsigned byte values, but the Sun tar uses signed byte values.
53 // We compute and return both.
54 func checksum(header []byte) (unsigned int64, signed int64) {
55 for i := 0; i < len(header); i++ {
56 if i == 148 {
57 // The chksum field (header[148:156]) is special: it should be treated as space bytes.
58 unsigned += ' ' * 8
59 signed += ' ' * 8
60 i += 7
61 continue
63 unsigned += int64(header[i])
64 signed += int64(int8(header[i]))
66 return
69 type slicer []byte
71 func (sp *slicer) next(n int) (b []byte) {
72 s := *sp
73 b, *sp = s[0:n], s[n:]
74 return