diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-11-14 22:29:54 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-11-14 22:29:54 +0000 |
commit | b5cae4c14b4acf4372b11546b6b03a39efac15cf (patch) | |
tree | 587fcdc56a08d9ed62ad2a02e9800efff749bd7e | |
parent | facfa9ebaddcd6343c58e5546e9c221ab0da11f4 (diff) |
Add support for inflating multiple concatenated file like GNU gzip does.
Problem noticed by lebel@, OK mickey@
-rw-r--r-- | usr.bin/compress/gzopen.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/usr.bin/compress/gzopen.c b/usr.bin/compress/gzopen.c index c0893a0bb19..6e701d4118a 100644 --- a/usr.bin/compress/gzopen.c +++ b/usr.bin/compress/gzopen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gzopen.c,v 1.14 2003/07/17 20:17:02 mickey Exp $ */ +/* $OpenBSD: gzopen.c,v 1.15 2003/11/14 22:29:53 millert Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -59,7 +59,7 @@ */ const char gz_rcsid[] = - "$OpenBSD: gzopen.c,v 1.14 2003/07/17 20:17:02 mickey Exp $"; + "$OpenBSD: gzopen.c,v 1.15 2003/11/14 22:29:53 millert Exp $"; #include <sys/param.h> #include <sys/stat.h> @@ -443,8 +443,22 @@ gz_read(void *cookie, char *buf, int len) } s->z_crc = crc32(s->z_crc, start, (uInt)(s->z_stream.next_out - start)); + len -= s->z_stream.avail_out; - return (int)(len - s->z_stream.avail_out); + /* If at EOF, check for another appended file. */ + if (s->z_eof) { + int ocrc = s->z_crc; + s->z_crc = crc32(0L, Z_NULL, 0); + s->z_eof = 0; + if (get_header(s, NULL, 0) != 0 || + inflateEnd(&s->z_stream) != Z_OK || + inflateInit2(&s->z_stream, -MAX_WBITS) != Z_OK) { + s->z_eof = 1; + s->z_crc = ocrc; + } + } + + return (len); } int |