diff options
Diffstat (limited to 'contrib/file/compress.c')
-rw-r--r-- | contrib/file/compress.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/contrib/file/compress.c b/contrib/file/compress.c index 2ccbef6..487b1b7 100644 --- a/contrib/file/compress.c +++ b/contrib/file/compress.c @@ -49,13 +49,14 @@ #if defined(HAVE_SYS_TIME_H) #include <sys/time.h> #endif -#ifdef HAVE_LIBZ +#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ) +#define BUILTIN_DECOMPRESS #include <zlib.h> #endif #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.51 2007/03/05 02:41:29 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.54 2007/12/02 00:28:10 christos Exp $") #endif private struct { @@ -86,7 +87,7 @@ private size_t ncompr = sizeof(compr) / sizeof(compr[0]); private ssize_t swrite(int, const void *, size_t); private size_t uncompressbuf(struct magic_set *, int, size_t, const unsigned char *, unsigned char **, size_t); -#ifdef HAVE_LIBZ +#ifdef BUILTIN_DECOMPRESS private size_t uncompressgzipped(struct magic_set *, const unsigned char *, unsigned char **, size_t); #endif @@ -98,6 +99,7 @@ file_zmagic(struct magic_set *ms, int fd, const char *name, unsigned char *newbuf = NULL; size_t i, nsz; int rv = 0; + int mime = ms->flags & MAGIC_MIME; if ((ms->flags & MAGIC_COMPRESS) == 0) return 0; @@ -112,11 +114,18 @@ file_zmagic(struct magic_set *ms, int fd, const char *name, rv = -1; if (file_buffer(ms, -1, name, newbuf, nsz) == -1) goto error; - if (file_printf(ms, " (") == -1) - goto error; - if (file_buffer(ms, -1, NULL, buf, nbytes) == -1) + + if (mime == MAGIC_MIME || mime == 0) { + if (file_printf(ms, mime ? + " compressed-encoding=" : " (") == -1) + goto error; + } + + if ((mime == 0 || mime & MAGIC_MIME_ENCODING) && + file_buffer(ms, -1, NULL, buf, nbytes) == -1) goto error; - if (file_printf(ms, ")") == -1) + + if (!mime && file_printf(ms, ")") == -1) goto error; rv = 1; break; @@ -285,7 +294,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf, return fd; } -#ifdef HAVE_LIBZ +#ifdef BUILTIN_DECOMPRESS #define FHCRC (1 << 1) #define FEXTRA (1 << 2) @@ -364,7 +373,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method, int fdin[2], fdout[2]; int r; -#ifdef HAVE_LIBZ +#ifdef BUILTIN_DECOMPRESS if (method == 2) return uncompressgzipped(ms, old, newch, n); #endif |