Compare commits

..

2 Commits

Author SHA1 Message Date
Mark Adler
423eb40306 zlib 1.0.1 2011-09-09 23:14:39 -07:00
Mark Adler
8a2acbffc8 zlib 1.0-pre 2011-09-09 23:13:27 -07:00
29 changed files with 603 additions and 156 deletions

View File

@@ -1,7 +1,28 @@
ChangeLog file for zlib ChangeLog file for zlib
Changes in 1.0 (15 Jan 96) Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
- fix array overlay in deflate.c which sometimes caused bad compressed data
- fix inflate bug with empty stored block
- fix MSDOS medium model which was broken in 0.99
- fix deflateParams() which could generated bad compressed data.
- Bytef is define'd instead of typedef'ed (work around Borland bug)
- added an INDEX file
- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
- speed up adler32 for modern machines without auto-increment
- added -ansi for IRIX in configure
- static_init_done in trees.c is an int
- define unlink as delete for VMS
- fix configure for QNX
- add configure branch for SCO and HPUX
- avoid many warnings (unused variables, dead assignments, etc...)
- no fdopen for BeOS
- fix the Watcom fix for 32 bit mode (define FAR as empty)
- removed redefinition of Byte for MKWERKS
- work around an MWKERKS bug (incorrect merge of all .h files)
Changes in 0.99 (27 Jan 96)
- allow preset dictionary shared between compressor and decompressor - allow preset dictionary shared between compressor and decompressor
- allow compression level 0 (no compression) - allow compression level 0 (no compression)
- add deflateParams in zlib.h: allow dynamic change of compression level - add deflateParams in zlib.h: allow dynamic change of compression level

46
INDEX Normal file
View File

@@ -0,0 +1,46 @@
ChangeLog history of changes
INDEX this file
Make_vms.com script for Vax/VMS
Makefile makefile for Unix (generated by configure)
Makefile.b32 makefile for Borland C++ 32-bit
Makefile.bor makefile for Borland C/C++ 16-bit
Makefile.dj2 makefile for DJGPP 2.x
Makefile.in makefile for Unix (template for configure)
Makefile.msc makefile for Microsoft C 16-bit
Makefile.sas makefile for Amiga SAS/C
Makefile.tc makefile for Turbo C
Makefile.wat makefile for Watcom C
README guess what
configure configure script for Unix
descrip.mms makefile for Vax/VMS
zlib public header files (must be kept):
zconf.h
zlib.h
private source files used to build the zlib library:
adler32.c
compress.c
crc32.c
deflate.c
deflate.h
gzio.c
infblock.c
infblock.h
infcodes.c
infcodes.h
inffast.c
inffast.h
inflate.c
inftrees.c
inftrees.h
infutil.c
infutil.h
trees.c
uncompr.c
zutil.c
zutil.h
source files for sample programs:
example.c
minigzip.c

View File

@@ -22,7 +22,7 @@ CFLAGS=-O
LDFLAGS=-L. -lz LDFLAGS=-L. -lz
LDSHARED=$(CC) LDSHARED=$(CC)
VER=1.0 VER=1.0.1
LIBS=libz.a LIBS=libz.a
AR=ar rc AR=ar rc
@@ -37,8 +37,7 @@ OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
TEST_OBJS = example.o minigzip.o TEST_OBJS = example.o minigzip.o
DISTFILES = README ChangeLog configure Makefile.in Makefile Makefile.msc \ DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] descrip.mms *.[ch]
Makefile.bor Makefile.tc Make_vms.com descrip.mms *.[ch]
all: example minigzip all: example minigzip
@@ -86,7 +85,7 @@ clean:
zip: zip:
mv Makefile Makefile~; cp -p Makefile.in Makefile mv Makefile Makefile~; cp -p Makefile.in Makefile
v=`sed -n -e 's/\./-/' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ v=`sed -n -e 's/\./-/g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
zip -ul9 zlib-$$v $(DISTFILES) zip -ul9 zlib-$$v $(DISTFILES)
mv Makefile~ Makefile mv Makefile~ Makefile

104
Makefile.b32 Normal file
View File

@@ -0,0 +1,104 @@
# Makefile for zlib
# Borland C++
# This version of the zlib makefile was adapted by Chris Young for use
# with Borland C 4.5x with the Dos Power Pack for a 32-bit protected mode
# flat memory model. It was created for use with POV-Ray ray tracer and
# you may choose to edit the CFLAGS to suit your needs but the
# switches -WX and -DMSDOS are required.
# -- Chris Young 76702.1655@compuserve.com
# To use, do "make -fmakefile.b32"
# See zconf.h for details about the memory requirements.
# ------------- Borland C++ -------------
MODEL=-WX
CFLAGS= $(MODEL) -P-C -K -N- -k- -d -3 -r- -v- -f -DMSDOS
CC=bcc32
LD=bcc32
LIB=tlib
LDFLAGS= $(MODEL)
O=.obj
# variables
OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \
trees$(O)
OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\
trees$(O)
OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \
infutil$(O) inffast$(O)
OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\
infutil$(O)+inffast$(O)
all: test
adler32.obj: adler32.c zutil.h zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
compress.obj: compress.c zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
crc32.obj: crc32.c zutil.h zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
gzio.obj: gzio.c zutil.h zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h\
infcodes.h infutil.h
$(CC) -c $(CFLAGS) $*.c
infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h\
infcodes.h inffast.h
$(CC) -c $(CFLAGS) $*.c
inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h
$(CC) -c $(CFLAGS) $*.c
inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
$(CC) -c $(CFLAGS) $*.c
infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h
$(CC) -c $(CFLAGS) $*.c
inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
$(CC) -c $(CFLAGS) $*.c
trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
uncompr.obj: uncompr.c zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
zutil.obj: zutil.c zutil.h zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
example.obj: example.c zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
minigzip.obj: minigzip.c zlib.h zconf.h
$(CC) -c $(CFLAGS) $*.c
# we must cut the command line to fit in the MS/DOS 128 byte limit:
zlib.lib: $(OBJ1) $(OBJ2)
del zlib.lib
$(LIB) zlib +$(OBJP1)
$(LIB) zlib +$(OBJP2)
example.exe: example.obj zlib.lib
$(LD) $(LDFLAGS) example.obj zlib.lib
minigzip.exe: minigzip.obj zlib.lib
$(LD) $(LDFLAGS) minigzip.obj zlib.lib
test: example.exe minigzip.exe
example
echo hello world | minigzip | minigzip -d
#clean:
# del *.obj
# del *.exe

79
Makefile.dj2 Normal file
View File

