]> granicus.if.org Git - file/commitdiff
allow child to return 0 bytes.
authorChristos Zoulas <christos@zoulas.com>
Fri, 20 Oct 2006 21:03:40 +0000 (21:03 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 20 Oct 2006 21:03:40 +0000 (21:03 +0000)
src/compress.c

index 1f82d423e6597ffd3ad2ed469683098ada3bb61b..0ad3e7cdc81a2160a467e1d59dbe969997108278 100644 (file)
 #endif
 
 #ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.43 2006/06/08 20:52:08 christos Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.44 2006/10/20 21:03:40 christos Exp $")
 #endif
 
-
 private struct {
        const char *magic;
        size_t maglen;
@@ -77,6 +76,8 @@ private struct {
 
 private int ncompr = sizeof(compr) / sizeof(compr[0]);
 
+#define NODATA ((size_t)~0)
+
 
 private ssize_t swrite(int, const void *, size_t);
 private size_t uncompressbuf(struct magic_set *, int, size_t,
@@ -102,7 +103,7 @@ file_zmagic(struct magic_set *ms, int fd, const unsigned char *buf,
                        continue;
                if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
                    (nsz = uncompressbuf(ms, fd, i, buf, &newbuf,
-                   nbytes)) != 0) {
+                   nbytes)) != NODATA) {
                        ms->flags &= ~MAGIC_COMPRESS;
                        rv = -1;
                        if (file_buffer(ms, -1, newbuf, nsz) == -1)
@@ -344,7 +345,7 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old,
        inflateEnd(&z);
        
        /* let's keep the nul-terminate tradition */
-       (*newch)[n++] = '\0';
+       (*newch)[n] = '\0';
 
        return n;
 }
@@ -366,7 +367,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
 
        if ((fd != -1 && pipe(fdin) == -1) || pipe(fdout) == -1) {
                file_error(ms, errno, "cannot create pipe");    
-               return 0;
+               return NODATA;
        }
        switch (fork()) {
        case 0: /* child */
@@ -399,7 +400,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
                /*NOTREACHED*/
        case -1:
                file_error(ms, errno, "could not fork");
-               return 0;
+               return NODATA;
 
        default: /* parent */
                (void) close(fdout[1]);
@@ -459,7 +460,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
                        n = r;
                }
                /* NUL terminate, as every buffer is handled here. */
-               (*newch)[n++] = '\0';
+               (*newch)[n] = '\0';
 err:
                if (fdin[1] != -1)
                        (void) close(fdin[1]);