diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:13:27 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:13:27 -0700 |
commit | 8a2acbffc86012de3523ecf91db2c4ea1b1c4ea2 (patch) | |
tree | c461eb314065024b6cb87d136e107dca2cc09a33 | |
parent | 56bcb184fac036a45cb8937238d51778d0a796aa (diff) | |
download | zlib-1.0-pre.tar.gz zlib-1.0-pre.tar.bz2 zlib-1.0-pre.zip |
zlib 1.0-prev1.0-pre
-rw-r--r-- | ChangeLog | 45 | ||||
-rw-r--r-- | Makefile | 121 | ||||
-rw-r--r-- | Makefile.bor | 2 | ||||
-rw-r--r-- | Makefile.in | 130 | ||||
-rw-r--r-- | Makefile.qnx | 75 | ||||
-rw-r--r-- | README | 70 | ||||
-rw-r--r-- | adler32.c | 4 | ||||
-rw-r--r-- | compress.c | 6 | ||||
-rwxr-xr-x | configure | 81 | ||||
-rw-r--r-- | crc32.c | 60 | ||||
-rw-r--r-- | deflate.c | 194 | ||||
-rw-r--r-- | deflate.h | 25 | ||||
-rw-r--r-- | example.c | 122 | ||||
-rw-r--r-- | gzio.c | 363 | ||||
-rw-r--r-- | infblock.c | 23 | ||||
-rw-r--r-- | infblock.h | 8 | ||||
-rw-r--r-- | infcodes.c | 9 | ||||
-rw-r--r-- | infcodes.h | 2 | ||||
-rw-r--r-- | inffast.c | 9 | ||||
-rw-r--r-- | inffast.h | 2 | ||||
-rw-r--r-- | inflate.c | 94 | ||||
-rw-r--r-- | inftrees.c | 26 | ||||
-rw-r--r-- | inftrees.h | 2 | ||||
-rw-r--r-- | infutil.c | 8 | ||||
-rw-r--r-- | infutil.h | 27 | ||||
-rw-r--r-- | minigzip.c | 12 | ||||
-rw-r--r-- | trees.c | 34 | ||||
-rw-r--r-- | uncompr.c | 6 | ||||
-rw-r--r-- | zconf.h | 57 | ||||
-rw-r--r-- | zlib.h | 187 | ||||
-rw-r--r-- | zutil.c | 42 | ||||
-rw-r--r-- | zutil.h | 20 |
32 files changed, 590 insertions, 1276 deletions
@@ -2,32 +2,19 @@ | |||
2 | ChangeLog file for zlib | 2 | ChangeLog file for zlib |
3 | 3 | ||
4 | Changes in 1.0 (15 Jan 96) | 4 | Changes in 1.0 (15 Jan 96) |
5 | - allow preset dictionary shared between compressor and decompressor | ||
6 | - allow compression level 0 (no compression) | ||
7 | - add deflateParams in zlib.h: allow dynamic change of compression level | ||
8 | and compression strategy. | ||
9 | - test large buffers and deflateParams in example.c | ||
10 | - add optional "configure" to build zlib as a shared library | ||
11 | - suppress Makefile.qnx, use configure instead | ||
12 | - fixed deflate for 64-bit systems (detected on Cray) | 5 | - fixed deflate for 64-bit systems (detected on Cray) |
13 | - fixed inflate_blocks for 64-bit systems (detected on Alpha) | 6 | - fixed inflate_blocks for 64-bit systems (detected on Alpha) |
14 | - declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) | ||
15 | - always return Z_BUF_ERROR when deflate() has nothing to do | ||
16 | - deflateInit and inflateInit are now macros to allow version checking | ||
17 | - prefix all global functions and types with z_ with -DZ_PREFIX | ||
18 | - make falloc completely reentrant (inftrees.c) | 7 | - make falloc completely reentrant (inftrees.c) |
19 | - fixed very unlikely race condition in ct_static_init | 8 | - fixed very unlikely race condition in ct_static_init |
20 | - free in reverse order of allocation to help memory manager | 9 | - always return Z_BUF_ERROR when deflate() has nothing to do |
21 | - use zlib-1.0/* instead of zlib/* inside the tar.gz | 10 | - add deflateParams in zlib.h. |
22 | - make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith | 11 | - test large buffers and deflateParams in example.c |
23 | -Wconversion -Wstrict-prototypes -Wmissing-prototypes" | 12 | - declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) |
24 | - allow gzread on concatenated .gz files | ||
25 | - deflateEnd now returns Z_DATA_ERROR if it was premature | ||
26 | - deflate is finally (?) fully deterministic (no matches beyond end of input) | ||
27 | - Document Z_SYNC_FLUSH | 13 | - Document Z_SYNC_FLUSH |
28 | - add uninstall in Makefile | 14 | - added deflateGetAdler32 and deflateSetAdler32 |
15 | - free in reverse order of allocation to help memory manager | ||
29 | - Check for __cpluplus in zlib.h | 16 | - Check for __cpluplus in zlib.h |
30 | - Better test in ct_align for partial flush | 17 | - Finer test in ct_align for partial flush |
31 | - avoid harmless warnings for Borland C++ | 18 | - avoid harmless warnings for Borland C++ |
32 | - initialize hash_head in deflate.c | 19 | - initialize hash_head in deflate.c |
33 | - avoid warning on fdopen (gzio.c) for HP cc -Aa | 20 | - avoid warning on fdopen (gzio.c) for HP cc -Aa |
@@ -36,7 +23,7 @@ Changes in 1.0 (15 Jan 96) | |||
36 | - ignore error if ranlib doesn't exist | 23 | - ignore error if ranlib doesn't exist |
37 | - call ranlib twice for NeXTSTEP | 24 | - call ranlib twice for NeXTSTEP |
38 | - use exec_prefix instead of prefix for libz.a | 25 | - use exec_prefix instead of prefix for libz.a |
39 | - renamed ct_* as _tr_* to avoid conflict with applications | 26 | - renamed ct_* as tr_* to avoid conflict with another application. |
40 | - clear z->msg in inflateInit2 before any error return | 27 | - clear z->msg in inflateInit2 before any error return |
41 | - initialize opaque in example.c, gzio.c, deflate.c and inflate.c | 28 | - initialize opaque in example.c, gzio.c, deflate.c and inflate.c |
42 | - fixed typo in zconf.h (_GNUC__ => __GNUC__) | 29 | - fixed typo in zconf.h (_GNUC__ => __GNUC__) |
@@ -45,22 +32,6 @@ Changes in 1.0 (15 Jan 96) | |||
45 | - in fcalloc, normalize pointer if size > 65520 bytes | 32 | - in fcalloc, normalize pointer if size > 65520 bytes |
46 | - don't use special fcalloc for 32 bit Borland C++ | 33 | - don't use special fcalloc for 32 bit Borland C++ |
47 | - use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... | 34 | - use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... |
48 | - use Z_BINARY instead of BINARY | ||
49 | - document that gzclose after gzdopen will close the file | ||
50 | - allow "a" as mode in gzopen. | ||
51 | - fix error checking in gzread | ||
52 | - allow skipping .gz extra-field on pipes | ||
53 | - added reference to Perl interface in README | ||
54 | - put the crc table in FAR data (I dislike more and more the medium model :) | ||
55 | - added get_crc_table | ||
56 | - added a dimension to all arrays (Borland C can't count). | ||
57 | - workaround Borland C bug in declaration of inflate_codes_new & inflate_fast | ||
58 | - guard against multiple inclusion of *.h (for precompiled header on Mac) | ||
59 | - Watcom C pretends to be Microsoft C small model even in 32 bit mode. | ||
60 | - don't use unsized arrays to avoid silly warnings by Visual C++: | ||
61 | warning C4746: 'inflate_mask' : unsized array treated as '__far' | ||
62 | (what's wrong with far data in far model?). | ||
63 | - define enum out of inflate_blocks_state to allow compilation with C++ | ||
64 | 35 | ||
65 | Changes in 0.95 (16 Aug 95) | 36 | Changes in 0.95 (16 Aug 95) |
66 | - fix MSDOS small and medium model (now easier to adapt to any compiler) | 37 | - fix MSDOS small and medium model (now easier to adapt to any compiler) |
@@ -2,129 +2,78 @@ | |||
2 | # Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | # Copyright (C) 1995-1996 Jean-loup Gailly. |
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 | # To compile and test, type: | ||
6 | # ./configure; make test | ||
7 | # The call of configure is optional if you don't have special requirements | ||
8 | |||
9 | # To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: | ||
10 | # make install | ||
11 | # To install in $HOME instead of /usr/local, use: | ||
12 | # make install prefix=$HOME | ||
13 | |||
14 | CC=cc | 5 | CC=cc |
15 | |||
16 | CFLAGS=-O | 6 | CFLAGS=-O |
17 | #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 | 7 | #use -O3 for gcc |
8 | #CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" | ||
18 | #CFLAGS=-g -DDEBUG | 9 | #CFLAGS=-g -DDEBUG |
19 | #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ | ||
20 | # -Wstrict-prototypes -Wmissing-prototypes | ||
21 | |||
22 | LDFLAGS=-L. -lz | 10 | LDFLAGS=-L. -lz |
23 | LDSHARED=$(CC) | ||
24 | 11 | ||
25 | VER=1.0 | ||
26 | LIBS=libz.a | ||
27 | |||
28 | AR=ar rc | ||
29 | RANLIB=ranlib | 12 | RANLIB=ranlib |
30 | TAR=tar | ||
31 | 13 | ||
32 | prefix=/usr/local | 14 | prefix=/usr/local |
33 | exec_prefix = $(prefix) | 15 | exec_prefix = ${prefix} |
34 | 16 | ||
35 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 17 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ |
36 | zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o | 18 | zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o |
37 | 19 | ||
38 | TEST_OBJS = example.o minigzip.o | 20 | TEST_OBJS = example.o minigzip.o |
39 | 21 | ||
40 | DISTFILES = README ChangeLog configure Makefile.in Makefile Makefile.msc \ | ||
41 | Makefile.bor Makefile.tc Make_vms.com descrip.mms *.[ch] | ||
42 | |||
43 | all: example minigzip | 22 | all: example minigzip |
44 | 23 | ||
45 | test: all | 24 | test: all |
46 | ./example | 25 | ./example |
47 | echo hello world | ./minigzip | ./minigzip -d | 26 | echo hello world | ./minigzip | ./minigzip -d |
48 | 27 | ||
49 | libz.a: $(OBJS) | 28 | install: libz.a |
50 | $(AR) $@ $(OBJS) | 29 | -@mkdir $(prefix)/include |
51 | -@ ($(RANLIB) $@ || true) 2>/dev/null | 30 | -@mkdir $(exec_prefix)/lib |
31 | cp zlib.h zconf.h $(prefix)/include | ||
32 | chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h | ||
33 | cp libz.a $(exec_prefix)/lib | ||
34 | chmod 644 $(exec_prefix)/lib/libz.a | ||
35 | -@$(RANLIB) $(prefix)/lib/libz.a | ||
36 | # This second ranlib is needed on NeXTSTEP which checks file times | ||
52 | 37 | ||
53 | libz.so.$(VER): $(OBJS) | 38 | libz.a: $(OBJS) |
54 | $(LDSHARED) -o $@ $(OBJS) | 39 | ar rc $@ $(OBJS) |
55 | rm -f libz.so; ln -s $@ libz.so | 40 | -@$(RANLIB) $@ |
56 | 41 | ||
57 | example: example.o $(LIBS) | 42 | example: example.o libz.a |
58 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) | 43 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) |
59 | 44 | ||
60 | minigzip: minigzip.o $(LIBS) | 45 | minigzip: minigzip.o libz.a |
61 | $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) | 46 | $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) |
62 | 47 | ||
63 | install: $(LIBS) | ||
64 | -@if [ ! $(prefix)/include ]; then mkdir $(prefix)/include; fi | ||
65 | -@if [ ! $(exec_prefix)/lib ]; then mkdir $(exec_prefix)/lib; fi | ||
66 | cp zlib.h zconf.h $(prefix)/include | ||
67 | chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h | ||
68 | cp $(LIBS) $(exec_prefix)/lib | ||
69 | cd $(exec_prefix)/lib; chmod 644 $(LIBS) | ||
70 | -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1 | ||
71 | cd $(exec_prefix)/lib; if test -f libz.so.$(VER); then \ | ||
72 | ln -s libz.so.$(VER) libz.so; \ | ||
73 | fi | ||
74 | # The ranlib in install is needed on NeXTSTEP which checks file times | ||
75 | |||
76 | uninstall: | ||
77 | cd $(exec_prefix)/lib; rm -f $(LIBS); \ | ||
78 | if test -f libz.so; then \ | ||
79 | v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p'<$(prefix)/include/zlib.h`;\ | ||
80 | rm -f libz.so.$$v libz.so; \ | ||
81 | fi | ||
82 | cd $(prefix)/include; rm -f zlib.h zconf.h | ||
83 | |||
84 | clean: | 48 | clean: |
85 | rm -f *.o *~ example minigzip libz.a libz.so* foo.gz | 49 | rm -f *.o example minigzip libz.a foo.gz |
86 | 50 | ||
87 | zip: | 51 | zip: |
88 | mv Makefile Makefile~; cp -p Makefile.in Makefile | 52 | zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \ |
89 | v=`sed -n -e 's/\./-/' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ | 53 | descrip.mms *.[ch] |
90 | zip -ul9 zlib-$$v $(DISTFILES) | ||
91 | mv Makefile~ Makefile | ||
92 | |||
93 | dist: | ||
94 | mv Makefile Makefile~; cp -p Makefile.in Makefile | ||
95 | d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ | ||
96 | rm -f $$d.tar.gz; \ | ||
97 | if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \ | ||
98 | files=""; \ | ||
99 | for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \ | ||
100 | cd ..; \ | ||
101 | GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \ | ||
102 | if test ! -d $$d; then rm -f $$d; fi | ||
103 | mv Makefile~ Makefile | ||
104 | |||
105 | tags: | ||
106 | etags *.[ch] | ||
107 | 54 | ||
108 | depend: | 55 | tgz: |
109 | makedepend -- $(CFLAGS) -- *.[ch] | 56 | cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ |
57 | zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch] | ||
58 | |||
59 | TAGS: | ||
60 | etags *.[ch] | ||
110 | 61 | ||
111 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 62 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
112 | 63 | ||
113 | adler32.o: zlib.h zconf.h | 64 | adler32.o: zutil.h zlib.h zconf.h |
114 | compress.o: zlib.h zconf.h | 65 | compress.o: zlib.h zconf.h |
115 | crc32.o: zlib.h zconf.h | 66 | crc32.o: zutil.h zlib.h zconf.h |
116 | deflate.o: deflate.h zutil.h zlib.h zconf.h | 67 | deflate.o: deflate.h zutil.h zlib.h zconf.h |
117 | example.o: zlib.h zconf.h | 68 | example.o: zlib.h zconf.h |
118 | gzio.o: zutil.h zlib.h zconf.h | 69 | gzio.o: zutil.h zlib.h zconf.h |
119 | infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h | 70 | infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h |
120 | infcodes.o: zutil.h zlib.h zconf.h | 71 | infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h |
121 | infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h | 72 | inffast.o: zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h |
122 | inffast.o: zutil.h zlib.h zconf.h inftrees.h | ||
123 | inffast.o: infblock.h infcodes.h infutil.h inffast.h | ||
124 | inflate.o: zutil.h zlib.h zconf.h infblock.h | 73 | inflate.o: zutil.h zlib.h zconf.h infblock.h |
125 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h | 74 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h |
126 | infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h | 75 | infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h |
127 | minigzip.o: zlib.h zconf.h | 76 | minigzip.o: zlib.h zconf.h |
128 | trees.o: deflate.h zutil.h zlib.h zconf.h | 77 | trees.o: deflate.h zutil.h zlib.h zconf.h |
129 | uncompr.o: zlib.h zconf.h | 78 | uncompr.o: zlib.h zconf.h |
130 | zutil.o: zutil.h zlib.h zconf.h | 79 | zutil.o: zutil.h zlib.h zconf.h |
diff --git a/Makefile.bor b/Makefile.bor index 2116563..536b76d 100644 --- a/Makefile.bor +++ b/Makefile.bor | |||
@@ -18,7 +18,7 @@ CFLAGS=-O2 -Z $(MODEL) | |||
18 | CC=bcc | 18 | CC=bcc |
19 | LD=bcc | 19 | LD=bcc |
20 | LIB=tlib | 20 | LIB=tlib |
21 | # replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version | 21 | # replace bcc with tcc for Turbo C++ 1.0 |
22 | LDFLAGS=$(MODEL) | 22 | LDFLAGS=$(MODEL) |
23 | O=.obj | 23 | O=.obj |
24 | 24 | ||
diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index fe5b372..0000000 --- a/Makefile.in +++ /dev/null | |||
@@ -1,130 +0,0 @@ | |||
1 | # Makefile for zlib | ||
2 | # Copyright (C) 1995-1996 Jean-loup Gailly. | ||
3 | # For conditions of distribution and use, see copyright notice in zlib.h | ||
4 | |||
5 | # To compile and test, type: | ||
6 | # ./configure; make test | ||
7 | # The call of configure is optional if you don't have special requirements | ||
8 | |||
9 | # To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: | ||
10 | # make install | ||
11 | # To install in $HOME instead of /usr/local, use: | ||
12 | # make install prefix=$HOME | ||
13 | |||
14 | CC=cc | ||
15 | |||
16 | CFLAGS=-O | ||
17 | #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 | ||
18 | #CFLAGS=-g -DDEBUG | ||
19 | #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ | ||
20 | # -Wstrict-prototypes -Wmissing-prototypes | ||
21 | |||
22 | LDFLAGS=-L. -lz | ||
23 | LDSHARED=$(CC) | ||
24 | |||
25 | VER=1.0 | ||
26 | LIBS=libz.a | ||
27 | |||
28 | AR=ar rc | ||
29 | RANLIB=ranlib | ||
30 | TAR=tar | ||
31 | |||
32 | prefix=/usr/local | ||
33 | exec_prefix = $(prefix) | ||
34 | |||
35 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | ||
36 | zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o | ||
37 | |||
38 | TEST_OBJS = example.o minigzip.o | ||
39 | |||
40 | DISTFILES = README ChangeLog configure Makefile.in Makefile Makefile.msc \ | ||
41 | Makefile.bor Makefile.tc Make_vms.com descrip.mms *.[ch] | ||
42 | |||
43 | all: example minigzip | ||
44 | |||
45 | test: all | ||
46 | ./example | ||
47 | echo hello world | ./minigzip | ./minigzip -d | ||
48 | |||
49 | libz.a: $(OBJS) | ||
50 | $(AR) $@ $(OBJS) | ||
51 | -@ ($(RANLIB) $@ || true) 2>/dev/null | ||
52 | |||
53 | libz.so.$(VER): $(OBJS) | ||
54 | $(LDSHARED) -o $@ $(OBJS) | ||
55 | rm -f libz.so; ln -s $@ libz.so | ||
56 | |||
57 | example: example.o $(LIBS) | ||
58 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) | ||
59 | |||
60 | minigzip: minigzip.o $(LIBS) | ||
61 | $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) | ||
62 | |||
63 | install: $(LIBS) | ||
64 | -@if [ ! $(prefix)/include ]; then mkdir $(prefix)/include; fi | ||
65 | -@if [ ! $(exec_prefix)/lib ]; then mkdir $(exec_prefix)/lib; fi | ||
66 | cp zlib.h zconf.h $(prefix)/include | ||
67 | chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h | ||
68 | cp $(LIBS) $(exec_prefix)/lib | ||
69 | cd $(exec_prefix)/lib; chmod 644 $(LIBS) | ||
70 | -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1 | ||
71 | cd $(exec_prefix)/lib; if test -f libz.so.$(VER); then \ | ||
72 | ln -s libz.so.$(VER) libz.so; \ | ||
73 | fi | ||
74 | # The ranlib in install is needed on NeXTSTEP which checks file times | ||
75 | |||
76 | uninstall: | ||
77 | cd $(exec_prefix)/lib; rm -f $(LIBS); \ | ||
78 | if test -f libz.so; then \ | ||
79 | v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p'<$(prefix)/include/zlib.h`;\ | ||
80 | rm -f libz.so.$$v libz.so; \ | ||
81 | fi | ||
82 | cd $(prefix)/include; rm -f zlib.h zconf.h | ||
83 | |||
84 | clean: | ||
85 | rm -f *.o *~ example minigzip libz.a libz.so* foo.gz | ||
86 | |||
87 | zip: | ||
88 | mv Makefile Makefile~; cp -p Makefile.in Makefile | ||
89 | v=`sed -n -e 's/\./-/' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ | ||
90 | zip -ul9 zlib-$$v $(DISTFILES) | ||
91 | mv Makefile~ Makefile | ||
92 | |||
93 | dist: | ||
94 | mv Makefile Makefile~; cp -p Makefile.in Makefile | ||
95 | d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ | ||
96 | rm -f $$d.tar.gz; \ | ||
97 | if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \ | ||
98 | files=""; \ | ||
99 | for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \ | ||
100 | cd ..; \ | ||
101 | GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \ | ||
102 | if test ! -d $$d; then rm -f $$d; fi | ||
103 | mv Makefile~ Makefile | ||
104 | |||
105 | tags: | ||
106 | etags *.[ch] | ||
107 | |||
108 | depend: | ||
109 | makedepend -- $(CFLAGS) -- *.[ch] | ||
110 | |||
111 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
112 | |||
113 | adler32.o: zlib.h zconf.h | ||
114 | compress.o: zlib.h zconf.h | ||
115 | crc32.o: zlib.h zconf.h | ||
116 | deflate.o: deflate.h zutil.h zlib.h zconf.h | ||
117 | example.o: zlib.h zconf.h | ||
118 | gzio.o: zutil.h zlib.h zconf.h | ||
119 | infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h | ||
120 | infcodes.o: zutil.h zlib.h zconf.h | ||
121 | infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h | ||
122 | inffast.o: zutil.h zlib.h zconf.h inftrees.h | ||
123 | inffast.o: infblock.h infcodes.h infutil.h inffast.h | ||
124 | inflate.o: zutil.h zlib.h zconf.h infblock.h | ||
125 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h | ||
126 | infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h | ||
127 | minigzip.o: zlib.h zconf.h | ||
128 | trees.o: deflate.h zutil.h zlib.h zconf.h | ||
129 | uncompr.o: zlib.h zconf.h | ||
130 | zutil.o: zutil.h zlib.h zconf.h | ||
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 | |||
7 | CC=cc | ||
8 | CFLAGS=-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 | ||
12 | LDFLAGS=-L. -lz | ||
13 | |||
14 | #RANLIB=ranlib | ||
15 | |||
16 | prefix=/usr/local | ||
17 | |||
18 | OBJS = 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 | |||
21 | TEST_OBJS = example.o minigzip.o | ||
22 | |||
23 | all: example minigzip | ||
24 | |||
25 | test: all | ||
26 | ./example | ||
27 | echo hello world | ./minigzip | ./minigzip -d | ||
28 | |||
29 | install: 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 | |||
37 | zlib.lib: $(OBJS) | ||
38 | cc -A $@ $(OBJS) | ||
39 | # ar rc $@ $(OBJS) | ||
40 | # $(RANLIB) $@ | ||
41 | |||
42 | example: example.o zlib.lib | ||
43 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) | ||
44 | |||
45 | minigzip: minigzip.o zlib.lib | ||
46 | $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) | ||
47 | |||
48 | clean: | ||
49 | rm -f *.o example minigzip zlib.lib foo.gz | ||
50 | |||
51 | zip: | ||
52 | zip -ul9 zlib README ChangeLog Makefile Makefile.??? Makefile.?? *.[ch] | ||
53 | |||
54 | tgz: | ||
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 | |||
60 | adler32.o: zutil.h zlib.h zconf.h | ||
61 | compress.o: zlib.h zconf.h | ||
62 | crc32.o: zutil.h zlib.h zconf.h | ||
63 | deflate.o: deflate.h zutil.h zlib.h zconf.h | ||
64 | example.o: zlib.h zconf.h | ||
65 | gzio.o: zutil.h zlib.h zconf.h | ||
66 | infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h | ||
67 | infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h | ||
68 | inffast.o: zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h | ||
69 | inflate.o: zutil.h zlib.h zconf.h infblock.h | ||
70 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h | ||
71 | infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h | ||
72 | minigzip.o: zlib.h zconf.h | ||
73 | trees.o: deflate.h zutil.h zlib.h zconf.h | ||
74 | uncompr.o: zlib.h zconf.h | ||
75 | zutil.o: zutil.h zlib.h zconf.h | ||
@@ -1,71 +1,55 @@ | |||
1 | zlib 1.0 is a general purpose data compression library. All the code | 1 | zlib 1.0 is a general purpose data compression library. |
2 | is reentrant (thread safe). The data format used by the zlib library | 2 | All the code is reentrant (thread safe). |
3 | is described in the files zlib-3.3.doc, deflate-1.3.doc and | 3 | |
4 | gzip-4.3.doc, available in ftp://ftp.uu.net/pub/archiving/zip/doc/ | 4 | The data format used by the zlib library is described in the |
5 | files zlib-3.2.doc, deflate-1.2.doc and gzip-4.2.doc, available | ||
6 | in ftp://ftp.uu.net/pub/archiving/zip/doc | ||
5 | 7 | ||
6 | All functions of the compression library are documented in the file | 8 | All functions of the compression library are documented in the file |
7 | zlib.h. A usage example of the library is given in the file example.c | 9 | zlib.h. A usage example of the library is given in the file example.c |
8 | which also tests that the library is working correctly. Another | 10 | which also tests that the library is working correctly. Another |
9 | example is given in the file minigzip.c. The compression library itself | 11 | example is given in the file minigzip.c. |
10 | is composed of all source files except example.c and minigzip.c. | ||
11 | 12 | ||
12 | To compile all files and run the test program, follow the instructions | 13 | To compile all files and run the test program, just type: make test |
13 | given at the top of Makefile. In short "make test; make install" | 14 | (For MSDOS, use one of the special makefiles such as Makefile.msc; |
14 | should work for most machines. For MSDOS, use one of the special | 15 | for VMS, use Make_vms.com or descrip.mms.) |
15 | makefiles such as Makefile.msc; for VMS, use Make_vms.com or descrip.mms. | 16 | To install the zlib library (libz.a) in /usr/local/lib, type: make install |
17 | To install in a different directory, use for example: | ||
18 | make install prefix=$HOME | ||
19 | This will install in $HOME/lib instead of /usr/local/lib. | ||
16 | 20 | ||
17 | Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov> or, | 21 | Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov>. |
18 | if this fails, to the addresses given below in the Copyright section. | ||
19 | 22 | ||
20 | The changes made in version 1.0 are documented in the file ChangeLog. | 23 | The changes made in version 1.0 are documented in the file ChangeLog. |
21 | The main changes since 0.95 are: | 24 | The main changes since 0.95 are: |
22 | - allow preset dictionary shared between compressor and decompressor | ||
23 | - allow compression level 0 (no compression) | 25 | - allow compression level 0 (no compression) |
24 | - add deflateParams in zlib.h: allow dynamic change of compression level | 26 | - add deflateParams in zlib.h: allow dynamic change of compression level |
25 | and compression strategy. | 27 | and compression strategy. |
26 | - test large buffers and deflateParams in example.c | 28 | - test large buffers and deflateParams in example.c |
27 | - add optional "configure" to build zlib as a shared library | ||
28 | - suppress Makefile.qnx, use configure instead | ||
29 | - fixes for 64-bit systems (needed for Alpha and Cray) | ||
30 | - declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) | 29 | - declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) |
30 | - fixes for 64-bit systems (needed for Alpha and Cray) | ||
31 | - always return Z_BUF_ERROR when deflate() has nothing to do | 31 | - always return Z_BUF_ERROR when deflate() has nothing to do |
32 | - deflateInit and inflateInit are now macros to allow version checking | 32 | - fix some very unlikely race conditions. |
33 | - prefix all global functions and types with z_ with -DZ_PREFIX | ||
34 | - fix some very unlikely race conditions in multi-threaded environment | ||
35 | - several minor fixes for better portability | 33 | - several minor fixes for better portability |
36 | - free in reverse order of allocation to help memory manager | 34 | - free in reverse order of allocation to help memory manager |
37 | - use zlib-1.0/* instead of zlib/* inside the tar.gz | ||
38 | - make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith | ||
39 | -Wconversion -Wstrict-prototypes -Wmissing-prototypes" | ||
40 | - allow gzread on concatenated .gz files | ||
41 | - deflateEnd now returns Z_DATA_ERROR if it was premature | ||
42 | - deflate is finally (?) fully deterministic | ||
43 | 35 | ||
44 | Notes for some targets: | 36 | Notes for some targets: |
45 | 37 | ||
46 | - For Turbo C the small model is supported only with reduced performance to | 38 | - For MSDOS, the small and medium models have been tested only with |
47 | avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 | 39 | Microsoft C. (This should work for Borland C also, but I don't have |
40 | a Borland compiler to test with.) The small model was tested with | ||
41 | Turbo C but only with reduced performance to avoid any far | ||
42 | allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 | ||
43 | |||
44 | MS Visual C++1.5 in far model gives: | ||
45 | warning C4746: 'z_errmsg' : unsized array treated as '__far' | ||
46 | warning C4746: 'inflate_mask' : unsized array treated as '__far' | ||
47 | Ignore those warnings. | ||
48 | 48 | ||
49 | - For 64-bit Iris, deflate.c must be compiled without any optimization. | 49 | - For 64-bit Iris, deflate.c must be compiled without any optimization. |
50 | With -O, one libpng test fails. The test works in 32 bit mode (with the | 50 | With -O, one libpng test fails. The test works in 32 bit mode (with the |
51 | -32 compiler flag). | 51 | -32 compiler flag). |
52 | 52 | ||
53 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 | ||
54 | it works when compiled with cc. | ||
55 | |||
56 | - zlib doesn't work on HP-UX 9.05 with one cc compiler (the one not | ||
57 | accepting the -O option). It works with the other cc compiler. | ||
58 | |||
59 | A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk> | ||
60 | is in the CPAN (Comprehensive Perl Archive Network) sites, such as: | ||
61 | ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib* | ||
62 | |||
63 | Acknowledgments: | ||
64 | |||
65 | The deflate format used by zlib was defined by Phil Katz. The deflate | ||
66 | and zlib specifications were written by Peter Deutsch. Thanks to all the | ||
67 | people who reported problems and suggested various improvements in zlib; | ||
68 | they are too numerous to cite here. | ||
69 | 53 | ||
70 | Copyright notice: | 54 | Copyright notice: |
71 | 55 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* adler32.c -- compute the Adler-32 checksum of a data stream | 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -20,7 +20,7 @@ | |||
20 | /* ========================================================================= */ | 20 | /* ========================================================================= */ |
21 | uLong adler32(adler, buf, len) | 21 | uLong adler32(adler, buf, len) |
22 | uLong adler; | 22 | uLong adler; |
23 | const Bytef *buf; | 23 | Bytef *buf; |
24 | uInt len; | 24 | uInt len; |
25 | { | 25 | { |
26 | unsigned long s1 = adler & 0xffff; | 26 | unsigned long s1 = adler & 0xffff; |
@@ -1,5 +1,5 @@ | |||
1 | /* compress.c -- compress a memory buffer | 1 | /* compress.c -- compress a memory buffer |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -22,13 +22,13 @@ | |||
22 | int compress (dest, destLen, source, sourceLen) | 22 | int compress (dest, destLen, source, sourceLen) |
23 | Bytef *dest; | 23 | Bytef *dest; |
24 | uLongf *destLen; | 24 | uLongf *destLen; |
25 | const Bytef *source; | 25 | Bytef *source; |
26 | uLong sourceLen; | 26 | uLong sourceLen; |
27 | { | 27 | { |
28 | z_stream stream; | 28 | z_stream stream; |
29 | int err; | 29 | int err; |
30 | 30 | ||
31 | stream.next_in = (Bytef*)source; | 31 | stream.next_in = source; |
32 | stream.avail_in = (uInt)sourceLen; | 32 | stream.avail_in = (uInt)sourceLen; |
33 | /* Check for source > 64K on 16-bit machine: */ | 33 | /* Check for source > 64K on 16-bit machine: */ |
34 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | 34 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; |
diff --git a/configure b/configure deleted file mode 100755 index 6f3c729..0000000 --- a/configure +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | # configure script for zlib. This script is needed only if | ||
3 | # you wish to build a shared library and your system supports them, | ||
4 | # of if you need special compiler, flags or install directory. | ||
5 | # Otherwise, you can just use directly "make test; make install" | ||
6 | # | ||
7 | # To impose specific compiler or flags or install directory, use for example: | ||
8 | # prefix=$HOME CC=cc CFLAGS="-O4" ./configure | ||
9 | # or for csh/tcsh users: | ||
10 | # (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure) | ||
11 | # LDSHARED is the command to be used to create a shared library | ||
12 | |||
13 | LIBS=libz.a | ||
14 | VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` | ||
15 | AR=${AR-"ar rc"} | ||
16 | prefix=${prefix-/usr/local} | ||
17 | exec_prefix=${exec_prefix-$prefix} | ||
18 | |||
19 | test -z "$CC" && echo Checking for gcc... | ||
20 | test=ztest$$ | ||
21 | cat > $test.c <<EOF | ||
22 | int hello() { printf("hello\n"); } | ||
23 | EOF | ||
24 | if test -z "$CC" && (gcc -c -O3 $test.c) 2>/dev/null; then | ||
25 | CC=gcc | ||
26 | SFLAGS=${CFLAGS-"-fPIC -O3"} | ||
27 | CFLAGS=${CFLAGS-"-O3"} | ||
28 | LDSHARED=${LDSHARED-"gcc -shared"} | ||
29 | else | ||
30 | # find system name and corresponding cc options | ||
31 | CC=${CC-cc} | ||
32 | case `(uname -sr || echo unknown) 2>/dev/null` in | ||
33 | SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."} | ||
34 | CFLAGS=${CFLAGS-"-fast -xcg89"} | ||
35 | LDSHARED=${LDSHARED-"cc -G"};; | ||
36 | SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} | ||
37 | CFLAGS=${CFLAGS-"-O2"} | ||
38 | LDSHARED=${LDSHARED-"ld"};; | ||
39 | IRIX*) SFLAGS=${CFLAGS-"-O2 -rpath ."} | ||
40 | CFLAGS=${CFLAGS-"-O2"} | ||
41 | LDSHARED=${LDSHARED-"cc -shared"};; | ||
42 | QNX*) SFLAGS=${CFLAGS-"-4 -O -Q"} | ||
43 | CFLAGS=${CFLAGS-"-4 -O -Q"} | ||
44 | LDSHARED=${LDSHARED-"cc"} | ||
45 | LIBS=zlib.lib | ||
46 | AR="cc -A";; | ||
47 | # send working options for other systems to gzip@prep.ai.mit.edu | ||
48 | *) SFLAGS=${CFLAGS-"-O"} | ||
49 | CFLAGS=${CFLAGS-"-O"} | ||
50 | LDSHARED=${LDSHARED-"-shared"};; | ||
51 | esac | ||
52 | fi | ||
53 | |||
54 | echo Checking for shared library support... | ||
55 | # we must test in two steps (cc then ld), required at least on SunOS 4.x | ||
56 | if test "`$CC -c $SFLAGS $test.c 2>&1`" = "" && | ||
57 | test "`$LDSHARED -o $test.so $test.o 2>&1`" = ""; then | ||
58 | CFLAGS="$SFLAGS" | ||
59 | LIBS='libz.so.$(VER)' | ||
60 | echo Building shared library libz.so.$VER with $CC. | ||
61 | else | ||
62 | LDSHARED="$CC" | ||
63 | echo Building static library $LIBS version $VER with $CC. | ||
64 | fi | ||
65 | rm -f $test.[co] $test.so | ||
66 | |||
67 | # udpate Makefile | ||
68 | # ed -s Makefile <<EOF | ||
69 | sed < Makefile.in " | ||
70 | /^CC *=/s/=.*/=$CC/ | ||
71 | /^CFLAGS *=/s/=.*/=$CFLAGS/ | ||
72 | /^LDSHARED *=/s/=.*/=$LDSHARED/ | ||
73 | /^LIBS *=/s,=.*,=$LIBS, | ||
74 | /^AR *=/s/=.*/=$AR/ | ||
75 | /^VER *=/s/=.*/=$VER/ | ||
76 | /^prefix *=/s,=.*,=$prefix, | ||
77 | /^exec_prefix *=/s,=.*,=$exec_prefix, | ||
78 | " > Makefile | ||
79 | #w | ||
80 | #q | ||
81 | #EOF | ||
@@ -1,5 +1,5 @@ | |||
1 | /* crc32.c -- compute the CRC-32 of a data stream | 1 | /* crc32.c -- compute the CRC-32 of a data stream |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -10,53 +10,23 @@ | |||
10 | #define local static | 10 | #define local static |
11 | 11 | ||
12 | #ifdef DYNAMIC_CRC_TABLE | 12 | #ifdef DYNAMIC_CRC_TABLE |
13 | 13 | /* ========================================================================= | |
14 | * Make the crc table. This function is needed only if you want to compute | ||
15 | * the table dynamically. | ||
16 | */ | ||
14 | local int crc_table_empty = 1; | 17 | local int crc_table_empty = 1; |
15 | local uLongf crc_table[256]; | 18 | local uLong crc_table[256]; |
16 | local void make_crc_table OF((void)); | ||
17 | |||
18 | /* | ||
19 | Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: | ||
20 | x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. | ||
21 | 19 | ||
22 | Polynomials over GF(2) are represented in binary, one bit per coefficient, | ||
23 | with the lowest powers in the most significant bit. Then adding polynomials | ||
24 | is just exclusive-or, and multiplying a polynomial by x is a right shift by | ||
25 | one. If we call the above polynomial p, and represent a byte as the | ||
26 | polynomial q, also with the lowest power in the most significant bit (so the | ||
27 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, | ||
28 | where a mod b means the remainder after dividing a by b. | ||
29 | |||
30 | This calculation is done using the shift-register method of multiplying and | ||
31 | taking the remainder. The register is initialized to zero, and for each | ||
32 | incoming bit, x^32 is added mod p to the register if the bit is a one (where | ||
33 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by | ||
34 | x (which is shifting right by one and adding x^32 mod p if the bit shifted | ||
35 | out is a one). We start with the highest power (least significant bit) of | ||
36 | q and repeat for all eight bits of q. | ||
37 | |||
38 | The table is simply the CRC of all possible eight bit values. This is all | ||
39 | the information needed to generate CRC's on data a byte at a time for all | ||
40 | combinations of CRC register values and incoming bytes. | ||
41 | */ | ||
42 | local void make_crc_table() | 20 | local void make_crc_table() |
43 | { | 21 | { |
44 | uLong c; | 22 | uLong c; |
45 | int n, k; | 23 | int n, k; |
46 | uLong poly; /* polynomial exclusive-or pattern */ | ||
47 | /* terms of polynomial defining this crc (except x^32): */ | ||
48 | static Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; | ||
49 | |||
50 | /* make exclusive-or pattern from polynomial (0xedb88320L) */ | ||
51 | poly = 0L; | ||
52 | for (n = 0; n < sizeof(p)/sizeof(Byte); n++) | ||
53 | poly |= 1L << (31 - p[n]); | ||
54 | 24 | ||
55 | for (n = 0; n < 256; n++) | 25 | for (n = 0; n < 256; n++) |
56 | { | 26 | { |
57 | c = (uLong)n; | 27 | c = (uLong)n; |
58 | for (k = 0; k < 8; k++) | 28 | for (k = 0; k < 8; k++) |
59 | c = c & 1 ? poly ^ (c >> 1) : c >> 1; | 29 | c = c & 1 ? 0xedb88320L ^ (c >> 1) : c >> 1; |
60 | crc_table[n] = c; | 30 | crc_table[n] = c; |
61 | } | 31 | } |
62 | crc_table_empty = 0; | 32 | crc_table_empty = 0; |
@@ -65,7 +35,7 @@ local void make_crc_table() | |||
65 | /* ======================================================================== | 35 | /* ======================================================================== |
66 | * Table of CRC-32's of all single-byte values (made by make_crc_table) | 36 | * Table of CRC-32's of all single-byte values (made by make_crc_table) |
67 | */ | 37 | */ |
68 | local uLongf crc_table[256] = { | 38 | local uLong crc_table[] = { |
69 | 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, | 39 | 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, |
70 | 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, | 40 | 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, |
71 | 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, | 41 | 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, |
@@ -121,18 +91,6 @@ local uLongf crc_table[256] = { | |||
121 | }; | 91 | }; |
122 | #endif | 92 | #endif |
123 | 93 | ||
124 | /* ========================================================================= | ||
125 | * This function can be used by asm versions of crc32() | ||
126 | */ | ||
127 | uLongf *get_crc_table() | ||
128 | { | ||
129 | #ifdef DYNAMIC_CRC_TABLE | ||
130 | if (crc_table_empty) make_crc_table(); | ||
131 | #endif | ||
132 | return (uLongf *)crc_table; | ||
133 | } | ||
134 | |||
135 | /* ========================================================================= */ | ||
136 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); | 94 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); |
137 | #define DO2(buf) DO1(buf); DO1(buf); | 95 | #define DO2(buf) DO1(buf); DO1(buf); |
138 | #define DO4(buf) DO2(buf); DO2(buf); | 96 | #define DO4(buf) DO2(buf); DO2(buf); |
@@ -141,7 +99,7 @@ uLongf *get_crc_table() | |||
141 | /* ========================================================================= */ | 99 | /* ========================================================================= */ |
142 | uLong crc32(crc, buf, len) | 100 | uLong crc32(crc, buf, len) |
143 | uLong crc; | 101 | uLong crc; |
144 | const Bytef *buf; | 102 | Bytef *buf; |
145 | uInt len; | 103 | uInt len; |
146 | { | 104 | { |
147 | if (buf == Z_NULL) return 0L; | 105 | if (buf == Z_NULL) return 0L; |
@@ -1,5 +1,5 @@ | |||
1 | /* deflate.c -- compress data using the deflation algorithm | 1 | /* deflate.c -- compress data using the deflation algorithm |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -51,7 +51,7 @@ | |||
51 | 51 | ||
52 | #include "deflate.h" | 52 | #include "deflate.h" |
53 | 53 | ||
54 | char deflate_copyright[] = " deflate 1.0 Copyright 1995-1996 Jean-loup Gailly "; | 54 | char deflate_copyright[] = " deflate 1.0 Copyright 1995 Jean-loup Gailly "; |
55 | /* | 55 | /* |
56 | If you use the zlib library in a product, an acknowledgment is welcome | 56 | If you use the zlib library in a product, an acknowledgment is welcome |
57 | in the documentation of your product. If for some reason you cannot | 57 | in the documentation of your product. If for some reason you cannot |
@@ -60,8 +60,9 @@ char deflate_copyright[] = " deflate 1.0 Copyright 1995-1996 Jean-loup Gailly "; | |||
60 | */ | 60 | */ |
61 | 61 | ||
62 | /* =========================================================================== | 62 | /* =========================================================================== |
63 | * Function prototypes. | 63 | * Prototypes for local functions. |
64 | */ | 64 | */ |
65 | |||
65 | local void fill_window OF((deflate_state *s)); | 66 | local void fill_window OF((deflate_state *s)); |
66 | local int deflate_stored OF((deflate_state *s, int flush)); | 67 | local int deflate_stored OF((deflate_state *s, int flush)); |
67 | local int deflate_fast OF((deflate_state *s, int flush)); | 68 | local int deflate_fast OF((deflate_state *s, int flush)); |
@@ -168,36 +169,26 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ | |||
168 | zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); | 169 | zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); |
169 | 170 | ||
170 | /* ========================================================================= */ | 171 | /* ========================================================================= */ |
171 | int deflateInit_(strm, level, version, stream_size) | 172 | int deflateInit (strm, level) |
172 | z_stream *strm; | 173 | z_stream *strm; |
173 | int level; | 174 | int level; |
174 | const char *version; | ||
175 | int stream_size; | ||
176 | { | 175 | { |
177 | return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, | 176 | return deflateInit2 (strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 0); |
178 | Z_DEFAULT_STRATEGY, version, stream_size); | ||
179 | /* To do: ignore strm->next_in if we use it as window */ | 177 | /* To do: ignore strm->next_in if we use it as window */ |
180 | } | 178 | } |
181 | 179 | ||
182 | /* ========================================================================= */ | 180 | /* ========================================================================= */ |
183 | int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | 181 | int deflateInit2 (strm, level, method, windowBits, memLevel, strategy) |
184 | version, stream_size) | ||
185 | z_stream *strm; | 182 | z_stream *strm; |
186 | int level; | 183 | int level; |
187 | int method; | 184 | int method; |
188 | int windowBits; | 185 | int windowBits; |
189 | int memLevel; | 186 | int memLevel; |
190 | int strategy; | 187 | int strategy; |
191 | const char *version; | ||
192 | int stream_size; | ||
193 | { | 188 | { |
194 | deflate_state *s; | 189 | deflate_state *s; |
195 | int noheader = 0; | 190 | int noheader = 0; |
196 | 191 | ||
197 | if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || | ||
198 | stream_size != sizeof(z_stream)) { | ||
199 | return Z_VERSION_ERROR; | ||
200 | } | ||
201 | if (strm == Z_NULL) return Z_STREAM_ERROR; | 192 | if (strm == Z_NULL) return Z_STREAM_ERROR; |
202 | 193 | ||
203 | strm->msg = Z_NULL; | 194 | strm->msg = Z_NULL; |
@@ -243,7 +234,7 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
243 | 234 | ||
244 | if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || | 235 | if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || |
245 | s->pending_buf == Z_NULL) { | 236 | s->pending_buf == Z_NULL) { |
246 | strm->msg = ERR_MSG(Z_MEM_ERROR); | 237 | strm->msg = z_errmsg[1-Z_MEM_ERROR]; |
247 | deflateEnd (strm); | 238 | deflateEnd (strm); |
248 | return Z_MEM_ERROR; | 239 | return Z_MEM_ERROR; |
249 | } | 240 | } |
@@ -261,41 +252,32 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
261 | return deflateReset(strm); | 252 | return deflateReset(strm); |
262 | } | 253 | } |
263 | 254 | ||
264 | /* ========================================================================= */ | 255 | /* ========================================================================= |
265 | int deflateSetDictionary (strm, dictionary, dictLength) | 256 | * Undocumented function to return the Adler32 of a stream. It can be |
257 | * called immediately after a flush with Z_SYNC_FLUSH, to allow later | ||
258 | * resumption of the compressor with deflateSetAdler32. | ||
259 | */ | ||
260 | uLong deflateGetAdler32 (strm) | ||
266 | z_stream *strm; | 261 | z_stream *strm; |
267 | const Bytef *dictionary; | ||
268 | uInt dictLength; | ||
269 | { | 262 | { |
270 | deflate_state *s; | 263 | if (strm == Z_NULL || strm->state == Z_NULL) return (uLong)Z_STREAM_ERROR; |
271 | uInt length = dictLength; | 264 | /* Z_STREAM_ERROR happens to be an invalid Adler32 value. */ |
272 | uInt n; | ||
273 | IPos hash_head; | ||
274 | |||
275 | if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || | ||
276 | strm->state->status != INIT_STATE) return Z_STREAM_ERROR; | ||
277 | 265 | ||
278 | s = strm->state; | 266 | return strm->state->adler; |
279 | strm->adler = adler32(strm->adler, dictionary, dictLength); | 267 | } |
280 | 268 | ||
281 | if (length < MIN_MATCH) return Z_OK; | 269 | /* ========================================================================= |
282 | if (length > MAX_DIST(s)) { | 270 | * Undocumented function to set the Adler32 of a stream. It can be called |
283 | length = MAX_DIST(s); | 271 | * immediately after deflateInit to reset the Adler32 of a compression |
284 | dictionary += dictLength - length; | 272 | * stream which had been interrupted. |
285 | } | 273 | */ |
286 | zmemcpy((charf *)s->window, dictionary, length); | 274 | int deflateSetAdler32 (strm, adler) |
287 | s->strstart = length; | 275 | z_stream *strm; |
288 | s->block_start = (long)length; | 276 | uLong adler; |
277 | { | ||
278 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | ||
289 | 279 | ||
290 | /* Insert all strings in the hash table (except for the last two bytes). | 280 | strm->state->adler = adler; |
291 | * s->lookahead stays null, so s->ins_h will be recomputed at the next | ||
292 | * call of fill_window. | ||
293 | */ | ||
294 | s->ins_h = s->window[0]; | ||
295 | UPDATE_HASH(s, s->ins_h, s->window[1]); | ||
296 | for (n = 0; n <= length - MIN_MATCH; n++) { | ||
297 | INSERT_STRING(s, n, hash_head); | ||
298 | } | ||
299 | return Z_OK; | 281 | return Z_OK; |
300 | } | 282 | } |
301 | 283 | ||
@@ -320,10 +302,10 @@ int deflateReset (strm) | |||
320 | s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ | 302 | s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ |
321 | } | 303 | } |
322 | s->status = s->noheader ? BUSY_STATE : INIT_STATE; | 304 | s->status = s->noheader ? BUSY_STATE : INIT_STATE; |
323 | strm->adler = 1; | 305 | s->adler = 1; |
324 | s->last_flush = Z_NO_FLUSH; | 306 | s->last_flush = Z_NO_FLUSH; |
325 | 307 | ||
326 | _tr_init(s); | 308 | tr_init(s); |
327 | lm_init(s); | 309 | lm_init(s); |
328 | 310 | ||
329 | return Z_OK; | 311 | return Z_OK; |
@@ -410,47 +392,36 @@ int deflate (strm, flush) | |||
410 | int flush; | 392 | int flush; |
411 | { | 393 | { |
412 | int old_flush; /* value of flush param for previous deflate call */ | 394 | int old_flush; /* value of flush param for previous deflate call */ |
413 | deflate_state *s; | ||
414 | 395 | ||
415 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 396 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; |
416 | 397 | ||
417 | s = strm->state; | ||
418 | |||
419 | if (strm->next_out == Z_NULL || | 398 | if (strm->next_out == Z_NULL || |
420 | (strm->next_in == Z_NULL && strm->avail_in != 0) || | 399 | (strm->next_in == Z_NULL && strm->avail_in != 0) || |
421 | (s->status == FINISH_STATE && flush != Z_FINISH)) { | 400 | (strm->state->status == FINISH_STATE && flush != Z_FINISH)) { |
422 | ERR_RETURN(strm, Z_STREAM_ERROR); | 401 | ERR_RETURN(strm, Z_STREAM_ERROR); |
423 | } | 402 | } |
424 | if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); | 403 | if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); |
425 | 404 | ||
426 | s->strm = strm; /* just in case */ | 405 | strm->state->strm = strm; /* just in case */ |
427 | old_flush = s->last_flush; | 406 | old_flush = strm->state->last_flush; |
428 | s->last_flush = flush; | 407 | strm->state->last_flush = flush; |
429 | 408 | ||
430 | /* Write the zlib header */ | 409 | /* Write the zlib header */ |
431 | if (s->status == INIT_STATE) { | 410 | if (strm->state->status == INIT_STATE) { |
432 | 411 | ||
433 | uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; | 412 | uInt header = (Z_DEFLATED + ((strm->state->w_bits-8)<<4)) << 8; |
434 | uInt level_flags = (s->level-1) >> 1; | 413 | uInt level_flags = (strm->state->level-1) >> 1; |
435 | 414 | ||
436 | if (level_flags > 3) level_flags = 3; | 415 | if (level_flags > 3) level_flags = 3; |
437 | header |= (level_flags << 6); | 416 | header |= (level_flags << 6); |
438 | if (s->strstart != 0) header |= PRESET_DICT; | ||
439 | header += 31 - (header % 31); | 417 | header += 31 - (header % 31); |
440 | 418 | ||
441 | s->status = BUSY_STATE; | 419 | strm->state->status = BUSY_STATE; |
442 | putShortMSB(s, header); | 420 | putShortMSB(strm->state, header); |
443 | |||
444 | /* Save the adler32 of the preset dictionary: */ | ||
445 | if (s->strstart != 0) { | ||
446 | putShortMSB(s, (uInt)(strm->adler >> 16)); | ||
447 | putShortMSB(s, (uInt)(strm->adler & 0xffff)); | ||
448 | strm->adler = 1L; | ||
449 | } | ||
450 | } | 421 | } |
451 | 422 | ||
452 | /* Flush as much pending output as possible */ | 423 | /* Flush as much pending output as possible */ |
453 | if (s->pending != 0) { | 424 | if (strm->state->pending != 0) { |
454 | flush_pending(strm); | 425 | flush_pending(strm); |
455 | if (strm->avail_out == 0) return Z_OK; | 426 | if (strm->avail_out == 0) return Z_OK; |
456 | 427 | ||
@@ -464,20 +435,21 @@ int deflate (strm, flush) | |||
464 | } | 435 | } |
465 | 436 | ||
466 | /* User must not provide more input after the first FINISH: */ | 437 | /* User must not provide more input after the first FINISH: */ |
467 | if (s->status == FINISH_STATE && strm->avail_in != 0) { | 438 | if (strm->state->status == FINISH_STATE && strm->avail_in != 0) { |
468 | ERR_RETURN(strm, Z_BUF_ERROR); | 439 | ERR_RETURN(strm, Z_BUF_ERROR); |
469 | } | 440 | } |
470 | 441 | ||
471 | /* Start a new block or continue the current one. | 442 | /* Start a new block or continue the current one. |
472 | */ | 443 | */ |
473 | if (strm->avail_in != 0 || s->lookahead != 0 || | 444 | if (strm->avail_in != 0 || strm->state->lookahead != 0 || |
474 | (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { | 445 | (flush != Z_NO_FLUSH && strm->state->status != FINISH_STATE)) { |
475 | int quit; | 446 | int quit; |
476 | 447 | ||
477 | if (flush == Z_FINISH) { | 448 | if (flush == Z_FINISH) { |
478 | s->status = FINISH_STATE; | 449 | strm->state->status = FINISH_STATE; |
479 | } | 450 | } |
480 | quit = (*(configuration_table[s->level].func))(s, flush); | 451 | quit = (*(configuration_table[strm->state->level].func)) |
452 | (strm->state, flush); | ||
481 | 453 | ||
482 | if (quit || strm->avail_out == 0) return Z_OK; | 454 | if (quit || strm->avail_out == 0) return Z_OK; |
483 | /* If flush != Z_NO_FLUSH && avail_out == 0, the next call | 455 | /* If flush != Z_NO_FLUSH && avail_out == 0, the next call |
@@ -489,14 +461,14 @@ int deflate (strm, flush) | |||
489 | */ | 461 | */ |
490 | if (flush != Z_NO_FLUSH && flush != Z_FINISH) { | 462 | if (flush != Z_NO_FLUSH && flush != Z_FINISH) { |
491 | if (flush == Z_PARTIAL_FLUSH) { | 463 | if (flush == Z_PARTIAL_FLUSH) { |
492 | _tr_align(s); | 464 | tr_align(strm->state); |
493 | } else { /* FULL_FLUSH or SYNC_FLUSH */ | 465 | } else { /* FULL_FLUSH or SYNC_FLUSH */ |
494 | _tr_stored_block(s, (char*)0, 0L, 0); | 466 | tr_stored_block(strm->state, (char*)0, 0L, 0); |
495 | /* For a full flush, this empty block will be recognized | 467 | /* For a full flush, this empty block will be recognized |
496 | * as a special marker by inflate_sync(). | 468 | * as a special marker by inflate_sync(). |
497 | */ | 469 | */ |
498 | if (flush == Z_FULL_FLUSH) { | 470 | if (flush == Z_FULL_FLUSH) { |
499 | CLEAR_HASH(s); /* forget history */ | 471 | CLEAR_HASH(strm->state); /* forget history */ |
500 | } | 472 | } |
501 | } | 473 | } |
502 | flush_pending(strm); | 474 | flush_pending(strm); |
@@ -506,25 +478,23 @@ int deflate (strm, flush) | |||
506 | Assert(strm->avail_out > 0, "bug2"); | 478 | Assert(strm->avail_out > 0, "bug2"); |
507 | 479 | ||
508 | if (flush != Z_FINISH) return Z_OK; | 480 | if (flush != Z_FINISH) return Z_OK; |
509 | if (s->noheader) return Z_STREAM_END; | 481 | if (strm->state->noheader) return Z_STREAM_END; |
510 | 482 | ||
511 | /* Write the zlib trailer (adler32) */ | 483 | /* Write the zlib trailer (adler32) */ |
512 | putShortMSB(s, (uInt)(strm->adler >> 16)); | 484 | putShortMSB(strm->state, (uInt)(strm->state->adler >> 16)); |
513 | putShortMSB(s, (uInt)(strm->adler & 0xffff)); | 485 | putShortMSB(strm->state, (uInt)(strm->state->adler & 0xffff)); |
514 | flush_pending(strm); | 486 | flush_pending(strm); |
515 | /* If avail_out is zero, the application will call deflate again | 487 | /* If avail_out is zero, the application will call deflate again |
516 | * to flush the rest. | 488 | * to flush the rest. |
517 | */ | 489 | */ |
518 | s->noheader = -1; /* write the trailer only once! */ | 490 | strm->state->noheader = -1; /* write the trailer only once! */ |
519 | return s->pending != 0 ? Z_OK : Z_STREAM_END; | 491 | return strm->state->pending != 0 ? Z_OK : Z_STREAM_END; |
520 | } | 492 | } |
521 | 493 | ||
522 | /* ========================================================================= */ | 494 | /* ========================================================================= */ |
523 | int deflateEnd (strm) | 495 | int deflateEnd (strm) |
524 | z_stream *strm; | 496 | z_stream *strm; |
525 | { | 497 | { |
526 | int status; | ||
527 | |||
528 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 498 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; |
529 | 499 | ||
530 | /* Deallocate in reverse order of allocations: */ | 500 | /* Deallocate in reverse order of allocations: */ |
@@ -533,11 +503,10 @@ int deflateEnd (strm) | |||
533 | TRY_FREE(strm, strm->state->prev); | 503 | TRY_FREE(strm, strm->state->prev); |
534 | TRY_FREE(strm, strm->state->window); | 504 | TRY_FREE(strm, strm->state->window); |
535 | 505 | ||
536 | status = strm->state->status; | ||
537 | ZFREE(strm, strm->state); | 506 | ZFREE(strm, strm->state); |
538 | strm->state = Z_NULL; | 507 | strm->state = Z_NULL; |
539 | 508 | ||
540 | return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; | 509 | return Z_OK; |
541 | } | 510 | } |
542 | 511 | ||
543 | /* ========================================================================= */ | 512 | /* ========================================================================= */ |
@@ -580,7 +549,7 @@ local int read_buf(strm, buf, size) | |||
580 | strm->avail_in -= len; | 549 | strm->avail_in -= len; |
581 | 550 | ||
582 | if (!strm->state->noheader) { | 551 | if (!strm->state->noheader) { |
583 | strm->adler = adler32(strm->adler, strm->next_in, len); | 552 | strm->state->adler = adler32(strm->state->adler, strm->next_in, len); |
584 | } | 553 | } |
585 | zmemcpy(buf, strm->next_in, len); | 554 | zmemcpy(buf, strm->next_in, len); |
586 | strm->next_in += len; | 555 | strm->next_in += len; |
@@ -624,7 +593,6 @@ local void lm_init (s) | |||
624 | * garbage. | 593 | * garbage. |
625 | * IN assertions: cur_match is the head of the hash chain for the current | 594 | * IN assertions: cur_match is the head of the hash chain for the current |
626 | * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 | 595 | * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 |
627 | * OUT assertion: the match length is not greater than s->lookahead. | ||
628 | */ | 596 | */ |
629 | #ifndef ASMV | 597 | #ifndef ASMV |
630 | /* For 80x86 and 680x0, an optimized version will be provided in match.asm or | 598 | /* For 80x86 and 680x0, an optimized version will be provided in match.asm or |
@@ -639,7 +607,6 @@ local int longest_match(s, cur_match) | |||
639 | register Bytef *match; /* matched string */ | 607 | register Bytef *match; /* matched string */ |
640 | register int len; /* length of current match */ | 608 | register int len; /* length of current match */ |
641 | int best_len = s->prev_length; /* best match length so far */ | 609 | int best_len = s->prev_length; /* best match length so far */ |
642 | int nice_match = s->nice_match; /* stop if match long enough */ | ||
643 | IPos limit = s->strstart > (IPos)MAX_DIST(s) ? | 610 | IPos limit = s->strstart > (IPos)MAX_DIST(s) ? |
644 | s->strstart - (IPos)MAX_DIST(s) : NIL; | 611 | s->strstart - (IPos)MAX_DIST(s) : NIL; |
645 | /* Stop when cur_match becomes <= limit. To simplify the code, | 612 | /* Stop when cur_match becomes <= limit. To simplify the code, |
@@ -670,11 +637,6 @@ local int longest_match(s, cur_match) | |||
670 | if (s->prev_length >= s->good_match) { | 637 | if (s->prev_length >= s->good_match) { |
671 | chain_length >>= 2; | 638 | chain_length >>= 2; |
672 | } | 639 | } |
673 | /* Do not look for matches beyond the end of the input. This is necessary | ||
674 | * to make deflate deterministic. | ||
675 | */ | ||
676 | if (nice_match > s->lookahead) nice_match = s->lookahead; | ||
677 | |||
678 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); | 640 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); |
679 | 641 | ||
680 | do { | 642 | do { |
@@ -753,7 +715,7 @@ local int longest_match(s, cur_match) | |||
753 | if (len > best_len) { | 715 | if (len > best_len) { |
754 | s->match_start = cur_match; | 716 | s->match_start = cur_match; |
755 | best_len = len; | 717 | best_len = len; |
756 | if (len >= nice_match) break; | 718 | if (len >= s->nice_match) break; |
757 | #ifdef UNALIGNED_OK | 719 | #ifdef UNALIGNED_OK |
758 | scan_end = *(ushf*)(scan+best_len-1); | 720 | scan_end = *(ushf*)(scan+best_len-1); |
759 | #else | 721 | #else |
@@ -764,8 +726,7 @@ local int longest_match(s, cur_match) | |||
764 | } while ((cur_match = prev[cur_match & wmask]) > limit | 726 | } while ((cur_match = prev[cur_match & wmask]) > limit |
765 | && --chain_length != 0); | 727 | && --chain_length != 0); |
766 | 728 | ||
767 | if (best_len <= s->lookahead) return best_len; | 729 | return best_len; |
768 | return s->lookahead; | ||
769 | } | 730 | } |
770 | #endif /* ASMV */ | 731 | #endif /* ASMV */ |
771 | 732 | ||
@@ -779,13 +740,13 @@ local void check_match(s, start, match, length) | |||
779 | int length; | 740 | int length; |
780 | { | 741 | { |
781 | /* check that the match is indeed a match */ | 742 | /* check that the match is indeed a match */ |
782 | if (zmemcmp((charf *)s->window + match, | 743 | if (memcmp((charf *)s->window + match, |
783 | (charf *)s->window + start, length) != EQUAL) { | 744 | (charf *)s->window + start, length) != EQUAL) { |
784 | fprintf(stderr, " start %u, match %u, length %d\n", | 745 | fprintf(stderr, |
785 | start, match, length); | 746 | " start %u, match %u, length %d\n", |
786 | do { | 747 | start, match, length); |
787 | fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); | 748 | do { fprintf(stderr, "%c%c", s->window[match++], |
788 | } while (--length != 0); | 749 | s->window[start++]); } while (--length != 0); |
789 | z_error("invalid match"); | 750 | z_error("invalid match"); |
790 | } | 751 | } |
791 | if (verbose > 1) { | 752 | if (verbose > 1) { |
@@ -901,11 +862,9 @@ local void fill_window(s) | |||
901 | * IN assertion: strstart is set to the end of the current match. | 862 | * IN assertion: strstart is set to the end of the current match. |
902 | */ | 863 | */ |
903 | #define FLUSH_BLOCK_ONLY(s, eof) { \ | 864 | #define FLUSH_BLOCK_ONLY(s, eof) { \ |
904 | _tr_flush_block(s, (s->block_start >= 0L ? \ | 865 | tr_flush_block(s, (s->block_start >= 0L ? \ |
905 | (charf *)&s->window[(unsigned)s->block_start] : \ | 866 | (charf *)&s->window[(unsigned)s->block_start] : \ |
906 | (charf *)Z_NULL), \ | 867 | (charf *)Z_NULL), (long)s->strstart - s->block_start, (eof)); \ |
907 | (ulg)((long)s->strstart - s->block_start), \ | ||
908 | (eof)); \ | ||
909 | s->block_start = s->strstart; \ | 868 | s->block_start = s->strstart; \ |
910 | flush_pending(s->strm); \ | 869 | flush_pending(s->strm); \ |
911 | Tracev((stderr,"[FLUSH]")); \ | 870 | Tracev((stderr,"[FLUSH]")); \ |
@@ -1008,12 +967,14 @@ local int deflate_fast(s, flush) | |||
1008 | s->match_length = longest_match (s, hash_head); | 967 | s->match_length = longest_match (s, hash_head); |
1009 | } | 968 | } |
1010 | /* longest_match() sets match_start */ | 969 | /* longest_match() sets match_start */ |
970 | |||
971 | if (s->match_length > s->lookahead) s->match_length = s->lookahead; | ||
1011 | } | 972 | } |
1012 | if (s->match_length >= MIN_MATCH) { | 973 | if (s->match_length >= MIN_MATCH) { |
1013 | check_match(s, s->strstart, s->match_start, s->match_length); | 974 | check_match(s, s->strstart, s->match_start, s->match_length); |
1014 | 975 | ||
1015 | bflush = _tr_tally(s, s->strstart - s->match_start, | 976 | bflush = tr_tally(s, s->strstart - s->match_start, |
1016 | s->match_length - MIN_MATCH); | 977 | s->match_length - MIN_MATCH); |
1017 | 978 | ||
1018 | s->lookahead -= s->match_length; | 979 | s->lookahead -= s->match_length; |
1019 | 980 | ||
@@ -1046,7 +1007,7 @@ local int deflate_fast(s, flush) | |||
1046 | } else { | 1007 | } else { |
1047 | /* No match, output a literal byte */ | 1008 | /* No match, output a literal byte */ |
1048 | Tracevv((stderr,"%c", s->window[s->strstart])); | 1009 | Tracevv((stderr,"%c", s->window[s->strstart])); |
1049 | bflush = _tr_tally (s, 0, s->window[s->strstart]); | 1010 | bflush = tr_tally (s, 0, s->window[s->strstart]); |
1050 | s->lookahead--; | 1011 | s->lookahead--; |
1051 | s->strstart++; | 1012 | s->strstart++; |
1052 | } | 1013 | } |
@@ -1104,6 +1065,7 @@ local int deflate_slow(s, flush) | |||
1104 | s->match_length = longest_match (s, hash_head); | 1065 | s->match_length = longest_match (s, hash_head); |
1105 | } | 1066 | } |
1106 | /* longest_match() sets match_start */ | 1067 | /* longest_match() sets match_start */ |
1068 | if (s->match_length > s->lookahead) s->match_length = s->lookahead; | ||
1107 | 1069 | ||
1108 | if (s->match_length <= 5 && (s->strategy == Z_FILTERED || | 1070 | if (s->match_length <= 5 && (s->strategy == Z_FILTERED || |
1109 | (s->match_length == MIN_MATCH && | 1071 | (s->match_length == MIN_MATCH && |
@@ -1124,8 +1086,8 @@ local int deflate_slow(s, flush) | |||
1124 | 1086 | ||
1125 | check_match(s, s->strstart-1, s->prev_match, s->prev_length); | 1087 | check_match(s, s->strstart-1, s->prev_match, s->prev_length); |
1126 | 1088 | ||
1127 | bflush = _tr_tally(s, s->strstart -1 - s->prev_match, | 1089 | bflush = tr_tally(s, s->strstart -1 - s->prev_match, |
1128 | s->prev_length - MIN_MATCH); | 1090 | s->prev_length - MIN_MATCH); |
1129 | 1091 | ||
1130 | /* Insert in hash table all strings up to the end of the match. | 1092 | /* Insert in hash table all strings up to the end of the match. |
1131 | * strstart-1 and strstart are already inserted. If there is not | 1093 | * strstart-1 and strstart are already inserted. If there is not |
@@ -1151,7 +1113,7 @@ local int deflate_slow(s, flush) | |||
1151 | * is longer, truncate the previous match to a single literal. | 1113 | * is longer, truncate the previous match to a single literal. |
1152 | */ | 1114 | */ |
1153 | Tracevv((stderr,"%c", s->window[s->strstart-1])); | 1115 | Tracevv((stderr,"%c", s->window[s->strstart-1])); |
1154 | if (_tr_tally (s, 0, s->window[s->strstart-1])) { | 1116 | if (tr_tally (s, 0, s->window[s->strstart-1])) { |
1155 | FLUSH_BLOCK_ONLY(s, 0); | 1117 | FLUSH_BLOCK_ONLY(s, 0); |
1156 | } | 1118 | } |
1157 | s->strstart++; | 1119 | s->strstart++; |
@@ -1169,7 +1131,7 @@ local int deflate_slow(s, flush) | |||
1169 | Assert (flush != Z_NO_FLUSH, "no flush?"); | 1131 | Assert (flush != Z_NO_FLUSH, "no flush?"); |
1170 | if (s->match_available) { | 1132 | if (s->match_available) { |
1171 | Tracevv((stderr,"%c", s->window[s->strstart-1])); | 1133 | Tracevv((stderr,"%c", s->window[s->strstart-1])); |
1172 | _tr_tally (s, 0, s->window[s->strstart-1]); | 1134 | tr_tally (s, 0, s->window[s->strstart-1]); |
1173 | s->match_available = 0; | 1135 | s->match_available = 0; |
1174 | } | 1136 | } |
1175 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1137 | FLUSH_BLOCK(s, flush == Z_FINISH); |
@@ -1,5 +1,5 @@ | |||
1 | /* deflate.h -- internal compression state | 1 | /* deflate.h -- internal compression state |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly | 2 | * Copyright (C) 1995 Jean-loup Gailly |
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 | ||
@@ -10,15 +10,17 @@ | |||
10 | 10 | ||
11 | /* $Id: deflate.h,v 1.5 1995/05/03 17:27:09 jloup Exp $ */ | 11 | /* $Id: deflate.h,v 1.5 1995/05/03 17:27:09 jloup Exp $ */ |
12 | 12 | ||
13 | #ifndef _DEFLATE_H | ||
14 | #define _DEFLATE_H | ||
15 | |||
16 | #include "zutil.h" | 13 | #include "zutil.h" |
17 | 14 | ||
18 | /* =========================================================================== | 15 | /* =========================================================================== |
19 | * Internal compression state. | 16 | * Internal compression state. |
20 | */ | 17 | */ |
21 | 18 | ||
19 | /* Data type */ | ||
20 | #define BINARY 0 | ||
21 | #define ASCII 1 | ||
22 | #define UNKNOWN 2 | ||
23 | |||
22 | #define LENGTH_CODES 29 | 24 | #define LENGTH_CODES 29 |
23 | /* number of length codes, not counting the special END_BLOCK code */ | 25 | /* number of length codes, not counting the special END_BLOCK code */ |
24 | 26 | ||
@@ -85,6 +87,7 @@ typedef struct internal_state { | |||
85 | Bytef *pending_buf; /* output still pending */ | 87 | Bytef *pending_buf; /* output still pending */ |
86 | Bytef *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 */ |
90 | uLong adler; /* adler32 of uncompressed data */ | ||
88 | int noheader; /* suppress zlib header and adler32 */ | 91 | int noheader; /* suppress zlib header and adler32 */ |
89 | Byte data_type; /* UNKNOWN, BINARY or ASCII */ | 92 | Byte data_type; /* UNKNOWN, BINARY or ASCII */ |
90 | Byte method; /* STORED (for zip only) or DEFLATED */ | 93 | Byte method; /* STORED (for zip only) or DEFLATED */ |
@@ -265,11 +268,9 @@ typedef struct internal_state { | |||
265 | */ | 268 | */ |
266 | 269 | ||
267 | /* in trees.c */ | 270 | /* in trees.c */ |
268 | void _tr_init OF((deflate_state *s)); | 271 | void tr_init OF((deflate_state *s)); |
269 | int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); | 272 | int tr_tally OF((deflate_state *s, int dist, int lc)); |
270 | ulg _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, | 273 | ulg tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, int eof)); |
271 | int eof)); | 274 | void tr_align OF((deflate_state *s)); |
272 | void _tr_align OF((deflate_state *s)); | 275 | void tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, |
273 | void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, | 276 | int eof)); |
274 | int eof)); | ||
275 | #endif | ||
@@ -1,5 +1,5 @@ | |||
1 | /* example.c -- usage example of the zlib compression library | 1 | /* example.c -- usage example of the zlib compression library |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -22,17 +22,14 @@ | |||
22 | } \ | 22 | } \ |
23 | } | 23 | } |
24 | 24 | ||
25 | const char hello[] = "hello, hello!"; | 25 | char *hello = "hello, hello!"; |
26 | /* "hello world" would be more standard, but the repeated "hello" | 26 | /* "hello world" would be more standard, but the repeated "hello" |
27 | * stresses the compression code better, sorry... | 27 | * stresses the compression code better, sorry... |
28 | */ | 28 | */ |
29 | 29 | ||
30 | const char dictionary[] = "hello"; | ||
31 | uLong dictId; /* Adler32 value of the dictionary */ | ||
32 | |||
33 | void test_compress OF((Bytef *compr, uLong comprLen, | 30 | void test_compress OF((Bytef *compr, uLong comprLen, |
34 | Bytef *uncompr, uLong uncomprLen)); | 31 | Bytef *uncompr, uLong uncomprLen)); |
35 | void test_gzio OF((const char *out, const char *in, | 32 | void test_gzio OF((char *out, char *in, |
36 | Bytef *uncompr, int uncomprLen)); | 33 | Bytef *uncompr, int uncomprLen)); |
37 | void test_deflate OF((Bytef *compr, uLong comprLen)); | 34 | void test_deflate OF((Bytef *compr, uLong comprLen)); |
38 | void test_inflate OF((Bytef *compr, uLong comprLen, | 35 | void test_inflate OF((Bytef *compr, uLong comprLen, |
@@ -44,9 +41,6 @@ void test_large_inflate OF((Bytef *compr, uLong comprLen, | |||
44 | void test_flush OF((Bytef *compr, uLong comprLen)); | 41 | void test_flush OF((Bytef *compr, uLong comprLen)); |
45 | void test_sync OF((Bytef *compr, uLong comprLen, | 42 | void test_sync OF((Bytef *compr, uLong comprLen, |
46 | Bytef *uncompr, uLong uncomprLen)); | 43 | Bytef *uncompr, uLong uncomprLen)); |
47 | void test_dict_deflate OF((Bytef *compr, uLong comprLen)); | ||
48 | void test_dict_inflate OF((Bytef *compr, uLong comprLen, | ||
49 | Bytef *uncompr, uLong uncomprLen)); | ||
50 | int main OF((int argc, char *argv[])); | 44 | int main OF((int argc, char *argv[])); |
51 | 45 | ||
52 | /* =========================================================================== | 46 | /* =========================================================================== |
@@ -59,7 +53,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen) | |||
59 | int err; | 53 | int err; |
60 | uLong len = strlen(hello)+1; | 54 | uLong len = strlen(hello)+1; |
61 | 55 | ||
62 | err = compress(compr, &comprLen, (const Bytef*)hello, len); | 56 | err = compress(compr, &comprLen, (Byte*)hello, len); |
63 | CHECK_ERR(err, "compress"); | 57 | CHECK_ERR(err, "compress"); |
64 | 58 | ||
65 | strcpy((char*)uncompr, "garbage"); | 59 | strcpy((char*)uncompr, "garbage"); |
@@ -78,8 +72,8 @@ void test_compress(compr, comprLen, uncompr, uncomprLen) | |||
78 | * Test read/write of .gz files | 72 | * Test read/write of .gz files |
79 | */ | 73 | */ |
80 | void test_gzio(out, in, uncompr, uncomprLen) | 74 | void test_gzio(out, in, uncompr, uncomprLen) |
81 | const char *out; /* output file */ | 75 | char *out; /* output file */ |
82 | const char *in; /* input file */ | 76 | char *in; /* input file */ |
83 | Bytef *uncompr; | 77 | Bytef *uncompr; |
84 | int uncomprLen; | 78 | int uncomprLen; |
85 | { | 79 | { |
@@ -93,7 +87,7 @@ void test_gzio(out, in, uncompr, uncomprLen) | |||
93 | exit(1); | 87 | exit(1); |
94 | } | 88 | } |
95 | 89 | ||
96 | if (gzwrite(file, (const voidp)hello, (unsigned)len) != len) { | 90 | if (gzwrite(file, hello, len) != len) { |
97 | fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err)); | 91 | fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err)); |
98 | } | 92 | } |
99 | gzclose(file); | 93 | gzclose(file); |
@@ -104,7 +98,7 @@ void test_gzio(out, in, uncompr, uncomprLen) | |||
104 | } | 98 | } |
105 | strcpy((char*)uncompr, "garbage"); | 99 | strcpy((char*)uncompr, "garbage"); |
106 | 100 | ||
107 | uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); | 101 | uncomprLen = gzread(file, uncompr, uncomprLen); |
108 | if (uncomprLen != len) { | 102 | if (uncomprLen != len) { |
109 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); | 103 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
110 | } | 104 | } |
@@ -177,7 +171,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen) | |||
177 | d_stream.next_in = compr; | 171 | d_stream.next_in = compr; |
178 | d_stream.next_out = uncompr; | 172 | d_stream.next_out = uncompr; |
179 | 173 | ||
180 | while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { | 174 | while (d_stream.total_out < uncomprLen) { |
181 | d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ | 175 | d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ |
182 | err = inflate(&d_stream, Z_NO_FLUSH); | 176 | err = inflate(&d_stream, Z_NO_FLUSH); |
183 | if (err == Z_STREAM_END) break; | 177 | if (err == Z_STREAM_END) break; |
@@ -212,7 +206,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) | |||
212 | CHECK_ERR(err, "deflateInit"); | 206 | CHECK_ERR(err, "deflateInit"); |
213 | 207 | ||
214 | c_stream.next_out = compr; | 208 | c_stream.next_out = compr; |
215 | c_stream.avail_out = (uInt)comprLen; | 209 | c_stream.avail_out = comprLen; |
216 | 210 | ||
217 | /* At this point, uncompr is still mostly zeroes, so it should compress | 211 | /* At this point, uncompr is still mostly zeroes, so it should compress |
218 | * very well: | 212 | * very well: |
@@ -271,7 +265,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) | |||
271 | 265 | ||
272 | for (;;) { | 266 | for (;;) { |
273 | d_stream.next_out = uncompr; /* discard the output */ | 267 | d_stream.next_out = uncompr; /* discard the output */ |
274 | d_stream.avail_out = (uInt)uncomprLen; | 268 | d_stream.avail_out = uncomprLen; |
275 | err = inflate(&d_stream, Z_NO_FLUSH); | 269 | err = inflate(&d_stream, Z_NO_FLUSH); |
276 | if (err == Z_STREAM_END) break; | 270 | if (err == Z_STREAM_END) break; |
277 | CHECK_ERR(err, "large inflate"); | 271 | CHECK_ERR(err, "large inflate"); |
@@ -350,7 +344,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen) | |||
350 | inflate(&d_stream, Z_NO_FLUSH); | 344 | inflate(&d_stream, Z_NO_FLUSH); |
351 | CHECK_ERR(err, "inflate"); | 345 | CHECK_ERR(err, "inflate"); |
352 | 346 | ||
353 | d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */ | 347 | d_stream.avail_in = (uInt)uncomprLen-2; /* read all compressed data */ |
354 | err = inflateSync(&d_stream); /* but skip the damaged part */ | 348 | err = inflateSync(&d_stream); /* but skip the damaged part */ |
355 | CHECK_ERR(err, "inflateSync"); | 349 | CHECK_ERR(err, "inflateSync"); |
356 | 350 | ||
@@ -366,91 +360,6 @@ void test_sync(compr, comprLen, uncompr, uncomprLen) | |||
366 | } | 360 | } |
367 | 361 | ||
368 | /* =========================================================================== | 362 | /* =========================================================================== |
369 | * Test deflate() with preset dictionary | ||
370 | */ | ||
371 | void test_dict_deflate(compr, comprLen) | ||
372 | Bytef *compr; | ||
373 | uLong comprLen; | ||
374 | { | ||
375 | z_stream c_stream; /* compression stream */ | ||
376 | int err; | ||
377 | |||
378 | c_stream.zalloc = (alloc_func)0; | ||
379 | c_stream.zfree = (free_func)0; | ||
380 | c_stream.opaque = (voidpf)0; | ||
381 | |||
382 | err = deflateInit(&c_stream, Z_BEST_COMPRESSION); | ||
383 | CHECK_ERR(err, "deflateInit"); | ||
384 | |||
385 | err = deflateSetDictionary(&c_stream, | ||
386 | (const Bytef*)dictionary, sizeof(dictionary)); | ||
387 | CHECK_ERR(err, "deflateSetDictionary"); | ||
388 | |||
389 | dictId = c_stream.adler; | ||
390 | c_stream.next_out = compr; | ||
391 | c_stream.avail_out = (uInt)comprLen; | ||
392 | |||
393 | c_stream.next_in = (Bytef*)hello; | ||
394 | c_stream.avail_in = (uInt)strlen(hello)+1; | ||
395 | |||
396 | err = deflate(&c_stream, Z_FINISH); | ||
397 | if (err != Z_STREAM_END) { | ||
398 | fprintf(stderr, "deflate should report Z_STREAM_END\n"); | ||
399 | } | ||
400 | err = deflateEnd(&c_stream); | ||
401 | CHECK_ERR(err, "deflateEnd"); | ||
402 | } | ||
403 | |||
404 | /* =========================================================================== | ||
405 | * Test inflate() with a preset dictionary | ||
406 | */ | ||
407 | void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) | ||
408 | Bytef *compr, *uncompr; | ||
409 | uLong comprLen, uncomprLen; | ||
410 | { | ||
411 | int err; | ||
412 | z_stream d_stream; /* decompression stream */ | ||
413 | |||
414 | strcpy((char*)uncompr, "garbage"); | ||
415 | |||
416 | d_stream.zalloc = (alloc_func)0; | ||
417 | d_stream.zfree = (free_func)0; | ||
418 | d_stream.opaque = (voidpf)0; | ||
419 | |||
420 | err = inflateInit(&d_stream); | ||
421 | CHECK_ERR(err, "inflateInit"); | ||
422 | |||
423 | d_stream.next_in = compr; | ||
424 | d_stream.avail_in = (uInt)comprLen; | ||
425 | |||
426 | d_stream.next_out = uncompr; | ||
427 | d_stream.avail_out = (uInt)uncomprLen; | ||
428 | |||
429 | for (;;) { | ||
430 | err = inflate(&d_stream, Z_NO_FLUSH); | ||
431 | if (err == Z_STREAM_END) break; | ||
432 | if (err == Z_NEED_DICT) { | ||
433 | if (d_stream.adler != dictId) { | ||
434 | fprintf(stderr, "unexpected dictionary"); | ||
435 | exit(1); | ||
436 | } | ||
437 | err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, | ||
438 | sizeof(dictionary)); | ||
439 | } | ||
440 | CHECK_ERR(err, "inflate with dict"); | ||
441 | } | ||
442 | |||
443 | err = inflateEnd(&d_stream); | ||
444 | CHECK_ERR(err, "inflateEnd"); | ||
445 | |||
446 | if (strcmp((char*)uncompr, hello)) { | ||
447 | fprintf(stderr, "bad inflate with dict\n"); | ||
448 | } else { | ||
449 | printf("inflate with dictionary: %s\n", uncompr); | ||
450 | } | ||
451 | } | ||
452 | |||
453 | /* =========================================================================== | ||
454 | * Usage: example [output.gz [input.gz]] | 363 | * Usage: example [output.gz [input.gz]] |
455 | */ | 364 | */ |
456 | 365 | ||
@@ -470,8 +379,8 @@ int main(argc, argv) | |||
470 | fprintf(stderr, "warning: different zlib version\n"); | 379 | fprintf(stderr, "warning: different zlib version\n"); |
471 | } | 380 | } |
472 | 381 | ||
473 | compr = (Bytef*)malloc((uInt)comprLen); | 382 | compr = (Bytef*)malloc(comprLen); |
474 | uncompr = (Bytef*)calloc((uInt)uncomprLen, 1); /* must be cleared */ | 383 | uncompr = (Bytef*)calloc(uncomprLen, 1); /* must be cleared initially */ |
475 | if (compr == Z_NULL || uncompr == Z_NULL) { | 384 | if (compr == Z_NULL || uncompr == Z_NULL) { |
476 | printf("out of memory\n"); | 385 | printf("out of memory\n"); |
477 | exit(1); | 386 | exit(1); |
@@ -492,9 +401,6 @@ int main(argc, argv) | |||
492 | test_flush(compr, comprLen); | 401 | test_flush(compr, comprLen); |
493 | test_sync(compr, comprLen, uncompr, uncomprLen); | 402 | test_sync(compr, comprLen, uncompr, uncomprLen); |
494 | 403 | ||
495 | test_dict_deflate(compr, comprLen); | ||
496 | test_dict_inflate(compr, comprLen, uncompr, uncomprLen); | ||
497 | |||
498 | exit(0); | 404 | exit(0); |
499 | return 0; /* to avoid warning */ | 405 | return 0; /* to avoid warning */ |
500 | } | 406 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* gzio.c -- IO on .gz files | 1 | /* gzio.c -- IO on .gz files |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -16,7 +16,8 @@ struct internal_state {int dummy;}; /* for buggy compilers */ | |||
16 | #define ALLOC(size) malloc(size) | 16 | #define ALLOC(size) malloc(size) |
17 | #define TRYFREE(p) {if (p) free(p);} | 17 | #define TRYFREE(p) {if (p) free(p);} |
18 | 18 | ||
19 | static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ | 19 | #define GZ_MAGIC_1 0x1f |
20 | #define GZ_MAGIC_2 0x8b | ||
20 | 21 | ||
21 | /* gzip flag byte */ | 22 | /* gzip flag byte */ |
22 | #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ | 23 | #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ |
@@ -26,6 +27,10 @@ static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ | |||
26 | #define COMMENT 0x10 /* bit 4 set: file comment present */ | 27 | #define COMMENT 0x10 /* bit 4 set: file comment present */ |
27 | #define RESERVED 0xE0 /* bits 5..7: reserved */ | 28 | #define RESERVED 0xE0 /* bits 5..7: reserved */ |
28 | 29 | ||
30 | #ifndef SEEK_CUR | ||
31 | # define SEEK_CUR 1 | ||
32 | #endif | ||
33 | |||
29 | typedef struct gz_stream { | 34 | typedef struct gz_stream { |
30 | z_stream stream; | 35 | z_stream stream; |
31 | int z_err; /* error code for last stream operation */ | 36 | int z_err; /* error code for last stream operation */ |
@@ -41,12 +46,40 @@ typedef struct gz_stream { | |||
41 | } gz_stream; | 46 | } gz_stream; |
42 | 47 | ||
43 | 48 | ||
44 | local gzFile gz_open OF((const char *path, const char *mode, int fd)); | 49 | local int destroy OF((gz_stream *s)); |
45 | local int get_byte OF((gz_stream *s)); | 50 | local gzFile gz_open OF((char *path, char *mode, int fd)); |
46 | local void check_header OF((gz_stream *s)); | 51 | local void putLong OF((FILE *file, uLong x)); |
47 | local int destroy OF((gz_stream *s)); | 52 | local uLong getLong OF((Bytef *buf)); |
48 | local void putLong OF((FILE *file, uLong x)); | 53 | |
49 | local uLong getLong OF((gz_stream *s)); | 54 | /* =========================================================================== |
55 | * Cleanup then free the given gz_stream. Return a zlib error code. | ||
56 | */ | ||
57 | local int destroy (s) | ||
58 | gz_stream *s; | ||
59 | { | ||
60 | int err = Z_OK; | ||
61 | |||
62 | if (!s) return Z_STREAM_ERROR; | ||
63 | |||
64 | TRYFREE(s->inbuf); | ||
65 | TRYFREE(s->outbuf); | ||
66 | TRYFREE(s->path); | ||
67 | TRYFREE(s->msg); | ||
68 | |||
69 | if (s->stream.state != NULL) { | ||
70 | if (s->mode == 'w') { | ||
71 | err = deflateEnd(&(s->stream)); | ||
72 | } else if (s->mode == 'r') { | ||
73 | err = inflateEnd(&(s->stream)); | ||
74 | } | ||
75 | } | ||
76 | if (s->file != NULL && fclose(s->file)) { | ||
77 | err = Z_ERRNO; | ||
78 | } | ||
79 | if (s->z_err < 0) err = s->z_err; | ||
80 | TRYFREE(s); | ||
81 | return err; | ||
82 | } | ||
50 | 83 | ||
51 | /* =========================================================================== | 84 | /* =========================================================================== |
52 | Opens a gzip (.gz) file for reading or writing. The mode parameter | 85 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
@@ -58,20 +91,15 @@ local uLong getLong OF((gz_stream *s)); | |||
58 | zlib error is Z_MEM_ERROR). | 91 | zlib error is Z_MEM_ERROR). |
59 | */ | 92 | */ |
60 | local gzFile gz_open (path, mode, fd) | 93 | local gzFile gz_open (path, mode, fd) |
61 | const char *path; | 94 | char *path; |
62 | const char *mode; | 95 | char *mode; |
63 | int fd; | 96 | int fd; |
64 | { | 97 | { |
65 | int err; | 98 | int err; |
66 | int level = Z_DEFAULT_COMPRESSION; /* compression level */ | 99 | int level = Z_DEFAULT_COMPRESSION; /* compression level */ |
67 | char *p = (char*)mode; | 100 | char *p = mode; |
68 | gz_stream *s; | 101 | gz_stream *s = (gz_stream *)ALLOC(sizeof(gz_stream)); |
69 | char fmode[80]; /* copy of mode, without the compression level */ | ||
70 | char *m = fmode; | ||
71 | |||
72 | if (!path || !mode) return Z_NULL; | ||
73 | 102 | ||
74 | s = (gz_stream *)ALLOC(sizeof(gz_stream)); | ||
75 | if (!s) return Z_NULL; | 103 | if (!s) return Z_NULL; |
76 | 104 | ||
77 | s->stream.zalloc = (alloc_func)0; | 105 | s->stream.zalloc = (alloc_func)0; |
@@ -96,13 +124,9 @@ local gzFile gz_open (path, mode, fd) | |||
96 | s->mode = '\0'; | 124 | s->mode = '\0'; |
97 | do { | 125 | do { |
98 | if (*p == 'r') s->mode = 'r'; | 126 | if (*p == 'r') s->mode = 'r'; |
99 | if (*p == 'w' || *p == 'a') s->mode = 'w'; | 127 | if (*p == 'w') s->mode = 'w'; |
100 | if (*p >= '0' && *p <= '9') { | 128 | if (*p >= '1' && *p <= '9') level = *p - '0'; |
101 | level = *p - '0'; | 129 | } while (*p++); |
102 | } else { | ||
103 | *m++ = *p; /* copy the mode */ | ||
104 | } | ||
105 | } while (*p++ && m != fmode + sizeof(fmode)); | ||
106 | if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; | 130 | if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; |
107 | 131 | ||
108 | if (s->mode == 'w') { | 132 | if (s->mode == 'w') { |
@@ -126,7 +150,7 @@ local gzFile gz_open (path, mode, fd) | |||
126 | s->stream.avail_out = Z_BUFSIZE; | 150 | s->stream.avail_out = Z_BUFSIZE; |
127 | 151 | ||
128 | errno = 0; | 152 | errno = 0; |
129 | s->file = fd < 0 ? FOPEN(path, fmode) : (FILE*)fdopen(fd, fmode); | 153 | s->file = fd < 0 ? FOPEN(path, mode) : (FILE*)fdopen(fd, mode); |
130 | 154 | ||
131 | if (s->file == NULL) { | 155 | if (s->file == NULL) { |
132 | return destroy(s), (gzFile)Z_NULL; | 156 | return destroy(s), (gzFile)Z_NULL; |
@@ -134,10 +158,50 @@ local gzFile gz_open (path, mode, fd) | |||
134 | if (s->mode == 'w') { | 158 | if (s->mode == 'w') { |
135 | /* Write a very simple .gz header: | 159 | /* Write a very simple .gz header: |
136 | */ | 160 | */ |
137 | fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], | 161 | fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", GZ_MAGIC_1, GZ_MAGIC_2, |
138 | Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); | 162 | Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); |
139 | } else { | 163 | } else { |
140 | check_header(s); /* skip the .gz header */ | 164 | /* Check and skip the header: |
165 | */ | ||
166 | Byte c1 = 0, c2 = 0; | ||
167 | Byte method = 0; | ||
168 | Byte flags = 0; | ||
169 | Byte xflags = 0; | ||
170 | Byte time[4]; | ||
171 | Byte osCode; | ||
172 | int c; | ||
173 | |||
174 | s->stream.avail_in = fread(s->inbuf, 1, 2, s->file); | ||
175 | if (s->stream.avail_in != 2 || s->inbuf[0] != GZ_MAGIC_1 | ||
176 | || s->inbuf[1] != GZ_MAGIC_2) { | ||
177 | s->transparent = 1; | ||
178 | return (gzFile)s; | ||
179 | } | ||
180 | s->stream.avail_in = 0; | ||
181 | fscanf(s->file,"%c%c%4c%c%c", &method, &flags, time, &xflags, &osCode); | ||
182 | |||
183 | if (method != Z_DEFLATED || feof(s->file) || (flags & RESERVED) != 0) { | ||
184 | s->z_err = Z_DATA_ERROR; | ||
185 | return (gzFile)s; | ||
186 | } | ||
187 | if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ | ||
188 | long len; | ||
189 | fscanf(s->file, "%c%c", &c1, &c2); | ||
190 | len = c1 + ((long)c2<<8); | ||
191 | fseek(s->file, len, SEEK_CUR); | ||
192 | } | ||
193 | if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ | ||
194 | while ((c = getc(s->file)) != 0 && c != EOF) ; | ||
195 | } | ||
196 | if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ | ||
197 | while ((c = getc(s->file)) != 0 && c != EOF) ; | ||
198 | } | ||
199 | if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ | ||
200 | fscanf(s->file, "%c%c", &c1, &c2); | ||
201 | } | ||
202 | if (feof(s->file)) { | ||
203 | s->z_err = Z_DATA_ERROR; | ||
204 | } | ||
141 | } | 205 | } |
142 | return (gzFile)s; | 206 | return (gzFile)s; |
143 | } | 207 | } |
@@ -146,139 +210,26 @@ local gzFile gz_open (path, mode, fd) | |||
146 | Opens a gzip (.gz) file for reading or writing. | 210 | Opens a gzip (.gz) file for reading or writing. |
147 | */ | 211 | */ |
148 | gzFile gzopen (path, mode) | 212 | gzFile gzopen (path, mode) |
149 | const char *path; | 213 | char *path; |
150 | const char *mode; | 214 | char *mode; |
151 | { | 215 | { |
152 | return gz_open (path, mode, -1); | 216 | return gz_open (path, mode, -1); |
153 | } | 217 | } |
154 | 218 | ||
155 | /* =========================================================================== | 219 | /* =========================================================================== |
156 | Associate a gzFile with the file descriptor fd. fd is not dup'ed here | 220 | Associate a gzFile with the file descriptor fd. |
157 | to mimic the behavio(u)r of fdopen. | ||
158 | */ | 221 | */ |
159 | gzFile gzdopen (fd, mode) | 222 | gzFile gzdopen (fd, mode) |
160 | int fd; | 223 | int fd; |
161 | const char *mode; | 224 | char *mode; |
162 | { | 225 | { |
163 | char name[20]; | 226 | char name[20]; |
164 | |||
165 | if (fd < 0) return (gzFile)Z_NULL; | ||
166 | sprintf(name, "<fd:%d>", fd); /* for debugging */ | 227 | sprintf(name, "<fd:%d>", fd); /* for debugging */ |
167 | 228 | ||
168 | return gz_open (name, mode, fd); | 229 | return gz_open (name, mode, fd); |
169 | } | 230 | } |
170 | 231 | ||
171 | /* =========================================================================== | 232 | /* =========================================================================== |
172 | Read a byte from a gz_stream; update next_in and avail_in. Return EOF | ||
173 | for end of file. | ||
174 | IN assertion: the stream s has been sucessfully opened for reading. | ||
175 | */ | ||
176 | local int get_byte(s) | ||
177 | gz_stream *s; | ||
178 | { | ||
179 | if (s->z_eof) return EOF; | ||
180 | if (s->stream.avail_in == 0) { | ||
181 | errno = 0; | ||
182 | s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); | ||
183 | if (s->stream.avail_in == 0) { | ||
184 | s->z_eof = 1; | ||
185 | if (ferror(s->file)) s->z_err = Z_ERRNO; | ||
186 | return EOF; | ||
187 | } | ||
188 | s->stream.next_in = s->inbuf; | ||
189 | } | ||
190 | s->stream.avail_in--; | ||
191 | return *(s->stream.next_in)++; | ||
192 | } | ||
193 | |||
194 | /* =========================================================================== | ||
195 | Check the gzip header of a gz_stream opened for reading. Set the stream | ||
196 | mode to transparent if the gzip magic header is not present; set s->err | ||
197 | to Z_DATA_ERROR if the magic header is present but the rest of the header | ||
198 | is incorrect. | ||
199 | IN assertion: the stream s has already been created sucessfully; | ||
200 | s->stream.avail_in is zero for the first time, but may be non-zero | ||
201 | for concatenated .gz files. | ||
202 | */ | ||
203 | local void check_header(s) | ||
204 | gz_stream *s; | ||
205 | { | ||
206 | int method = 0; | ||
207 | int flags = 0; | ||
208 | uInt len; | ||
209 | int c; | ||
210 | |||
211 | /* Check the gzip magic header */ | ||
212 | for (len = 0; len < 2; len++) { | ||
213 | c = get_byte(s); | ||
214 | if (c != gz_magic[len]) { | ||
215 | s->transparent = 1; | ||
216 | if (c != EOF) s->stream.avail_in++, s->stream.next_in--; | ||
217 | s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END; | ||
218 | return; | ||
219 | } | ||
220 | } | ||
221 | method = get_byte(s); | ||
222 | flags = get_byte(s); | ||
223 | if (method != Z_DEFLATED || (flags & RESERVED) != 0) { | ||
224 | s->z_err = Z_DATA_ERROR; | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | /* Discard time, xflags and OS code: */ | ||
229 | for (len = 0; len < 6; len++) (void)get_byte(s); | ||
230 | |||
231 | if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ | ||
232 | len = (uInt)get_byte(s); | ||
233 | len += ((uInt)get_byte(s))<<8; | ||
234 | /* len is garbage if EOF but the loop below will quit anyway */ | ||
235 | while (len-- != 0 && get_byte(s) != EOF) ; | ||
236 | } | ||
237 | if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ | ||
238 | while ((c = get_byte(s)) != 0 && c != EOF) ; | ||
239 | } | ||
240 | if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ | ||
241 | while ((c = get_byte(s)) != 0 && c != EOF) ; | ||
242 | } | ||
243 | if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ | ||
244 | for (len = 0; len < 2; len++) (void)get_byte(s); | ||
245 | } | ||
246 | s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; | ||
247 | } | ||
248 | |||
249 | /* =========================================================================== | ||
250 | * Cleanup then free the given gz_stream. Return a zlib error code. | ||
251 | Try freeing in the reverse order of allocations. | ||
252 | */ | ||
253 | local int destroy (s) | ||
254 | gz_stream *s; | ||
255 | { | ||
256 | int err = Z_OK; | ||
257 | |||
258 | if (!s) return Z_STREAM_ERROR; | ||
259 | |||
260 | TRYFREE(s->msg); | ||
261 | |||
262 | if (s->stream.state != NULL) { | ||
263 | if (s->mode == 'w') { | ||
264 | err = deflateEnd(&(s->stream)); | ||
265 | } else if (s->mode == 'r') { | ||
266 | err = inflateEnd(&(s->stream)); | ||
267 | } | ||
268 | } | ||
269 | if (s->file != NULL && fclose(s->file)) { | ||
270 | err = Z_ERRNO; | ||
271 | } | ||
272 | if (s->z_err < 0) err = s->z_err; | ||
273 | |||
274 | TRYFREE(s->inbuf); | ||
275 | TRYFREE(s->outbuf); | ||
276 | TRYFREE(s->path); | ||
277 | TRYFREE(s); | ||
278 | return err; | ||
279 | } | ||
280 | |||
281 | /* =========================================================================== | ||
282 | Reads the given number of uncompressed bytes from the compressed file. | 233 | Reads the given number of uncompressed bytes from the compressed file. |
283 | gzread returns the number of bytes actually read (0 for end of file). | 234 | gzread returns the number of bytes actually read (0 for end of file). |
284 | */ | 235 | */ |
@@ -288,71 +239,52 @@ int gzread (file, buf, len) | |||
288 | unsigned len; | 239 | unsigned len; |
289 | { | 240 | { |
290 | gz_stream *s = (gz_stream*)file; | 241 | gz_stream *s = (gz_stream*)file; |
291 | Byte *start = buf; /* starting point for crc computation */ | ||
292 | 242 | ||
293 | if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; | 243 | if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; |
294 | 244 | ||
295 | if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; | 245 | if (s->transparent) { |
296 | if (s->z_err == Z_STREAM_END) return 0; /* EOF */ | 246 | int n = 0; |
247 | Byte *b = (Byte*)buf; | ||
248 | /* Copy the first two (non-magic) bytes if not done already */ | ||
249 | while (s->stream.avail_in > 0 && len > 0) { | ||
250 | *b++ = *s->stream.next_in++; | ||
251 | s->stream.avail_in--; | ||
252 | len--; n++; | ||
253 | } | ||
254 | if (len == 0) return n; | ||
255 | return n + fread(b, 1, len, s->file); | ||
256 | } | ||
257 | if (s->z_err == Z_DATA_ERROR) return -1; /* bad .gz file */ | ||
258 | if (s->z_err == Z_STREAM_END) return 0; /* don't read crc as data */ | ||
297 | 259 | ||
298 | s->stream.next_out = buf; | 260 | s->stream.next_out = buf; |
299 | s->stream.avail_out = len; | 261 | s->stream.avail_out = len; |
300 | 262 | ||
301 | while (s->stream.avail_out != 0) { | 263 | while (s->stream.avail_out != 0) { |
302 | 264 | ||
303 | if (s->transparent) { | ||
304 | /* Copy first the lookahead bytes: */ | ||
305 | uInt n = s->stream.avail_in; | ||
306 | if (n > s->stream.avail_out) n = s->stream.avail_out; | ||
307 | if (n > 0) { | ||
308 | zmemcpy(s->stream.next_out, s->stream.next_in, n); | ||
309 | s->stream.next_out += n; | ||
310 | s->stream.next_in += n; | ||
311 | s->stream.avail_out -= n; | ||
312 | s->stream.avail_in -= n; | ||
313 | } | ||
314 | if (s->stream.avail_out > 0) { | ||
315 | s->stream.avail_out -= fread(s->stream.next_out, | ||
316 | 1, s->stream.avail_out, s->file); | ||
317 | } | ||
318 | return (int)(len - s->stream.avail_out); | ||
319 | } | ||
320 | if (s->stream.avail_in == 0 && !s->z_eof) { | 265 | if (s->stream.avail_in == 0 && !s->z_eof) { |
321 | 266 | ||
322 | errno = 0; | 267 | errno = 0; |
323 | s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); | 268 | s->stream.avail_in = |
269 | fread(s->inbuf, 1, Z_BUFSIZE, s->file); | ||
324 | if (s->stream.avail_in == 0) { | 270 | if (s->stream.avail_in == 0) { |
325 | s->z_eof = 1; | 271 | s->z_eof = 1; |
326 | if (ferror(s->file)) { | 272 | } else if (s->stream.avail_in == (uInt)EOF) { |
327 | s->z_err = Z_ERRNO; | 273 | s->stream.avail_in = 0; |
328 | break; | 274 | s->z_eof = 1; |
329 | } | 275 | s->z_err = Z_ERRNO; |
276 | break; | ||
330 | } | 277 | } |
331 | s->stream.next_in = s->inbuf; | 278 | s->stream.next_in = s->inbuf; |
332 | } | 279 | } |
333 | s->z_err = inflate(&(s->stream), Z_NO_FLUSH); | 280 | s->z_err = inflate(&(s->stream), Z_NO_FLUSH); |
334 | 281 | ||
335 | if (s->z_err == Z_STREAM_END) { | 282 | if (s->z_err == Z_STREAM_END || |
336 | /* Check CRC and original size */ | 283 | s->z_err != Z_OK || s->z_eof) break; |
337 | s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); | ||
338 | start = s->stream.next_out; | ||
339 | |||
340 | if (getLong(s) != s->crc || getLong(s) != s->stream.total_out) { | ||
341 | s->z_err = Z_DATA_ERROR; | ||
342 | } else { | ||
343 | /* Check for concatenated .gz files: */ | ||
344 | check_header(s); | ||
345 | if (s->z_err == Z_OK) { | ||
346 | inflateReset(&(s->stream)); | ||
347 | s->crc = crc32(0L, Z_NULL, 0); | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | if (s->z_err != Z_OK || s->z_eof) break; | ||
352 | } | 284 | } |
353 | s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); | 285 | len -= s->stream.avail_out; |
354 | 286 | s->crc = crc32(s->crc, buf, len); | |
355 | return (int)(len - s->stream.avail_out); | 287 | return (int)len; |
356 | } | 288 | } |
357 | 289 | ||
358 | /* =========================================================================== | 290 | /* =========================================================================== |
@@ -361,7 +293,7 @@ int gzread (file, buf, len) | |||
361 | */ | 293 | */ |
362 | int gzwrite (file, buf, len) | 294 | int gzwrite (file, buf, len) |
363 | gzFile file; | 295 | gzFile file; |
364 | const voidp buf; | 296 | voidp buf; |
365 | unsigned len; | 297 | unsigned len; |
366 | { | 298 | { |
367 | gz_stream *s = (gz_stream*)file; | 299 | gz_stream *s = (gz_stream*)file; |
@@ -412,7 +344,7 @@ int gzflush (file, flush) | |||
412 | len = Z_BUFSIZE - s->stream.avail_out; | 344 | len = Z_BUFSIZE - s->stream.avail_out; |
413 | 345 | ||
414 | if (len != 0) { | 346 | if (len != 0) { |
415 | if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) { | 347 | if (fwrite(s->outbuf, 1, len, s->file) != len) { |
416 | s->z_err = Z_ERRNO; | 348 | s->z_err = Z_ERRNO; |
417 | return Z_ERRNO; | 349 | return Z_ERRNO; |
418 | } | 350 | } |
@@ -448,19 +380,18 @@ local void putLong (file, x) | |||
448 | } | 380 | } |
449 | 381 | ||
450 | /* =========================================================================== | 382 | /* =========================================================================== |
451 | Reads a long in LSB order from the given gz_stream. Sets | 383 | Reads a long in LSB order from the given buffer |
452 | */ | 384 | */ |
453 | local uLong getLong (s) | 385 | local uLong getLong (buf) |
454 | gz_stream *s; | 386 | Bytef *buf; |
455 | { | 387 | { |
456 | uLong x = (uLong)get_byte(s); | 388 | uLong x = 0; |
457 | int c; | 389 | Bytef *p = buf+4; |
458 | 390 | ||
459 | x += ((uLong)get_byte(s))<<8; | 391 | do { |
460 | x += ((uLong)get_byte(s))<<16; | 392 | x <<= 8; |
461 | c = get_byte(s); | 393 | x |= *--p; |
462 | if (c == EOF) s->z_err = Z_DATA_ERROR; | 394 | } while (p != buf); |
463 | x += ((uLong)c)<<24; | ||
464 | return x; | 395 | return x; |
465 | } | 396 | } |
466 | 397 | ||
@@ -471,6 +402,7 @@ local uLong getLong (s) | |||
471 | int gzclose (file) | 402 | int gzclose (file) |
472 | gzFile file; | 403 | gzFile file; |
473 | { | 404 | { |
405 | uInt n; | ||
474 | int err; | 406 | int err; |
475 | gz_stream *s = (gz_stream*)file; | 407 | gz_stream *s = (gz_stream*)file; |
476 | 408 | ||
@@ -483,6 +415,25 @@ int gzclose (file) | |||
483 | putLong (s->file, s->crc); | 415 | putLong (s->file, s->crc); |
484 | putLong (s->file, s->stream.total_in); | 416 | putLong (s->file, s->stream.total_in); |
485 | 417 | ||
418 | } else if (s->mode == 'r' && s->z_err == Z_STREAM_END) { | ||
419 | |||
420 | /* slide CRC and original size if they are at the end of inbuf */ | ||
421 | if ((n = s->stream.avail_in) < 8 && !s->z_eof) { | ||
422 | Byte *p = s->inbuf; | ||
423 | Bytef *q = s->stream.next_in; | ||
424 | while (n--) { *p++ = *q++; }; | ||
425 | |||
426 | n = s->stream.avail_in; | ||
427 | n += fread(p, 1, 8, s->file); | ||
428 | s->stream.next_in = s->inbuf; | ||
429 | } | ||
430 | /* check CRC and original size */ | ||
431 | if (n < 8 || | ||
432 | getLong(s->stream.next_in) != s->crc || | ||
433 | getLong(s->stream.next_in + 4) != s->stream.total_out) { | ||
434 | |||
435 | s->z_err = Z_DATA_ERROR; | ||
436 | } | ||
486 | } | 437 | } |
487 | return destroy(file); | 438 | return destroy(file); |
488 | } | 439 | } |
@@ -503,14 +454,14 @@ char* gzerror (file, errnum) | |||
503 | 454 | ||
504 | if (s == NULL) { | 455 | if (s == NULL) { |
505 | *errnum = Z_STREAM_ERROR; | 456 | *errnum = Z_STREAM_ERROR; |
506 | return ERR_MSG(Z_STREAM_ERROR); | 457 | return z_errmsg[1-Z_STREAM_ERROR]; |
507 | } | 458 | } |
508 | *errnum = s->z_err; | 459 | *errnum = s->z_err; |
509 | if (*errnum == Z_OK) return (char*)""; | 460 | if (*errnum == Z_OK) return ""; |
510 | 461 | ||
511 | m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); | 462 | m = *errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg; |
512 | 463 | ||
513 | if (m == NULL || *m == '\0') m = (char*)z_errmsg[1-s->z_err]; | 464 | if (m == NULL || *m == '\0') m = z_errmsg[1-s->z_err]; |
514 | 465 | ||
515 | TRYFREE(s->msg); | 466 | TRYFREE(s->msg); |
516 | s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); | 467 | s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); |
@@ -1,5 +1,5 @@ | |||
1 | /* infblock.c -- interpret and process block types to last block | 1 | /* infblock.c -- interpret and process block types to last block |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -81,7 +81,7 @@ uLongf *c; | |||
81 | s->bitb = 0; | 81 | s->bitb = 0; |
82 | s->read = s->write = s->window; | 82 | s->read = s->write = s->window; |
83 | if (s->checkfn != Z_NULL) | 83 | if (s->checkfn != Z_NULL) |
84 | z->adler = s->check = (*s->checkfn)(0L, Z_NULL, 0); | 84 | s->check = (*s->checkfn)(0L, Z_NULL, 0); |
85 | Trace((stderr, "inflate: blocks reset\n")); | 85 | Trace((stderr, "inflate: blocks reset\n")); |
86 | } | 86 | } |
87 | 87 | ||
@@ -172,7 +172,7 @@ int r; | |||
172 | case 3: /* illegal */ | 172 | case 3: /* illegal */ |
173 | DUMPBITS(3) | 173 | DUMPBITS(3) |
174 | s->mode = BAD; | 174 | s->mode = BAD; |
175 | z->msg = (char*)"invalid block type"; | 175 | z->msg = "invalid block type"; |
176 | r = Z_DATA_ERROR; | 176 | r = Z_DATA_ERROR; |
177 | LEAVE | 177 | LEAVE |
178 | } | 178 | } |
@@ -182,7 +182,7 @@ int r; | |||
182 | if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) | 182 | if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) |
183 | { | 183 | { |
184 | s->mode = BAD; | 184 | s->mode = BAD; |
185 | z->msg = (char*)"invalid stored block lengths"; | 185 | z->msg = "invalid stored block lengths"; |
186 | r = Z_DATA_ERROR; | 186 | r = Z_DATA_ERROR; |
187 | LEAVE | 187 | LEAVE |
188 | } | 188 | } |
@@ -215,7 +215,7 @@ int r; | |||
215 | if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) | 215 | if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) |
216 | { | 216 | { |
217 | s->mode = BAD; | 217 | s->mode = BAD; |
218 | z->msg = (char*)"too many length or distance symbols"; | 218 | z->msg = "too many length or distance symbols"; |
219 | r = Z_DATA_ERROR; | 219 | r = Z_DATA_ERROR; |
220 | LEAVE | 220 | LEAVE |
221 | } | 221 | } |
@@ -285,7 +285,7 @@ int r; | |||
285 | (c == 16 && i < 1)) | 285 | (c == 16 && i < 1)) |
286 | { | 286 | { |
287 | s->mode = BAD; | 287 | s->mode = BAD; |
288 | z->msg = (char*)"invalid bit length repeat"; | 288 | z->msg = "invalid bit length repeat"; |
289 | r = Z_DATA_ERROR; | 289 | r = Z_DATA_ERROR; |
290 | LEAVE | 290 | LEAVE |
291 | } | 291 | } |
@@ -383,14 +383,3 @@ uLongf *c; | |||
383 | Trace((stderr, "inflate: blocks freed\n")); | 383 | Trace((stderr, "inflate: blocks freed\n")); |
384 | return Z_OK; | 384 | return Z_OK; |
385 | } | 385 | } |
386 | |||
387 | |||
388 | void inflate_set_dictionary(s, z, d, n) | ||
389 | inflate_blocks_statef *s; | ||
390 | z_stream *z; | ||
391 | const Bytef *d; | ||
392 | uInt n; | ||
393 | { | ||
394 | zmemcpy((charf *)s->window, d, n); | ||
395 | s->read = s->write = s->window + n; | ||
396 | } | ||
@@ -1,5 +1,5 @@ | |||
1 | /* infblock.h -- header to use infblock.c | 1 | /* infblock.h -- header to use infblock.c |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -30,9 +30,3 @@ extern int inflate_blocks_free OF(( | |||
30 | inflate_blocks_statef *, | 30 | inflate_blocks_statef *, |
31 | z_stream *, | 31 | z_stream *, |
32 | uLongf *)); /* check value on output */ | 32 | uLongf *)); /* check value on output */ |
33 | |||
34 | extern void inflate_set_dictionary OF(( | ||
35 | inflate_blocks_statef *s, | ||
36 | z_stream *z, | ||
37 | const Bytef *d, /* dictionary */ | ||
38 | uInt n)); /* dictionary length */ | ||
@@ -1,5 +1,5 @@ | |||
1 | /* infcodes.c -- process literals and length/distance pairs | 1 | /* infcodes.c -- process literals and length/distance pairs |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -58,8 +58,7 @@ struct inflate_codes_state { | |||
58 | 58 | ||
59 | inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z) | 59 | inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z) |
60 | uInt bl, bd; | 60 | uInt bl, bd; |
61 | inflate_huft *tl; | 61 | inflate_huft *tl, *td; |
62 | inflate_huft *td; /* need separate declaration for Borland C++ */ | ||
63 | z_stream *z; | 62 | z_stream *z; |
64 | { | 63 | { |
65 | inflate_codes_statef *c; | 64 | inflate_codes_statef *c; |
@@ -153,7 +152,7 @@ int r; | |||
153 | break; | 152 | break; |
154 | } | 153 | } |
155 | c->mode = BADCODE; /* invalid code */ | 154 | c->mode = BADCODE; /* invalid code */ |
156 | z->msg = (char*)"invalid literal/length code"; | 155 | z->msg = "invalid literal/length code"; |
157 | r = Z_DATA_ERROR; | 156 | r = Z_DATA_ERROR; |
158 | LEAVE | 157 | LEAVE |
159 | case LENEXT: /* i: getting length extra (have base) */ | 158 | case LENEXT: /* i: getting length extra (have base) */ |
@@ -185,7 +184,7 @@ int r; | |||
185 | break; | 184 | break; |
186 | } | 185 | } |
187 | c->mode = BADCODE; /* invalid code */ | 186 | c->mode = BADCODE; /* invalid code */ |
188 | z->msg = (char*)"invalid distance code"; | 187 | z->msg = "invalid distance code"; |
189 | r = Z_DATA_ERROR; | 188 | r = Z_DATA_ERROR; |
190 | LEAVE | 189 | LEAVE |
191 | case DISTEXT: /* i: getting distance extra */ | 190 | case DISTEXT: /* i: getting distance extra */ |
@@ -1,5 +1,5 @@ | |||
1 | /* infcodes.h -- header to use infcodes.c | 1 | /* infcodes.h -- header to use infcodes.c |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* inffast.c -- process literals and length/distance pairs fast | 1 | /* inffast.c -- process literals and length/distance pairs fast |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -29,8 +29,7 @@ struct inflate_codes_state {int dummy;}; /* for buggy compilers */ | |||
29 | 29 | ||
30 | int inflate_fast(bl, bd, tl, td, s, z) | 30 | int inflate_fast(bl, bd, tl, td, s, z) |
31 | uInt bl, bd; | 31 | uInt bl, bd; |
32 | inflate_huft *tl; | 32 | inflate_huft *tl, *td; |
33 | inflate_huft *td; /* need separate declaration for Borland C++ */ | ||
34 | inflate_blocks_statef *s; | 33 | inflate_blocks_statef *s; |
35 | z_stream *z; | 34 | z_stream *z; |
36 | { | 35 | { |
@@ -123,7 +122,7 @@ z_stream *z; | |||
123 | e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop; | 122 | e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop; |
124 | else | 123 | else |
125 | { | 124 | { |
126 | z->msg = (char*)"invalid distance code"; | 125 | z->msg = "invalid distance code"; |
127 | UNGRAB | 126 | UNGRAB |
128 | UPDATE | 127 | UPDATE |
129 | return Z_DATA_ERROR; | 128 | return Z_DATA_ERROR; |
@@ -153,7 +152,7 @@ z_stream *z; | |||
153 | } | 152 | } |
154 | else | 153 | else |
155 | { | 154 | { |
156 | z->msg = (char*)"invalid literal/length code"; | 155 | z->msg = "invalid literal/length code"; |
157 | UNGRAB | 156 | UNGRAB |
158 | UPDATE | 157 | UPDATE |
159 | return Z_DATA_ERROR; | 158 | return Z_DATA_ERROR; |
@@ -1,5 +1,5 @@ | |||
1 | /* inffast.h -- header to use inffast.c | 1 | /* inffast.h -- header to use inffast.c |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* inflate.c -- zlib interface to inflate modules | 1 | /* inflate.c -- zlib interface to inflate modules |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -15,11 +15,6 @@ struct internal_state { | |||
15 | enum { | 15 | enum { |
16 | METHOD, /* waiting for method byte */ | 16 | METHOD, /* waiting for method byte */ |
17 | FLAG, /* waiting for flag byte */ | 17 | FLAG, /* waiting for flag byte */ |
18 | DICT4, /* four dictionary check bytes to go */ | ||
19 | DICT3, /* three dictionary check bytes to go */ | ||
20 | DICT2, /* two dictionary check bytes to go */ | ||
21 | DICT1, /* one dictionary check byte to go */ | ||
22 | DICT0, /* waiting for inflateSetDictionary */ | ||
23 | BLOCKS, /* decompressing blocks */ | 18 | BLOCKS, /* decompressing blocks */ |
24 | CHECK4, /* four check bytes to go */ | 19 | CHECK4, /* four check bytes to go */ |
25 | CHECK3, /* three check bytes to go */ | 20 | CHECK3, /* three check bytes to go */ |
@@ -80,16 +75,10 @@ z_stream *z; | |||
80 | } | 75 | } |
81 | 76 | ||
82 | 77 | ||
83 | int inflateInit2_(z, w, version, stream_size) | 78 | int inflateInit2(z, w) |
84 | z_stream *z; | 79 | z_stream *z; |
85 | int w; | 80 | int w; |
86 | const char *version; | ||
87 | int stream_size; | ||
88 | { | 81 | { |
89 | if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || | ||
90 | stream_size != sizeof(z_stream)) | ||
91 | return Z_VERSION_ERROR; | ||
92 | |||
93 | /* initialize state */ | 82 | /* initialize state */ |
94 | if (z == Z_NULL) | 83 | if (z == Z_NULL) |
95 | return Z_STREAM_ERROR; | 84 | return Z_STREAM_ERROR; |
@@ -123,7 +112,7 @@ int stream_size; | |||
123 | 112 | ||
124 | /* create inflate_blocks state */ | 113 | /* create inflate_blocks state */ |
125 | if ((z->state->blocks = | 114 | if ((z->state->blocks = |
126 | inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) | 115 | inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w)) |
127 | == Z_NULL) | 116 | == Z_NULL) |
128 | { | 117 | { |
129 | inflateEnd(z); | 118 | inflateEnd(z); |
@@ -137,12 +126,10 @@ int stream_size; | |||
137 | } | 126 | } |
138 | 127 | ||
139 | 128 | ||
140 | int inflateInit_(z, version, stream_size) | 129 | int inflateInit(z) |
141 | z_stream *z; | 130 | z_stream *z; |
142 | const char *version; | ||
143 | int stream_size; | ||
144 | { | 131 | { |
145 | return inflateInit2_(z, DEF_WBITS, version, stream_size); | 132 | return inflateInit2(z, DEF_WBITS); |
146 | } | 133 | } |
147 | 134 | ||
148 | 135 | ||
@@ -156,7 +143,7 @@ int f; | |||
156 | int r = f; /* to avoid warning about unused f */ | 143 | int r = f; /* to avoid warning about unused f */ |
157 | uInt b; | 144 | uInt b; |
158 | 145 | ||
159 | if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL) | 146 | if (z == Z_NULL || z->next_in == Z_NULL) |
160 | return Z_STREAM_ERROR; | 147 | return Z_STREAM_ERROR; |
161 | r = Z_BUF_ERROR; | 148 | r = Z_BUF_ERROR; |
162 | while (1) switch (z->state->mode) | 149 | while (1) switch (z->state->mode) |
@@ -166,58 +153,36 @@ int f; | |||
166 | if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) | 153 | if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) |
167 | { | 154 | { |
168 | z->state->mode = BAD; | 155 | z->state->mode = BAD; |
169 | z->msg = (char*)"unknown compression method"; | 156 | z->msg = "unknown compression method"; |
170 | z->state->sub.marker = 5; /* can't try inflateSync */ | 157 | z->state->sub.marker = 5; /* can't try inflateSync */ |
171 | break; | 158 | break; |
172 | } | 159 | } |
173 | if ((z->state->sub.method >> 4) + 8 > z->state->wbits) | 160 | if ((z->state->sub.method >> 4) + 8 > z->state->wbits) |
174 | { | 161 | { |
175 | z->state->mode = BAD; | 162 | z->state->mode = BAD; |
176 | z->msg = (char*)"invalid window size"; | 163 | z->msg = "invalid window size"; |
177 | z->state->sub.marker = 5; /* can't try inflateSync */ | 164 | z->state->sub.marker = 5; /* can't try inflateSync */ |
178 | break; | 165 | break; |
179 | } | 166 | } |
180 | z->state->mode = FLAG; | 167 | z->state->mode = FLAG; |
181 | case FLAG: | 168 | case FLAG: |
182 | NEEDBYTE | 169 | NEEDBYTE |
183 | b = NEXTBYTE; | 170 | if ((b = NEXTBYTE) & 0x20) |
184 | if (((z->state->sub.method << 8) + b) % 31) | ||
185 | { | 171 | { |
186 | z->state->mode = BAD; | 172 | z->state->mode = BAD; |
187 | z->msg = (char*)"incorrect header check"; | 173 | z->msg = "invalid reserved bit"; |
188 | z->state->sub.marker = 5; /* can't try inflateSync */ | 174 | z->state->sub.marker = 5; /* can't try inflateSync */ |
189 | break; | 175 | break; |
190 | } | 176 | } |
191 | Trace((stderr, "inflate: zlib header ok\n")); | 177 | if (((z->state->sub.method << 8) + b) % 31) |
192 | if (!(b & PRESET_DICT)) | ||
193 | { | 178 | { |
194 | z->state->mode = BLOCKS; | 179 | z->state->mode = BAD; |
195 | break; | 180 | z->msg = "incorrect header check"; |
181 | z->state->sub.marker = 5; /* can't try inflateSync */ | ||
182 | break; | ||
196 | } | 183 | } |
197 | z->state->mode = DICT4; | 184 | Trace((stderr, "inflate: zlib header ok\n")); |
198 | case DICT4: | 185 | z->state->mode = BLOCKS; |
199 | NEEDBYTE | ||
200 | z->state->sub.check.need = (uLong)NEXTBYTE << 24; | ||
201 | z->state->mode = DICT3; | ||
202 | case DICT3: | ||
203 | NEEDBYTE | ||
204 | z->state->sub.check.need += (uLong)NEXTBYTE << 16; | ||
205 | z->state->mode = DICT2; | ||
206 | case DICT2: | ||
207 | NEEDBYTE | ||
208 | z->state->sub.check.need += (uLong)NEXTBYTE << 8; | ||
209 | z->state->mode = DICT1; | ||
210 | case DICT1: | ||
211 | NEEDBYTE | ||
212 | z->state->sub.check.need += (uLong)NEXTBYTE; | ||
213 | z->adler = z->state->sub.check.need; | ||
214 | z->state->mode = DICT0; | ||
215 | return Z_NEED_DICT; | ||
216 | case DICT0: | ||
217 | z->state->mode = BAD; | ||
218 | z->msg = (char*)"need dictionary"; | ||
219 | z->state->sub.marker = 0; /* can try inflateSync */ | ||
220 | return Z_STREAM_ERROR; | ||
221 | case BLOCKS: | 186 | case BLOCKS: |
222 | r = inflate_blocks(z->state->blocks, z, r); | 187 | r = inflate_blocks(z->state->blocks, z, r); |
223 | if (r == Z_DATA_ERROR) | 188 | if (r == Z_DATA_ERROR) |
@@ -255,7 +220,7 @@ int f; | |||
255 | if (z->state->sub.check.was != z->state->sub.check.need) | 220 | if (z->state->sub.check.was != z->state->sub.check.need) |
256 | { | 221 | { |
257 | z->state->mode = BAD; | 222 | z->state->mode = BAD; |
258 | z->msg = (char*)"incorrect data check"; | 223 | z->msg = "incorrect data check"; |
259 | z->state->sub.marker = 5; /* can't try inflateSync */ | 224 | z->state->sub.marker = 5; /* can't try inflateSync */ |
260 | break; | 225 | break; |
261 | } | 226 | } |
@@ -271,29 +236,6 @@ int f; | |||
271 | } | 236 | } |
272 | 237 | ||
273 | 238 | ||
274 | int inflateSetDictionary(z, dictionary, dictLength) | ||
275 | z_stream *z; | ||
276 | const Bytef *dictionary; | ||
277 | uInt dictLength; | ||
278 | { | ||
279 | uInt length = dictLength; | ||
280 | |||
281 | if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0) | ||
282 | return Z_STREAM_ERROR; | ||
283 | if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; | ||
284 | z->adler = 1L; | ||
285 | |||
286 | if (length >= (1<<z->state->wbits)) | ||
287 | { | ||
288 | length = (1<<z->state->wbits)-1; | ||
289 | dictionary += dictLength - length; | ||
290 | } | ||
291 | inflate_set_dictionary(z->state->blocks, z, dictionary, length); | ||
292 | z->state->mode = BLOCKS; | ||
293 | return Z_OK; | ||
294 | } | ||
295 | |||
296 | |||
297 | int inflateSync(z) | 239 | int inflateSync(z) |
298 | z_stream *z; | 240 | z_stream *z; |
299 | { | 241 | { |
@@ -1,12 +1,12 @@ | |||
1 | /* inftrees.c -- generate Huffman trees for efficient decoding | 1 | /* inftrees.c -- generate Huffman trees for efficient decoding |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | #include "zutil.h" | 6 | #include "zutil.h" |
7 | #include "inftrees.h" | 7 | #include "inftrees.h" |
8 | 8 | ||
9 | char inflate_copyright[] = " inflate 1.0 Copyright 1995-1996 Mark Adler "; | 9 | char inflate_copyright[] = " inflate 1.0 Copyright 1995 Mark Adler "; |
10 | /* | 10 | /* |
11 | If you use the zlib library in a product, an acknowledgment is welcome | 11 | If you use the zlib library in a product, an acknowledgment is welcome |
12 | in the documentation of your product. If for some reason you cannot | 12 | in the documentation of your product. If for some reason you cannot |
@@ -38,18 +38,18 @@ local voidpf falloc OF(( | |||
38 | uInt)); /* size of item */ | 38 | uInt)); /* size of item */ |
39 | 39 | ||
40 | /* Tables for deflate from PKZIP's appnote.txt. */ | 40 | /* Tables for deflate from PKZIP's appnote.txt. */ |
41 | local uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */ | 41 | local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */ |
42 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, | 42 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, |
43 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; | 43 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; |
44 | /* actually lengths - 2; also see note #13 above about 258 */ | 44 | /* actually lengths - 2; also see note #13 above about 258 */ |
45 | local uInt cplext[31] = { /* Extra bits for literal codes 257..285 */ | 45 | local uInt cplext[] = { /* Extra bits for literal codes 257..285 */ |
46 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, | 46 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, |
47 | 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */ | 47 | 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */ |
48 | local uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */ | 48 | local uInt cpdist[] = { /* Copy offsets for distance codes 0..29 */ |
49 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, | 49 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, |
50 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, | 50 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, |
51 | 8193, 12289, 16385, 24577}; | 51 | 8193, 12289, 16385, 24577}; |
52 | local uInt cpdext[30] = { /* Extra bits for distance codes */ | 52 | local uInt cpdext[] = { /* Extra bits for distance codes */ |
53 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, | 53 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, |
54 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, | 54 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, |
55 | 12, 12, 13, 13}; | 55 | 12, 12, 13, 13}; |
@@ -307,11 +307,11 @@ z_stream *z; /* for zfree function */ | |||
307 | 307 | ||
308 | r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z); | 308 | r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z); |
309 | if (r == Z_DATA_ERROR) | 309 | if (r == Z_DATA_ERROR) |
310 | z->msg = (char*)"oversubscribed dynamic bit lengths tree"; | 310 | z->msg = "oversubscribed dynamic bit lengths tree"; |
311 | else if (r == Z_BUF_ERROR) | 311 | else if (r == Z_BUF_ERROR) |
312 | { | 312 | { |
313 | inflate_trees_free(*tb, z); | 313 | inflate_trees_free(*tb, z); |
314 | z->msg = (char*)"incomplete dynamic bit lengths tree"; | 314 | z->msg = "incomplete dynamic bit lengths tree"; |
315 | r = Z_DATA_ERROR; | 315 | r = Z_DATA_ERROR; |
316 | } | 316 | } |
317 | return r; | 317 | return r; |
@@ -334,11 +334,11 @@ z_stream *z; /* for zfree function */ | |||
334 | if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK) | 334 | if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK) |
335 | { | 335 | { |
336 | if (r == Z_DATA_ERROR) | 336 | if (r == Z_DATA_ERROR) |
337 | z->msg = (char*)"oversubscribed literal/length tree"; | 337 | z->msg = "oversubscribed literal/length tree"; |
338 | else if (r == Z_BUF_ERROR) | 338 | else if (r == Z_BUF_ERROR) |
339 | { | 339 | { |
340 | inflate_trees_free(*tl, z); | 340 | inflate_trees_free(*tl, z); |
341 | z->msg = (char*)"incomplete literal/length tree"; | 341 | z->msg = "incomplete literal/length tree"; |
342 | r = Z_DATA_ERROR; | 342 | r = Z_DATA_ERROR; |
343 | } | 343 | } |
344 | return r; | 344 | return r; |
@@ -348,14 +348,14 @@ z_stream *z; /* for zfree function */ | |||
348 | if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK) | 348 | if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK) |
349 | { | 349 | { |
350 | if (r == Z_DATA_ERROR) | 350 | if (r == Z_DATA_ERROR) |
351 | z->msg = (char*)"oversubscribed literal/length tree"; | 351 | z->msg = "oversubscribed literal/length tree"; |
352 | else if (r == Z_BUF_ERROR) { | 352 | else if (r == Z_BUF_ERROR) { |
353 | #ifdef PKZIP_BUG_WORKAROUND | 353 | #ifdef PKZIP_BUG_WORKAROUND |
354 | r = Z_OK; | 354 | r = Z_OK; |
355 | } | 355 | } |
356 | #else | 356 | #else |
357 | inflate_trees_free(*td, z); | 357 | inflate_trees_free(*td, z); |
358 | z->msg = (char*)"incomplete literal/length tree"; | 358 | z->msg = "incomplete literal/length tree"; |
359 | r = Z_DATA_ERROR; | 359 | r = Z_DATA_ERROR; |
360 | } | 360 | } |
361 | inflate_trees_free(*tl, z); | 361 | inflate_trees_free(*tl, z); |
@@ -385,7 +385,7 @@ uInt s; /* size of item */ | |||
385 | { | 385 | { |
386 | Assert(s == sizeof(inflate_huft) && n <= *(intf *)q, | 386 | Assert(s == sizeof(inflate_huft) && n <= *(intf *)q, |
387 | "inflate_trees falloc overflow"); | 387 | "inflate_trees falloc overflow"); |
388 | *(intf *)q -= n+s-s; /* s-s to avoid warning */ | 388 | *(intf *)q -= n; |
389 | return (voidpf)(fixed_mem + *(intf *)q); | 389 | return (voidpf)(fixed_mem + *(intf *)q); |
390 | } | 390 | } |
391 | 391 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* inftrees.h -- header to use inftrees.c | 1 | /* inftrees.h -- header to use inftrees.c |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* inflate_util.c -- data and routines common to blocks and codes | 1 | /* inflate_util.c -- data and routines common to blocks and codes |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -12,7 +12,7 @@ | |||
12 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ | 12 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ |
13 | 13 | ||
14 | /* And'ing with mask[n] masks the lower n bits */ | 14 | /* And'ing with mask[n] masks the lower n bits */ |
15 | uInt inflate_mask[17] = { | 15 | uInt inflate_mask[] = { |
16 | 0x0000, | 16 | 0x0000, |
17 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, | 17 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, |
18 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 18 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
@@ -43,7 +43,7 @@ int r; | |||
43 | 43 | ||
44 | /* update check information */ | 44 | /* update check information */ |
45 | if (s->checkfn != Z_NULL) | 45 | if (s->checkfn != Z_NULL) |
46 | z->adler = s->check = (*s->checkfn)(s->check, q, n); | 46 | s->check = (*s->checkfn)(s->check, q, n); |
47 | 47 | ||
48 | /* copy as far as end of window */ | 48 | /* copy as far as end of window */ |
49 | zmemcpy(p, q, n); | 49 | zmemcpy(p, q, n); |
@@ -69,7 +69,7 @@ int r; | |||
69 | 69 | ||
70 | /* update check information */ | 70 | /* update check information */ |
71 | if (s->checkfn != Z_NULL) | 71 | if (s->checkfn != Z_NULL) |
72 | z->adler = s->check = (*s->checkfn)(s->check, q, n); | 72 | s->check = (*s->checkfn)(s->check, q, n); |
73 | 73 | ||
74 | /* copy */ | 74 | /* copy */ |
75 | zmemcpy(p, q, n); | 75 | zmemcpy(p, q, n); |
@@ -1,5 +1,5 @@ | |||
1 | /* infutil.h -- types and macros common to blocks and codes | 1 | /* infutil.h -- types and macros common to blocks and codes |
2 | * Copyright (C) 1995-1996 Mark Adler | 2 | * Copyright (C) 1995 Mark Adler |
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 | ||
@@ -8,10 +8,11 @@ | |||
8 | subject to change. Applications should only use zlib.h. | 8 | subject to change. Applications should only use zlib.h. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #ifndef _INFUTIL_H | 11 | /* inflate blocks semi-private state */ |
12 | #define _INFUTIL_H | 12 | struct inflate_blocks_state { |
13 | 13 | ||
14 | typedef enum { | 14 | /* mode */ |
15 | enum { | ||
15 | TYPE, /* get type bits (3, including end bit) */ | 16 | TYPE, /* get type bits (3, including end bit) */ |
16 | LENS, /* get lengths for stored */ | 17 | LENS, /* get lengths for stored */ |
17 | STORED, /* processing stored block */ | 18 | STORED, /* processing stored block */ |
@@ -22,13 +23,7 @@ typedef enum { | |||
22 | DRY, /* output remaining window bytes */ | 23 | DRY, /* output remaining window bytes */ |
23 | DONE, /* finished last block, done */ | 24 | DONE, /* finished last block, done */ |
24 | BAD} /* got a data error--stuck here */ | 25 | BAD} /* got a data error--stuck here */ |
25 | inflate_block_mode; | 26 | mode; /* current inflate_block mode */ |
26 | |||
27 | /* inflate blocks semi-private state */ | ||
28 | struct inflate_blocks_state { | ||
29 | |||
30 | /* mode */ | ||
31 | inflate_block_mode mode; /* current inflate_block mode */ | ||
32 | 27 | ||
33 | /* mode dependent information */ | 28 | /* mode dependent information */ |
34 | union { | 29 | union { |
@@ -76,16 +71,16 @@ struct inflate_blocks_state { | |||
76 | #define DUMPBITS(j) {b>>=(j);k-=(j);} | 71 | #define DUMPBITS(j) {b>>=(j);k-=(j);} |
77 | /* output bytes */ | 72 | /* output bytes */ |
78 | #define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q) | 73 | #define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q) |
79 | #define LOADOUT {q=s->write;m=(uInt)WAVAIL;} | 74 | #define LOADOUT {q=s->write;m=WAVAIL;} |
80 | #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}} | 75 | #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}} |
81 | #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} | 76 | #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} |
82 | #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} | 77 | #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} |
83 | #define OUTBYTE(a) {*q++=(Byte)(a);m--;} | 78 | #define OUTBYTE(a) {*q++=(Byte)(a);m--;} |
84 | /* load local pointers */ | 79 | /* load local pointers */ |
85 | #define LOAD {LOADIN LOADOUT} | 80 | #define LOAD {LOADIN LOADOUT} |
86 | 81 | ||
87 | /* masks for lower bits (size given to avoid silly warnings with Visual C++) */ | 82 | /* masks for lower bits */ |
88 | extern uInt inflate_mask[17]; | 83 | extern uInt inflate_mask[]; |
89 | 84 | ||
90 | /* 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 */ |
91 | extern int inflate_flush OF(( | 86 | extern int inflate_flush OF(( |
@@ -94,5 +89,3 @@ extern int inflate_flush OF(( | |||
94 | int)); | 89 | int)); |
95 | 90 | ||
96 | struct internal_state {int dummy;}; /* for buggy compilers */ | 91 | struct internal_state {int dummy;}; /* for buggy compilers */ |
97 | |||
98 | #endif | ||
@@ -1,5 +1,5 @@ | |||
1 | /* minigzip.c -- simulate gzip using the zlib compression library | 1 | /* minigzip.c -- simulate gzip using the zlib compression library |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -52,7 +52,7 @@ extern int unlink OF((const char *)); | |||
52 | 52 | ||
53 | char *prog; | 53 | char *prog; |
54 | 54 | ||
55 | void error OF((const char *msg)); | 55 | void error OF((char *msg)); |
56 | void gz_compress OF((FILE *in, gzFile out)); | 56 | void gz_compress OF((FILE *in, gzFile out)); |
57 | void gz_uncompress OF((gzFile in, FILE *out)); | 57 | void gz_uncompress OF((gzFile in, FILE *out)); |
58 | void file_compress OF((char *file)); | 58 | void file_compress OF((char *file)); |
@@ -63,7 +63,7 @@ int main OF((int argc, char *argv[])); | |||
63 | * Display error message and exit | 63 | * Display error message and exit |
64 | */ | 64 | */ |
65 | void error(msg) | 65 | void error(msg) |
66 | const char *msg; | 66 | char *msg; |
67 | { | 67 | { |
68 | fprintf(stderr, "%s: %s\n", prog, msg); | 68 | fprintf(stderr, "%s: %s\n", prog, msg); |
69 | exit(1); | 69 | exit(1); |
@@ -88,7 +88,7 @@ void gz_compress(in, out) | |||
88 | } | 88 | } |
89 | if (len == 0) break; | 89 | if (len == 0) break; |
90 | 90 | ||
91 | if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); | 91 | if (gzwrite(out, buf, len) != len) error(gzerror(out, &err)); |
92 | } | 92 | } |
93 | fclose(in); | 93 | fclose(in); |
94 | if (gzclose(out) != Z_OK) error("failed gzclose"); | 94 | if (gzclose(out) != Z_OK) error("failed gzclose"); |
@@ -110,9 +110,7 @@ void gz_uncompress(in, out) | |||
110 | if (len < 0) error (gzerror(in, &err)); | 110 | if (len < 0) error (gzerror(in, &err)); |
111 | if (len == 0) break; | 111 | if (len == 0) break; |
112 | 112 | ||
113 | if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { | 113 | if (fwrite(buf, 1, len, out) != (uInt)len) error("failed fwrite"); |
114 | error("failed fwrite"); | ||
115 | } | ||
116 | } | 114 | } |
117 | if (fclose(out)) error("failed fclose"); | 115 | if (fclose(out)) error("failed fclose"); |
118 | 116 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* trees.c -- output deflated data using Huffman coding | 1 | /* trees.c -- output deflated data using Huffman coding |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly | 2 | * Copyright (C) 1995 Jean-loup Gailly |
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 | ||
@@ -83,7 +83,7 @@ local uch bl_order[BL_CODES] | |||
83 | local ct_data static_ltree[L_CODES+2]; | 83 | local ct_data static_ltree[L_CODES+2]; |
84 | /* The static literal tree. Since the bit lengths are imposed, there is no | 84 | /* The static literal tree. Since the bit lengths are imposed, there is no |
85 | * need for the L_CODES extra codes used during heap construction. However | 85 | * need for the L_CODES extra codes used during heap construction. However |
86 | * The codes 286 and 287 are needed to build a canonical tree (see _tr_init | 86 | * The codes 286 and 287 are needed to build a canonical tree (see tr_init |
87 | * below). | 87 | * below). |
88 | */ | 88 | */ |
89 | 89 | ||
@@ -292,7 +292,7 @@ local void tr_static_init() | |||
292 | /* The static distance tree is trivial: */ | 292 | /* The static distance tree is trivial: */ |
293 | for (n = 0; n < D_CODES; n++) { | 293 | for (n = 0; n < D_CODES; n++) { |
294 | static_dtree[n].Len = 5; | 294 | static_dtree[n].Len = 5; |
295 | static_dtree[n].Code = bi_reverse((unsigned)n, 5); | 295 | static_dtree[n].Code = bi_reverse(n, 5); |
296 | } | 296 | } |
297 | static_init_done = 1; | 297 | static_init_done = 1; |
298 | } | 298 | } |
@@ -300,7 +300,7 @@ local void tr_static_init() | |||
300 | /* =========================================================================== | 300 | /* =========================================================================== |
301 | * Initialize the tree data structures for a new zlib stream. | 301 | * Initialize the tree data structures for a new zlib stream. |
302 | */ | 302 | */ |
303 | void _tr_init(s) | 303 | void tr_init(s) |
304 | deflate_state *s; | 304 | deflate_state *s; |
305 | { | 305 | { |
306 | tr_static_init(); | 306 | tr_static_init(); |
@@ -785,14 +785,14 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) | |||
785 | /* =========================================================================== | 785 | /* =========================================================================== |
786 | * Send a stored block | 786 | * Send a stored block |
787 | */ | 787 | */ |
788 | void _tr_stored_block(s, buf, stored_len, eof) | 788 | void tr_stored_block(s, buf, stored_len, eof) |
789 | deflate_state *s; | 789 | deflate_state *s; |
790 | charf *buf; /* input block */ | 790 | charf *buf; /* input block */ |
791 | ulg stored_len; /* length of input block */ | 791 | ulg stored_len; /* length of input block */ |
792 | int eof; /* true if this is the last block for a file */ | 792 | int eof; /* true if this is the last block for a file */ |
793 | { | 793 | { |
794 | send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ | 794 | send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ |
795 | s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; | 795 | s->compressed_len = (s->compressed_len + 3 + 7) & ~7L; |
796 | s->compressed_len += (stored_len + 4) << 3; | 796 | s->compressed_len += (stored_len + 4) << 3; |
797 | 797 | ||
798 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ | 798 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ |
@@ -809,7 +809,7 @@ void _tr_stored_block(s, buf, stored_len, eof) | |||
809 | * To simplify the code, we assume the worst case of last real code encoded | 809 | * To simplify the code, we assume the worst case of last real code encoded |
810 | * on one bit only. | 810 | * on one bit only. |
811 | */ | 811 | */ |
812 | void _tr_align(s) | 812 | void tr_align(s) |
813 | deflate_state *s; | 813 | deflate_state *s; |
814 | { | 814 | { |
815 | send_bits(s, STATIC_TREES<<1, 3); | 815 | send_bits(s, STATIC_TREES<<1, 3); |
@@ -835,20 +835,20 @@ void _tr_align(s) | |||
835 | * trees or store, and output the encoded block to the zip file. This function | 835 | * trees or store, and output the encoded block to the zip file. This function |
836 | * returns the total compressed length for the file so far. | 836 | * returns the total compressed length for the file so far. |
837 | */ | 837 | */ |
838 | ulg _tr_flush_block(s, buf, stored_len, eof) | 838 | ulg tr_flush_block(s, buf, stored_len, eof) |
839 | deflate_state *s; | 839 | deflate_state *s; |
840 | charf *buf; /* input block, or NULL if too old */ | 840 | charf *buf; /* input block, or NULL if too old */ |
841 | ulg stored_len; /* length of input block */ | 841 | ulg stored_len; /* length of input block */ |
842 | int eof; /* true if this is the last block for a file */ | 842 | int eof; /* true if this is the last block for a file */ |
843 | { | 843 | { |
844 | ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ | 844 | ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ |
845 | int max_blindex = 0; /* index of last bit length code of non zero freq */ | 845 | int max_blindex; /* index of last bit length code of non zero freq */ |
846 | 846 | ||
847 | /* Build the Huffman trees unless a stored block is forced */ | 847 | /* Build the Huffman trees unless a stored block is forced */ |
848 | if (s->level > 0) { | 848 | if (s->level > 0) { |
849 | 849 | ||
850 | /* Check if the file is ascii or binary */ | 850 | /* Check if the file is ascii or binary */ |
851 | if (s->data_type == Z_UNKNOWN) set_data_type(s); | 851 | if (s->data_type == UNKNOWN) set_data_type(s); |
852 | 852 | ||
853 | /* Construct the literal and distance trees */ | 853 | /* Construct the literal and distance trees */ |
854 | build_tree(s, (tree_desc *)(&(s->l_desc))); | 854 | build_tree(s, (tree_desc *)(&(s->l_desc))); |
@@ -879,7 +879,7 @@ ulg _tr_flush_block(s, buf, stored_len, eof) | |||
879 | 879 | ||
880 | } else { | 880 | } else { |
881 | Assert(buf != (char*)0, "lost buf"); | 881 | Assert(buf != (char*)0, "lost buf"); |
882 | opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ | 882 | opt_lenb = stored_len + 5; /* force a stored block */ |
883 | } | 883 | } |
884 | 884 | ||
885 | /* If compression failed and this is the first and last block, | 885 | /* If compression failed and this is the first and last block, |
@@ -913,7 +913,7 @@ ulg _tr_flush_block(s, buf, stored_len, eof) | |||
913 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to | 913 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to |
914 | * transform a block into a stored block. | 914 | * transform a block into a stored block. |
915 | */ | 915 | */ |
916 | _tr_stored_block(s, buf, stored_len, eof); | 916 | tr_stored_block(s, buf, stored_len, eof); |
917 | 917 | ||
918 | #ifdef FORCE_STATIC | 918 | #ifdef FORCE_STATIC |
919 | } else if (static_lenb >= 0) { /* force static trees */ | 919 | } else if (static_lenb >= 0) { /* force static trees */ |
@@ -947,10 +947,10 @@ ulg _tr_flush_block(s, buf, stored_len, eof) | |||
947 | * Save the match info and tally the frequency counts. Return true if | 947 | * Save the match info and tally the frequency counts. Return true if |
948 | * the current block must be flushed. | 948 | * the current block must be flushed. |
949 | */ | 949 | */ |
950 | int _tr_tally (s, dist, lc) | 950 | int tr_tally (s, dist, lc) |
951 | deflate_state *s; | 951 | deflate_state *s; |
952 | unsigned dist; /* distance of matched string */ | 952 | int dist; /* distance of matched string */ |
953 | unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ | 953 | int lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ |
954 | { | 954 | { |
955 | s->d_buf[s->last_lit] = (ush)dist; | 955 | s->d_buf[s->last_lit] = (ush)dist; |
956 | s->l_buf[s->last_lit++] = (uch)lc; | 956 | s->l_buf[s->last_lit++] = (uch)lc; |
@@ -963,7 +963,7 @@ int _tr_tally (s, dist, lc) | |||
963 | dist--; /* dist = match distance - 1 */ | 963 | dist--; /* dist = match distance - 1 */ |
964 | Assert((ush)dist < (ush)MAX_DIST(s) && | 964 | Assert((ush)dist < (ush)MAX_DIST(s) && |
965 | (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && | 965 | (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && |
966 | (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); | 966 | (ush)d_code(dist) < (ush)D_CODES, "tr_tally: bad match"); |
967 | 967 | ||
968 | s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; | 968 | s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; |
969 | s->dyn_dtree[d_code(dist)].Freq++; | 969 | s->dyn_dtree[d_code(dist)].Freq++; |
@@ -1057,7 +1057,7 @@ local void set_data_type(s) | |||
1057 | while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; | 1057 | while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; |
1058 | while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; | 1058 | while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; |
1059 | while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; | 1059 | while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; |
1060 | s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); | 1060 | s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII); |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | /* =========================================================================== | 1063 | /* =========================================================================== |
@@ -1,5 +1,5 @@ | |||
1 | /* uncompr.c -- decompress a memory buffer | 1 | /* uncompr.c -- decompress a memory buffer |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -25,13 +25,13 @@ | |||
25 | int uncompress (dest, destLen, source, sourceLen) | 25 | int uncompress (dest, destLen, source, sourceLen) |
26 | Bytef *dest; | 26 | Bytef *dest; |
27 | uLongf *destLen; | 27 | uLongf *destLen; |
28 | const Bytef *source; | 28 | Bytef *source; |
29 | uLong sourceLen; | 29 | uLong sourceLen; |
30 | { | 30 | { |
31 | z_stream stream; | 31 | z_stream stream; |
32 | int err; | 32 | int err; |
33 | 33 | ||
34 | stream.next_in = (Bytef*)source; | 34 | stream.next_in = source; |
35 | stream.avail_in = (uInt)sourceLen; | 35 | stream.avail_in = (uInt)sourceLen; |
36 | /* Check for source > 64K on 16-bit machine: */ | 36 | /* Check for source > 64K on 16-bit machine: */ |
37 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | 37 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; |
@@ -1,5 +1,5 @@ | |||
1 | /* zconf.h -- configuration of the zlib compression library | 1 | /* zconf.h -- configuration of the zlib compression library |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -9,40 +9,11 @@ | |||
9 | #define _ZCONF_H | 9 | #define _ZCONF_H |
10 | 10 | ||
11 | /* | 11 | /* |
12 | * People prefering a unique prefix for all types and library functions | 12 | The library does not install any signal handler. It is recommended to |
13 | * should compile with -DZ_PREFIX | 13 | add at least a handler for SIGSEGV when decompressing; the library checks |
14 | the consistency of the input data whenever possible but may go nuts | ||
15 | for some forms of corrupted input. | ||
14 | */ | 16 | */ |
15 | #ifdef Z_PREFIX | ||
16 | # define deflateInit_ z_deflateInit_ | ||
17 | # define deflate z_deflate | ||
18 | # define deflateEnd z_deflateEnd | ||
19 | # define inflateInit_ z_inflateInit_ | ||
20 | # define inflate z_inflate | ||
21 | # define inflateEnd z_inflateEnd | ||
22 | # define deflateInit2_ z_deflateInit2_ | ||
23 | # define deflateCopy z_deflateCopy | ||
24 | # define deflateReset z_deflateReset | ||
25 | # define deflateParams z_deflateParams | ||
26 | # define inflateInit2_ z_inflateInit2_ | ||
27 | # define inflateSync z_inflateSync | ||
28 | # define inflateReset z_inflateReset | ||
29 | # define compress z_compress | ||
30 | # define uncompress z_uncompress | ||
31 | # define adler32 z_adler32 | ||
32 | # define crc32 z_crc32 | ||
33 | # define get_crc_table z_get_crc_table | ||
34 | |||
35 | # define Byte z_Byte | ||
36 | # define uInt z_uInt | ||
37 | # define uLong z_uLong | ||
38 | # define Bytef z_Bytef | ||
39 | # define charf z_charf | ||
40 | # define intf z_intf | ||
41 | # define uIntf z_uIntf | ||
42 | # define uLongf z_uLongf | ||
43 | # define voidpf z_voidpf | ||
44 | # define voidp z_voidp | ||
45 | #endif | ||
46 | 17 | ||
47 | #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) | 18 | #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) |
48 | # define WIN32 | 19 | # define WIN32 |
@@ -78,7 +49,6 @@ | |||
78 | 49 | ||
79 | #ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */ | 50 | #ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */ |
80 | # include <unix.h> | 51 | # include <unix.h> |
81 | # define Byte _Byte /* Byte already used on Mac */ | ||
82 | #endif | 52 | #endif |
83 | 53 | ||
84 | /* Maximum value for memLevel in deflateInit2 */ | 54 | /* Maximum value for memLevel in deflateInit2 */ |
@@ -125,7 +95,6 @@ | |||
125 | * just define FAR to be empty. | 95 | * just define FAR to be empty. |
126 | */ | 96 | */ |
127 | #if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */ | 97 | #if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */ |
128 | # define SMALL_MEDIUM | ||
129 | # ifdef _MSC_VER | 98 | # ifdef _MSC_VER |
130 | # define FAR __far | 99 | # define FAR __far |
131 | # else | 100 | # else |
@@ -133,26 +102,20 @@ | |||
133 | # endif | 102 | # endif |
134 | #endif | 103 | #endif |
135 | #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) | 104 | #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) |
136 | # define SMALL_MEDIUM | 105 | # define FAR _far /* completely untested, just a best guess */ |
137 | # define FAR __far | ||
138 | #endif | 106 | #endif |
139 | #ifndef FAR | 107 | #ifndef FAR |
140 | # define FAR | 108 | # define FAR |
141 | #endif | 109 | #endif |
142 | /* The Watcom compiler defines M_I86SM and __SMALL__ even in 32 bit mode */ | ||
143 | #if defined(__WATCOMC__) && defined(__386__) | ||
144 | # undef FAR | ||
145 | # undef SMALL_MEDIUM | ||
146 | #endif | ||
147 | 110 | ||
148 | typedef unsigned char Byte; /* 8 bits */ | 111 | typedef unsigned char Byte; /* 8 bits */ |
149 | typedef unsigned int uInt; /* 16 bits or more */ | 112 | typedef unsigned int uInt; /* 16 bits or more */ |
150 | typedef unsigned long uLong; /* 32 bits or more */ | 113 | typedef unsigned long uLong; /* 32 bits or more */ |
151 | 114 | ||
152 | typedef Byte FAR Bytef; | 115 | typedef Byte FAR Bytef; |
153 | typedef char FAR charf; | 116 | typedef char FAR charf; |
154 | typedef int FAR intf; | 117 | typedef int FAR intf; |
155 | typedef uInt FAR uIntf; | 118 | typedef uInt FAR uIntf; |
156 | typedef uLong FAR uLongf; | 119 | typedef uLong FAR uLongf; |
157 | 120 | ||
158 | #ifdef STDC | 121 | #ifdef STDC |
@@ -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 1.0, Jan 27th, 1996. | 2 | version 1.0, Jan 14th, 1996. |
3 | 3 | ||
4 | Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler |
5 | 5 | ||
@@ -51,11 +51,6 @@ extern "C" { | |||
51 | repeated calls of the compression function. In the latter case, the | 51 | repeated calls of the compression function. In the latter case, the |
52 | application must provide more input and/or consume the output | 52 | application must provide more input and/or consume the output |
53 | (providing more output space) before each call. | 53 | (providing more output space) before each call. |
54 | |||
55 | The library does not install any signal handler. It is recommended to | ||
56 | add at least a handler for SIGSEGV when decompressing; the library checks | ||
57 | the consistency of the input data whenever possible but may go nuts | ||
58 | for some forms of corrupted input. | ||
59 | */ | 54 | */ |
60 | 55 | ||
61 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); | 56 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
@@ -79,9 +74,8 @@ typedef struct z_stream_s { | |||
79 | free_func zfree; /* used to free the internal state */ | 74 | free_func zfree; /* used to free the internal state */ |
80 | voidpf opaque; /* private data object passed to zalloc and zfree */ | 75 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
81 | 76 | ||
82 | int data_type; /* best guess about the data type: ascii or binary */ | 77 | Byte data_type; /* best guess about the data type: ascii or binary */ |
83 | uLong adler; /* adler32 value of the uncompressed data */ | 78 | |
84 | uLong reserved; /* reserved for future use */ | ||
85 | } z_stream; | 79 | } z_stream; |
86 | 80 | ||
87 | /* | 81 | /* |
@@ -124,16 +118,12 @@ typedef struct z_stream_s { | |||
124 | 118 | ||
125 | #define Z_OK 0 | 119 | #define Z_OK 0 |
126 | #define Z_STREAM_END 1 | 120 | #define Z_STREAM_END 1 |
127 | #define Z_NEED_DICT 2 | ||
128 | #define Z_ERRNO (-1) | 121 | #define Z_ERRNO (-1) |
129 | #define Z_STREAM_ERROR (-2) | 122 | #define Z_STREAM_ERROR (-2) |
130 | #define Z_DATA_ERROR (-3) | 123 | #define Z_DATA_ERROR (-3) |
131 | #define Z_MEM_ERROR (-4) | 124 | #define Z_MEM_ERROR (-4) |
132 | #define Z_BUF_ERROR (-5) | 125 | #define Z_BUF_ERROR (-5) |
133 | #define Z_VERSION_ERROR (-6) | 126 | /* error codes for the compression/decompression functions */ |
134 | /* Return codes for the compression/decompression functions. Negative | ||
135 | * values are errors, positive values are used for special but normal events. | ||
136 | */ | ||
137 | 127 | ||
138 | #define Z_NO_COMPRESSION 0 | 128 | #define Z_NO_COMPRESSION 0 |
139 | #define Z_BEST_SPEED 1 | 129 | #define Z_BEST_SPEED 1 |
@@ -144,19 +134,18 @@ typedef struct z_stream_s { | |||
144 | #define Z_FILTERED 1 | 134 | #define Z_FILTERED 1 |
145 | #define Z_HUFFMAN_ONLY 2 | 135 | #define Z_HUFFMAN_ONLY 2 |
146 | #define Z_DEFAULT_STRATEGY 0 | 136 | #define Z_DEFAULT_STRATEGY 0 |
147 | /* compression strategy; see deflateInit2() below for details */ | ||
148 | 137 | ||
149 | #define Z_BINARY 0 | 138 | #define Z_BINARY 0 |
150 | #define Z_ASCII 1 | 139 | #define Z_ASCII 1 |
151 | #define Z_UNKNOWN 2 | 140 | #define Z_UNKNOWN 2 |
152 | /* Possible values of the data_type field */ | 141 | /* Used to set the data_type field */ |
153 | 142 | ||
154 | #define Z_DEFLATED 8 | 143 | #define Z_DEFLATED 8 |
155 | /* The deflate compression method (the only one supported in this version) */ | 144 | /* The deflate compression method (the only one supported in this version) */ |
156 | 145 | ||
157 | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ | 146 | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ |
158 | 147 | ||
159 | extern const char *zlib_version; | 148 | extern char *zlib_version; |
160 | /* The application can compare zlib_version and ZLIB_VERSION for consistency. | 149 | /* The application can compare zlib_version and ZLIB_VERSION for consistency. |
161 | If the first character differs, the library code actually used is | 150 | If the first character differs, the library code actually used is |
162 | not compatible with the zlib.h header file used by the application. | 151 | not compatible with the zlib.h header file used by the application. |
@@ -164,9 +153,8 @@ extern const char *zlib_version; | |||
164 | 153 | ||
165 | /* basic functions */ | 154 | /* basic functions */ |
166 | 155 | ||
167 | /* | ||
168 | extern int deflateInit OF((z_stream *strm, int level)); | 156 | extern int deflateInit OF((z_stream *strm, int level)); |
169 | 157 | /* | |
170 | Initializes the internal stream state for compression. The fields | 158 | Initializes the internal stream state for compression. The fields |
171 | zalloc, zfree and opaque must be initialized before by the caller. | 159 | zalloc, zfree and opaque must be initialized before by the caller. |
172 | If zalloc and zfree are set to Z_NULL, deflateInit updates them to | 160 | If zalloc and zfree are set to Z_NULL, deflateInit updates them to |
@@ -179,9 +167,7 @@ extern int deflateInit OF((z_stream *strm, int level)); | |||
179 | compression (currently equivalent to level 6). | 167 | compression (currently equivalent to level 6). |
180 | 168 | ||
181 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | 169 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not |
182 | enough memory, Z_STREAM_ERROR if level is not a valid compression level, | 170 | enough memory, Z_STREAM_ERROR if level is not a valid compression level. |
183 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible | ||
184 | with the version assumed by the caller (ZLIB_VERSION). | ||
185 | msg is set to null if there is no error message. deflateInit does not | 171 | msg is set to null if there is no error message. deflateInit does not |
186 | perform any compression: this will be done by deflate(). | 172 | perform any compression: this will be done by deflate(). |
187 | */ | 173 | */ |
@@ -261,26 +247,22 @@ extern int deflateEnd OF((z_stream *strm)); | |||
261 | pending output. | 247 | pending output. |
262 | 248 | ||
263 | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the | 249 | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the |
264 | stream state was inconsistent, Z_DATA_ERROR if the stream was freed | 250 | stream state was inconsistent. In the error case, msg may be set |
265 | prematurely (some input or output was discarded). In the error case, | 251 | but then points to a static string (which must not be deallocated). |
266 | msg may be set but then points to a static string (which must not be | ||
267 | deallocated). | ||
268 | */ | 252 | */ |
269 | 253 | ||
270 | 254 | ||
271 | /* | ||
272 | extern int inflateInit OF((z_stream *strm)); | 255 | extern int inflateInit OF((z_stream *strm)); |
273 | 256 | /* | |
274 | Initializes the internal stream state for decompression. The fields | 257 | Initializes the internal stream state for decompression. The fields |
275 | zalloc, zfree and opaque must be initialized before by the caller. If | 258 | zalloc, zfree and opaque must be initialized before by the caller. If |
276 | zalloc and zfree are set to Z_NULL, inflateInit updates them to use default | 259 | zalloc and zfree are set to Z_NULL, inflateInit updates them to use default |
277 | allocation functions. | 260 | allocation functions. |
278 | 261 | ||
279 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | 262 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not |
280 | enough memory, Z_VERSION_ERROR if the zlib library version is incompatible | 263 | enough memory. msg is set to null if there is no error message. |
281 | with the version assumed by the caller. msg is set to null if there is no | 264 | inflateInit does not perform any decompression: this will be done by |
282 | error message. inflateInit does not perform any decompression: this will be | 265 | inflate(). |
283 | done by inflate(). | ||
284 | */ | 266 | */ |
285 | 267 | ||
286 | 268 | ||
@@ -324,15 +306,12 @@ extern int inflate OF((z_stream *strm, int flush)); | |||
324 | inflate() returns Z_OK if some progress has been made (more input | 306 | inflate() returns Z_OK if some progress has been made (more input |
325 | processed or more output produced), Z_STREAM_END if the end of the | 307 | processed or more output produced), Z_STREAM_END if the end of the |
326 | compressed data has been reached and all uncompressed output has been | 308 | compressed data has been reached and all uncompressed output has been |
327 | produced, Z_NEED_DICT if a preset dictionary is needed at this point (see | 309 | produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if |
328 | inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted, | 310 | the stream structure was inconsistent (for example if next_in or next_out |
329 | Z_STREAM_ERROR if the stream structure was inconsistent (for example if | 311 | was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no |
330 | next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, | 312 | progress is possible or if there was not enough room in the output buffer |
331 | Z_BUF_ERROR if no progress is possible or if there was not enough room in | 313 | when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then |
332 | the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the | 314 | call inflateSync to look for a good compression block. |
333 | application may then call inflateSync to look for a good compression block. | ||
334 | In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the | ||
335 | dictionary chosen by the compressor. | ||
336 | */ | 315 | */ |
337 | 316 | ||
338 | 317 | ||
@@ -347,20 +326,19 @@ extern int inflateEnd OF((z_stream *strm)); | |||
347 | static string (which must not be deallocated). | 326 | static string (which must not be deallocated). |
348 | */ | 327 | */ |
349 | 328 | ||
350 | /* Advanced functions */ | 329 | /* advanced functions */ |
351 | 330 | ||
352 | /* | 331 | /* |
353 | The following functions are needed only in some special applications. | 332 | The following functions are needed only in some special applications. |
354 | */ | 333 | */ |
355 | 334 | ||
356 | /* | ||
357 | extern int deflateInit2 OF((z_stream *strm, | 335 | extern int deflateInit2 OF((z_stream *strm, |
358 | int level, | 336 | int level, |
359 | int method, | 337 | int method, |
360 | int windowBits, | 338 | int windowBits, |
361 | int memLevel, | 339 | int memLevel, |
362 | int strategy)); | 340 | int strategy)); |
363 | 341 | /* | |
364 | This is another version of deflateInit with more compression options. The | 342 | This is another version of deflateInit with more compression options. The |
365 | fields next_in, zalloc, zfree and opaque must be initialized before by | 343 | fields next_in, zalloc, zfree and opaque must be initialized before by |
366 | the caller. | 344 | the caller. |
@@ -375,22 +353,20 @@ extern int deflateInit2 OF((z_stream *strm, | |||
375 | values of this parameter result in better compression at the expense of | 353 | values of this parameter result in better compression at the expense of |
376 | memory usage. The default value is 15 if deflateInit is used instead. | 354 | memory usage. The default value is 15 if deflateInit is used instead. |
377 | 355 | ||
378 | The memLevel parameter specifies how much memory should be allocated | 356 | The memLevel parameter specifies how much memory should be allocated |
379 | for the internal compression state. memLevel=1 uses minimum memory but | 357 | for the internal compression state. memLevel=1 uses minimum memory but |
380 | is slow and reduces compression ratio; memLevel=9 uses maximum memory | 358 | is slow and reduces compression ratio; memLevel=9 uses maximum memory |
381 | for optimal speed. The default value is 8. See zconf.h for total memory | 359 | for optimal speed. The default value is 8. See zconf.h for total memory |
382 | usage as a function of windowBits and memLevel. | 360 | usage as a function of windowBits and memLevel. |
383 | 361 | ||
384 | The strategy parameter is used to tune the compression algorithm. Use the | 362 | The strategy parameter is used to tune the compression algorithm. Use |
385 | value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a | 363 | the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data |
386 | filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no | 364 | produced by a filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman |
387 | string match). Filtered data consists mostly of small values with a | 365 | encoding only (no string match). Filtered data consists mostly of small |
388 | somewhat random distribution. In this case, the compression algorithm is | 366 | values with a somewhat random distribution. In this case, the |
389 | tuned to compress them better. The effect of Z_FILTERED is to force more | 367 | compression algorithm is tuned to compress them better. The strategy |
390 | Huffman coding and less string matching; it is somewhat intermediate | 368 | parameter only affects the compression ratio but not the correctness of |
391 | between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects | 369 | the compressed output even if it is not set appropriately. |
392 | the compression ratio but not the correctness of the compressed output even | ||
393 | if it is not set appropriately. | ||
394 | 370 | ||
395 | If next_in is not null, the library will use this buffer to hold also | 371 | If next_in is not null, the library will use this buffer to hold also |
396 | some history information; the buffer must either hold the entire input | 372 | some history information; the buffer must either hold the entire input |
@@ -409,38 +385,9 @@ extern int deflateInit2 OF((z_stream *strm, | |||
409 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as | 385 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as |
410 | an invalid method). msg is set to null if there is no error message. | 386 | an invalid method). msg is set to null if there is no error message. |
411 | deflateInit2 does not perform any compression: this will be done by | 387 | deflateInit2 does not perform any compression: this will be done by |
412 | deflate(). | 388 | deflate(). |
413 | */ | 389 | */ |
414 | 390 | ||
415 | extern int deflateSetDictionary OF((z_stream *strm, | ||
416 | const Bytef *dictionary, | ||
417 | uInt dictLength)); | ||
418 | /* | ||
419 | Initializes the compression dictionary (history buffer) from the given | ||
420 | byte sequence without producing any compressed output. This function must | ||
421 | be called immediately after deflateInit or deflateInit2, before any call | ||
422 | of deflate. The compressor and decompressor must use exactly the same | ||
423 | dictionary (see inflateSetDictionary). | ||
424 | The dictionary should consist of strings (byte sequences) that are likely | ||
425 | to be encountered later in the data to be compressed, with the most commonly | ||
426 | used strings preferably put towards the end of the dictionary. Using a | ||
427 | dictionary is most useful when the data to be compressed is short and | ||
428 | can be predicted with good accuracy; the data can then be compressed better | ||
429 | than with the default empty dictionary. In this version of the library, | ||
430 | only the last 32K bytes of the dictionary are used. | ||
431 | Upon return of this function, strm->adler is set to the Adler32 value | ||
432 | of the dictionary; the decompressor may later use this value to determine | ||
433 | which dictionary has been used by the compressor. (The Adler32 value | ||
434 | applies to the whole dictionary even if only a subset of the dictionary is | ||
435 | actually used by the compressor.) | ||
436 | |||
437 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a | ||
438 | parameter is invalid (such as NULL dictionary) or the stream state | ||
439 | is inconsistent (for example if deflate has already been called for this | ||
440 | stream). deflateSetDictionary does not perform any compression: this will | ||
441 | be done by deflate(). | ||
442 | */ | ||
443 | |||
444 | extern int deflateCopy OF((z_stream *dest, | 391 | extern int deflateCopy OF((z_stream *dest, |
445 | z_stream *source)); | 392 | z_stream *source)); |
446 | /* | 393 | /* |
@@ -451,14 +398,14 @@ extern int deflateCopy OF((z_stream *dest, | |||
451 | application to provide the correct values of next_out and avail_out for the | 398 | application to provide the correct values of next_out and avail_out for the |
452 | next call of deflate. | 399 | next call of deflate. |
453 | 400 | ||
454 | This function can be useful when several compression strategies will be | 401 | This function is useful when several compression strategies will be |
455 | tried, for example when there are several ways of pre-processing the input | 402 | tried, for example when there are several ways of pre-processing the input |
456 | data with a filter. The streams that will be discarded should then be freed | 403 | data with a filter. The streams that will be discarded should then be freed |
457 | by calling deflateEnd. Note that deflateCopy duplicates the internal | 404 | by calling deflateEnd. Note that deflateCopy duplicates the internal |
458 | compression state which can be quite large, so this strategy is slow and | 405 | compression state which can be quite large, so this strategy is slow and |
459 | can consume lots of memory. | 406 | can consume lots of memory. |
460 | 407 | ||
461 | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not | 408 | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not |
462 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent | 409 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent |
463 | (such as zalloc being NULL). msg is left unchanged in both source and | 410 | (such as zalloc being NULL). msg is left unchanged in both source and |
464 | destination. | 411 | destination. |
@@ -488,10 +435,9 @@ extern int deflateParams OF((z_stream *strm, int level, int strategy)); | |||
488 | stream state was inconsistent or if a parameter was invalid. | 435 | stream state was inconsistent or if a parameter was invalid. |
489 | */ | 436 | */ |
490 | 437 | ||
491 | /* | ||
492 | extern int inflateInit2 OF((z_stream *strm, | 438 | extern int inflateInit2 OF((z_stream *strm, |
493 | int windowBits)); | 439 | int windowBits)); |
494 | 440 | /* | |
495 | This is another version of inflateInit with more compression options. The | 441 | This is another version of inflateInit with more compression options. The |
496 | fields next_out, zalloc, zfree and opaque must be initialized before by | 442 | fields next_out, zalloc, zfree and opaque must be initialized before by |
497 | the caller. | 443 | the caller. |
@@ -523,25 +469,6 @@ extern int inflateInit2 OF((z_stream *strm, | |||
523 | inflate(). | 469 | inflate(). |
524 | */ | 470 | */ |
525 | 471 | ||
526 | extern int inflateSetDictionary OF((z_stream *strm, | ||
527 | const Bytef *dictionary, | ||
528 | uInt dictLength)); | ||
529 | /* | ||
530 | Initializes the decompression dictionary (history buffer) from the given | ||
531 | uncompressed byte sequence. This function must be called immediately after | ||
532 | a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen | ||
533 | by the compressor can be determined from the Adler32 value returned by this | ||
534 | call of inflate. The compressor and decompressor must use exactly the same | ||
535 | dictionary (see deflateSetDictionary). | ||
536 | |||
537 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a | ||
538 | parameter is invalid (such as NULL dictionary) or the stream state is | ||
539 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the | ||
540 | expected one (incorrect Adler32 value). inflateSetDictionary does not | ||
541 | perform any decompression: this will be done by subsequent calls of | ||
542 | inflate(). | ||
543 | */ | ||
544 | |||
545 | extern int inflateSync OF((z_stream *strm)); | 472 | extern int inflateSync OF((z_stream *strm)); |
546 | /* | 473 | /* |
547 | Skips invalid compressed data until the special marker (see deflate() | 474 | Skips invalid compressed data until the special marker (see deflate() |
@@ -579,7 +506,7 @@ extern int inflateReset OF((z_stream *strm)); | |||
579 | */ | 506 | */ |
580 | 507 | ||
581 | extern int compress OF((Bytef *dest, uLongf *destLen, | 508 | extern int compress OF((Bytef *dest, uLongf *destLen, |
582 | const Bytef *source, uLong sourceLen)); | 509 | Bytef *source, uLong sourceLen)); |
583 | /* | 510 | /* |
584 | Compresses the source buffer into the destination buffer. sourceLen is | 511 | Compresses the source buffer into the destination buffer. sourceLen is |
585 | the byte length of the source buffer. Upon entry, destLen is the total | 512 | the byte length of the source buffer. Upon entry, destLen is the total |
@@ -594,7 +521,7 @@ extern int compress OF((Bytef *dest, uLongf *destLen, | |||
594 | */ | 521 | */ |
595 | 522 | ||
596 | extern int uncompress OF((Bytef *dest, uLongf *destLen, | 523 | extern int uncompress OF((Bytef *dest, uLongf *destLen, |
597 | const Bytef *source, uLong sourceLen)); | 524 | Bytef *source, uLong sourceLen)); |
598 | /* | 525 | /* |
599 | Decompresses the source buffer into the destination buffer. sourceLen is | 526 | Decompresses the source buffer into the destination buffer. sourceLen is |
600 | the byte length of the source buffer. Upon entry, destLen is the total | 527 | the byte length of the source buffer. Upon entry, destLen is the total |
@@ -614,7 +541,7 @@ extern int uncompress OF((Bytef *dest, uLongf *destLen, | |||
614 | 541 | ||
615 | typedef voidp gzFile; | 542 | typedef voidp gzFile; |
616 | 543 | ||
617 | extern gzFile gzopen OF((const char *path, const char *mode)); | 544 | extern gzFile gzopen OF((char *path, char *mode)); |
618 | /* | 545 | /* |
619 | Opens a gzip (.gz) file for reading or writing. The mode parameter | 546 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
620 | is as in fopen ("rb" or "wb") but can also include a compression level | 547 | is as in fopen ("rb" or "wb") but can also include a compression level |
@@ -626,15 +553,12 @@ extern gzFile gzopen OF((const char *path, const char *mode)); | |||
626 | zlib error is Z_MEM_ERROR). | 553 | zlib error is Z_MEM_ERROR). |
627 | */ | 554 | */ |
628 | 555 | ||
629 | extern gzFile gzdopen OF((int fd, const char *mode)); | 556 | extern gzFile gzdopen OF((int fd, char *mode)); |
630 | /* | 557 | /* |
631 | gzdopen() associates a gzFile with the file descriptor fd. File | 558 | gzdopen() associates a gzFile with the file descriptor fd. File |
632 | descriptors are obtained from calls like open, dup, creat, pipe or | 559 | descriptors are obtained from calls like open, dup, creat, pipe or |
633 | fileno (in the file has been previously opened with fopen). | 560 | fileno (in the file has been previously opened with fopen). |
634 | The mode parameter is as in fopen ("rb" or "wb"). | 561 | The mode parameter is as in fopen ("rb" or "wb"). |
635 | The next call of gzclose on the returned gzFile will also close the | ||
636 | file descriptor fd, just like fclose(fdopen(fd), mode) closes the file | ||
637 | descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). | ||
638 | gzdopen returns NULL if there was insufficient memory to allocate | 562 | gzdopen returns NULL if there was insufficient memory to allocate |
639 | the (de)compression state. | 563 | the (de)compression state. |
640 | */ | 564 | */ |
@@ -647,7 +571,7 @@ extern int gzread OF((gzFile file, voidp buf, unsigned len)); | |||
647 | gzread returns the number of uncompressed bytes actually read (0 for | 571 | gzread returns the number of uncompressed bytes actually read (0 for |
648 | end of file, -1 for error). */ | 572 | end of file, -1 for error). */ |
649 | 573 | ||
650 | extern int gzwrite OF((gzFile file, const voidp buf, unsigned len)); | 574 | extern int gzwrite OF((gzFile file, voidp buf, unsigned len)); |
651 | /* | 575 | /* |
652 | Writes the given number of uncompressed bytes into the compressed file. | 576 | Writes the given number of uncompressed bytes into the compressed file. |
653 | gzwrite returns the number of uncompressed bytes actually written | 577 | gzwrite returns the number of uncompressed bytes actually written |
@@ -688,7 +612,7 @@ extern char* gzerror OF((gzFile file, int *errnum)); | |||
688 | compression library. | 612 | compression library. |
689 | */ | 613 | */ |
690 | 614 | ||
691 | extern uLong adler32 OF((uLong adler, const Bytef *buf, uInt len)); | 615 | extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len)); |
692 | 616 | ||
693 | /* | 617 | /* |
694 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and | 618 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
@@ -705,7 +629,7 @@ extern uLong adler32 OF((uLong adler, const Bytef *buf, uInt len)); | |||
705 | if (adler != original_adler) error(); | 629 | if (adler != original_adler) error(); |
706 | */ | 630 | */ |
707 | 631 | ||
708 | extern uLong crc32 OF((uLong crc, const Bytef *buf, uInt len)); | 632 | extern uLong crc32 OF((uLong crc, Bytef *buf, uInt len)); |
709 | /* | 633 | /* |
710 | Update a running crc with the bytes buf[0..len-1] and return the updated | 634 | Update a running crc with the bytes buf[0..len-1] and return the updated |
711 | crc. If buf is NULL, this function returns the required initial value | 635 | crc. If buf is NULL, this function returns the required initial value |
@@ -721,37 +645,10 @@ extern uLong crc32 OF((uLong crc, const Bytef *buf, uInt len)); | |||
721 | if (crc != original_crc) error(); | 645 | if (crc != original_crc) error(); |
722 | */ | 646 | */ |
723 | 647 | ||
724 | |||
725 | /* various hacks, don't look :) */ | ||
726 | |||
727 | /* deflateInit and inflateInit are macros to allow checking the zlib version | ||
728 | * and the compiler's view of z_stream: | ||
729 | */ | ||
730 | extern int deflateInit_ OF((z_stream *strm, int level, | ||
731 | const char *version, int stream_size)); | ||
732 | extern int inflateInit_ OF((z_stream *strm, | ||
733 | const char *version, int stream_size)); | ||
734 | extern int deflateInit2_ OF((z_stream *strm, int level, int method, | ||
735 | int windowBits, int memLevel, int strategy, | ||
736 | const char *version, int stream_size)); | ||
737 | extern int inflateInit2_ OF((z_stream *strm, int windowBits, | ||
738 | const char *version, int stream_size)); | ||
739 | #define deflateInit(strm, level) \ | ||
740 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) | ||
741 | #define inflateInit(strm) \ | ||
742 | inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) | ||
743 | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | ||
744 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | ||
745 | (strategy), ZLIB_VERSION, sizeof(z_stream)) | ||
746 | #define inflateInit2(strm, windowBits) \ | ||
747 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) | ||
748 | |||
749 | #ifndef _Z_UTIL_H | 648 | #ifndef _Z_UTIL_H |
750 | struct internal_state {int dummy;}; /* hack for buggy compilers */ | 649 | struct internal_state {int dummy;}; /* hack for buggy compilers */ |
751 | #endif | 650 | #endif |
752 | 651 | ||
753 | uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */ | ||
754 | |||
755 | #ifdef __cplusplus | 652 | #ifdef __cplusplus |
756 | } | 653 | } |
757 | #endif | 654 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* zutil.c -- target dependent utility functions for the compression library | 1 | /* zutil.c -- target dependent utility functions for the compression library |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -15,18 +15,16 @@ struct internal_state {int dummy;}; /* for buggy compilers */ | |||
15 | extern void exit OF((int)); | 15 | extern void exit OF((int)); |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | const char *zlib_version = ZLIB_VERSION; | 18 | char *zlib_version = ZLIB_VERSION; |
19 | 19 | ||
20 | const char *z_errmsg[10] = { | 20 | char *z_errmsg[] = { |
21 | "need dictionary", /* Z_NEED_DICT 2 */ | 21 | "stream end", /* Z_STREAM_END 1 */ |
22 | "stream end", /* Z_STREAM_END 1 */ | 22 | "", /* Z_OK 0 */ |
23 | "", /* Z_OK 0 */ | 23 | "file error", /* Z_ERRNO (-1) */ |
24 | "file error", /* Z_ERRNO (-1) */ | 24 | "stream error", /* Z_STREAM_ERROR (-2) */ |
25 | "stream error", /* Z_STREAM_ERROR (-2) */ | 25 | "data error", /* Z_DATA_ERROR (-3) */ |
26 | "data error", /* Z_DATA_ERROR (-3) */ | 26 | "insufficient memory", /* Z_MEM_ERROR (-4) */ |
27 | "insufficient memory", /* Z_MEM_ERROR (-4) */ | 27 | "buffer error", /* Z_BUF_ERROR (-5) */ |
28 | "buffer error", /* Z_BUF_ERROR (-5) */ | ||
29 | "incompatible version",/* Z_VERSION_ERROR (-6) */ | ||
30 | ""}; | 28 | ""}; |
31 | 29 | ||
32 | 30 | ||
@@ -62,9 +60,9 @@ void zmemzero(dest, len) | |||
62 | #endif | 60 | #endif |
63 | 61 | ||
64 | #ifdef __TURBOC__ | 62 | #ifdef __TURBOC__ |
65 | #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__) | 63 | #if !defined(__SMALL__) && !defined(__MEDIUM__) && !defined(__32BIT__) |
66 | /* Small and medium model in Turbo C are for now limited to near allocation | 64 | /* Small and medium model are for now limited to near allocation with |
67 | * with reduced MAX_WBITS and MAX_MEM_LEVEL | 65 | * reduced MAX_WBITS and MAX_MEM_LEVEL |
68 | */ | 66 | */ |
69 | # define MY_ZCALLOC | 67 | # define MY_ZCALLOC |
70 | 68 | ||
@@ -102,6 +100,9 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) | |||
102 | */ | 100 | */ |
103 | if (bsize < 65520L) { | 101 | if (bsize < 65520L) { |
104 | buf = farmalloc(bsize); | 102 | buf = farmalloc(bsize); |
103 | #ifdef DEBUG | ||
104 | zmemzero(buf, (uInt)bsize); | ||
105 | #endif | ||
105 | if (*(ush*)&buf != 0) return buf; | 106 | if (*(ush*)&buf != 0) return buf; |
106 | } else { | 107 | } else { |
107 | buf = farmalloc(bsize + 16L); | 108 | buf = farmalloc(bsize + 16L); |
@@ -113,6 +114,10 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) | |||
113 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; | 114 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; |
114 | *(ush*)&buf = 0; | 115 | *(ush*)&buf = 0; |
115 | table[next_ptr++].new_ptr = buf; | 116 | table[next_ptr++].new_ptr = buf; |
117 | #ifdef DEBUG | ||
118 | zmemzero(buf, (uInt)65535); | ||
119 | ((uch*)buf)[65535] = 0; | ||
120 | #endif | ||
116 | return buf; | 121 | return buf; |
117 | } | 122 | } |
118 | 123 | ||
@@ -141,8 +146,7 @@ void zcfree (voidpf opaque, voidpf ptr) | |||
141 | #endif /* __TURBOC__ */ | 146 | #endif /* __TURBOC__ */ |
142 | 147 | ||
143 | 148 | ||
144 | #if defined(M_I86) && !(defined(__WATCOMC__) && defined(__386__)) | 149 | #ifdef M_I86 /* Microsoft C */ |
145 | /* Microsoft C */ | ||
146 | 150 | ||
147 | # define MY_ZCALLOC | 151 | # define MY_ZCALLOC |
148 | 152 | ||
@@ -178,7 +182,6 @@ voidpf zcalloc (opaque, items, size) | |||
178 | unsigned items; | 182 | unsigned items; |
179 | unsigned size; | 183 | unsigned size; |
180 | { | 184 | { |
181 | if (opaque) opaque = 0; /* to make compiler happy */ | ||
182 | return (voidpf)calloc(items, size); | 185 | return (voidpf)calloc(items, size); |
183 | } | 186 | } |
184 | 187 | ||
@@ -186,7 +189,6 @@ void zcfree (opaque, ptr) | |||
186 | voidpf opaque; | 189 | voidpf opaque; |
187 | voidpf ptr; | 190 | voidpf ptr; |
188 | { | 191 | { |
189 | if (opaque) opaque = 0; /* to make compiler happy */ | ||
190 | free(ptr); | 192 | free(ptr); |
191 | } | 193 | } |
192 | 194 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* zutil.h -- internal interface and configuration of the compression library | 1 | /* zutil.h -- internal interface and configuration of the compression library |
2 | * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | * Copyright (C) 1995 Jean-loup Gailly. |
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 | ||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #include "zlib.h" | 16 | #include "zlib.h" |
17 | 17 | ||
18 | #if defined(MSDOS) || defined(VMS) || defined(CRAY) || defined(WIN32) | 18 | #if defined(MSDOS) || defined(VMS) || defined(CRAY) |
19 | # include <stddef.h> | 19 | # include <stddef.h> |
20 | # include <errno.h> | 20 | # include <errno.h> |
21 | #else | 21 | #else |
@@ -37,13 +37,9 @@ typedef unsigned short ush; | |||
37 | typedef ush FAR ushf; | 37 | typedef ush FAR ushf; |
38 | typedef unsigned long ulg; | 38 | typedef unsigned long ulg; |
39 | 39 | ||
40 | extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | 40 | extern char *z_errmsg[]; /* indexed by 1-zlib_error */ |
41 | /* (size given to avoid silly warnings with Visual C++) */ | ||
42 | 41 | ||
43 | #define ERR_MSG(err) (char*)z_errmsg[Z_NEED_DICT-(err)] | 42 | #define ERR_RETURN(strm,err) return (strm->msg = z_errmsg[1-(err)], (err)) |
44 | |||
45 | #define ERR_RETURN(strm,err) \ | ||
46 | return (strm->msg = ERR_MSG(err), (err)) | ||
47 | /* To be used only when the state is known to be valid */ | 43 | /* To be used only when the state is known to be valid */ |
48 | 44 | ||
49 | /* common constants */ | 45 | /* common constants */ |
@@ -69,8 +65,6 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
69 | #define MAX_MATCH 258 | 65 | #define MAX_MATCH 258 |
70 | /* The minimum and maximum match lengths */ | 66 | /* The minimum and maximum match lengths */ |
71 | 67 | ||
72 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ | ||
73 | |||
74 | /* target dependencies */ | 68 | /* target dependencies */ |
75 | 69 | ||
76 | #ifdef MSDOS | 70 | #ifdef MSDOS |
@@ -148,13 +142,11 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
148 | # define HAVE_MEMCPY | 142 | # define HAVE_MEMCPY |
149 | #endif | 143 | #endif |
150 | #ifdef HAVE_MEMCPY | 144 | #ifdef HAVE_MEMCPY |
151 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ | 145 | # if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */ |
152 | # define zmemcpy _fmemcpy | 146 | # define zmemcpy _fmemcpy |
153 | # define zmemcmp _fmemcmp | ||
154 | # define zmemzero(dest, len) _fmemset(dest, 0, len) | 147 | # define zmemzero(dest, len) _fmemset(dest, 0, len) |
155 | # else | 148 | # else |
156 | # define zmemcpy memcpy | 149 | # define zmemcpy memcpy |
157 | # define zmemcmp memcmp | ||
158 | # define zmemzero(dest, len) memset(dest, 0, len) | 150 | # define zmemzero(dest, len) memset(dest, 0, len) |
159 | # endif | 151 | # endif |
160 | #else | 152 | #else |
@@ -184,7 +176,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
184 | #endif | 176 | #endif |
185 | 177 | ||
186 | 178 | ||
187 | typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len)); | 179 | typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len)); |
188 | 180 | ||
189 | extern void z_error OF((char *m)); | 181 | extern void z_error OF((char *m)); |
190 | 182 | ||