mkports

recipes for building multiple softwares with mk(1)
git clone git://z3bra.org/mkports
Log | Files | Refs

commit 86376d5ae0a235ecbab20fa55533993672c9c7b9
parent b77b5713dfea1112e46171c4187e1cd6138c1281
Author: z3bra <contactatz3bradotorg>
Date:   Wed Feb 15 22:33:37 +0000

sbase: reformat tar patch

Diffstat:
sbase/patches/sbase-tarformaterrors-20170203-3bc2ffc.diff | 72------------------------------------------------------------------------
sbase/patches/sbase-tarreadall-20170203-3bc2ffc.diff | 30------------------------------
sbase/patches/tar-various-fixes.diff | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 99 insertions(+), 102 deletions(-)
diff --git a/sbase/patches/sbase-tarformaterrors-20170203-3bc2ffc.diff b/sbase/patches/sbase-tarformaterrors-20170203-3bc2ffc.diff @@ -1,72 +0,0 @@ -diff --git a/tar.c b/tar.c -index 71719b0..4a81f8f 100644 ---- a/tar.c -+++ b/tar.c -@@ -29,6 +29,12 @@ enum Type { - RESERVED = '7' - }; - -+enum Error { -+ BADCHKSUM, -+ BADMAGIC, -+ BADPATH -+}; -+ - struct header { - char name[100]; - char mode[8]; -@@ -71,6 +77,12 @@ static const char *filtertools[] = { - ['z'] = "gzip", - }; - -+static const char *errors[] = { -+ [BADCHKSUM] = "bad checksum", -+ [BADMAGIC] = "bad magic", -+ [BADPATH] = "empty filename" -+}; -+ - static void - pushdirtime(char *name, time_t mtime) - { -@@ -407,27 +419,36 @@ chktar(struct header *h) - char tmp[8], *err; - char *p = (char *)h; - long s1, s2, i; -+ int errnum; - -- if (h->prefix[0] == '\0' && h->name[0] == '\0') -+ if (h->prefix[0] == '\0' && h->name[0] == '\0') { -+ errnum = BADPATH; - goto bad; -- if (h->magic[0] && strncmp("ustar", h->magic, 5)) -+ } -+ if (h->magic[0] && strncmp("ustar", h->magic, 5)) { -+ errnum = BADMAGIC; - goto bad; -+ } - memcpy(tmp, h->chksum, sizeof(tmp)); - for (i = 0; i < sizeof(tmp); i++) - if (tmp[i] == ' ') - tmp[i] = '\0'; - s1 = strtol(tmp, &err, 8); -- if (s1 < 0 || *err != '\0') -+ if (s1 < 0 || *err != '\0') { -+ errnum = BADCHKSUM; - goto bad; -+ } - memset(h->chksum, ' ', sizeof(h->chksum)); - for (i = 0, s2 = 0; i < sizeof(*h); i++) - s2 += (unsigned char)p[i]; -- if (s1 != s2) -+ if (s1 != s2) { -+ errnum = BADCHKSUM; - goto bad; -+ } - memcpy(h->chksum, tmp, sizeof(h->chksum)); - return; - bad: -- eprintf("malformed tar archive\n"); -+ eprintf("malformed tar archive: %s\n", errors[errnum]); - } - - static void diff --git a/sbase/patches/sbase-tarreadall-20170203-3bc2ffc.diff b/sbase/patches/sbase-tarreadall-20170203-3bc2ffc.diff @@ -1,30 +0,0 @@ -diff --git a/tar.c b/tar.c -index 4a81f8f..ca2c2af 100644 ---- a/tar.c -+++ b/tar.c -@@ -155,16 +155,21 @@ decomp(int fd, const char *tool, const char *flags) - static ssize_t - eread(int fd, void *buf, size_t n) - { -- ssize_t r; -+ char *tmp = buf; -+ ssize_t r, s = 0; - - again: -- r = read(fd, buf, n); -+ r = read(fd, tmp + s, n - s); -+ s += r; - if (r < 0) { -- if (errno == EINTR) -+ if (errno == EINTR || errno == EAGAIN) - goto again; - eprintf("read:"); - } -- return r; -+ if (r && s < n) -+ goto again; -+ -+ return s; - } - - static ssize_t diff --git a/sbase/patches/tar-various-fixes.diff b/sbase/patches/tar-various-fixes.diff @@ -0,0 +1,99 @@ +diff --git a/tar.c b/tar.c +index 71719b0..5954047 100644 +--- a/tar.c ++++ b/tar.c +@@ -29,6 +30,12 @@ enum Type { + RESERVED = '7' + }; + ++enum Error { ++ BADCHKSUM, ++ BADMAGIC, ++ BADPATH ++}; ++ + struct header { + char name[100]; + char mode[8]; +@@ -71,6 +78,12 @@ static const char *filtertools[] = { + ['z'] = "gzip", + }; + ++static const char *errors[] = { ++ [BADCHKSUM] = "bad checksum", ++ [BADMAGIC] = "bad magic", ++ [BADPATH] = "empty filename" ++}; ++ + static void + pushdirtime(char *name, time_t mtime) + { +@@ -143,16 +156,22 @@ decomp(int fd, const char *tool, const char *flags) + static ssize_t + eread(int fd, void *buf, size_t n) + { +- ssize_t r; ++ char *tmp = buf; ++ ssize_t r, s = 0; + + again: +- r = read(fd, buf, n); ++ r = read(fd, tmp + s, n - s); + if (r < 0) { +- if (errno == EINTR) ++ if (errno == EINTR || errno == EAGAIN) + goto again; + eprintf("read:"); + } +- return r; ++ ++ s += r; ++ if (r && s < n) ++ goto again; ++ ++ return s; + } + + static ssize_t +@@ -407,27 +427,36 @@ chktar(struct header *h) + char tmp[8], *err; + char *p = (char *)h; + long s1, s2, i; ++ int errnum; + +- if (h->prefix[0] == '\0' && h->name[0] == '\0') ++ if (h->prefix[0] == '\0' && h->name[0] == '\0') { ++ errnum = BADPATH; + goto bad; +- if (h->magic[0] && strncmp("ustar", h->magic, 5)) ++ } ++ if (h->magic[0] && strncmp("ustar", h->magic, 5)) { ++ errnum = BADMAGIC; + goto bad; ++ } + memcpy(tmp, h->chksum, sizeof(tmp)); + for (i = 0; i < sizeof(tmp); i++) + if (tmp[i] == ' ') + tmp[i] = '\0'; + s1 = strtol(tmp, &err, 8); +- if (s1 < 0 || *err != '\0') ++ if (s1 < 0 || *err != '\0') { ++ errnum = BADCHKSUM; + goto bad; ++ } + memset(h->chksum, ' ', sizeof(h->chksum)); + for (i = 0, s2 = 0; i < sizeof(*h); i++) + s2 += (unsigned char)p[i]; +- if (s1 != s2) ++ if (s1 != s2) { ++ errnum = BADCHKSUM; + goto bad; ++ } + memcpy(h->chksum, tmp, sizeof(h->chksum)); + return; + bad: +- eprintf("malformed tar archive\n"); ++ eprintf("malformed tar archive: %s\n", errors[errnum]); + } + + static void