diff options
Diffstat (limited to 'usr.bin/gzip/unbzip2.c')
-rw-r--r-- | usr.bin/gzip/unbzip2.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/usr.bin/gzip/unbzip2.c b/usr.bin/gzip/unbzip2.c index e8990d7..4835325 100644 --- a/usr.bin/gzip/unbzip2.c +++ b/usr.bin/gzip/unbzip2.c @@ -1,4 +1,4 @@ -/* $NetBSD: unbzip2.c,v 1.11 2008/04/28 20:24:13 martin Exp $ */ +/* $NetBSD: unbzip2.c,v 1.12 2009/10/11 05:17:20 mrg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in) if (bytes_in) *bytes_in = prelen; - while (ret >= BZ_OK && ret != BZ_STREAM_END) { + while (ret == BZ_OK) { if (bzs.avail_in == 0 && !end_of_file) { ssize_t n; @@ -88,7 +88,7 @@ unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in) case BZ_OK: if (ret == BZ_OK && end_of_file) maybe_err("read"); - if (!tflag) { + if (!tflag && bzs.avail_out != BUFLEN) { ssize_t n; n = write(out, outbuf, BUFLEN - bzs.avail_out); @@ -96,7 +96,13 @@ unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in) maybe_err("write"); bytes_out += n; } - break; + if (ret == BZ_STREAM_END && !end_of_file) { + if (BZ2_bzDecompressEnd(&bzs) != BZ_OK || + BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK) + maybe_errx("bzip2 re-init"); + ret = BZ_OK; + } + break; case BZ_DATA_ERROR: maybe_warnx("bzip2 data integrity error"); @@ -109,7 +115,10 @@ unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in) case BZ_MEM_ERROR: maybe_warnx("bzip2 out of memory"); break; - + + default: + maybe_warnx("unknown bzip2 error: %d", ret); + break; } } |