Also, handle names and prefixes that fill the entire field (and have no
NUL byte) by using a precision specifier.
---
 tar.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tar.c b/tar.c
index 47d2334..7588a41 100644
--- a/tar.c
+++ b/tar.c
@@ -29,6 +29,7 @@ struct Header {
        char gname[32];
        char major[8];
        char minor[8];
+       char prefix[155];
 };
 
 enum {
@@ -317,11 +318,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);
        }
 }
-- 
2.1.3.1.g339ec9c


Reply via email to