tar: Add skipblk() and simplify code

This commit is contained in:
sin 2015-04-23 12:06:44 +01:00
parent 201e71be2b
commit aab2e273bd

20
tar.c
View File

@ -257,15 +257,21 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
return 0; return 0;
} }
static int static void
print(char *fname, ssize_t l, char b[BLKSIZ]) skipblk(ssize_t l)
{ {
puts(fname); char b[BLKSIZ];
for (; l > 0; l -= BLKSIZ) for (; l > 0; l -= BLKSIZ)
if (fread(b, BLKSIZ, 1, tarfile) != 1) if (fread(b, BLKSIZ, 1, tarfile) != 1)
eprintf("fread %s:", tarfilename); eprintf("fread %s:", tarfilename);
}
static int
print(char *fname, ssize_t l, char b[BLKSIZ])
{
puts(fname);
skipblk(l);
return 0; return 0;
} }
@ -332,18 +338,14 @@ xt(int argc, char *argv[], int (*fn)(char *, ssize_t, char[BLKSIZ]))
if (!strcmp(argv[i], fname)) if (!strcmp(argv[i], fname))
break; break;
if (i == argc) { if (i == argc) {
for (; size > 0; size -= BLKSIZ) skipblk(size);
if (fread(b, BLKSIZ, 1, tarfile) != 1)
eprintf("fread %s:", tarfilename);
continue; continue;
} }
} }
/* ignore global pax header craziness */ /* ignore global pax header craziness */
if (h->type == 'g') { if (h->type == 'g') {
for (; size > 0; size -= BLKSIZ) skipblk(size);
if (fread(b, BLKSIZ, 1, tarfile) != 1)
eprintf("fread %s:", tarfilename);
continue; continue;
} }