@@ -0,0 +1,79 @@
# Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96.
# Copyright (C) 1995-1996 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h
# To compile and test, type:
# make -fmakefile.dj2; make test -fmakefile.dj2
# To install libz.a, zconf.h and zlib.h in the djgpp directories, type:
# make install -fmakefile.dj2
# after first defining LIBRARY_PATH and INCLUDE_PATH in djgpp.env for [make].
# Alternately these variables may be defined below.
CC=gcc
#CFLAGS=-MMD -O
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-MMD -g -DDEBUG
CFLAGS=-MMD -O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
-Wstrict-prototypes -Wmissing-prototypes
INSTALL=install
LDLIBS=-L. -lz
LD=$(CC) -s -o
LDSHARED=$(CC)
VER=1.0
LIBS=libz.a
AR=ar rcs
# The default value of RM is "rm -f." If "rm.exe" is not found, uncomment:
# RM=del
prefix=/usr/local
exec_prefix = $(prefix)
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
TEST_OBJS = example.o minigzip.o
DISTFILES = README Change.Log configur Makefile.in Makefile Makefile.msc \
Makefile.bor Makefile.tc Make_vms.com descrip.mms zlib099.pat \
*.bak *.old *.[ch]
all: example.exe minigzip.exe
test: all
./example
echo hello world | .\minigzip | .\minigzip -d
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
libz.a: $(OBJS)
$(AR) $@ $(OBJS)
libz.so.$(VER): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f libz.so; ln -s $@ libz.so
%.exe : %.o $(LIBS)
$(LD) $@ $< $(LDLIBS)
# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env
install: $(LIBS)
$(INSTALL) zlib.h zconf.h $(INCLUDE_PATH)
$(INSTALL) $(LIBS) $(LIBRARY_PATH)
uninstall:
$(RM) $(LIBRARY_PATH)/$(LIBS)
$(RM) $(INCLUDE_PATH)/zlib.h $(INCLUDE_PATH)/zconf.h
clean:
$(RM) *.d *.o *.~ *.exe libz.a libz.so* foo.gz
DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif

View File

@@ -22,7 +22,7 @@ CFLAGS=-O
LDFLAGS=-L. -lz LDFLAGS=-L. -lz
LDSHARED=$(CC) LDSHARED=$(CC)
VER=1.0 VER=1.0.1
LIBS=libz.a LIBS=libz.a
AR=ar rc AR=ar rc
@@ -37,8 +37,7 @@ OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
TEST_OBJS = example.o minigzip.o TEST_OBJS = example.o minigzip.o
DISTFILES = README ChangeLog configure Makefile.in Makefile Makefile.msc \ DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] descrip.mms *.[ch]
Makefile.bor Makefile.tc Make_vms.com descrip.mms *.[ch]
all: example minigzip all: example minigzip
@@ -86,7 +85,7 @@ clean:
zip: zip:
mv Makefile Makefile~; cp -p Makefile.in Makefile mv Makefile Makefile~; cp -p Makefile.in Makefile
v=`sed -n -e 's/\./-/' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ v=`sed -n -e 's/\./-/g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
zip -ul9 zlib-$$v $(DISTFILES) zip -ul9 zlib-$$v $(DISTFILES)
mv Makefile~ Makefile mv Makefile~ Makefile

64
Makefile.sas Normal file
View File

@@ -0,0 +1,64 @@
# SMakefile for zlib
# Modified from the standard UNIX Makefile Copyright Jean-loup Gailly
# Osma Ahvenlampi <Osma.Ahvenlampi@hut.fi>
# Amiga, SAS/C 6.56 & Smake
CC=sc
CFLAGS=OPT
#CFLAGS=OPT CPU=68030
#CFLAGS=DEBUG=LINE
LDFLAGS=LIB z.lib
SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \
NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
TEST_OBJS = example.o minigzip.o
all: SCOPTIONS example minigzip
test: all
`cd`/example
echo hello world | minigzip | minigzip -d
install: z.lib
copy zlib.h zconf.h INCLUDE: clone
copy z.lib LIB: clone
z.lib: $(OBJS)
oml z.lib r $(OBJS)
example: example.o z.lib
$(CC) $(CFLAGS) LINK TO $@ example.o $(LDFLAGS)
minigzip: minigzip.o z.lib
$(CC) $(CFLAGS) LINK TO $@ minigzip.o $(LDFLAGS)
clean:
-delete force quiet *.o example minigzip z.lib foo.gz *.lnk SCOPTIONS
SCOPTIONS: Smakefile
copy to $@ <from <
$(SCOPTIONS)
<
# DO NOT DELETE THIS LINE -- make depend depends on it.
adler32.o: zutil.h zlib.h zconf.h
compress.o: zlib.h zconf.h
crc32.o: zutil.h zlib.h zconf.h
deflate.o: deflate.h zutil.h zlib.h zconf.h
example.o: zlib.h zconf.h
gzio.o: zutil.h zlib.h zconf.h
infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
inffast.o: zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
inflate.o: zutil.h zlib.h zconf.h infblock.h
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h
minigzip.o: zlib.h zconf.h
trees.o: deflate.h zutil.h zlib.h zconf.h
uncompr.o: zlib.h zconf.h
zutil.o: zutil.h zlib.h zconf.h

103
Makefile.wat Normal file
View File

@@ -0,0 +1,103 @@
# Makefile for zlib
# Watcom 10a
# This version of the zlib makefile was adapted by Chris Young for use
# with Watcom 10a 32-bit protected mode flat memory model. It was created
# for use with POV-Ray ray tracer and you may choose to edit the CFLAGS to
# suit your needs but the -DMSDOS is required.
# -- Chris Young 76702.1655@compuserve.com
# To use, do "wmake -f makefile.wat"
# See zconf.h for details about the memory requirements.
# ------------- Watcom 10a -------------
MODEL=-mf
CFLAGS= $(MODEL) -fpi87 -fp5 -zp4 -5r -w5 -oneatx -DMSDOS
CC=wcc386
LD=wcl386
LIB=wlib -b -c
LDFLAGS=
O=.obj
# variables
OBJ1=adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O)
OBJ2=trees$(O) zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O)
OBJ3=infutil$(O) inffast$(O)
OBJP1=adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)
OBJP2=trees$(O)+zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)
OBJP3=infutil$(O)+inffast$(O)
all: test
adler32.obj: adler32.c zutil.h zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
compress.obj: compress.c zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
crc32.obj: crc32.c zutil.h zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
gzio.obj: gzio.c zutil.h zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h &
infcodes.h infutil.h
$(CC) $(CFLAGS) $*.c
infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h &
infcodes.h inffast.h
$(CC) $(CFLAGS) $*.c
inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h
$(CC) $(CFLAGS) $*.c
inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
$(CC) $(CFLAGS) $*.c
infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h
$(CC) $(CFLAGS) $*.c
inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
$(CC) $(CFLAGS) $*.c
trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
uncompr.obj: uncompr.c zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
zutil.obj: zutil.c zutil.h zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
example.obj: example.c zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
minigzip.obj: minigzip.c zlib.h zconf.h
$(CC) $(CFLAGS) $*.c
# we must cut the command line to fit in the MS/DOS 128 byte limit:
zlib.lib: $(OBJ1) $(OBJ2) $(OBJ3)
del zlib.lib
$(LIB) zlib.lib +$(OBJP1)
$(LIB) zlib.lib +$(OBJP2)
$(LIB) zlib.lib +$(OBJP3)
example.exe: example.obj zlib.lib
$(LD) $(LDFLAGS) example.obj zlib.lib
minigzip.exe: minigzip.obj zlib.lib
$(LD) $(LDFLAGS) minigzip.obj zlib.lib
test: minigzip.exe example.exe
example
echo hello world | minigzip | minigzip -d >test
type test
#clean:
# del *.obj
# del *.exe

