Index: external/zlib/pigz/bin/pigz/Makefile =================================================================== RCS file: /cvsroot/src/external/zlib/pigz/bin/pigz/Makefile,v retrieving revision 1.7 diff -p -r1.7 Makefile *** external/zlib/pigz/bin/pigz/Makefile 26 May 2011 12:56:27 -0000 1.7 --- external/zlib/pigz/bin/pigz/Makefile 11 Jul 2011 01:44:45 -0000 *************** MAN= pigz.1 *** 15,21 **** .if !defined(HOSTPROG) DPADD= ${LIBM} ${LIBPTHREAD} .endif ! LDADD= -lz -lpthread .if ${MKPIGZGZIP} != "no" # these ones are from mrg's gzip --- 15,21 ---- .if !defined(HOSTPROG) DPADD= ${LIBM} ${LIBPTHREAD} .endif ! LDADD= -lz -lpthread -lbz2 .if ${MKPIGZGZIP} != "no" # these ones are from mrg's gzip Index: external/zlib/pigz/dist/pigz.c =================================================================== RCS file: /cvsroot/src/external/zlib/pigz/dist/pigz.c,v retrieving revision 1.1.1.1 diff -p -r1.1.1.1 pigz.c *** external/zlib/pigz/dist/pigz.c 17 Jun 2010 06:05:09 -0000 1.1.1.1 --- external/zlib/pigz/dist/pigz.c 11 Jul 2011 01:44:45 -0000 *************** local long tolong(unsigned long val) *** 1566,1571 **** --- 1566,1575 ---- return (long)(val & 0x7fffffffUL) - (long)(val & 0x80000000UL); } + #ifdef __NetBSD__ + #include "unbzip2.c" + #endif + #define LOW32 0xffffffffUL /* process zip extra field to extract zip64 lengths and Unix mod time */ *************** local int read_extra(unsigned len, int s *** 1624,1629 **** --- 1628,1637 ---- immediate EOF, -2 is not a recognized compressed format, -3 is premature EOF within the header, -4 is unexpected header flag values; a method of 256 is lzw -- set form to indicate gzip, zlib, or zip */ + /* + * on NetBSD, return of 66 indicates bzip2, and a return of 31 indicates + * pack. native pigz already includes compress support. + */ local int get_header(int save) { unsigned magic; /* magic header */ *************** local int get_header(int save) *** 1699,1704 **** --- 1707,1724 ---- form = 2 + ((flags & 8) >> 3); return in_eof ? -3 : method; } + #if defined(__NetBSD__) + if (magic == 0x1f1e) { /* is pack */ + return 31; + } + if (magic == 0x425a) { /* might be bzip2 */ + unsigned magic3; + magic3 = GET(); + if (magic3 == 0x68) { /* is bzip2 */ + return 66; + } + } + #endif if (magic != 0x1f8b) /* not gzip */ return -2; *************** local size_t compressed_suffix(char *nm) *** 1786,1791 **** --- 1806,1815 ---- if (strcmp(nm, ".zip") == 0 || strcmp(nm, ".ZIP") == 0 || strcmp(nm, ".tgz") == 0) return 4; + #if defined(__NetBSD__) + if (strcmp(nm, ".bz2") == 0 || strcmp(nm, ".tbz") == 0) + return 4; + #endif } if (len > 3) { nm += len - 3; *************** local void list_info(void) *** 1902,1907 **** --- 1926,1940 ---- return; } + #if defined(__NetBSD__) + /* don't support -l for bz2 or pack files */ + if (method == 66 || method == 31) { + if (verbosity > 1) + fprintf(stderr, "%s: no list info support -- skipping\n", in); + return; + } + #endif + /* list zip file */ if (form > 1) { in_tot = zip_clen; *************** local void process(char *path) *** 2633,2638 **** --- 2666,2676 ---- if (decode) { in_init(); method = get_header(1); + #if defined(__NetBSD__) + if (method == 66 || method == 31) { + /* do nothing */; + } else + #endif if (method != 8 && method != 256) { RELEASE(hname); if (ind != 0) *************** local void process(char *path) *** 2647,2652 **** --- 2685,2698 ---- /* if requested, test input file (possibly a special list) */ if (decode == 2) { + #if defined(__NetBSD__) + if (method == 66) { + bzip2_decode(); + } else if (method == 31) { + fprintf(stderr, "%s: WOULD TEST PACK\n", in); /* XXXMRG */ + //pack_decode(); + } else + #endif if (method == 8) infchk(); else { *************** local void process(char *path) *** 2742,2752 **** --- 2788,2815 ---- if (verbosity > 1) fprintf(stderr, "%s to %s ", in, out); if (decode) { + #if defined(__NetBSD__) + if (method == 66) { + bzip2_decode(); + } else if (method == 31) { + bail("WOULD PACK %s", in); /* XXXMRG */ + //pack_decode(); + } else + #endif if (method == 8) infchk(); else unlzw(); } + #if defined(__NetBSD__) + else if (method == 66 || method == 31) { + if (verbosity > 1) { + fprintf(stderr, "%s: no %s", in, method == 66 ? "bzip2" : "pack"); + fprintf(stderr, "compress support support -- skipping\n"); + } + return; + } + #endif #ifndef NOTHREAD else if (procs > 1) parallel_compress(); Index: external/zlib/pigz/dist/unbzip2.c =================================================================== RCS file: external/zlib/pigz/dist/unbzip2.c diff -N external/zlib/pigz/dist/unbzip2.c *** /dev/null 1 Jan 1970 00:00:00 -0000 --- external/zlib/pigz/dist/unbzip2.c 11 Jul 2011 01:44:45 -0000 *************** *** 0 **** --- 1,146 ---- + /* $NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg Exp $ */ + + /*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Simon Burge and Matthew R. Green. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + /* This file is #included by pigz.c */ + + #include + #include + + #ifndef BUFLEN + #define BUFLEN (64 * 1024) + #endif + + static void bzip2_decode(void); + + static void + bzip2_decode(void) + { + int ret, end_of_file, cold = 0; + bz_stream bzs; + static char *inbuf, *outbuf; + + if (inbuf == NULL) + inbuf = malloc(BUFLEN); + if (outbuf == NULL) + outbuf = malloc(BUFLEN); + if (inbuf == NULL || outbuf == NULL) + bail("malloc", strerror(errno)); + + bzs.bzalloc = NULL; + bzs.bzfree = NULL; + bzs.opaque = NULL; + + out_tot = 0; + + end_of_file = 0; + ret = BZ2_bzDecompressInit(&bzs, 0, 0); + if (ret != BZ_OK) + bail("bzip2 init", ""); + + /* Prepend the header, already read. */ + bzs.avail_in = 3; + bzs.next_in = "\102\132\150"; + + while (ret == BZ_OK) { + if (bzs.avail_in == 0 && !end_of_file) { + ssize_t n; + + n = read(ind, inbuf, BUFLEN); + if (n < 0) + bail("read: ", strerror(errno)); + if (n == 0) + end_of_file = 1; + bzs.next_in = inbuf; + bzs.avail_in = n; + in_tot += n; + } + + bzs.next_out = outbuf; + bzs.avail_out = BUFLEN; + ret = BZ2_bzDecompress(&bzs); + + switch (ret) { + case BZ_STREAM_END: + case BZ_OK: + if (ret == BZ_OK && end_of_file) { + /* + * If we hit this after a stream end, consider + * it as the end of the whole file and don't + * bail out. + */ + if (cold == 1) + ret = BZ_STREAM_END; + else + bail("truncated file", ""); + } + cold = 0; + if (decode != 2 && bzs.avail_out != BUFLEN) { + ssize_t n; + + n = write(outd, outbuf, BUFLEN - bzs.avail_out); + if (n < 0) + bail("write: ", strerror(errno)); + out_tot += BUFLEN - bzs.avail_out; + } + if (ret == BZ_STREAM_END && !end_of_file) { + if (BZ2_bzDecompressEnd(&bzs) != BZ_OK || + BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK) + bail("bzip2 re-init", ""); + cold = 1; + ret = BZ_OK; + } + break; + + case BZ_DATA_ERROR: + fprintf(stderr, "bzip2 data integrity error\n"); + break; + + case BZ_DATA_ERROR_MAGIC: + fprintf(stderr, "bzip2 magic number error\n"); + break; + + case BZ_MEM_ERROR: + fprintf(stderr, "bzip2 out of memory\n"); + break; + + default: + fprintf(stderr, "unknown bzip2 error: %d\n", ret); + break; + } + } + + #if 0 /* XXXMRG */ + if (ret != BZ_STREAM_END || BZ2_bzDecompressEnd(&bzs) != BZ_OK) + return (-1); + #endif + + return; + }