summaryrefslogtreecommitdiffstats
path: root/contrib/bzip2
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bzip2')
-rw-r--r--contrib/bzip2/FREEBSD-Xlist24
-rw-r--r--contrib/bzip2/FREEBSD-upgrade27
-rw-r--r--contrib/bzip2/bzip2.c199
-rw-r--r--contrib/bzip2/bzlib.c102
4 files changed, 276 insertions, 76 deletions
diff --git a/contrib/bzip2/FREEBSD-Xlist b/contrib/bzip2/FREEBSD-Xlist
new file mode 100644
index 0000000..2725621
--- /dev/null
+++ b/contrib/bzip2/FREEBSD-Xlist
@@ -0,0 +1,24 @@
+# $FreeBSD$
+*README.XML.STUFF
+*bz-common.xsl
+*bz-fo.xsl
+*bz-html.xsl
+*bzdiff
+*bzdiff.1
+*bzgrep
+*bzgrep.1
+*bzip.css
+*bzip2.1.preformatted
+*bzip2.txt
+*bzmore
+*bzmore.1
+*dlltest.dsp
+*entities.xml
+*format.pl
+*libbz2.dsp
+*manual.html
+*manual.pdf
+*manual.ps
+*manual.xml
+*mk251.c
+*xmlproc.sh
diff --git a/contrib/bzip2/FREEBSD-upgrade b/contrib/bzip2/FREEBSD-upgrade
new file mode 100644
index 0000000..58857ca
--- /dev/null
+++ b/contrib/bzip2/FREEBSD-upgrade
@@ -0,0 +1,27 @@
+$FreeBSD$
+
+Julian Seward's bzip2
+ originals can be found at: http://sources.redhat.com/bzip2/
+
+Imported by:
+
+ cvs import -m "Virgin import (trimmed) of Bzip2 version 1.0.3." \
+ src/contrib/bzip2 BZIP2 v1_0_3
+
+Notes:
+ The following log shows details of trimming:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ tar xvfz bzip2-1.0.3.tar.gz -X FREEBSD-Xlist
+ cd bzip2-1.0.3
+ uuencode sample1.bz2 sample1.bz2 > sample1.bz2.uu
+ uuencode sample2.bz2 sample2.bz2 > sample2.bz2.uu
+ uuencode sample3.bz2 sample3.bz2 > sample3.bz2.uu
+ gzip -9 sample1.ref sample2.ref sample3.ref
+ uuencode sample1.ref.gz sample1.ref.gz > sample1.ref.gz.uu
+ uuencode sample2.ref.gz sample2.ref.gz > sample2.ref.gz.uu
+ uuencode sample3.ref.gz sample3.ref.gz > sample3.ref.gz.uu
+ rm sample1.bz2 sample1.ref.gz sample2.bz2 sample2.ref.gz
+ rm sample3.bz2 sample3.ref.gz
+
+obrien@FreeBSD.org
+15 May 2005
diff --git a/contrib/bzip2/bzip2.c b/contrib/bzip2/bzip2.c
index 5fbae0e..5164e23 100644
--- a/contrib/bzip2/bzip2.c
+++ b/contrib/bzip2/bzip2.c
@@ -3,26 +3,119 @@
/*--- A block-sorting, lossless compressor bzip2.c ---*/
/*-----------------------------------------------------------*/
-/* ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
+/*--
+ This file is a part of bzip2 and/or libbzip2, a program and
+ library for lossless, block-sorting data compression.
+
+ Copyright (C) 1996-2005 Julian R Seward. All rights reserved.
+
+ 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. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+ 4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+
+ Julian Seward, Cambridge, UK.
+ jseward@bzip.org
+ bzip2/libbzip2 version 1.0 of 21 March 2000
+
+ This program is based on (at least) the work of:
+ Mike Burrows
+ David Wheeler
+ Peter Fenwick
+ Alistair Moffat
+ Radford Neal
+ Ian H. Witten
+ Robert Sedgewick
+ Jon L. Bentley
+
+ For more information on these sources, see the manual.
+--*/
- bzip2/libbzip2 version 1.0.4 of 20 December 2006
- Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
+/*----------------------------------------------------*/
+/*--- IMPORTANT ---*/
+/*----------------------------------------------------*/
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------ */
+/*--
+ WARNING:
+ This program and library (attempts to) compress data by
+ performing several non-trivial transformations on it.
+ Unless you are 100% familiar with *all* the algorithms
+ contained herein, and with the consequences of modifying them,
+ you should NOT meddle with the compression or decompression
+ machinery. Incorrect changes can and very likely *will*
+ lead to disasterous loss of data.
+
+ DISCLAIMER:
+ I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
+ USE OF THIS PROGRAM, HOWSOEVER CAUSED.
+
+ Every compression of a file implies an assumption that the
+ compressed file can be decompressed to reproduce the original.
+ Great efforts in design, coding and testing have been made to
+ ensure that this program works correctly. However, the
+ complexity of the algorithms, and, in particular, the presence
+ of various special cases in the code which occur with very low
+ but non-zero probability make it impossible to rule out the
+ possibility of bugs remaining in the program. DO NOT COMPRESS
+ ANY DATA WITH THIS PROGRAM AND/OR LIBRARY UNLESS YOU ARE PREPARED
+ TO ACCEPT THE POSSIBILITY, HOWEVER SMALL, THAT THE DATA WILL
+ NOT BE RECOVERABLE.
+
+ That is not to say this program is inherently unreliable.
+ Indeed, I very much hope the opposite is true. bzip2/libbzip2
+ has been carefully constructed and extensively tested.
+
+ PATENTS:
+ To the best of my knowledge, bzip2/libbzip2 does not use any
+ patented algorithms. However, I do not have the resources
+ available to carry out a full patent search. Therefore I cannot
+ give any guarantee of the above statement.
+--*/
+/* $FreeBSD$ */
-/* Place a 1 beside your platform, and 0 elsewhere.
- Generic 32-bit Unix.
- Also works on 64-bit Unix boxes.
- This is the default.
-*/
+
+/*----------------------------------------------------*/
+/*--- and now for something much more pleasant :-) ---*/
+/*----------------------------------------------------*/
+
+/*---------------------------------------------*/
+/*--
+ Place a 1 beside your platform, and 0 elsewhere.
+--*/
+
+/*--
+ Generic 32-bit Unix.
+ Also works on 64-bit Unix boxes.
+ This is the default.
+--*/
#define BZ_UNIX 1
/*--
@@ -210,17 +303,17 @@ Char progNameReally[FILE_NAME_LEN];
FILE *outputHandleJustInCase;
Int32 workFactor;
-static void panic ( const Char* ) NORETURN;
-static void ioError ( void ) NORETURN;
-static void outOfMemory ( void ) NORETURN;
-static void configError ( void ) NORETURN;
-static void crcError ( void ) NORETURN;
-static void cleanUpAndFail ( Int32 ) NORETURN;
-static void compressedStreamEOF ( void ) NORETURN;
+static void panic ( Char* ) NORETURN;
+static void ioError ( void ) NORETURN;
+static void outOfMemory ( void ) NORETURN;
+static void configError ( void ) NORETURN;
+static void crcError ( void ) NORETURN;
+static void cleanUpAndFail ( Int32 ) NORETURN;
+static void compressedStreamEOF ( void ) NORETURN;
static void copyFileName ( Char*, Char* );
static void* myMalloc ( Int32 );
-static void applySavedFileAttrToOutputFile ( IntNative fd );
+static int applySavedFileAttrToOutputFile ( int fd );
@@ -366,9 +459,10 @@ void compressStream ( FILE *stream, FILE *zStream )
ret = fflush ( zStream );
if (ret == EOF) goto errhandler_io;
if (zStream != stdout) {
- Int32 fd = fileno ( zStream );
+ int fd = fileno ( zStream );
if (fd < 0) goto errhandler_io;
- applySavedFileAttrToOutputFile ( fd );
+ ret = applySavedFileAttrToOutputFile ( fd );
+ if (ret != 0) goto errhandler_io;
ret = fclose ( zStream );
outputHandleJustInCase = NULL;
if (ret == EOF) goto errhandler_io;
@@ -481,10 +575,11 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
closeok:
if (ferror(zStream)) goto errhandler_io;
- if (stream != stdout) {
- Int32 fd = fileno ( stream );
+ if ( stream != stdout) {
+ int fd = fileno ( stream );
if (fd < 0) goto errhandler_io;
- applySavedFileAttrToOutputFile ( fd );
+ ret = applySavedFileAttrToOutputFile ( fd );
+ if (ret != 0) goto errhandler_io;
}
ret = fclose ( zStream );
if (ret == EOF) goto errhandler_io;
@@ -743,7 +838,7 @@ void cleanUpAndFail ( Int32 ec )
/*---------------------------------------------*/
static
-void panic ( const Char* s )
+void panic ( Char* s )
{
fprintf ( stderr,
"\n%s: PANIC -- internal consistency error:\n"
@@ -956,7 +1051,6 @@ Bool fileExists ( Char* name )
For non-Unix platforms, if we are not worrying about
security issues, simple this simply behaves like fopen.
*/
-static
FILE* fopen_output_safely ( Char* name, const char* mode )
{
# if BZ_UNIX
@@ -1062,18 +1156,20 @@ void applySavedTimeInfoToOutputFile ( Char *dstName )
}
static
-void applySavedFileAttrToOutputFile ( IntNative fd )
+int applySavedFileAttrToOutputFile ( int fd )
{
# if BZ_UNIX
- IntNative retVal;
+ IntNative retVal;
retVal = fchmod ( fd, fileMetaInfo.st_mode );
- ERROR_IF_NOT_ZERO ( retVal );
+ if (retVal != 0)
+ return retVal;
(void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
/* chown() will in many cases return with EPERM, which can
be safely ignored.
*/
+ return 0;
# endif
}
@@ -1101,13 +1197,13 @@ Bool containsDubiousChars ( Char* name )
/*---------------------------------------------*/
#define BZ_N_SUFFIX_PAIRS 4
-const Char* zSuffix[BZ_N_SUFFIX_PAIRS]
+Char* zSuffix[BZ_N_SUFFIX_PAIRS]
= { ".bz2", ".bz", ".tbz2", ".tbz" };
-const Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
+Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
= { "", "", ".tar", ".tar" };
static
-Bool hasSuffix ( Char* s, const Char* suffix )
+Bool hasSuffix ( Char* s, Char* suffix )
{
Int32 ns = strlen(s);
Int32 nx = strlen(suffix);
@@ -1118,8 +1214,7 @@ Bool hasSuffix ( Char* s, const Char* suffix )
static
Bool mapSuffix ( Char* name,
- const Char* oldSuffix,
- const Char* newSuffix )
+ Char* oldSuffix, Char* newSuffix )
{
if (!hasSuffix(name,oldSuffix)) return False;
name[strlen(name)-strlen(oldSuffix)] = 0;
@@ -1144,8 +1239,8 @@ void compress ( Char *name )
switch (srcMode) {
case SM_I2O:
- copyFileName ( inName, (Char*)"(stdin)" );
- copyFileName ( outName, (Char*)"(stdout)" );
+ copyFileName ( inName, "(stdin)" );
+ copyFileName ( outName, "(stdout)" );
break;
case SM_F2F:
copyFileName ( inName, name );
@@ -1154,7 +1249,7 @@ void compress ( Char *name )
break;
case SM_F2O:
copyFileName ( inName, name );
- copyFileName ( outName, (Char*)"(stdout)" );
+ copyFileName ( outName, "(stdout)" );
break;
}
@@ -1328,8 +1423,8 @@ void uncompress ( Char *name )
cantGuess = False;
switch (srcMode) {
case SM_I2O:
- copyFileName ( inName, (Char*)"(stdin)" );
- copyFileName ( outName, (Char*)"(stdout)" );
+ copyFileName ( inName, "(stdin)" );
+ copyFileName ( outName, "(stdout)" );
break;
case SM_F2F:
copyFileName ( inName, name );
@@ -1342,7 +1437,7 @@ void uncompress ( Char *name )
break;
case SM_F2O:
copyFileName ( inName, name );
- copyFileName ( outName, (Char*)"(stdout)" );
+ copyFileName ( outName, "(stdout)" );
break;
}
@@ -1520,9 +1615,9 @@ void testf ( Char *name )
if (name == NULL && srcMode != SM_I2O)
panic ( "testf: bad modes\n" );
- copyFileName ( outName, (Char*)"(none)" );
+ copyFileName ( outName, "(none)" );
switch (srcMode) {
- case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
+ case SM_I2O: copyFileName ( inName, "(stdin)" ); break;
case SM_F2F: copyFileName ( inName, name ); break;
case SM_F2O: copyFileName ( inName, name ); break;
}
@@ -1605,11 +1700,11 @@ void license ( void )
"bzip2, a block-sorting file compressor. "
"Version %s.\n"
" \n"
- " Copyright (C) 1996-2006 by Julian Seward.\n"
+ " Copyright (C) 1996-2005 by Julian Seward.\n"
" \n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms set out in the LICENSE file, which is included\n"
- " in the bzip2-1.0.4 source distribution.\n"
+ " in the bzip2-1.0 source distribution.\n"
" \n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
@@ -1812,8 +1907,8 @@ IntNative main ( IntNative argc, Char *argv[] )
# endif
# endif
- copyFileName ( inName, (Char*)"(none)" );
- copyFileName ( outName, (Char*)"(none)" );
+ copyFileName ( inName, "(none)" );
+ copyFileName ( outName, "(none)" );
copyFileName ( progNameReally, argv[0] );
progName = &progNameReally[0];
@@ -1825,8 +1920,8 @@ IntNative main ( IntNative argc, Char *argv[] )
expand filename wildcards in arg list.
--*/
argList = NULL;
- addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
- addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
+ addFlagsFromEnvVar ( &argList, "BZIP2" );
+ addFlagsFromEnvVar ( &argList, "BZIP" );
for (i = 1; i <= argc-1; i++)
APPEND_FILESPEC(argList, argv[i]);
diff --git a/contrib/bzip2/bzlib.c b/contrib/bzip2/bzlib.c
index 79c34a5..f365acd 100644
--- a/contrib/bzip2/bzlib.c
+++ b/contrib/bzip2/bzlib.c
@@ -4,32 +4,81 @@
/*--- bzlib.c ---*/
/*-------------------------------------------------------------*/
-/* ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
+/*--
+ This file is a part of bzip2 and/or libbzip2, a program and
+ library for lossless, block-sorting data compression.
+
+ Copyright (C) 1996-2005 Julian R Seward. All rights reserved.
+
+ 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. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+ 4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+
+ Julian Seward, Cambridge, UK.
+ jseward@bzip.org
+ bzip2/libbzip2 version 1.0 of 21 March 2000
+
+ This program is based on (at least) the work of:
+ Mike Burrows
+ David Wheeler
+ Peter Fenwick
+ Alistair Moffat
+ Radford Neal
+ Ian H. Witten
+ Robert Sedgewick
+ Jon L. Bentley
+
+ For more information on these sources, see the manual.
+--*/
- bzip2/libbzip2 version 1.0.4 of 20 December 2006
- Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+/*--
+ CHANGES
+ ~~~~~~~
+ 0.9.0 -- original version.
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
+ 0.9.0a/b -- no changes in this file.
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------ */
+ 0.9.0c
+ * made zero-length BZ_FLUSH work correctly in bzCompress().
+ * fixed bzWrite/bzRead to ignore zero-length requests.
+ * fixed bzread to correctly handle read requests after EOF.
+ * wrong parameter order in call to bzDecompressInit in
+ bzBuffToBuffDecompress. Fixed.
+--*/
-/* CHANGES
- 0.9.0 -- original version.
- 0.9.0a/b -- no changes in this file.
- 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
- fixed bzWrite/bzRead to ignore zero-length requests.
- fixed bzread to correctly handle read requests after EOF.
- wrong parameter order in call to bzDecompressInit in
- bzBuffToBuffDecompress. Fixed.
-*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
#include "bzlib_private.h"
+#ifndef BZ_NO_COMPRESS
/*---------------------------------------------------*/
/*--- Compression stuff ---*/
@@ -85,6 +134,7 @@ void BZ2_bz__AssertH__fail ( int errcode )
}
#endif
+#endif /* BZ_NO_COMPRESS */
/*---------------------------------------------------*/
static
@@ -111,6 +161,7 @@ void default_bzfree ( void* opaque, void* addr )
if (addr != NULL) free ( addr );
}
+#ifndef BZ_NO_COMPRESS
/*---------------------------------------------------*/
static
@@ -483,6 +534,7 @@ int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm )
return BZ_OK;
}
+#endif /* BZ_NO_COMPRESS */
/*---------------------------------------------------*/
/*--- Decompression stuff ---*/
@@ -876,6 +928,7 @@ int BZ_API(BZ2_bzDecompressEnd) ( bz_stream *strm )
return BZ_OK;
}
+#ifndef BZ_NO_COMPRESS
#ifndef BZ_NO_STDIO
/*---------------------------------------------------*/
@@ -1349,7 +1402,8 @@ int BZ_API(BZ2_bzBuffToBuffDecompress)
/*---------------------------------------------------*/
/*--
- Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
+ Code contributed by Yoshioka Tsuneo
+ (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
to support better zlib compatibility.
This code is not _officially_ part of libbzip2 (yet);
I haven't tested it, documented it, or considered the
@@ -1360,7 +1414,7 @@ int BZ_API(BZ2_bzBuffToBuffDecompress)
/*---------------------------------------------------*/
/*--
- return version like "0.9.5d, 4-Sept-1999".
+ return version like "0.9.0c".
--*/
const char * BZ_API(BZ2_bzlibVersion)(void)
{
@@ -1513,10 +1567,9 @@ int BZ_API(BZ2_bzflush) (BZFILE *b)
void BZ_API(BZ2_bzclose) (BZFILE* b)
{
int bzerr;
- FILE *fp;
+ FILE *fp = ((bzFile *)b)->handle;
if (b==NULL) {return;}
- fp = ((bzFile *)b)->handle;
if(((bzFile*)b)->writing){
BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
if(bzerr != BZ_OK){
@@ -1535,7 +1588,7 @@ void BZ_API(BZ2_bzclose) (BZFILE* b)
/*--
return last error code
--*/
-static const char *bzerrorstrings[] = {
+static char *bzerrorstrings[] = {
"OK"
,"SEQUENCE_ERROR"
,"PARAM_ERROR"
@@ -1565,6 +1618,7 @@ const char * BZ_API(BZ2_bzerror) (BZFILE *b, int *errnum)
}
#endif
+#endif /* BZ_NO_COMPRESS */
/*-------------------------------------------------------------*/
/*--- end bzlib.c ---*/
OpenPOWER on IntegriCloud