more tar changes

This commit is contained in:
rsc 2005-07-22 18:46:26 +00:00
parent 8824e122a3
commit 14f06f6792

View file

@ -16,7 +16,9 @@
* keyletters and options. * keyletters and options.
*/ */
#define TARGBEGIN {\ #define TARGBEGIN {\
(argv0 || (argv0 = *argv)), argv++, argc--;\ if (argv0 == nil)\
argv0 = *argv;\
argv++, argc--;\
if (argv[0]) {\ if (argv[0]) {\
char *_args, *_argt;\ char *_args, *_argt;\
Rune _argc;\ Rune _argc;\
@ -69,28 +71,25 @@ enum {
#define isreallink(lf) ((lf) == LF_LINK) #define isreallink(lf) ((lf) == LF_LINK)
#define issymlink(lf) ((lf) == LF_SYMLINK1 || (lf) == LF_SYMLINK2) #define issymlink(lf) ((lf) == LF_SYMLINK1 || (lf) == LF_SYMLINK2)
typedef union { typedef struct {
uchar data[Tblock]; char name[Namsiz];
struct { char mode[8];
char name[Namsiz]; char uid[8];
char mode[8]; char gid[8];
char uid[8]; char size[12];
char gid[8]; char mtime[12];
char size[12]; char chksum[8];
char mtime[12]; char linkflag;
char chksum[8]; char linkname[Namsiz];
char linkflag;
char linkname[Namsiz];
/* rest are defined by POSIX's ustar format; see p1003.2b */ /* rest are defined by POSIX's ustar format; see p1003.2b */
char magic[6]; /* "ustar" */ char magic[6]; /* "ustar" */
char version[2]; char version[2];
char uname[32]; char uname[32];
char gname[32]; char gname[32];
char devmajor[8]; char devmajor[8];
char devminor[8]; char devminor[8];
char prefix[Maxpfx]; /* if non-null, path= prefix "/" name */ char prefix[Maxpfx]; /* if non-null, path= prefix "/" name */
};
} Hdr; } Hdr;
typedef struct { typedef struct {
@ -318,7 +317,7 @@ getblkz(int ar)
Hdr *hp = getblke(ar); Hdr *hp = getblke(ar);
if (hp != nil) if (hp != nil)
memset(hp->data, 0, Tblock); memset(hp, 0, Tblock);
return hp; return hp;
} }
@ -391,7 +390,7 @@ chksum(Hdr *hp)
{ {
int n = Tblock; int n = Tblock;
long i = 0; long i = 0;
uchar *cp = hp->data; uchar *cp = (uchar*)hp;
char oldsum[sizeof hp->chksum]; char oldsum[sizeof hp->chksum];
memmove(oldsum, hp->chksum, sizeof oldsum); memmove(oldsum, hp->chksum, sizeof oldsum);
@ -664,7 +663,7 @@ addtoar(int ar, char *file, char *shortf)
hbp = getblke(ar); hbp = getblke(ar);
blksread = gothowmany(blksleft); blksread = gothowmany(blksleft);
bytes = blksread * Tblock; bytes = blksread * Tblock;
n = readn(fd, hbp->data, bytes); n = readn(fd, hbp, bytes);
if (n < 0) if (n < 0)
sysfatal("error reading %s: %r", file); sysfatal("error reading %s: %r", file);
/* /*
@ -672,7 +671,7 @@ addtoar(int ar, char *file, char *shortf)
* compression and emergency recovery of data. * compression and emergency recovery of data.
*/ */
if (n < Tblock) if (n < Tblock)
memset(hbp->data + n, 0, bytes - n); memset((uchar*)hbp + n, 0, bytes - n);
putblkmany(ar, blksread); putblkmany(ar, blksread);
} }
close(fd); close(fd);
@ -883,7 +882,7 @@ extract1(int ar, Hdr *hp, char *fname)
wrbytes = Tblock*blksread; wrbytes = Tblock*blksread;
if(wrbytes > bytes) if(wrbytes > bytes)
wrbytes = bytes; wrbytes = bytes;
if (fd >= 0 && write(fd, hbp->data, wrbytes) != wrbytes) if (fd >= 0 && write(fd, hbp, wrbytes) != wrbytes)
sysfatal("write error on %s: %r", fname); sysfatal("write error on %s: %r", fname);
putreadblks(ar, blksread); putreadblks(ar, blksread);
bytes -= wrbytes; bytes -= wrbytes;