From: Christos Zoulas Date: Fri, 20 Oct 2006 21:03:40 +0000 (+0000) Subject: allow child to return 0 bytes. X-Git-Tag: FILE5_05~722 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ec6b54f3bd3371ec5d7c3c01350c6e9a227d00c;p=file allow child to return 0 bytes. --- diff --git a/src/compress.c b/src/compress.c index 1f82d423..0ad3e7cd 100644 --- a/src/compress.c +++ b/src/compress.c @@ -51,10 +51,9 @@ #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]);