mirror of
https://github.com/golang/go
synced 2024-11-21 18:04:40 -07:00
gc: use HEADER_IO macro from gopack
Use HEADER_IO macro from gopack to read archive header The HEADER_IO macro portably reads archive headers. The current arsize code fails in the case of archive headers produced on plan 9 6c and read on other systems (it's not portable). Modify lex.c to use the portable macro Build tested (including tests) on OSX. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5323072
This commit is contained in:
parent
2e1bb76f9b
commit
986ad31b2d
@ -380,18 +380,30 @@ saveerrors(void)
|
||||
nerrors = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* macro to portably read/write archive header.
|
||||
* 'cmd' is read/write/Bread/Bwrite, etc.
|
||||
*/
|
||||
#define HEADER_IO(cmd, f, h) cmd(f, h.name, sizeof(h.name)) != sizeof(h.name)\
|
||||
|| cmd(f, h.date, sizeof(h.date)) != sizeof(h.date)\
|
||||
|| cmd(f, h.uid, sizeof(h.uid)) != sizeof(h.uid)\
|
||||
|| cmd(f, h.gid, sizeof(h.gid)) != sizeof(h.gid)\
|
||||
|| cmd(f, h.mode, sizeof(h.mode)) != sizeof(h.mode)\
|
||||
|| cmd(f, h.size, sizeof(h.size)) != sizeof(h.size)\
|
||||
|| cmd(f, h.fmag, sizeof(h.fmag)) != sizeof(h.fmag)
|
||||
|
||||
static int
|
||||
arsize(Biobuf *b, char *name)
|
||||
{
|
||||
struct ar_hdr *a;
|
||||
struct ar_hdr a;
|
||||
|
||||
if((a = Brdline(b, '\n')) == nil)
|
||||
if (HEADER_IO(Bread, b, a))
|
||||
return -1;
|
||||
if(Blinelen(b) != sizeof(struct ar_hdr))
|
||||
|
||||
if(strncmp(a.name, name, strlen(name)) != 0)
|
||||
return -1;
|
||||
if(strncmp(a->name, name, strlen(name)) != 0)
|
||||
return -1;
|
||||
return atoi(a->size);
|
||||
|
||||
return atoi(a.size);
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
Reference in New Issue
Block a user