From 7b04471dfaaddc49efad470275fcc45546870a73 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 1 Nov 2011 00:29:16 -0400 Subject: [PATCH] gopack: change archive file name length back to 16 This CL grew the archive file name length from 16 to 64: changeset: 909:58574851d792 user: Russ Cox date: Mon Oct 20 13:53:56 2008 -0700 Back then, every x.go file in a package became an x.6 file in the archive. It was important to be able to allow the use of long Go source file names, hence the increase in size. Today, all Go source files compile into a single _go_.6 file regardless of their names, so the archive file name length no longer needs to be long. The longer name causes some problems on Plan 9, where the native archive format is the same but with 16-byte names, so revert back to 16. R=golang-dev, r CC=golang-dev https://golang.org/cl/5333050 --- include/ar.h | 2 +- src/cmd/ld/lib.c | 10 ++-------- src/pkg/exp/types/exportdata.go | 6 +++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/include/ar.h b/include/ar.h index b565ac90bf2..d5636b3623c 100644 --- a/include/ar.h +++ b/include/ar.h @@ -32,7 +32,7 @@ #define SARMAG 8 #define ARFMAG "`\n" -#define SARNAME 64 +#define SARNAME 16 struct ar_hdr { diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 8f95665b335..33fa0d15462 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -313,15 +313,9 @@ nextar(Biobuf *bp, int off, struct ar_hdr *a) return 0; return -1; } - if(r == SAR_HDR) { - memmove(a, buf, SAR_HDR); - } else if (r == SAR_HDR-SARNAME+16) { // old Plan 9 - memset(a->name, ' ', sizeof a->name); - memmove(a, buf, 16); - memmove((char*)a+SARNAME, buf+16, SAR_HDR-SARNAME); - } else { // unexpected + if(r != SAR_HDR) return -1; - } + memmove(a, buf, SAR_HDR); if(strncmp(a->fmag, ARFMAG, sizeof a->fmag)) return -1; arsize = strtol(a->size, 0, 0); diff --git a/src/pkg/exp/types/exportdata.go b/src/pkg/exp/types/exportdata.go index 383520320f4..784ffff01a3 100644 --- a/src/pkg/exp/types/exportdata.go +++ b/src/pkg/exp/types/exportdata.go @@ -17,7 +17,7 @@ import ( func readGopackHeader(buf *bufio.Reader) (name string, size int, err os.Error) { // See $GOROOT/include/ar.h. - hdr := make([]byte, 64+12+6+6+8+10+2) + hdr := make([]byte, 16+12+6+6+8+10+2) _, err = io.ReadFull(buf, hdr) if err != nil { return @@ -25,13 +25,13 @@ func readGopackHeader(buf *bufio.Reader) (name string, size int, err os.Error) { if trace { fmt.Printf("header: %s", hdr) } - s := strings.TrimSpace(string(hdr[64+12+6+6+8:][:10])) + s := strings.TrimSpace(string(hdr[16+12+6+6+8:][:10])) size, err = strconv.Atoi(s) if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' { err = os.NewError("invalid archive header") return } - name = strings.TrimSpace(string(hdr[:64])) + name = strings.TrimSpace(string(hdr[:16])) return }