summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:09:18 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:09:18 -0700
commit23c69f10698301ae97709eb0bbfb371d66b99a08 (patch)
tree1956b671b3df8d12c315a38f33b190677ccd659e
parent6b834a58bdef976383cff6e2a83f353e668a9cf1 (diff)
downloadzlib-23c69f10698301ae97709eb0bbfb371d66b99a08.tar.gz
zlib-23c69f10698301ae97709eb0bbfb371d66b99a08.tar.bz2
zlib-23c69f10698301ae97709eb0bbfb371d66b99a08.zip
zlib 0.94v0.94
-rw-r--r--ChangeLog17
-rw-r--r--Make_vms.com115
-rw-r--r--Makefile21
-rw-r--r--Makefile.bor9
-rw-r--r--Makefile.msc8
-rw-r--r--Makefile.qnx75
-rw-r--r--Makefile.tc17
-rw-r--r--README43
-rw-r--r--adler32.c6
-rw-r--r--compress.c6
-rw-r--r--crc32.c4
-rw-r--r--deflate.c187
-rw-r--r--deflate.h47
-rw-r--r--descrip.mms48
-rw-r--r--example.c24
-rw-r--r--gzio.c40
-rw-r--r--infblock.c32
-rw-r--r--infblock.h25
-rw-r--r--infcodes.c27
-rw-r--r--infcodes.h12
-rw-r--r--inffast.c10
-rw-r--r--inffast.h4
-rw-r--r--inflate.c6
-rw-r--r--inftrees.c69
-rw-r--r--inftrees.h38
-rw-r--r--infutil.c6
-rw-r--r--infutil.h19
-rw-r--r--minigzip.c36
-rw-r--r--trees.c62
-rw-r--r--uncompr.c6
-rw-r--r--zconf.h63
-rw-r--r--zlib.h102
-rw-r--r--zutil.c12
-rw-r--r--zutil.h35
34 files changed, 800 insertions, 431 deletions
diff --git a/ChangeLog b/ChangeLog
index fc70594..d6733c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
1
1 ChangeLog file for zlib 2 ChangeLog file for zlib
2 3
4Changes in 0.94 (13 Aug 95)
5- support MSDOS medium model
6- fix deflate with flush (could sometimes generate bad output)
7- fix deflateReset (zlib header was incorrectly suppressed)
8- added support for VMS
9- allow a compression level in gzopen()
10- gzflush now calls fflush
11- For deflate with flush, flush even if no more input is provided.
12- rename libgz.a as libz.a
13- work around a problem with gcc on Alpha (in INSERT_STRING)
14- don't use inline functions (problem with some gcc versions)
15- allow renaming of Byte, uInt, etc... with #define.
16- avoid warning about (unused) pointer before start of array in deflate.c
17- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
18- avoid reserved word 'new' in trees.c
19
3Changes in 0.93 (25 June 95) 20Changes in 0.93 (25 June 95)
4- temporarily disable inline functions 21- temporarily disable inline functions
5- make deflate deterministic 22- make deflate deterministic
diff --git a/Make_vms.com b/Make_vms.com
new file mode 100644
index 0000000..2d09f7d
--- /dev/null
+++ b/Make_vms.com
@@ -0,0 +1,115 @@
1$! make libz under VMS
2$! written by Martin P.J. Zinser <m.zinser@gsi.de>
3$!
4$! Look for the compiler used
5$!
6$ ccopt = ""
7$ if f$trnlnm("HW_MODEL").ge.1024
8$ then
9$ ccopt = "/prefix=all"+ccopt
10$ comp = "__decc__=1"
11$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
12$ else
13$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
14$ then
15$ comp = "__vaxc__=1"
16$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
17$ else
18$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
19$ ccopt = "/decc/prefix=all"+ccopt
20$ comp = "__decc__=1"
21$ endif
22$ endif
23$!
24$! Build the thing plain or with mms
25$!
26$ write sys$output "Compiling Zlib sources ..."
27$ if f$search("SYS$SYSTEM:MMS.EXE").eqs.""
28$ then
29$ dele example.obj;*,minigzip.obj;*
30$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" -
31 adler32.c zutil.h zlib.h zconf.h
32$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" -
33 compress.c zlib.h zconf.h
34$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
35 crc32.c zutil.h zlib.h zconf.h
36$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
37 deflatec.c deflate.h zutil.h zlib.h zconf.h
38$ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" -
39 gsio.c zutil.h zlib.h zconf.h
40$ CALL MAKE infblock.OBJ "CC ''CCOPT' infblock" -
41 infblock.c zutil.h zlib.h zconf.h infblock.h
42$ CALL MAKE infcodes.OBJ "CC ''CCOPT' infcodes" -
43 infcodes.c zutil.h zlib.h zconf.h inftrees.h
44$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
45 inffast.c zutil.h zlib.h zconf.h inffast.h
46$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" -
47 inflate.c zutil.h zlib.h zconf.h infblock.h
48$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" -
49 inftrees.c zutil.h zlib.h zconf.h inftrees.h
50$ CALL MAKE infutil.OBJ "CC ''CCOPT' infutil" -
51 infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h
52$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" -
53 trees.c deflate.h zutil.h zlib.h zconf.h
54$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" -
55 uncompr.c zlib.h zconf.h
56$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" -
57 zutil.c zutil.h zlib.h zconf.h
58$ write sys$output "Building Zlib ..."
59$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ
60$ write sys$output "Building example..."
61$ CALL MAKE example.OBJ "CC ''CCOPT' example" -
62 example.c zlib.h zconf.h
63$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb
64$ write sys$output "Building minigzip..."
65$ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" -
66 minigzip.c zlib.h zconf.h
67$ call make minigzip.exe -
68 "LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" -
69 minigzip.obj libz.olb
70$ else
71$ mms/macro=('comp')
72$ endif
73$ write sys$output "Zlib build completed"
74$ exit
75$!
76$!
77$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
78$ V = 'F$Verify(0)
79$! P1 = What we are trying to make
80$! P2 = Command to make it
81$! P3 - P8 What it depends on
82$
83$ If F$Search(P1) .Eqs. "" Then Goto Makeit
84$ Time = F$CvTime(F$File(P1,"RDT"))
85$arg=3
86$Loop:
87$ Argument = P'arg
88$ If Argument .Eqs. "" Then Goto Exit
89$ El=0
90$Loop2:
91$ File = F$Element(El," ",Argument)
92$ If File .Eqs. " " Then Goto Endl
93$ AFile = ""
94$Loop3:
95$ OFile = AFile
96$ AFile = F$Search(File)
97$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
98$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
99$ Goto Loop3
100$NextEL:
101$ El = El + 1
102$ Goto Loop2
103$EndL:
104$ arg=arg+1
105$ If arg .Le. 8 Then Goto Loop
106$ Goto Exit
107$
108$Makeit:
109$ VV=F$VERIFY(0)
110$ write sys$output P2
111$ 'P2
112$ VV='F$Verify(VV)
113$Exit:
114$ If V Then Set Verify
115$ENDSUBROUTINE
diff --git a/Makefile b/Makefile
index 2d0cdc7..d9e11c5 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ CFLAGS=-O
7#use -O3 for gcc to take advantage of inlining 7#use -O3 for gcc to take advantage of inlining
8#CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 8#CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
9#CFLAGS=-g -DDEBUG 9#CFLAGS=-g -DDEBUG
10LDFLAGS=-L. -lgz 10LDFLAGS=-L. -lz
11 11
12RANLIB=ranlib 12RANLIB=ranlib
13 13
@@ -24,33 +24,34 @@ test: all
24 ./example 24 ./example
25 echo hello world | ./minigzip | ./minigzip -d 25 echo hello world | ./minigzip | ./minigzip -d
26 26
27install: libgz.a 27install: libz.a
28 -@mkdir $(prefix)/include 28 -@mkdir $(prefix)/include
29 -@mkdir $(prefix)/lib 29 -@mkdir $(prefix)/lib
30 cp zlib.h zconf.h $(prefix)/include 30 cp zlib.h zconf.h $(prefix)/include
31 chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h 31 chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h
32 cp libgz.a $(prefix)/lib 32 cp libz.a $(prefix)/lib
33 chmod 644 $(prefix)/lib/libgz.a 33 chmod 644 $(prefix)/lib/libz.a
34 34
35libgz.a: $(OBJS) 35libz.a: $(OBJS)
36 ar rc $@ $(OBJS) 36 ar rc $@ $(OBJS)
37 $(RANLIB) $@ 37 $(RANLIB) $@
38 38
39example: example.o libgz.a 39example: example.o libz.a
40 $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) 40 $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
41 41
42minigzip: minigzip.o libgz.a 42minigzip: minigzip.o libz.a
43 $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) 43 $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
44 44
45clean: 45clean:
46 rm -f *.o example minigzip libgz.a foo.gz 46 rm -f *.o example minigzip libz.a foo.gz
47 47
48zip: 48zip:
49 zip -ul9 zlib README ChangeLog Makefile Makefile.??? Makefile.?? *.[ch] 49 zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \
50 descrip.mms *.[ch]
50 51
51tgz: 52tgz:
52 cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ 53 cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \
53 zlib/Makefile.??? zlib/Makefile.?? zlib/*.[ch] 54 zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch]
54 55
55# DO NOT DELETE THIS LINE -- make depend depends on it. 56# DO NOT DELETE THIS LINE -- make depend depends on it.
56 57
diff --git a/Makefile.bor b/Makefile.bor
index 732ea5d..3a823d0 100644
--- a/Makefile.bor
+++ b/Makefile.bor
@@ -4,9 +4,11 @@
4# To use, do "make -fmakefile.bor" 4# To use, do "make -fmakefile.bor"
5 5
6# WARNING: the small model is supported but only for small values of 6# WARNING: the small model is supported but only for small values of
7# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory 7# MAX_WBITS and MAX_MEM_LEVEL. For example:
8# requirements (default 256K for big objects plus a few K), you can add 8# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3
9# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 9# If you wish to reduce the memory requirements (default 256K for big
10# objects plus a few K), you can add to CFLAGS below:
11# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
10# See zconf.h for details about the memory requirements. 12# See zconf.h for details about the memory requirements.
11 13
12# ------------- Turbo C++, Borland C++ ------------- 14# ------------- Turbo C++, Borland C++ -------------
@@ -83,6 +85,7 @@ minigzip.obj: minigzip.c zlib.h zconf.h
83 85
84# we must cut the command line to fit in the MS/DOS 128 byte limit: 86# we must cut the command line to fit in the MS/DOS 128 byte limit:
85zlib.lib: $(OBJ1) $(OBJ2) 87zlib.lib: $(OBJ1) $(OBJ2)
88 del zlib.lib
86 $(LIB) zlib +$(OBJP1) 89 $(LIB) zlib +$(OBJP1)
87 $(LIB) zlib +$(OBJP2) 90 $(LIB) zlib +$(OBJP2)
88 91
diff --git a/Makefile.msc b/Makefile.msc
index d6899d8..335a4e1 100644
--- a/Makefile.msc
+++ b/Makefile.msc
@@ -3,10 +3,9 @@
3 3
4# To use, do "make makefile.msc" 4# To use, do "make makefile.msc"
5 5
6# WARNING: the small model is supported but only for small values of 6# If you wish to reduce the memory requirements (default 256K for big
7# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory 7# objects plus a few K), you can add to CFLAGS below:
8# requirements (default 256K for big objects plus a few K), you can add 8# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
9# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
10# See zconf.h for details about the memory requirements. 9# See zconf.h for details about the memory requirements.
11 10
12# ------------- Microsoft C 5.1 and later ------------- 11# ------------- Microsoft C 5.1 and later -------------
@@ -80,6 +79,7 @@ minigzip.obj: minigzip.c zlib.h zconf.h
80 79
81# we must cut the command line to fit in the MS/DOS 128 byte limit: 80# we must cut the command line to fit in the MS/DOS 128 byte limit:
82zlib.lib: $(OBJ1) $(OBJ2) 81zlib.lib: $(OBJ1) $(OBJ2)
82 del zlib.lib
83 lib zlib $(OBJ1); 83 lib zlib $(OBJ1);
84 lib zlib $(OBJ2); 84 lib zlib $(OBJ2);
85 85
diff --git a/Makefile.qnx b/Makefile.qnx
new file mode 100644
index 0000000..22b1a23
--- /dev/null
+++ b/Makefile.qnx
@@ -0,0 +1,75 @@
1# Makefile for zlib
2# Copyright (C) 1995 Jean-loup Gailly.
3# For conditions of distribution and use, see copyright notice in zlib.h
4
5# Modified slightly for QNX by Chris Herborth (chrish@qnx.com)
6
7CC=cc
8CFLAGS=-4 -O -Q
9#use -O3 for gcc to take advantage of inlining
10#CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
11#CFLAGS=-g -DDEBUG
12LDFLAGS=-L. -lz
13
14#RANLIB=ranlib
15
16prefix=/usr/local
17
18OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
19 zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
20
21TEST_OBJS = example.o minigzip.o
22
23all: example minigzip
24
25test: all
26 ./example
27 echo hello world | ./minigzip | ./minigzip -d
28
29install: zlib.lib
30 -@mkdir $(prefix)/include
31 -@mkdir $(prefix)/lib
32 cp zlib.h zconf.h $(prefix)/include
33 chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h
34 cp zlib.lib $(prefix)/lib
35 chmod 644 $(prefix)/lib/zlib.lib
36
37zlib.lib: $(OBJS)
38 cc -A $@ $(OBJS)
39# ar rc $@ $(OBJS)
40# $(RANLIB) $@
41
42example: example.o zlib.lib
43 $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
44
45minigzip: minigzip.o zlib.lib
46 $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
47
48clean:
49 rm -f *.o example minigzip zlib.lib foo.gz
50
51zip:
52 zip -ul9 zlib README ChangeLog Makefile Makefile.??? Makefile.?? *.[ch]
53
54tgz:
55 cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \
56 zlib/Makefile.??? zlib/Makefile.?? zlib/*.[ch]
57
58# DO NOT DELETE THIS LINE -- make depend depends on it.
59
60adler32.o: zutil.h zlib.h zconf.h
61compress.o: zlib.h zconf.h
62crc32.o: zutil.h zlib.h zconf.h
63deflate.o: deflate.h zutil.h zlib.h zconf.h
64example.o: zlib.h zconf.h
65gzio.o: zutil.h zlib.h zconf.h
66infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
67infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
68inffast.o: zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
69inflate.o: zutil.h zlib.h zconf.h infblock.h
70inftrees.o: zutil.h zlib.h zconf.h inftrees.h
71infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h
72minigzip.o: zlib.h zconf.h
73trees.o: deflate.h zutil.h zlib.h zconf.h
74uncompr.o: zlib.h zconf.h
75zutil.o: zutil.h zlib.h zconf.h
diff --git a/Makefile.tc b/Makefile.tc
index e173a55..ceed87d 100644
--- a/Makefile.tc
+++ b/Makefile.tc
@@ -4,18 +4,20 @@
4# To use, do "make -fmakefile.tc" 4# To use, do "make -fmakefile.tc"
5 5
6# WARNING: the small model is supported but only for small values of 6# WARNING: the small model is supported but only for small values of
7# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory 7# MAX_WBITS and MAX_MEM_LEVEL. For example:
8# requirements (default 256K for big objects plus a few K), you can add 8# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3
9# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 9# If you wish to reduce the memory requirements (default 256K for big
10# objects plus a few K), you can add to CFLAGS below:
11# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
10# See zconf.h for details about the memory requirements. 12# See zconf.h for details about the memory requirements.
11 13
12# ------------- Turbo C 2.0 ------------- 14# ------------- Turbo C 2.0 -------------
13MODEL=-ml 15MODEL=-ml
14CFLAGS=-O2 -Z $(MODEL) 16CFLAGS=-O2 -G -Z $(MODEL)
15CC=tcc 17CC=tcc -I\tc\include
16LD=tcc 18LD=tcc -L\tc\lib
17LIB=tlib 19LIB=tlib
18LDFLAGS=$(MODEL) 20LDFLAGS=$(MODEL) -f-
19O=.obj 21O=.obj
20 22
21# variables 23# variables
@@ -82,6 +84,7 @@ minigzip.obj: minigzip.c zlib.h zconf.h
82 84
83# we must cut the command line to fit in the MS/DOS 128 byte limit: 85# we must cut the command line to fit in the MS/DOS 128 byte limit:
84zlib.lib: $(OBJ1) $(OBJ2) 86zlib.lib: $(OBJ1) $(OBJ2)
87 del zlib.lib
85 $(LIB) zlib +$(OBJP1) 88 $(LIB) zlib +$(OBJP1)
86 $(LIB) zlib +$(OBJP2) 89 $(LIB) zlib +$(OBJP2)
87 90
diff --git a/README b/README
index e82b56f..1cbd6be 100644
--- a/README
+++ b/README
@@ -1,4 +1,6 @@
1zlib 0.93 is a beta version of a general purpose compression library. 1zlib 0.94 is a beta version of a general purpose compression library.
2Unless new bugs are found it will be released again as the first official
3version (1.0). This version has no known bugs.
2 4
3The data format used by the zlib library is described in the 5The data format used by the zlib library is described in the
4files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available 6files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available
@@ -10,31 +12,30 @@ which also tests that the library is working correctly.
10 12
11To compile all files and run the test program, just type: make test 13To compile all files and run the test program, just type: make test
12(For MSDOS, use one of the special makefiles such as Makefile.msc.) 14(For MSDOS, use one of the special makefiles such as Makefile.msc.)
13To install the zlib library (libgz.a) in /usr/local/lib, type: make install 15To install the zlib library (libz.a) in /usr/local/lib, type: make install
14To install in a different directory, use for example: make install prefix=$HOME 16To install in a different directory, use for example:
17 make install prefix=$HOME
15This will install in $HOME/lib instead of /usr/local/lib. 18This will install in $HOME/lib instead of /usr/local/lib.
16 19
17The changes made in version 0.93 are documented in the file ChangeLog. 20The changes made in version 0.94 are documented in the file ChangeLog.
18The main changes since 0.9 are: 21The main changes since 0.93 are:
19- temporarily disable inline functions 22- support MSDOS small and medium model
20- make deflate deterministic 23- fix deflate with flush (could sometimes generate bad output)
21- don't use signed char in inflate (not portable enough) 24- fix deflateReset (zlib header was incorrectly suppressed)
22- fix inflate memory leak for segmented architectures 25- added support for VMS
23- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h 26- allow a compression level in gzopen()
24- Document the memory requirements in zconf.h 27- gzflush now calls fflush
25- added "make install" 28- For deflate with flush, flush even if no more input is provided.
26- added support for DJGPP and Pyramid 29- rename libgz.a as libz.a
27- fix an inflate bug for stored blocks.
28- various speedups
29 30
30On MSDOS, this version works in both large and small model. However 31For MSDOS, the small and medium models are supported only for Microsoft C.
31small model compression works only for small values of MAX_MEM_LEVEL 32(It should be easy to support them for Borland C also, but I don't have
32and MAX_WBITS (see zconf.h). Small model decompression should work up 33a recent Borland compiler to test with.) The small model currently works
33to MAX_WBITS=15. This version of zlib does not support small or 34for Turbo/Borland C but only with reduced performance to avoid any far
34medium model with far allocation of big objects. 35allocation (tested with -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3).
35 36
36 37
37 Copyright (C) 1995 Jean-loup Gailly and Mark Adler 38 (C) 1995 Jean-loup Gailly and Mark Adler
38 39
39 This software is provided 'as-is', without any express or implied 40 This software is provided 'as-is', without any express or implied
40 warranty. In no event will the authors be held liable for any damages 41 warranty. In no event will the authors be held liable for any damages
diff --git a/adler32.c b/adler32.c
index 0ad9bec..7e2e3f5 100644
--- a/adler32.c
+++ b/adler32.c
@@ -5,9 +5,9 @@
5 5
6/* $Id: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp $ */ 6/* $Id: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp $ */
7 7
8#include "zutil.h" 8#include "zlib.h"
9 9
10#define BASE 65521 /* largest prime smaller than 65536 */ 10#define BASE 65521L /* largest prime smaller than 65536 */
11#define NMAX 5552 11#define NMAX 5552
12/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 12/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
13 13
@@ -20,7 +20,7 @@
20/* ========================================================================= */ 20/* ========================================================================= */
21uLong adler32(adler, buf, len) 21uLong adler32(adler, buf, len)
22 uLong adler; 22 uLong adler;
23 Byte *buf; 23 Bytef *buf;
24 uInt len; 24 uInt len;
25{ 25{
26 unsigned long s1 = adler & 0xffff; 26 unsigned long s1 = adler & 0xffff;
diff --git a/compress.c b/compress.c
index 98ced3e..a541af4 100644
--- a/compress.c
+++ b/compress.c
@@ -20,9 +20,9 @@
20 buffer. 20 buffer.
21*/ 21*/
22int compress (dest, destLen, source, sourceLen) 22int compress (dest, destLen, source, sourceLen)
23 Byte *dest; 23 Bytef *dest;
24 uLong *destLen; 24 uLongf *destLen;
25 Byte *source; 25 Bytef *source;
26 uLong sourceLen; 26 uLong sourceLen;
27{ 27{
28 z_stream stream; 28 z_stream stream;
diff --git a/crc32.c b/crc32.c
index 92bc3f0..4089255 100644
--- a/crc32.c
+++ b/crc32.c
@@ -3,7 +3,7 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* $Id: crc32.c,v 1.5 1995/05/01 13:55:46 jloup Exp $ */ 6/* $Id: crc32.c,v 1.4 1995/04/14 14:55:12 jloup Exp $ */
7 7
8#include "zlib.h" 8#include "zlib.h"
9 9
@@ -99,7 +99,7 @@ local uLong crc_table[] = {
99/* ========================================================================= */ 99/* ========================================================================= */
100uLong crc32(crc, buf, len) 100uLong crc32(crc, buf, len)
101 uLong crc; 101 uLong crc;
102 Byte *buf; 102 Bytef *buf;
103 uInt len; 103 uInt len;
104{ 104{
105 if (buf == Z_NULL) return 0L; 105 if (buf == Z_NULL) return 0L;
diff --git a/deflate.c b/deflate.c
index 726da18..70095e6 100644
--- a/deflate.c
+++ b/deflate.c
@@ -113,21 +113,21 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
113 * Prototypes for local functions. 113 * Prototypes for local functions.
114 */ 114 */
115 115
116local void fill_window __P((deflate_state *s)); 116local void fill_window OF((deflate_state *s));
117local int deflate_fast __P((deflate_state *s, int flush)); 117local int deflate_fast OF((deflate_state *s, int flush));
118local int deflate_slow __P((deflate_state *s, int flush)); 118local int deflate_slow OF((deflate_state *s, int flush));
119local void lm_init __P((deflate_state *s)); 119local void lm_init OF((deflate_state *s));
120local inline int longest_match __P((deflate_state *s, IPos cur_match)); 120local int longest_match OF((deflate_state *s, IPos cur_match));
121local void putShortMSB __P((deflate_state *s, uInt b)); 121local void putShortMSB OF((deflate_state *s, uInt b));
122local void flush_pending __P((z_stream *strm)); 122local void flush_pending OF((z_stream *strm));
123local int read_buf __P((z_stream *strm, char *buf, unsigned size)); 123local int read_buf OF((z_stream *strm, charf *buf, unsigned size));
124#ifdef ASMV 124#ifdef ASMV
125 void match_init __P((void)); /* asm code initialization */ 125 void match_init OF((void)); /* asm code initialization */
126#endif 126#endif
127 127
128#ifdef DEBUG 128#ifdef DEBUG
129local void check_match __P((deflate_state *s, IPos start, IPos match, 129local void check_match OF((deflate_state *s, IPos start, IPos match,
130 int length)); 130 int length));
131#endif 131#endif
132 132
133 133
@@ -139,6 +139,7 @@ local void check_match __P((deflate_state *s, IPos start, IPos match,
139 */ 139 */
140#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) 140#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
141 141
142
142/* =========================================================================== 143/* ===========================================================================
143 * Insert string str in the dictionary and set match_head to the previous head 144 * Insert string str in the dictionary and set match_head to the previous head
144 * of the hash chain (the most recent string with same hash key). Return 145 * of the hash chain (the most recent string with same hash key). Return
@@ -148,7 +149,7 @@ local void check_match __P((deflate_state *s, IPos start, IPos match,
148 * (except for the last MIN_MATCH-1 bytes of the input file). 149 * (except for the last MIN_MATCH-1 bytes of the input file).
149 */ 150 */
150#define INSERT_STRING(s, str, match_head) \ 151#define INSERT_STRING(s, str, match_head) \
151 (UPDATE_HASH(s, s->ins_h, s->window[(str) + MIN_MATCH-1]), \ 152 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
152 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ 153 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
153 s->head[s->ins_h] = (str)) 154 s->head[s->ins_h] = (str))
154 155
@@ -158,7 +159,7 @@ local void check_match __P((deflate_state *s, IPos start, IPos match,
158 */ 159 */
159#define CLEAR_HASH(s) \ 160#define CLEAR_HASH(s) \
160 s->head[s->hash_size-1] = NIL; \ 161 s->head[s->hash_size-1] = NIL; \
161 zmemzero((char*)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); 162 zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
162 163
163/* ========================================================================= */ 164/* ========================================================================= */
164int deflateInit (strm, level) 165int deflateInit (strm, level)
@@ -199,7 +200,7 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, strategy)
199 } 200 }
200 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); 201 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
201 if (s == Z_NULL) return Z_MEM_ERROR; 202 if (s == Z_NULL) return Z_MEM_ERROR;
202 strm->state = (struct internal_state *)s; 203 strm->state = (struct internal_state FAR *)s;
203 s->strm = strm; 204 s->strm = strm;
204 205
205 s->noheader = noheader; 206 s->noheader = noheader;
@@ -212,13 +213,13 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, strategy)
212 s->hash_mask = s->hash_size - 1; 213 s->hash_mask = s->hash_size - 1;
213 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); 214 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
214 215
215 s->window = (Byte*) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 216 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
216 s->prev = (Pos*) ZALLOC(strm, s->w_size, sizeof(Pos)); 217 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
217 s->head = (Pos*) ZALLOC(strm, s->hash_size, sizeof(Pos)); 218 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
218 219
219 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 220 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
220 221
221 s->pending_buf = (uch*) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush)); 222 s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush));
222 223
223 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 224 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
224 s->pending_buf == Z_NULL) { 225 s->pending_buf == Z_NULL) {
@@ -226,8 +227,8 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, strategy)
226 deflateEnd (strm); 227 deflateEnd (strm);
227 return Z_MEM_ERROR; 228 return Z_MEM_ERROR;
228 } 229 }
229 s->d_buf = (ush*) &(s->pending_buf[s->lit_bufsize]); 230 s->d_buf = (ushf *) &(s->pending_buf[s->lit_bufsize]);
230 s->l_buf = (uch*) &(s->pending_buf[3*s->lit_bufsize]); 231 s->l_buf = (uchf *) &(s->pending_buf[3*s->lit_bufsize]);
231 /* We overlay pending_buf and d_buf+l_buf. This works since the average 232 /* We overlay pending_buf and d_buf+l_buf. This works since the average
232 * output size for (length,distance) codes is <= 32 bits (worst case 233 * output size for (length,distance) codes is <= 32 bits (worst case
233 * is 15+15+13=33). 234 * is 15+15+13=33).
@@ -257,6 +258,9 @@ int deflateReset (strm)
257 s->pending = 0; 258 s->pending = 0;
258 s->pending_out = s->pending_buf; 259 s->pending_out = s->pending_buf;
259 260
261 if (s->noheader < 0) {
262 s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
263 }
260 s->status = s->noheader ? BUSY_STATE : INIT_STATE; 264 s->status = s->noheader ? BUSY_STATE : INIT_STATE;
261 s->adler = 1; 265 s->adler = 1;
262 266
@@ -267,9 +271,9 @@ int deflateReset (strm)
267} 271}
268 272
269/* ========================================================================= 273/* =========================================================================
270 * Put a short the pending_out buffer. The 16-bit value is put in MSB order. 274 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
271 * IN assertion: the stream state is correct and there is enough room in 275 * IN assertion: the stream state is correct and there is enough room in
272 * the pending_out buffer. 276 * pending_buf.
273 */ 277 */
274local void putShortMSB (s, b) 278local void putShortMSB (s, b)
275 deflate_state *s; 279 deflate_state *s;
@@ -308,7 +312,8 @@ int deflate (strm, flush)
308{ 312{
309 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 313 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
310 314
311 if (strm->next_out == Z_NULL || strm->next_in == Z_NULL) { 315 if (strm->next_out == Z_NULL ||
316 (strm->next_in == Z_NULL && strm->avail_in != 0)) {
312 ERR_RETURN(strm, Z_STREAM_ERROR); 317 ERR_RETURN(strm, Z_STREAM_ERROR);
313 } 318 }
314 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); 319 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
@@ -342,10 +347,10 @@ int deflate (strm, flush)
342 347
343 /* Start a new block or continue the current one. 348 /* Start a new block or continue the current one.
344 */ 349 */
345 if (strm->avail_in != 0 || 350 if (strm->avail_in != 0 || strm->state->lookahead != 0 ||
346 (flush == Z_FINISH && strm->state->status != FINISH_STATE)) { 351 (flush != Z_NO_FLUSH && strm->state->status != FINISH_STATE)) {
347 int quit; 352 int quit;
348 353
349 if (flush == Z_FINISH) { 354 if (flush == Z_FINISH) {
350 strm->state->status = FINISH_STATE; 355 strm->state->status = FINISH_STATE;
351 } 356 }
@@ -354,17 +359,29 @@ int deflate (strm, flush)
354 } else { 359 } else {
355 quit = deflate_slow(strm->state, flush); 360 quit = deflate_slow(strm->state, flush);
356 } 361 }
357 if (flush == Z_FULL_FLUSH || flush == Z_SYNC_FLUSH) { 362 if (quit || strm->avail_out == 0) return Z_OK;
358 ct_stored_block(strm->state, (char*)0, 0L, 0); /* special marker */ 363 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
359 flush_pending(strm); 364 * of deflate should use the same flush parameter to make sure
360 if (flush == Z_FULL_FLUSH) { 365 * that the flush is complete. So we don't have to output an
361 CLEAR_HASH(strm->state); /* forget history */ 366 * empty block here, this will be done at next call. This also
362 } 367 * ensures that for a very small output buffer, we emit at most
363 } else if (flush == Z_PARTIAL_FLUSH) { 368 * one empty block.
364 ct_align(strm->state); 369 */
370 if (flush != Z_OK && flush != Z_FINISH) {
371 if (flush == Z_PARTIAL_FLUSH) {
372 ct_align(strm->state);
373 } else { /* FULL_FLUSH or SYNC_FLUSH */
374 ct_stored_block(strm->state, (char*)0, 0L, 0);
375 /* For a full flush, this empty block will be recognized
376 * as a special marker by inflate_sync().
377 */
378 if (flush == Z_FULL_FLUSH) {
379 CLEAR_HASH(strm->state); /* forget history */
380 }
381 }
365 flush_pending(strm); 382 flush_pending(strm);
383 if (strm->avail_out == 0) return Z_OK;
366 } 384 }
367 if (quit || strm->avail_out == 0) return Z_OK;
368 } 385 }
369 Assert(strm->avail_out > 0, "bug2"); 386 Assert(strm->avail_out > 0, "bug2");
370 387
@@ -378,7 +395,7 @@ int deflate (strm, flush)
378 /* If avail_out is zero, the application will call deflate again 395 /* If avail_out is zero, the application will call deflate again
379 * to flush the rest. 396 * to flush the rest.
380 */ 397 */
381 strm->state->noheader = 1; /* write the trailer only once! */ 398 strm->state->noheader = -1; /* write the trailer only once! */
382 return strm->state->pending != 0 ? Z_OK : Z_STREAM_END; 399 return strm->state->pending != 0 ? Z_OK : Z_STREAM_END;
383} 400}
384 401
@@ -410,7 +427,7 @@ int deflateCopy (dest, source)
410 *dest = *source; 427 *dest = *source;
411 return Z_STREAM_ERROR; /* to be implemented */ 428 return Z_STREAM_ERROR; /* to be implemented */
412#if 0 429#if 0
413 dest->state = (struct internal_state *) 430 dest->state = (struct internal_state FAR *)
414 (*dest->zalloc)(1, sizeof(deflate_state)); 431 (*dest->zalloc)(1, sizeof(deflate_state));
415 if (dest->state == Z_NULL) return Z_MEM_ERROR; 432 if (dest->state == Z_NULL) return Z_MEM_ERROR;
416 433
@@ -425,7 +442,7 @@ int deflateCopy (dest, source)
425 */ 442 */
426local int read_buf(strm, buf, size) 443local int read_buf(strm, buf, size)
427 z_stream *strm; 444 z_stream *strm;
428 char *buf; 445 charf *buf;
429 unsigned size; 446 unsigned size;
430{ 447{
431 unsigned len = strm->avail_in; 448 unsigned len = strm->avail_in;
@@ -485,13 +502,13 @@ local void lm_init (s)
485/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 502/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
486 * match.S. The code will be functionally equivalent. 503 * match.S. The code will be functionally equivalent.
487 */ 504 */
488local inline int longest_match(s, cur_match) 505local int longest_match(s, cur_match)
489 deflate_state *s; 506 deflate_state *s;
490 IPos cur_match; /* current match */ 507 IPos cur_match; /* current match */
491{ 508{
492 unsigned chain_length = s->max_chain_length;/* max hash chain length */ 509 unsigned chain_length = s->max_chain_length;/* max hash chain length */
493 register Byte *scan = s->window + s->strstart; /* current string */ 510 register Bytef *scan = s->window + s->strstart; /* current string */
494 register Byte *match; /* matched string */ 511 register Bytef *match; /* matched string */
495 register int len; /* length of current match */ 512 register int len; /* length of current match */
496 int best_len = s->prev_length; /* best match length so far */ 513 int best_len = s->prev_length; /* best match length so far */
497 IPos limit = s->strstart > (IPos)MAX_DIST(s) ? 514 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
@@ -499,18 +516,18 @@ local inline int longest_match(s, cur_match)
499 /* Stop when cur_match becomes <= limit. To simplify the code, 516 /* Stop when cur_match becomes <= limit. To simplify the code,
500 * we prevent matches with the string of window index 0. 517 * we prevent matches with the string of window index 0.
501 */ 518 */
502 Pos *prev = s->prev; 519 Posf *prev = s->prev;
503 uInt wmask = s->w_mask; 520 uInt wmask = s->w_mask;
504 521
505#ifdef UNALIGNED_OK 522#ifdef UNALIGNED_OK
506 /* Compare two bytes at a time. Note: this is not always beneficial. 523 /* Compare two bytes at a time. Note: this is not always beneficial.
507 * Try with and without -DUNALIGNED_OK to check. 524 * Try with and without -DUNALIGNED_OK to check.
508 */ 525 */
509 register Byte *strend = s->window + s->strstart + MAX_MATCH - 1; 526 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
510 register ush scan_start = *(ush*)scan; 527 register ush scan_start = *(ush*)scan;
511 register ush scan_end = *(ush*)(scan+best_len-1); 528 register ush scan_end = *(ush*)(scan+best_len-1);
512#else 529#else
513 register Byte *strend = s->window + s->strstart + MAX_MATCH; 530 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
514 register Byte scan_end1 = scan[best_len-1]; 531 register Byte scan_end1 = scan[best_len-1];
515 register Byte scan_end = scan[best_len]; 532 register Byte scan_end = scan[best_len];
516#endif 533#endif
@@ -524,7 +541,7 @@ local inline int longest_match(s, cur_match)
524 if (s->prev_length >= s->good_match) { 541 if (s->prev_length >= s->good_match) {
525 chain_length >>= 2; 542 chain_length >>= 2;
526 } 543 }
527 Assert(s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 544 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
528 545
529 do { 546 do {
530 Assert(cur_match < s->strstart, "no future"); 547 Assert(cur_match < s->strstart, "no future");
@@ -549,6 +566,7 @@ local inline int longest_match(s, cur_match)
549 * necessary to put more guard bytes at the end of the window, or 566 * necessary to put more guard bytes at the end of the window, or
550 * to check more often for insufficient lookahead. 567 * to check more often for insufficient lookahead.
551 */ 568 */
569 Assert(scan[2] == match[2], "scan[2]?");
552 scan++, match++; 570 scan++, match++;
553 do { 571 do {
554 } while (*(ush*)(scan+=2) == *(ush*)(match+=2) && 572 } while (*(ush*)(scan+=2) == *(ush*)(match+=2) &&
@@ -579,6 +597,7 @@ local inline int longest_match(s, cur_match)
579 * the hash keys are equal and that HASH_BITS >= 8. 597 * the hash keys are equal and that HASH_BITS >= 8.
580 */ 598 */
581 scan += 2, match++; 599 scan += 2, match++;
600 Assert(*scan == *match, "match[2]?");
582 601
583 /* We check for insufficient lookahead only every 8th comparison; 602 /* We check for insufficient lookahead only every 8th comparison;
584 * the 256th check will be made at strstart+258. 603 * the 256th check will be made at strstart+258.
@@ -625,11 +644,13 @@ local void check_match(s, start, match, length)
625 int length; 644 int length;
626{ 645{
627 /* check that the match is indeed a match */ 646 /* check that the match is indeed a match */
628 if (memcmp((char*)s->window + match, 647 if (memcmp((charf *)s->window + match,
629 (char*)s->window + start, length) != EQUAL) { 648 (charf *)s->window + start, length) != EQUAL) {
630 fprintf(stderr, 649 fprintf(stderr,
631 " start %d, match %d, length %d\n", 650 " start %u, match %u, length %d\n",
632 start, match, length); 651 start, match, length);
652 do { fprintf(stderr, "%c%c", s->window[match++],
653 s->window[start++]); } while (--length != 0);
633 z_error("invalid match"); 654 z_error("invalid match");
634 } 655 }
635 if (verbose > 1) { 656 if (verbose > 1) {
@@ -655,7 +676,7 @@ local void fill_window(s)
655 deflate_state *s; 676 deflate_state *s;
656{ 677{
657 register unsigned n, m; 678 register unsigned n, m;
658 register Pos *p; 679 register Posf *p;
659 unsigned more; /* Amount of free space at the end of the window. */ 680 unsigned more; /* Amount of free space at the end of the window. */
660 uInt wsize = s->w_size; 681 uInt wsize = s->w_size;
661 682
@@ -679,7 +700,7 @@ local void fill_window(s)
679 /* By the IN assertion, the window is not empty so we can't confuse 700 /* By the IN assertion, the window is not empty so we can't confuse
680 * more == 0 with more == 64K on a 16 bit machine. 701 * more == 0 with more == 64K on a 16 bit machine.
681 */ 702 */
682 zmemcpy((char*)s->window, (char*)s->window+wsize, 703 zmemcpy((charf *)s->window, (charf *)s->window+wsize,
683 (unsigned)wsize); 704 (unsigned)wsize);
684 s->match_start -= wsize; 705 s->match_start -= wsize;
685 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ 706 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
@@ -690,17 +711,17 @@ local void fill_window(s)
690 at the expense of memory usage): 711 at the expense of memory usage):
691 */ 712 */
692 n = s->hash_size; 713 n = s->hash_size;
693 p = &s->head[n-1]; 714 p = &s->head[n];
694 do { 715 do {
695 m = *p; 716 m = *--p;
696 *p-- = (Pos)(m >= wsize ? m-wsize : NIL); 717 *p = (Pos)(m >= wsize ? m-wsize : NIL);
697 } while (--n); 718 } while (--n);
698 719
699 n = wsize; 720 n = wsize;
700 p = &s->prev[n-1]; 721 p = &s->prev[n];
701 do { 722 do {
702 m = *p; 723 m = *--p;
703 *p-- = (Pos)(m >= wsize ? m-wsize : NIL); 724 *p = (Pos)(m >= wsize ? m-wsize : NIL);
704 /* If n is not on any hash chain, prev[n] is garbage but 725 /* If n is not on any hash chain, prev[n] is garbage but
705 * its value will never be used. 726 * its value will never be used.
706 */ 727 */
@@ -723,15 +744,17 @@ local void fill_window(s)
723 */ 744 */
724 Assert(more >= 2, "more < 2"); 745 Assert(more >= 2, "more < 2");
725 746
726 n = read_buf(s->strm, (char*)s->window + s->strstart + s->lookahead, 747 n = read_buf(s->strm, (charf *)s->window + s->strstart + s->lookahead,
727 more); 748 more);
728 s->lookahead += n; 749 s->lookahead += n;
729 750
730 /* Initialize the hash value now that we have some input: */ 751 /* Initialize the hash value now that we have some input: */
731 if (s->strstart == 0 && s->lookahead >= MIN_MATCH-1) { 752 if (s->lookahead >= MIN_MATCH) {
732 for (n=0; n<MIN_MATCH-1; n++) { 753 s->ins_h = s->window[s->strstart];
733 UPDATE_HASH(s, s->ins_h, s->window[n]); 754 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
734 } 755#if MIN_MATCH != 3
756 Call UPDATE_HASH() MIN_MATCH-3 more times
757#endif
735 } 758 }
736 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, 759 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
737 * but this is not important since only literal bytes will be emitted. 760 * but this is not important since only literal bytes will be emitted.
@@ -746,10 +769,11 @@ local void fill_window(s)
746 */ 769 */
747#define FLUSH_BLOCK_ONLY(s, eof) { \ 770#define FLUSH_BLOCK_ONLY(s, eof) { \
748 ct_flush_block(s, (s->block_start >= 0L ? \ 771 ct_flush_block(s, (s->block_start >= 0L ? \
749 (char*)&s->window[(unsigned)s->block_start] : \ 772 (charf *)&s->window[(unsigned)s->block_start] : \
750 (char*)Z_NULL), (long)s->strstart - s->block_start, (eof)); \ 773 (charf *)Z_NULL), (long)s->strstart - s->block_start, (eof)); \
751 s->block_start = s->strstart; \ 774 s->block_start = s->strstart; \
752 flush_pending(s->strm); \ 775 flush_pending(s->strm); \
776 Tracev((stderr,"[FLUSH]")); \
753} 777}
754 778
755/* Same but force premature exit if necessary. */ 779/* Same but force premature exit if necessary. */
@@ -790,7 +814,9 @@ local int deflate_fast(s, flush)
790 /* Insert the string window[strstart .. strstart+2] in the 814 /* Insert the string window[strstart .. strstart+2] in the
791 * dictionary, and set hash_head to the head of the hash chain: 815 * dictionary, and set hash_head to the head of the hash chain:
792 */ 816 */
793 INSERT_STRING(s, s->strstart, hash_head); 817 if (s->lookahead >= MIN_MATCH) {
818 INSERT_STRING(s, s->strstart, hash_head);
819 }
794 820
795 /* Find the longest match, discarding those <= prev_length. 821 /* Find the longest match, discarding those <= prev_length.
796 * At this point we have always match_length < MIN_MATCH 822 * At this point we have always match_length < MIN_MATCH
@@ -818,15 +844,14 @@ local int deflate_fast(s, flush)
818 /* Insert new strings in the hash table only if the match length 844 /* Insert new strings in the hash table only if the match length
819 * is not too large. This saves time but degrades compression. 845 * is not too large. This saves time but degrades compression.
820 */ 846 */
821 if (s->match_length <= s->max_insert_length) { 847 if (s->match_length <= s->max_insert_length &&
848 s->lookahead >= MIN_MATCH) {
822 s->match_length--; /* string at strstart already in hash table */ 849 s->match_length--; /* string at strstart already in hash table */
823 do { 850 do {
824 s->strstart++; 851 s->strstart++;
825 INSERT_STRING(s, s->strstart, hash_head); 852 INSERT_STRING(s, s->strstart, hash_head);
826 /* strstart never exceeds WSIZE-MAX_MATCH, so there are 853 /* strstart never exceeds WSIZE-MAX_MATCH, so there are
827 * always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH 854 * always MIN_MATCH bytes ahead.
828 * these bytes are garbage, but it does not matter since
829 * the next lookahead bytes will be emitted as literals.
830 */ 855 */
831 } while (--s->match_length != 0); 856 } while (--s->match_length != 0);
832 s->strstart++; 857 s->strstart++;
@@ -838,6 +863,9 @@ local int deflate_fast(s, flush)
838#if MIN_MATCH != 3 863#if MIN_MATCH != 3
839 Call UPDATE_HASH() MIN_MATCH-3 more times 864 Call UPDATE_HASH() MIN_MATCH-3 more times
840#endif 865#endif
866 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
867 * matter since it will be recomputed at next deflate call.
868 */
841 } 869 }
842 } else { 870 } else {
843 /* No match, output a literal byte */ 871 /* No match, output a literal byte */
@@ -881,7 +909,9 @@ local int deflate_slow(s, flush)
881 /* Insert the string window[strstart .. strstart+2] in the 909 /* Insert the string window[strstart .. strstart+2] in the
882 * dictionary, and set hash_head to the head of the hash chain: 910 * dictionary, and set hash_head to the head of the hash chain:
883 */ 911 */
884 INSERT_STRING(s, s->strstart, hash_head); 912 if (s->lookahead >= MIN_MATCH) {
913 INSERT_STRING(s, s->strstart, hash_head);
914 }
885 915
886 /* Find the longest match, discarding those <= prev_length. 916 /* Find the longest match, discarding those <= prev_length.
887 */ 917 */
@@ -914,6 +944,8 @@ local int deflate_slow(s, flush)
914 * match is not better, output the previous match: 944 * match is not better, output the previous match:
915 */ 945 */
916 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 946 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
947 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
948 /* Do not insert strings in hash table beyond this. */
917 949
918 check_match(s, s->strstart-1, s->prev_match, s->prev_length); 950 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
919 951
@@ -921,18 +953,16 @@ local int deflate_slow(s, flush)
921 s->prev_length - MIN_MATCH); 953 s->prev_length - MIN_MATCH);
922 954
923 /* Insert in hash table all strings up to the end of the match. 955 /* Insert in hash table all strings up to the end of the match.
924 * strstart-1 and strstart are already inserted. 956 * strstart-1 and strstart are already inserted. If there is not
957 * enough lookahead, the last two strings are not inserted in
958 * the hash table.
925 */ 959 */
926 s->lookahead -= s->prev_length-1; 960 s->lookahead -= s->prev_length-1;
927 s->prev_length -= 2; 961 s->prev_length -= 2;
928 do { 962 do {
929 s->strstart++; 963 if (++s->strstart <= max_insert) {
930 INSERT_STRING(s, s->strstart, hash_head); 964 INSERT_STRING(s, s->strstart, hash_head);
931 /* strstart never exceeds WSIZE-MAX_MATCH, so there are 965 }
932 * always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH
933 * these bytes are garbage, but it does not matter since the
934 * next lookahead bytes will always be emitted as literals.
935 */
936 } while (--s->prev_length != 0); 966 } while (--s->prev_length != 0);
937 s->match_available = 0; 967 s->match_available = 0;
938 s->match_length = MIN_MATCH-1; 968 s->match_length = MIN_MATCH-1;
@@ -961,10 +991,13 @@ local int deflate_slow(s, flush)
961 s->lookahead--; 991 s->lookahead--;
962 } 992 }
963 } 993 }
994 Assert (flush != Z_NO_FLUSH, "no flush?");
964 if (s->match_available) { 995 if (s->match_available) {
996 Tracevv((stderr,"%c", s->window[s->strstart-1]));
965 ct_tally (s, 0, s->window[s->strstart-1]); 997 ct_tally (s, 0, s->window[s->strstart-1]);
966 s->match_available = 0; 998 s->match_available = 0;
967 } 999 }
968 FLUSH_BLOCK(s, flush == Z_FINISH); 1000 FLUSH_BLOCK(s, flush == Z_FINISH);
969 return 0; 1001 return 0;
970} 1002}
1003
diff --git a/deflate.h b/deflate.h
index fb6c233..eada3ba 100644
--- a/deflate.h
+++ b/deflate.h
@@ -58,7 +58,7 @@ typedef struct ct_data_s {
58 ush dad; /* father node in Huffman tree */ 58 ush dad; /* father node in Huffman tree */
59 ush len; /* length of bit string */ 59 ush len; /* length of bit string */
60 } dl; 60 } dl;
61} ct_data; 61} FAR ct_data;
62 62
63#define Freq fc.freq 63#define Freq fc.freq
64#define Code fc.code 64#define Code fc.code
@@ -71,10 +71,12 @@ typedef struct tree_desc_s {
71 ct_data *dyn_tree; /* the dynamic tree */ 71 ct_data *dyn_tree; /* the dynamic tree */
72 int max_code; /* largest code with non zero frequency */ 72 int max_code; /* largest code with non zero frequency */
73 static_tree_desc *stat_desc; /* the corresponding static tree */ 73 static_tree_desc *stat_desc; /* the corresponding static tree */
74} tree_desc; 74} FAR tree_desc;
75 75
76typedef ush Pos; 76typedef ush Pos;
77typedef Pos FAR Posf;
77typedef unsigned IPos; 78typedef unsigned IPos;
79
78/* A Pos is an index in the character window. We use short instead of int to 80/* A Pos is an index in the character window. We use short instead of int to
79 * save space in the various tables. IPos is used only for parameter passing. 81 * save space in the various tables. IPos is used only for parameter passing.
80 */ 82 */
@@ -82,8 +84,8 @@ typedef unsigned IPos;
82typedef struct internal_state { 84typedef struct internal_state {
83 z_stream *strm; /* pointer back to this zlib stream */ 85 z_stream *strm; /* pointer back to this zlib stream */
84 int status; /* as the name implies */ 86 int status; /* as the name implies */
85 Byte *pending_buf; /* output still pending */ 87 Bytef *pending_buf; /* output still pending */
86 Byte *pending_out; /* next pending byte to output to the stream */ 88 Bytef *pending_out; /* next pending byte to output to the stream */
87 int pending; /* nb of bytes in the pending buffer */ 89 int pending; /* nb of bytes in the pending buffer */
88 uLong adler; /* adler32 of uncompressed data */ 90 uLong adler; /* adler32 of uncompressed data */
89 int noheader; /* suppress zlib header and adler32 */ 91 int noheader; /* suppress zlib header and adler32 */
@@ -96,7 +98,7 @@ typedef struct internal_state {
96 uInt w_bits; /* log2(w_size) (8..16) */ 98 uInt w_bits; /* log2(w_size) (8..16) */
97 uInt w_mask; /* w_size - 1 */ 99 uInt w_mask; /* w_size - 1 */
98 100
99 Byte *window; 101 Bytef *window;
100 /* Sliding window. Input bytes are read into the second half of the window, 102 /* Sliding window. Input bytes are read into the second half of the window,
101 * and move to the first half later to keep a dictionary of at least wSize 103 * and move to the first half later to keep a dictionary of at least wSize
102 * bytes. With this organization, matches are limited to a distance of 104 * bytes. With this organization, matches are limited to a distance of
@@ -111,13 +113,13 @@ typedef struct internal_state {
111 * is directly used as sliding window. 113 * is directly used as sliding window.
112 */ 114 */
113 115
114 Pos *prev; 116 Posf *prev;
115 /* Link to older string with same hash index. To limit the size of this 117 /* Link to older string with same hash index. To limit the size of this
116 * array to 64K, this link is maintained only for the last 32K strings. 118 * array to 64K, this link is maintained only for the last 32K strings.
117 * An index in this array is thus a window index modulo 32K. 119 * An index in this array is thus a window index modulo 32K.
118 */ 120 */
119 121
120 Pos *head; /* Heads of the hash chains or NIL. */ 122 Posf *head; /* Heads of the hash chains or NIL. */
121 123
122 uInt ins_h; /* hash index of string to be inserted */ 124 uInt ins_h; /* hash index of string to be inserted */
123 uInt hash_size; /* number of elements in hash table */ 125 uInt hash_size; /* number of elements in hash table */
@@ -174,14 +176,14 @@ typedef struct internal_state {
174 int nice_match; /* Stop searching when current match exceeds this */ 176 int nice_match; /* Stop searching when current match exceeds this */
175 177
176 /* used by trees.c: */ 178 /* used by trees.c: */
179 /* Didn't use ct_data typedef below to supress compiler warning */
180 struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
181 struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
182 struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
177 183
178 ct_data dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 184 struct tree_desc_s l_desc; /* desc. for literal tree */
179 ct_data dyn_dtree[2*D_CODES+1]; /* distance tree */ 185 struct tree_desc_s d_desc; /* desc. for distance tree */
180 ct_data bl_tree[2*BL_CODES+1]; /* Huffman tree for the bit lengths */ 186 struct tree_desc_s bl_desc; /* desc. for bit length tree */
181
182 tree_desc l_desc; /* descriptor for literal tree */
183 tree_desc d_desc; /* descriptor for distance tree */
184 tree_desc bl_desc; /* descriptor for bit length tree */
185 187
186 ush bl_count[MAX_BITS+1]; 188 ush bl_count[MAX_BITS+1];
187 /* number of codes at each bit length for an optimal tree */ 189 /* number of codes at each bit length for an optimal tree */
@@ -197,7 +199,7 @@ typedef struct internal_state {
197 /* Depth of each subtree used as tie breaker for trees of equal frequency 199 /* Depth of each subtree used as tie breaker for trees of equal frequency
198 */ 200 */
199 201
200 uch *l_buf; /* buffer for literals or lengths */ 202 uchf *l_buf; /* buffer for literals or lengths */
201 203
202 uInt lit_bufsize; 204 uInt lit_bufsize;
203 /* Size of match buffer for literals/lengths. There are 4 reasons for 205 /* Size of match buffer for literals/lengths. There are 4 reasons for
@@ -221,7 +223,7 @@ typedef struct internal_state {
221 223
222 uInt last_lit; /* running index in l_buf */ 224 uInt last_lit; /* running index in l_buf */
223 225
224 ush *d_buf; 226 ushf *d_buf;
225 /* Buffer for distances. To simplify the code, d_buf and l_buf have 227 /* Buffer for distances. To simplify the code, d_buf and l_buf have
226 * the same number of elements. To use different lengths, an extra flag 228 * the same number of elements. To use different lengths, an extra flag
227 * array would be necessary. 229 * array would be necessary.
@@ -245,8 +247,7 @@ typedef struct internal_state {
245 * are always zero. 247 * are always zero.
246 */ 248 */
247 249
248} deflate_state; 250} FAR deflate_state;
249
250 251
251/* Output a byte on the stream. 252/* Output a byte on the stream.
252 * IN assertion: there is enough room in pending_buf. 253 * IN assertion: there is enough room in pending_buf.
@@ -265,9 +266,9 @@ typedef struct internal_state {
265 */ 266 */
266 267
267 /* in trees.c */ 268 /* in trees.c */
268void ct_init __P((deflate_state *s)); 269void ct_init OF((deflate_state *s));
269int ct_tally __P((deflate_state *s, int dist, int lc)); 270int ct_tally OF((deflate_state *s, int dist, int lc));
270ulg ct_flush_block __P((deflate_state *s, char *buf, ulg stored_len, int eof)); 271ulg ct_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, int eof));
271void ct_align __P((deflate_state *s)); 272void ct_align OF((deflate_state *s));
272void ct_stored_block __P((deflate_state *s, char *buf, ulg stored_len, 273void ct_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
273 int eof)); 274 int eof));
diff --git a/descrip.mms b/descrip.mms
new file mode 100644
index 0000000..9d36459
--- /dev/null
+++ b/descrip.mms
@@ -0,0 +1,48 @@
1# descrip.mms: MMS description file for building zlib on VMS
2# written by Martin P.J. Zinser <m.zinser@gsi.de>
3
4cc_defs =
5c_deb =
6
7.ifdef __DECC__
8pref = /prefix=all
9.endif
10
11OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj,\
12 deflate.obj, trees.obj, zutil.obj, inflate.obj, infblock.obj,\
13 inftrees.obj, infcodes.obj, infutil.obj, inffast.obj
14
15CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)
16
17all : example.exe minigzip.exe
18 @ write sys$output " Example applications available"
19libz.olb : libz.olb($(OBJS))
20 @ write sys$output " libz available"
21
22example.exe : example.obj libz.olb
23 link example,libz.olb/lib
24
25minigzip.exe : minigzip.obj libz.olb
26 link minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib
27
28clean :
29 delete *.obj;*,libz.olb;*
30
31
32# Other dependencies.
33adler32.obj : zutil.h zlib.h zconf.h
34compress.obj : zlib.h zconf.h
35crc32.obj : zutil.h zlib.h zconf.h
36deflate.obj : deflate.h zutil.h zlib.h zconf.h
37example.obj : zlib.h zconf.h
38gzio.obj : zutil.h zlib.h zconf.h
39infblock.obj : zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
40infcodes.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
41inffast.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
42inflate.obj : zutil.h zlib.h zconf.h infblock.h
43inftrees.obj : zutil.h zlib.h zconf.h inftrees.h
44infutil.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h
45minigzip.obj : zlib.h zconf.h
46trees.obj : deflate.h zutil.h zlib.h zconf.h
47uncompr.obj : zlib.h zconf.h
48zutil.obj : zutil.h zlib.h zconf.h
diff --git a/example.c b/example.c
index a2213e0..d362c7a 100644
--- a/example.c
+++ b/example.c
@@ -13,7 +13,7 @@
13#endif 13#endif
14 14
15#ifndef __GO32__ 15#ifndef __GO32__
16extern void exit __P((int)); 16extern void exit OF((int));
17#endif 17#endif
18 18
19#define BUFLEN 4096 19#define BUFLEN 4096
@@ -31,13 +31,18 @@ extern void exit __P((int));
31 } \ 31 } \
32} 32}
33 33
34char *hello = "hello world"; 34char *hello = "hello, hello!";
35/* "hello world" would be more standard, but the repeated "hello"
36 * stresses the compression code better, sorry...
37 */
35 38
36void test_compress __P((void)); 39void test_compress OF((void));
37void test_gzio __P((char *out, char *in)); 40void test_gzio OF((char *out, char *in));
38void test_deflate __P((Byte compr[])); 41void test_deflate OF((Byte compr[]));
39void test_inflate __P((Byte compr[])); 42void test_inflate OF((Byte compr[]));
40void main __P((int argc, char *argv[])); 43void test_flush OF((Byte compr[]));
44void test_sync OF((Byte compr[]));
45int main OF((int argc, char *argv[]));
41 46
42/* =========================================================================== 47/* ===========================================================================
43 * Test compress() and uncompress() 48 * Test compress() and uncompress()
@@ -262,7 +267,7 @@ void test_sync(compr)
262 * Usage: example [output.gz [input.gz]] 267 * Usage: example [output.gz [input.gz]]
263 */ 268 */
264 269
265void main(argc, argv) 270int main(argc, argv)
266 int argc; 271 int argc;
267 char *argv[]; 272 char *argv[];
268{ 273{
@@ -272,7 +277,7 @@ void main(argc, argv)
272 fprintf(stderr, "incompatible zlib version\n"); 277 fprintf(stderr, "incompatible zlib version\n");
273 exit(1); 278 exit(1);
274 279
275 } else if (strcmp(zlib_version, ZLIB_VERSION) != 0) { 280 } else if (zstrcmp(zlib_version, ZLIB_VERSION) != 0) {
276 fprintf(stderr, "warning: different zlib version\n"); 281 fprintf(stderr, "warning: different zlib version\n");
277 } 282 }
278 test_compress(); 283 test_compress();
@@ -287,4 +292,5 @@ void main(argc, argv)
287 test_sync(compr); 292 test_sync(compr);
288 293
289 exit(0); 294 exit(0);
295 return 0; /* to avoid warning */
290} 296}
diff --git a/gzio.c b/gzio.c
index d323fbc..1f0f9fc 100644
--- a/gzio.c
+++ b/gzio.c
@@ -13,8 +13,8 @@ struct internal_state {int dummy;}; /* for buggy compilers */
13 13
14#define Z_BUFSIZE 4096 14#define Z_BUFSIZE 4096
15 15
16#define ALLOC(size) zcalloc((voidp)0, 1, size) 16#define ALLOC(size) malloc(size)
17#define TRYFREE(p) {if (p) zcfree((voidp)0, p);} 17#define TRYFREE(p) {if (p) free(p);}
18 18
19#define GZ_MAGIC_1 0x1f 19#define GZ_MAGIC_1 0x1f
20#define GZ_MAGIC_2 0x8b 20#define GZ_MAGIC_2 0x8b
@@ -46,10 +46,10 @@ typedef struct gz_stream {
46} gz_stream; 46} gz_stream;
47 47
48 48
49local int destroy __P((gz_stream *s)); 49local int destroy OF((gz_stream *s));
50local gzFile gz_open __P((char *path, char *mode, int fd)); 50local gzFile gz_open OF((char *path, char *mode, int fd));
51local void putLong __P((FILE *file, uLong x)); 51local void putLong OF((FILE *file, uLong x));
52local uLong getLong __P((Byte *buf)); 52local uLong getLong OF((Bytef *buf));
53 53
54 /* =========================================================================== 54 /* ===========================================================================
55 * Cleanup then free the given gz_stream. Return a zlib error code. 55 * Cleanup then free the given gz_stream. Return a zlib error code.
@@ -77,7 +77,7 @@ local int destroy (s)
77 err = Z_ERRNO; 77 err = Z_ERRNO;
78 } 78 }
79 if (s->z_err < 0) err = s->z_err; 79 if (s->z_err < 0) err = s->z_err;
80 zcfree((voidp)0, s); 80 TRYFREE(s);
81 return err; 81 return err;
82} 82}
83 83
@@ -96,6 +96,7 @@ local gzFile gz_open (path, mode, fd)
96 int fd; 96 int fd;
97{ 97{
98 int err; 98 int err;
99 int level = Z_DEFAULT_COMPRESSION; /* compression level */
99 char *p = mode; 100 char *p = mode;
100 gz_stream *s = (gz_stream *)ALLOC(sizeof(gz_stream)); 101 gz_stream *s = (gz_stream *)ALLOC(sizeof(gz_stream));
101 102
@@ -123,22 +124,23 @@ local gzFile gz_open (path, mode, fd)
123 do { 124 do {
124 if (*p == 'r') s->mode = 'r'; 125 if (*p == 'r') s->mode = 'r';
125 if (*p == 'w') s->mode = 'w'; 126 if (*p == 'w') s->mode = 'w';
127 if (*p >= '1' && *p <= '9') level = *p - '0';
126 } while (*p++); 128 } while (*p++);
127 if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; 129 if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
128 130
129 if (s->mode == 'w') { 131 if (s->mode == 'w') {
130 err = deflateInit2(&(s->stream), Z_DEFAULT_COMPRESSION, 132 err = deflateInit2(&(s->stream), level,
131 DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0); 133 DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
132 /* windowBits is passed < 0 to suppress zlib header */ 134 /* windowBits is passed < 0 to suppress zlib header */
133 135
134 s->stream.next_out = s->outbuf = ALLOC(Z_BUFSIZE); 136 s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
135 137
136 if (err != Z_OK || s->outbuf == Z_NULL) { 138 if (err != Z_OK || s->outbuf == Z_NULL) {
137 return destroy(s), (gzFile)Z_NULL; 139 return destroy(s), (gzFile)Z_NULL;
138 } 140 }
139 } else { 141 } else {
140 err = inflateInit2(&(s->stream), -MAX_WBITS); 142 err = inflateInit2(&(s->stream), -MAX_WBITS);
141 s->stream.next_in = s->inbuf = ALLOC(Z_BUFSIZE); 143 s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
142 144
143 if (err != Z_OK || s->inbuf == Z_NULL) { 145 if (err != Z_OK || s->inbuf == Z_NULL) {
144 return destroy(s), (gzFile)Z_NULL; 146 return destroy(s), (gzFile)Z_NULL;
@@ -232,7 +234,7 @@ gzFile gzdopen (fd, mode)
232*/ 234*/
233int gzread (file, buf, len) 235int gzread (file, buf, len)
234 gzFile file; 236 gzFile file;
235 voidp buf; 237 voidnp buf;
236 unsigned len; 238 unsigned len;
237{ 239{
238 gz_stream *s = (gz_stream*)file; 240 gz_stream *s = (gz_stream*)file;
@@ -240,7 +242,7 @@ int gzread (file, buf, len)
240 if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; 242 if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
241 243
242 if (s->transparent) { 244 if (s->transparent) {
243 unsigned n = 0; 245 int n = 0;
244 Byte *b = (Byte*)buf; 246 Byte *b = (Byte*)buf;
245 /* Copy the first two (non-magic) bytes if not done already */ 247 /* Copy the first two (non-magic) bytes if not done already */
246 while (s->stream.avail_in > 0 && len > 0) { 248 while (s->stream.avail_in > 0 && len > 0) {
@@ -281,7 +283,7 @@ int gzread (file, buf, len)
281 } 283 }
282 len -= s->stream.avail_out; 284 len -= s->stream.avail_out;
283 s->crc = crc32(s->crc, buf, len); 285 s->crc = crc32(s->crc, buf, len);
284 return len; 286 return (int)len;
285} 287}
286 288
287/* =========================================================================== 289/* ===========================================================================
@@ -290,7 +292,7 @@ int gzread (file, buf, len)
290*/ 292*/
291int gzwrite (file, buf, len) 293int gzwrite (file, buf, len)
292 gzFile file; 294 gzFile file;
293 voidp buf; 295 voidnp buf;
294 unsigned len; 296 unsigned len;
295{ 297{
296 gz_stream *s = (gz_stream*)file; 298 gz_stream *s = (gz_stream*)file;
@@ -312,12 +314,11 @@ int gzwrite (file, buf, len)
312 s->stream.avail_out = Z_BUFSIZE; 314 s->stream.avail_out = Z_BUFSIZE;
313 } 315 }
314 s->z_err = deflate(&(s->stream), Z_NO_FLUSH); 316 s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
315
316 if (s->z_err != Z_OK) break; 317 if (s->z_err != Z_OK) break;
317 } 318 }
318 s->crc = crc32(s->crc, buf, len); 319 s->crc = crc32(s->crc, buf, len);
319 320
320 return len - s->stream.avail_in; 321 return (int)(len - s->stream.avail_in);
321} 322}
322 323
323/* =========================================================================== 324/* ===========================================================================
@@ -359,6 +360,7 @@ int gzflush (file, flush)
359 360
360 if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; 361 if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
361 } 362 }
363 fflush(s->file);
362 return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; 364 return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
363} 365}
364 366
@@ -380,10 +382,10 @@ local void putLong (file, x)
380 Reads a long in LSB order from the given buffer 382 Reads a long in LSB order from the given buffer
381*/ 383*/
382local uLong getLong (buf) 384local uLong getLong (buf)
383 Byte *buf; 385 Bytef *buf;
384{ 386{
385 uLong x = 0; 387 uLong x = 0;
386 Byte *p = buf+4; 388 Bytef *p = buf+4;
387 389
388 do { 390 do {
389 x <<= 8; 391 x <<= 8;
@@ -417,7 +419,7 @@ int gzclose (file)
417 /* slide CRC and original size if they are at the end of inbuf */ 419 /* slide CRC and original size if they are at the end of inbuf */
418 if ((n = s->stream.avail_in) < 8 && !s->z_eof) { 420 if ((n = s->stream.avail_in) < 8 && !s->z_eof) {
419 Byte *p = s->inbuf; 421 Byte *p = s->inbuf;
420 Byte *q = s->stream.next_in; 422 Bytef *q = s->stream.next_in;
421 while (n--) { *p++ = *q++; }; 423 while (n--) { *p++ = *q++; };
422 424
423 n = s->stream.avail_in; 425 n = s->stream.avail_in;
diff --git a/infblock.c b/infblock.c
index 04a5653..1fc0726 100644
--- a/infblock.c
+++ b/infblock.c
@@ -62,9 +62,9 @@ local uInt border[] = { /* Order of the bit length code lengths */
62 62
63 63
64void inflate_blocks_reset(s, z, c) 64void inflate_blocks_reset(s, z, c)
65struct inflate_blocks_state *s; 65inflate_blocks_statef *s;
66z_stream *z; 66z_stream *z;
67uLong *c; 67uLongf *c;
68{ 68{
69 if (s->checkfn != Z_NULL) 69 if (s->checkfn != Z_NULL)
70 *c = s->check; 70 *c = s->check;
@@ -86,17 +86,17 @@ uLong *c;
86} 86}
87 87
88 88
89struct inflate_blocks_state *inflate_blocks_new(z, c, w) 89inflate_blocks_statef *inflate_blocks_new(z, c, w)
90z_stream *z; 90z_stream *z;
91check_func c; 91check_func c;
92uInt w; 92uInt w;
93{ 93{
94 struct inflate_blocks_state *s; 94 inflate_blocks_statef *s;
95 95
96 if ((s = (struct inflate_blocks_state *)ZALLOC 96 if ((s = (inflate_blocks_statef *)ZALLOC
97 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) 97 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
98 return s; 98 return s;
99 if ((s->window = (Byte *)ZALLOC(z, 1, w)) == Z_NULL) 99 if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
100 { 100 {
101 ZFREE(z, s); 101 ZFREE(z, s);
102 return Z_NULL; 102 return Z_NULL;
@@ -111,16 +111,16 @@ uInt w;
111 111
112 112
113int inflate_blocks(s, z, r) 113int inflate_blocks(s, z, r)
114struct inflate_blocks_state *s; 114inflate_blocks_statef *s;
115z_stream *z; 115z_stream *z;
116int r; 116int r;
117{ 117{
118 uInt t; /* temporary storage */ 118 uInt t; /* temporary storage */
119 uLong b; /* bit buffer */ 119 uLong b; /* bit buffer */
120 uInt k; /* bits in bit buffer */ 120 uInt k; /* bits in bit buffer */
121 Byte *p; /* input data pointer */ 121 Bytef *p; /* input data pointer */
122 uInt n; /* bytes available there */ 122 uInt n; /* bytes available there */
123 Byte *q; /* output window write pointer */ 123 Bytef *q; /* output window write pointer */
124 uInt m; /* bytes to end of window or read pointer */ 124 uInt m; /* bytes to end of window or read pointer */
125 125
126 /* copy input/output information to locals (UPDATE macro restores) */ 126 /* copy input/output information to locals (UPDATE macro restores) */
@@ -179,7 +179,7 @@ int r;
179 break; 179 break;
180 case LENS: 180 case LENS:
181 NEEDBITS(32) 181 NEEDBITS(32)
182 if ((~b) >> 16 != (b & 0xffff)) 182 if (((~b) >> 16) != (b & 0xffff))
183 { 183 {
184 s->mode = BAD; 184 s->mode = BAD;
185 z->msg = "invalid stored block lengths"; 185 z->msg = "invalid stored block lengths";
@@ -223,7 +223,7 @@ int r;
223 t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); 223 t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
224 if (t < 19) 224 if (t < 19)
225 t = 19; 225 t = 19;
226 if ((s->sub.trees.blens = (uInt*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL) 226 if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
227 { 227 {
228 r = Z_MEM_ERROR; 228 r = Z_MEM_ERROR;
229 LEAVE 229 LEAVE
@@ -301,10 +301,10 @@ int r;
301 { 301 {
302 uInt bl, bd; 302 uInt bl, bd;
303 inflate_huft *tl, *td; 303 inflate_huft *tl, *td;
304 struct inflate_codes_state *c; 304 inflate_codes_statef *c;
305 305
306 bl = 9; 306 bl = 9; /* must be <= 9 for lookahead assumptions */
307 bd = 6; 307 bd = 6; /* must be <= 9 for lookahead assumptions */
308 t = s->sub.trees.table; 308 t = s->sub.trees.table;
309 t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), 309 t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
310 s->sub.trees.blens, &bl, &bd, &tl, &td, z); 310 s->sub.trees.blens, &bl, &bd, &tl, &td, z);
@@ -373,9 +373,9 @@ int r;
373 373
374 374
375int inflate_blocks_free(s, z, c) 375int inflate_blocks_free(s, z, c)
376struct inflate_blocks_state *s; 376inflate_blocks_statef *s;
377z_stream *z; 377z_stream *z;
378uLong *c; 378uLongf *c;
379{ 379{
380 inflate_blocks_reset(s, z, c); 380 inflate_blocks_reset(s, z, c);
381 ZFREE(z, s->window); 381 ZFREE(z, s->window);
diff --git a/infblock.h b/infblock.h
index c0712c1..aba6e24 100644
--- a/infblock.h
+++ b/infblock.h
@@ -9,23 +9,24 @@
9 */ 9 */
10 10
11struct inflate_blocks_state; 11struct inflate_blocks_state;
12typedef struct inflate_blocks_state FAR inflate_blocks_statef;
12 13
13extern struct inflate_blocks_state * inflate_blocks_new __P(( 14extern inflate_blocks_statef * inflate_blocks_new OF((
14 z_stream *, 15 z_stream *z,
15 check_func, /* check function */ 16 check_func c, /* check function */
16 uInt)); /* window size */ 17 uInt w)); /* window size */
17 18
18extern int inflate_blocks __P(( 19extern int inflate_blocks OF((
19 struct inflate_blocks_state *, 20 inflate_blocks_statef *,
20 z_stream *, 21 z_stream *,
21 int)); /* initial return code */ 22 int)); /* initial return code */
22 23
23extern void inflate_blocks_reset __P(( 24extern void inflate_blocks_reset OF((
24 struct inflate_blocks_state *, 25 inflate_blocks_statef *,
25 z_stream *, 26 z_stream *,
26 uLong *)); /* check value on output */ 27 uLongf *)); /* check value on output */
27 28
28extern int inflate_blocks_free __P(( 29extern int inflate_blocks_free OF((
29 struct inflate_blocks_state *, 30 inflate_blocks_statef *,
30 z_stream *, 31 z_stream *,
31 uLong *)); /* check value on output */ 32 uLongf *)); /* check value on output */
diff --git a/infcodes.c b/infcodes.c
index 4305290..22ce856 100644
--- a/infcodes.c
+++ b/infcodes.c
@@ -5,9 +5,10 @@
5 5
6#include "zutil.h" 6#include "zutil.h"
7#include "inftrees.h" 7#include "inftrees.h"
8#include "infblock.h"
9#include "infcodes.h"
8#include "infutil.h" 10#include "infutil.h"
9#include "inffast.h" 11#include "inffast.h"
10#include "infcodes.h"
11 12
12/* simplify the use of the inflate_huft type with some defines */ 13/* simplify the use of the inflate_huft type with some defines */
13#define base more.Base 14#define base more.Base
@@ -55,14 +56,14 @@ struct inflate_codes_state {
55}; 56};
56 57
57 58
58struct inflate_codes_state *inflate_codes_new(bl, bd, tl, td, z) 59inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
59uInt bl, bd; 60uInt bl, bd;
60inflate_huft *tl, *td; 61inflate_huft *tl, *td;
61z_stream *z; 62z_stream *z;
62{ 63{
63 struct inflate_codes_state *c; 64 inflate_codes_statef *c;
64 65
65 if ((c = (struct inflate_codes_state *) 66 if ((c = (inflate_codes_statef *)
66 ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL) 67 ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
67 { 68 {
68 c->mode = START; 69 c->mode = START;
@@ -77,7 +78,7 @@ z_stream *z;
77 78
78 79
79int inflate_codes(s, z, r) 80int inflate_codes(s, z, r)
80struct inflate_blocks_state *s; 81inflate_blocks_statef *s;
81z_stream *z; 82z_stream *z;
82int r; 83int r;
83{ 84{
@@ -86,12 +87,12 @@ int r;
86 uInt e; /* extra bits or operation */ 87 uInt e; /* extra bits or operation */
87 uLong b; /* bit buffer */ 88 uLong b; /* bit buffer */
88 uInt k; /* bits in bit buffer */ 89 uInt k; /* bits in bit buffer */
89 Byte *p; /* input data pointer */ 90 Bytef *p; /* input data pointer */
90 uInt n; /* bytes available there */ 91 uInt n; /* bytes available there */
91 Byte *q; /* output window write pointer */ 92 Bytef *q; /* output window write pointer */
92 uInt m; /* bytes to end of window or read pointer */ 93 uInt m; /* bytes to end of window or read pointer */
93 Byte *f; /* pointer to copy strings from */ 94 Bytef *f; /* pointer to copy strings from */
94 struct inflate_codes_state *c = s->sub.decode.codes; /* codes state */ 95 inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
95 96
96 /* copy input/output information to locals (UPDATE macro restores) */ 97 /* copy input/output information to locals (UPDATE macro restores) */
97 LOAD 98 LOAD
@@ -194,9 +195,15 @@ int r;
194 Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); 195 Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
195 c->mode = COPY; 196 c->mode = COPY;
196 case COPY: /* o: copying bytes in window, waiting for space */ 197 case COPY: /* o: copying bytes in window, waiting for space */
198#ifndef __TURBOC__ /* Turbo C bug for following expression */
197 f = (uInt)(q - s->window) < c->sub.copy.dist ? 199 f = (uInt)(q - s->window) < c->sub.copy.dist ?
198 s->end - (c->sub.copy.dist - (q - s->window)) : 200 s->end - (c->sub.copy.dist - (q - s->window)) :
199 q - c->sub.copy.dist; 201 q - c->sub.copy.dist;
202#else
203 f = q - c->sub.copy.dist;
204 if ((uInt)(q - s->window) < c->sub.copy.dist)
205 f = s->end - (c->sub.copy.dist - (q - s->window));
206#endif
200 while (c->len) 207 while (c->len)
201 { 208 {
202 NEEDOUT 209 NEEDOUT
@@ -231,7 +238,7 @@ int r;
231 238
232 239
233void inflate_codes_free(c, z) 240void inflate_codes_free(c, z)
234struct inflate_codes_state *c; 241inflate_codes_statef *c;
235z_stream *z; 242z_stream *z;
236{ 243{
237 ZFREE(z, c); 244 ZFREE(z, c);
diff --git a/infcodes.h b/infcodes.h
index af99cd1..a772e42 100644
--- a/infcodes.h
+++ b/infcodes.h
@@ -9,17 +9,19 @@
9 */ 9 */
10 10
11struct inflate_codes_state; 11struct inflate_codes_state;
12typedef struct inflate_codes_state FAR inflate_codes_statef;
12 13
13extern struct inflate_codes_state *inflate_codes_new __P(( 14extern inflate_codes_statef *inflate_codes_new OF((
14 uInt, uInt, 15 uInt, uInt,
15 inflate_huft *, inflate_huft *, 16 inflate_huft *, inflate_huft *,
16 z_stream *)); 17 z_stream *));
17 18
18extern int inflate_codes __P(( 19extern int inflate_codes OF((
19 struct inflate_blocks_state *, 20 inflate_blocks_statef *,
20 z_stream *, 21 z_stream *,
21 int)); 22 int));
22 23
23extern void inflate_codes_free __P(( 24extern void inflate_codes_free OF((
24 struct inflate_codes_state *, 25 inflate_codes_statef *,
25 z_stream *)); 26 z_stream *));
27
diff --git a/inffast.c b/inffast.c
index 49ed1df..d1f1ad2 100644
--- a/inffast.c
+++ b/inffast.c
@@ -5,6 +5,8 @@
5 5
6#include "zutil.h" 6#include "zutil.h"
7#include "inftrees.h" 7#include "inftrees.h"
8#include "infblock.h"
9#include "infcodes.h"
8#include "infutil.h" 10#include "infutil.h"
9#include "inffast.h" 11#include "inffast.h"
10 12
@@ -28,22 +30,22 @@ struct inflate_codes_state {int dummy;}; /* for buggy compilers */
28int inflate_fast(bl, bd, tl, td, s, z) 30int inflate_fast(bl, bd, tl, td, s, z)
29uInt bl, bd; 31uInt bl, bd;
30inflate_huft *tl, *td; 32inflate_huft *tl, *td;
31struct inflate_blocks_state *s; 33inflate_blocks_statef *s;
32z_stream *z; 34z_stream *z;
33{ 35{
34 inflate_huft *t; /* temporary pointer */ 36 inflate_huft *t; /* temporary pointer */
35 uInt e; /* extra bits or operation */ 37 uInt e; /* extra bits or operation */
36 uLong b; /* bit buffer */ 38 uLong b; /* bit buffer */
37 uInt k; /* bits in bit buffer */ 39 uInt k; /* bits in bit buffer */
38 Byte *p; /* input data pointer */ 40 Bytef *p; /* input data pointer */
39 uInt n; /* bytes available there */ 41 uInt n; /* bytes available there */
40 Byte *q; /* output window write pointer */ 42 Bytef *q; /* output window write pointer */
41 uInt m; /* bytes to end of window or read pointer */ 43 uInt m; /* bytes to end of window or read pointer */
42 uInt ml; /* mask for literal/length tree */ 44 uInt ml; /* mask for literal/length tree */
43 uInt md; /* mask for distance tree */ 45 uInt md; /* mask for distance tree */
44 uInt c; /* bytes to copy */ 46 uInt c; /* bytes to copy */
45 uInt d; /* distance back to copy from */ 47 uInt d; /* distance back to copy from */
46 Byte *r; /* copy source pointer */ 48 Bytef *r; /* copy source pointer */
47 49
48 /* load input, output, bit values */ 50 /* load input, output, bit values */
49 LOAD 51 LOAD
diff --git a/inffast.h b/inffast.h
index 2c05820..ad3cf97 100644
--- a/inffast.h
+++ b/inffast.h
@@ -8,10 +8,10 @@
8 subject to change. Applications should only use zlib.h. 8 subject to change. Applications should only use zlib.h.
9 */ 9 */
10 10
11extern int inflate_fast __P(( 11extern int inflate_fast OF((
12 uInt, 12 uInt,
13 uInt, 13 uInt,
14 inflate_huft *, 14 inflate_huft *,
15 inflate_huft *, 15 inflate_huft *,
16 struct inflate_blocks_state *, 16 inflate_blocks_statef *,
17 z_stream *)); 17 z_stream *));
diff --git a/inflate.c b/inflate.c
index 1c58d98..ec0f3a0 100644
--- a/inflate.c
+++ b/inflate.c
@@ -37,7 +37,7 @@ struct internal_state {
37 /* mode independent information */ 37 /* mode independent information */
38 int nowrap; /* flag for no wrapper */ 38 int nowrap; /* flag for no wrapper */
39 uInt wbits; /* log2(window size) (8..15, defaults to 15) */ 39 uInt wbits; /* log2(window size) (8..15, defaults to 15) */
40 struct inflate_blocks_state 40 inflate_blocks_statef
41 *blocks; /* current inflate_blocks state */ 41 *blocks; /* current inflate_blocks state */
42 42
43}; 43};
@@ -84,7 +84,7 @@ int w;
84 return Z_STREAM_ERROR; 84 return Z_STREAM_ERROR;
85 if (z->zalloc == Z_NULL) z->zalloc = zcalloc; 85 if (z->zalloc == Z_NULL) z->zalloc = zcalloc;
86 if (z->zfree == Z_NULL) z->zfree = zcfree; 86 if (z->zfree == Z_NULL) z->zfree = zcfree;
87 if ((z->state = (struct internal_state *) 87 if ((z->state = (struct internal_state FAR *)
88 ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) 88 ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
89 return Z_MEM_ERROR; 89 return Z_MEM_ERROR;
90 z->state->blocks = Z_NULL; 90 z->state->blocks = Z_NULL;
@@ -235,7 +235,7 @@ int inflateSync(z)
235z_stream *z; 235z_stream *z;
236{ 236{
237 uInt n; /* number of bytes to look at */ 237 uInt n; /* number of bytes to look at */
238 Byte *p; /* pointer to bytes */ 238 Bytef *p; /* pointer to bytes */
239 uInt m; /* number of marker bytes found in a row */ 239 uInt m; /* number of marker bytes found in a row */
240 uLong r, w; /* temporaries to save total_in and total_out */ 240 uLong r, w; /* temporaries to save total_in and total_out */
241 241
diff --git a/inftrees.c b/inftrees.c
index 377e8da..7a45e92 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -15,22 +15,22 @@ struct internal_state {int dummy;}; /* for buggy compilers */
15#define bits word.what.Bits 15#define bits word.what.Bits
16 16
17 17
18local int huft_build __P(( 18local int huft_build OF((
19 uInt *, /* code lengths in bits */ 19 uIntf *, /* code lengths in bits */
20 uInt, /* number of codes */ 20 uInt, /* number of codes */
21 uInt, /* number of "simple" codes */ 21 uInt, /* number of "simple" codes */
22 uInt *, /* list of base values for non-simple codes */ 22 uIntf *, /* list of base values for non-simple codes */
23 uInt *, /* list of extra bits for non-simple codes */ 23 uIntf *, /* list of extra bits for non-simple codes */
24 inflate_huft **, /* result: starting table */ 24 inflate_huft * FAR*,/* result: starting table */
25 uInt *, /* maximum lookup bits (returns actual) */ 25 uIntf *, /* maximum lookup bits (returns actual) */
26 z_stream *)); /* for zalloc function */ 26 z_stream *)); /* for zalloc function */
27 27
28local voidp falloc __P(( 28local voidp falloc OF((
29 voidp, /* opaque pointer (not used) */ 29 voidp, /* opaque pointer (not used) */
30 uInt, /* number of items */ 30 uInt, /* number of items */
31 uInt)); /* size of item */ 31 uInt)); /* size of item */
32 32
33local void ffree __P(( 33local void ffree OF((
34 voidp q, /* opaque pointer (not used) */ 34 voidp q, /* opaque pointer (not used) */
35 voidp p)); /* what to free (not used) */ 35 voidp p)); /* what to free (not used) */
36 36
@@ -93,13 +93,13 @@ local uInt cpdext[] = { /* Extra bits for distance codes */
93#endif 93#endif
94 94
95local int huft_build(b, n, s, d, e, t, m, zs) 95local int huft_build(b, n, s, d, e, t, m, zs)
96uInt *b; /* code lengths in bits (all assumed <= BMAX) */ 96uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
97uInt n; /* number of codes (assumed <= N_MAX) */ 97uInt n; /* number of codes (assumed <= N_MAX) */
98uInt s; /* number of simple-valued codes (0..s-1) */ 98uInt s; /* number of simple-valued codes (0..s-1) */
99uInt *d; /* list of base values for non-simple codes */ 99uIntf *d; /* list of base values for non-simple codes */
100uInt *e; /* list of extra bits for non-simple codes */ 100uIntf *e; /* list of extra bits for non-simple codes */
101inflate_huft **t; /* result: starting table */ 101inflate_huft * FAR *t; /* result: starting table */
102uInt *m; /* maximum lookup bits, returns actual */ 102uIntf *m; /* maximum lookup bits, returns actual */
103z_stream *zs; /* for zalloc function */ 103z_stream *zs; /* for zalloc function */
104/* Given a list of code lengths and a maximum table size, make a set of 104/* Given a list of code lengths and a maximum table size, make a set of
105 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR 105 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
@@ -107,6 +107,7 @@ z_stream *zs; /* for zalloc function */
107 case), Z_DATA_ERROR if the input is invalid (all zero length codes or an 107 case), Z_DATA_ERROR if the input is invalid (all zero length codes or an
108 over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */ 108 over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */
109{ 109{
110
110 uInt a; /* counter for codes of length k */ 111 uInt a; /* counter for codes of length k */
111 uInt c[BMAX+1]; /* bit length count table */ 112 uInt c[BMAX+1]; /* bit length count table */
112 uInt f; /* i repeats in table every f entries */ 113 uInt f; /* i repeats in table every f entries */
@@ -116,14 +117,14 @@ z_stream *zs; /* for zalloc function */
116 register uInt j; /* counter */ 117 register uInt j; /* counter */
117 register int k; /* number of bits in current code */ 118 register int k; /* number of bits in current code */
118 int l; /* bits per table (returned in m) */ 119 int l; /* bits per table (returned in m) */
119 register uInt *p; /* pointer into c[], b[], or v[] */ 120 register uIntf *p; /* pointer into c[], b[], or v[] */
120 register inflate_huft *q; /* points to current table */ 121 inflate_huft *q; /* points to current table */
121 inflate_huft r; /* table entry for structure assignment */ 122 struct inflate_huft_s r; /* table entry for structure assignment */
122 inflate_huft *u[BMAX]; /* table stack */ 123 inflate_huft *u[BMAX]; /* table stack */
123 uInt v[N_MAX]; /* values in order of bit length */ 124 uInt v[N_MAX]; /* values in order of bit length */
124 register int w; /* bits before this table == (l * h) */ 125 register int w; /* bits before this table == (l * h) */
125 uInt x[BMAX+1]; /* bit offsets, then code stack */ 126 uInt x[BMAX+1]; /* bit offsets, then code stack */
126 uInt *xp; /* pointer into x */ 127 uIntf *xp; /* pointer into x */
127 int y; /* number of dummy codes added */ 128 int y; /* number of dummy codes added */
128 uInt z; /* number of entries in current table */ 129 uInt z; /* number of entries in current table */
129 130
@@ -238,7 +239,7 @@ z_stream *zs; /* for zalloc function */
238 inflate_hufts += z + 1; 239 inflate_hufts += z + 1;
239#endif 240#endif
240 *t = q + 1; /* link to list for huft_free() */ 241 *t = q + 1; /* link to list for huft_free() */
241 *(t = &(q->next)) = (inflate_huft *)Z_NULL; 242 *(t = &(q->next)) = Z_NULL;
242 u[h] = ++q; /* table starts after link */ 243 u[h] = ++q; /* table starts after link */
243 244
244 /* connect to last table, if there is one */ 245 /* connect to last table, if there is one */
@@ -246,7 +247,7 @@ z_stream *zs; /* for zalloc function */
246 { 247 {
247 x[h] = i; /* save pattern for backing up */ 248 x[h] = i; /* save pattern for backing up */
248 r.bits = (Byte)l; /* bits to dump before this table */ 249 r.bits = (Byte)l; /* bits to dump before this table */
249 r.exop = j; /* bits in this table */ 250 r.exop = (Byte)j; /* bits in this table */
250 r.next = q; /* pointer to this table */ 251 r.next = q; /* pointer to this table */
251 j = i >> (w - l); /* (get around Turbo C bug) */ 252 j = i >> (w - l); /* (get around Turbo C bug) */
252 u[h-1][j] = r; /* connect to last table */ 253 u[h-1][j] = r; /* connect to last table */
@@ -259,12 +260,12 @@ z_stream *zs; /* for zalloc function */
259 r.exop = 128 + 64; /* out of values--invalid code */ 260 r.exop = 128 + 64; /* out of values--invalid code */
260 else if (*p < s) 261 else if (*p < s)
261 { 262 {
262 r.exop = (*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ 263 r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
263 r.base = *p++; /* simple code is just the value */ 264 r.base = *p++; /* simple code is just the value */
264 } 265 }
265 else 266 else
266 { 267 {
267 r.exop = e[*p - s] + 16 + 64; /* non-simple--look up in lists */ 268 r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */
268 r.base = d[*p++ - s]; 269 r.base = d[*p++ - s];
269 } 270 }
270 271
@@ -294,14 +295,14 @@ z_stream *zs; /* for zalloc function */
294 295
295 296
296int inflate_trees_bits(c, bb, tb, z) 297int inflate_trees_bits(c, bb, tb, z)
297uInt *c; /* 19 code lengths */ 298uIntf *c; /* 19 code lengths */
298uInt *bb; /* bits tree desired/actual depth */ 299uIntf *bb; /* bits tree desired/actual depth */
299inflate_huft **tb; /* bits tree result */ 300inflate_huft * FAR *tb; /* bits tree result */
300z_stream *z; /* for zfree function */ 301z_stream *z; /* for zfree function */
301{ 302{
302 int r; 303 int r;
303 304
304 r = huft_build(c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL, tb, bb, z); 305 r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
305 if (r == Z_DATA_ERROR) 306 if (r == Z_DATA_ERROR)
306 z->msg = "oversubscribed dynamic bit lengths tree"; 307 z->msg = "oversubscribed dynamic bit lengths tree";
307 else if (r == Z_BUF_ERROR) 308 else if (r == Z_BUF_ERROR)
@@ -317,11 +318,11 @@ z_stream *z; /* for zfree function */
317int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z) 318int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
318uInt nl; /* number of literal/length codes */ 319uInt nl; /* number of literal/length codes */
319uInt nd; /* number of distance codes */ 320uInt nd; /* number of distance codes */
320uInt *c; /* that many (total) code lengths */ 321uIntf *c; /* that many (total) code lengths */
321uInt *bl; /* literal desired/actual bit depth */ 322uIntf *bl; /* literal desired/actual bit depth */
322uInt *bd; /* distance desired/actual bit depth */ 323uIntf *bd; /* distance desired/actual bit depth */
323inflate_huft **tl; /* literal/length tree result */ 324inflate_huft * FAR *tl; /* literal/length tree result */
324inflate_huft **td; /* distance tree result */ 325inflate_huft * FAR *td; /* distance tree result */
325z_stream *z; /* for zfree function */ 326z_stream *z; /* for zfree function */
326{ 327{
327 int r; 328 int r;
@@ -399,10 +400,10 @@ voidp p;
399 400
400 401
401int inflate_trees_fixed(bl, bd, tl, td) 402int inflate_trees_fixed(bl, bd, tl, td)
402uInt *bl; /* literal desired/actual bit depth */ 403uIntf *bl; /* literal desired/actual bit depth */
403uInt *bd; /* distance desired/actual bit depth */ 404uIntf *bd; /* distance desired/actual bit depth */
404inflate_huft **tl; /* literal/length tree result */ 405inflate_huft * FAR *tl; /* literal/length tree result */
405inflate_huft **td; /* distance tree result */ 406inflate_huft * FAR *td; /* distance tree result */
406{ 407{
407 /* build fixed tables if not built already--lock out other instances */ 408 /* build fixed tables if not built already--lock out other instances */
408 while (++fixed_lock > 1) 409 while (++fixed_lock > 1)
diff --git a/inftrees.h b/inftrees.h
index 03b85c5..9eaaa66 100644
--- a/inftrees.h
+++ b/inftrees.h
@@ -11,14 +11,15 @@
11/* Huffman code lookup table entry--this entry is four bytes for machines 11/* Huffman code lookup table entry--this entry is four bytes for machines
12 that have 16-bit pointers (e.g. PC's in the small or medium model). */ 12 that have 16-bit pointers (e.g. PC's in the small or medium model). */
13 13
14typedef struct inflate_huft_s inflate_huft; 14typedef struct inflate_huft_s FAR inflate_huft;
15
15struct inflate_huft_s { 16struct inflate_huft_s {
16 union { 17 union {
17 struct { 18 struct {
18 Byte Exop; /* number of extra bits or operation */ 19 Byte Exop; /* number of extra bits or operation */
19 Byte Bits; /* number of bits in this code or subcode */ 20 Byte Bits; /* number of bits in this code or subcode */
20 } what; 21 } what;
21 Byte *pad; /* pad structure to a power of 2 (4 bytes for */ 22 Bytef *pad; /* pad structure to a power of 2 (4 bytes for */
22 } word; /* 16-bit, 8 bytes for 32-bit machines) */ 23 } word; /* 16-bit, 8 bytes for 32-bit machines) */
23 union { 24 union {
24 uInt Base; /* literal, length base, or distance base */ 25 uInt Base; /* literal, length base, or distance base */
@@ -30,28 +31,29 @@ struct inflate_huft_s {
30 extern uInt inflate_hufts; 31 extern uInt inflate_hufts;
31#endif 32#endif
32 33
33extern int inflate_trees_bits __P(( 34extern int inflate_trees_bits OF((
34 uInt *, /* 19 code lengths */ 35 uIntf *, /* 19 code lengths */
35 uInt *, /* bits tree desired/actual depth */ 36 uIntf *, /* bits tree desired/actual depth */
36 inflate_huft **, /* bits tree result */ 37 inflate_huft * FAR *, /* bits tree result */
37 z_stream *)); /* for zalloc, zfree functions */ 38 z_stream *)); /* for zalloc, zfree functions */
38 39
39extern int inflate_trees_dynamic __P(( 40extern int inflate_trees_dynamic OF((
40 uInt, /* number of literal/length codes */ 41 uInt, /* number of literal/length codes */
41 uInt, /* number of distance codes */ 42 uInt, /* number of distance codes */
42 uInt *, /* that many (total) code lengths */ 43 uIntf *, /* that many (total) code lengths */
43 uInt *, /* literal desired/actual bit depth */ 44 uIntf *, /* literal desired/actual bit depth */
44 uInt *, /* distance desired/actual bit depth */ 45 uIntf *, /* distance desired/actual bit depth */
45 inflate_huft **, /* literal/length tree result */ 46 inflate_huft * FAR *, /* literal/length tree result */
46 inflate_huft **, /* distance tree result */ 47 inflate_huft * FAR *, /* distance tree result */
47 z_stream *)); /* for zalloc, zfree functions */ 48 z_stream *)); /* for zalloc, zfree functions */
48 49
49extern int inflate_trees_fixed __P(( 50extern int inflate_trees_fixed OF((
50 uInt *, /* literal desired/actual bit depth */ 51 uIntf *, /* literal desired/actual bit depth */
51 uInt *, /* distance desired/actual bit depth */ 52 uIntf *, /* distance desired/actual bit depth */
52 inflate_huft **, /* literal/length tree result */ 53 inflate_huft * FAR *, /* literal/length tree result */
53 inflate_huft **)); /* distance tree result */ 54 inflate_huft * FAR *)); /* distance tree result */
54 55
55extern int inflate_trees_free __P(( 56extern int inflate_trees_free OF((
56 inflate_huft *, /* tables to free */ 57 inflate_huft *, /* tables to free */
57 z_stream *)); /* for zfree function */ 58 z_stream *)); /* for zfree function */
59
diff --git a/infutil.c b/infutil.c
index a5902e7..96db3a4 100644
--- a/infutil.c
+++ b/infutil.c
@@ -4,7 +4,9 @@
4 */ 4 */
5 5
6#include "zutil.h" 6#include "zutil.h"
7#include "infblock.h"
7#include "inftrees.h" 8#include "inftrees.h"
9#include "infcodes.h"
8#include "infutil.h" 10#include "infutil.h"
9 11
10struct inflate_codes_state {int dummy;}; /* for buggy compilers */ 12struct inflate_codes_state {int dummy;}; /* for buggy compilers */
@@ -19,12 +21,12 @@ uInt inflate_mask[] = {
19 21
20/* copy as much as possible from the sliding window to the output area */ 22/* copy as much as possible from the sliding window to the output area */
21int inflate_flush(s, z, r) 23int inflate_flush(s, z, r)
22struct inflate_blocks_state *s; 24inflate_blocks_statef *s;
23z_stream *z; 25z_stream *z;
24int r; 26int r;
25{ 27{
26 uInt n; 28 uInt n;
27 Byte *p, *q; 29 Bytef *p, *q;
28 30
29 /* local copies of source and destination pointers */ 31 /* local copies of source and destination pointers */
30 p = z->next_out; 32 p = z->next_out;
diff --git a/infutil.h b/infutil.h
index b5639d6..4c8c2d2 100644
--- a/infutil.h
+++ b/infutil.h
@@ -31,14 +31,14 @@ struct inflate_blocks_state {
31 struct { 31 struct {
32 uInt table; /* table lengths (14 bits) */ 32 uInt table; /* table lengths (14 bits) */
33 uInt index; /* index into blens (or border) */ 33 uInt index; /* index into blens (or border) */
34 uInt *blens; /* bit lengths of codes */ 34 uIntf *blens; /* bit lengths of codes */
35 uInt bb; /* bit length tree depth */ 35 uInt bb; /* bit length tree depth */
36 inflate_huft *tb; /* bit length decoding tree */ 36 inflate_huft *tb; /* bit length decoding tree */
37 } trees; /* if DTREE, decoding info for trees */ 37 } trees; /* if DTREE, decoding info for trees */
38 struct { 38 struct {
39 inflate_huft *tl, *td; /* trees to free */ 39 inflate_huft *tl, *td; /* trees to free */
40 struct inflate_codes_state 40 inflate_codes_statef
41 *codes; 41 *codes;
42 } decode; /* if CODES, current state */ 42 } decode; /* if CODES, current state */
43 } sub; /* submode */ 43 } sub; /* submode */
44 uInt last; /* true if this block is the last block */ 44 uInt last; /* true if this block is the last block */
@@ -46,15 +46,16 @@ struct inflate_blocks_state {
46 /* mode independent information */ 46 /* mode independent information */
47 uInt bitk; /* bits in bit buffer */ 47 uInt bitk; /* bits in bit buffer */
48 uLong bitb; /* bit buffer */ 48 uLong bitb; /* bit buffer */
49 Byte *window; /* sliding window */ 49 Bytef *window; /* sliding window */
50 Byte *end; /* one byte after sliding window */ 50 Bytef *end; /* one byte after sliding window */
51 Byte *read; /* window read pointer */ 51 Bytef *read; /* window read pointer */
52 Byte *write; /* window write pointer */ 52 Bytef *write; /* window write pointer */
53 check_func checkfn; /* check function */ 53 check_func checkfn; /* check function */
54 uLong check; /* check on output */ 54 uLong check; /* check on output */
55 55
56}; 56};
57 57
58
58/* defines for inflate input/output */ 59/* defines for inflate input/output */
59/* update pointers and return */ 60/* update pointers and return */
60#define UPDBITS {s->bitb=b;s->bitk=k;} 61#define UPDBITS {s->bitb=b;s->bitk=k;}
@@ -82,8 +83,8 @@ struct inflate_blocks_state {
82extern uInt inflate_mask[]; 83extern uInt inflate_mask[];
83 84
84/* copy as much as possible from the sliding window to the output area */ 85/* copy as much as possible from the sliding window to the output area */
85extern int inflate_flush __P(( 86extern int inflate_flush OF((
86 struct inflate_blocks_state *, 87 inflate_blocks_statef *,
87 z_stream *, 88 z_stream *,
88 int)); 89 int));
89 90
diff --git a/minigzip.c b/minigzip.c
index a542bfc..1aa67f2 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -19,9 +19,9 @@
19#include "zlib.h" 19#include "zlib.h"
20 20
21#ifndef __GO32__ 21#ifndef __GO32__
22extern void exit __P((int)); 22extern void exit OF((int));
23#endif 23#endif
24extern int unlink __P((const char *)); 24extern int unlink OF((const char *));
25 25
26#ifdef STDC 26#ifdef STDC
27# include <string.h> 27# include <string.h>
@@ -35,6 +35,13 @@ extern int unlink __P((const char *));
35# define SET_BINARY_MODE(file) 35# define SET_BINARY_MODE(file)
36#endif 36#endif
37 37
38#ifdef VMS
39# define GZ_SUFFIX "-gz"
40#else
41# define GZ_SUFFIX ".gz"
42#endif
43#define SUFFIX_LEN sizeof(GZ_SUFFIX)
44
38#define BUFLEN 4096 45#define BUFLEN 4096
39#define MAX_NAME_LEN 1024 46#define MAX_NAME_LEN 1024
40 47
@@ -46,12 +53,12 @@ extern int unlink __P((const char *));
46 53
47char *prog; 54char *prog;
48 55
49void error __P((char *msg)); 56void error OF((char *msg));
50void gz_compress __P((FILE *in, gzFile out)); 57void gz_compress OF((FILE *in, gzFile out));
51void gz_uncompress __P((gzFile in, FILE *out)); 58void gz_uncompress OF((gzFile in, FILE *out));
52void file_compress __P((char *file)); 59void file_compress OF((char *file));
53void file_uncompress __P((char *file)); 60void file_uncompress OF((char *file));
54void main __P((int argc, char *argv[])); 61int main OF((int argc, char *argv[]));
55 62
56/* =========================================================================== 63/* ===========================================================================
57 * Display error message and exit 64 * Display error message and exit
@@ -124,14 +131,14 @@ void file_compress(file)
124 gzFile out; 131 gzFile out;
125 132
126 strcpy(outfile, file); 133 strcpy(outfile, file);
127 strcat(outfile, ".gz"); 134 strcat(outfile, GZ_SUFFIX);
128 135
129 in = fopen(file, "rb"); 136 in = fopen(file, "rb");
130 if (in == NULL) { 137 if (in == NULL) {
131 perror(file); 138 perror(file);
132 exit(1); 139 exit(1);
133 } 140 }
134 out = gzopen(outfile, "wb"); 141 out = gzopen(outfile, "wb"); /* use "wb9" for maximal compression */
135 if (out == NULL) { 142 if (out == NULL) {
136 fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); 143 fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
137 exit(1); 144 exit(1);
@@ -156,14 +163,14 @@ void file_uncompress(file)
156 163
157 strcpy(buf, file); 164 strcpy(buf, file);
158 165
159 if (len > 3 && strcmp(file+len-3, ".gz") == 0) { 166 if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
160 infile = file; 167 infile = file;
161 outfile = buf; 168 outfile = buf;
162 outfile[len-3] = '\0'; 169 outfile[len-3] = '\0';
163 } else { 170 } else {
164 outfile = file; 171 outfile = file;
165 infile = buf; 172 infile = buf;
166 strcat(infile, ".gz"); 173 strcat(infile, GZ_SUFFIX);
167 } 174 }
168 in = gzopen(infile, "rb"); 175 in = gzopen(infile, "rb");
169 if (in == NULL) { 176 if (in == NULL) {
@@ -186,7 +193,7 @@ void file_uncompress(file)
186 * Usage: minigzip [-d] [files...] 193 * Usage: minigzip [-d] [files...]
187 */ 194 */
188 195
189void main(argc, argv) 196int main(argc, argv)
190 int argc; 197 int argc;
191 char *argv[]; 198 char *argv[];
192{ 199{
@@ -210,7 +217,7 @@ void main(argc, argv)
210 if (file == NULL) error("can't gzdopen stdin"); 217 if (file == NULL) error("can't gzdopen stdin");
211 gz_uncompress(file, stdout); 218 gz_uncompress(file, stdout);
212 } else { 219 } else {
213 file = gzdopen(fileno(stdout), "wb"); 220 file = gzdopen(fileno(stdout), "wb"); /* "wb9" for max compr. */
214 if (file == NULL) error("can't gzdopen stdout"); 221 if (file == NULL) error("can't gzdopen stdout");
215 gz_compress(stdin, file); 222 gz_compress(stdin, file);
216 } 223 }
@@ -224,4 +231,5 @@ void main(argc, argv)
224 } while (argv++, --argc); 231 } while (argv++, --argc);
225 } 232 }
226 exit(0); 233 exit(0);
234 return 0; /* to avoid warning */
227} 235}
diff --git a/trees.c b/trees.c
index 4c7c136..f6b97ff 100644
--- a/trees.c
+++ b/trees.c
@@ -110,7 +110,7 @@ local int base_dist[D_CODES];
110 110
111struct static_tree_desc_s { 111struct static_tree_desc_s {
112 ct_data *static_tree; /* static tree or NULL */ 112 ct_data *static_tree; /* static tree or NULL */
113 int *extra_bits; /* extra bits for each code or NULL */ 113 intf *extra_bits; /* extra bits for each code or NULL */
114 int extra_base; /* base index for extra_bits */ 114 int extra_base; /* base index for extra_bits */
115 int elems; /* max number of elements in the tree */ 115 int elems; /* max number of elements in the tree */
116 int max_length; /* max bit length for the codes */ 116 int max_length; /* max bit length for the codes */
@@ -129,25 +129,25 @@ local static_tree_desc static_bl_desc =
129 * Local (static) routines in this file. 129 * Local (static) routines in this file.
130 */ 130 */
131 131
132local void ct_static_init __P((void)); 132local void ct_static_init OF((void));
133local void init_block __P((deflate_state *s)); 133local void init_block OF((deflate_state *s));
134local void pqdownheap __P((deflate_state *s, ct_data *tree, int k)); 134local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
135local void gen_bitlen __P((deflate_state *s, tree_desc *desc)); 135local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
136local void gen_codes __P((ct_data *tree, int max_code, ush bl_count[])); 136local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
137local void build_tree __P((deflate_state *s, tree_desc *desc)); 137local void build_tree OF((deflate_state *s, tree_desc *desc));
138local void scan_tree __P((deflate_state *s, ct_data *tree, int max_code)); 138local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
139local void send_tree __P((deflate_state *s, ct_data *tree, int max_code)); 139local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
140local int build_bl_tree __P((deflate_state *s)); 140local int build_bl_tree OF((deflate_state *s));
141local void send_all_trees __P((deflate_state *s, int lcodes, int dcodes, 141local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
142 int blcodes)); 142 int blcodes));
143local void compress_block __P((deflate_state *s, ct_data *ltree, 143local void compress_block OF((deflate_state *s, ct_data *ltree,
144 ct_data *dtree)); 144 ct_data *dtree));
145local void set_data_type __P((deflate_state *s)); 145local void set_data_type OF((deflate_state *s));
146local void send_bits __P((deflate_state *s, int value, int length)); 146local void send_bits OF((deflate_state *s, int value, int length));
147local unsigned bi_reverse __P((unsigned value, int length)); 147local unsigned bi_reverse OF((unsigned value, int length));
148local void bi_windup __P((deflate_state *s)); 148local void bi_windup OF((deflate_state *s));
149local void copy_block __P((deflate_state *s, char *buf, unsigned len, 149local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
150 int header)); 150 int header));
151 151
152#ifndef DEBUG 152#ifndef DEBUG
153# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) 153# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
@@ -356,7 +356,7 @@ local void gen_bitlen(s, desc)
356 ct_data *tree = desc->dyn_tree; 356 ct_data *tree = desc->dyn_tree;
357 int max_code = desc->max_code; 357 int max_code = desc->max_code;
358 ct_data *stree = desc->stat_desc->static_tree; 358 ct_data *stree = desc->stat_desc->static_tree;
359 int *extra = desc->stat_desc->extra_bits; 359 intf *extra = desc->stat_desc->extra_bits;
360 int base = desc->stat_desc->extra_base; 360 int base = desc->stat_desc->extra_base;
361 int max_length = desc->stat_desc->max_length; 361 int max_length = desc->stat_desc->max_length;
362 int h; /* heap index */ 362 int h; /* heap index */
@@ -439,7 +439,7 @@ local void gen_bitlen(s, desc)
439local void gen_codes (tree, max_code, bl_count) 439local void gen_codes (tree, max_code, bl_count)
440 ct_data *tree; /* the tree to decorate */ 440 ct_data *tree; /* the tree to decorate */
441 int max_code; /* largest code with non zero frequency */ 441 int max_code; /* largest code with non zero frequency */
442 ush bl_count[]; /* number of codes at each bit length */ 442 ushf *bl_count; /* number of codes at each bit length */
443{ 443{
444 ush next_code[MAX_BITS+1]; /* next code value for each bit length */ 444 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
445 ush code = 0; /* running code value */ 445 ush code = 0; /* running code value */
@@ -487,8 +487,7 @@ local void build_tree(s, desc)
487 int elems = desc->stat_desc->elems; 487 int elems = desc->stat_desc->elems;
488 int n, m; /* iterate over heap elements */ 488 int n, m; /* iterate over heap elements */
489 int max_code = -1; /* largest code with non zero frequency */ 489 int max_code = -1; /* largest code with non zero frequency */
490 int node = elems; /* next internal node of the tree */ 490 int node; /* new node being created */
491 int new; /* new node being created */
492 491
493 /* Construct the initial heap, with least frequent element in 492 /* Construct the initial heap, with least frequent element in
494 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. 493 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
@@ -511,11 +510,11 @@ local void build_tree(s, desc)
511 * two codes of non zero frequency. 510 * two codes of non zero frequency.
512 */ 511 */
513 while (s->heap_len < 2) { 512 while (s->heap_len < 2) {
514 new = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); 513 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
515 tree[new].Freq = 1; 514 tree[node].Freq = 1;
516 s->depth[new] = 0; 515 s->depth[node] = 0;
517 s->opt_len--; if (stree) s->static_len -= stree[new].Len; 516 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
518 /* new is 0 or 1 so it does not have extra bits */ 517 /* node is 0 or 1 so it does not have extra bits */
519 } 518 }
520 desc->max_code = max_code; 519 desc->max_code = max_code;
521 520
@@ -527,6 +526,7 @@ local void build_tree(s, desc)
527 /* Construct the Huffman tree by repeatedly combining the least two 526 /* Construct the Huffman tree by repeatedly combining the least two
528 * frequent nodes. 527 * frequent nodes.
529 */ 528 */
529 node = elems; /* next internal node of the tree */
530 do { 530 do {
531 pqremove(s, tree, n); /* n = node of least frequency */ 531 pqremove(s, tree, n); /* n = node of least frequency */
532 m = s->heap[SMALLEST]; /* m = node of next least frequency */ 532 m = s->heap[SMALLEST]; /* m = node of next least frequency */
@@ -727,7 +727,7 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
727 */ 727 */
728void ct_stored_block(s, buf, stored_len, eof) 728void ct_stored_block(s, buf, stored_len, eof)
729 deflate_state *s; 729 deflate_state *s;
730 char *buf; /* input block */ 730 charf *buf; /* input block */
731 ulg stored_len; /* length of input block */ 731 ulg stored_len; /* length of input block */
732 int eof; /* true if this is the last block for a file */ 732 int eof; /* true if this is the last block for a file */
733{ 733{
@@ -756,7 +756,7 @@ void ct_align(s)
756 */ 756 */
757ulg ct_flush_block(s, buf, stored_len, eof) 757ulg ct_flush_block(s, buf, stored_len, eof)
758 deflate_state *s; 758 deflate_state *s;
759 char *buf; /* input block, or NULL if too old */ 759 charf *buf; /* input block, or NULL if too old */
760 ulg stored_len; /* length of input block */ 760 ulg stored_len; /* length of input block */
761 int eof; /* true if this is the last block for a file */ 761 int eof; /* true if this is the last block for a file */
762{ 762{
@@ -804,7 +804,7 @@ ulg ct_flush_block(s, buf, stored_len, eof)
804 if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) { 804 if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
805# endif 805# endif
806 /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ 806 /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
807 if (buf == (char*)0) error ("block vanished"); 807 if (buf == (charf*)0) error ("block vanished");
808 808
809 copy_block(buf, (unsigned)stored_len, 0); /* without header */ 809 copy_block(buf, (unsigned)stored_len, 0); /* without header */
810 s->compressed_len = stored_len << 3; 810 s->compressed_len = stored_len << 3;
@@ -1049,7 +1049,7 @@ local void bi_windup(s)
1049 */ 1049 */
1050local void copy_block(s, buf, len, header) 1050local void copy_block(s, buf, len, header)
1051 deflate_state *s; 1051 deflate_state *s;
1052 char *buf; /* the input data */ 1052 charf *buf; /* the input data */
1053 unsigned len; /* its length */ 1053 unsigned len; /* its length */
1054 int header; /* true if block header must be written */ 1054 int header; /* true if block header must be written */
1055{ 1055{
diff --git a/uncompr.c b/uncompr.c
index c76286c..b423696 100644
--- a/uncompr.c
+++ b/uncompr.c
@@ -23,9 +23,9 @@
23 buffer, or Z_DATA_ERROR if the input data was corrupted. 23 buffer, or Z_DATA_ERROR if the input data was corrupted.
24*/ 24*/
25int uncompress (dest, destLen, source, sourceLen) 25int uncompress (dest, destLen, source, sourceLen)
26 Byte *dest; 26 Bytef *dest;
27 uLong *destLen; 27 uLongf *destLen;
28 Byte *source; 28 Bytef *source;
29 uLong sourceLen; 29 uLong sourceLen;
30{ 30{
31 z_stream stream; 31 z_stream stream;
diff --git a/zconf.h b/zconf.h
index a819c8b..92fdbbc 100644
--- a/zconf.h
+++ b/zconf.h
@@ -28,14 +28,24 @@
28#if defined(MSDOS) && !defined(__32BIT__) 28#if defined(MSDOS) && !defined(__32BIT__)
29# define MAXSEG_64K 29# define MAXSEG_64K
30#endif 30#endif
31#ifdef MSDOS
32# define UNALIGNED_OK
33#endif
34
31#ifndef STDC 35#ifndef STDC
32# if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus) 36# if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
33# define STDC 37# define STDC
34# endif 38# endif
35#endif 39#endif
36 40
37#if !defined(STDC) && !defined(const) 41#ifndef STDC
38# define const 42# ifndef const
43# define const
44# endif
45#endif
46
47#ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
48# include <unix.h>
39#endif 49#endif
40 50
41/* Maximum value for memLevel in deflateInit2 */ 51/* Maximum value for memLevel in deflateInit2 */
@@ -67,29 +77,44 @@
67 77
68 /* Type declarations */ 78 /* Type declarations */
69 79
70#ifndef __P /* function prototypes */ 80#ifndef OF /* function prototypes */
71# ifdef STDC 81# ifdef STDC
72# define __P(args) args 82# define OF(args) args
73# else 83# else
74# define __P(args) () 84# define OF(args) ()
75# endif 85# endif
76#endif 86#endif
77 87
78#ifndef Byte 88#if defined(M_I86SM) || defined(M_I86MM) /* model independent MSC functions */
79 typedef unsigned char Byte; /* 8 bits */ 89# define zstrcpy _fstrcpy
80#endif 90# define zstrcat _fstrcat
81#ifndef uInt 91# define zstrlen _fstrlen
82 typedef unsigned int uInt; /* 16 bits or more */ 92# define zstrcmp _fstrcmp
93# define FAR __far
94#else
95# define zstrcpy strcpy
96# define zstrcat strcat
97# define zstrlen strlen
98# define zstrcmp strcmp
99# define FAR
83#endif 100#endif
84#ifndef uLong 101
85 typedef unsigned long uLong; /* 32 bits or more */ 102typedef unsigned char Byte; /* 8 bits */
86#endif 103typedef unsigned int uInt; /* 16 bits or more */
87#ifndef voidp 104typedef unsigned long uLong; /* 32 bits or more */
88# ifdef STDC 105
89 typedef void *voidp; 106typedef Byte FAR Bytef;
90# else 107typedef char FAR charf;
91 typedef Byte *voidp; 108typedef int FAR intf;
92# endif 109typedef uInt FAR uIntf;
110typedef uLong FAR uLongf;
111
112#ifdef STDC
113 typedef void FAR *voidp;
114 typedef void *voidnp;
115#else
116 typedef Byte FAR *voidp;
117 typedef Byte *voidnp;
93#endif 118#endif
94 119
95#endif /* _ZCONF_H */ 120#endif /* _ZCONF_H */
diff --git a/zlib.h b/zlib.h
index d27173d..56ad7f7 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 0.93 June 25th, 1995. 2 version 0.94, Aug 13th, 1995.
3 3
4 Copyright (C) 1995 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995 Jean-loup Gailly and Mark Adler
5 5
@@ -28,7 +28,7 @@
28 28
29#include "zconf.h" 29#include "zconf.h"
30 30
31#define ZLIB_VERSION "0.93" 31#define ZLIB_VERSION "0.94"
32 32
33/* 33/*
34 The 'zlib' compression library provides in-memory compression and 34 The 'zlib' compression library provides in-memory compression and
@@ -49,22 +49,22 @@
49 (providing more output space) before each call. 49 (providing more output space) before each call.
50*/ 50*/
51 51
52typedef voidp (*alloc_func) __P((voidp opaque, uInt items, uInt size)); 52typedef voidp (*alloc_func) OF((voidp opaque, uInt items, uInt size));
53typedef void (*free_func) __P((voidp opaque, voidp address)); 53typedef void (*free_func) OF((voidp opaque, voidp address));
54 54
55struct internal_state; 55struct internal_state;
56 56
57typedef struct z_stream_s { 57typedef struct z_stream_s {
58 Byte *next_in; /* next input byte */ 58 Bytef *next_in; /* next input byte */
59 uInt avail_in; /* number of bytes available at next_in */ 59 uInt avail_in; /* number of bytes available at next_in */
60 uLong total_in; /* total nb of input bytes read so far */ 60 uLong total_in; /* total nb of input bytes read so far */
61 61
62 Byte *next_out; /* next output byte should be put there */ 62 Bytef *next_out; /* next output byte should be put there */
63 uInt avail_out; /* remaining free space at next_out */ 63 uInt avail_out; /* remaining free space at next_out */
64 uLong total_out; /* total nb of bytes output so far */ 64 uLong total_out; /* total nb of bytes output so far */
65 65
66 char *msg; /* last error message, NULL if no error */ 66 char *msg; /* last error message, NULL if no error */
67 struct internal_state *state; /* not visible by applications */ 67 struct internal_state FAR *state; /* not visible by applications */
68 68
69 alloc_func zalloc; /* used to allocate the internal state */ 69 alloc_func zalloc; /* used to allocate the internal state */
70 free_func zfree; /* used to free the internal state */ 70 free_func zfree; /* used to free the internal state */
@@ -145,7 +145,7 @@ extern char *zlib_version;
145 145
146 /* basic functions */ 146 /* basic functions */
147 147
148extern int deflateInit __P((z_stream *strm, int level)); 148extern int deflateInit OF((z_stream *strm, int level));
149/* 149/*
150 Initializes the internal stream state for compression. The fields 150 Initializes the internal stream state for compression. The fields
151 zalloc, zfree and opaque must be initialized before by the caller. 151 zalloc, zfree and opaque must be initialized before by the caller.
@@ -164,7 +164,7 @@ extern int deflateInit __P((z_stream *strm, int level));
164*/ 164*/
165 165
166 166
167extern int deflate __P((z_stream *strm, int flush)); 167extern int deflate OF((z_stream *strm, int flush));
168/* 168/*
169 Performs one or both of the following actions: 169 Performs one or both of the following actions:
170 170
@@ -195,7 +195,10 @@ extern int deflate __P((z_stream *strm, int flush));
195 is useful to allow the decompressor to synchronize if one compressed block 195 is useful to allow the decompressor to synchronize if one compressed block
196 has been damaged (see inflateSync below). Flushing degrades compression and 196 has been damaged (see inflateSync below). Flushing degrades compression and
197 so should be used only when necessary. Using Z_FULL_FLUSH too often can 197 so should be used only when necessary. Using Z_FULL_FLUSH too often can
198 seriously degrade the compression. 198 seriously degrade the compression. If deflate returns with avail_out == 0,
199 this function must be called again with the same value of the flush
200 parameter and more output space (updated avail_out), until the flush is
201 complete (deflate returns with non-zero avail_out).
199 202
200 If the parameter flush is set to Z_FINISH, all pending input is processed, 203 If the parameter flush is set to Z_FINISH, all pending input is processed,
201 all pending output is flushed and deflate returns with Z_STREAM_END if there 204 all pending output is flushed and deflate returns with Z_STREAM_END if there
@@ -223,7 +226,7 @@ extern int deflate __P((z_stream *strm, int flush));
223*/ 226*/
224 227
225 228
226extern int deflateEnd __P((z_stream *strm)); 229extern int deflateEnd OF((z_stream *strm));
227/* 230/*
228 All dynamically allocated data structures for this stream are freed. 231 All dynamically allocated data structures for this stream are freed.
229 This function discards any unprocessed input and does not flush any 232 This function discards any unprocessed input and does not flush any
@@ -235,11 +238,11 @@ extern int deflateEnd __P((z_stream *strm));
235*/ 238*/
236 239
237 240
238extern int inflateInit __P((z_stream *strm)); 241extern int inflateInit OF((z_stream *strm));
239/* 242/*
240 Initializes the internal stream state for decompression. The fields 243 Initializes the internal stream state for decompression. The fields
241 zalloc and zfree must be initialized before by the caller. If zalloc and 244 zalloc and zfree must be initialized before by the caller. If zalloc and
242 zfree are set to Z_NULL, deflateInit updates them to use default allocation 245 zfree are set to Z_NULL, inflateInit updates them to use default allocation
243 functions. 246 functions.
244 247
245 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 248 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
@@ -249,7 +252,7 @@ extern int inflateInit __P((z_stream *strm));
249*/ 252*/
250 253
251 254
252extern int inflate __P((z_stream *strm, int flush)); 255extern int inflate OF((z_stream *strm, int flush));
253/* 256/*
254 Performs one or both of the following actions: 257 Performs one or both of the following actions:
255 258
@@ -260,7 +263,7 @@ extern int inflate __P((z_stream *strm, int flush));
260 263
261 - Provide more output starting at next_out and update next_out and avail_out 264 - Provide more output starting at next_out and update next_out and avail_out
262 accordingly. inflate() always provides as much output as possible 265 accordingly. inflate() always provides as much output as possible
263 (until no more input data or no more space in the output buffer). 266 (until there is no more input data or no more space in the output buffer).
264 267
265 Before the call of inflate(), the application should ensure that at least 268 Before the call of inflate(), the application should ensure that at least
266 one of the actions is possible, by providing more input and/or consuming 269 one of the actions is possible, by providing more input and/or consuming
@@ -282,7 +285,9 @@ extern int inflate __P((z_stream *strm, int flush));
282 output is flushed; avail_out must be large enough to hold all the 285 output is flushed; avail_out must be large enough to hold all the
283 uncompressed data. (The size of the uncompressed data may have been saved 286 uncompressed data. (The size of the uncompressed data may have been saved
284 by the compressor for this purpose.) The next operation on this stream must 287 by the compressor for this purpose.) The next operation on this stream must
285 be inflateEnd to deallocate the decompression state. 288 be inflateEnd to deallocate the decompression state. The use of Z_FINISH
289 is never required, but can be used to inform inflate that a faster routine
290 may be used for the single inflate() call.
286 291
287 inflate() returns Z_OK if some progress has been made (more input 292 inflate() returns Z_OK if some progress has been made (more input
288 processed or more output produced), Z_STREAM_END if the end of the 293 processed or more output produced), Z_STREAM_END if the end of the
@@ -296,7 +301,7 @@ extern int inflate __P((z_stream *strm, int flush));
296*/ 301*/
297 302
298 303
299extern int inflateEnd __P((z_stream *strm)); 304extern int inflateEnd OF((z_stream *strm));
300/* 305/*
301 All dynamically allocated data structures for this stream are freed. 306 All dynamically allocated data structures for this stream are freed.
302 This function discards any unprocessed input and does not flush any 307 This function discards any unprocessed input and does not flush any
@@ -313,12 +318,12 @@ extern int inflateEnd __P((z_stream *strm));
313 The following functions are needed only in some special applications. 318 The following functions are needed only in some special applications.
314*/ 319*/
315 320
316extern int deflateInit2 __P((z_stream *strm, 321extern int deflateInit2 OF((z_stream *strm,
317 int level, 322 int level,
318 int method, 323 int method,
319 int windowBits, 324 int windowBits,
320 int memLevel, 325 int memLevel,
321 int strategy)); 326 int strategy));
322/* 327/*
323 This is another version of deflateInit with more compression options. The 328 This is another version of deflateInit with more compression options. The
324 fields next_in, zalloc and zfree must be initialized before by the caller. 329 fields next_in, zalloc and zfree must be initialized before by the caller.
@@ -368,8 +373,8 @@ extern int deflateInit2 __P((z_stream *strm,
368 deflate(). 373 deflate().
369*/ 374*/
370 375
371extern int deflateCopy __P((z_stream *dest, 376extern int deflateCopy OF((z_stream *dest,
372 z_stream *source)); 377 z_stream *source));
373/* 378/*
374 Sets the destination stream as a complete copy of the source stream. If 379 Sets the destination stream as a complete copy of the source stream. If
375 the source stream is using an application-supplied history buffer, a new 380 the source stream is using an application-supplied history buffer, a new
@@ -391,7 +396,7 @@ extern int deflateCopy __P((z_stream *dest,
391 destination. 396 destination.
392*/ 397*/
393 398
394extern int deflateReset __P((z_stream *strm)); 399extern int deflateReset OF((z_stream *strm));
395/* 400/*
396 This function is equivalent to deflateEnd followed by deflateInit, 401 This function is equivalent to deflateEnd followed by deflateInit,
397 but does not free and reallocate all the internal compression state. 402 but does not free and reallocate all the internal compression state.
@@ -402,8 +407,8 @@ extern int deflateReset __P((z_stream *strm));
402 stream state was inconsistent (such as zalloc or state being NULL). 407 stream state was inconsistent (such as zalloc or state being NULL).
403*/ 408*/
404 409
405extern int inflateInit2 __P((z_stream *strm, 410extern int inflateInit2 OF((z_stream *strm,
406 int windowBits)); 411 int windowBits));
407/* 412/*
408 This is another version of inflateInit with more compression options. The 413 This is another version of inflateInit with more compression options. The
409 fields next_out, zalloc and zfree must be initialized before by the caller. 414 fields next_out, zalloc and zfree must be initialized before by the caller.
@@ -431,11 +436,11 @@ extern int inflateInit2 __P((z_stream *strm,
431 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 436 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
432 not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as 437 not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
433 windowBits < 8). msg is set to null if there is no error message. 438 windowBits < 8). msg is set to null if there is no error message.
434 inflateInit2 does not perform any compression: this will be done by 439 inflateInit2 does not perform any decompression: this will be done by
435 inflate(). 440 inflate().
436*/ 441*/
437 442
438extern int inflateSync __P((z_stream *strm)); 443extern int inflateSync OF((z_stream *strm));
439/* 444/*
440 Skips invalid compressed data until the special marker (see deflate() 445 Skips invalid compressed data until the special marker (see deflate()
441 above) can be found, or until all available input is skipped. No output 446 above) can be found, or until all available input is skipped. No output
@@ -450,7 +455,7 @@ extern int inflateSync __P((z_stream *strm));
450 until success or end of the input data. 455 until success or end of the input data.
451*/ 456*/
452 457
453extern int inflateReset __P((z_stream *strm)); 458extern int inflateReset OF((z_stream *strm));
454/* 459/*
455 This function is equivalent to inflateEnd followed by inflateInit, 460 This function is equivalent to inflateEnd followed by inflateInit,
456 but does not free and reallocate all the internal decompression state. 461 but does not free and reallocate all the internal decompression state.
@@ -471,8 +476,8 @@ extern int inflateReset __P((z_stream *strm));
471 utility functions can easily be modified if you need special options. 476 utility functions can easily be modified if you need special options.
472*/ 477*/
473 478
474extern int compress __P((Byte *dest, uLong *destLen, 479extern int compress OF((Bytef *dest, uLongf *destLen,
475 Byte *source, uLong sourceLen)); 480 Bytef *source, uLong sourceLen));
476/* 481/*
477 Compresses the source buffer into the destination buffer. sourceLen is 482 Compresses the source buffer into the destination buffer. sourceLen is
478 the byte length of the source buffer. Upon entry, destLen is the total 483 the byte length of the source buffer. Upon entry, destLen is the total
@@ -486,8 +491,8 @@ extern int compress __P((Byte *dest, uLong *destLen,
486 buffer. 491 buffer.
487*/ 492*/
488 493
489extern int uncompress __P((Byte *dest, uLong *destLen, 494extern int uncompress OF((Bytef *dest, uLongf *destLen,
490 Byte *source, uLong sourceLen)); 495 Bytef *source, uLong sourceLen));
491/* 496/*
492 Decompresses the source buffer into the destination buffer. sourceLen is 497 Decompresses the source buffer into the destination buffer. sourceLen is
493 the byte length of the source buffer. Upon entry, destLen is the total 498 the byte length of the source buffer. Upon entry, destLen is the total
@@ -505,21 +510,21 @@ extern int uncompress __P((Byte *dest, uLong *destLen,
505*/ 510*/
506 511
507 512
508typedef voidp gzFile; 513typedef voidnp gzFile;
509 514
510extern gzFile gzopen __P((char *path, char *mode)); 515extern gzFile gzopen OF((char *path, char *mode));
511/* 516/*
512 Opens a gzip (.gz) file for reading or writing. The mode parameter 517 Opens a gzip (.gz) file for reading or writing. The mode parameter
513 is as in fopen ("rb" or "wb"). gzopen can also be used to read a file 518 is as in fopen ("rb" or "wb") but can also include a compression level
514 which is not in gzip format; in this case gzread will directly read from 519 ("wb9"). gzopen can be used to read a file which is not in gzip format;
515 the file without decompression. 520 in this case gzread will directly read from the file without decompression.
516 gzopen returns NULL if the file could not be opened or if there was 521 gzopen returns NULL if the file could not be opened or if there was
517 insufficient memory to allocate the (de)compression state; errno 522 insufficient memory to allocate the (de)compression state; errno
518 can be checked to distinguish the two cases (if errno is zero, the 523 can be checked to distinguish the two cases (if errno is zero, the
519 zlib error is Z_MEM_ERROR). 524 zlib error is Z_MEM_ERROR).
520*/ 525*/
521 526
522extern gzFile gzdopen __P((int fd, char *mode)); 527extern gzFile gzdopen OF((int fd, char *mode));
523/* 528/*
524 gzdopen() associates a gzFile with the file descriptor fd. File 529 gzdopen() associates a gzFile with the file descriptor fd. File
525 descriptors are obtained from calls like open, dup, creat, or pipe. 530 descriptors are obtained from calls like open, dup, creat, or pipe.
@@ -528,7 +533,7 @@ extern gzFile gzdopen __P((int fd, char *mode));
528 the (de)compression state. 533 the (de)compression state.
529*/ 534*/
530 535
531extern int gzread __P((gzFile file, voidp buf, unsigned len)); 536extern int gzread OF((gzFile file, voidnp buf, unsigned len));
532/* 537/*
533 Reads the given number of uncompressed bytes from the compressed file. 538 Reads the given number of uncompressed bytes from the compressed file.
534 If the input file was not in gzip format, gzread copies the given number 539 If the input file was not in gzip format, gzread copies the given number
@@ -536,14 +541,14 @@ extern int gzread __P((gzFile file, voidp buf, unsigned len));
536 gzread returns the number of uncompressed bytes actually read (0 for 541 gzread returns the number of uncompressed bytes actually read (0 for
537 end of file, -1 for error). */ 542 end of file, -1 for error). */
538 543
539extern int gzwrite __P((gzFile file, voidp buf, unsigned len)); 544extern int gzwrite OF((gzFile file, voidnp buf, unsigned len));
540/* 545/*
541 Writes the given number of uncompressed bytes into the compressed file. 546 Writes the given number of uncompressed bytes into the compressed file.
542 gzwrite returns the number of uncompressed bytes actually written 547 gzwrite returns the number of uncompressed bytes actually written
543 (0 in case of error). 548 (0 in case of error).
544*/ 549*/
545 550
546extern int gzflush __P((gzFile file, int flush)); 551extern int gzflush OF((gzFile file, int flush));
547/* 552/*
548 Flushes all pending output into the compressed file. The parameter 553 Flushes all pending output into the compressed file. The parameter
549 flush is as in the deflate() function. The return value is the zlib 554 flush is as in the deflate() function. The return value is the zlib
@@ -553,14 +558,14 @@ extern int gzflush __P((gzFile file, int flush));
553 degrade compression. 558 degrade compression.
554*/ 559*/
555 560
556extern int gzclose __P((gzFile file)); 561extern int gzclose OF((gzFile file));
557/* 562/*
558 Flushes all pending output if necessary, closes the compressed file 563 Flushes all pending output if necessary, closes the compressed file
559 and deallocates all the (de)compression state. The return value is the zlib 564 and deallocates all the (de)compression state. The return value is the zlib
560 error number (see function gzerror below). 565 error number (see function gzerror below).
561*/ 566*/
562 567
563extern char* gzerror __P((gzFile file, int *errnum)); 568extern char* gzerror OF((gzFile file, int *errnum));
564/* 569/*
565 Returns the error message for the last error which occurred on the 570 Returns the error message for the last error which occurred on the
566 given compressed file. errnum is set to zlib error number. If an 571 given compressed file. errnum is set to zlib error number. If an
@@ -577,7 +582,8 @@ extern char* gzerror __P((gzFile file, int *errnum));
577 compression library. 582 compression library.
578*/ 583*/
579 584
580extern uLong adler32 __P((uLong adler, Byte *buf, uInt len)); 585extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
586
581/* 587/*
582 Update a running Adler-32 checksum with the bytes buf[0..len-1] and 588 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
583 return the updated checksum. If buf is NULL, this function returns 589 return the updated checksum. If buf is NULL, this function returns
@@ -593,7 +599,7 @@ extern uLong adler32 __P((uLong adler, Byte *buf, uInt len));
593 if (adler != original_adler) error(); 599 if (adler != original_adler) error();
594*/ 600*/
595 601
596extern uLong crc32 __P((uLong crc, Byte *buf, uInt len)); 602extern uLong crc32 OF((uLong crc, Bytef *buf, uInt len));
597/* 603/*
598 Update a running crc with the bytes buf[0..len-1] and return the updated 604 Update a running crc with the bytes buf[0..len-1] and return the updated
599 crc. If buf is NULL, this function returns the required initial value 605 crc. If buf is NULL, this function returns the required initial value
diff --git a/zutil.c b/zutil.c
index 2cddcff..1dce6fb 100644
--- a/zutil.c
+++ b/zutil.c
@@ -9,8 +9,10 @@
9 9
10#include "zutil.h" 10#include "zutil.h"
11 11
12struct internal_state {int dummy;}; /* for buggy compilers */
13
12#ifndef __GO32__ 14#ifndef __GO32__
13extern void exit __P((int)); 15extern void exit OF((int));
14#endif 16#endif
15 17
16char *zlib_version = ZLIB_VERSION; 18char *zlib_version = ZLIB_VERSION;
@@ -129,7 +131,7 @@ void zcfree (voidp opaque, voidp ptr)
129} 131}
130#endif /* __TURBOC__ */ 132#endif /* __TURBOC__ */
131 133
132#if defined(M_I86CM) || defined(M_I86LM) /* MSC compact or large model */ 134#if defined(MSDOS) && !defined(__TURBOC__) /* MSC */
133 135
134# define MY_ZCALLOC 136# define MY_ZCALLOC
135 137
@@ -150,14 +152,14 @@ void zcfree (voidp opaque, voidp ptr)
150 _hfree(ptr); 152 _hfree(ptr);
151} 153}
152 154
153#endif /* defined(M_I86CM) || defined(M_I86LM) */ 155#endif /* MSC */
154 156
155 157
156#ifndef MY_ZCALLOC /* Any system without a special alloc function */ 158#ifndef MY_ZCALLOC /* Any system without a special alloc function */
157 159
158#ifndef __GO32__ 160#ifndef __GO32__
159extern voidp calloc __P((uInt items, uInt size)); 161extern voidp calloc OF((uInt items, uInt size));
160extern void free __P((voidp ptr)); 162extern void free OF((voidp ptr));
161#endif 163#endif
162 164
163voidp zcalloc (opaque, items, size) 165voidp zcalloc (opaque, items, size)
diff --git a/zutil.h b/zutil.h
index fc54d57..053eb8c 100644
--- a/zutil.h
+++ b/zutil.h
@@ -15,11 +15,7 @@
15 15
16#include "zlib.h" 16#include "zlib.h"
17 17
18/* #ifndef __GNUC__ disable inline for now */ 18#if defined(MSDOS) || defined(VMS)
19# define inline
20/* #endif */
21
22#ifdef MSDOS
23# include <stddef.h> 19# include <stddef.h>
24# include <errno.h> 20# include <errno.h>
25#else 21#else
@@ -35,7 +31,9 @@
35/* compile with -Dlocal if your debugger can't find static symbols */ 31/* compile with -Dlocal if your debugger can't find static symbols */
36 32
37typedef unsigned char uch; 33typedef unsigned char uch;
34typedef uch FAR uchf;
38typedef unsigned short ush; 35typedef unsigned short ush;
36typedef ush FAR ushf;
39typedef unsigned long ulg; 37typedef unsigned long ulg;
40 38
41extern char *z_errmsg[]; /* indexed by 1-zlib_error */ 39extern char *z_errmsg[]; /* indexed by 1-zlib_error */
@@ -47,7 +45,9 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
47 45
48#define DEFLATED 8 46#define DEFLATED 8
49 47
50#define DEF_WBITS 15 48#ifndef DEF_WBITS
49# define DEF_WBITS 15
50#endif
51/* default windowBits for decompression. MAX_WBITS is for compression only */ 51/* default windowBits for decompression. MAX_WBITS is for compression only */
52 52
53#if MAX_MEM_LEVEL >= 8 53#if MAX_MEM_LEVEL >= 8
@@ -124,7 +124,7 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
124 /* functions */ 124 /* functions */
125 125
126#ifdef HAVE_STRERROR 126#ifdef HAVE_STRERROR
127 extern char *strerror __P((int)); 127 extern char *strerror OF((int));
128# define zstrerror(errnum) strerror(errnum) 128# define zstrerror(errnum) strerror(errnum)
129#else 129#else
130# define zstrerror(errnum) "" 130# define zstrerror(errnum) ""
@@ -137,11 +137,16 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
137# define HAVE_MEMCPY 137# define HAVE_MEMCPY
138#endif 138#endif
139#ifdef HAVE_MEMCPY 139#ifdef HAVE_MEMCPY
140# define zmemcpy memcpy 140# ifdef M_I86MM /* MSC medium model */
141# define zmemzero(dest, len) memset(dest, 0, len) 141# define zmemcpy _fmemcpy
142# define zmemzero(dest, len) _fmemset(dest, 0, len)
143# else
144# define zmemcpy memcpy
145# define zmemzero(dest, len) memset(dest, 0, len)
146# endif
142#else 147#else
143 extern void zmemcpy __P((Byte* dest, Byte* source, uInt len)); 148 extern void zmemcpy OF((Byte* dest, Byte* source, uInt len));
144 extern void zmemzero __P((Byte* dest, uInt len)); 149 extern void zmemzero OF((Byte* dest, uInt len));
145#endif 150#endif
146 151
147/* Diagnostic functions */ 152/* Diagnostic functions */
@@ -166,12 +171,12 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
166#endif 171#endif
167 172
168 173
169typedef uLong (*check_func) __P((uLong check, Byte *buf, uInt len)); 174typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
170 175
171extern void z_error __P((char *m)); 176extern void z_error OF((char *m));
172 177
173voidp zcalloc __P((voidp opaque, unsigned items, unsigned size)); 178voidp zcalloc OF((voidp opaque, unsigned items, unsigned size));
174void zcfree __P((voidp opaque, voidp ptr)); 179void zcfree OF((voidp opaque, voidp ptr));
175 180
176#define ZALLOC(strm, items, size) \ 181#define ZALLOC(strm, items, size) \
177 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 182 (*((strm)->zalloc))((strm)->opaque, (items), (size))