[hackers] [sbase] tar: Add skipblk() and simplify code || sin

From: <git_AT_suckless.org>
Date: Thu, 23 Apr 2015 13:37:44 +0200 (CEST)

commit aab2e273bda0208f7f3cea28087566522b691ee5
Author: sin <sin_AT_2f30.org>
Date: Thu Apr 23 12:06:44 2015 +0100

    tar: Add skipblk() and simplify code

diff --git a/tar.c b/tar.c
index d2e6495..c08ea47 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -257,15 +257,21 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
         return 0;
 }
 
-static int
-print(char *fname, ssize_t l, char b[BLKSIZ])
+static void
+skipblk(ssize_t l)
 {
- puts(fname);
+ char b[BLKSIZ];
 
         for (; l > 0; l -= BLKSIZ)
                 if (fread(b, BLKSIZ, 1, tarfile) != 1)
                         eprintf("fread %s:", tarfilename);
+}
 
+static int
+print(char *fname, ssize_t l, char b[BLKSIZ])
+{
+ puts(fname);
+ skipblk(l);
         return 0;
 }
 
_AT_@ -332,18 +338,14 @@ xt(int argc, char *argv[], int (*fn)(char *, ssize_t, char[BLKSIZ]))
                                 if (!strcmp(argv[i], fname))
                                         break;
                         if (i == argc) {
- for (; size > 0; size -= BLKSIZ)
- if (fread(b, BLKSIZ, 1, tarfile) != 1)
- eprintf("fread %s:", tarfilename);
+ skipblk(size);
                                 continue;
                         }
                 }
 
                 /* ignore global pax header craziness */
                 if (h->type == 'g') {
- for (; size > 0; size -= BLKSIZ)
- if (fread(b, BLKSIZ, 1, tarfile) != 1)
- eprintf("fread %s:", tarfilename);
+ skipblk(size);
                         continue;
                 }
 
Received on Thu Apr 23 2015 - 13:37:44 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 23 2015 - 13:48:13 CEST