[dev] [sbase] [PATCH 4/4] tar: Handle archives with the prefix field

From: Michael Forney <mforney_AT_mforney.org>
Date: Sat, 1 Nov 2014 20:36:40 +0000

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
_AT_@ -29,6 +29,7 @@ struct Header {
 	char gname[32];
 	char major[8];
 	char minor[8];
+	char prefix[155];
 };
 
 enum {
_AT_@ -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
Received on Sat Nov 01 2014 - 21:36:40 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 01 2014 - 21:48:24 CET