version 1.12, 2008/05/08 01:40:56 |
version 1.13, 2009/04/24 18:54:34 |
|
|
#if defined(HAVE_SYS_TIME_H) |
#if defined(HAVE_SYS_TIME_H) |
#include <sys/time.h> |
#include <sys/time.h> |
#endif |
#endif |
#ifdef HAVE_LIBZ |
#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ) |
|
#define BUILTIN_DECOMPRESS |
#include <zlib.h> |
#include <zlib.h> |
#endif |
#endif |
|
|
|
|
FILE_RCSID("@(#)$Id$") |
FILE_RCSID("@(#)$Id$") |
#endif |
#endif |
|
|
private struct { |
private const struct { |
const char *magic; |
const char magic[8]; |
size_t maglen; |
size_t maglen; |
const char *const argv[3]; |
const char *argv[3]; |
int silent; |
int silent; |
} compr[] = { |
} compr[] = { |
{ "\037\235", 2, { "gzip", "-cdq", NULL }, 1 }, /* compressed */ |
{ "\037\235", 2, { "gzip", "-cdq", NULL }, 1 }, /* compressed */ |
|
|
private ssize_t swrite(int, const void *, size_t); |
private ssize_t swrite(int, const void *, size_t); |
private size_t uncompressbuf(struct magic_set *, int, size_t, |
private size_t uncompressbuf(struct magic_set *, int, size_t, |
const unsigned char *, unsigned char **, 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 *, |
private size_t uncompressgzipped(struct magic_set *, const unsigned char *, |
unsigned char **, size_t); |
unsigned char **, size_t); |
#endif |
#endif |
|
|
unsigned char *newbuf = NULL; |
unsigned char *newbuf = NULL; |
size_t i, nsz; |
size_t i, nsz; |
int rv = 0; |
int rv = 0; |
|
int mime = ms->flags & MAGIC_MIME; |
|
|
if ((ms->flags & MAGIC_COMPRESS) == 0) |
if ((ms->flags & MAGIC_COMPRESS) == 0) |
return 0; |
return 0; |
|
|
rv = -1; |
rv = -1; |
if (file_buffer(ms, -1, name, newbuf, nsz) == -1) |
if (file_buffer(ms, -1, name, newbuf, nsz) == -1) |
goto error; |
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; |
goto error; |
if (file_buffer(ms, -1, NULL, buf, nbytes) == -1) |
|
|
if (!mime && file_printf(ms, ")") == -1) |
goto error; |
goto error; |
if (file_printf(ms, ")") == -1) |
|
goto error; |
|
rv = 1; |
rv = 1; |
break; |
break; |
} |
} |
|
|
return fd; |
return fd; |
} |
} |
|
|
#ifdef HAVE_LIBZ |
#ifdef BUILTIN_DECOMPRESS |
|
|
#define FHCRC (1 << 1) |
#define FHCRC (1 << 1) |
#define FEXTRA (1 << 2) |
#define FEXTRA (1 << 2) |
|
|
int fdin[2], fdout[2]; |
int fdin[2], fdout[2]; |
int r; |
int r; |
|
|
#ifdef HAVE_LIBZ |
#ifdef BUILTIN_DECOMPRESS |
|
/* FIXME: This doesn't cope with bzip2 */ |
if (method == 2) |
if (method == 2) |
return uncompressgzipped(ms, old, newch, n); |
return uncompressgzipped(ms, old, newch, n); |
#endif |
#endif |