45
README
View File

@@ -1,7 +1,8 @@
zlib 1.0 is a general purpose data compression library. All the code zlib 1.0.1 is a general purpose data compression library. All the code
is reentrant (thread safe). The data format used by the zlib library is reentrant (thread safe). The data format used by the zlib library
is described in the files zlib-3.3.doc, deflate-1.3.doc and is described in the files zlib-3.3.doc, deflate-1.3.doc and
gzip-4.3.doc, available in ftp://ftp.uu.net/pub/archiving/zip/doc/ gzip-4.3.doc, available in various formats from
ftp://swrinde.nde.swri.edu/pub/png/documents/zlib/
All functions of the compression library are documented in the file All functions of the compression library are documented in the file
zlib.h. A usage example of the library is given in the file example.c zlib.h. A usage example of the library is given in the file example.c
@@ -17,29 +18,18 @@ makefiles such as Makefile.msc; for VMS, use Make_vms.com or descrip.mms.
Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov> or, Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov> or,
if this fails, to the addresses given below in the Copyright section. if this fails, to the addresses given below in the Copyright section.
The changes made in version 1.0 are documented in the file ChangeLog. The changes made in version 1.0.1 are documented in the file ChangeLog.
The main changes since 0.95 are: Version number 1.0 was skipped to avoid confusion with version 0.99
- allow preset dictionary shared between compressor and decompressor which had some references to 1.0 already. The main changes since 0.99 are:
- allow compression level 0 (no compression)
- add deflateParams in zlib.h: allow dynamic change of compression level - fix array overlay in deflate.c which sometimes caused bad compressed data
and compression strategy. - fix inflate bug with empty stored block
- test large buffers and deflateParams in example.c - fix MSDOS medium model which was broken in 0.99
- add optional "configure" to build zlib as a shared library - fix deflateParams() which could generated bad compressed data.
- suppress Makefile.qnx, use configure instead - added an INDEX file
- fixes for 64-bit systems (needed for Alpha and Cray) - new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
- always return Z_BUF_ERROR when deflate() has nothing to do - several portability improvements
- deflateInit and inflateInit are now macros to allow version checking
- prefix all global functions and types with z_ with -DZ_PREFIX
- fix some very unlikely race conditions in multi-threaded environment
- several minor fixes for better portability
- free in reverse order of allocation to help memory manager
- use zlib-1.0/* instead of zlib/* inside the tar.gz
- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
-Wconversion -Wstrict-prototypes -Wmissing-prototypes"
- allow gzread on concatenated .gz files
- deflateEnd now returns Z_DATA_ERROR if it was premature
- deflate is finally (?) fully deterministic
Notes for some targets: Notes for some targets:
@@ -47,8 +37,8 @@ Notes for some targets:
avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
- For 64-bit Iris, deflate.c must be compiled without any optimization. - For 64-bit Iris, deflate.c must be compiled without any optimization.
With -O, one libpng test fails. The test works in 32 bit mode (with the With -O, one libpng test fails. The test works in 32 bit mode (with
-32 compiler flag). the -32 compiler flag).
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1
it works when compiled with cc. it works when compiled with cc.
@@ -60,6 +50,7 @@ A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk>
is in the CPAN (Comprehensive Perl Archive Network) sites, such as: is in the CPAN (Comprehensive Perl Archive Network) sites, such as:
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib* ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
Acknowledgments: Acknowledgments:
The deflate format used by zlib was defined by Phil Katz. The deflate The deflate format used by zlib was defined by Phil Katz. The deflate

View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp $ */ /* $Id: adler32.c,v 1.9 1996/01/30 21:59:09 me Exp $ */
#include "zlib.h" #include "zlib.h"
@@ -11,11 +11,11 @@
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf) {s1 += *buf++; s2 += s1;} #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf) DO1(buf); DO1(buf); #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf) DO2(buf); DO2(buf); #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf) DO4(buf); DO4(buf); #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf); DO8(buf); #define DO16(buf) DO8(buf,0); DO8(buf,8);
/* ========================================================================= */ /* ========================================================================= */
uLong adler32(adler, buf, len) uLong adler32(adler, buf, len)
@@ -34,10 +34,12 @@ uLong adler32(adler, buf, len)
len -= k; len -= k;
while (k >= 16) { while (k >= 16) {
DO16(buf); DO16(buf);
buf += 16;
k -= 16; k -= 16;
} }
if (k != 0) do { if (k != 0) do {
DO1(buf); s1 += *buf++;
s2 += s1;
} while (--k); } while (--k);
s1 %= BASE; s1 %= BASE;
s2 %= BASE; s2 %= BASE;

View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: compress.c,v 1.6 1995/05/03 17:27:08 jloup Exp $ */ /* $Id: compress.c,v 1.9 1996/01/30 21:59:09 me Exp $ */
#include "zlib.h" #include "zlib.h"

29
configure vendored
View File

