Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Nov 2009 02:37:02 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r199066 - head/usr.bin/gzip
Message-ID:  <200911090237.nA92b2m7005471@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Nov  9 02:37:02 2009
New Revision: 199066
URL: http://svn.freebsd.org/changeset/base/199066

Log:
  Apply a NetBSD fix (revision 1.12) to handle multi-session bzip2 files
  as created by pbzip2.
  
  Submitted by:	mrg (NetBSD.org)
  MFC after:	1 week

Modified:
  head/usr.bin/gzip/unbzip2.c

Modified: head/usr.bin/gzip/unbzip2.c
==============================================================================
--- head/usr.bin/gzip/unbzip2.c	Mon Nov  9 00:16:50 2009	(r199065)
+++ head/usr.bin/gzip/unbzip2.c	Mon Nov  9 02:37:02 2009	(r199066)
@@ -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
 	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
 	        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
 	                                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
 	        case BZ_MEM_ERROR:
 	                maybe_warnx("bzip2 out of memory");
 			break;
-
+		
+		default:	
+			maybe_warnx("unknown bzip2 error: %d", ret);
+			break;
 	        }
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200911090237.nA92b2m7005471>