* zmagic() - returns 0 if not recognized, uncompresses and prints
* information if recognized
* uncompress(method, old, n, newch) - uncompress old into new,
* using method, return sizeof new
* $Id: compress.c,v 1.7 1993/10/27 20:59:05 christos Exp $
{ "\037\235", 2, { "uncompress", "-c", NULL
}, 0 },
{ "\037\213", 2, { "gzip", "-dq", NULL
}, 1 },
/* XXX pcat does not work, cause I don't know how to make it read stdin */
{ "\037\036", 2, { "pcat", NULL
, NULL
}, 0 },
static int ncompr
= sizeof(compr
) / sizeof(compr
[0]);
static int uncompress
__P((int, const unsigned char *, unsigned char **, int));
for (i
= 0; i
< ncompr
; i
++) {
if (nbytes
< compr
[i
].maglen
)
if (memcmp(buf
, compr
[i
].magic
, compr
[i
].maglen
) == 0)
if ((newsize
= uncompress(i
, buf
, &newbuf
, nbytes
)) != 0) {
tryit(newbuf
, newsize
, 1);
uncompress(method
, old
, newch
, n
)
const unsigned char *old
;
if (pipe(fdin
) == -1 || pipe(fdout
) == -1) {
error("cannot create pipe (%s).\n", strerror(errno
));
if (compr
[method
].silent
)
execvp(compr
[method
].argv
[0], compr
[method
].argv
);
error("could not execute `%s' (%s).\n",
compr
[method
].argv
[0], strerror(errno
));
error("could not fork (%s).\n", strerror(errno
));
if (write(fdin
[1], old
, n
) != n
) {
error("write failed (%s).\n", strerror(errno
));
if ((*newch
= (unsigned char *) malloc(n
)) == NULL
) {
error("out of memory.\n");
if ((n
= read(fdout
[0], *newch
, n
)) <= 0) {
error("read failed (%s).\n", strerror(errno
));