@@ -13,6 +13,7 @@
LIBS=libz.a LIBS=libz.a
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
AR=${AR-"ar rc"} AR=${AR-"ar rc"}
RANLIB=${RANLIB-"ranlib"}
prefix=${prefix-/usr/local} prefix=${prefix-/usr/local}
exec_prefix=${exec_prefix-$prefix} exec_prefix=${exec_prefix-$prefix}
@@ -36,25 +37,32 @@ else
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
CFLAGS=${CFLAGS-"-O2"} CFLAGS=${CFLAGS-"-O2"}
LDSHARED=${LDSHARED-"ld"};; LDSHARED=${LDSHARED-"ld"};;
IRIX*) SFLAGS=${CFLAGS-"-O2 -rpath ."} IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
CFLAGS=${CFLAGS-"-O2"} CFLAGS=${CFLAGS-"-ansi -O2"}
LDSHARED=${LDSHARED-"cc -shared"};; LDSHARED=${LDSHARED-"cc -shared"};;
QNX*) SFLAGS=${CFLAGS-"-4 -O -Q"} QNX*) SFLAGS=${CFLAGS-"-4 -O"}
CFLAGS=${CFLAGS-"-4 -O -Q"} CFLAGS=${CFLAGS-"-4 -O"}
LDSHARED=${LDSHARED-"cc"} LDSHARED=${LDSHARED-"cc"}
LIBS=zlib.lib RANLIB=${RANLIB-"true"}
AR="cc -A";; AR="cc -A";;
SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
CFLAGS=${CFLAGS-"-O3"}
LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"ld -b"}
SHAREDLIBS='libz.sl';;
# send working options for other systems to gzip@prep.ai.mit.edu # send working options for other systems to gzip@prep.ai.mit.edu
*) SFLAGS=${CFLAGS-"-O"} *) SFLAGS=${CFLAGS-"-O"}
CFLAGS=${CFLAGS-"-O"} CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"-shared"};; LDSHARED=${LDSHARED-"cc -shared"};;
esac esac
fi fi
echo Checking for shared library support... echo Checking for shared library support...
# we must test in two steps (cc then ld), required at least on SunOS 4.x # we must test in two steps (cc then ld), required at least on SunOS 4.x
if test "`$CC -c $SFLAGS $test.c 2>&1`" = "" && if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
test "`$LDSHARED -o $test.so $test.o 2>&1`" = ""; then test "`($LDSHARED -o $test.so $test.o) 2>&1`" = ""; then
CFLAGS="$SFLAGS" CFLAGS="$SFLAGS"
LIBS='libz.so.$(VER)' LIBS='libz.so.$(VER)'
echo Building shared library libz.so.$VER with $CC. echo Building shared library libz.so.$VER with $CC.
@@ -65,17 +73,14 @@ fi
rm -f $test.[co] $test.so rm -f $test.[co] $test.so
# udpate Makefile # udpate Makefile
# ed -s Makefile <<EOF
sed < Makefile.in " sed < Makefile.in "
/^CC *=/s/=.*/=$CC/ /^CC *=/s/=.*/=$CC/
/^CFLAGS *=/s/=.*/=$CFLAGS/ /^CFLAGS *=/s/=.*/=$CFLAGS/
/^LDSHARED *=/s/=.*/=$LDSHARED/ /^LDSHARED *=/s/=.*/=$LDSHARED/
/^LIBS *=/s,=.*,=$LIBS, /^LIBS *=/s,=.*,=$LIBS,
/^AR *=/s/=.*/=$AR/ /^AR *=/s/=.*/=$AR/
/^RANLIB *=/s,=.*,=$RANLIB,
/^VER *=/s/=.*/=$VER/ /^VER *=/s/=.*/=$VER/
/^prefix *=/s,=.*,=$prefix, /^prefix *=/s,=.*,=$prefix,
/^exec_prefix *=/s,=.*,=$exec_prefix, /^exec_prefix *=/s,=.*,=$exec_prefix,
" > Makefile " > Makefile
#w
#q
#EOF

View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: crc32.c,v 1.4 1995/04/14 14:55:12 jloup Exp $ */ /* $Id: crc32.c,v 1.8 1996/01/30 21:59:10 me Exp $ */
#include "zlib.h" #include "zlib.h"

View File

