[hackers] [sbase] tar: Handle archives with the prefix field || Michael Forney
commit e1f87da43e4805ac6758fa11cc49fbebaa5c3c89
Author: Michael Forney <mforney_AT_mforney.org>
Date: Sat Nov 1 20:36:40 2014 +0000
tar: Handle archives with the prefix field
Also, handle names and prefixes that fill the entire field (and have no
NUL byte) by using a precision specifier.
diff --git a/tar.c b/tar.c
index 7bd709d..0a41795 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -27,6 +27,7 @@ struct Header {
char gname[32];
char major[8];
char minor[8];
+ char prefix[155];
};
enum {
_AT_@ -298,11 +299,14 @@ c(const char * path)
static void
xt(int (*fn)(char*, int, char[Blksiz]))
{
- char b[Blksiz], fname[101];
+ char b[Blksiz], fname[257], *s;
Header *h = (void*)b;
while(fread(b, Blksiz, 1, tarfile) && h->name[0] != '\0') {
- snprintf(fname, sizeof fname, "%s", h->name);
+ s = fname;
+ if (h->prefix[0] != '\0')
+ s += sprintf(s, "%.*s/", (int)sizeof h->prefix, h->prefix);
+ sprintf(s, "%.*s", (int)sizeof h->name, h->name);
fn(fname, strtol(h->size, 0, 8), b);
}
}
Received on Sat Nov 01 2014 - 23:34:23 CET
This archive was generated by hypermail 2.3.0
: Sat Nov 01 2014 - 23:36:26 CET