=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/file/Attic/compress.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- src/usr.bin/file/Attic/compress.c 2008/05/08 01:40:56 1.12 +++ src/usr.bin/file/Attic/compress.c 2009/04/24 18:54:34 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: compress.c,v 1.12 2008/05/08 01:40:56 chl Exp $ */ +/* $OpenBSD: compress.c,v 1.13 2009/04/24 18:54:34 chl Exp $ */ /* * Copyright (c) Ian F. Darwin 1986-1995. * Software written by Ian F. Darwin and others; @@ -50,19 +50,20 @@ #if defined(HAVE_SYS_TIME_H) #include #endif -#ifdef HAVE_LIBZ +#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ) +#define BUILTIN_DECOMPRESS #include #endif #ifndef lint -FILE_RCSID("@(#)$Id: compress.c,v 1.12 2008/05/08 01:40:56 chl Exp $") +FILE_RCSID("@(#)$Id: compress.c,v 1.13 2009/04/24 18:54:34 chl Exp $") #endif -private struct { - const char *magic; +private const struct { + const char magic[8]; size_t maglen; - const char *const argv[3]; + const char *argv[3]; int silent; } compr[] = { { "\037\235", 2, { "gzip", "-cdq", NULL }, 1 }, /* compressed */ @@ -87,7 +88,7 @@ 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 @@ -99,6 +100,7 @@ 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; @@ -113,12 +115,19 @@ rv = -1; if (file_buffer(ms, -1, name, newbuf, nsz) == -1) goto error; - if (file_printf(ms, " (") == -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_buffer(ms, -1, NULL, buf, nbytes) == -1) + + if (!mime && file_printf(ms, ")") == -1) goto error; - if (file_printf(ms, ")") == -1) - goto error; rv = 1; break; } @@ -286,7 +295,7 @@ return fd; } -#ifdef HAVE_LIBZ +#ifdef BUILTIN_DECOMPRESS #define FHCRC (1 << 1) #define FEXTRA (1 << 2) @@ -365,7 +374,8 @@ int fdin[2], fdout[2]; int r; -#ifdef HAVE_LIBZ +#ifdef BUILTIN_DECOMPRESS + /* FIXME: This doesn't cope with bzip2 */ if (method == 2) return uncompressgzipped(ms, old, newch, n); #endif