@@ -47,11 +47,11 @@
* *
*/ */
/* $Id: deflate.c,v 1.8 1995/05/03 17:27:08 jloup Exp $ */ /* $Id: deflate.c,v 1.12 1996/01/30 21:59:11 me Exp $ */
#include "deflate.h" #include "deflate.h"
char deflate_copyright[] = " deflate 1.0 Copyright 1995-1996 Jean-loup Gailly "; char deflate_copyright[] = " deflate 1.0.1 Copyright 1995-1996 Jean-loup Gailly ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@@ -67,7 +67,7 @@ local int deflate_stored OF((deflate_state *s, int flush));
local int deflate_fast OF((deflate_state *s, int flush)); local int deflate_fast OF((deflate_state *s, int flush));
local int deflate_slow OF((deflate_state *s, int flush)); local int deflate_slow OF((deflate_state *s, int flush));
local void lm_init OF((deflate_state *s)); local void lm_init OF((deflate_state *s));
local int longest_match OF((deflate_state *s, IPos cur_match)); local uInt longest_match OF((deflate_state *s, IPos cur_match));
local void putShortMSB OF((deflate_state *s, uInt b)); local void putShortMSB OF((deflate_state *s, uInt b));
local void flush_pending OF((z_stream *strm)); local void flush_pending OF((z_stream *strm));
local int read_buf OF((z_stream *strm, charf *buf, unsigned size)); local int read_buf OF((z_stream *strm, charf *buf, unsigned size));
@@ -157,7 +157,7 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
#define INSERT_STRING(s, str, match_head) \ #define INSERT_STRING(s, str, match_head) \
(UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
s->head[s->ins_h] = (str)) s->head[s->ins_h] = (Pos)(str))
/* =========================================================================== /* ===========================================================================
* Initialize the hash table (avoiding 64K overflow for 16 bit systems). * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
@@ -194,6 +194,11 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
deflate_state *s; deflate_state *s;
int noheader = 0; int noheader = 0;
ushf *overlay;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 24 bits.
*/
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != sizeof(z_stream)) { stream_size != sizeof(z_stream)) {
return Z_VERSION_ERROR; return Z_VERSION_ERROR;
@@ -239,7 +244,8 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush)); overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
s->pending_buf = (uchf *) overlay;
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) { s->pending_buf == Z_NULL) {
@@ -247,12 +253,8 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
deflateEnd (strm); deflateEnd (strm);
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
s->l_buf = (uchf *) &(s->pending_buf[s->lit_bufsize]); s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
s->d_buf = (ushf *) &(s->pending_buf[2*s->lit_bufsize]); s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 32 bits (worst case
* is 15+15+13=33). d_buf is put last in case sizeof(short)>2.
*/
s->level = level; s->level = level;
s->strategy = strategy; s->strategy = strategy;
@@ -270,7 +272,7 @@ int deflateSetDictionary (strm, dictionary, dictLength)
deflate_state *s; deflate_state *s;
uInt length = dictLength; uInt length = dictLength;
uInt n; uInt n;
IPos hash_head; IPos hash_head = 0;
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
strm->state->status != INIT_STATE) return Z_STREAM_ERROR; strm->state->status != INIT_STATE) return Z_STREAM_ERROR;
@@ -296,6 +298,7 @@ int deflateSetDictionary (strm, dictionary, dictLength)
for (n = 0; n <= length - MIN_MATCH; n++) { for (n = 0; n <= length - MIN_MATCH; n++) {
INSERT_STRING(s, n, hash_head); INSERT_STRING(s, n, hash_head);
} }
if (hash_head) hash_head = 0; /* to make compiler happy */
return Z_OK; return Z_OK;
} }
@@ -337,6 +340,7 @@ int deflateParams(strm, level, strategy)
{ {
deflate_state *s; deflate_state *s;
compress_func func; compress_func func;
int err = Z_OK;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
s = strm->state; s = strm->state;
@@ -349,11 +353,9 @@ int deflateParams(strm, level, strategy)
} }
func = configuration_table[s->level].func; func = configuration_table[s->level].func;
if (func != configuration_table[level].func if (func != configuration_table[level].func && strm->total_in != 0) {
&& strm->state->lookahead != 0) {
/* Flush the last buffer: */ /* Flush the last buffer: */
(void)(*func)(strm->state, Z_PARTIAL_FLUSH); err = deflate(strm, Z_PARTIAL_FLUSH);
} }
if (s->level != level) { if (s->level != level) {
s->level = level; s->level = level;
@@ -363,7 +365,7 @@ int deflateParams(strm, level, strategy)
s->max_chain_length = configuration_table[level].max_chain; s->max_chain_length = configuration_table[level].max_chain;
} }
s->strategy = strategy; s->strategy = strategy;
return Z_OK; return err;
} }
/* ========================================================================= /* =========================================================================
@@ -630,7 +632,7 @@ local void lm_init (s)
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or /* For 80x86 and 680x0, an optimized version will be provided in match.asm or
* match.S. The code will be functionally equivalent. * match.S. The code will be functionally equivalent.
*/ */
local int longest_match(s, cur_match) local uInt longest_match(s, cur_match)
deflate_state *s; deflate_state *s;
IPos cur_match; /* current match */ IPos cur_match; /* current match */
{ {
@@ -673,7 +675,7 @@ local int longest_match(s, cur_match)
/* Do not look for matches beyond the end of the input. This is necessary /* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic. * to make deflate deterministic.
*/ */
if (nice_match > s->lookahead) nice_match = s->lookahead; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
@@ -764,7 +766,7 @@ local int longest_match(s, cur_match)
} while ((cur_match = prev[cur_match & wmask]) > limit } while ((cur_match = prev[cur_match & wmask]) > limit
&& --chain_length != 0); && --chain_length != 0);
if (best_len <= s->lookahead) return best_len; if ((uInt)best_len <= s->lookahead) return best_len;
return s->lookahead; return s->lookahead;
} }
#endif /* ASMV */ #endif /* ASMV */
@@ -947,7 +949,7 @@ local int deflate_stored(s, flush)
s->lookahead = 0; s->lookahead = 0;
/* Stored blocks are limited to 0xffff bytes: */ /* Stored blocks are limited to 0xffff bytes: */
if (s->strstart == 0 || s->strstart > 0xffff) { if (s->strstart == 0 || s->strstart > 0xfffe) {
/* strstart == 0 is possible when wraparound on 16-bit machine */ /* strstart == 0 is possible when wraparound on 16-bit machine */
s->lookahead = s->strstart - 0xffff; s->lookahead = s->strstart - 0xffff;
s->strstart = 0xffff; s->strstart = 0xffff;

View File

@@ -8,7 +8,7 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
/* $Id: deflate.h,v 1.5 1995/05/03 17:27:09 jloup Exp $ */ /* $Id: deflate.h,v 1.9 1996/01/30 21:59:13 me Exp $ */
#ifndef _DEFLATE_H #ifndef _DEFLATE_H
#define _DEFLATE_H #define _DEFLATE_H

View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: example.c,v 1.9 1995/05/03 17:27:09 jloup Exp $ */ /* $Id: example.c,v 1.13 1996/01/30 21:59:13 me Exp $ */
#include <stdio.h> #include <stdio.h>
#include "zlib.h" #include "zlib.h"
@@ -30,30 +30,30 @@ const char hello[] = "hello, hello!";
const char dictionary[] = "hello"; const char dictionary[] = "hello";
uLong dictId; /* Adler32 value of the dictionary */ uLong dictId; /* Adler32 value of the dictionary */
void test_compress OF((Bytef *compr, uLong comprLen, void test_compress OF((Byte *compr, uLong comprLen,
Bytef *uncompr, uLong uncomprLen)); Byte *uncompr, uLong uncomprLen));
void test_gzio OF((const char *out, const char *in, void test_gzio OF((const char *out, const char *in,
Bytef *uncompr, int uncomprLen)); Byte *uncompr, int uncomprLen));
void test_deflate OF((Bytef *compr, uLong comprLen)); void test_deflate OF((Byte *compr, uLong comprLen));
void test_inflate OF((Bytef *compr, uLong comprLen, void test_inflate OF((Byte *compr, uLong comprLen,
Bytef *uncompr, uLong uncomprLen)); Byte *uncompr, uLong uncomprLen));
void test_large_deflate OF((Bytef *compr, uLong comprLen, void test_large_deflate OF((Byte *compr, uLong comprLen,
Bytef *uncompr, uLong uncomprLen)); Byte *uncompr, uLong uncomprLen));
void test_large_inflate OF((Bytef *compr, uLong comprLen, void test_large_inflate OF((Byte *compr, uLong comprLen,
Bytef *uncompr, uLong uncomprLen)); Byte *uncompr, uLong uncomprLen));
void test_flush OF((Bytef *compr, uLong comprLen)); void test_flush OF((Byte *compr, uLong comprLen));
void test_sync OF((Bytef *compr, uLong comprLen, void test_sync OF((Byte *compr, uLong comprLen,
Bytef *uncompr, uLong uncomprLen)); Byte *uncompr, uLong uncomprLen));
void test_dict_deflate OF((Bytef *compr, uLong comprLen)); void test_dict_deflate OF((Byte *compr, uLong comprLen));
void test_dict_inflate OF((Bytef *compr, uLong comprLen, void test_dict_inflate OF((Byte *compr, uLong comprLen,
Bytef *uncompr, uLong uncomprLen)); Byte *uncompr, uLong uncomprLen));
int main OF((int argc, char *argv[])); int main OF((int argc, char *argv[]));
/* =========================================================================== /* ===========================================================================
* Test compress() and uncompress() * Test compress() and uncompress()
*/ */
void test_compress(compr, comprLen, uncompr, uncomprLen) void test_compress(compr, comprLen, uncompr, uncomprLen)
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen, uncomprLen; uLong comprLen, uncomprLen;
{ {
int err; int err;
@@ -80,7 +80,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
void test_gzio(out, in, uncompr, uncomprLen) void test_gzio(out, in, uncompr, uncomprLen)
const char *out; /* output file */ const char *out; /* output file */
const char *in; /* input file */ const char *in; /* input file */
Bytef *uncompr; Byte *uncompr;
int uncomprLen; int uncomprLen;
{ {
int err; int err;
@@ -121,7 +121,7 @@ void test_gzio(out, in, uncompr, uncomprLen)
* Test deflate() with small buffers * Test deflate() with small buffers
*/ */
void test_deflate(compr, comprLen) void test_deflate(compr, comprLen)
Bytef *compr; Byte *compr;
uLong comprLen; uLong comprLen;
{ {
z_stream c_stream; /* compression stream */ z_stream c_stream; /* compression stream */
@@ -159,7 +159,7 @@ void test_deflate(compr, comprLen)
* Test inflate() with small buffers * Test inflate() with small buffers
*/ */
void test_inflate(compr, comprLen, uncompr, uncomprLen) void test_inflate(compr, comprLen, uncompr, uncomprLen)
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen, uncomprLen; uLong comprLen, uncomprLen;
{ {
int err; int err;
@@ -198,7 +198,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
* Test deflate() with large buffers and dynamic change of compression level * Test deflate() with large buffers and dynamic change of compression level
*/ */
void test_large_deflate(compr, comprLen, uncompr, uncomprLen) void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen, uncomprLen; uLong comprLen, uncomprLen;
{ {
z_stream c_stream; /* compression stream */ z_stream c_stream; /* compression stream */
@@ -251,7 +251,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
* Test inflate() with large buffers * Test inflate() with large buffers
*/ */
void test_large_inflate(compr, comprLen, uncompr, uncomprLen) void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen, uncomprLen; uLong comprLen, uncomprLen;
{ {
int err; int err;
@@ -291,7 +291,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
* Test deflate() with full flush * Test deflate() with full flush
*/ */
void test_flush(compr, comprLen) void test_flush(compr, comprLen)
Bytef *compr; Byte *compr;
uLong comprLen; uLong comprLen;
{ {
z_stream c_stream; /* compression stream */ z_stream c_stream; /* compression stream */
@@ -327,7 +327,7 @@ void test_flush(compr, comprLen)
* Test inflateSync() * Test inflateSync()
*/ */
void test_sync(compr, comprLen, uncompr, uncomprLen) void test_sync(compr, comprLen, uncompr, uncomprLen)
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen, uncomprLen; uLong comprLen, uncomprLen;
{ {
int err; int err;
@@ -369,7 +369,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
* Test deflate() with preset dictionary * Test deflate() with preset dictionary
*/ */
void test_dict_deflate(compr, comprLen) void test_dict_deflate(compr, comprLen)
Bytef *compr; Byte *compr;
uLong comprLen; uLong comprLen;
{ {
z_stream c_stream; /* compression stream */ z_stream c_stream; /* compression stream */
@@ -405,7 +405,7 @@ void test_dict_deflate(compr, comprLen)
* Test inflate() with a preset dictionary * Test inflate() with a preset dictionary
*/ */
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen, uncomprLen; uLong comprLen, uncomprLen;
{ {
int err; int err;
@@ -458,8 +458,8 @@ int main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
Bytef *compr, *uncompr; Byte *compr, *uncompr;
uLong comprLen = 32750*sizeof(int); /* don't overflow on MSDOS */ uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen; uLong uncomprLen = comprLen;
if (zlib_version[0] != ZLIB_VERSION[0]) { if (zlib_version[0] != ZLIB_VERSION[0]) {
@@ -470,8 +470,8 @@ int main(argc, argv)
fprintf(stderr, "warning: different zlib version\n"); fprintf(stderr, "warning: different zlib version\n");
} }
compr = (Bytef*)malloc((uInt)comprLen); compr = (Byte*)malloc((uInt)comprLen);
uncompr = (Bytef*)calloc((uInt)uncomprLen, 1); /* must be cleared */ uncompr = (Byte*)calloc((uInt)uncomprLen, 1); /* must be cleared */
if (compr == Z_NULL || uncompr == Z_NULL) { if (compr == Z_NULL || uncompr == Z_NULL) {
printf("out of memory\n"); printf("out of memory\n");
exit(1); exit(1);

20
gzio.c
View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: gzio.c,v 1.8 1995/05/03 17:27:09 jloup Exp $ */ /* $Id: gzio.c,v 1.12 1996/01/30 21:59:14 me Exp $ */
#include <stdio.h> #include <stdio.h>
@@ -203,8 +203,8 @@ local int get_byte(s)
local void check_header(s) local void check_header(s)
gz_stream *s; gz_stream *s;
{ {
int method = 0; int method; /* method byte */
int flags = 0; int flags; /* flags byte */
uInt len; uInt len;
int c; int c;
@@ -288,14 +288,15 @@ int gzread (file, buf, len)
unsigned len; unsigned len;
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
Byte *start = buf; /* starting point for crc computation */ Bytef *start = buf; /* starting point for crc computation */
Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
if (s->z_err == Z_STREAM_END) return 0; /* EOF */ if (s->z_err == Z_STREAM_END) return 0; /* EOF */
s->stream.next_out = buf; s->stream.next_out = next_out = buf;
s->stream.avail_out = len; s->stream.avail_out = len;
while (s->stream.avail_out != 0) { while (s->stream.avail_out != 0) {
@@ -306,14 +307,15 @@ int gzread (file, buf, len)
if (n > s->stream.avail_out) n = s->stream.avail_out; if (n > s->stream.avail_out) n = s->stream.avail_out;
if (n > 0) { if (n > 0) {
zmemcpy(s->stream.next_out, s->stream.next_in, n); zmemcpy(s->stream.next_out, s->stream.next_in, n);
s->stream.next_out += n; next_out += n;
s->stream.next_out = next_out;
s->stream.next_in += n; s->stream.next_in += n;
s->stream.avail_out -= n; s->stream.avail_out -= n;
s->stream.avail_in -= n; s->stream.avail_in -= n;
} }
if (s->stream.avail_out > 0) { if (s->stream.avail_out > 0) {
s->stream.avail_out -= fread(s->stream.next_out, s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
1, s->stream.avail_out, s->file); s->file);
} }
return (int)(len - s->stream.avail_out); return (int)(len - s->stream.avail_out);
} }
@@ -510,7 +512,7 @@ char* gzerror (file, errnum)
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
if (m == NULL || *m == '\0') m = (char*)z_errmsg[1-s->z_err]; if (m == NULL || *m == '\0') m = ERR_MSG(s->z_err);
TRYFREE(s->msg); TRYFREE(s->msg);
s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);

View File

@@ -110,6 +110,9 @@ uInt w;
} }
#ifdef DEBUG
extern uInt inflate_hufts;
#endif
int inflate_blocks(s, z, r) int inflate_blocks(s, z, r)
inflate_blocks_statef *s; inflate_blocks_statef *s;
z_stream *z; z_stream *z;
@@ -189,7 +192,7 @@ int r;
s->sub.left = (uInt)b & 0xffff; s->sub.left = (uInt)b & 0xffff;
b = k = 0; /* dump bits */ b = k = 0; /* dump bits */
Tracev((stderr, "inflate: stored length %u\n", s->sub.left)); Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
s->mode = s->sub.left ? STORED : TYPE; s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
break; break;
case STORED: case STORED:
if (n == 0) if (n == 0)
@@ -306,6 +309,9 @@ int r;
bl = 9; /* must be <= 9 for lookahead assumptions */ bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */ bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table; t = s->sub.trees.table;
#ifdef DEBUG
inflate_hufts = 0;
#endif
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
s->sub.trees.blens, &bl, &bd, &tl, &td, z); s->sub.trees.blens, &bl, &bd, &tl, &td, z);
if (t != Z_OK) if (t != Z_OK)
@@ -315,7 +321,8 @@ int r;
r = t; r = t;
LEAVE LEAVE
} }
Tracev((stderr, "inflate: trees ok\n")); Tracev((stderr, "inflate: trees ok, %d * %d bytes used\n",
inflate_hufts, sizeof(inflate_huft)));
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
{ {
inflate_trees_free(td, z); inflate_trees_free(td, z);
@@ -385,9 +392,8 @@ uLongf *c;
} }
void inflate_set_dictionary(s, z, d, n) void inflate_set_dictionary(s, d, n)
inflate_blocks_statef *s; inflate_blocks_statef *s;
z_stream *z;
const Bytef *d; const Bytef *d;
uInt n; uInt n;
{ {

View File

@@ -33,6 +33,5 @@ extern int inflate_blocks_free OF((
extern void inflate_set_dictionary OF(( extern void inflate_set_dictionary OF((
inflate_blocks_statef *s, inflate_blocks_statef *s,
z_stream *z,
const Bytef *d, /* dictionary */ const Bytef *d, /* dictionary */
uInt n)); /* dictionary length */ uInt n)); /* dictionary length */

View File

@@ -153,10 +153,10 @@ int inflate(z, f)
z_stream *z; z_stream *z;
int f; int f;
{ {
int r = f; /* to avoid warning about unused f */ int r;
uInt b; uInt b;
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL) if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL || f < 0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
r = Z_BUF_ERROR; r = Z_BUF_ERROR;
while (1) switch (z->state->mode) while (1) switch (z->state->mode)
@@ -283,12 +283,12 @@ uInt dictLength;
if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
z->adler = 1L; z->adler = 1L;
if (length >= (1<<z->state->wbits)) if (length >= ((uInt)1<<z->state->wbits))
{ {
length = (1<<z->state->wbits)-1; length = (1<<z->state->wbits)-1;
dictionary += dictLength - length; dictionary += dictLength - length;
} }
inflate_set_dictionary(z->state->blocks, z, dictionary, length); inflate_set_dictionary(z->state->blocks, dictionary, length);
z->state->mode = BLOCKS; z->state->mode = BLOCKS;
return Z_OK; return Z_OK;
} }

View File

@@ -6,7 +6,7 @@
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
char inflate_copyright[] = " inflate 1.0 Copyright 1995-1996 Mark Adler "; char inflate_copyright[] = " inflate 1.0.1 Copyright 1995-1996 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@@ -215,7 +215,8 @@ z_stream *zs; /* for zalloc function */
w += l; /* previous table always l bits */ w += l; /* previous table always l bits */
/* compute minimum size table less than or equal to l bits */ /* compute minimum size table less than or equal to l bits */
z = (z = g - w) > (uInt)l ? l : z; /* table size upper limit */ z = g - w;
z = z > (uInt)l ? l : z; /* table size upper limit */
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */ { /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */ f -= a + 1; /* deduct codes from patterns left */
@@ -268,7 +269,7 @@ z_stream *zs; /* for zalloc function */
} }
else else
{ {
r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */ r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
r.base = d[*p++ - s]; r.base = d[*p++ - s];
} }

View File

@@ -41,7 +41,8 @@ struct inflate_blocks_state {
inflate_huft *tb; /* bit length decoding tree */ inflate_huft *tb; /* bit length decoding tree */
} trees; /* if DTREE, decoding info for trees */ } trees; /* if DTREE, decoding info for trees */
struct { struct {
inflate_huft *tl, *td; /* trees to free */ inflate_huft *tl;
inflate_huft *td; /* trees to free */
inflate_codes_statef inflate_codes_statef
*codes; *codes;
} decode; /* if CODES, current state */ } decode; /* if CODES, current state */

View File

@@ -13,7 +13,7 @@
* or in pipe mode. * or in pipe mode.
*/ */
/* $Id: minigzip.c,v 1.5 1995/05/03 17:27:11 jloup Exp $ */ /* $Id: minigzip.c,v 1.8 1996/01/30 21:59:23 me Exp $ */
#include <stdio.h> #include <stdio.h>
#include "zlib.h" #include "zlib.h"
@@ -24,7 +24,7 @@
#else #else
extern void exit OF((int)); extern void exit OF((int));
#endif #endif
extern int unlink OF((const char *));
#if defined(MSDOS) || defined(OS2) || defined(WIN32) #if defined(MSDOS) || defined(OS2) || defined(WIN32)
# include <fcntl.h> # include <fcntl.h>
@@ -35,12 +35,15 @@ extern int unlink OF((const char *));
#endif #endif
#ifdef VMS #ifdef VMS
# define unlink delete
# define GZ_SUFFIX "-gz" # define GZ_SUFFIX "-gz"
#else #else
# define GZ_SUFFIX ".gz" # define GZ_SUFFIX ".gz"
#endif #endif
#define SUFFIX_LEN sizeof(GZ_SUFFIX) #define SUFFIX_LEN sizeof(GZ_SUFFIX)
extern int unlink OF((const char *));
#define BUFLEN 4096 #define BUFLEN 4096
#define MAX_NAME_LEN 1024 #define MAX_NAME_LEN 1024

View File

@@ -232,7 +232,7 @@ local void send_bits(s, value, length)
*/ */
local void tr_static_init() local void tr_static_init()
{ {
static static_init_done = 0; static int static_init_done = 0;
int n; /* iterates over tree elements */ int n; /* iterates over tree elements */
int bits; /* bit counter */ int bits; /* bit counter */
int length; /* length value */ int length; /* length value */

View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: uncompr.c,v 1.5 1995/05/03 17:27:12 jloup Exp $ */ /* $Id: uncompr.c,v 1.8 1996/01/30 21:59:26 me Exp $ */
#include "zlib.h" #include "zlib.h"

18
zconf.h
View File

@@ -9,8 +9,8 @@
#define _ZCONF_H #define _ZCONF_H
/* /*
* People prefering a unique prefix for all types and library functions * If you *really* need a unique prefix for all types and library functions,
* should compile with -DZ_PREFIX * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/ */
#ifdef Z_PREFIX #ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_ # define deflateInit_ z_deflateInit_
@@ -20,10 +20,12 @@
# define inflate z_inflate # define inflate z_inflate
# define inflateEnd z_inflateEnd # define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_ # define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy # define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset # define deflateReset z_deflateReset
# define deflateParams z_deflateParams # define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_ # define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync # define inflateSync z_inflateSync
# define inflateReset z_inflateReset # define inflateReset z_inflateReset
# define compress z_compress # define compress z_compress
@@ -35,7 +37,7 @@
# define Byte z_Byte # define Byte z_Byte
# define uInt z_uInt # define uInt z_uInt
# define uLong z_uLong # define uLong z_uLong
# define Bytef z_Bytef /* # define Bytef z_Bytef */
# define charf z_charf # define charf z_charf
# define intf z_intf # define intf z_intf
# define uIntf z_uIntf # define uIntf z_uIntf
@@ -72,13 +74,15 @@
# define STDC # define STDC
#endif #endif
#if !defined(STDC) && !defined(const) #ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const # define const
# endif # endif
#endif
#ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */ #ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
# include <unix.h> # include <unix.h>
# define Byte _Byte /* Byte already used on Mac */ # define NO_DUMMY_DECL /* buggy compiler merges all .h files incorrectly */
#endif #endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
@@ -142,6 +146,7 @@
/* The Watcom compiler defines M_I86SM and __SMALL__ even in 32 bit mode */ /* The Watcom compiler defines M_I86SM and __SMALL__ even in 32 bit mode */
#if defined(__WATCOMC__) && defined(__386__) #if defined(__WATCOMC__) && defined(__386__)
# undef FAR # undef FAR
# define FAR
# undef SMALL_MEDIUM # undef SMALL_MEDIUM
#endif #endif
@@ -149,7 +154,8 @@ typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */ typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */ typedef unsigned long uLong; /* 32 bits or more */
typedef Byte FAR Bytef; /* "typedef Byte FAR Bytef;" doesn't work with Borland C/C++ */
#define Bytef Byte FAR
typedef char FAR charf; typedef char FAR charf;
typedef int FAR intf; typedef int FAR intf;
typedef uInt FAR uIntf; typedef uInt FAR uIntf;

28
zlib.h
View File

@@ -1,5 +1,5 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.0, Jan 27th, 1996. version 1.0.1, May 20th, 1996.
Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
@@ -32,7 +32,7 @@ extern "C" {
#include "zconf.h" #include "zconf.h"
#define ZLIB_VERSION "1.0" #define ZLIB_VERSION "1.0.1"
/* /*
The 'zlib' compression library provides in-memory compression and The 'zlib' compression library provides in-memory compression and
@@ -207,7 +207,9 @@ extern int deflate OF((z_stream *strm, int flush));
more output, and updating avail_in or avail_out accordingly; avail_out more output, and updating avail_in or avail_out accordingly; avail_out
should never be zero before the call. The application can consume the should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of deflate(). (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
block is terminated and flushed to the output buffer so that the block is terminated and flushed to the output buffer so that the
@@ -294,15 +296,18 @@ extern int inflate OF((z_stream *strm, int flush));
will resume at this point for the next call of inflate(). will resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out - Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() always provides as much output as possible accordingly. inflate() provides as much output as possible, until there
(until there is no more input data or no more space in the output buffer). is no more input data or no more space in the output buffer (see below
about the flush parameter).
Before the call of inflate(), the application should ensure that at least Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly. more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for The application can consume the uncompressed output when it wants, for
example when the output buffer is full (avail_out == 0), or after each example when the output buffer is full (avail_out == 0), or after each
call of inflate(). call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
output as possible to the output buffer. The flushing behavior of inflate is output as possible to the output buffer. The flushing behavior of inflate is
@@ -484,8 +489,13 @@ extern int deflateParams OF((z_stream *strm, int level, int strategy));
available so far is compressed with the old level (and may be flushed); available so far is compressed with the old level (and may be flushed);
the new level will take effect only at the next call of deflate(). the new level will take effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid. stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/ */
/* /*
@@ -631,7 +641,7 @@ extern gzFile gzdopen OF((int fd, const char *mode));
gzdopen() associates a gzFile with the file descriptor fd. File gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen). fileno (in the file has been previously opened with fopen).
The mode parameter is as in fopen ("rb" or "wb"). The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
@@ -746,7 +756,7 @@ extern int inflateInit2_ OF((z_stream *strm, int windowBits,
#define inflateInit2(strm, windowBits) \ #define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#ifndef _Z_UTIL_H #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */ struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif #endif

View File

@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* $Id: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp $ */ /* $Id: zutil.c,v 1.12 1996/01/30 21:59:29 me Exp $ */
#include <stdio.h> #include <stdio.h>
@@ -178,7 +178,7 @@ voidpf zcalloc (opaque, items, size)
unsigned items; unsigned items;
unsigned size; unsigned size;
{ {
if (opaque) opaque = 0; /* to make compiler happy */ if (opaque) items += size - size; /* make compiler happy */
return (voidpf)calloc(items, size); return (voidpf)calloc(items, size);
} }
@@ -186,8 +186,8 @@ void zcfree (opaque, ptr)
voidpf opaque; voidpf opaque;
voidpf ptr; voidpf ptr;
{ {
if (opaque) opaque = 0; /* to make compiler happy */
free(ptr); free(ptr);
if (opaque) return; /* make compiler happy */
} }
#endif /* MY_ZCALLOC */ #endif /* MY_ZCALLOC */

View File

@@ -8,7 +8,7 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
/* $Id: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp $ */ /* $Id: zutil.h,v 1.13 1996/01/30 21:59:29 me Exp $ */
#ifndef _Z_UTIL_H #ifndef _Z_UTIL_H
#define _Z_UTIL_H #define _Z_UTIL_H
@@ -114,6 +114,10 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef TOPS20 #ifdef TOPS20
# define OS_CODE 0x0a # define OS_CODE 0x0a
#endif
#ifdef _BEOS_
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif #endif
/* Common defaults */ /* Common defaults */