diff options
-rw-r--r-- | ChangeLog | 92 | ||||
-rw-r--r-- | INDEX | 61 | ||||
-rw-r--r-- | Makefile | 42 | ||||
-rw-r--r-- | Makefile.in | 42 | ||||
-rw-r--r-- | README | 62 | ||||
-rw-r--r-- | adler32.c | 6 | ||||
-rw-r--r-- | algorithm.txt (renamed from algorithm.doc) | 122 | ||||
-rw-r--r-- | compress.c | 6 | ||||
-rwxr-xr-x | configure | 69 | ||||
-rw-r--r-- | contrib/README.contrib | 21 | ||||
-rw-r--r-- | contrib/asm386/gvmat32.asm | 464 | ||||
-rw-r--r-- | contrib/asm386/gvmat32c.c | 229 | ||||
-rw-r--r-- | contrib/asm386/mkgvmt32.bat | 1 | ||||
-rw-r--r-- | contrib/asm386/zlibvc.mak | 781 | ||||
-rw-r--r-- | contrib/iostream/test.cpp | 24 | ||||
-rw-r--r-- | contrib/iostream/zfstream.cpp | 329 | ||||
-rw-r--r-- | contrib/iostream/zfstream.h | 142 | ||||
-rw-r--r-- | contrib/iostream2/zstream.h | 307 | ||||
-rw-r--r-- | contrib/iostream2/zstream_test.cpp | 25 | ||||
-rw-r--r-- | contrib/untgz/Makefile | 14 | ||||
-rw-r--r-- | contrib/untgz/makefile.w32 | 63 | ||||
-rw-r--r-- | contrib/untgz/untgz.c | 478 | ||||
-rw-r--r-- | contrib/visual-basic.txt | 57 | ||||
-rw-r--r-- | crc32.c | 8 | ||||
-rw-r--r-- | deflate.c | 169 | ||||
-rw-r--r-- | deflate.h | 5 | ||||
-rw-r--r-- | example.c | 58 | ||||
-rw-r--r-- | gzio.c | 347 | ||||
-rw-r--r-- | infblock.c | 22 | ||||
-rw-r--r-- | infblock.h | 8 | ||||
-rw-r--r-- | infcodes.c | 19 | ||||
-rw-r--r-- | infcodes.h | 2 | ||||
-rw-r--r-- | inffast.c | 2 | ||||
-rw-r--r-- | inffast.h | 2 | ||||
-rw-r--r-- | inflate.c | 72 | ||||
-rw-r--r-- | inftrees.c | 3 | ||||
-rw-r--r-- | inftrees.h | 2 | ||||
-rw-r--r-- | infutil.c | 2 | ||||
-rw-r--r-- | infutil.h | 2 | ||||
-rw-r--r-- | minigzip.c | 46 | ||||
-rw-r--r-- | msdos/Makefile.b32 (renamed from Makefile.b32) | 0 | ||||
-rw-r--r-- | msdos/Makefile.bor (renamed from Makefile.bor) | 0 | ||||
-rw-r--r-- | msdos/Makefile.dj2 (renamed from Makefile.dj2) | 33 | ||||
-rw-r--r-- | msdos/Makefile.msc (renamed from Makefile.msc) | 2 | ||||
-rw-r--r-- | msdos/Makefile.tc (renamed from Makefile.tc) | 0 | ||||
-rw-r--r-- | msdos/Makefile.wat (renamed from Makefile.wat) | 0 | ||||
-rw-r--r-- | msdos/zlib.def | 57 | ||||
-rw-r--r-- | msdos/zlib.rc (renamed from zlib.rc) | 10 | ||||
-rw-r--r-- | nt/Makefile.nt | 88 | ||||
-rw-r--r-- | nt/zlib.dnt | 44 | ||||
-rw-r--r-- | trees.c | 18 | ||||
-rw-r--r-- | uncompr.c | 8 | ||||
-rw-r--r-- | zconf.h | 77 | ||||
-rw-r--r-- | zlib.3 | 107 | ||||
-rw-r--r-- | zlib.def | 46 | ||||
-rw-r--r-- | zlib.h | 363 | ||||
-rw-r--r-- | zutil.c | 22 | ||||
-rw-r--r-- | zutil.h | 56 |
58 files changed, 4613 insertions, 524 deletions
@@ -1,13 +1,103 @@ | |||
1 | 1 | ||
2 | ChangeLog file for zlib | 2 | ChangeLog file for zlib |
3 | 3 | ||
4 | Changes in 1.0.7 (20 Jan 1998) | ||
5 | - fix gzseek which was broken in write mode | ||
6 | - return error for gzseek to negative absolute position | ||
7 | - fix configure for Linux (Chun-Chung Chen) | ||
8 | - increase stack space for MSC (Tim Wegner) | ||
9 | - get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) | ||
10 | - define EXPORTVA for gzprintf (Gilles Vollant) | ||
11 | - added man page zlib.3 (Rick Rodgers) | ||
12 | - for contrib/untgz, fix makedir() and improve Makefile | ||
13 | |||
14 | - check gzseek in write mode in example.c | ||
15 | - allocate extra buffer for seeks only if gzseek is actually called | ||
16 | - avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) | ||
17 | - add inflateSyncPoint in zconf.h | ||
18 | - fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def | ||
19 | |||
20 | Changes in 1.0.6 (19 Jan 1998) | ||
21 | - add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and | ||
22 | gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) | ||
23 | - Fix a deflate bug occuring only with compression level 0 (thanks to | ||
24 | Andy Buckler for finding this one). | ||
25 | - In minigzip, pass transparently also the first byte for .Z files. | ||
26 | - return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() | ||
27 | - check Z_FINISH in inflate (thanks to Marc Schluper) | ||
28 | - Implement deflateCopy (thanks to Adam Costello) | ||
29 | - make static libraries by default in configure, add --shared option. | ||
30 | - move MSDOS or Windows specific files to directory msdos | ||
31 | - suppress the notion of partial flush to simplify the interface | ||
32 | (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) | ||
33 | - suppress history buffer provided by application to simplify the interface | ||
34 | (this feature was not implemented anyway in 1.0.4) | ||
35 | - next_in and avail_in must be initialized before calling inflateInit or | ||
36 | inflateInit2 | ||
37 | - add EXPORT in all exported functions (for Windows DLL) | ||
38 | - added Makefile.nt (thanks to Stephen Williams) | ||
39 | - added the unsupported "contrib" directory: | ||
40 | contrib/asm386/ by Gilles Vollant <info@winimage.com> | ||
41 | 386 asm code replacing longest_match(). | ||
42 | contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> | ||
43 | A C++ I/O streams interface to the zlib gz* functions | ||
44 | contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no> | ||
45 | Another C++ I/O streams interface | ||
46 | contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> | ||
47 | A very simple tar.gz file extractor using zlib | ||
48 | contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl> | ||
49 | How to use compress(), uncompress() and the gz* functions from VB. | ||
50 | - pass params -f (filtered data), -h (huffman only), -1 to -9 (compression | ||
51 | level) in minigzip (thanks to Tom Lane) | ||
52 | |||
53 | - use const for rommable constants in deflate | ||
54 | - added test for gzseek and gztell in example.c | ||
55 | - add undocumented function inflateSyncPoint() (hack for Paul Mackerras) | ||
56 | - add undocumented function zError to convert error code to string | ||
57 | (for Tim Smithers) | ||
58 | - Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. | ||
59 | - Use default memcpy for Symantec MSDOS compiler. | ||
60 | - Add EXPORT keyword for check_func (needed for Windows DLL) | ||
61 | - add current directory to LD_LIBRARY_PATH for "make test" | ||
62 | - create also a link for libz.so.1 | ||
63 | - added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) | ||
64 | - use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) | ||
65 | - added -soname for Linux in configure (Chun-Chung Chen, | ||
66 | - assign numbers to the exported functions in zlib.def (for Windows DLL) | ||
67 | - add advice in zlib.h for best usage of deflateSetDictionary | ||
68 | - work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) | ||
69 | - allow compilation with ANSI keywords only enabled for TurboC in large model | ||
70 | - avoid "versionString"[0] (Borland bug) | ||
71 | - add NEED_DUMMY_RETURN for Borland | ||
72 | - use variable z_verbose for tracing in debug mode (Peter Deutsch). | ||
73 | - allow compilation with CC | ||
74 | - defined STDC for OS/2 (David Charlap) | ||
75 | - limit external names to 8 chars for MVS (Thomas Lund) | ||
76 | - in minigzip.c, use static buffers only for 16-bit systems | ||
77 | - fix suffix check for "minigzip -d foo.gz" | ||
78 | - do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) | ||
79 | - use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) | ||
80 | - added makelcc.bat for lcc-win32 (Tom St Denis) | ||
81 | - in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) | ||
82 | - Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. | ||
83 | - check for unistd.h in configure (for off_t) | ||
84 | - use Tracev instead of Trace in infblock.c | ||
85 | - remove useless check parameter in inflate_blocks_free | ||
86 | - avoid useless assignment of s->check to itself in inflate_blocks_new | ||
87 | - do not flush twice in gzclose (thanks to Ken Raeburn) | ||
88 | - rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h | ||
89 | - use NO_ERRNO_H instead of enumeration of operating systems with errno.h | ||
90 | - work around buggy fclose on pipes for HP/UX | ||
91 | - support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) | ||
92 | - fix configure if CC is already equal to gcc | ||
93 | |||
4 | Changes in 1.0.5 (3 Jan 98) | 94 | Changes in 1.0.5 (3 Jan 98) |
5 | - Fix inflate to terminate gracefully when fed corrupted or invalid data | 95 | - Fix inflate to terminate gracefully when fed corrupted or invalid data |
6 | - Use const for rommable constants in inflate | 96 | - Use const for rommable constants in inflate |
7 | - Eliminate memory leaks on error conditions in inflate | 97 | - Eliminate memory leaks on error conditions in inflate |
8 | - Removed some vestigial code in inflate | 98 | - Removed some vestigial code in inflate |
9 | - Update web address in README | 99 | - Update web address in README |
10 | 100 | ||
11 | Changes in 1.0.4 (24 Jul 96) | 101 | Changes in 1.0.4 (24 Jul 96) |
12 | - In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF | 102 | - In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF |
13 | bit, so the decompressor could decompress all the correct data but went | 103 | bit, so the decompressor could decompress all the correct data but went |
@@ -1,22 +1,28 @@ | |||
1 | ChangeLog history of changes | 1 | ChangeLog history of changes |
2 | INDEX this file | 2 | INDEX this file |
3 | Make_vms.com script for Vax/VMS | 3 | Make_vms.com script for Vax/VMS |
4 | Makefile makefile for Unix (generated by configure) | 4 | Makefile makefile for Unix (generated by configure) |
5 | Makefile.b32 makefile for Borland C++ 32-bit | 5 | Makefile.in makefile for Unix (template for configure) |
6 | Makefile.bor makefile for Borland C/C++ 16-bit | 6 | Makefile.msc makefile for Microsoft C 16-bit |
7 | Makefile.dj2 makefile for DJGPP 2.x | 7 | Makefile.riscos makefile for RISCOS |
8 | Makefile.in makefile for Unix (template for configure) | 8 | Makefile.sas makefile for Amiga SAS/C |
9 | Makefile.msc makefile for Microsoft C 16-bit | 9 | README guess what |
10 | Makefile.riscos makefile for RISCOS | 10 | algorithm.txt description of the (de)compression algorithm |
11 | Makefile.sas makefile for Amiga SAS/C | 11 | configure configure script for Unix |
12 | Makefile.tc makefile for Turbo C | 12 | descrip.mms makefile for Vax/VMS |
13 | Makefile.wat makefile for Watcom C | 13 | zlib.3 mini man page for zlib (volunteers to write full |
14 | README guess what | 14 | man pages from zlib.h welcome. write to jloup@gzip.org) |
15 | algorithm.doc description of the compression & decompression algorithms | 15 | |
16 | configure configure script for Unix | 16 | msdos/Makefile.b32 makefile for Borland C++ 32-bit |
17 | descrip.mms makefile for Vax/VMS | 17 | msdos/Makefile.bor makefile for Borland C/C++ 16-bit |
18 | zlib.def definition file for Windows DLL | 18 | msdos/Makefile.dj2 makefile for DJGPP 2.x |
19 | zlib.rc definition file for Windows DLL | 19 | msdos/Makefile.tc makefile for Turbo C |
20 | msdos/Makefile.wat makefile for Watcom C | ||
21 | msdos/zlib.def definition file for Windows DLL | ||
22 | msdos/zlib.rc definition file for Windows DLL | ||
23 | |||
24 | nt/Makefile.nt makefile for Windows NT | ||
25 | nt/zlib.dnt definition file for Windows NT DLL | ||
20 | 26 | ||
21 | 27 | ||
22 | zlib public header files (must be kept): | 28 | zlib public header files (must be kept): |
@@ -49,3 +55,20 @@ zutil.h | |||
49 | source files for sample programs: | 55 | source files for sample programs: |
50 | example.c | 56 | example.c |
51 | minigzip.c | 57 | minigzip.c |
58 | |||
59 | unsupported contribution by third parties | ||
60 | |||
61 | contrib/asm386/ by Gilles Vollant <info@winimage.com> | ||
62 | 386 asm code replacing longest_match(). | ||
63 | |||
64 | contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> | ||
65 | A C++ I/O streams interface to the zlib gz* functions | ||
66 | |||
67 | contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no> | ||
68 | Another C++ I/O streams interface | ||
69 | |||
70 | contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> | ||
71 | A very simple tar.gz extractor using zlib | ||
72 | |||
73 | contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl> | ||
74 | How to use compress(), uncompress() and the gz* functions from VB. | ||
@@ -22,12 +22,14 @@ CFLAGS=-O | |||
22 | LDFLAGS=-L. -lz | 22 | LDFLAGS=-L. -lz |
23 | LDSHARED=$(CC) | 23 | LDSHARED=$(CC) |
24 | 24 | ||
25 | VER=1.0.5 | 25 | VER=1.0.7 |
26 | LIBS=libz.a | 26 | LIBS=libz.a |
27 | SHAREDLIB=libz.so | ||
27 | 28 | ||
28 | AR=ar rc | 29 | AR=ar rc |
29 | RANLIB=ranlib | 30 | RANLIB=ranlib |
30 | TAR=tar | 31 | TAR=tar |
32 | SHELL=/bin/sh | ||
31 | 33 | ||
32 | prefix=/usr/local | 34 | prefix=/usr/local |
33 | exec_prefix = $(prefix) | 35 | exec_prefix = $(prefix) |
@@ -37,22 +39,30 @@ OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | |||
37 | 39 | ||
38 | TEST_OBJS = example.o minigzip.o | 40 | TEST_OBJS = example.o minigzip.o |
39 | 41 | ||
40 | DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] descrip.mms \ | 42 | DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \ |
41 | zlib.def zlib.rc algorithm.doc *.[ch] | 43 | algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \ |
44 | nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \ | ||
45 | contrib/asm386/*.asm contrib/asm386/*.c \ | ||
46 | contrib/asm386/*.bat contrib/asm386/*.mak contrib/iostream/*.cpp \ | ||
47 | contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \ | ||
48 | contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 | ||
42 | 49 | ||
43 | all: example minigzip | 50 | all: example minigzip |
44 | 51 | ||
45 | test: all | 52 | test: all |
46 | ./example | 53 | @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ |
47 | echo hello world | ./minigzip | ./minigzip -d | 54 | ./example ; \ |
55 | echo hello world | ./minigzip | ./minigzip -d | ||
48 | 56 | ||
49 | libz.a: $(OBJS) | 57 | libz.a: $(OBJS) |
50 | $(AR) $@ $(OBJS) | 58 | $(AR) $@ $(OBJS) |
51 | -@ ($(RANLIB) $@ || true) 2>/dev/null | 59 | -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 |
52 | 60 | ||
53 | libz.so.$(VER): $(OBJS) | 61 | $(SHAREDLIB).$(VER): $(OBJS) |
54 | $(LDSHARED) -o $@ $(OBJS) | 62 | $(LDSHARED) -o $@ $(OBJS) |
55 | rm -f libz.so; ln -s $@ libz.so | 63 | rm -f $(SHAREDLIB) $(SHAREDLIB).1 |
64 | ln -s $@ $(SHAREDLIB) | ||
65 | ln -s $@ $(SHAREDLIB).1 | ||
56 | 66 | ||
57 | example: example.o $(LIBS) | 67 | example: example.o $(LIBS) |
58 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) | 68 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) |
@@ -68,22 +78,28 @@ install: $(LIBS) | |||
68 | cp $(LIBS) $(exec_prefix)/lib | 78 | cp $(LIBS) $(exec_prefix)/lib |
69 | cd $(exec_prefix)/lib; chmod 644 $(LIBS) | 79 | cd $(exec_prefix)/lib; chmod 644 $(LIBS) |
70 | -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1 | 80 | -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1 |
71 | cd $(exec_prefix)/lib; if test -f libz.so.$(VER); then \ | 81 | cd $(exec_prefix)/lib; if test -f $(SHAREDLIB).$(VER); then \ |
72 | ln -s libz.so.$(VER) libz.so; \ | 82 | rm -f $(SHAREDLIB) $(SHAREDLIB).1; \ |
83 | ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \ | ||
84 | ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \ | ||
85 | (ldconfig || true) >/dev/null 2>&1; \ | ||
73 | fi | 86 | fi |
74 | # The ranlib in install is needed on NeXTSTEP which checks file times | 87 | # The ranlib in install is needed on NeXTSTEP which checks file times |
88 | # ldconfig is for Linux | ||
75 | 89 | ||
76 | uninstall: | 90 | uninstall: |
77 | cd $(exec_prefix)/lib; rm -f $(LIBS); \ | 91 | cd $(exec_prefix)/lib; rm -f $(LIBS); \ |
78 | if test -f libz.so; then \ | 92 | if test -f $(SHAREDLIB); then \ |
79 | v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p'<$(prefix)/include/zlib.h`;\ | 93 | v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p'<$(prefix)/include/zlib.h`;\ |
80 | rm -f libz.so.$$v libz.so; \ | 94 | rm -f $(SHAREDLIB).$$v $(SHAREDLIB); \ |
81 | fi | 95 | fi |
82 | cd $(prefix)/include; rm -f zlib.h zconf.h | 96 | cdz $(prefix)/include; rm -f zlib.h zconf.h |
83 | 97 | ||
84 | clean: | 98 | clean: |
85 | rm -f *.o *~ example minigzip libz.a libz.so* foo.gz | 99 | rm -f *.o *~ example minigzip libz.a libz.so* foo.gz |
86 | 100 | ||
101 | distclean: clean | ||
102 | |||
87 | zip: | 103 | zip: |
88 | mv Makefile Makefile~; cp -p Makefile.in Makefile | 104 | mv Makefile Makefile~; cp -p Makefile.in Makefile |
89 | v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ | 105 | v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ |
diff --git a/Makefile.in b/Makefile.in index b216ba7..3981614 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -22,12 +22,14 @@ CFLAGS=-O | |||
22 | LDFLAGS=-L. -lz | 22 | LDFLAGS=-L. -lz |
23 | LDSHARED=$(CC) | 23 | LDSHARED=$(CC) |
24 | 24 | ||
25 | VER=1.0.5 | 25 | VER=1.0.7 |
26 | LIBS=libz.a | 26 | LIBS=libz.a |
27 | SHAREDLIB=libz.so | ||
27 | 28 | ||
28 | AR=ar rc | 29 | AR=ar rc |
29 | RANLIB=ranlib | 30 | RANLIB=ranlib |
30 | TAR=tar | 31 | TAR=tar |
32 | SHELL=/bin/sh | ||
31 | 33 | ||
32 | prefix=/usr/local | 34 | prefix=/usr/local |
33 | exec_prefix = $(prefix) | 35 | exec_prefix = $(prefix) |
@@ -37,22 +39,30 @@ OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | |||
37 | 39 | ||
38 | TEST_OBJS = example.o minigzip.o | 40 | TEST_OBJS = example.o minigzip.o |
39 | 41 | ||
40 | DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] descrip.mms \ | 42 | DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \ |
41 | zlib.def zlib.rc algorithm.doc *.[ch] | 43 | algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \ |
44 | nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \ | ||
45 | contrib/asm386/*.asm contrib/asm386/*.c \ | ||
46 | contrib/asm386/*.bat contrib/asm386/*.mak contrib/iostream/*.cpp \ | ||
47 | contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \ | ||
48 | contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 | ||
42 | 49 | ||
43 | all: example minigzip | 50 | all: example minigzip |
44 | 51 | ||
45 | test: all | 52 | test: all |
46 | ./example | 53 | @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ |
47 | echo hello world | ./minigzip | ./minigzip -d | 54 | ./example ; \ |
55 | echo hello world | ./minigzip | ./minigzip -d | ||
48 | 56 | ||
49 | libz.a: $(OBJS) | 57 | libz.a: $(OBJS) |
50 | $(AR) $@ $(OBJS) | 58 | $(AR) $@ $(OBJS) |
51 | -@ ($(RANLIB) $@ || true) 2>/dev/null | 59 | -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 |
52 | 60 | ||
53 | libz.so.$(VER): $(OBJS) | 61 | $(SHAREDLIB).$(VER): $(OBJS) |
54 | $(LDSHARED) -o $@ $(OBJS) | 62 | $(LDSHARED) -o $@ $(OBJS) |
55 | rm -f libz.so; ln -s $@ libz.so | 63 | rm -f $(SHAREDLIB) $(SHAREDLIB).1 |
64 | ln -s $@ $(SHAREDLIB) | ||
65 | ln -s $@ $(SHAREDLIB).1 | ||
56 | 66 | ||
57 | example: example.o $(LIBS) | 67 | example: example.o $(LIBS) |
58 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) | 68 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) |
@@ -68,22 +78,28 @@ install: $(LIBS) | |||
68 | cp $(LIBS) $(exec_prefix)/lib | 78 | cp $(LIBS) $(exec_prefix)/lib |
69 | cd $(exec_prefix)/lib; chmod 644 $(LIBS) | 79 | cd $(exec_prefix)/lib; chmod 644 $(LIBS) |
70 | -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1 | 80 | -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1 |
71 | cd $(exec_prefix)/lib; if test -f libz.so.$(VER); then \ | 81 | cd $(exec_prefix)/lib; if test -f $(SHAREDLIB).$(VER); then \ |
72 | ln -s libz.so.$(VER) libz.so; \ | 82 | rm -f $(SHAREDLIB) $(SHAREDLIB).1; \ |
83 | ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \ | ||
84 | ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \ | ||
85 | (ldconfig || true) >/dev/null 2>&1; \ | ||
73 | fi | 86 | fi |
74 | # The ranlib in install is needed on NeXTSTEP which checks file times | 87 | # The ranlib in install is needed on NeXTSTEP which checks file times |
88 | # ldconfig is for Linux | ||
75 | 89 | ||
76 | uninstall: | 90 | uninstall: |
77 | cd $(exec_prefix)/lib; rm -f $(LIBS); \ | 91 | cd $(exec_prefix)/lib; rm -f $(LIBS); \ |
78 | if test -f libz.so; then \ | 92 | if test -f $(SHAREDLIB); then \ |
79 | v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p'<$(prefix)/include/zlib.h`;\ | 93 | v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p'<$(prefix)/include/zlib.h`;\ |
80 | rm -f libz.so.$$v libz.so; \ | 94 | rm -f $(SHAREDLIB).$$v $(SHAREDLIB); \ |
81 | fi | 95 | fi |
82 | cd $(prefix)/include; rm -f zlib.h zconf.h | 96 | cdz $(prefix)/include; rm -f zlib.h zconf.h |
83 | 97 | ||
84 | clean: | 98 | clean: |
85 | rm -f *.o *~ example minigzip libz.a libz.so* foo.gz | 99 | rm -f *.o *~ example minigzip libz.a libz.so* foo.gz |
86 | 100 | ||
101 | distclean: clean | ||
102 | |||
87 | zip: | 103 | zip: |
88 | mv Makefile Makefile~; cp -p Makefile.in Makefile | 104 | mv Makefile Makefile~; cp -p Makefile.in Makefile |
89 | v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ | 105 | v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ |
@@ -1,4 +1,4 @@ | |||
1 | zlib 1.0.5 is a general purpose data compression library. All the code | 1 | zlib 1.0.7 is a general purpose data compression library. All the code |
2 | is reentrant (thread safe). The data format used by the zlib library | 2 | is reentrant (thread safe). The data format used by the zlib library |
3 | is described by RFCs (Request for Comments) 1950 to 1952 in the files | 3 | is described by RFCs (Request for Comments) 1950 to 1952 in the files |
4 | ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate | 4 | ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate |
@@ -19,27 +19,54 @@ makefiles such as Makefile.msc; for VMS, use Make_vms.com or descrip.mms. | |||
19 | Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov> or, | 19 | Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov> or, |
20 | if this fails, to the addresses given below in the Copyright section. | 20 | if this fails, to the addresses given below in the Copyright section. |
21 | The zlib home page is http://www.cdrom.com/pub/infozip/zlib/ | 21 | The zlib home page is http://www.cdrom.com/pub/infozip/zlib/ |
22 | 22 | The official zlib ftp site is ftp://ftp.cdrom.com/pub/infozip/zlib/ | |
23 | The changes made in version 1.0.5 are documented in the file ChangeLog. | 23 | Mark Nelson wrote an article about zlib for the Jan. 1997 issue of |
24 | The main changes since 1.0.4 are: | 24 | Dr. Dobb's Journal; a copy of the article is available in |
25 | 25 | http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm | |
26 | - Fix inflate to terminate gracefully when fed corrupted or invalid data | 26 | |
27 | - Use const for rommable constants in inflate | 27 | The changes made in version 1.0.7 are documented in the file ChangeLog. |
28 | 28 | The main changes since 1.0.6 are: | |
29 | |||
30 | - fix gzseek which was broken in write mode | ||
31 | - return error for gzseek to negative absolute position | ||
32 | - fix configure for Linux (Chun-Chung Chen) | ||
33 | - increase stack space for MSC (Tim Wegner) | ||
34 | - get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) | ||
35 | - define EXPORTVA for gzprintf (Gilles Vollant) | ||
36 | - added mini man page zlib.3 (Rick Rodgers) [volunteers to write full | ||
37 | man pages from zlib.h most welcome. write to jloup@gzip.org] | ||
38 | - for contrib/untgz, fix makedir() and improve Makefile | ||
39 | |||
40 | Unsupported third party contributions are provided in directory "contrib". | ||
41 | |||
42 | A Java implementation of zlib is available in the Java Development Kit 1.1 | ||
43 | http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html | ||
44 | See the zlib home page http://www.cdrom.com/pub/infozip/zlib/ for details. | ||
29 | 45 | ||
30 | A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk> | 46 | A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk> |
31 | is in the CPAN (Comprehensive Perl Archive Network) sites, such as: | 47 | is in the CPAN (Comprehensive Perl Archive Network) sites, such as: |
32 | ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib* | 48 | ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib* |
33 | 49 | ||
50 | A Python interface to zlib written by A.M. Kuchling <amk@magnet.com> | ||
51 | is available from the Python Software Association sites, such as: | ||
52 | ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz | ||
34 | 53 | ||
35 | Notes for some targets: | 54 | Notes for some targets: |
36 | 55 | ||
37 | - For Turbo C the small model is supported only with reduced performance to | 56 | - To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc |
38 | avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 | 57 | and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL |
58 | The zlib DLL support was initially done by Alessandro Iacopetti and is | ||
59 | now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL | ||
60 | home page at http://www.winimage.com/zLibDll | ||
39 | 61 | ||
40 | - For 64-bit Iris, deflate.c must be compiled without any optimization. | 62 | From Visual Basic, you can call the DLL functions which do not take |
63 | a structure as argument: compress, uncompress and all gz* functions. | ||
64 | See contrib/visual-basic.txt for more information. | ||
65 | I don't know how to handle structures in Visual Basic, sorry. | ||
66 | |||
67 | - For 64-bit Irix, deflate.c must be compiled without any optimization. | ||
41 | With -O, one libpng test fails. The test works in 32 bit mode (with | 68 | With -O, one libpng test fails. The test works in 32 bit mode (with |
42 | the -32 compiler flag). The compiler bug has been reported to SGI. | 69 | the -n32 compiler flag). The compiler bug has been reported to SGI. |
43 | 70 | ||
44 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 | 71 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 |
45 | it works when compiled with cc. | 72 | it works when compiled with cc. |
@@ -47,14 +74,11 @@ Notes for some targets: | |||
47 | - zlib doesn't work on HP-UX 9.05 with one cc compiler (the one not | 74 | - zlib doesn't work on HP-UX 9.05 with one cc compiler (the one not |
48 | accepting the -O option). It works with the other cc compiler. | 75 | accepting the -O option). It works with the other cc compiler. |
49 | 76 | ||
50 | - To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc | ||
51 | and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL | ||
52 | For help on building a zlib DLL, contact Alessandro Iacopetti | ||
53 | <iaco@email.alessandria.alpcom.it> http://lisa.unial.it/iaco , | ||
54 | or contact Brad Clarke <bclarke@cyberus.ca>. | ||
55 | |||
56 | - gzdopen is not supported on RISCOS | 77 | - gzdopen is not supported on RISCOS |
57 | 78 | ||
79 | - For Turbo C the small model is supported only with reduced performance to | ||
80 | avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 | ||
81 | |||
58 | 82 | ||
59 | Acknowledgments: | 83 | Acknowledgments: |
60 | 84 | ||
@@ -84,7 +108,7 @@ Copyright notice: | |||
84 | 3. This notice may not be removed or altered from any source distribution. | 108 | 3. This notice may not be removed or altered from any source distribution. |
85 | 109 | ||
86 | Jean-loup Gailly Mark Adler | 110 | Jean-loup Gailly Mark Adler |
87 | gzip@prep.ai.mit.edu madler@alumni.caltech.edu | 111 | jloup@gzip.org madler@alumni.caltech.edu |
88 | 112 | ||
89 | If you use the zlib library in a product, we would appreciate *not* | 113 | If you use the zlib library in a product, we would appreciate *not* |
90 | receiving lengthy legal documents to sign. The sources are provided | 114 | receiving lengthy legal documents to sign. The sources are provided |
@@ -1,9 +1,9 @@ | |||
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-1998 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 | /* $Id: adler32.c,v 1.10 1996/05/22 11:52:18 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #include "zlib.h" | 8 | #include "zlib.h" |
9 | 9 | ||
@@ -18,7 +18,7 @@ | |||
18 | #define DO16(buf) DO8(buf,0); DO8(buf,8); | 18 | #define DO16(buf) DO8(buf,0); DO8(buf,8); |
19 | 19 | ||
20 | /* ========================================================================= */ | 20 | /* ========================================================================= */ |
21 | uLong adler32(adler, buf, len) | 21 | uLong EXPORT adler32(adler, buf, len) |
22 | uLong adler; | 22 | uLong adler; |
23 | const Bytef *buf; | 23 | const Bytef *buf; |
24 | uInt len; | 24 | uInt len; |
diff --git a/algorithm.doc b/algorithm.txt index 01902af..cdc830b 100644 --- a/algorithm.doc +++ b/algorithm.txt | |||
@@ -1,6 +1,6 @@ | |||
1 | 1. Compression algorithm (deflate) | 1 | 1. Compression algorithm (deflate) |
2 | 2 | ||
3 | The deflation algorithm used by zlib (also zip and gzip) is a variation of | 3 | The deflation algorithm used by gzip (also zip and zlib) is a variation of |
4 | LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in | 4 | LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in |
5 | the input data. The second occurrence of a string is replaced by a | 5 | the input data. The second occurrence of a string is replaced by a |
6 | pointer to the previous string, in the form of a pair (distance, | 6 | pointer to the previous string, in the form of a pair (distance, |
@@ -35,12 +35,12 @@ parameter of deflateInit). So deflate() does not always find the longest | |||
35 | possible match but generally finds a match which is long enough. | 35 | possible match but generally finds a match which is long enough. |
36 | 36 | ||
37 | deflate() also defers the selection of matches with a lazy evaluation | 37 | deflate() also defers the selection of matches with a lazy evaluation |
38 | mechanism. After a match of length N has been found, deflate() searches for a | 38 | mechanism. After a match of length N has been found, deflate() searches for |
39 | longer match at the next input byte. If a longer match is found, the | 39 | a longer match at the next input byte. If a longer match is found, the |
40 | previous match is truncated to a length of one (thus producing a single | 40 | previous match is truncated to a length of one (thus producing a single |
41 | literal byte) and the longer match is emitted afterwards. Otherwise, | 41 | literal byte) and the process of lazy evaluation begins again. Otherwise, |
42 | the original match is kept, and the next match search is attempted only | 42 | the original match is kept, and the next match search is attempted only N |
43 | N steps later. | 43 | steps later. |
44 | 44 | ||
45 | The lazy match evaluation is also subject to a runtime parameter. If | 45 | The lazy match evaluation is also subject to a runtime parameter. If |
46 | the current match is long enough, deflate() reduces the search for a longer | 46 | the current match is long enough, deflate() reduces the search for a longer |
@@ -57,6 +57,8 @@ but saves time since there are both fewer insertions and fewer searches. | |||
57 | 57 | ||
58 | 2. Decompression algorithm (inflate) | 58 | 2. Decompression algorithm (inflate) |
59 | 59 | ||
60 | 2.1 Introduction | ||
61 | |||
60 | The real question is, given a Huffman tree, how to decode fast. The most | 62 | The real question is, given a Huffman tree, how to decode fast. The most |
61 | important realization is that shorter codes are much more common than | 63 | important realization is that shorter codes are much more common than |
62 | longer codes, so pay attention to decoding the short codes fast, and let | 64 | longer codes, so pay attention to decoding the short codes fast, and let |
@@ -91,8 +93,114 @@ interesting to see if optimizing the first level table for other | |||
91 | applications gave values within a bit or two of the flat code size. | 93 | applications gave values within a bit or two of the flat code size. |
92 | 94 | ||
93 | 95 | ||
96 | 2.2 More details on the inflate table lookup | ||
97 | |||
98 | Ok, you want to know what this cleverly obfuscated inflate tree actually | ||
99 | looks like. You are correct that it's not a Huffman tree. It is simply a | ||
100 | lookup table for the first, let's say, nine bits of a Huffman symbol. The | ||
101 | symbol could be as short as one bit or as long as 15 bits. If a particular | ||
102 | symbol is shorter than nine bits, then that symbol's translation is duplicated | ||
103 | in all those entries that start with that symbol's bits. For example, if the | ||
104 | symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a | ||
105 | symbol is nine bits long, it appears in the table once. | ||
106 | |||
107 | If the symbol is longer than nine bits, then that entry in the table points | ||
108 | to another similar table for the remaining bits. Again, there are duplicated | ||
109 | entries as needed. The idea is that most of the time the symbol will be short | ||
110 | and there will only be one table look up. (That's whole idea behind data | ||
111 | compression in the first place.) For the less frequent long symbols, there | ||
112 | will be two lookups. If you had a compression method with really long | ||
113 | symbols, you could have as many levels of lookups as is efficient. For | ||
114 | inflate, two is enough. | ||
115 | |||
116 | So a table entry either points to another table (in which case nine bits in | ||
117 | the above example are gobbled), or it contains the translation for the symbol | ||
118 | and the number of bits to gobble. Then you start again with the next | ||
119 | ungobbled bit. | ||
120 | |||
121 | You may wonder: why not just have one lookup table for how ever many bits the | ||
122 | longest symbol is? The reason is that if you do that, you end up spending | ||
123 | more time filling in duplicate symbol entries than you do actually decoding. | ||
124 | At least for deflate's output that generates new trees every several 10's of | ||
125 | kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code | ||
126 | would take too long if you're only decoding several thousand symbols. At the | ||
127 | other extreme, you could make a new table for every bit in the code. In fact, | ||
128 | that's essentially a Huffman tree. But then you spend two much time | ||
129 | traversing the tree while decoding, even for short symbols. | ||
130 | |||
131 | So the number of bits for the first lookup table is a trade of the time to | ||
132 | fill out the table vs. the time spent looking at the second level and above of | ||
133 | the table. | ||
134 | |||
135 | Here is an example, scaled down: | ||
136 | |||
137 | The code being decoded, with 10 symbols, from 1 to 6 bits long: | ||
138 | |||
139 | A: 0 | ||
140 | B: 10 | ||
141 | C: 1100 | ||
142 | D: 11010 | ||
143 | E: 11011 | ||
144 | F: 11100 | ||
145 | G: 11101 | ||
146 | H: 11110 | ||
147 | I: 111110 | ||
148 | J: 111111 | ||
149 | |||
150 | Let's make the first table three bits long (eight entries): | ||
151 | |||
152 | 000: A,1 | ||
153 | 001: A,1 | ||
154 | 010: A,1 | ||
155 | 011: A,1 | ||
156 | 100: B,2 | ||
157 | 101: B,2 | ||
158 | 110: -> table X (gobble 3 bits) | ||
159 | 111: -> table Y (gobble 3 bits) | ||
160 | |||
161 | Each entry is what the bits decode to and how many bits that is, i.e. how | ||
162 | many bits to gobble. Or the entry points to another table, with the number of | ||
163 | bits to gobble implicit in the size of the table. | ||
164 | |||
165 | Table X is two bits long since the longest code starting with 110 is five bits | ||
166 | long: | ||
167 | |||
168 | 00: C,1 | ||
169 | 01: C,1 | ||
170 | 10: D,2 | ||
171 | 11: E,2 | ||
172 | |||
173 | Table Y is three bits long since the longest code starting with 111 is six | ||
174 | bits long: | ||
175 | |||
176 | 000: F,2 | ||
177 | 001: F,2 | ||
178 | 010: G,2 | ||
179 | 011: G,2 | ||
180 | 100: H,2 | ||
181 | 101: H,2 | ||
182 | 110: I,3 | ||
183 | 111: J,3 | ||
184 | |||
185 | So what we have here are three tables with a total of 20 entries that had to | ||
186 | be constructed. That's compared to 64 entries for a single table. Or | ||
187 | compared to 16 entries for a Huffman tree (six two entry tables and one four | ||
188 | entry table). Assuming that the code ideally represents the probability of | ||
189 | the symbols, it takes on the average 1.25 lookups per symbol. That's compared | ||
190 | to one lookup for the single table, or 1.66 lookups per symbol for the | ||
191 | Huffman tree. | ||
192 | |||
193 | There, I think that gives you a picture of what's going on. For inflate, the | ||
194 | meaning of a particular symbol is often more than just a letter. It can be a | ||
195 | byte (a "literal"), or it can be either a length or a distance which | ||
196 | indicates a base value and a number of bits to fetch after the code that is | ||
197 | added to the base value. Or it might be the special end-of-block code. The | ||
198 | data structures created in inftrees.c try to encode all that information | ||
199 | compactly in the tables. | ||
200 | |||
201 | |||
94 | Jean-loup Gailly Mark Adler | 202 | Jean-loup Gailly Mark Adler |
95 | gzip@prep.ai.mit.edu madler@alumni.caltech.edu | 203 | jloup@gzip.org madler@alumni.caltech.edu |
96 | 204 | ||
97 | 205 | ||
98 | References: | 206 | References: |
@@ -1,9 +1,9 @@ | |||
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-1998 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 | ||
6 | /* $Id: compress.c,v 1.10 1996/05/23 16:51:12 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #include "zlib.h" | 8 | #include "zlib.h" |
9 | 9 | ||
@@ -19,7 +19,7 @@ | |||
19 | enough memory, Z_BUF_ERROR if there was not enough room in the output | 19 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
20 | buffer. | 20 | buffer. |
21 | */ | 21 | */ |
22 | int compress (dest, destLen, source, sourceLen) | 22 | int EXPORT compress (dest, destLen, source, sourceLen) |
23 | Bytef *dest; | 23 | Bytef *dest; |
24 | uLongf *destLen; | 24 | uLongf *destLen; |
25 | const Bytef *source; | 25 | const Bytef *source; |
@@ -4,6 +4,10 @@ | |||
4 | # of if you need special compiler, flags or install directory. | 4 | # of if you need special compiler, flags or install directory. |
5 | # Otherwise, you can just use directly "make test; make install" | 5 | # Otherwise, you can just use directly "make test; make install" |
6 | # | 6 | # |
7 | # To create a shared library, use "configure --shared"; by default a static | ||
8 | # library is created. If the primitive shared library support provided here | ||
9 | # does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz | ||
10 | # | ||
7 | # To impose specific compiler or flags or install directory, use for example: | 11 | # To impose specific compiler or flags or install directory, use for example: |
8 | # prefix=$HOME CC=cc CFLAGS="-O4" ./configure | 12 | # prefix=$HOME CC=cc CFLAGS="-O4" ./configure |
9 | # or for csh/tcsh users: | 13 | # or for csh/tcsh users: |
@@ -11,22 +15,33 @@ | |||
11 | # LDSHARED is the command to be used to create a shared library | 15 | # LDSHARED is the command to be used to create a shared library |
12 | 16 | ||
13 | LIBS=libz.a | 17 | LIBS=libz.a |
18 | SHAREDLIB=libz.so | ||
14 | VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` | 19 | VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` |
15 | AR=${AR-"ar rc"} | 20 | AR=${AR-"ar rc"} |
16 | RANLIB=${RANLIB-"ranlib"} | 21 | RANLIB=${RANLIB-"ranlib"} |
17 | prefix=${prefix-/usr/local} | 22 | prefix=${prefix-/usr/local} |
18 | exec_prefix=${exec_prefix-$prefix} | 23 | exec_prefix=${exec_prefix-$prefix} |
24 | shared_ext='.so' | ||
25 | shared=0 | ||
26 | |||
27 | case "$1" in | ||
28 | -s* | --s*) shared=1; shift;; | ||
29 | -h* | --h*) echo 'syntax: configure [ --shared ]'; exit 0;; | ||
30 | esac | ||
19 | 31 | ||
20 | test -z "$CC" && echo Checking for gcc... | 32 | test -z "$CC" && echo Checking for gcc... |
21 | test=ztest$$ | 33 | test=ztest$$ |
22 | cat > $test.c <<EOF | 34 | cat > $test.c <<EOF |
23 | int hello() { printf("hello\n"); } | 35 | int hello() { printf("hello\n"); } |
24 | EOF | 36 | EOF |
25 | if test -z "$CC" && (gcc -c -O3 $test.c) 2>/dev/null; then | 37 | if test -z "$CC" -o "$CC" = "gcc" && (gcc -c -O3 $test.c) 2>/dev/null; then |
26 | CC=gcc | 38 | CC=gcc |
27 | SFLAGS=${CFLAGS-"-fPIC -O3"} | 39 | SFLAGS=${CFLAGS-"-fPIC -O3"} |
28 | CFLAGS=${CFLAGS-"-O3"} | 40 | CFLAGS=${CFLAGS-"-O3"} |
29 | LDSHARED=${LDSHARED-"gcc -shared"} | 41 | case `(uname -s || echo unknown) 2>/dev/null` in |
42 | Linux | linux) LDSHARED=${LDSHARED-"gcc -shared -Wl,-soname,libz.so.1"};; | ||
43 | *) LDSHARED=${LDSHARED-"gcc -shared"};; | ||
44 | esac | ||
30 | else | 45 | else |
31 | # find system name and corresponding cc options | 46 | # find system name and corresponding cc options |
32 | CC=${CC-cc} | 47 | CC=${CC-cc} |
@@ -50,35 +65,55 @@ else | |||
50 | LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};; | 65 | LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};; |
51 | HP-UX*) SFLAGS=${CFLAGS-"-O +z"} | 66 | HP-UX*) SFLAGS=${CFLAGS-"-O +z"} |
52 | CFLAGS=${CFLAGS-"-O"} | 67 | CFLAGS=${CFLAGS-"-O"} |
53 | LDSHARED=${LDSHARED-"ld -b"} | 68 | LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"} |
54 | SHAREDLIBS='libz.sl';; | 69 | shared_ext='.sl' |
55 | # send working options for other systems to gzip@prep.ai.mit.edu | 70 | SHAREDLIB='libz.sl';; |
71 | UNIX_System_V\ 4.2.0) | ||
72 | SFLAGS=${CFLAGS-"-KPIC -O"} | ||
73 | CFLAGS=${CFLAGS-"-O"} | ||
74 | LDSHARED=${LDSHARED-"cc -G"};; | ||
75 | # send working options for other systems to support@gzip.org | ||
56 | *) SFLAGS=${CFLAGS-"-O"} | 76 | *) SFLAGS=${CFLAGS-"-O"} |
57 | CFLAGS=${CFLAGS-"-O"} | 77 | CFLAGS=${CFLAGS-"-O"} |
58 | LDSHARED=${LDSHARED-"cc -shared"};; | 78 | LDSHARED=${LDSHARED-"cc -shared"};; |
59 | esac | 79 | esac |
60 | fi | 80 | fi |
61 | 81 | ||
62 | echo Checking for shared library support... | 82 | if test $shared -eq 1; then |
63 | # we must test in two steps (cc then ld), required at least on SunOS 4.x | 83 | echo Checking for shared library support... |
64 | if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" && | 84 | # we must test in two steps (cc then ld), required at least on SunOS 4.x |
65 | test "`($LDSHARED -o $test.so $test.o) 2>&1`" = ""; then | 85 | if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" && |
66 | CFLAGS="$SFLAGS" | 86 | test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then |
67 | LIBS='libz.so.$(VER)' | 87 | CFLAGS="$SFLAGS" |
68 | echo Building shared library libz.so.$VER with $CC. | 88 | LIBS="$SHAREDLIB.$VER" |
69 | else | 89 | echo Building shared library $SHAREDLIB.$VER with $CC. |
90 | else | ||
91 | echo No shared library suppport. | ||
92 | shared=0; | ||
93 | fi | ||
94 | fi | ||
95 | if test $shared -eq 0; then | ||
70 | LDSHARED="$CC" | 96 | LDSHARED="$CC" |
71 | echo Building static library $LIBS version $VER with $CC. | 97 | echo Building static library $LIBS version $VER with $CC. |
72 | fi | 98 | fi |
73 | rm -f $test.[co] $test.so | 99 | rm -f $test.[co] $test$shared_ext |
100 | |||
101 | if test -f /usr/include/unistd.h; then | ||
102 | CFLAGS="$CFLAGS -DHAVE_UNISTD_H" | ||
103 | fi | ||
104 | |||
105 | if test ! -f /usr/include/errno.h; then | ||
106 | CFLAGS="$CFLAGS -DNO_ERRNO_H" | ||
107 | fi | ||
74 | 108 | ||
75 | # udpate Makefile | 109 | # udpate Makefile |
76 | sed < Makefile.in " | 110 | sed < Makefile.in " |
77 | /^CC *=/s/=.*/=$CC/ | 111 | /^CC *=/s,=.*,=$CC, |
78 | /^CFLAGS *=/s/=.*/=$CFLAGS/ | 112 | /^CFLAGS *=/s/=.*/=$CFLAGS/ |
79 | /^LDSHARED *=/s/=.*/=$LDSHARED/ | 113 | /^LDSHARED *=/s%=.*%=$LDSHARED% |
80 | /^LIBS *=/s,=.*,=$LIBS, | 114 | /^LIBS *=/s,=.*,=$LIBS, |
81 | /^AR *=/s/=.*/=$AR/ | 115 | /^SHAREDLIB *=/s,=.*,=$SHAREDLIB, |
116 | /^AR *=/s,=.*,=$AR, | ||
82 | /^RANLIB *=/s,=.*,=$RANLIB, | 117 | /^RANLIB *=/s,=.*,=$RANLIB, |
83 | /^VER *=/s/=.*/=$VER/ | 118 | /^VER *=/s/=.*/=$VER/ |
84 | /^prefix *=/s,=.*,=$prefix, | 119 | /^prefix *=/s,=.*,=$prefix, |
diff --git a/contrib/README.contrib b/contrib/README.contrib new file mode 100644 index 0000000..87eb1e3 --- /dev/null +++ b/contrib/README.contrib | |||
@@ -0,0 +1,21 @@ | |||
1 | All files under this contrib directory are UNSUPPORTED. There were | ||
2 | provided by users of zlib and were not tested by the authors of zlib. | ||
3 | Use at your own risk. Please contact the authors of the contributions | ||
4 | for help about these, not the zlib authors. Thanks. | ||
5 | |||
6 | |||
7 | asm386/ by Gilles Vollant <info@winimage.com> | ||
8 | 386 asm code replacing longest_match(). This code may be slower | ||
9 | than the C code if you have a good compiler. | ||
10 | |||
11 | iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> | ||
12 | A C++ I/O streams interface to the zlib gz* functions | ||
13 | |||
14 | iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no> | ||
15 | Another C++ I/O streams interface | ||
16 | |||
17 | untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> | ||
18 | A very simple tar.gz file extractor using zlib | ||
19 | |||
20 | visual-basic.txt by Carlos Rios <c_rios@sonda.cl> | ||
21 | How to use compress(), uncompress() and the gz* functions from VB. | ||
diff --git a/contrib/asm386/gvmat32.asm b/contrib/asm386/gvmat32.asm new file mode 100644 index 0000000..b175871 --- /dev/null +++ b/contrib/asm386/gvmat32.asm | |||
@@ -0,0 +1,464 @@ | |||
1 | ; | ||
2 | ; gvmat32.asm -- Asm portion of the optimized longest_match for 32 bits x86 | ||
3 | ; Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant. | ||
4 | ; File written by Gilles Vollant, by modifiying the longest_match | ||
5 | ; from Jean-loup Gailly in deflate.c | ||
6 | ; It need wmask == 0x7fff | ||
7 | ; (assembly code is faster with a fixed wmask) | ||
8 | ; | ||
9 | ; For Visual C++ 4.2 and ML 6.11c (version in directory \MASM611C of Win95 DDK) | ||
10 | ; I compile with : "ml /coff /Zi /c gvmat32.asm" | ||
11 | ; | ||
12 | ; uInt longest_match_gvasm(IPos cur_match,int* match_start_ptr,uInt scan_end, | ||
13 | ; uInt scan_start,ush* prev,uch* window,int best_len, | ||
14 | ; IPos limit,uInt chain_length,uch* scanrp, | ||
15 | ; uInt nice_match); | ||
16 | |||
17 | ;uInt longest_match(s, cur_match) | ||
18 | ; deflate_state *s; | ||
19 | ; IPos cur_match; /* current match */ | ||
20 | |||
21 | NbStack equ 76 | ||
22 | cur_match equ dword ptr[esp+NbStack-0] | ||
23 | str_s equ dword ptr[esp+NbStack-4] | ||
24 | ; 5 dword on top (ret,ebp,esi,edi,ebx) | ||
25 | adrret equ dword ptr[esp+NbStack-8] | ||
26 | pushebp equ dword ptr[esp+NbStack-12] | ||
27 | pushedi equ dword ptr[esp+NbStack-16] | ||
28 | pushesi equ dword ptr[esp+NbStack-20] | ||
29 | pushebx equ dword ptr[esp+NbStack-24] | ||
30 | |||
31 | chain_length equ dword ptr [esp+NbStack-28] | ||
32 | limit equ dword ptr [esp+NbStack-32] | ||
33 | best_len equ dword ptr [esp+NbStack-36] | ||
34 | window equ dword ptr [esp+NbStack-40] | ||
35 | prev equ dword ptr [esp+NbStack-44] | ||
36 | scan_start equ word ptr [esp+NbStack-48] | ||
37 | scan_end equ word ptr [esp+NbStack-52] | ||
38 | match_start_ptr equ dword ptr [esp+NbStack-56] | ||
39 | nice_match equ dword ptr [esp+NbStack-60] | ||
40 | scanrp equ dword ptr [esp+NbStack-64] | ||
41 | |||
42 | windowlen equ dword ptr [esp+NbStack-68] | ||
43 | match_start equ dword ptr [esp+NbStack-72] | ||
44 | strend equ dword ptr [esp+NbStack-76] | ||
45 | NbStackAdd equ (76-24) | ||
46 | |||
47 | .386p | ||
48 | |||
49 | name gvmatch | ||
50 | .MODEL FLAT | ||
51 | |||
52 | |||
53 | @lmtype TYPEDEF PROTO C :PTR , :SDWORD | ||
54 | longest_match_c PROTO @lmtype | ||
55 | |||
56 | dep_max_chain_length equ 70h | ||
57 | dep_window equ 2ch | ||
58 | dep_strstart equ 60h | ||
59 | dep_prev_length equ 6ch | ||
60 | dep_nice_match equ 84h | ||
61 | dep_w_size equ 20h | ||
62 | dep_prev equ 34h | ||
63 | dep_w_mask equ 28h | ||
64 | dep_good_match equ 80h | ||
65 | dep_match_start equ 64h | ||
66 | dep_lookahead equ 68h | ||
67 | |||
68 | |||
69 | _TEXT segment | ||
70 | public _longest_match_asm7fff | ||
71 | |||
72 | MAX_MATCH equ 258 | ||
73 | MIN_MATCH equ 3 | ||
74 | MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) | ||
75 | |||
76 | ; initialize or check the variables used in match.asm. | ||
77 | |||
78 | |||
79 | ; ----------------------------------------------------------------------- | ||
80 | ; Set match_start to the longest match starting at the given string and | ||
81 | ; return its length. Matches shorter or equal to prev_length are discarded, | ||
82 | ; in which case the result is equal to prev_length and match_start is | ||
83 | ; garbage. | ||
84 | ; IN assertions: cur_match is the head of the hash chain for the current | ||
85 | ; string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 | ||
86 | |||
87 | ; int longest_match(cur_match) | ||
88 | |||
89 | _longest_match_asm7fff proc near | ||
90 | |||
91 | |||
92 | |||
93 | ; return address | ||
94 | |||
95 | mov eax,[esp+4] | ||
96 | mov bx,[eax+dep_w_mask] | ||
97 | cmp bx,7fffh | ||
98 | jnz longest_match_c | ||
99 | |||
100 | push ebp | ||
101 | push edi | ||
102 | push esi | ||
103 | push ebx | ||
104 | |||
105 | sub esp,NbStackAdd | ||
106 | |||
107 | ;//mov ebp,str_s | ||
108 | mov ebp,eax | ||
109 | |||
110 | mov eax,[ebp+dep_max_chain_length] | ||
111 | mov ebx,[ebp+dep_prev_length] | ||
112 | cmp [ebp+dep_good_match],ebx ; if prev_length>=good_match chain_length >>= 2 | ||
113 | ja noshr | ||
114 | shr eax,2 | ||
115 | noshr: | ||
116 | mov edi,[ebp+dep_nice_match] | ||
117 | mov chain_length,eax | ||
118 | mov edx,[ebp+dep_lookahead] | ||
119 | cmp edx,edi | ||
120 | ;if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; | ||
121 | jae nolookaheadnicematch | ||
122 | mov edi,edx | ||
123 | nolookaheadnicematch: | ||
124 | mov best_len,ebx | ||
125 | |||
126 | |||
127 | mov esi,[ebp+dep_window] | ||
128 | mov ecx,[ebp+dep_strstart] | ||
129 | mov window,esi | ||
130 | |||
131 | mov nice_match,edi | ||
132 | add esi,ecx | ||
133 | mov scanrp,esi | ||
134 | mov ax,word ptr [esi] | ||
135 | mov bx,word ptr [esi+ebx-1] | ||
136 | add esi,MAX_MATCH-1 | ||
137 | mov scan_start,ax | ||
138 | mov strend,esi | ||
139 | mov scan_end,bx | ||
140 | |||
141 | ; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? | ||
142 | ; s->strstart - (IPos)MAX_DIST(s) : NIL; | ||
143 | |||
144 | mov esi,[ebp+dep_w_size] | ||
145 | sub esi,MIN_LOOKAHEAD | ||
146 | ; here esi = MAX_DIST(s) | ||
147 | sub ecx,esi | ||
148 | ja nodist | ||
149 | xor ecx,ecx | ||
150 | nodist: | ||
151 | mov limit,ecx | ||
152 | |||
153 | |||
154 | |||
155 | |||
156 | mov eax,[ebp+dep_prev] | ||
157 | mov prev,eax | ||
158 | |||
159 | mov ebx,dword ptr [ebp+dep_match_start] | ||
160 | mov bp,scan_start | ||
161 | mov edx,cur_match | ||
162 | mov match_start,ebx | ||
163 | |||
164 | mov bx,scan_end | ||
165 | mov eax,window | ||
166 | mov edi,eax | ||
167 | add edi,best_len | ||
168 | mov esi,prev | ||
169 | dec edi | ||
170 | mov windowlen,edi | ||
171 | |||
172 | jmp beginloop2 | ||
173 | align 4 | ||
174 | |||
175 | ; here, in the loop | ||
176 | ;;;; eax = chain_length | ||
177 | ; edx = dx = cur_match | ||
178 | ; ecx = limit | ||
179 | ; bx = scan_end | ||
180 | ; bp = scan_start | ||
181 | ; edi = windowlen (window + best_len) | ||
182 | ; esi = prev | ||
183 | |||
184 | |||
185 | ;// here; eax <=16 | ||
186 | normalbeg0add16: | ||
187 | add chain_length,16 | ||
188 | jz exitloop | ||
189 | normalbeg0: | ||
190 | cmp word ptr[edi+edx-0],bx | ||
191 | je normalbeg2 | ||
192 | and edx,7fffh | ||
193 | mov dx,word ptr[esi+edx*2] | ||
194 | cmp ecx,edx | ||
195 | jnb exitloop | ||
196 | dec chain_length | ||
197 | jnz normalbeg0 | ||
198 | ;jnbexitloopshort1: | ||
199 | jmp exitloop | ||
200 | |||
201 | contloop3: | ||
202 | mov edi,windowlen | ||
203 | |||
204 | ; cur_match = prev[cur_match & wmask] | ||
205 | and edx,7fffh | ||
206 | mov dx,word ptr[esi+edx*2] | ||
207 | ; if cur_match > limit, go to exitloop | ||
208 | cmp ecx,edx | ||
209 | jnbexitloopshort1: | ||
210 | jnb exitloop | ||
211 | ; if --chain_length != 0, go to exitloop | ||
212 | |||
213 | beginloop2: | ||
214 | sub chain_length,16+1 | ||
215 | jna normalbeg0add16 | ||
216 | |||
217 | do16: | ||
218 | cmp word ptr[edi+edx],bx | ||
219 | je normalbeg2dc0 | ||
220 | |||
221 | maccn MACRO lab | ||
222 | and edx,7fffh | ||
223 | mov dx,word ptr[esi+edx*2] | ||
224 | cmp ecx,edx | ||
225 | jnb exitloop | ||
226 | cmp word ptr[edi+edx-0],bx | ||
227 | je lab | ||
228 | ENDM | ||
229 | |||
230 | rcontloop0: | ||
231 | maccn normalbeg2dc1 | ||
232 | |||
233 | rcontloop1: | ||
234 | maccn normalbeg2dc2 | ||
235 | |||
236 | rcontloop2: | ||
237 | maccn normalbeg2dc3 | ||
238 | |||
239 | rcontloop3: | ||
240 | maccn normalbeg2dc4 | ||
241 | |||
242 | rcontloop4: | ||
243 | maccn normalbeg2dc5 | ||
244 | |||
245 | rcontloop5: | ||
246 | maccn normalbeg2dc6 | ||
247 | |||
248 | rcontloop6: | ||
249 | maccn normalbeg2dc7 | ||
250 | |||
251 | rcontloop7: | ||
252 | maccn normalbeg2dc8 | ||
253 | |||
254 | rcontloop8: | ||
255 | maccn normalbeg2dc9 | ||
256 | |||
257 | rcontloop9: | ||
258 | maccn normalbeg2dc10 | ||
259 | |||
260 | rcontloop10: | ||
261 | maccn normalbeg2dc11 | ||
262 | |||
263 | rcontloop11: | ||
264 | maccn short normalbeg2dc12 | ||
265 | |||
266 | rcontloop12: | ||
267 | maccn short normalbeg2dc13 | ||
268 | |||
269 | rcontloop13: | ||
270 | maccn short normalbeg2dc14 | ||
271 | |||
272 | rcontloop14: | ||
273 | maccn short normalbeg2dc15 | ||
274 | |||
275 | rcontloop15: | ||
276 | and edx,7fffh | ||
277 | mov dx,word ptr[esi+edx*2] | ||
278 | cmp ecx,edx | ||
279 | jnb short exitloopshort | ||
280 | |||
281 | sub chain_length,16 | ||
282 | ja do16 | ||
283 | jmp normalbeg0add16 | ||
284 | |||
285 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
286 | |||
287 | exitloopshort: | ||
288 | jmp exitloop | ||
289 | |||
290 | normbeg MACRO rcontlab,valsub | ||
291 | cmp bp,word ptr[eax+edx] | ||
292 | jne rcontlab | ||
293 | add chain_length,16-valsub | ||
294 | jmp iseq | ||
295 | ENDM | ||
296 | |||
297 | normalbeg2dc12: | ||
298 | normbeg rcontloop12,12 | ||
299 | |||
300 | normalbeg2dc13: | ||
301 | normbeg rcontloop13,13 | ||
302 | |||
303 | normalbeg2dc14: | ||
304 | normbeg rcontloop14,14 | ||
305 | |||
306 | normalbeg2dc15: | ||
307 | normbeg rcontloop15,15 | ||
308 | |||
309 | normalbeg2dc11: | ||
310 | normbeg rcontloop11,11 | ||
311 | |||
312 | normalbeg2dc10: | ||
313 | normbeg rcontloop10,10 | ||
314 | |||
315 | |||
316 | normalbeg2dc9: | ||
317 | normbeg rcontloop9,9 | ||
318 | |||
319 | normalbeg2dc8: | ||
320 | normbeg rcontloop8,8 | ||
321 | |||
322 | normalbeg2dc7: | ||
323 | normbeg rcontloop7,7 | ||
324 | |||
325 | normalbeg2dc5: | ||
326 | normbeg rcontloop5,5 | ||
327 | |||
328 | |||
329 | |||
330 | |||
331 | |||
332 | normalbeg2dc6: | ||
333 | normbeg rcontloop6,6 | ||
334 | |||
335 | normalbeg2dc4: | ||
336 | normbeg rcontloop4,4 | ||
337 | |||
338 | normalbeg2dc3: | ||
339 | normbeg rcontloop3,3 | ||
340 | |||
341 | normalbeg2dc2: | ||
342 | normbeg rcontloop2,2 | ||
343 | |||
344 | normalbeg2dc1: | ||
345 | normbeg rcontloop1,1 | ||
346 | |||
347 | normalbeg2dc0: | ||
348 | normbeg rcontloop0,0 | ||
349 | |||
350 | |||
351 | ; we go in normalbeg2 because *(ushf*)(match+best_len-1) == scan_end | ||
352 | |||
353 | normalbeg2: | ||
354 | |||
355 | ; 10 nop here take 10% time | ||
356 | mov edi,window | ||
357 | ;mov chain_length,eax ; now, we need eax... | ||
358 | |||
359 | cmp bp,word ptr[edi+edx] | ||
360 | jne contloop3 ; if *(ushf*)match != scan_start, continue | ||
361 | |||
362 | iseq: | ||
363 | |||
364 | mov edi,eax | ||
365 | mov esi,scanrp ; esi = scan | ||
366 | add edi,edx ; edi = window + cur_match = match | ||
367 | |||
368 | |||
369 | mov eax,[esi+3] ; compare manually dword at match+3 | ||
370 | xor eax,[edi+3] ; and scan +3 | ||
371 | |||
372 | jz begincompare ; if equal, go to long compare | ||
373 | |||
374 | ; we will determine the unmatch byte and calculate len (in esi) | ||
375 | or al,al | ||
376 | je eq1rr | ||
377 | mov esi,3 | ||
378 | jmp trfinval | ||
379 | eq1rr: | ||
380 | or ax,ax | ||
381 | je eq1 | ||
382 | |||
383 | mov esi,4 | ||
384 | jmp trfinval | ||
385 | eq1: | ||
386 | shl eax,8 | ||
387 | jz eq11 | ||
388 | mov esi,5 | ||
389 | jmp trfinval | ||
390 | eq11: | ||
391 | mov esi,6 | ||
392 | jmp trfinval | ||
393 | |||
394 | begincompare: | ||
395 | ; here we now scan and match begin same | ||
396 | add edi,6 | ||
397 | add esi,6 | ||
398 | mov ecx,(MAX_MATCH-(2+4))/4 ;//; scan for at most MAX_MATCH bytes | ||
399 | repe cmpsd ;//; loop until mismatch | ||
400 | |||
401 | je trfin ; go to trfin if not unmatch | ||
402 | ; we determine the unmatch byte | ||
403 | sub esi,4 | ||
404 | mov eax,[edi-4] | ||
405 | xor eax,[esi] | ||
406 | or al,al | ||
407 | |||
408 | jnz trfin | ||
409 | inc esi | ||
410 | |||
411 | or ax,ax | ||
412 | jnz trfin | ||
413 | inc esi | ||
414 | |||
415 | shl eax,8 | ||
416 | jnz trfin | ||
417 | inc esi | ||
418 | |||
419 | trfin: | ||
420 | sub esi,scanrp ; esi = len | ||
421 | trfinval: | ||
422 | cmp esi,best_len ; if len <= best_len, go contloop2 | ||
423 | jbe contloop2 | ||
424 | |||
425 | mov best_len,esi ; len become best_len | ||
426 | |||
427 | mov match_start,edx | ||
428 | cmp esi,nice_match ;//; if esi >= nice_match, exit | ||
429 | mov ecx,scanrp | ||
430 | jae exitloop | ||
431 | add esi,window | ||
432 | add ecx,best_len | ||
433 | dec esi | ||
434 | mov windowlen,esi | ||
435 | mov bx,[ecx-1] | ||
436 | |||
437 | |||
438 | ; now we restore eax, ecx and esi, for the big loop : | ||
439 | contloop2: | ||
440 | mov esi,prev | ||
441 | mov ecx,limit | ||
442 | ;mov eax,chain_length | ||
443 | mov eax,window | ||
444 | jmp contloop3 | ||
445 | |||
446 | exitloop: | ||
447 | mov ebx,match_start | ||
448 | mov ebp,str_s | ||
449 | mov dword ptr [ebp+dep_match_start],ebx | ||
450 | mov eax,best_len | ||
451 | add esp,NbStackAdd | ||
452 | |||
453 | |||
454 | pop ebx | ||
455 | pop esi | ||
456 | pop edi | ||
457 | pop ebp | ||
458 | ret | ||
459 | |||
460 | _longest_match_asm7fff endp | ||
461 | |||
462 | _TEXT ends | ||
463 | end | ||
464 | \ No newline at end of file | ||
diff --git a/contrib/asm386/gvmat32c.c b/contrib/asm386/gvmat32c.c new file mode 100644 index 0000000..43d530b --- /dev/null +++ b/contrib/asm386/gvmat32c.c | |||
@@ -0,0 +1,229 @@ | |||
1 | /* gvmat32.c -- C portion of the optimized longest_match for 32 bits x86 | ||
2 | * Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant. | ||
3 | * File written by Gilles Vollant, by modifiying the longest_match | ||
4 | * from Jean-loup Gailly in deflate.c | ||
5 | * it prepare all parameters and call the assembly longest_match_gvasm | ||
6 | * longest_match execute standard C code is wmask != 0x7fff | ||
7 | * (assembly code is faster with a fixed wmask) | ||
8 | * | ||
9 | */ | ||
10 | //#pragma optimize("agt",on) | ||
11 | |||
12 | #include "deflate.h" | ||
13 | |||
14 | #undef FAR | ||
15 | #include <windows.h> | ||
16 | |||
17 | #ifdef ASMV | ||
18 | |||
19 | #define NIL 0 | ||
20 | |||
21 | static unsigned int tot=0; | ||
22 | static unsigned int totl0=0; | ||
23 | static unsigned int totl0p0=0; | ||
24 | static unsigned int ba0=0; | ||
25 | static unsigned int ba1=0; | ||
26 | static unsigned int cpta=0; | ||
27 | static unsigned int cptb=0; | ||
28 | |||
29 | #define UNALIGNED_OK | ||
30 | #define gvshow(a,b,c,d) | ||
31 | /* | ||
32 | void gvshow(int chain_length,int len,int limit,ushf* prev) | ||
33 | { | ||
34 | static int ival=0; | ||
35 | char sz[80]; | ||
36 | unsigned long i; | ||
37 | int prev0=*prev; | ||
38 | ival++; | ||
39 | //wsprintf(sz,"call %u, len=%u, chain_length=%u\n",ival,len,chain_length); | ||
40 | //OutputDebugString(sz); | ||
41 | tot++; | ||
42 | if (limit==NIL) | ||
43 | totl0++; | ||
44 | if ((limit==NIL) && (prev0==0)) | ||
45 | totl0p0++; | ||
46 | for (i=limit+1;i<32768;i++) | ||
47 | { | ||
48 | ush va=*(prev+i); | ||
49 | if (ba0>4000000000) | ||
50 | { | ||
51 | ba0+=10; | ||
52 | } | ||
53 | ba0++; | ||
54 | if ((va>limit) || (va==0)) | ||
55 | continue; | ||
56 | ba1++; | ||
57 | } | ||
58 | } | ||
59 | */ | ||
60 | |||
61 | |||
62 | /* if your C compiler don't add underline before function name, | ||
63 | define ADD_UNDERLINE_ASMFUNC */ | ||
64 | #ifdef ADD_UNDERLINE_ASMFUNC | ||
65 | #define longest_match_asm7fff _longest_match_asm7fff | ||
66 | #endif | ||
67 | void match_init() | ||
68 | { | ||
69 | } | ||
70 | |||
71 | uInt longest_match_c( | ||
72 | deflate_state *s, | ||
73 | IPos cur_match); /* current match */ | ||
74 | |||
75 | |||
76 | uInt longest_match_asm7fff( | ||
77 | deflate_state *s, | ||
78 | IPos cur_match); /* current match */ | ||
79 | |||
80 | uInt longest_match( | ||
81 | deflate_state *s, | ||
82 | IPos cur_match) /* current match */ | ||
83 | { | ||
84 | if (s->w_mask == 0x7fff) | ||
85 | return longest_match_asm7fff(s,cur_match); | ||
86 | return longest_match_c(s,cur_match); | ||
87 | } | ||
88 | |||
89 | |||
90 | |||
91 | uInt longest_match_c(s, cur_match) | ||
92 | deflate_state *s; | ||
93 | IPos cur_match; /* current match */ | ||
94 | { | ||
95 | unsigned chain_length = s->max_chain_length;/* max hash chain length */ | ||
96 | register Bytef *scan = s->window + s->strstart; /* current string */ | ||
97 | register Bytef *match; /* matched string */ | ||
98 | register int len; /* length of current match */ | ||
99 | int best_len = s->prev_length; /* best match length so far */ | ||
100 | int nice_match = s->nice_match; /* stop if match long enough */ | ||
101 | IPos limit = s->strstart > (IPos)MAX_DIST(s) ? | ||
102 | s->strstart - (IPos)MAX_DIST(s) : NIL; | ||
103 | /* Stop when cur_match becomes <= limit. To simplify the code, | ||
104 | * we prevent matches with the string of window index 0. | ||
105 | */ | ||
106 | Posf *prev = s->prev; | ||
107 | uInt wmask = s->w_mask; | ||
108 | |||
109 | #ifdef UNALIGNED_OK | ||
110 | /* Compare two bytes at a time. Note: this is not always beneficial. | ||
111 | * Try with and without -DUNALIGNED_OK to check. | ||
112 | */ | ||
113 | register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; | ||
114 | register ush scan_start = *(ushf*)scan; | ||
115 | register ush scan_end = *(ushf*)(scan+best_len-1); | ||
116 | #else | ||
117 | register Bytef *strend = s->window + s->strstart + MAX_MATCH; | ||
118 | register Byte scan_end1 = scan[best_len-1]; | ||
119 | register Byte scan_end = scan[best_len]; | ||
120 | #endif | ||
121 | |||
122 | /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. | ||
123 | * It is easy to get rid of this optimization if necessary. | ||
124 | */ | ||
125 | Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); | ||
126 | |||
127 | /* Do not waste too much time if we already have a good match: */ | ||
128 | if (s->prev_length >= s->good_match) { | ||
129 | chain_length >>= 2; | ||
130 | } | ||
131 | /* Do not look for matches beyond the end of the input. This is necessary | ||
132 | * to make deflate deterministic. | ||
133 | */ | ||
134 | if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; | ||
135 | |||
136 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); | ||
137 | |||
138 | do { | ||
139 | Assert(cur_match < s->strstart, "no future"); | ||
140 | match = s->window + cur_match; | ||
141 | |||
142 | /* Skip to next match if the match length cannot increase | ||
143 | * or if the match length is less than 2: | ||
144 | */ | ||
145 | #if (defined(UNALIGNED_OK) && MAX_MATCH == 258) | ||
146 | /* This code assumes sizeof(unsigned short) == 2. Do not use | ||
147 | * UNALIGNED_OK if your compiler uses a different size. | ||
148 | */ | ||
149 | if (*(ushf*)(match+best_len-1) != scan_end || | ||
150 | *(ushf*)match != scan_start) continue; | ||
151 | |||
152 | /* It is not necessary to compare scan[2] and match[2] since they are | ||
153 | * always equal when the other bytes match, given that the hash keys | ||
154 | * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at | ||
155 | * strstart+3, +5, ... up to strstart+257. We check for insufficient | ||
156 | * lookahead only every 4th comparison; the 128th check will be made | ||
157 | * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is | ||
158 | * necessary to put more guard bytes at the end of the window, or | ||
159 | * to check more often for insufficient lookahead. | ||
160 | */ | ||
161 | Assert(scan[2] == match[2], "scan[2]?"); | ||
162 | scan++, match++; | ||
163 | do { | ||
164 | } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && | ||
165 | *(ushf*)(scan+=2) == *(ushf*)(match+=2) && | ||
166 | *(ushf*)(scan+=2) == *(ushf*)(match+=2) && | ||
167 | *(ushf*)(scan+=2) == *(ushf*)(match+=2) && | ||
168 | scan < strend); | ||
169 | /* The funny "do {}" generates better code on most compilers */ | ||
170 | |||
171 | /* Here, scan <= window+strstart+257 */ | ||
172 | Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | ||
173 | if (*scan == *match) scan++; | ||
174 | |||
175 | len = (MAX_MATCH - 1) - (int)(strend-scan); | ||
176 | scan = strend - (MAX_MATCH-1); | ||
177 | |||
178 | #else /* UNALIGNED_OK */ | ||
179 | |||
180 | if (match[best_len] != scan_end || | ||
181 | match[best_len-1] != scan_end1 || | ||
182 | *match != *scan || | ||
183 | *++match != scan[1]) continue; | ||
184 | |||
185 | /* The check at best_len-1 can be removed because it will be made | ||
186 | * again later. (This heuristic is not always a win.) | ||
187 | * It is not necessary to compare scan[2] and match[2] since they | ||
188 | * are always equal when the other bytes match, given that | ||
189 | * the hash keys are equal and that HASH_BITS >= 8. | ||
190 | */ | ||
191 | scan += 2, match++; | ||
192 | Assert(*scan == *match, "match[2]?"); | ||
193 | |||
194 | /* We check for insufficient lookahead only every 8th comparison; | ||
195 | * the 256th check will be made at strstart+258. | ||
196 | */ | ||
197 | do { | ||
198 | } while (*++scan == *++match && *++scan == *++match && | ||
199 | *++scan == *++match && *++scan == *++match && | ||
200 | *++scan == *++match && *++scan == *++match && | ||
201 | *++scan == *++match && *++scan == *++match && | ||
202 | scan < strend); | ||
203 | |||
204 | Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | ||
205 | |||
206 | len = MAX_MATCH - (int)(strend - scan); | ||
207 | scan = strend - MAX_MATCH; | ||
208 | |||
209 | #endif /* UNALIGNED_OK */ | ||
210 | |||
211 | if (len > best_len) { | ||
212 | s->match_start = cur_match; | ||
213 | best_len = len; | ||
214 | if (len >= nice_match) break; | ||
215 | #ifdef UNALIGNED_OK | ||
216 | scan_end = *(ushf*)(scan+best_len-1); | ||
217 | #else | ||
218 | scan_end1 = scan[best_len-1]; | ||
219 | scan_end = scan[best_len]; | ||
220 | #endif | ||
221 | } | ||
222 | } while ((cur_match = prev[cur_match & wmask]) > limit | ||
223 | && --chain_length != 0); | ||
224 | |||
225 | if ((uInt)best_len <= s->lookahead) return best_len; | ||
226 | return s->lookahead; | ||
227 | } | ||
228 | |||
229 | #endif /* ASMV */ | ||
diff --git a/contrib/asm386/mkgvmt32.bat b/contrib/asm386/mkgvmt32.bat new file mode 100644 index 0000000..6c5ffd7 --- /dev/null +++ b/contrib/asm386/mkgvmt32.bat | |||
@@ -0,0 +1 @@ | |||
c:\masm611\bin\ml /coff /Zi /c /Flgvmat32.lst gvmat32.asm | |||
diff --git a/contrib/asm386/zlibvc.mak b/contrib/asm386/zlibvc.mak new file mode 100644 index 0000000..ae3d14b --- /dev/null +++ b/contrib/asm386/zlibvc.mak | |||
@@ -0,0 +1,781 @@ | |||
1 | # Microsoft Developer Studio Generated NMAKE File, Format Version 4.20 | ||
2 | # ** DO NOT EDIT ** | ||
3 | |||
4 | # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 | ||
5 | |||
6 | !IF "$(CFG)" == "" | ||
7 | CFG=zlibvc - Win32 Debug | ||
8 | !MESSAGE No configuration specified. Defaulting to zlibvc - Win32 Debug. | ||
9 | !ENDIF | ||
10 | |||
11 | !IF "$(CFG)" != "zlibvc - Win32 Release" && "$(CFG)" != "zlibvc - Win32 Debug" | ||
12 | !MESSAGE Invalid configuration "$(CFG)" specified. | ||
13 | !MESSAGE You can specify a configuration when running NMAKE on this makefile | ||
14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
15 | !MESSAGE | ||
16 | !MESSAGE NMAKE /f "zlibvc.mak" CFG="zlibvc - Win32 Debug" | ||
17 | !MESSAGE | ||
18 | !MESSAGE Possible choices for configuration are: | ||
19 | !MESSAGE | ||
20 | !MESSAGE "zlibvc - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") | ||
21 | !MESSAGE "zlibvc - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") | ||
22 | !MESSAGE | ||
23 | !ERROR An invalid configuration is specified. | ||
24 | !ENDIF | ||
25 | |||
26 | !IF "$(OS)" == "Windows_NT" | ||
27 | NULL= | ||
28 | !ELSE | ||
29 | NULL=nul | ||
30 | !ENDIF | ||
31 | ################################################################################ | ||
32 | # Begin Project | ||
33 | # PROP Target_Last_Scanned "zlibvc - Win32 Debug" | ||
34 | CPP=cl.exe | ||
35 | RSC=rc.exe | ||
36 | MTL=mktyplib.exe | ||
37 | |||
38 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
39 | |||
40 | # PROP BASE Use_MFC 0 | ||
41 | # PROP BASE Use_Debug_Libraries 0 | ||
42 | # PROP BASE Output_Dir "Release" | ||
43 | # PROP BASE Intermediate_Dir "Release" | ||
44 | # PROP BASE Target_Dir "" | ||
45 | # PROP Use_MFC 0 | ||
46 | # PROP Use_Debug_Libraries 0 | ||
47 | # PROP Output_Dir "Release" | ||
48 | # PROP Intermediate_Dir "Release" | ||
49 | # PROP Target_Dir "" | ||
50 | OUTDIR=.\Release | ||
51 | INTDIR=.\Release | ||
52 | |||
53 | ALL : "$(OUTDIR)\zlib.dll" "$(OUTDIR)\zlibvc.bsc" | ||
54 | |||
55 | CLEAN : | ||
56 | -@erase "$(INTDIR)\adler32.obj" | ||
57 | -@erase "$(INTDIR)\adler32.sbr" | ||
58 | -@erase "$(INTDIR)\compress.obj" | ||
59 | -@erase "$(INTDIR)\compress.sbr" | ||
60 | -@erase "$(INTDIR)\crc32.obj" | ||
61 | -@erase "$(INTDIR)\crc32.sbr" | ||
62 | -@erase "$(INTDIR)\deflate.obj" | ||
63 | -@erase "$(INTDIR)\deflate.sbr" | ||
64 | -@erase "$(INTDIR)\gvmat32c.obj" | ||
65 | -@erase "$(INTDIR)\gvmat32c.sbr" | ||
66 | -@erase "$(INTDIR)\gzio.obj" | ||
67 | -@erase "$(INTDIR)\gzio.sbr" | ||
68 | -@erase "$(INTDIR)\infblock.obj" | ||
69 | -@erase "$(INTDIR)\infblock.sbr" | ||
70 | -@erase "$(INTDIR)\infcodes.obj" | ||
71 | -@erase "$(INTDIR)\infcodes.sbr" | ||
72 | -@erase "$(INTDIR)\inffast.obj" | ||
73 | -@erase "$(INTDIR)\inffast.sbr" | ||
74 | -@erase "$(INTDIR)\inflate.obj" | ||
75 | -@erase "$(INTDIR)\inflate.sbr" | ||
76 | -@erase "$(INTDIR)\inftrees.obj" | ||
77 | -@erase "$(INTDIR)\inftrees.sbr" | ||
78 | -@erase "$(INTDIR)\infutil.obj" | ||
79 | -@erase "$(INTDIR)\infutil.sbr" | ||
80 | -@erase "$(INTDIR)\trees.obj" | ||
81 | -@erase "$(INTDIR)\trees.sbr" | ||
82 | -@erase "$(INTDIR)\uncompr.obj" | ||
83 | -@erase "$(INTDIR)\uncompr.sbr" | ||
84 | -@erase "$(INTDIR)\zlib.res" | ||
85 | -@erase "$(INTDIR)\zutil.obj" | ||
86 | -@erase "$(INTDIR)\zutil.sbr" | ||
87 | -@erase "$(OUTDIR)\zlib.dll" | ||
88 | -@erase "$(OUTDIR)\zlib.exp" | ||
89 | -@erase "$(OUTDIR)\zlib.lib" | ||
90 | -@erase "$(OUTDIR)\zlib.map" | ||
91 | -@erase "$(OUTDIR)\zlibvc.bsc" | ||
92 | |||
93 | "$(OUTDIR)" : | ||
94 | if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" | ||
95 | |||
96 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c | ||
97 | # ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D fdopen=_fdopen /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "ASMV" /FR /YX /c | ||
98 | CPP_PROJ=/nologo /MT /W3 /GX /O2 /D "NDEBUG" /D fdopen=_fdopen /D "WIN32" /D\ | ||
99 | "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "ASMV"\ | ||
100 | /FR"$(INTDIR)/" /Fp"$(INTDIR)/zlibvc.pch" /YX /Fo"$(INTDIR)/" /c | ||
101 | CPP_OBJS=.\Release/ | ||
102 | CPP_SBRS=.\Release/ | ||
103 | # ADD BASE MTL /nologo /D "NDEBUG" /win32 | ||
104 | # ADD MTL /nologo /D "NDEBUG" /win32 | ||
105 | MTL_PROJ=/nologo /D "NDEBUG" /win32 | ||
106 | # ADD BASE RSC /l 0x40c /d "NDEBUG" | ||
107 | # ADD RSC /l 0x40c /d "NDEBUG" | ||
108 | RSC_PROJ=/l 0x40c /fo"$(INTDIR)/zlib.res" /d "NDEBUG" | ||
109 | BSC32=bscmake.exe | ||
110 | # ADD BASE BSC32 /nologo | ||
111 | # ADD BSC32 /nologo | ||
112 | BSC32_FLAGS=/nologo /o"$(OUTDIR)/zlibvc.bsc" | ||
113 | BSC32_SBRS= \ | ||
114 | "$(INTDIR)\adler32.sbr" \ | ||
115 | "$(INTDIR)\compress.sbr" \ | ||
116 | "$(INTDIR)\crc32.sbr" \ | ||
117 | "$(INTDIR)\deflate.sbr" \ | ||
118 | "$(INTDIR)\gvmat32c.sbr" \ | ||
119 | "$(INTDIR)\gzio.sbr" \ | ||
120 | "$(INTDIR)\infblock.sbr" \ | ||
121 | "$(INTDIR)\infcodes.sbr" \ | ||
122 | "$(INTDIR)\inffast.sbr" \ | ||
123 | "$(INTDIR)\inflate.sbr" \ | ||
124 | "$(INTDIR)\inftrees.sbr" \ | ||
125 | "$(INTDIR)\infutil.sbr" \ | ||
126 | "$(INTDIR)\trees.sbr" \ | ||
127 | "$(INTDIR)\uncompr.sbr" \ | ||
128 | "$(INTDIR)\zutil.sbr" | ||
129 | |||
130 | "$(OUTDIR)\zlibvc.bsc" : "$(OUTDIR)" $(BSC32_SBRS) | ||
131 | $(BSC32) @<< | ||
132 | $(BSC32_FLAGS) $(BSC32_SBRS) | ||
133 | << | ||
134 | |||
135 | LINK32=link.exe | ||
136 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 | ||
137 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:"Release/zlib.dll" | ||
138 | LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\ | ||
139 | advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo\ | ||
140 | /subsystem:windows /dll /incremental:no /pdb:"$(OUTDIR)/zlib.pdb"\ | ||
141 | /map:"$(INTDIR)/zlib.map" /machine:I386 /nodefaultlib /def:".\zlib.def"\ | ||
142 | /out:"$(OUTDIR)/zlib.dll" /implib:"$(OUTDIR)/zlib.lib" | ||
143 | DEF_FILE= \ | ||
144 | ".\zlib.def" | ||
145 | LINK32_OBJS= \ | ||
146 | "$(INTDIR)\adler32.obj" \ | ||
147 | "$(INTDIR)\compress.obj" \ | ||
148 | "$(INTDIR)\crc32.obj" \ | ||
149 | "$(INTDIR)\deflate.obj" \ | ||
150 | "$(INTDIR)\gvmat32c.obj" \ | ||
151 | "$(INTDIR)\gzio.obj" \ | ||
152 | "$(INTDIR)\infblock.obj" \ | ||
153 | "$(INTDIR)\infcodes.obj" \ | ||
154 | "$(INTDIR)\inffast.obj" \ | ||
155 | "$(INTDIR)\inflate.obj" \ | ||
156 | "$(INTDIR)\inftrees.obj" \ | ||
157 | "$(INTDIR)\infutil.obj" \ | ||
158 | "$(INTDIR)\trees.obj" \ | ||
159 | "$(INTDIR)\uncompr.obj" \ | ||
160 | "$(INTDIR)\zlib.res" \ | ||
161 | "$(INTDIR)\zutil.obj" \ | ||
162 | ".\GVMAT32.obj" | ||
163 | |||
164 | "$(OUTDIR)\zlib.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) | ||
165 | $(LINK32) @<< | ||
166 | $(LINK32_FLAGS) $(LINK32_OBJS) | ||
167 | << | ||
168 | |||
169 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
170 | |||
171 | # PROP BASE Use_MFC 0 | ||
172 | # PROP BASE Use_Debug_Libraries 1 | ||
173 | # PROP BASE Output_Dir "Debug" | ||
174 | # PROP BASE Intermediate_Dir "Debug" | ||
175 | # PROP BASE Target_Dir "" | ||
176 | # PROP Use_MFC 0 | ||
177 | # PROP Use_Debug_Libraries 1 | ||
178 | # PROP Output_Dir "Debug" | ||
179 | # PROP Intermediate_Dir "Debug" | ||
180 | # PROP Target_Dir "" | ||
181 | OUTDIR=.\Debug | ||
182 | INTDIR=.\Debug | ||
183 | |||
184 | ALL : "$(OUTDIR)\zlib.dll" | ||
185 | |||
186 | CLEAN : | ||
187 | -@erase "$(INTDIR)\adler32.obj" | ||
188 | -@erase "$(INTDIR)\compress.obj" | ||
189 | -@erase "$(INTDIR)\crc32.obj" | ||
190 | -@erase "$(INTDIR)\deflate.obj" | ||
191 | -@erase "$(INTDIR)\gvmat32c.obj" | ||
192 | -@erase "$(INTDIR)\gzio.obj" | ||
193 | -@erase "$(INTDIR)\infblock.obj" | ||
194 | -@erase "$(INTDIR)\infcodes.obj" | ||
195 | -@erase "$(INTDIR)\inffast.obj" | ||
196 | -@erase "$(INTDIR)\inflate.obj" | ||
197 | -@erase "$(INTDIR)\inftrees.obj" | ||
198 | -@erase "$(INTDIR)\infutil.obj" | ||
199 | -@erase "$(INTDIR)\trees.obj" | ||
200 | -@erase "$(INTDIR)\uncompr.obj" | ||
201 | -@erase "$(INTDIR)\vc40.idb" | ||
202 | -@erase "$(INTDIR)\vc40.pdb" | ||
203 | -@erase "$(INTDIR)\zlib.res" | ||
204 | -@erase "$(INTDIR)\zutil.obj" | ||
205 | -@erase "$(OUTDIR)\zlib.dll" | ||
206 | -@erase "$(OUTDIR)\zlib.exp" | ||
207 | -@erase "$(OUTDIR)\zlib.ilk" | ||
208 | -@erase "$(OUTDIR)\zlib.lib" | ||
209 | -@erase "$(OUTDIR)\zlib.pdb" | ||
210 | |||
211 | "$(OUTDIR)" : | ||
212 | if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" | ||
213 | |||
214 | # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c | ||
215 | # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /YX /c | ||
216 | CPP_PROJ=/nologo /MTd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS"\ | ||
217 | /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL"\ | ||
218 | /Fp"$(INTDIR)/zlibvc.pch" /YX /Fo"$(INTDIR)/" /Fd"$(INTDIR)/" /c | ||
219 | CPP_OBJS=.\Debug/ | ||
220 | CPP_SBRS=.\. | ||
221 | # ADD BASE MTL /nologo /D "_DEBUG" /win32 | ||
222 | # ADD MTL /nologo /D "_DEBUG" /win32 | ||
223 | MTL_PROJ=/nologo /D "_DEBUG" /win32 | ||
224 | # ADD BASE RSC /l 0x40c /d "_DEBUG" | ||
225 | # ADD RSC /l 0x40c /d "_DEBUG" | ||
226 | RSC_PROJ=/l 0x40c /fo"$(INTDIR)/zlib.res" /d "_DEBUG" | ||
227 | BSC32=bscmake.exe | ||
228 | # ADD BASE BSC32 /nologo | ||
229 | # ADD BSC32 /nologo | ||
230 | BSC32_FLAGS=/nologo /o"$(OUTDIR)/zlibvc.bsc" | ||
231 | BSC32_SBRS= \ | ||
232 | |||
233 | LINK32=link.exe | ||
234 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 | ||
235 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug/zlib.dll" | ||
236 | LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\ | ||
237 | advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo\ | ||
238 | /subsystem:windows /dll /incremental:yes /pdb:"$(OUTDIR)/zlib.pdb" /debug\ | ||
239 | /machine:I386 /def:".\zlib.def" /out:"$(OUTDIR)/zlib.dll"\ | ||
240 | /implib:"$(OUTDIR)/zlib.lib" | ||
241 | DEF_FILE= \ | ||
242 | ".\zlib.def" | ||
243 | LINK32_OBJS= \ | ||
244 | "$(INTDIR)\adler32.obj" \ | ||
245 | "$(INTDIR)\compress.obj" \ | ||
246 | "$(INTDIR)\crc32.obj" \ | ||
247 | "$(INTDIR)\deflate.obj" \ | ||
248 | "$(INTDIR)\gvmat32c.obj" \ | ||
249 | "$(INTDIR)\gzio.obj" \ | ||
250 | "$(INTDIR)\infblock.obj" \ | ||
251 | "$(INTDIR)\infcodes.obj" \ | ||
252 | "$(INTDIR)\inffast.obj" \ | ||
253 | "$(INTDIR)\inflate.obj" \ | ||
254 | "$(INTDIR)\inftrees.obj" \ | ||
255 | "$(INTDIR)\infutil.obj" \ | ||
256 | "$(INTDIR)\trees.obj" \ | ||
257 | "$(INTDIR)\uncompr.obj" \ | ||
258 | "$(INTDIR)\zlib.res" \ | ||
259 | "$(INTDIR)\zutil.obj" \ | ||
260 | ".\GVMAT32.obj" | ||
261 | |||
262 | "$(OUTDIR)\zlib.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) | ||
263 | $(LINK32) @<< | ||
264 | $(LINK32_FLAGS) $(LINK32_OBJS) | ||
265 | << | ||
266 | |||
267 | !ENDIF | ||
268 | |||
269 | .c{$(CPP_OBJS)}.obj: | ||
270 | $(CPP) $(CPP_PROJ) $< | ||
271 | |||
272 | .cpp{$(CPP_OBJS)}.obj: | ||
273 | $(CPP) $(CPP_PROJ) $< | ||
274 | |||
275 | .cxx{$(CPP_OBJS)}.obj: | ||
276 | $(CPP) $(CPP_PROJ) $< | ||
277 | |||
278 | .c{$(CPP_SBRS)}.sbr: | ||
279 | $(CPP) $(CPP_PROJ) $< | ||
280 | |||
281 | .cpp{$(CPP_SBRS)}.sbr: | ||
282 | $(CPP) $(CPP_PROJ) $< | ||
283 | |||
284 | .cxx{$(CPP_SBRS)}.sbr: | ||
285 | $(CPP) $(CPP_PROJ) $< | ||
286 | |||
287 | ################################################################################ | ||
288 | # Begin Target | ||
289 | |||
290 | # Name "zlibvc - Win32 Release" | ||
291 | # Name "zlibvc - Win32 Debug" | ||
292 | |||
293 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
294 | |||
295 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
296 | |||
297 | !ENDIF | ||
298 | |||
299 | ################################################################################ | ||
300 | # Begin Source File | ||
301 | |||
302 | SOURCE=.\adler32.c | ||
303 | DEP_CPP_ADLER=\ | ||
304 | ".\zconf.h"\ | ||
305 | ".\zlib.h"\ | ||
306 | |||
307 | |||
308 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
309 | |||
310 | |||
311 | "$(INTDIR)\adler32.obj" : $(SOURCE) $(DEP_CPP_ADLER) "$(INTDIR)" | ||
312 | |||
313 | "$(INTDIR)\adler32.sbr" : $(SOURCE) $(DEP_CPP_ADLER) "$(INTDIR)" | ||
314 | |||
315 | |||
316 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
317 | |||
318 | |||
319 | "$(INTDIR)\adler32.obj" : $(SOURCE) $(DEP_CPP_ADLER) "$(INTDIR)" | ||
320 | |||
321 | |||
322 | !ENDIF | ||
323 | |||
324 | # End Source File | ||
325 | ################################################################################ | ||
326 | # Begin Source File | ||
327 | |||
328 | SOURCE=.\compress.c | ||
329 | DEP_CPP_COMPR=\ | ||
330 | ".\zconf.h"\ | ||
331 | ".\zlib.h"\ | ||
332 | |||
333 | |||
334 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
335 | |||
336 | |||
337 | "$(INTDIR)\compress.obj" : $(SOURCE) $(DEP_CPP_COMPR) "$(INTDIR)" | ||
338 | |||
339 | "$(INTDIR)\compress.sbr" : $(SOURCE) $(DEP_CPP_COMPR) "$(INTDIR)" | ||
340 | |||
341 | |||
342 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
343 | |||
344 | |||
345 | "$(INTDIR)\compress.obj" : $(SOURCE) $(DEP_CPP_COMPR) "$(INTDIR)" | ||
346 | |||
347 | |||
348 | !ENDIF | ||
349 | |||
350 | # End Source File | ||
351 | ################################################################################ | ||
352 | # Begin Source File | ||
353 | |||
354 | SOURCE=.\crc32.c | ||
355 | DEP_CPP_CRC32=\ | ||
356 | ".\zconf.h"\ | ||
357 | ".\zlib.h"\ | ||
358 | |||
359 | |||
360 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
361 | |||
362 | |||
363 | "$(INTDIR)\crc32.obj" : $(SOURCE) $(DEP_CPP_CRC32) "$(INTDIR)" | ||
364 | |||
365 | "$(INTDIR)\crc32.sbr" : $(SOURCE) $(DEP_CPP_CRC32) "$(INTDIR)" | ||
366 | |||
367 | |||
368 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
369 | |||
370 | |||
371 | "$(INTDIR)\crc32.obj" : $(SOURCE) $(DEP_CPP_CRC32) "$(INTDIR)" | ||
372 | |||
373 | |||
374 | !ENDIF | ||
375 | |||
376 | # End Source File | ||
377 | ################################################################################ | ||
378 | # Begin Source File | ||
379 | |||
380 | SOURCE=.\deflate.c | ||
381 | |||
382 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
383 | |||
384 | DEP_CPP_DEFLA=\ | ||
385 | ".\deflate.h"\ | ||
386 | ".\zconf.h"\ | ||
387 | ".\zlib.h"\ | ||
388 | ".\zutil.h"\ | ||
389 | |||
390 | |||
391 | "$(INTDIR)\deflate.obj" : $(SOURCE) $(DEP_CPP_DEFLA) "$(INTDIR)" | ||
392 | |||
393 | "$(INTDIR)\deflate.sbr" : $(SOURCE) $(DEP_CPP_DEFLA) "$(INTDIR)" | ||
394 | |||
395 | |||
396 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
397 | |||
398 | DEP_CPP_DEFLA=\ | ||
399 | ".\deflate.h"\ | ||
400 | ".\zconf.h"\ | ||
401 | ".\zlib.h"\ | ||
402 | ".\zutil.h"\ | ||
403 | |||
404 | NODEP_CPP_DEFLA=\ | ||
405 | ".\local"\ | ||
406 | |||
407 | |||
408 | "$(INTDIR)\deflate.obj" : $(SOURCE) $(DEP_CPP_DEFLA) "$(INTDIR)" | ||
409 | |||
410 | |||
411 | !ENDIF | ||
412 | |||
413 | # End Source File | ||
414 | ################################################################################ | ||
415 | # Begin Source File | ||
416 | |||
417 | SOURCE=.\gzio.c | ||
418 | DEP_CPP_GZIO_=\ | ||
419 | ".\zconf.h"\ | ||
420 | ".\zlib.h"\ | ||
421 | ".\zutil.h"\ | ||
422 | |||
423 | |||
424 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
425 | |||
426 | |||
427 | "$(INTDIR)\gzio.obj" : $(SOURCE) $(DEP_CPP_GZIO_) "$(INTDIR)" | ||
428 | |||
429 | "$(INTDIR)\gzio.sbr" : $(SOURCE) $(DEP_CPP_GZIO_) "$(INTDIR)" | ||
430 | |||
431 | |||
432 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
433 | |||
434 | |||
435 | "$(INTDIR)\gzio.obj" : $(SOURCE) $(DEP_CPP_GZIO_) "$(INTDIR)" | ||
436 | |||
437 | |||
438 | !ENDIF | ||
439 | |||
440 | # End Source File | ||
441 | ################################################################################ | ||
442 | # Begin Source File | ||
443 | |||
444 | SOURCE=.\infblock.c | ||
445 | DEP_CPP_INFBL=\ | ||
446 | ".\infblock.h"\ | ||
447 | ".\infcodes.h"\ | ||
448 | ".\inftrees.h"\ | ||
449 | ".\infutil.h"\ | ||
450 | ".\zconf.h"\ | ||
451 | ".\zlib.h"\ | ||
452 | ".\zutil.h"\ | ||
453 | |||
454 | |||
455 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
456 | |||
457 | |||
458 | "$(INTDIR)\infblock.obj" : $(SOURCE) $(DEP_CPP_INFBL) "$(INTDIR)" | ||
459 | |||
460 | "$(INTDIR)\infblock.sbr" : $(SOURCE) $(DEP_CPP_INFBL) "$(INTDIR)" | ||
461 | |||
462 | |||
463 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
464 | |||
465 | |||
466 | "$(INTDIR)\infblock.obj" : $(SOURCE) $(DEP_CPP_INFBL) "$(INTDIR)" | ||
467 | |||
468 | |||
469 | !ENDIF | ||
470 | |||
471 | # End Source File | ||
472 | ################################################################################ | ||
473 | # Begin Source File | ||
474 | |||
475 | SOURCE=.\infcodes.c | ||
476 | DEP_CPP_INFCO=\ | ||
477 | ".\infblock.h"\ | ||
478 | ".\infcodes.h"\ | ||
479 | ".\inffast.h"\ | ||
480 | ".\inftrees.h"\ | ||
481 | ".\infutil.h"\ | ||
482 | ".\zconf.h"\ | ||
483 | ".\zlib.h"\ | ||
484 | ".\zutil.h"\ | ||
485 | |||
486 | |||
487 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
488 | |||
489 | |||
490 | "$(INTDIR)\infcodes.obj" : $(SOURCE) $(DEP_CPP_INFCO) "$(INTDIR)" | ||
491 | |||
492 | "$(INTDIR)\infcodes.sbr" : $(SOURCE) $(DEP_CPP_INFCO) "$(INTDIR)" | ||
493 | |||
494 | |||
495 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
496 | |||
497 | |||
498 | "$(INTDIR)\infcodes.obj" : $(SOURCE) $(DEP_CPP_INFCO) "$(INTDIR)" | ||
499 | |||
500 | |||
501 | !ENDIF | ||
502 | |||
503 | # End Source File | ||
504 | ################################################################################ | ||
505 | # Begin Source File | ||
506 | |||
507 | SOURCE=.\inffast.c | ||
508 | DEP_CPP_INFFA=\ | ||
509 | ".\infblock.h"\ | ||
510 | ".\infcodes.h"\ | ||
511 | ".\inffast.h"\ | ||
512 | ".\inftrees.h"\ | ||
513 | ".\infutil.h"\ | ||
514 | ".\zconf.h"\ | ||
515 | ".\zlib.h"\ | ||
516 | ".\zutil.h"\ | ||
517 | |||
518 | |||
519 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
520 | |||
521 | |||
522 | "$(INTDIR)\inffast.obj" : $(SOURCE) $(DEP_CPP_INFFA) "$(INTDIR)" | ||
523 | |||
524 | "$(INTDIR)\inffast.sbr" : $(SOURCE) $(DEP_CPP_INFFA) "$(INTDIR)" | ||
525 | |||
526 | |||
527 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
528 | |||
529 | |||
530 | "$(INTDIR)\inffast.obj" : $(SOURCE) $(DEP_CPP_INFFA) "$(INTDIR)" | ||
531 | |||
532 | |||
533 | !ENDIF | ||
534 | |||
535 | # End Source File | ||
536 | ################################################################################ | ||
537 | # Begin Source File | ||
538 | |||
539 | SOURCE=.\inflate.c | ||
540 | DEP_CPP_INFLA=\ | ||
541 | ".\infblock.h"\ | ||
542 | ".\zconf.h"\ | ||
543 | ".\zlib.h"\ | ||
544 | ".\zutil.h"\ | ||
545 | |||
546 | |||
547 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
548 | |||
549 | |||
550 | "$(INTDIR)\inflate.obj" : $(SOURCE) $(DEP_CPP_INFLA) "$(INTDIR)" | ||
551 | |||
552 | "$(INTDIR)\inflate.sbr" : $(SOURCE) $(DEP_CPP_INFLA) "$(INTDIR)" | ||
553 | |||
554 | |||
555 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
556 | |||
557 | |||
558 | "$(INTDIR)\inflate.obj" : $(SOURCE) $(DEP_CPP_INFLA) "$(INTDIR)" | ||
559 | |||
560 | |||
561 | !ENDIF | ||
562 | |||
563 | # End Source File | ||
564 | ################################################################################ | ||
565 | # Begin Source File | ||
566 | |||
567 | SOURCE=.\inftrees.c | ||
568 | DEP_CPP_INFTR=\ | ||
569 | ".\inftrees.h"\ | ||
570 | ".\zconf.h"\ | ||
571 | ".\zlib.h"\ | ||
572 | ".\zutil.h"\ | ||
573 | |||
574 | |||
575 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
576 | |||
577 | |||
578 | "$(INTDIR)\inftrees.obj" : $(SOURCE) $(DEP_CPP_INFTR) "$(INTDIR)" | ||
579 | |||
580 | "$(INTDIR)\inftrees.sbr" : $(SOURCE) $(DEP_CPP_INFTR) "$(INTDIR)" | ||
581 | |||
582 | |||
583 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
584 | |||
585 | |||
586 | "$(INTDIR)\inftrees.obj" : $(SOURCE) $(DEP_CPP_INFTR) "$(INTDIR)" | ||
587 | |||
588 | |||
589 | !ENDIF | ||
590 | |||
591 | # End Source File | ||
592 | ################################################################################ | ||
593 | # Begin Source File | ||
594 | |||
595 | SOURCE=.\infutil.c | ||
596 | DEP_CPP_INFUT=\ | ||
597 | ".\infblock.h"\ | ||
598 | ".\infcodes.h"\ | ||
599 | ".\inftrees.h"\ | ||
600 | ".\infutil.h"\ | ||
601 | ".\zconf.h"\ | ||
602 | ".\zlib.h"\ | ||
603 | ".\zutil.h"\ | ||
604 | |||
605 | |||
606 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
607 | |||
608 | |||
609 | "$(INTDIR)\infutil.obj" : $(SOURCE) $(DEP_CPP_INFUT) "$(INTDIR)" | ||
610 | |||
611 | "$(INTDIR)\infutil.sbr" : $(SOURCE) $(DEP_CPP_INFUT) "$(INTDIR)" | ||
612 | |||
613 | |||
614 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
615 | |||
616 | |||
617 | "$(INTDIR)\infutil.obj" : $(SOURCE) $(DEP_CPP_INFUT) "$(INTDIR)" | ||
618 | |||
619 | |||
620 | !ENDIF | ||
621 | |||
622 | # End Source File | ||
623 | ################################################################################ | ||
624 | # Begin Source File | ||
625 | |||
626 | SOURCE=.\trees.c | ||
627 | DEP_CPP_TREES=\ | ||
628 | ".\deflate.h"\ | ||
629 | ".\zconf.h"\ | ||
630 | ".\zlib.h"\ | ||
631 | ".\zutil.h"\ | ||
632 | |||
633 | |||
634 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
635 | |||
636 | |||
637 | "$(INTDIR)\trees.obj" : $(SOURCE) $(DEP_CPP_TREES) "$(INTDIR)" | ||
638 | |||
639 | "$(INTDIR)\trees.sbr" : $(SOURCE) $(DEP_CPP_TREES) "$(INTDIR)" | ||
640 | |||
641 | |||
642 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
643 | |||
644 | |||
645 | "$(INTDIR)\trees.obj" : $(SOURCE) $(DEP_CPP_TREES) "$(INTDIR)" | ||
646 | |||
647 | |||
648 | !ENDIF | ||
649 | |||
650 | # End Source File | ||
651 | ################################################################################ | ||
652 | # Begin Source File | ||
653 | |||
654 | SOURCE=.\uncompr.c | ||
655 | |||
656 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
657 | |||
658 | DEP_CPP_UNCOM=\ | ||
659 | ".\zconf.h"\ | ||
660 | ".\zlib.h"\ | ||
661 | |||
662 | |||
663 | "$(INTDIR)\uncompr.obj" : $(SOURCE) $(DEP_CPP_UNCOM) "$(INTDIR)" | ||
664 | |||
665 | "$(INTDIR)\uncompr.sbr" : $(SOURCE) $(DEP_CPP_UNCOM) "$(INTDIR)" | ||
666 | |||
667 | |||
668 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
669 | |||
670 | DEP_CPP_UNCOM=\ | ||
671 | ".\zconf.h"\ | ||
672 | ".\zlib.h"\ | ||
673 | |||
674 | NODEP_CPP_UNCOM=\ | ||
675 | ".\uncompress"\ | ||
676 | |||
677 | |||
678 | "$(INTDIR)\uncompr.obj" : $(SOURCE) $(DEP_CPP_UNCOM) "$(INTDIR)" | ||
679 | |||
680 | |||
681 | !ENDIF | ||
682 | |||
683 | # End Source File | ||
684 | ################################################################################ | ||
685 | # Begin Source File | ||
686 | |||
687 | SOURCE=.\zutil.c | ||
688 | DEP_CPP_ZUTIL=\ | ||
689 | ".\zconf.h"\ | ||
690 | ".\zlib.h"\ | ||
691 | ".\zutil.h"\ | ||
692 | |||
693 | |||
694 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
695 | |||
696 | |||
697 | "$(INTDIR)\zutil.obj" : $(SOURCE) $(DEP_CPP_ZUTIL) "$(INTDIR)" | ||
698 | |||
699 | "$(INTDIR)\zutil.sbr" : $(SOURCE) $(DEP_CPP_ZUTIL) "$(INTDIR)" | ||
700 | |||
701 | |||
702 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
703 | |||
704 | |||
705 | "$(INTDIR)\zutil.obj" : $(SOURCE) $(DEP_CPP_ZUTIL) "$(INTDIR)" | ||
706 | |||
707 | |||
708 | !ENDIF | ||
709 | |||
710 | # End Source File | ||
711 | ################################################################################ | ||
712 | # Begin Source File | ||
713 | |||
714 | SOURCE=.\zlib.rc | ||
715 | |||
716 | "$(INTDIR)\zlib.res" : $(SOURCE) "$(INTDIR)" | ||
717 | $(RSC) $(RSC_PROJ) $(SOURCE) | ||
718 | |||
719 | |||
720 | # End Source File | ||
721 | ################################################################################ | ||
722 | # Begin Source File | ||
723 | |||
724 | SOURCE=.\zlib.def | ||
725 | |||
726 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
727 | |||
728 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
729 | |||
730 | !ENDIF | ||
731 | |||
732 | # End Source File | ||
733 | ################################################################################ | ||
734 | # Begin Source File | ||
735 | |||
736 | SOURCE=.\GVMAT32.obj | ||
737 | |||
738 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
739 | |||
740 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
741 | |||
742 | !ENDIF | ||
743 | |||
744 | # End Source File | ||
745 | ################################################################################ | ||
746 | # Begin Source File | ||
747 | |||
748 | SOURCE=.\gvmat32c.c | ||
749 | |||
750 | !IF "$(CFG)" == "zlibvc - Win32 Release" | ||
751 | |||
752 | DEP_CPP_GVMAT=\ | ||
753 | ".\deflate.h"\ | ||
754 | ".\zconf.h"\ | ||
755 | ".\zlib.h"\ | ||
756 | ".\zutil.h"\ | ||
757 | |||
758 | |||
759 | "$(INTDIR)\gvmat32c.obj" : $(SOURCE) $(DEP_CPP_GVMAT) "$(INTDIR)" | ||
760 | |||
761 | "$(INTDIR)\gvmat32c.sbr" : $(SOURCE) $(DEP_CPP_GVMAT) "$(INTDIR)" | ||
762 | |||
763 | |||
764 | !ELSEIF "$(CFG)" == "zlibvc - Win32 Debug" | ||
765 | |||
766 | DEP_CPP_GVMAT=\ | ||
767 | ".\deflate.h"\ | ||
768 | ".\zconf.h"\ | ||
769 | ".\zlib.h"\ | ||
770 | ".\zutil.h"\ | ||
771 | |||
772 | |||
773 | "$(INTDIR)\gvmat32c.obj" : $(SOURCE) $(DEP_CPP_GVMAT) "$(INTDIR)" | ||
774 | |||
775 | |||
776 | !ENDIF | ||
777 | |||
778 | # End Source File | ||
779 | # End Target | ||
780 | # End Project | ||
781 | ################################################################################ | ||
diff --git a/contrib/iostream/test.cpp b/contrib/iostream/test.cpp new file mode 100644 index 0000000..7d265b3 --- /dev/null +++ b/contrib/iostream/test.cpp | |||
@@ -0,0 +1,24 @@ | |||
1 | |||
2 | #include "zfstream.h" | ||
3 | |||
4 | int main() { | ||
5 | |||
6 | // Construct a stream object with this filebuffer. Anything sent | ||
7 | // to this stream will go to standard out. | ||
8 | gzofstream os( 1, ios::out ); | ||
9 | |||
10 | // This text is getting compressed and sent to stdout. | ||
11 | // To prove this, run 'test | zcat'. | ||
12 | os << "Hello, Mommy" << endl; | ||
13 | |||
14 | os << setcompressionlevel( Z_NO_COMPRESSION ); | ||
15 | os << "hello, hello, hi, ho!" << endl; | ||
16 | |||
17 | setcompressionlevel( os, Z_DEFAULT_COMPRESSION ) | ||
18 | << "I'm compressing again" << endl; | ||
19 | |||
20 | os.close(); | ||
21 | |||
22 | return 0; | ||
23 | |||
24 | } | ||
diff --git a/contrib/iostream/zfstream.cpp b/contrib/iostream/zfstream.cpp new file mode 100644 index 0000000..a690bbe --- /dev/null +++ b/contrib/iostream/zfstream.cpp | |||
@@ -0,0 +1,329 @@ | |||
1 | |||
2 | #include <memory.h> | ||
3 | #include "zfstream.h" | ||
4 | |||
5 | gzfilebuf::gzfilebuf() : | ||
6 | file(NULL), | ||
7 | mode(0), | ||
8 | own_file_descriptor(0) | ||
9 | { } | ||
10 | |||
11 | gzfilebuf::~gzfilebuf() { | ||
12 | |||
13 | sync(); | ||
14 | if ( own_file_descriptor ) | ||
15 | close(); | ||
16 | |||
17 | } | ||
18 | |||
19 | gzfilebuf *gzfilebuf::open( const char *name, | ||
20 | int io_mode ) { | ||
21 | |||
22 | if ( is_open() ) | ||
23 | return NULL; | ||
24 | |||
25 | char char_mode[10]; | ||
26 | char *p; | ||
27 | memset(char_mode,'\0',10); | ||
28 | p = char_mode; | ||
29 | |||
30 | if ( io_mode & ios::in ) { | ||
31 | mode = ios::in; | ||
32 | *p++ = 'r'; | ||
33 | } else if ( io_mode & ios::app ) { | ||
34 | mode = ios::app; | ||
35 | *p++ = 'a'; | ||
36 | } else { | ||
37 | mode = ios::out; | ||
38 | *p++ = 'w'; | ||
39 | } | ||
40 | |||
41 | if ( io_mode & ios::binary ) { | ||
42 | mode |= ios::binary; | ||
43 | *p++ = 'b'; | ||
44 | } | ||
45 | |||
46 | // Hard code the compression level | ||
47 | if ( io_mode & (ios::out|ios::app )) { | ||
48 | *p++ = '9'; | ||
49 | } | ||
50 | |||
51 | if ( (file = gzopen(name, char_mode)) == NULL ) | ||
52 | return NULL; | ||
53 | |||
54 | own_file_descriptor = 1; | ||
55 | |||
56 | return this; | ||
57 | |||
58 | } | ||
59 | |||
60 | gzfilebuf *gzfilebuf::attach( int file_descriptor, | ||
61 | int io_mode ) { | ||
62 | |||
63 | if ( is_open() ) | ||
64 | return NULL; | ||
65 | |||
66 | char char_mode[10]; | ||
67 | char *p; | ||
68 | memset(char_mode,'\0',10); | ||
69 | p = char_mode; | ||
70 | |||
71 | if ( io_mode & ios::in ) { | ||
72 | mode = ios::in; | ||
73 | *p++ = 'r'; | ||
74 | } else if ( io_mode & ios::app ) { | ||
75 | mode = ios::app; | ||
76 | *p++ = 'a'; | ||
77 | } else { | ||
78 | mode = ios::out; | ||
79 | *p++ = 'w'; | ||
80 | } | ||
81 | |||
82 | if ( io_mode & ios::binary ) { | ||
83 | mode |= ios::binary; | ||
84 | *p++ = 'b'; | ||
85 | } | ||
86 | |||
87 | // Hard code the compression level | ||
88 | if ( io_mode & (ios::out|ios::app )) { | ||
89 | *p++ = '9'; | ||
90 | } | ||
91 | |||
92 | if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) | ||
93 | return NULL; | ||
94 | |||
95 | own_file_descriptor = 0; | ||
96 | |||
97 | return this; | ||
98 | |||
99 | } | ||
100 | |||
101 | gzfilebuf *gzfilebuf::close() { | ||
102 | |||
103 | if ( is_open() ) { | ||
104 | |||
105 | sync(); | ||
106 | gzclose( file ); | ||
107 | file = NULL; | ||
108 | |||
109 | } | ||
110 | |||
111 | return this; | ||
112 | |||
113 | } | ||
114 | |||
115 | int gzfilebuf::setcompressionlevel( short comp_level ) { | ||
116 | |||
117 | return gzsetparams(file, comp_level, -2); | ||
118 | |||
119 | } | ||
120 | |||
121 | int gzfilebuf::setcompressionstrategy( short comp_strategy ) { | ||
122 | |||
123 | return gzsetparams(file, -2, comp_strategy); | ||
124 | |||
125 | } | ||
126 | |||
127 | |||
128 | streampos gzfilebuf::seekoff( streamoff off, ios::seek_dir dir, int which ) { | ||
129 | |||
130 | return streampos(EOF); | ||
131 | |||
132 | } | ||
133 | |||
134 | int gzfilebuf::underflow() { | ||
135 | |||
136 | // If the file hasn't been opened for reading, error. | ||
137 | if ( !is_open() || !(mode & ios::in) ) | ||
138 | return EOF; | ||
139 | |||
140 | // if a buffer doesn't exists, allocate one. | ||
141 | if ( !base() ) { | ||
142 | |||
143 | if ( (allocate()) == EOF ) | ||
144 | return EOF; | ||
145 | setp(0,0); | ||
146 | |||
147 | } else { | ||
148 | |||
149 | if ( in_avail() ) | ||
150 | return (unsigned char) *gptr(); | ||
151 | |||
152 | if ( out_waiting() ) { | ||
153 | if ( flushbuf() == EOF ) | ||
154 | return EOF; | ||
155 | } | ||
156 | |||
157 | } | ||
158 | |||
159 | // Attempt to fill the buffer. | ||
160 | |||
161 | int result = fillbuf(); | ||
162 | if ( result == EOF ) { | ||
163 | // disable get area | ||
164 | setg(0,0,0); | ||
165 | return EOF; | ||
166 | } | ||
167 | |||
168 | return (unsigned char) *gptr(); | ||
169 | |||
170 | } | ||
171 | |||
172 | int gzfilebuf::overflow( int c ) { | ||
173 | |||
174 | if ( !is_open() || !(mode & ios::out) ) | ||
175 | return EOF; | ||
176 | |||
177 | if ( !base() ) { | ||
178 | if ( allocate() == EOF ) | ||
179 | return EOF; | ||
180 | setg(0,0,0); | ||
181 | } else { | ||
182 | if (in_avail()) { | ||
183 | return EOF; | ||
184 | } | ||
185 | if (out_waiting()) { | ||
186 | if (flushbuf() == EOF) | ||
187 | return EOF; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | int bl = blen(); | ||
192 | setp( base(), base() + bl); | ||
193 | |||
194 | if ( c != EOF ) { | ||
195 | |||
196 | *pptr() = c; | ||
197 | pbump(1); | ||
198 | |||
199 | } | ||
200 | |||
201 | return 0; | ||
202 | |||
203 | } | ||
204 | |||
205 | int gzfilebuf::sync() { | ||
206 | |||
207 | if ( !is_open() ) | ||
208 | return EOF; | ||
209 | |||
210 | if ( out_waiting() ) | ||
211 | return flushbuf(); | ||
212 | |||
213 | return 0; | ||
214 | |||
215 | } | ||
216 | |||
217 | int gzfilebuf::flushbuf() { | ||
218 | |||
219 | int n; | ||
220 | char *q; | ||
221 | |||
222 | q = pbase(); | ||
223 | n = pptr() - q; | ||
224 | |||
225 | if ( gzwrite( file, q, n) < n ) | ||
226 | return EOF; | ||
227 | |||
228 | setp(0,0); | ||
229 | |||
230 | return 0; | ||
231 | |||
232 | } | ||
233 | |||
234 | int gzfilebuf::fillbuf() { | ||
235 | |||
236 | int required; | ||
237 | char *p; | ||
238 | |||
239 | p = base(); | ||
240 | |||
241 | required = blen(); | ||
242 | |||
243 | int t = gzread( file, p, required ); | ||
244 | |||
245 | if ( t <= 0) return EOF; | ||
246 | |||
247 | setg( base(), base(), base()+t); | ||
248 | |||
249 | return t; | ||
250 | |||
251 | } | ||
252 | |||
253 | gzfilestream_common::gzfilestream_common() : | ||
254 | ios( gzfilestream_common::rdbuf() ) | ||
255 | { } | ||
256 | |||
257 | gzfilestream_common::~gzfilestream_common() | ||
258 | { } | ||
259 | |||
260 | void gzfilestream_common::attach( int fd, int io_mode ) { | ||
261 | |||
262 | if ( !buffer.attach( fd, io_mode) ) | ||
263 | clear( ios::failbit | ios::badbit ); | ||
264 | else | ||
265 | clear(); | ||
266 | |||
267 | } | ||
268 | |||
269 | void gzfilestream_common::open( const char *name, int io_mode ) { | ||
270 | |||
271 | if ( !buffer.open( name, io_mode ) ) | ||
272 | clear( ios::failbit | ios::badbit ); | ||
273 | else | ||
274 | clear(); | ||
275 | |||
276 | } | ||
277 | |||
278 | void gzfilestream_common::close() { | ||
279 | |||
280 | if ( !buffer.close() ) | ||
281 | clear( ios::failbit | ios::badbit ); | ||
282 | |||
283 | } | ||
284 | |||
285 | gzfilebuf *gzfilestream_common::rdbuf() { | ||
286 | |||
287 | return &buffer; | ||
288 | |||
289 | } | ||
290 | |||
291 | gzifstream::gzifstream() : | ||
292 | ios( gzfilestream_common::rdbuf() ) | ||
293 | { | ||
294 | clear( ios::badbit ); | ||
295 | } | ||
296 | |||
297 | gzifstream::gzifstream( const char *name, int io_mode ) : | ||
298 | ios( gzfilestream_common::rdbuf() ) | ||
299 | { | ||
300 | gzfilestream_common::open( name, io_mode ); | ||
301 | } | ||
302 | |||
303 | gzifstream::gzifstream( int fd, int io_mode ) : | ||
304 | ios( gzfilestream_common::rdbuf() ) | ||
305 | { | ||
306 | gzfilestream_common::attach( fd, io_mode ); | ||
307 | } | ||
308 | |||
309 | gzifstream::~gzifstream() { } | ||
310 | |||
311 | gzofstream::gzofstream() : | ||
312 | ios( gzfilestream_common::rdbuf() ) | ||
313 | { | ||
314 | clear( ios::badbit ); | ||
315 | } | ||
316 | |||
317 | gzofstream::gzofstream( const char *name, int io_mode ) : | ||
318 | ios( gzfilestream_common::rdbuf() ) | ||
319 | { | ||
320 | gzfilestream_common::open( name, io_mode ); | ||
321 | } | ||
322 | |||
323 | gzofstream::gzofstream( int fd, int io_mode ) : | ||
324 | ios( gzfilestream_common::rdbuf() ) | ||
325 | { | ||
326 | gzfilestream_common::attach( fd, io_mode ); | ||
327 | } | ||
328 | |||
329 | gzofstream::~gzofstream() { } | ||
diff --git a/contrib/iostream/zfstream.h b/contrib/iostream/zfstream.h new file mode 100644 index 0000000..c87fa08 --- /dev/null +++ b/contrib/iostream/zfstream.h | |||
@@ -0,0 +1,142 @@ | |||
1 | |||
2 | #ifndef _zfstream_h | ||
3 | #define _zfstream_h | ||
4 | |||
5 | #include <fstream.h> | ||
6 | #include "zlib.h" | ||
7 | |||
8 | class gzfilebuf : public streambuf { | ||
9 | |||
10 | public: | ||
11 | |||
12 | gzfilebuf( ); | ||
13 | virtual ~gzfilebuf(); | ||
14 | |||
15 | gzfilebuf *open( const char *name, int io_mode ); | ||
16 | gzfilebuf *attach( int file_descriptor, int io_mode ); | ||
17 | gzfilebuf *close(); | ||
18 | |||
19 | int setcompressionlevel( short comp_level ); | ||
20 | int setcompressionstrategy( short comp_strategy ); | ||
21 | |||
22 | inline int is_open() const { return (file !=NULL); } | ||
23 | |||
24 | virtual streampos seekoff( streamoff, ios::seek_dir, int ); | ||
25 | |||
26 | virtual int sync(); | ||
27 | |||
28 | protected: | ||
29 | |||
30 | virtual int underflow(); | ||
31 | virtual int overflow( int = EOF ); | ||
32 | |||
33 | private: | ||
34 | |||
35 | gzFile file; | ||
36 | short mode; | ||
37 | short own_file_descriptor; | ||
38 | |||
39 | int flushbuf(); | ||
40 | int fillbuf(); | ||
41 | |||
42 | }; | ||
43 | |||
44 | class gzfilestream_common : virtual public ios { | ||
45 | |||
46 | friend class gzifstream; | ||
47 | friend class gzofstream; | ||
48 | friend gzofstream &setcompressionlevel( gzofstream &, int ); | ||
49 | friend gzofstream &setcompressionstrategy( gzofstream &, int ); | ||
50 | |||
51 | public: | ||
52 | virtual ~gzfilestream_common(); | ||
53 | |||
54 | void attach( int fd, int io_mode ); | ||
55 | void open( const char *name, int io_mode ); | ||
56 | void close(); | ||
57 | |||
58 | protected: | ||
59 | gzfilestream_common(); | ||
60 | |||
61 | private: | ||
62 | gzfilebuf *rdbuf(); | ||
63 | |||
64 | gzfilebuf buffer; | ||
65 | |||
66 | }; | ||
67 | |||
68 | class gzifstream : public gzfilestream_common, public istream { | ||
69 | |||
70 | public: | ||
71 | |||
72 | gzifstream(); | ||
73 | gzifstream( const char *name, int io_mode = ios::in ); | ||
74 | gzifstream( int fd, int io_mode = ios::in ); | ||
75 | |||
76 | virtual ~gzifstream(); | ||
77 | |||
78 | }; | ||
79 | |||
80 | class gzofstream : public gzfilestream_common, public ostream { | ||
81 | |||
82 | public: | ||
83 | |||
84 | gzofstream(); | ||
85 | gzofstream( const char *name, int io_mode = ios::out ); | ||
86 | gzofstream( int fd, int io_mode = ios::out ); | ||
87 | |||
88 | virtual ~gzofstream(); | ||
89 | |||
90 | }; | ||
91 | |||
92 | template<class T> class gzomanip { | ||
93 | friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &); | ||
94 | public: | ||
95 | gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { } | ||
96 | private: | ||
97 | gzofstream &(*func)(gzofstream &, T); | ||
98 | T val; | ||
99 | }; | ||
100 | |||
101 | template<class T> gzofstream &operator<<(gzofstream &s, | ||
102 | const gzomanip<T> &m) { | ||
103 | return (*m.func)(s, m.val); | ||
104 | |||
105 | } | ||
106 | |||
107 | inline gzofstream &setcompressionlevel( gzofstream &s, int l ) { | ||
108 | (s.rdbuf())->setcompressionlevel(l); | ||
109 | return s; | ||
110 | } | ||
111 | |||
112 | inline gzofstream &setcompressionstrategy( gzofstream &s, int l ) { | ||
113 | (s.rdbuf())->setcompressionstrategy(l); | ||
114 | return s; | ||
115 | } | ||
116 | |||
117 | inline gzomanip<int> setcompressionlevel(int l) | ||
118 | { | ||
119 | return gzomanip<int>(&setcompressionlevel,l); | ||
120 | } | ||
121 | |||
122 | inline gzomanip<int> setcompressionstrategy(int l) | ||
123 | { | ||
124 | return gzomanip<int>(&setcompressionstrategy,l); | ||
125 | } | ||
126 | |||
127 | #endif | ||
128 | |||
129 | |||
130 | |||
131 | |||
132 | |||
133 | |||
134 | |||
135 | |||
136 | |||
137 | |||
138 | |||
139 | |||
140 | |||
141 | |||
142 | |||
diff --git a/contrib/iostream2/zstream.h b/contrib/iostream2/zstream.h new file mode 100644 index 0000000..43d2332 --- /dev/null +++ b/contrib/iostream2/zstream.h | |||
@@ -0,0 +1,307 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Copyright (c) 1997 | ||
4 | * Christian Michelsen Research AS | ||
5 | * Advanced Computing | ||
6 | * Fantoftvegen 38, 5036 BERGEN, Norway | ||
7 | * http://www.cmr.no | ||
8 | * | ||
9 | * Permission to use, copy, modify, distribute and sell this software | ||
10 | * and its documentation for any purpose is hereby granted without fee, | ||
11 | * provided that the above copyright notice appear in all copies and | ||
12 | * that both that copyright notice and this permission notice appear | ||
13 | * in supporting documentation. Christian Michelsen Research AS makes no | ||
14 | * representations about the suitability of this software for any | ||
15 | * purpose. It is provided "as is" without express or implied warranty. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #ifndef ZSTREAM__H | ||
20 | #define ZSTREAM__H | ||
21 | |||
22 | /* | ||
23 | * zstream.h - C++ interface to the 'zlib' general purpose compression library | ||
24 | * $Id: zstream.h 1.1 1997-06-25 12:00:56+02 tyge Exp tyge $ | ||
25 | */ | ||
26 | |||
27 | #include <strstream.h> | ||
28 | #include <string.h> | ||
29 | #include <stdio.h> | ||
30 | #include "zlib.h" | ||
31 | |||
32 | #if defined(_WIN32) | ||
33 | # include <fcntl.h> | ||
34 | # include <io.h> | ||
35 | # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) | ||
36 | #else | ||
37 | # define SET_BINARY_MODE(file) | ||
38 | #endif | ||
39 | |||
40 | class zstringlen { | ||
41 | public: | ||
42 | zstringlen(class izstream&); | ||
43 | zstringlen(class ozstream&, const char*); | ||
44 | size_t value() const { return val.word; } | ||
45 | private: | ||
46 | struct Val { unsigned char byte; size_t word; } val; | ||
47 | }; | ||
48 | |||
49 | // ----------------------------- izstream ----------------------------- | ||
50 | |||
51 | class izstream | ||
52 | { | ||
53 | public: | ||
54 | izstream() : m_fp(0) {} | ||
55 | izstream(FILE* fp) : m_fp(0) { open(fp); } | ||
56 | izstream(const char* name) : m_fp(0) { open(name); } | ||
57 | ~izstream() { close(); } | ||
58 | |||
59 | /* Opens a gzip (.gz) file for reading. | ||
60 | * open() can be used to read a file which is not in gzip format; | ||
61 | * in this case read() will directly read from the file without | ||
62 | * decompression. errno can be checked to distinguish two error | ||
63 | * cases (if errno is zero, the zlib error is Z_MEM_ERROR). | ||
64 | */ | ||
65 | void open(const char* name) { | ||
66 | if (m_fp) close(); | ||
67 | m_fp = ::gzopen(name, "rb"); | ||
68 | } | ||
69 | |||
70 | void open(FILE* fp) { | ||
71 | SET_BINARY_MODE(fp); | ||
72 | if (m_fp) close(); | ||
73 | m_fp = ::gzdopen(fileno(fp), "rb"); | ||
74 | } | ||
75 | |||
76 | /* Flushes all pending input if necessary, closes the compressed file | ||
77 | * and deallocates all the (de)compression state. The return value is | ||
78 | * the zlib error number (see function error() below). | ||
79 | */ | ||
80 | int close() { | ||
81 | int r = ::gzclose(m_fp); | ||
82 | m_fp = 0; return r; | ||
83 | } | ||
84 | |||
85 | /* Binary read the given number of bytes from the compressed file. | ||
86 | */ | ||
87 | int read(void* buf, size_t len) { | ||
88 | return ::gzread(m_fp, buf, len); | ||
89 | } | ||
90 | |||
91 | /* Returns the error message for the last error which occurred on the | ||
92 | * given compressed file. errnum is set to zlib error number. If an | ||
93 | * error occurred in the file system and not in the compression library, | ||
94 | * errnum is set to Z_ERRNO and the application may consult errno | ||
95 | * to get the exact error code. | ||
96 | */ | ||
97 | const char* error(int* errnum) { | ||
98 | return ::gzerror(m_fp, errnum); | ||
99 | } | ||
100 | |||
101 | gzFile fp() { return m_fp; } | ||
102 | |||
103 | private: | ||
104 | gzFile m_fp; | ||
105 | }; | ||
106 | |||
107 | /* | ||
108 | * Binary read the given (array of) object(s) from the compressed file. | ||
109 | * If the input file was not in gzip format, read() copies the objects number | ||
110 | * of bytes into the buffer. | ||
111 | * returns the number of uncompressed bytes actually read | ||
112 | * (0 for end of file, -1 for error). | ||
113 | */ | ||
114 | template <class T, class Items> | ||
115 | inline int read(izstream& zs, T* x, Items items) { | ||
116 | return ::gzread(zs.fp(), x, items*sizeof(T)); | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * Binary input with the '>' operator. | ||
121 | */ | ||
122 | template <class T> | ||
123 | inline izstream& operator>(izstream& zs, T& x) { | ||
124 | ::gzread(zs.fp(), &x, sizeof(T)); | ||
125 | return zs; | ||
126 | } | ||
127 | |||
128 | |||
129 | inline zstringlen::zstringlen(izstream& zs) { | ||
130 | zs > val.byte; | ||
131 | if (val.byte == 255) zs > val.word; | ||
132 | else val.word = val.byte; | ||
133 | } | ||
134 | |||
135 | /* | ||
136 | * Read length of string + the string with the '>' operator. | ||
137 | */ | ||
138 | inline izstream& operator>(izstream& zs, char* x) { | ||
139 | zstringlen len(zs); | ||
140 | ::gzread(zs.fp(), x, len.value()); | ||
141 | x[len.value()] = '\0'; | ||
142 | return zs; | ||
143 | } | ||
144 | |||
145 | inline char* read_string(izstream& zs) { | ||
146 | zstringlen len(zs); | ||
147 | char* x = new char[len.value()+1]; | ||
148 | ::gzread(zs.fp(), x, len.value()); | ||
149 | x[len.value()] = '\0'; | ||
150 | return x; | ||
151 | } | ||
152 | |||
153 | // ----------------------------- ozstream ----------------------------- | ||
154 | |||
155 | class ozstream | ||
156 | { | ||
157 | public: | ||
158 | ozstream() : m_fp(0), m_os(0) { | ||
159 | } | ||
160 | ozstream(FILE* fp, int level = Z_DEFAULT_COMPRESSION) | ||
161 | : m_fp(0), m_os(0) { | ||
162 | open(fp, level); | ||
163 | } | ||
164 | ozstream(const char* name, int level = Z_DEFAULT_COMPRESSION) | ||
165 | : m_fp(0), m_os(0) { | ||
166 | open(name, level); | ||
167 | } | ||
168 | ~ozstream() { | ||
169 | close(); | ||
170 | } | ||
171 | |||
172 | /* Opens a gzip (.gz) file for writing. | ||
173 | * The compression level parameter should be in 0..9 | ||
174 | * errno can be checked to distinguish two error cases | ||
175 | * (if errno is zero, the zlib error is Z_MEM_ERROR). | ||
176 | */ | ||
177 | void open(const char* name, int level = Z_DEFAULT_COMPRESSION) { | ||
178 | char mode[4] = "wb\0"; | ||
179 | if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; | ||
180 | if (m_fp) close(); | ||
181 | m_fp = ::gzopen(name, mode); | ||
182 | } | ||
183 | |||
184 | /* open from a FILE pointer. | ||
185 | */ | ||
186 | void open(FILE* fp, int level = Z_DEFAULT_COMPRESSION) { | ||
187 | SET_BINARY_MODE(fp); | ||
188 | char mode[4] = "wb\0"; | ||
189 | if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; | ||
190 | if (m_fp) close(); | ||
191 | m_fp = ::gzdopen(fileno(fp), mode); | ||
192 | } | ||
193 | |||
194 | /* Flushes all pending output if necessary, closes the compressed file | ||
195 | * and deallocates all the (de)compression state. The return value is | ||
196 | * the zlib error number (see function error() below). | ||
197 | */ | ||
198 | int close() { | ||
199 | if (m_os) { | ||
200 | ::gzwrite(m_fp, m_os->str(), m_os->pcount()); | ||
201 | delete[] m_os->str(); delete m_os; m_os = 0; | ||
202 | } | ||
203 | int r = ::gzclose(m_fp); m_fp = 0; return r; | ||
204 | } | ||
205 | |||
206 | /* Binary write the given number of bytes into the compressed file. | ||
207 | */ | ||
208 | int write(const void* buf, size_t len) { | ||
209 | return ::gzwrite(m_fp, (voidp) buf, len); | ||
210 | } | ||
211 | |||
212 | /* Flushes all pending output into the compressed file. The parameter | ||
213 | * _flush is as in the deflate() function. The return value is the zlib | ||
214 | * error number (see function gzerror below). flush() returns Z_OK if | ||
215 | * the flush_ parameter is Z_FINISH and all output could be flushed. | ||
216 | * flush() should be called only when strictly necessary because it can | ||
217 | * degrade compression. | ||
218 | */ | ||
219 | int flush(int _flush) { | ||
220 | os_flush(); | ||
221 | return ::gzflush(m_fp, _flush); | ||
222 | } | ||
223 | |||
224 | /* Returns the error message for the last error which occurred on the | ||
225 | * given compressed file. errnum is set to zlib error number. If an | ||
226 | * error occurred in the file system and not in the compression library, | ||
227 | * errnum is set to Z_ERRNO and the application may consult errno | ||
228 | * to get the exact error code. | ||
229 | */ | ||
230 | const char* error(int* errnum) { | ||
231 | return ::gzerror(m_fp, errnum); | ||
232 | } | ||
233 | |||
234 | gzFile fp() { return m_fp; } | ||
235 | |||
236 | ostream& os() { | ||
237 | if (m_os == 0) m_os = new ostrstream; | ||
238 | return *m_os; | ||
239 | } | ||
240 | |||
241 | void os_flush() { | ||
242 | if (m_os && m_os->pcount()>0) { | ||
243 | ostrstream* oss = new ostrstream; | ||
244 | oss->fill(m_os->fill()); | ||
245 | oss->flags(m_os->flags()); | ||
246 | oss->precision(m_os->precision()); | ||
247 | oss->width(m_os->width()); | ||
248 | ::gzwrite(m_fp, m_os->str(), m_os->pcount()); | ||
249 | delete[] m_os->str(); delete m_os; m_os = oss; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | private: | ||
254 | gzFile m_fp; | ||
255 | ostrstream* m_os; | ||
256 | }; | ||
257 | |||
258 | /* | ||
259 | * Binary write the given (array of) object(s) into the compressed file. | ||
260 | * returns the number of uncompressed bytes actually written | ||
261 | * (0 in case of error). | ||
262 | */ | ||
263 | template <class T, class Items> | ||
264 | inline int write(ozstream& zs, const T* x, Items items) { | ||
265 | return ::gzwrite(zs.fp(), (voidp) x, items*sizeof(T)); | ||
266 | } | ||
267 | |||
268 | /* | ||
269 | * Binary output with the '<' operator. | ||
270 | */ | ||
271 | template <class T> | ||
272 | inline ozstream& operator<(ozstream& zs, const T& x) { | ||
273 | ::gzwrite(zs.fp(), (voidp) &x, sizeof(T)); | ||
274 | return zs; | ||
275 | } | ||
276 | |||
277 | inline zstringlen::zstringlen(ozstream& zs, const char* x) { | ||
278 | val.byte = 255; val.word = ::strlen(x); | ||
279 | if (val.word < 255) zs < (val.byte = val.word); | ||
280 | else zs < val; | ||
281 | } | ||
282 | |||
283 | /* | ||
284 | * Write length of string + the string with the '<' operator. | ||
285 | */ | ||
286 | inline ozstream& operator<(ozstream& zs, const char* x) { | ||
287 | zstringlen len(zs, x); | ||
288 | ::gzwrite(zs.fp(), (voidp) x, len.value()); | ||
289 | return zs; | ||
290 | } | ||
291 | |||
292 | #ifdef _MSC_VER | ||
293 | inline ozstream& operator<(ozstream& zs, char* const& x) { | ||
294 | return zs < (const char*) x; | ||
295 | } | ||
296 | #endif | ||
297 | |||
298 | /* | ||
299 | * Ascii write with the << operator; | ||
300 | */ | ||
301 | template <class T> | ||
302 | inline ostream& operator<<(ozstream& zs, const T& x) { | ||
303 | zs.os_flush(); | ||
304 | return zs.os() << x; | ||
305 | } | ||
306 | |||
307 | #endif | ||
diff --git a/contrib/iostream2/zstream_test.cpp b/contrib/iostream2/zstream_test.cpp new file mode 100644 index 0000000..5bbd56c --- /dev/null +++ b/contrib/iostream2/zstream_test.cpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "zstream.h" | ||
2 | #include <math.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <iomanip.h> | ||
5 | |||
6 | void main() { | ||
7 | char h[256] = "Hello"; | ||
8 | char* g = "Goodbye"; | ||
9 | ozstream out("temp.gz"); | ||
10 | out < "This works well" < h < g; | ||
11 | out.close(); | ||
12 | |||
13 | izstream in("temp.gz"); // read it back | ||
14 | char *x = read_string(in), *y = new char[256], z[256]; | ||
15 | in > y > z; | ||
16 | in.close(); | ||
17 | cout << x << endl << y << endl << z << endl; | ||
18 | |||
19 | out.open("temp.gz"); // try ascii output; zcat temp.gz to see the results | ||
20 | out << setw(50) << setfill('#') << setprecision(20) << x << endl << y << endl << z << endl; | ||
21 | out << z << endl << y << endl << x << endl; | ||
22 | out << 1.1234567890123456789 << endl; | ||
23 | |||
24 | delete[] x; delete[] y; | ||
25 | } | ||
diff --git a/contrib/untgz/Makefile b/contrib/untgz/Makefile new file mode 100644 index 0000000..409b4bd --- /dev/null +++ b/contrib/untgz/Makefile | |||
@@ -0,0 +1,14 @@ | |||
1 | CC=cc | ||
2 | CFLAGS=-g | ||
3 | |||
4 | untgz: untgz.o ../../libz.a | ||
5 | $(CC) $(CFLAGS) -o untgz untgz.o -L../.. -lz | ||
6 | |||
7 | untgz.o: untgz.c ../../zlib.h | ||
8 | $(CC) $(CFLAGS) -c -I../.. untgz.c | ||
9 | |||
10 | ../../libz.a: | ||
11 | cd ../..; make | ||
12 | |||
13 | clean: | ||
14 | rm -f untgz untgz.o *~ | ||
diff --git a/contrib/untgz/makefile.w32 b/contrib/untgz/makefile.w32 new file mode 100644 index 0000000..c99dc28 --- /dev/null +++ b/contrib/untgz/makefile.w32 | |||
@@ -0,0 +1,63 @@ | |||
1 | # Makefile for zlib. Modified for mingw32 | ||
2 | # For conditions of distribution and use, see copyright notice in zlib.h | ||
3 | |||
4 | # To compile, | ||
5 | # | ||
6 | # make -fmakefile.w32 | ||
7 | # | ||
8 | |||
9 | CC=gcc | ||
10 | |||
11 | # Generate dependencies (see end of the file) | ||
12 | |||
13 | CPPFLAGS=-MMD | ||
14 | |||
15 | #CFLAGS=-MMD -O | ||
16 | #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 | ||
17 | #CFLAGS=-MMD -g -DDEBUG | ||
18 | CFLAGS=-O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ | ||
19 | -Wstrict-prototypes -Wmissing-prototypes | ||
20 | |||
21 | # If cp.exe is not found, replace with copy /Y . | ||
22 | CP=cp -f | ||
23 | |||
24 | # The default value of RM is "rm -f." | ||
25 | # If "rm.exe" is not found, uncomment: | ||
26 | # RM=del | ||
27 | |||
28 | LD=gcc | ||
29 | LDLIBS=-L. -lz | ||
30 | LDFLAGS=-s | ||
31 | |||
32 | |||
33 | INCL=zlib.h zconf.h | ||
34 | LIBS=libz.a | ||
35 | |||
36 | AR=ar rcs | ||
37 | |||
38 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | ||
39 | zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o \ | ||
40 | inffast.o | ||
41 | |||
42 | TEST_OBJS = minigzip.o untgz.o | ||
43 | |||
44 | all: minigzip.exe untgz.exe | ||
45 | |||
46 | rebuild: clean all | ||
47 | |||
48 | libz.a: $(OBJS) | ||
49 | $(AR) $@ $(OBJS) | ||
50 | |||
51 | %.exe : %.o $(LIBS) | ||
52 | $(LD) $(LDFLAGS) -o $@ $< $(LDLIBS) | ||
53 | |||
54 | .PHONY : clean | ||
55 | |||
56 | clean: | ||
57 | $(RM) *.d *.o *.exe libz.a foo.gz | ||
58 | |||
59 | DEPS := $(wildcard *.d) | ||
60 | ifneq ($(DEPS),) | ||
61 | include $(DEPS) | ||
62 | endif | ||
63 | |||
diff --git a/contrib/untgz/untgz.c b/contrib/untgz/untgz.c new file mode 100644 index 0000000..6fa9a5d --- /dev/null +++ b/contrib/untgz/untgz.c | |||
@@ -0,0 +1,478 @@ | |||
1 | /* | ||
2 | * untgz.c -- Display contents and/or extract file from | ||
3 | * a gzip'd TAR file | ||
4 | * written by "Pedro A. Aranda Guti\irrez" <paag@tid.es> | ||
5 | * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org> | ||
6 | */ | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <string.h> | ||
11 | #include <time.h> | ||
12 | #include <utime.h> | ||
13 | #include <errno.h> | ||
14 | #include <fcntl.h> | ||
15 | #ifdef unix | ||
16 | # include <unistd.h> | ||
17 | #else | ||
18 | # include <direct.h> | ||
19 | # include <io.h> | ||
20 | #endif | ||
21 | |||
22 | #include "zlib.h" | ||
23 | |||
24 | /* Values used in typeflag field. */ | ||
25 | |||
26 | #define REGTYPE '0' /* regular file */ | ||
27 | #define AREGTYPE '\0' /* regular file */ | ||
28 | #define LNKTYPE '1' /* link */ | ||
29 | #define SYMTYPE '2' /* reserved */ | ||
30 | #define CHRTYPE '3' /* character special */ | ||
31 | #define BLKTYPE '4' /* block special */ | ||
32 | #define DIRTYPE '5' /* directory */ | ||
33 | #define FIFOTYPE '6' /* FIFO special */ | ||
34 | #define CONTTYPE '7' /* reserved */ | ||
35 | |||
36 | #define BLOCKSIZE 512 | ||
37 | |||
38 | struct tar_header | ||
39 | { /* byte offset */ | ||
40 | char name[100]; /* 0 */ | ||
41 | char mode[8]; /* 100 */ | ||
42 | char uid[8]; /* 108 */ | ||
43 | char gid[8]; /* 116 */ | ||
44 | char size[12]; /* 124 */ | ||
45 | char mtime[12]; /* 136 */ | ||
46 | char chksum[8]; /* 148 */ | ||
47 | char typeflag; /* 156 */ | ||
48 | char linkname[100]; /* 157 */ | ||
49 | char magic[6]; /* 257 */ | ||
50 | char version[2]; /* 263 */ | ||
51 | char uname[32]; /* 265 */ | ||
52 | char gname[32]; /* 297 */ | ||
53 | char devmajor[8]; /* 329 */ | ||
54 | char devminor[8]; /* 337 */ | ||
55 | char prefix[155]; /* 345 */ | ||
56 | /* 500 */ | ||
57 | }; | ||
58 | |||
59 | union tar_buffer { | ||
60 | char buffer[BLOCKSIZE]; | ||
61 | struct tar_header header; | ||
62 | }; | ||
63 | |||
64 | enum { TGZ_EXTRACT = 0, TGZ_LIST }; | ||
65 | |||
66 | static char *TGZfname OF((const char *)); | ||
67 | void TGZnotfound OF((const char *)); | ||
68 | |||
69 | int getoct OF((char *, int)); | ||
70 | char *strtime OF((time_t *)); | ||
71 | int ExprMatch OF((char *,char *)); | ||
72 | |||
73 | int makedir OF((char *)); | ||
74 | int matchname OF((int,int,char **,char *)); | ||
75 | |||
76 | void error OF((const char *)); | ||
77 | int tar OF((gzFile, int, int, int, char **)); | ||
78 | |||
79 | void help OF((int)); | ||
80 | int main OF((int, char **)); | ||
81 | |||
82 | char *prog; | ||
83 | |||
84 | /* This will give a benign warning */ | ||
85 | |||
86 | static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", NULL }; | ||
87 | |||
88 | /* Return the real name of the TGZ archive */ | ||
89 | /* or NULL if it does not exist. */ | ||
90 | |||
91 | static char *TGZfname OF((const char *fname)) | ||
92 | { | ||
93 | static char buffer[1024]; | ||
94 | int origlen,i; | ||
95 | |||
96 | strcpy(buffer,fname); | ||
97 | origlen = strlen(buffer); | ||
98 | |||
99 | for (i=0; TGZprefix[i]; i++) | ||
100 | { | ||
101 | strcpy(buffer+origlen,TGZprefix[i]); | ||
102 | if (access(buffer,F_OK) == 0) | ||
103 | return buffer; | ||
104 | } | ||
105 | return NULL; | ||
106 | } | ||
107 | |||
108 | /* error message for the filename */ | ||
109 | |||
110 | void TGZnotfound OF((const char *fname)) | ||
111 | { | ||
112 | int i; | ||
113 | |||
114 | fprintf(stderr,"%s : couldn't find ",prog); | ||
115 | for (i=0;TGZprefix[i];i++) | ||
116 | fprintf(stderr,(TGZprefix[i+1]) ? "%s%s, " : "or %s%s\n", | ||
117 | fname, | ||
118 | TGZprefix[i]); | ||
119 | exit(1); | ||
120 | } | ||
121 | |||
122 | |||
123 | /* help functions */ | ||
124 | |||
125 | int getoct(char *p,int width) | ||
126 | { | ||
127 | int result = 0; | ||
128 | char c; | ||
129 | |||
130 | while (width --) | ||
131 | { | ||
132 | c = *p++; | ||
133 | if (c == ' ') | ||
134 | continue; | ||
135 | if (c == 0) | ||
136 | break; | ||
137 | result = result * 8 + (c - '0'); | ||
138 | } | ||
139 | return result; | ||
140 | } | ||
141 | |||
142 | char *strtime (time_t *t) | ||
143 | { | ||
144 | struct tm *local; | ||
145 | static char result[32]; | ||
146 | |||
147 | local = localtime(t); | ||
148 | sprintf(result,"%2d/%02d/%4d %02d:%02d:%02d", | ||
149 | local->tm_mday, local->tm_mon+1, local->tm_year+1900, | ||
150 | local->tm_hour, local->tm_min, local->tm_sec); | ||
151 | return result; | ||
152 | } | ||
153 | |||
154 | |||
155 | /* regular expression matching */ | ||
156 | |||
157 | #define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) | ||
158 | |||
159 | int ExprMatch(char *string,char *expr) | ||
160 | { | ||
161 | while (1) | ||
162 | { | ||
163 | if (ISSPECIAL(*expr)) | ||
164 | { | ||
165 | if (*expr == '/') | ||
166 | { | ||
167 | if (*string != '\\' && *string != '/') | ||
168 | return 0; | ||
169 | string ++; expr++; | ||
170 | } | ||
171 | else if (*expr == '*') | ||
172 | { | ||
173 | if (*expr ++ == 0) | ||
174 | return 1; | ||
175 | while (*++string != *expr) | ||
176 | if (*string == 0) | ||
177 | return 0; | ||
178 | } | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | if (*string != *expr) | ||
183 | return 0; | ||
184 | if (*expr++ == 0) | ||
185 | return 1; | ||
186 | string++; | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | |||
191 | /* recursive make directory */ | ||
192 | /* abort if you get an ENOENT errno somewhere in the middle */ | ||
193 | /* e.g. ignore error "mkdir on existing directory" */ | ||
194 | /* */ | ||
195 | /* return 1 if OK */ | ||
196 | /* 0 on error */ | ||
197 | |||
198 | int makedir (char *newdir) | ||
199 | { | ||
200 | char *buffer = strdup(newdir); | ||
201 | char *p; | ||
202 | int len = strlen(buffer); | ||
203 | |||
204 | if (len <= 0) { | ||
205 | free(buffer); | ||
206 | return 0; | ||
207 | } | ||
208 | if (buffer[len-1] == '/') { | ||
209 | buffer[len-1] = '\0'; | ||
210 | } | ||
211 | if (mkdir(buffer, 0775) == 0) | ||
212 | { | ||
213 | free(buffer); | ||
214 | return 1; | ||
215 | } | ||
216 | |||
217 | p = buffer+1; | ||
218 | while (1) | ||
219 | { | ||
220 | char hold; | ||
221 | |||
222 | while(*p && *p != '\\' && *p != '/') | ||
223 | p++; | ||
224 | hold = *p; | ||
225 | *p = 0; | ||
226 | if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT)) | ||
227 | { | ||
228 | fprintf(stderr,"%s: couldn't create directory %s\n",prog,buffer); | ||
229 | free(buffer); | ||
230 | return 0; | ||
231 | } | ||
232 | if (hold == 0) | ||
233 | break; | ||
234 | *p++ = hold; | ||
235 | } | ||
236 | free(buffer); | ||
237 | return 1; | ||
238 | } | ||
239 | |||
240 | int matchname (int arg,int argc,char **argv,char *fname) | ||
241 | { | ||
242 | if (arg == argc) /* no arguments given (untgz tgzarchive) */ | ||
243 | return 1; | ||
244 | |||
245 | while (arg < argc) | ||
246 | if (ExprMatch(fname,argv[arg++])) | ||
247 | return 1; | ||
248 | |||
249 | return 0; /* ignore this for the moment being */ | ||
250 | } | ||
251 | |||
252 | |||
253 | /* Tar file list or extract */ | ||
254 | |||
255 | int tar (gzFile in,int action,int arg,int argc,char **argv) | ||
256 | { | ||
257 | union tar_buffer buffer; | ||
258 | int len; | ||
259 | int err; | ||
260 | int getheader = 1; | ||
261 | int remaining = 0; | ||
262 | FILE *outfile = NULL; | ||
263 | char fname[BLOCKSIZE]; | ||
264 | time_t tartime; | ||
265 | |||
266 | if (action == TGZ_LIST) | ||
267 | printf(" day time size file\n" | ||
268 | " ---------- -------- --------- -------------------------------------\n"); | ||
269 | while (1) | ||
270 | { | ||
271 | len = gzread(in, &buffer, BLOCKSIZE); | ||
272 | if (len < 0) | ||
273 | error (gzerror(in, &err)); | ||
274 | /* | ||
275 | * if we met the end of the tar | ||
276 | * or the end-of-tar block, | ||
277 | * we are done | ||
278 | */ | ||
279 | if ((len == 0) || (buffer.header.name[0]== 0)) | ||
280 | break; | ||
281 | |||
282 | /* | ||
283 | * Always expect complete blocks to process | ||
284 | * the tar information. | ||
285 | */ | ||
286 | if (len != BLOCKSIZE) | ||
287 | error("gzread: incomplete block read"); | ||
288 | |||
289 | /* | ||
290 | * If we have to get a tar header | ||
291 | */ | ||
292 | if (getheader == 1) | ||
293 | { | ||
294 | tartime = (time_t)getoct(buffer.header.mtime,12); | ||
295 | strcpy(fname,buffer.header.name); | ||
296 | |||
297 | switch (buffer.header.typeflag) | ||
298 | { | ||
299 | case DIRTYPE: | ||
300 | if (action == TGZ_LIST) | ||
301 | printf(" %s <dir> %s\n",strtime(&tartime),fname); | ||
302 | if (action == TGZ_EXTRACT) | ||
303 | makedir(fname); | ||
304 | break; | ||
305 | case REGTYPE: | ||
306 | case AREGTYPE: | ||
307 | remaining = getoct(buffer.header.size,12); | ||
308 | if (action == TGZ_LIST) | ||
309 | printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); | ||
310 | if (action == TGZ_EXTRACT) | ||
311 | { | ||
312 | if ((remaining) && (matchname(arg,argc,argv,fname))) | ||
313 | { | ||
314 | outfile = fopen(fname,"wb"); | ||
315 | if (outfile == NULL) { | ||
316 | /* try creating directory */ | ||
317 | char *p = strrchr(fname, '/'); | ||
318 | if (p != NULL) { | ||
319 | *p = '\0'; | ||
320 | makedir(fname); | ||
321 | *p = '/'; | ||
322 | outfile = fopen(fname,"wb"); | ||
323 | } | ||
324 | } | ||
325 | fprintf(stderr, | ||
326 | "%s %s\n", | ||
327 | (outfile) ? "Extracting" : "Couldn't create", | ||
328 | fname); | ||
329 | } | ||
330 | else | ||
331 | outfile = NULL; | ||
332 | } | ||
333 | /* | ||
334 | * could have no contents | ||
335 | */ | ||
336 | getheader = (remaining) ? 0 : 1; | ||
337 | break; | ||
338 | default: | ||
339 | if (action == TGZ_LIST) | ||
340 | printf(" %s <---> %s\n",strtime(&tartime),fname); | ||
341 | break; | ||
342 | } | ||
343 | } | ||
344 | else | ||
345 | { | ||
346 | unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining; | ||
347 | |||
348 | if ((action == TGZ_EXTRACT) && (outfile != NULL)) | ||
349 | { | ||
350 | if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) | ||
351 | { | ||
352 | fprintf(stderr,"%s : error writing %s skipping...\n",prog,fname); | ||
353 | fclose(outfile); | ||
354 | unlink(fname); | ||
355 | } | ||
356 | } | ||
357 | remaining -= bytes; | ||
358 | if (remaining == 0) | ||
359 | { | ||
360 | getheader = 1; | ||
361 | if ((action == TGZ_EXTRACT) && (outfile != NULL)) | ||
362 | { | ||
363 | struct utimbuf settime; | ||
364 | |||
365 | settime.actime = settime.modtime = tartime; | ||
366 | |||
367 | fclose(outfile); | ||
368 | outfile = NULL; | ||
369 | utime(fname,&settime); | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | |||
375 | if (gzclose(in) != Z_OK) | ||
376 | error("failed gzclose"); | ||
377 | |||
378 | return 0; | ||
379 | } | ||
380 | |||
381 | |||
382 | /* =========================================================== */ | ||
383 | |||
384 | void help(int exitval) | ||
385 | { | ||
386 | fprintf(stderr, | ||
387 | "untgz v 0.1\n" | ||
388 | " an sample application of zlib 1.0.4\n\n" | ||
389 | "Usage : untgz TGZfile to extract all files\n" | ||
390 | " untgz TGZfile fname ... to extract selected files\n" | ||
391 | " untgz -l TGZfile to list archive contents\n" | ||
392 | " untgz -h to display this help\n\n"); | ||
393 | exit(exitval); | ||
394 | } | ||
395 | |||
396 | void error(const char *msg) | ||
397 | { | ||
398 | fprintf(stderr, "%s: %s\n", prog, msg); | ||
399 | exit(1); | ||
400 | } | ||
401 | |||
402 | |||
403 | /* ====================================================================== */ | ||
404 | |||
405 | int _CRT_glob = 0; /* disable globbing of the arguments */ | ||
406 | |||
407 | int main(int argc,char **argv) | ||
408 | { | ||
409 | int action = TGZ_EXTRACT; | ||
410 | int arg = 1; | ||
411 | char *TGZfile; | ||
412 | gzFile *f; | ||
413 | |||
414 | |||
415 | prog = strrchr(argv[0],'\\'); | ||
416 | if (prog == NULL) | ||
417 | { | ||
418 | prog = strrchr(argv[0],'/'); | ||
419 | if (prog == NULL) | ||
420 | { | ||
421 | prog = strrchr(argv[0],':'); | ||
422 | if (prog == NULL) | ||
423 | prog = argv[0]; | ||
424 | else | ||
425 | prog++; | ||
426 | } | ||
427 | else | ||
428 | prog++; | ||
429 | } | ||
430 | else | ||
431 | prog++; | ||
432 | |||
433 | if (argc == 1) | ||
434 | help(0); | ||
435 | |||
436 | if (strcmp(argv[arg],"-l") == 0) | ||
437 | { | ||
438 | action = TGZ_LIST; | ||
439 | if (argc == ++arg) | ||
440 | help(0); | ||
441 | } | ||
442 | else if (strcmp(argv[arg],"-h") == 0) | ||
443 | { | ||
444 | help(0); | ||
445 | } | ||
446 | |||
447 | if ((TGZfile = TGZfname(argv[arg])) == NULL) | ||
448 | TGZnotfound(argv[arg]); | ||
449 | |||
450 | ++arg; | ||
451 | if ((action == TGZ_LIST) && (arg != argc)) | ||
452 | help(1); | ||
453 | |||
454 | /* | ||
455 | * Process the TGZ file | ||
456 | */ | ||
457 | switch(action) | ||
458 | { | ||
459 | case TGZ_LIST: | ||
460 | case TGZ_EXTRACT: | ||
461 | f = gzopen(TGZfile,"rb"); | ||
462 | if (f == NULL) | ||
463 | { | ||
464 | fprintf(stderr,"%s: Couldn't gzopen %s\n", | ||
465 | prog, | ||
466 | TGZfile); | ||
467 | return 1; | ||
468 | } | ||
469 | exit(tar(f, action, arg, argc, argv)); | ||
470 | break; | ||
471 | |||
472 | default: | ||
473 | error("Unknown option!"); | ||
474 | exit(1); | ||
475 | } | ||
476 | |||
477 | return 0; | ||
478 | } | ||
diff --git a/contrib/visual-basic.txt b/contrib/visual-basic.txt new file mode 100644 index 0000000..18aa084 --- /dev/null +++ b/contrib/visual-basic.txt | |||
@@ -0,0 +1,57 @@ | |||
1 | From: "Jon Caruana" <jon-net@usa.net> | ||
2 | To: "Jean-loup Gailly" <gzip@prep.ai.mit.edu> | ||
3 | Subject: Re: How to port zlib declares to vb? | ||
4 | Date: Mon, 28 Oct 1996 18:33:03 -0600 | ||
5 | |||
6 | Got the answer! (I haven't had time to check this but it's what I got, and | ||
7 | looks correct): | ||
8 | |||
9 | He has the following routines working: | ||
10 | compress | ||
11 | uncompress | ||
12 | gzopen | ||
13 | gzwrite | ||
14 | gzread | ||
15 | gzclose | ||
16 | |||
17 | Declares follow: (Quoted from Carlos Rios <c_rios@sonda.cl>, in Vb4 form) | ||
18 | |||
19 | #If Win16 Then 'Use Win16 calls. | ||
20 | Declare Function compress Lib "ZLIB.DLL" (ByVal compr As | ||
21 | String, comprLen As Any, ByVal buf As String, ByVal buflen | ||
22 | As Long) As Integer | ||
23 | Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr | ||
24 | As String, uncomprLen As Any, ByVal compr As String, ByVal | ||
25 | lcompr As Long) As Integer | ||
26 | Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As | ||
27 | String, ByVal mode As String) As Long | ||
28 | Declare Function gzread Lib "ZLIB.DLL" (ByVal file As | ||
29 | Long, ByVal uncompr As String, ByVal uncomprLen As Integer) | ||
30 | As Integer | ||
31 | Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As | ||
32 | Long, ByVal uncompr As String, ByVal uncomprLen As Integer) | ||
33 | As Integer | ||
34 | Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As | ||
35 | Long) As Integer | ||
36 | #Else | ||
37 | Declare Function compress Lib "ZLIB32.DLL" | ||
38 | (ByVal compr As String, comprLen As Any, ByVal buf As | ||
39 | String, ByVal buflen As Long) As Integer | ||
40 | Declare Function uncompress Lib "ZLIB32.DLL" | ||
41 | (ByVal uncompr As String, uncomprLen As Any, ByVal compr As | ||
42 | String, ByVal lcompr As Long) As Long | ||
43 | Declare Function gzopen Lib "ZLIB32.DLL" | ||
44 | (ByVal file As String, ByVal mode As String) As Long | ||
45 | Declare Function gzread Lib "ZLIB32.DLL" | ||
46 | (ByVal file As Long, ByVal uncompr As String, ByVal | ||
47 | uncomprLen As Long) As Long | ||
48 | Declare Function gzwrite Lib "ZLIB32.DLL" | ||
49 | (ByVal file As Long, ByVal uncompr As String, ByVal | ||
50 | uncomprLen As Long) As Long | ||
51 | Declare Function gzclose Lib "ZLIB32.DLL" | ||
52 | (ByVal file As Long) As Long | ||
53 | #End If | ||
54 | |||
55 | -Jon Caruana | ||
56 | jon-net@usa.net | ||
57 | Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member | ||
@@ -1,9 +1,9 @@ | |||
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-1998 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 | /* $Id: crc32.c,v 1.8 1996/01/30 21:59:10 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #include "zlib.h" | 8 | #include "zlib.h" |
9 | 9 | ||
@@ -124,7 +124,7 @@ local uLongf crc_table[256] = { | |||
124 | /* ========================================================================= | 124 | /* ========================================================================= |
125 | * This function can be used by asm versions of crc32() | 125 | * This function can be used by asm versions of crc32() |
126 | */ | 126 | */ |
127 | uLongf *get_crc_table() | 127 | uLongf * EXPORT get_crc_table() |
128 | { | 128 | { |
129 | #ifdef DYNAMIC_CRC_TABLE | 129 | #ifdef DYNAMIC_CRC_TABLE |
130 | if (crc_table_empty) make_crc_table(); | 130 | if (crc_table_empty) make_crc_table(); |
@@ -139,7 +139,7 @@ uLongf *get_crc_table() | |||
139 | #define DO8(buf) DO4(buf); DO4(buf); | 139 | #define DO8(buf) DO4(buf); DO4(buf); |
140 | 140 | ||
141 | /* ========================================================================= */ | 141 | /* ========================================================================= */ |
142 | uLong crc32(crc, buf, len) | 142 | uLong EXPORT crc32(crc, buf, len) |
143 | uLong crc; | 143 | uLong crc; |
144 | const Bytef *buf; | 144 | const Bytef *buf; |
145 | uInt len; | 145 | uInt len; |
@@ -36,8 +36,8 @@ | |||
36 | * | 36 | * |
37 | * REFERENCES | 37 | * REFERENCES |
38 | * | 38 | * |
39 | * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". | 39 | * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". |
40 | * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc | 40 | * Available in ftp://ds.internic.net/rfc/rfc1951.txt |
41 | * | 41 | * |
42 | * A description of the Rabin and Karp algorithm is given in the book | 42 | * A description of the Rabin and Karp algorithm is given in the book |
43 | * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. | 43 | * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. |
@@ -47,10 +47,12 @@ | |||
47 | * | 47 | * |
48 | */ | 48 | */ |
49 | 49 | ||
50 | /* @(#) $Id$ */ | ||
50 | 51 | ||
51 | #include "deflate.h" | 52 | #include "deflate.h" |
52 | 53 | ||
53 | char deflate_copyright[] = " deflate 1.0.5 Copyright 1995-1998 Jean-loup Gailly "; | 54 | const char deflate_copyright[] = |
55 | " deflate 1.0.7 Copyright 1995-1998 Jean-loup Gailly "; | ||
54 | /* | 56 | /* |
55 | If you use the zlib library in a product, an acknowledgment is welcome | 57 | If you use the zlib library in a product, an acknowledgment is welcome |
56 | in the documentation of your product. If for some reason you cannot | 58 | in the documentation of your product. If for some reason you cannot |
@@ -76,12 +78,14 @@ local block_state deflate_stored OF((deflate_state *s, int flush)); | |||
76 | local block_state deflate_fast OF((deflate_state *s, int flush)); | 78 | local block_state deflate_fast OF((deflate_state *s, int flush)); |
77 | local block_state deflate_slow OF((deflate_state *s, int flush)); | 79 | local block_state deflate_slow OF((deflate_state *s, int flush)); |
78 | local void lm_init OF((deflate_state *s)); | 80 | local void lm_init OF((deflate_state *s)); |
79 | local uInt longest_match OF((deflate_state *s, IPos cur_match)); | ||
80 | local void putShortMSB OF((deflate_state *s, uInt b)); | 81 | local void putShortMSB OF((deflate_state *s, uInt b)); |
81 | local void flush_pending OF((z_streamp strm)); | 82 | local void flush_pending OF((z_streamp strm)); |
82 | local int read_buf OF((z_streamp strm, charf *buf, unsigned size)); | 83 | local int read_buf OF((z_streamp strm, charf *buf, unsigned size)); |
83 | #ifdef ASMV | 84 | #ifdef ASMV |
84 | void match_init OF((void)); /* asm code initialization */ | 85 | void match_init OF((void)); /* asm code initialization */ |
86 | uInt longest_match OF((deflate_state *s, IPos cur_match)); | ||
87 | #else | ||
88 | local uInt longest_match OF((deflate_state *s, IPos cur_match)); | ||
85 | #endif | 89 | #endif |
86 | 90 | ||
87 | #ifdef DEBUG | 91 | #ifdef DEBUG |
@@ -119,7 +123,7 @@ typedef struct config_s { | |||
119 | compress_func func; | 123 | compress_func func; |
120 | } config; | 124 | } config; |
121 | 125 | ||
122 | local config configuration_table[10] = { | 126 | local const config configuration_table[10] = { |
123 | /* good lazy nice chain */ | 127 | /* good lazy nice chain */ |
124 | /* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ | 128 | /* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ |
125 | /* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */ | 129 | /* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */ |
@@ -174,7 +178,7 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ | |||
174 | zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); | 178 | zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); |
175 | 179 | ||
176 | /* ========================================================================= */ | 180 | /* ========================================================================= */ |
177 | int deflateInit_(strm, level, version, stream_size) | 181 | int EXPORT deflateInit_(strm, level, version, stream_size) |
178 | z_streamp strm; | 182 | z_streamp strm; |
179 | int level; | 183 | int level; |
180 | const char *version; | 184 | const char *version; |
@@ -186,7 +190,7 @@ int deflateInit_(strm, level, version, stream_size) | |||
186 | } | 190 | } |
187 | 191 | ||
188 | /* ========================================================================= */ | 192 | /* ========================================================================= */ |
189 | int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | 193 | int EXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
190 | version, stream_size) | 194 | version, stream_size) |
191 | z_streamp strm; | 195 | z_streamp strm; |
192 | int level; | 196 | int level; |
@@ -199,13 +203,14 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
199 | { | 203 | { |
200 | deflate_state *s; | 204 | deflate_state *s; |
201 | int noheader = 0; | 205 | int noheader = 0; |
206 | static const char* my_version = ZLIB_VERSION; | ||
202 | 207 | ||
203 | ushf *overlay; | 208 | ushf *overlay; |
204 | /* We overlay pending_buf and d_buf+l_buf. This works since the average | 209 | /* We overlay pending_buf and d_buf+l_buf. This works since the average |
205 | * output size for (length,distance) codes is <= 24 bits. | 210 | * output size for (length,distance) codes is <= 24 bits. |
206 | */ | 211 | */ |
207 | 212 | ||
208 | if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || | 213 | if (version == Z_NULL || version[0] != my_version[0] || |
209 | stream_size != sizeof(z_stream)) { | 214 | stream_size != sizeof(z_stream)) { |
210 | return Z_VERSION_ERROR; | 215 | return Z_VERSION_ERROR; |
211 | } | 216 | } |
@@ -252,6 +257,7 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
252 | 257 | ||
253 | overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); | 258 | overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); |
254 | s->pending_buf = (uchf *) overlay; | 259 | s->pending_buf = (uchf *) overlay; |
260 | s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); | ||
255 | 261 | ||
256 | if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || | 262 | if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || |
257 | s->pending_buf == Z_NULL) { | 263 | s->pending_buf == Z_NULL) { |
@@ -270,7 +276,7 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
270 | } | 276 | } |
271 | 277 | ||
272 | /* ========================================================================= */ | 278 | /* ========================================================================= */ |
273 | int deflateSetDictionary (strm, dictionary, dictLength) | 279 | int EXPORT deflateSetDictionary (strm, dictionary, dictLength) |
274 | z_streamp strm; | 280 | z_streamp strm; |
275 | const Bytef *dictionary; | 281 | const Bytef *dictionary; |
276 | uInt dictLength; | 282 | uInt dictLength; |
@@ -289,7 +295,9 @@ int deflateSetDictionary (strm, dictionary, dictLength) | |||
289 | if (length < MIN_MATCH) return Z_OK; | 295 | if (length < MIN_MATCH) return Z_OK; |
290 | if (length > MAX_DIST(s)) { | 296 | if (length > MAX_DIST(s)) { |
291 | length = MAX_DIST(s); | 297 | length = MAX_DIST(s); |
292 | dictionary += dictLength - length; | 298 | #ifndef USE_DICT_HEAD |
299 | dictionary += dictLength - length; /* use the tail of the dictionary */ | ||
300 | #endif | ||
293 | } | 301 | } |
294 | zmemcpy((charf *)s->window, dictionary, length); | 302 | zmemcpy((charf *)s->window, dictionary, length); |
295 | s->strstart = length; | 303 | s->strstart = length; |
@@ -309,7 +317,7 @@ int deflateSetDictionary (strm, dictionary, dictLength) | |||
309 | } | 317 | } |
310 | 318 | ||
311 | /* ========================================================================= */ | 319 | /* ========================================================================= */ |
312 | int deflateReset (strm) | 320 | int EXPORT deflateReset (strm) |
313 | z_streamp strm; | 321 | z_streamp strm; |
314 | { | 322 | { |
315 | deflate_state *s; | 323 | deflate_state *s; |
@@ -339,7 +347,7 @@ int deflateReset (strm) | |||
339 | } | 347 | } |
340 | 348 | ||
341 | /* ========================================================================= */ | 349 | /* ========================================================================= */ |
342 | int deflateParams(strm, level, strategy) | 350 | int EXPORT deflateParams(strm, level, strategy) |
343 | z_streamp strm; | 351 | z_streamp strm; |
344 | int level; | 352 | int level; |
345 | int strategy; | 353 | int strategy; |
@@ -413,7 +421,7 @@ local void flush_pending(strm) | |||
413 | } | 421 | } |
414 | 422 | ||
415 | /* ========================================================================= */ | 423 | /* ========================================================================= */ |
416 | int deflate (strm, flush) | 424 | int EXPORT deflate (strm, flush) |
417 | z_streamp strm; | 425 | z_streamp strm; |
418 | int flush; | 426 | int flush; |
419 | { | 427 | { |
@@ -547,42 +555,85 @@ int deflate (strm, flush) | |||
547 | } | 555 | } |
548 | 556 | ||
549 | /* ========================================================================= */ | 557 | /* ========================================================================= */ |
550 | int deflateEnd (strm) | 558 | int EXPORT deflateEnd (strm) |
551 | z_streamp strm; | 559 | z_streamp strm; |
552 | { | 560 | { |
553 | int status; | 561 | int status; |
554 | 562 | ||
555 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | 563 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; |
556 | 564 | ||
565 | status = strm->state->status; | ||
566 | if (status != INIT_STATE && status != BUSY_STATE && | ||
567 | status != FINISH_STATE) { | ||
568 | return Z_STREAM_ERROR; | ||
569 | } | ||
570 | |||
557 | /* Deallocate in reverse order of allocations: */ | 571 | /* Deallocate in reverse order of allocations: */ |
558 | TRY_FREE(strm, strm->state->pending_buf); | 572 | TRY_FREE(strm, strm->state->pending_buf); |
559 | TRY_FREE(strm, strm->state->head); | 573 | TRY_FREE(strm, strm->state->head); |
560 | TRY_FREE(strm, strm->state->prev); | 574 | TRY_FREE(strm, strm->state->prev); |
561 | TRY_FREE(strm, strm->state->window); | 575 | TRY_FREE(strm, strm->state->window); |
562 | 576 | ||
563 | status = strm->state->status; | ||
564 | ZFREE(strm, strm->state); | 577 | ZFREE(strm, strm->state); |
565 | strm->state = Z_NULL; | 578 | strm->state = Z_NULL; |
566 | 579 | ||
567 | return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; | 580 | return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; |
568 | } | 581 | } |
569 | 582 | ||
570 | /* ========================================================================= */ | 583 | /* ========================================================================= |
571 | int deflateCopy (dest, source) | 584 | * Copy the source state to the destination state. |
585 | * To simplify the source, this is not supported for 16-bit MSDOS (which | ||
586 | * doesn't have enough memory anyway to duplicate compression states). | ||
587 | */ | ||
588 | int EXPORT deflateCopy (dest, source) | ||
572 | z_streamp dest; | 589 | z_streamp dest; |
573 | z_streamp source; | 590 | z_streamp source; |
574 | { | 591 | { |
575 | if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { | 592 | #ifdef MAXSEG_64K |
593 | return Z_STREAM_ERROR; | ||
594 | #else | ||
595 | deflate_state *ds; | ||
596 | deflate_state *ss; | ||
597 | ushf *overlay; | ||
598 | |||
599 | ss = source->state; | ||
600 | |||
601 | if (source == Z_NULL || dest == Z_NULL || ss == Z_NULL) { | ||
576 | return Z_STREAM_ERROR; | 602 | return Z_STREAM_ERROR; |
577 | } | 603 | } |
578 | *dest = *source; | 604 | *dest = *source; |
579 | return Z_STREAM_ERROR; /* to be implemented */ | ||
580 | #if 0 | ||
581 | dest->state = (struct internal_state FAR *) | ||
582 | (*dest->zalloc)(1, sizeof(deflate_state)); | ||
583 | if (dest->state == Z_NULL) return Z_MEM_ERROR; | ||
584 | 605 | ||
585 | *(dest->state) = *(source->state); | 606 | ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); |
607 | if (ds == Z_NULL) return Z_MEM_ERROR; | ||
608 | dest->state = (struct internal_state FAR *) ds; | ||
609 | *ds = *ss; | ||
610 | ds->strm = dest; | ||
611 | |||
612 | ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); | ||
613 | ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); | ||
614 | ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); | ||
615 | overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); | ||
616 | ds->pending_buf = (uchf *) overlay; | ||
617 | |||
618 | if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || | ||
619 | ds->pending_buf == Z_NULL) { | ||
620 | deflateEnd (dest); | ||
621 | return Z_MEM_ERROR; | ||
622 | } | ||
623 | /* following zmemcpy do not work for 16-bit MSDOS */ | ||
624 | zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); | ||
625 | zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); | ||
626 | zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); | ||
627 | zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); | ||
628 | |||
629 | ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); | ||
630 | ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); | ||
631 | ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; | ||
632 | |||
633 | ds->l_desc.dyn_tree = ds->dyn_ltree; | ||
634 | ds->d_desc.dyn_tree = ds->dyn_dtree; | ||
635 | ds->bl_desc.dyn_tree = ds->bl_tree; | ||
636 | |||
586 | return Z_OK; | 637 | return Z_OK; |
587 | #endif | 638 | #endif |
588 | } | 639 | } |
@@ -815,7 +866,7 @@ local void check_match(s, start, match, length) | |||
815 | } while (--length != 0); | 866 | } while (--length != 0); |
816 | z_error("invalid match"); | 867 | z_error("invalid match"); |
817 | } | 868 | } |
818 | if (verbose > 1) { | 869 | if (z_verbose > 1) { |
819 | fprintf(stderr,"\\[%d,%d]", start-match, length); | 870 | fprintf(stderr,"\\[%d,%d]", start-match, length); |
820 | do { putc(s->window[start++], stderr); } while (--length != 0); | 871 | do { putc(s->window[start++], stderr); } while (--length != 0); |
821 | } | 872 | } |
@@ -864,29 +915,30 @@ local void fill_window(s) | |||
864 | (unsigned)wsize); | 915 | (unsigned)wsize); |
865 | s->match_start -= wsize; | 916 | s->match_start -= wsize; |
866 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ | 917 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
867 | |||
868 | s->block_start -= (long) wsize; | 918 | s->block_start -= (long) wsize; |
869 | 919 | ||
870 | /* Slide the hash table (could be avoided with 32 bit values | 920 | /* Slide the hash table (could be avoided with 32 bit values |
871 | at the expense of memory usage): | 921 | at the expense of memory usage). We slide even when level == 0 |
922 | to keep the hash table consistent if we switch back to level > 0 | ||
923 | later. (Using level 0 permanently is not an optimal usage of | ||
924 | zlib, so we don't care about this pathological case.) | ||
872 | */ | 925 | */ |
873 | n = s->hash_size; | 926 | n = s->hash_size; |
874 | p = &s->head[n]; | 927 | p = &s->head[n]; |
875 | do { | 928 | do { |
876 | m = *--p; | 929 | m = *--p; |
877 | *p = (Pos)(m >= wsize ? m-wsize : NIL); | 930 | *p = (Pos)(m >= wsize ? m-wsize : NIL); |
878 | } while (--n); | 931 | } while (--n); |
879 | 932 | ||
880 | n = wsize; | 933 | n = wsize; |
881 | p = &s->prev[n]; | 934 | p = &s->prev[n]; |
882 | do { | 935 | do { |
883 | m = *--p; | 936 | m = *--p; |
884 | *p = (Pos)(m >= wsize ? m-wsize : NIL); | 937 | *p = (Pos)(m >= wsize ? m-wsize : NIL); |
885 | /* If n is not on any hash chain, prev[n] is garbage but | 938 | /* If n is not on any hash chain, prev[n] is garbage but |
886 | * its value will never be used. | 939 | * its value will never be used. |
887 | */ | 940 | */ |
888 | } while (--n); | 941 | } while (--n); |
889 | |||
890 | more += wsize; | 942 | more += wsize; |
891 | } | 943 | } |
892 | if (s->strm->avail_in == 0) return; | 944 | if (s->strm->avail_in == 0) return; |
@@ -950,12 +1002,24 @@ local void fill_window(s) | |||
950 | * This function does not insert new strings in the dictionary since | 1002 | * This function does not insert new strings in the dictionary since |
951 | * uncompressible data is probably not useful. This function is used | 1003 | * uncompressible data is probably not useful. This function is used |
952 | * only for the level=0 compression option. | 1004 | * only for the level=0 compression option. |
953 | * NOTE: this function should be optimized to avoid extra copying. | 1005 | * NOTE: this function should be optimized to avoid extra copying from |
1006 | * window to pending_buf. | ||
954 | */ | 1007 | */ |
955 | local block_state deflate_stored(s, flush) | 1008 | local block_state deflate_stored(s, flush) |
956 | deflate_state *s; | 1009 | deflate_state *s; |
957 | int flush; | 1010 | int flush; |
958 | { | 1011 | { |
1012 | /* Stored blocks are limited to 0xffff bytes, pending_buf is limited | ||
1013 | * to pending_buf_size, and each stored block has a 5 byte header: | ||
1014 | */ | ||
1015 | ulg max_block_size = 0xffff; | ||
1016 | ulg max_start; | ||
1017 | |||
1018 | if (max_block_size > s->pending_buf_size - 5) { | ||
1019 | max_block_size = s->pending_buf_size - 5; | ||
1020 | } | ||
1021 | |||
1022 | /* Copy as much as possible from input to output: */ | ||
959 | for (;;) { | 1023 | for (;;) { |
960 | /* Fill the window as much as possible: */ | 1024 | /* Fill the window as much as possible: */ |
961 | if (s->lookahead <= 1) { | 1025 | if (s->lookahead <= 1) { |
@@ -973,14 +1037,17 @@ local block_state deflate_stored(s, flush) | |||
973 | s->strstart += s->lookahead; | 1037 | s->strstart += s->lookahead; |
974 | s->lookahead = 0; | 1038 | s->lookahead = 0; |
975 | 1039 | ||
976 | /* Stored blocks are limited to 0xffff bytes: */ | 1040 | /* Emit a stored block if pending_buf will be full: */ |
977 | if (s->strstart == 0 || s->strstart > 0xfffe) { | 1041 | max_start = s->block_start + max_block_size; |
1042 | if (s->strstart == 0 || (ulg)s->strstart >= max_start) { | ||
978 | /* strstart == 0 is possible when wraparound on 16-bit machine */ | 1043 | /* strstart == 0 is possible when wraparound on 16-bit machine */ |
979 | s->lookahead = s->strstart - 0xffff; | 1044 | s->lookahead = (uInt)(s->strstart - max_start); |
980 | s->strstart = 0xffff; | 1045 | s->strstart = (uInt)max_start; |
1046 | FLUSH_BLOCK(s, 0); | ||
981 | } | 1047 | } |
982 | 1048 | /* Flush if we may have to slide, otherwise block_start may become | |
983 | /* Emit a stored block if it is large enough: */ | 1049 | * negative and the data will be gone: |
1050 | */ | ||
984 | if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { | 1051 | if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { |
985 | FLUSH_BLOCK(s, 0); | 1052 | FLUSH_BLOCK(s, 0); |
986 | } | 1053 | } |
@@ -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-1998 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 | ||
@@ -8,7 +8,7 @@ | |||
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 | /* $Id: deflate.h,v 1.10 1996/07/02 12:41:00 me Exp $ */ | 11 | /* @(#) $Id$ */ |
12 | 12 | ||
13 | #ifndef _DEFLATE_H | 13 | #ifndef _DEFLATE_H |
14 | #define _DEFLATE_H | 14 | #define _DEFLATE_H |
@@ -83,6 +83,7 @@ typedef struct internal_state { | |||
83 | z_streamp strm; /* pointer back to this zlib stream */ | 83 | z_streamp strm; /* pointer back to this zlib stream */ |
84 | int status; /* as the name implies */ | 84 | int status; /* as the name implies */ |
85 | Bytef *pending_buf; /* output still pending */ | 85 | Bytef *pending_buf; /* output still pending */ |
86 | ulg pending_buf_size; /* size of pending_buf */ | ||
86 | Bytef *pending_out; /* next pending byte to output to the stream */ | 87 | Bytef *pending_out; /* next pending byte to output to the stream */ |
87 | int pending; /* nb of bytes in the pending buffer */ | 88 | int pending; /* nb of bytes in the pending buffer */ |
88 | int noheader; /* suppress zlib header and adler32 */ | 89 | int noheader; /* suppress zlib header and adler32 */ |
@@ -1,9 +1,9 @@ | |||
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-1998 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 | ||
6 | /* $Id: example.c,v 1.16 1996/05/23 17:11:28 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include "zlib.h" | 9 | #include "zlib.h" |
@@ -86,16 +86,17 @@ void test_gzio(out, in, uncompr, uncomprLen) | |||
86 | int err; | 86 | int err; |
87 | int len = strlen(hello)+1; | 87 | int len = strlen(hello)+1; |
88 | gzFile file; | 88 | gzFile file; |
89 | z_off_t pos; | ||
89 | 90 | ||
90 | file = gzopen(out, "wb"); | 91 | file = gzopen(out, "wb"); |
91 | if (file == NULL) { | 92 | if (file == NULL) { |
92 | fprintf(stderr, "gzopen error\n"); | 93 | fprintf(stderr, "gzopen error\n"); |
93 | exit(1); | 94 | exit(1); |
94 | } | 95 | } |
95 | 96 | if (gzprintf(file, "%s, %s!", "hello", "hello") != len-1) { | |
96 | if (gzwrite(file, (const voidp)hello, (unsigned)len) != len) { | 97 | fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); |
97 | fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err)); | ||
98 | } | 98 | } |
99 | gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ | ||
99 | gzclose(file); | 100 | gzclose(file); |
100 | 101 | ||
101 | file = gzopen(in, "rb"); | 102 | file = gzopen(in, "rb"); |
@@ -108,13 +109,28 @@ void test_gzio(out, in, uncompr, uncomprLen) | |||
108 | if (uncomprLen != len) { | 109 | if (uncomprLen != len) { |
109 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); | 110 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
110 | } | 111 | } |
111 | gzclose(file); | ||
112 | |||
113 | if (strcmp((char*)uncompr, hello)) { | 112 | if (strcmp((char*)uncompr, hello)) { |
114 | fprintf(stderr, "bad gzread\n"); | 113 | fprintf(stderr, "bad gzread\n"); |
115 | } else { | 114 | } else { |
116 | printf("gzread(): %s\n", uncompr); | 115 | printf("gzread(): %s\n", uncompr); |
117 | } | 116 | } |
117 | |||
118 | pos = gzseek(file, -7L, SEEK_CUR); | ||
119 | if (pos != 7 || gztell(file) != pos) { | ||
120 | fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", | ||
121 | pos, gztell(file)); | ||
122 | } | ||
123 | uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); | ||
124 | if (uncomprLen != 7) { | ||
125 | fprintf(stderr, "gzread err after gzseek: %s\n", gzerror(file, &err)); | ||
126 | } | ||
127 | if (strcmp((char*)uncompr, hello+7)) { | ||
128 | fprintf(stderr, "bad gzread after gzseek\n"); | ||
129 | } else { | ||
130 | printf("gzread() after gzseek: %s\n", uncompr); | ||
131 | } | ||
132 | |||
133 | gzclose(file); | ||
118 | } | 134 | } |
119 | 135 | ||
120 | /* =========================================================================== | 136 | /* =========================================================================== |
@@ -171,12 +187,13 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen) | |||
171 | d_stream.zfree = (free_func)0; | 187 | d_stream.zfree = (free_func)0; |
172 | d_stream.opaque = (voidpf)0; | 188 | d_stream.opaque = (voidpf)0; |
173 | 189 | ||
174 | err = inflateInit(&d_stream); | ||
175 | CHECK_ERR(err, "inflateInit"); | ||
176 | |||
177 | d_stream.next_in = compr; | 190 | d_stream.next_in = compr; |
191 | d_stream.avail_in = 0; | ||
178 | d_stream.next_out = uncompr; | 192 | d_stream.next_out = uncompr; |
179 | 193 | ||
194 | err = inflateInit(&d_stream); | ||
195 | CHECK_ERR(err, "inflateInit"); | ||
196 | |||
180 | while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { | 197 | while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { |
181 | d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ | 198 | d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ |
182 | err = inflate(&d_stream, Z_NO_FLUSH); | 199 | err = inflate(&d_stream, Z_NO_FLUSH); |
@@ -263,12 +280,12 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) | |||
263 | d_stream.zfree = (free_func)0; | 280 | d_stream.zfree = (free_func)0; |
264 | d_stream.opaque = (voidpf)0; | 281 | d_stream.opaque = (voidpf)0; |
265 | 282 | ||
266 | err = inflateInit(&d_stream); | ||
267 | CHECK_ERR(err, "inflateInit"); | ||
268 | |||
269 | d_stream.next_in = compr; | 283 | d_stream.next_in = compr; |
270 | d_stream.avail_in = (uInt)comprLen; | 284 | d_stream.avail_in = (uInt)comprLen; |
271 | 285 | ||
286 | err = inflateInit(&d_stream); | ||
287 | CHECK_ERR(err, "inflateInit"); | ||
288 | |||
272 | for (;;) { | 289 | for (;;) { |
273 | d_stream.next_out = uncompr; /* discard the output */ | 290 | d_stream.next_out = uncompr; /* discard the output */ |
274 | d_stream.avail_out = (uInt)uncomprLen; | 291 | d_stream.avail_out = (uInt)uncomprLen; |
@@ -339,12 +356,13 @@ void test_sync(compr, comprLen, uncompr, uncomprLen) | |||
339 | d_stream.zfree = (free_func)0; | 356 | d_stream.zfree = (free_func)0; |
340 | d_stream.opaque = (voidpf)0; | 357 | d_stream.opaque = (voidpf)0; |
341 | 358 | ||
359 | d_stream.next_in = compr; | ||
360 | d_stream.avail_in = 2; /* just read the zlib header */ | ||
361 | |||
342 | err = inflateInit(&d_stream); | 362 | err = inflateInit(&d_stream); |
343 | CHECK_ERR(err, "inflateInit"); | 363 | CHECK_ERR(err, "inflateInit"); |
344 | 364 | ||
345 | d_stream.next_in = compr; | ||
346 | d_stream.next_out = uncompr; | 365 | d_stream.next_out = uncompr; |
347 | d_stream.avail_in = 2; /* just read the zlib header */ | ||
348 | d_stream.avail_out = (uInt)uncomprLen; | 366 | d_stream.avail_out = (uInt)uncomprLen; |
349 | 367 | ||
350 | inflate(&d_stream, Z_NO_FLUSH); | 368 | inflate(&d_stream, Z_NO_FLUSH); |
@@ -417,12 +435,12 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) | |||
417 | d_stream.zfree = (free_func)0; | 435 | d_stream.zfree = (free_func)0; |
418 | d_stream.opaque = (voidpf)0; | 436 | d_stream.opaque = (voidpf)0; |
419 | 437 | ||
420 | err = inflateInit(&d_stream); | ||
421 | CHECK_ERR(err, "inflateInit"); | ||
422 | |||
423 | d_stream.next_in = compr; | 438 | d_stream.next_in = compr; |
424 | d_stream.avail_in = (uInt)comprLen; | 439 | d_stream.avail_in = (uInt)comprLen; |
425 | 440 | ||
441 | err = inflateInit(&d_stream); | ||
442 | CHECK_ERR(err, "inflateInit"); | ||
443 | |||
426 | d_stream.next_out = uncompr; | 444 | d_stream.next_out = uncompr; |
427 | d_stream.avail_out = (uInt)uncomprLen; | 445 | d_stream.avail_out = (uInt)uncomprLen; |
428 | 446 | ||
@@ -461,8 +479,9 @@ int main(argc, argv) | |||
461 | Byte *compr, *uncompr; | 479 | Byte *compr, *uncompr; |
462 | uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ | 480 | uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ |
463 | uLong uncomprLen = comprLen; | 481 | uLong uncomprLen = comprLen; |
482 | static const char* myVersion = ZLIB_VERSION; | ||
464 | 483 | ||
465 | if (zlibVersion()[0] != ZLIB_VERSION[0]) { | 484 | if (zlibVersion()[0] != myVersion[0]) { |
466 | fprintf(stderr, "incompatible zlib version\n"); | 485 | fprintf(stderr, "incompatible zlib version\n"); |
467 | exit(1); | 486 | exit(1); |
468 | 487 | ||
@@ -479,7 +498,6 @@ int main(argc, argv) | |||
479 | printf("out of memory\n"); | 498 | printf("out of memory\n"); |
480 | exit(1); | 499 | exit(1); |
481 | } | 500 | } |
482 | |||
483 | test_compress(compr, comprLen, uncompr, uncomprLen); | 501 | test_compress(compr, comprLen, uncompr, uncomprLen); |
484 | 502 | ||
485 | test_gzio((argc > 1 ? argv[1] : "foo.gz"), | 503 | test_gzio((argc > 1 ? argv[1] : "foo.gz"), |
@@ -1,9 +1,11 @@ | |||
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-1998 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 | * | ||
5 | * Compile this file with -DNO_DEFLATE to avoid the compression code. | ||
4 | */ | 6 | */ |
5 | 7 | ||
6 | /* $Id: gzio.c,v 1.14 1996/07/24 13:41:01 me Exp $ */ | 8 | /* @(#) $Id$ */ |
7 | 9 | ||
8 | #include <stdio.h> | 10 | #include <stdio.h> |
9 | 11 | ||
@@ -38,10 +40,12 @@ typedef struct gz_stream { | |||
38 | char *path; /* path name for debugging only */ | 40 | char *path; /* path name for debugging only */ |
39 | int transparent; /* 1 if input file is not a .gz file */ | 41 | int transparent; /* 1 if input file is not a .gz file */ |
40 | char mode; /* 'w' or 'r' */ | 42 | char mode; /* 'w' or 'r' */ |
43 | long startpos; /* start of compressed data in file (header skipped) */ | ||
41 | } gz_stream; | 44 | } gz_stream; |
42 | 45 | ||
43 | 46 | ||
44 | local gzFile gz_open OF((const char *path, const char *mode, int fd)); | 47 | local gzFile gz_open OF((const char *path, const char *mode, int fd)); |
48 | local int do_flush OF((gzFile file, int flush)); | ||
45 | local int get_byte OF((gz_stream *s)); | 49 | local int get_byte OF((gz_stream *s)); |
46 | local void check_header OF((gz_stream *s)); | 50 | local void check_header OF((gz_stream *s)); |
47 | local int destroy OF((gz_stream *s)); | 51 | local int destroy OF((gz_stream *s)); |
@@ -64,6 +68,7 @@ local gzFile gz_open (path, mode, fd) | |||
64 | { | 68 | { |
65 | int err; | 69 | int err; |
66 | int level = Z_DEFAULT_COMPRESSION; /* compression level */ | 70 | int level = Z_DEFAULT_COMPRESSION; /* compression level */ |
71 | int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ | ||
67 | char *p = (char*)mode; | 72 | char *p = (char*)mode; |
68 | gz_stream *s; | 73 | gz_stream *s; |
69 | char fmode[80]; /* copy of mode, without the compression level */ | 74 | char fmode[80]; /* copy of mode, without the compression level */ |
@@ -99,6 +104,10 @@ local gzFile gz_open (path, mode, fd) | |||
99 | if (*p == 'w' || *p == 'a') s->mode = 'w'; | 104 | if (*p == 'w' || *p == 'a') s->mode = 'w'; |
100 | if (*p >= '0' && *p <= '9') { | 105 | if (*p >= '0' && *p <= '9') { |
101 | level = *p - '0'; | 106 | level = *p - '0'; |
107 | } else if (*p == 'f') { | ||
108 | strategy = Z_FILTERED; | ||
109 | } else if (*p == 'h') { | ||
110 | strategy = Z_HUFFMAN_ONLY; | ||
102 | } else { | 111 | } else { |
103 | *m++ = *p; /* copy the mode */ | 112 | *m++ = *p; /* copy the mode */ |
104 | } | 113 | } |
@@ -106,19 +115,24 @@ local gzFile gz_open (path, mode, fd) | |||
106 | if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; | 115 | if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; |
107 | 116 | ||
108 | if (s->mode == 'w') { | 117 | if (s->mode == 'w') { |
118 | #ifdef NO_DEFLATE | ||
119 | err = Z_STREAM_ERROR; | ||
120 | #else | ||
109 | err = deflateInit2(&(s->stream), level, | 121 | err = deflateInit2(&(s->stream), level, |
110 | Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0); | 122 | Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy); |
111 | /* windowBits is passed < 0 to suppress zlib header */ | 123 | /* windowBits is passed < 0 to suppress zlib header */ |
112 | 124 | ||
113 | s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); | 125 | s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); |
114 | 126 | #endif | |
115 | if (err != Z_OK || s->outbuf == Z_NULL) { | 127 | if (err != Z_OK || s->outbuf == Z_NULL) { |
116 | return destroy(s), (gzFile)Z_NULL; | 128 | return destroy(s), (gzFile)Z_NULL; |
117 | } | 129 | } |
118 | } else { | 130 | } else { |
119 | err = inflateInit2(&(s->stream), -MAX_WBITS); | ||
120 | s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); | 131 | s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); |
121 | 132 | ||
133 | err = inflateInit2(&(s->stream), -MAX_WBITS); | ||
134 | /* windowBits is passed < 0 to tell that there is no zlib header */ | ||
135 | |||
122 | if (err != Z_OK || s->inbuf == Z_NULL) { | 136 | if (err != Z_OK || s->inbuf == Z_NULL) { |
123 | return destroy(s), (gzFile)Z_NULL; | 137 | return destroy(s), (gzFile)Z_NULL; |
124 | } | 138 | } |
@@ -126,7 +140,7 @@ local gzFile gz_open (path, mode, fd) | |||
126 | s->stream.avail_out = Z_BUFSIZE; | 140 | s->stream.avail_out = Z_BUFSIZE; |
127 | 141 | ||
128 | errno = 0; | 142 | errno = 0; |
129 | s->file = fd < 0 ? FOPEN(path, fmode) : (FILE*)fdopen(fd, fmode); | 143 | s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); |
130 | 144 | ||
131 | if (s->file == NULL) { | 145 | if (s->file == NULL) { |
132 | return destroy(s), (gzFile)Z_NULL; | 146 | return destroy(s), (gzFile)Z_NULL; |
@@ -136,16 +150,19 @@ local gzFile gz_open (path, mode, fd) | |||
136 | */ | 150 | */ |
137 | fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], | 151 | fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], |
138 | Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); | 152 | Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); |
153 | s->startpos = ftell(s->file); | ||
139 | } else { | 154 | } else { |
140 | check_header(s); /* skip the .gz header */ | 155 | check_header(s); /* skip the .gz header */ |
156 | s->startpos = (ftell(s->file) - s->stream.avail_in); | ||
141 | } | 157 | } |
158 | |||
142 | return (gzFile)s; | 159 | return (gzFile)s; |
143 | } | 160 | } |
144 | 161 | ||
145 | /* =========================================================================== | 162 | /* =========================================================================== |
146 | Opens a gzip (.gz) file for reading or writing. | 163 | Opens a gzip (.gz) file for reading or writing. |
147 | */ | 164 | */ |
148 | gzFile gzopen (path, mode) | 165 | gzFile EXPORT gzopen (path, mode) |
149 | const char *path; | 166 | const char *path; |
150 | const char *mode; | 167 | const char *mode; |
151 | { | 168 | { |
@@ -156,7 +173,7 @@ gzFile gzopen (path, mode) | |||
156 | Associate a gzFile with the file descriptor fd. fd is not dup'ed here | 173 | Associate a gzFile with the file descriptor fd. fd is not dup'ed here |
157 | to mimic the behavio(u)r of fdopen. | 174 | to mimic the behavio(u)r of fdopen. |
158 | */ | 175 | */ |
159 | gzFile gzdopen (fd, mode) | 176 | gzFile EXPORT gzdopen (fd, mode) |
160 | int fd; | 177 | int fd; |
161 | const char *mode; | 178 | const char *mode; |
162 | { | 179 | { |
@@ -169,6 +186,31 @@ gzFile gzdopen (fd, mode) | |||
169 | } | 186 | } |
170 | 187 | ||
171 | /* =========================================================================== | 188 | /* =========================================================================== |
189 | * Update the compression level and strategy | ||
190 | */ | ||
191 | int EXPORT gzsetparams (file, level, strategy) | ||
192 | gzFile file; | ||
193 | int level; | ||
194 | int strategy; | ||
195 | { | ||
196 | gz_stream *s = (gz_stream*)file; | ||
197 | |||
198 | if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; | ||
199 | |||
200 | /* Make room to allow flushing */ | ||
201 | if (s->stream.avail_out == 0) { | ||
202 | |||
203 | s->stream.next_out = s->outbuf; | ||
204 | if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { | ||
205 | s->z_err = Z_ERRNO; | ||
206 | } | ||
207 | s->stream.avail_out = Z_BUFSIZE; | ||
208 | } | ||
209 | |||
210 | return deflateParams (&(s->stream), level, strategy); | ||
211 | } | ||
212 | |||
213 | /* =========================================================================== | ||
172 | Read a byte from a gz_stream; update next_in and avail_in. Return EOF | 214 | Read a byte from a gz_stream; update next_in and avail_in. Return EOF |
173 | for end of file. | 215 | for end of file. |
174 | IN assertion: the stream s has been sucessfully opened for reading. | 216 | IN assertion: the stream s has been sucessfully opened for reading. |
@@ -212,8 +254,11 @@ local void check_header(s) | |||
212 | for (len = 0; len < 2; len++) { | 254 | for (len = 0; len < 2; len++) { |
213 | c = get_byte(s); | 255 | c = get_byte(s); |
214 | if (c != gz_magic[len]) { | 256 | if (c != gz_magic[len]) { |
215 | s->transparent = 1; | 257 | if (len != 0) s->stream.avail_in++, s->stream.next_in--; |
216 | if (c != EOF) s->stream.avail_in++, s->stream.next_in--; | 258 | if (c != EOF) { |
259 | s->stream.avail_in++, s->stream.next_in--; | ||
260 | s->transparent = 1; | ||
261 | } | ||
217 | s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END; | 262 | s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END; |
218 | return; | 263 | return; |
219 | } | 264 | } |
@@ -260,14 +305,21 @@ local int destroy (s) | |||
260 | TRYFREE(s->msg); | 305 | TRYFREE(s->msg); |
261 | 306 | ||
262 | if (s->stream.state != NULL) { | 307 | if (s->stream.state != NULL) { |
263 | if (s->mode == 'w') { | 308 | if (s->mode == 'w') { |
264 | err = deflateEnd(&(s->stream)); | 309 | #ifdef NO_DEFLATE |
265 | } else if (s->mode == 'r') { | 310 | err = Z_STREAM_ERROR; |
266 | err = inflateEnd(&(s->stream)); | 311 | #else |
267 | } | 312 | err = deflateEnd(&(s->stream)); |
313 | #endif | ||
314 | } else if (s->mode == 'r') { | ||
315 | err = inflateEnd(&(s->stream)); | ||
316 | } | ||
268 | } | 317 | } |
269 | if (s->file != NULL && fclose(s->file)) { | 318 | if (s->file != NULL && fclose(s->file)) { |
270 | err = Z_ERRNO; | 319 | #ifdef ESPIPE |
320 | if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ | ||
321 | #endif | ||
322 | err = Z_ERRNO; | ||
271 | } | 323 | } |
272 | if (s->z_err < 0) err = s->z_err; | 324 | if (s->z_err < 0) err = s->z_err; |
273 | 325 | ||
@@ -282,13 +334,13 @@ local int destroy (s) | |||
282 | Reads the given number of uncompressed bytes from the compressed file. | 334 | 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). | 335 | gzread returns the number of bytes actually read (0 for end of file). |
284 | */ | 336 | */ |
285 | int gzread (file, buf, len) | 337 | int EXPORT gzread (file, buf, len) |
286 | gzFile file; | 338 | gzFile file; |
287 | voidp buf; | 339 | voidp buf; |
288 | unsigned len; | 340 | unsigned len; |
289 | { | 341 | { |
290 | gz_stream *s = (gz_stream*)file; | 342 | gz_stream *s = (gz_stream*)file; |
291 | Bytef *start = buf; /* starting point for crc computation */ | 343 | Bytef *start = (Bytef*)buf; /* starting point for crc computation */ |
292 | Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ | 344 | Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ |
293 | 345 | ||
294 | if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; | 346 | if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; |
@@ -296,7 +348,8 @@ int gzread (file, buf, len) | |||
296 | if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; | 348 | if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; |
297 | if (s->z_err == Z_STREAM_END) return 0; /* EOF */ | 349 | if (s->z_err == Z_STREAM_END) return 0; /* EOF */ |
298 | 350 | ||
299 | s->stream.next_out = next_out = buf; | 351 | next_out = (Byte*)buf; |
352 | s->stream.next_out = (Bytef*)buf; | ||
300 | s->stream.avail_out = len; | 353 | s->stream.avail_out = len; |
301 | 354 | ||
302 | while (s->stream.avail_out != 0) { | 355 | while (s->stream.avail_out != 0) { |
@@ -345,7 +398,12 @@ int gzread (file, buf, len) | |||
345 | /* Check for concatenated .gz files: */ | 398 | /* Check for concatenated .gz files: */ |
346 | check_header(s); | 399 | check_header(s); |
347 | if (s->z_err == Z_OK) { | 400 | if (s->z_err == Z_OK) { |
401 | uLong total_in = s->stream.total_in; | ||
402 | uLong total_out = s->stream.total_out; | ||
403 | |||
348 | inflateReset(&(s->stream)); | 404 | inflateReset(&(s->stream)); |
405 | s->stream.total_in = total_in; | ||
406 | s->stream.total_out = total_out; | ||
349 | s->crc = crc32(0L, Z_NULL, 0); | 407 | s->crc = crc32(0L, Z_NULL, 0); |
350 | } | 408 | } |
351 | } | 409 | } |
@@ -357,11 +415,26 @@ int gzread (file, buf, len) | |||
357 | return (int)(len - s->stream.avail_out); | 415 | return (int)(len - s->stream.avail_out); |
358 | } | 416 | } |
359 | 417 | ||
418 | |||
419 | /* =========================================================================== | ||
420 | Reads one byte from the compressed file. gzgetc returns this byte | ||
421 | or -1 in case of end of file or error. | ||
422 | */ | ||
423 | int EXPORT gzgetc(file) | ||
424 | gzFile file; | ||
425 | { | ||
426 | int c; | ||
427 | |||
428 | return gzread(file, &c, 1) == 1 ? c : -1; | ||
429 | } | ||
430 | |||
431 | |||
432 | #ifndef NO_DEFLATE | ||
360 | /* =========================================================================== | 433 | /* =========================================================================== |
361 | Writes the given number of uncompressed bytes into the compressed file. | 434 | Writes the given number of uncompressed bytes into the compressed file. |
362 | gzwrite returns the number of bytes actually written (0 in case of error). | 435 | gzwrite returns the number of bytes actually written (0 in case of error). |
363 | */ | 436 | */ |
364 | int gzwrite (file, buf, len) | 437 | int EXPORT gzwrite (file, buf, len) |
365 | gzFile file; | 438 | gzFile file; |
366 | const voidp buf; | 439 | const voidp buf; |
367 | unsigned len; | 440 | unsigned len; |
@@ -370,7 +443,7 @@ int gzwrite (file, buf, len) | |||
370 | 443 | ||
371 | if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; | 444 | if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; |
372 | 445 | ||
373 | s->stream.next_in = buf; | 446 | s->stream.next_in = (Bytef*)buf; |
374 | s->stream.avail_in = len; | 447 | s->stream.avail_in = len; |
375 | 448 | ||
376 | while (s->stream.avail_in != 0) { | 449 | while (s->stream.avail_in != 0) { |
@@ -387,18 +460,79 @@ int gzwrite (file, buf, len) | |||
387 | s->z_err = deflate(&(s->stream), Z_NO_FLUSH); | 460 | s->z_err = deflate(&(s->stream), Z_NO_FLUSH); |
388 | if (s->z_err != Z_OK) break; | 461 | if (s->z_err != Z_OK) break; |
389 | } | 462 | } |
390 | s->crc = crc32(s->crc, buf, len); | 463 | s->crc = crc32(s->crc, (const Bytef *)buf, len); |
391 | 464 | ||
392 | return (int)(len - s->stream.avail_in); | 465 | return (int)(len - s->stream.avail_in); |
393 | } | 466 | } |
394 | 467 | ||
395 | /* =========================================================================== | 468 | /* =========================================================================== |
469 | Converts, formats, and writes the args to the compressed file under | ||
470 | control of the format string, as in fprintf. gzprintf returns the number of | ||
471 | uncompressed bytes actually written (0 in case of error). | ||
472 | */ | ||
473 | #ifdef STDC | ||
474 | #include <stdarg.h> | ||
475 | |||
476 | int EXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) | ||
477 | { | ||
478 | char buf[Z_BUFSIZE]; | ||
479 | va_list va; | ||
480 | int len; | ||
481 | |||
482 | va_start(va, format); | ||
483 | #ifdef HAS_vsnprintf | ||
484 | len = vsnprintf(buf, sizeof(buf), format, va); | ||
485 | #else | ||
486 | len = vsprintf(buf, format, va); | ||
487 | #endif | ||
488 | va_end(va); | ||
489 | if (len <= 0) return 0; | ||
490 | |||
491 | return gzwrite(file, buf, (unsigned)len); | ||
492 | } | ||
493 | #else /* not ANSI C */ | ||
494 | |||
495 | int EXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | ||
496 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) | ||
497 | gzFile file; | ||
498 | const char *format; | ||
499 | int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | ||
500 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; | ||
501 | { | ||
502 | char buf[Z_BUFSIZE]; | ||
503 | int len; | ||
504 | |||
505 | #ifdef HAS_snprintf | ||
506 | snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, | ||
507 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | ||
508 | #else | ||
509 | sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, | ||
510 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | ||
511 | #endif | ||
512 | len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */ | ||
513 | if (len <= 0) return 0; | ||
514 | |||
515 | return gzwrite(file, buf, len); | ||
516 | } | ||
517 | #endif | ||
518 | |||
519 | /* =========================================================================== | ||
520 | Writes c, converted to an unsigned char, into the compressed file. | ||
521 | gzputc returns the value that was written, or -1 in case of error. | ||
522 | */ | ||
523 | int EXPORT gzputc(file, c) | ||
524 | gzFile file; | ||
525 | int c; | ||
526 | { | ||
527 | return gzwrite(file, &c, 1) == 1 ? c : -1; | ||
528 | } | ||
529 | |||
530 | |||
531 | /* =========================================================================== | ||
396 | Flushes all pending output into the compressed file. The parameter | 532 | Flushes all pending output into the compressed file. The parameter |
397 | flush is as in the deflate() function. | 533 | flush is as in the deflate() function. |
398 | gzflush should be called only when strictly necessary because it can | ||
399 | degrade compression. | ||
400 | */ | 534 | */ |
401 | int gzflush (file, flush) | 535 | local int do_flush (file, flush) |
402 | gzFile file; | 536 | gzFile file; |
403 | int flush; | 537 | int flush; |
404 | { | 538 | { |
@@ -424,6 +558,9 @@ int gzflush (file, flush) | |||
424 | if (done) break; | 558 | if (done) break; |
425 | s->z_err = deflate(&(s->stream), flush); | 559 | s->z_err = deflate(&(s->stream), flush); |
426 | 560 | ||
561 | /* Ignore the second of two consecutive flushes: */ | ||
562 | if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; | ||
563 | |||
427 | /* deflate has finished flushing only when it hasn't used up | 564 | /* deflate has finished flushing only when it hasn't used up |
428 | * all the available space in the output buffer: | 565 | * all the available space in the output buffer: |
429 | */ | 566 | */ |
@@ -431,9 +568,154 @@ int gzflush (file, flush) | |||
431 | 568 | ||
432 | if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; | 569 | if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; |
433 | } | 570 | } |
571 | return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; | ||
572 | } | ||
573 | |||
574 | int EXPORT gzflush (file, flush) | ||
575 | gzFile file; | ||
576 | int flush; | ||
577 | { | ||
578 | gz_stream *s = (gz_stream*)file; | ||
579 | int err = do_flush (file, flush); | ||
580 | |||
581 | if (err) return err; | ||
434 | fflush(s->file); | 582 | fflush(s->file); |
435 | return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; | 583 | return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; |
436 | } | 584 | } |
585 | #endif /* NO_DEFLATE */ | ||
586 | |||
587 | /* =========================================================================== | ||
588 | Sets the starting position for the next gzread or gzwrite on the given | ||
589 | compressed file. The offset represents a number of bytes in the | ||
590 | gzseek returns the resulting offset location as measured in bytes from | ||
591 | the beginning of the uncompressed stream, or -1 in case of error. | ||
592 | SEEK_END is not implemented, returns error. | ||
593 | In this version of the library, gzseek can be extremely slow. | ||
594 | */ | ||
595 | z_off_t EXPORT gzseek (file, offset, whence) | ||
596 | gzFile file; | ||
597 | z_off_t offset; | ||
598 | int whence; | ||
599 | { | ||
600 | gz_stream *s = (gz_stream*)file; | ||
601 | |||
602 | if (s == NULL || whence == SEEK_END || s->z_err == Z_ERRNO) return -1L; | ||
603 | |||
604 | s->z_err = Z_OK; | ||
605 | s->z_eof = 0; | ||
606 | |||
607 | if (s->mode == 'w') { | ||
608 | #ifdef NO_DEFLATE | ||
609 | return -1L; | ||
610 | #else | ||
611 | if (whence == SEEK_SET) { | ||
612 | offset -= s->stream.total_out; | ||
613 | } | ||
614 | if (offset < 0) return -1L; | ||
615 | |||
616 | /* At this point, offset is the number of zero bytes to write. */ | ||
617 | if (s->inbuf == Z_NULL) { | ||
618 | s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ | ||
619 | zmemzero(s->inbuf, Z_BUFSIZE); | ||
620 | } | ||
621 | while (offset > 0) { | ||
622 | uInt size = Z_BUFSIZE; | ||
623 | if (offset < Z_BUFSIZE) size = (uInt)offset; | ||
624 | |||
625 | size = gzwrite(file, s->inbuf, size); | ||
626 | if (size == 0) return -1L; | ||
627 | |||
628 | offset -= size; | ||
629 | } | ||
630 | return s->stream.total_in; | ||
631 | #endif | ||
632 | } | ||
633 | /* Rest of function is for reading only */ | ||
634 | |||
635 | if (s->z_err == Z_DATA_ERROR) return -1L; | ||
636 | |||
637 | /* compute absolute position */ | ||
638 | if (whence == SEEK_CUR) { | ||
639 | offset += s->stream.total_out; | ||
640 | } | ||
641 | if (offset < 0) return -1L; | ||
642 | |||
643 | if (s->transparent) { | ||
644 | /* map to fseek */ | ||
645 | s->stream.avail_in = 0; | ||
646 | s->stream.next_in = s->inbuf; | ||
647 | if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; | ||
648 | return offset; | ||
649 | } | ||
650 | |||
651 | /* For a negative seek, rewind and use positive seek */ | ||
652 | if ((uLong)offset >= s->stream.total_out) { | ||
653 | offset -= s->stream.total_out; | ||
654 | } else if (gzrewind(file) < 0) { | ||
655 | return -1L; | ||
656 | } | ||
657 | /* offset is now the number of bytes to skip. */ | ||
658 | |||
659 | if (offset != 0 && s->outbuf == Z_NULL) { | ||
660 | s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); | ||
661 | } | ||
662 | while (offset > 0) { | ||
663 | int size = Z_BUFSIZE; | ||
664 | if (offset < Z_BUFSIZE) size = (int)offset; | ||
665 | |||
666 | size = gzread(file, s->outbuf, (uInt)size); | ||
667 | if (size <= 0) return -1L; | ||
668 | offset -= size; | ||
669 | } | ||
670 | return s->stream.total_out; | ||
671 | } | ||
672 | |||
673 | /* =========================================================================== | ||
674 | Rewinds input file. | ||
675 | */ | ||
676 | int EXPORT gzrewind (file) | ||
677 | gzFile file; | ||
678 | { | ||
679 | gz_stream *s = (gz_stream*)file; | ||
680 | |||
681 | if (s == NULL || s->mode != 'r') return -1; | ||
682 | |||
683 | s->z_err = Z_OK; | ||
684 | s->z_eof = 0; | ||
685 | s->stream.avail_in = 0; | ||
686 | s->stream.next_in = s->inbuf; | ||
687 | |||
688 | if (s->startpos == 0) { /* not a compressed file */ | ||
689 | rewind(s->file); | ||
690 | return 0; | ||
691 | } | ||
692 | |||
693 | (void) inflateReset(&s->stream); | ||
694 | return fseek(s->file, s->startpos, SEEK_SET); | ||
695 | } | ||
696 | |||
697 | /* =========================================================================== | ||
698 | Returns the starting position for the next gzread or gzwrite on the | ||
699 | given compressed file. This position represents a number of bytes in the | ||
700 | uncompressed data stream. | ||
701 | */ | ||
702 | z_off_t EXPORT gztell (file) | ||
703 | gzFile file; | ||
704 | { | ||
705 | return gzseek(file, 0L, SEEK_CUR); | ||
706 | } | ||
707 | |||
708 | /* =========================================================================== | ||
709 | Returns 1 when EOF has previously been detected reading the given | ||
710 | input stream, otherwise zero. | ||
711 | */ | ||
712 | int EXPORT gzeof (file) | ||
713 | gzFile file; | ||
714 | { | ||
715 | gz_stream *s = (gz_stream*)file; | ||
716 | |||
717 | return (s == NULL || s->mode != 'r') ? 0 : s->z_eof; | ||
718 | } | ||
437 | 719 | ||
438 | /* =========================================================================== | 720 | /* =========================================================================== |
439 | Outputs a long in LSB order to the given file | 721 | Outputs a long in LSB order to the given file |
@@ -470,7 +752,7 @@ local uLong getLong (s) | |||
470 | Flushes all pending output if necessary, closes the compressed file | 752 | Flushes all pending output if necessary, closes the compressed file |
471 | and deallocates all the (de)compression state. | 753 | and deallocates all the (de)compression state. |
472 | */ | 754 | */ |
473 | int gzclose (file) | 755 | int EXPORT gzclose (file) |
474 | gzFile file; | 756 | gzFile file; |
475 | { | 757 | { |
476 | int err; | 758 | int err; |
@@ -479,14 +761,17 @@ int gzclose (file) | |||
479 | if (s == NULL) return Z_STREAM_ERROR; | 761 | if (s == NULL) return Z_STREAM_ERROR; |
480 | 762 | ||
481 | if (s->mode == 'w') { | 763 | if (s->mode == 'w') { |
482 | err = gzflush (file, Z_FINISH); | 764 | #ifdef NO_DEFLATE |
483 | if (err != Z_OK) return destroy(file); | 765 | return Z_STREAM_ERROR; |
766 | #else | ||
767 | err = do_flush (file, Z_FINISH); | ||
768 | if (err != Z_OK) return destroy((gz_stream*)file); | ||
484 | 769 | ||
485 | putLong (s->file, s->crc); | 770 | putLong (s->file, s->crc); |
486 | putLong (s->file, s->stream.total_in); | 771 | putLong (s->file, s->stream.total_in); |
487 | 772 | #endif | |
488 | } | 773 | } |
489 | return destroy(file); | 774 | return destroy((gz_stream*)file); |
490 | } | 775 | } |
491 | 776 | ||
492 | /* =========================================================================== | 777 | /* =========================================================================== |
@@ -496,7 +781,7 @@ int gzclose (file) | |||
496 | errnum is set to Z_ERRNO and the application may consult errno | 781 | errnum is set to Z_ERRNO and the application may consult errno |
497 | to get the exact error code. | 782 | to get the exact error code. |
498 | */ | 783 | */ |
499 | const char* gzerror (file, errnum) | 784 | const char* EXPORT gzerror (file, errnum) |
500 | gzFile file; | 785 | gzFile file; |
501 | int *errnum; | 786 | int *errnum; |
502 | { | 787 | { |
@@ -66,7 +66,7 @@ inflate_blocks_statef *s; | |||
66 | z_streamp z; | 66 | z_streamp z; |
67 | uLongf *c; | 67 | uLongf *c; |
68 | { | 68 | { |
69 | if (s->checkfn != Z_NULL) | 69 | if (c != Z_NULL) |
70 | *c = s->check; | 70 | *c = s->check; |
71 | if (s->mode == BTREE || s->mode == DTREE) | 71 | if (s->mode == BTREE || s->mode == DTREE) |
72 | ZFREE(z, s->sub.trees.blens); | 72 | ZFREE(z, s->sub.trees.blens); |
@@ -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 | z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); |
85 | Trace((stderr, "inflate: blocks reset\n")); | 85 | Trace((stderr, "inflate: blocks reset\n")); |
86 | } | 86 | } |
87 | 87 | ||
@@ -105,7 +105,7 @@ uInt w; | |||
105 | s->checkfn = c; | 105 | s->checkfn = c; |
106 | s->mode = TYPE; | 106 | s->mode = TYPE; |
107 | Trace((stderr, "inflate: blocks allocated\n")); | 107 | Trace((stderr, "inflate: blocks allocated\n")); |
108 | inflate_blocks_reset(s, z, &s->check); | 108 | inflate_blocks_reset(s, z, Z_NULL); |
109 | return s; | 109 | return s; |
110 | } | 110 | } |
111 | 111 | ||
@@ -380,12 +380,11 @@ int r; | |||
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | int inflate_blocks_free(s, z, c) | 383 | int inflate_blocks_free(s, z) |
384 | inflate_blocks_statef *s; | 384 | inflate_blocks_statef *s; |
385 | z_streamp z; | 385 | z_streamp z; |
386 | uLongf *c; | ||
387 | { | 386 | { |
388 | inflate_blocks_reset(s, z, c); | 387 | inflate_blocks_reset(s, z, Z_NULL); |
389 | ZFREE(z, s->window); | 388 | ZFREE(z, s->window); |
390 | ZFREE(z, s); | 389 | ZFREE(z, s); |
391 | Trace((stderr, "inflate: blocks freed\n")); | 390 | Trace((stderr, "inflate: blocks freed\n")); |
@@ -401,3 +400,14 @@ uInt n; | |||
401 | zmemcpy((charf *)s->window, d, n); | 400 | zmemcpy((charf *)s->window, d, n); |
402 | s->read = s->write = s->window + n; | 401 | s->read = s->write = s->window + n; |
403 | } | 402 | } |
403 | |||
404 | |||
405 | /* Returns true if inflate is currently at the end of a block generated | ||
406 | * by Z_SYNC_FLUSH or Z_FULL_FLUSH. | ||
407 | * IN assertion: s != Z_NULL | ||
408 | */ | ||
409 | int inflate_blocks_sync_point(s) | ||
410 | inflate_blocks_statef *s; | ||
411 | { | ||
412 | return s->mode == LENS; | ||
413 | } | ||
@@ -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-1998 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 | ||
@@ -28,10 +28,12 @@ extern void inflate_blocks_reset OF(( | |||
28 | 28 | ||
29 | extern int inflate_blocks_free OF(( | 29 | extern int inflate_blocks_free OF(( |
30 | inflate_blocks_statef *, | 30 | inflate_blocks_statef *, |
31 | z_streamp , | 31 | z_streamp)); |
32 | uLongf *)); /* check value on output */ | ||
33 | 32 | ||
34 | extern void inflate_set_dictionary OF(( | 33 | extern void inflate_set_dictionary OF(( |
35 | inflate_blocks_statef *s, | 34 | inflate_blocks_statef *s, |
36 | const Bytef *d, /* dictionary */ | 35 | const Bytef *d, /* dictionary */ |
37 | uInt n)); /* dictionary length */ | 36 | uInt n)); /* dictionary length */ |
37 | |||
38 | extern int inflate_blocks_sync_point OF(( | ||
39 | inflate_blocks_statef *s)); | ||
@@ -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-1998 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 | ||
@@ -16,11 +16,7 @@ | |||
16 | #define exop word.what.Exop | 16 | #define exop word.what.Exop |
17 | #define bits word.what.Bits | 17 | #define bits word.what.Bits |
18 | 18 | ||
19 | /* inflate codes private state */ | 19 | typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ |
20 | struct inflate_codes_state { | ||
21 | |||
22 | /* mode */ | ||
23 | enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ | ||
24 | START, /* x: set up for LEN */ | 20 | START, /* x: set up for LEN */ |
25 | LEN, /* i: get length/literal/eob next */ | 21 | LEN, /* i: get length/literal/eob next */ |
26 | LENEXT, /* i: getting length extra (have base) */ | 22 | LENEXT, /* i: getting length extra (have base) */ |
@@ -31,7 +27,13 @@ struct inflate_codes_state { | |||
31 | WASH, /* o: got eob, possibly still output waiting */ | 27 | WASH, /* o: got eob, possibly still output waiting */ |
32 | END, /* x: got eob and all data flushed */ | 28 | END, /* x: got eob and all data flushed */ |
33 | BADCODE} /* x: got error */ | 29 | BADCODE} /* x: got error */ |
34 | mode; /* current inflate_codes mode */ | 30 | inflate_codes_mode; |
31 | |||
32 | /* inflate codes private state */ | ||
33 | struct inflate_codes_state { | ||
34 | |||
35 | /* mode */ | ||
36 | inflate_codes_mode mode; /* current inflate_codes mode */ | ||
35 | 37 | ||
36 | /* mode dependent information */ | 38 | /* mode dependent information */ |
37 | uInt len; | 39 | uInt len; |
@@ -235,6 +237,9 @@ int r; | |||
235 | r = Z_STREAM_ERROR; | 237 | r = Z_STREAM_ERROR; |
236 | LEAVE | 238 | LEAVE |
237 | } | 239 | } |
240 | #ifdef NEED_DUMMY_RETURN | ||
241 | return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ | ||
242 | #endif | ||
238 | } | 243 | } |
239 | 244 | ||
240 | 245 | ||
@@ -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-1998 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-1998 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.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-1998 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-1998 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,11 +8,7 @@ | |||
8 | 8 | ||
9 | struct inflate_blocks_state {int dummy;}; /* for buggy compilers */ | 9 | struct inflate_blocks_state {int dummy;}; /* for buggy compilers */ |
10 | 10 | ||
11 | /* inflate private state */ | 11 | typedef enum { |
12 | struct internal_state { | ||
13 | |||
14 | /* mode */ | ||
15 | enum { | ||
16 | METHOD, /* waiting for method byte */ | 12 | METHOD, /* waiting for method byte */ |
17 | FLAG, /* waiting for flag byte */ | 13 | FLAG, /* waiting for flag byte */ |
18 | DICT4, /* four dictionary check bytes to go */ | 14 | DICT4, /* four dictionary check bytes to go */ |
@@ -27,7 +23,13 @@ struct internal_state { | |||
27 | CHECK1, /* one check byte to go */ | 23 | CHECK1, /* one check byte to go */ |
28 | DONE, /* finished check, done */ | 24 | DONE, /* finished check, done */ |
29 | BAD} /* got an error--stay here */ | 25 | BAD} /* got an error--stay here */ |
30 | mode; /* current inflate mode */ | 26 | inflate_mode; |
27 | |||
28 | /* inflate private state */ | ||
29 | struct internal_state { | ||
30 | |||
31 | /* mode */ | ||
32 | inflate_mode mode; /* current inflate mode */ | ||
31 | 33 | ||
32 | /* mode dependent information */ | 34 | /* mode dependent information */ |
33 | union { | 35 | union { |
@@ -48,39 +50,35 @@ struct internal_state { | |||
48 | }; | 50 | }; |
49 | 51 | ||
50 | 52 | ||
51 | int inflateReset(z) | 53 | int EXPORT inflateReset(z) |
52 | z_streamp z; | 54 | z_streamp z; |
53 | { | 55 | { |
54 | uLong c; | ||
55 | |||
56 | if (z == Z_NULL || z->state == Z_NULL) | 56 | if (z == Z_NULL || z->state == Z_NULL) |
57 | return Z_STREAM_ERROR; | 57 | return Z_STREAM_ERROR; |
58 | z->total_in = z->total_out = 0; | 58 | z->total_in = z->total_out = 0; |
59 | z->msg = Z_NULL; | 59 | z->msg = Z_NULL; |
60 | z->state->mode = z->state->nowrap ? BLOCKS : METHOD; | 60 | z->state->mode = z->state->nowrap ? BLOCKS : METHOD; |
61 | inflate_blocks_reset(z->state->blocks, z, &c); | 61 | inflate_blocks_reset(z->state->blocks, z, Z_NULL); |
62 | Trace((stderr, "inflate: reset\n")); | 62 | Tracev((stderr, "inflate: reset\n")); |
63 | return Z_OK; | 63 | return Z_OK; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | int inflateEnd(z) | 67 | int EXPORT inflateEnd(z) |
68 | z_streamp z; | 68 | z_streamp z; |
69 | { | 69 | { |
70 | uLong c; | ||
71 | |||
72 | if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) | 70 | if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) |
73 | return Z_STREAM_ERROR; | 71 | return Z_STREAM_ERROR; |
74 | if (z->state->blocks != Z_NULL) | 72 | if (z->state->blocks != Z_NULL) |
75 | inflate_blocks_free(z->state->blocks, z, &c); | 73 | inflate_blocks_free(z->state->blocks, z); |
76 | ZFREE(z, z->state); | 74 | ZFREE(z, z->state); |
77 | z->state = Z_NULL; | 75 | z->state = Z_NULL; |
78 | Trace((stderr, "inflate: end\n")); | 76 | Tracev((stderr, "inflate: end\n")); |
79 | return Z_OK; | 77 | return Z_OK; |
80 | } | 78 | } |
81 | 79 | ||
82 | 80 | ||
83 | int inflateInit2_(z, w, version, stream_size) | 81 | int EXPORT inflateInit2_(z, w, version, stream_size) |
84 | z_streamp z; | 82 | z_streamp z; |
85 | int w; | 83 | int w; |
86 | const char *version; | 84 | const char *version; |
@@ -129,7 +127,7 @@ int stream_size; | |||
129 | inflateEnd(z); | 127 | inflateEnd(z); |
130 | return Z_MEM_ERROR; | 128 | return Z_MEM_ERROR; |
131 | } | 129 | } |
132 | Trace((stderr, "inflate: allocated\n")); | 130 | Tracev((stderr, "inflate: allocated\n")); |
133 | 131 | ||
134 | /* reset state */ | 132 | /* reset state */ |
135 | inflateReset(z); | 133 | inflateReset(z); |
@@ -137,7 +135,7 @@ int stream_size; | |||
137 | } | 135 | } |
138 | 136 | ||
139 | 137 | ||
140 | int inflateInit_(z, version, stream_size) | 138 | int EXPORT inflateInit_(z, version, stream_size) |
141 | z_streamp z; | 139 | z_streamp z; |
142 | const char *version; | 140 | const char *version; |
143 | int stream_size; | 141 | int stream_size; |
@@ -146,10 +144,10 @@ int stream_size; | |||
146 | } | 144 | } |
147 | 145 | ||
148 | 146 | ||
149 | #define NEEDBYTE {if(z->avail_in==0)return r;r=Z_OK;} | 147 | #define NEEDBYTE {if(z->avail_in==0)return r; if (f != Z_FINISH) r = Z_OK;} |
150 | #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) | 148 | #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) |
151 | 149 | ||
152 | int inflate(z, f) | 150 | int EXPORT inflate(z, f) |
153 | z_streamp z; | 151 | z_streamp z; |
154 | int f; | 152 | int f; |
155 | { | 153 | { |
@@ -188,7 +186,7 @@ int f; | |||
188 | z->state->sub.marker = 5; /* can't try inflateSync */ | 186 | z->state->sub.marker = 5; /* can't try inflateSync */ |
189 | break; | 187 | break; |
190 | } | 188 | } |
191 | Trace((stderr, "inflate: zlib header ok\n")); | 189 | Tracev((stderr, "inflate: zlib header ok\n")); |
192 | if (!(b & PRESET_DICT)) | 190 | if (!(b & PRESET_DICT)) |
193 | { | 191 | { |
194 | z->state->mode = BLOCKS; | 192 | z->state->mode = BLOCKS; |
@@ -227,7 +225,7 @@ int f; | |||
227 | break; | 225 | break; |
228 | } | 226 | } |
229 | if (r != Z_STREAM_END) | 227 | if (r != Z_STREAM_END) |
230 | return r; | 228 | return f == Z_FINISH && r == Z_OK ? Z_BUF_ERROR : r; |
231 | r = Z_OK; | 229 | r = Z_OK; |
232 | inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); | 230 | inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); |
233 | if (z->state->nowrap) | 231 | if (z->state->nowrap) |
@@ -236,6 +234,7 @@ int f; | |||
236 | break; | 234 | break; |
237 | } | 235 | } |
238 | z->state->mode = CHECK4; | 236 | z->state->mode = CHECK4; |
237 | if (f == Z_FINISH) r = Z_BUF_ERROR; | ||
239 | case CHECK4: | 238 | case CHECK4: |
240 | NEEDBYTE | 239 | NEEDBYTE |
241 | z->state->sub.check.need = (uLong)NEXTBYTE << 24; | 240 | z->state->sub.check.need = (uLong)NEXTBYTE << 24; |
@@ -259,7 +258,7 @@ int f; | |||
259 | z->state->sub.marker = 5; /* can't try inflateSync */ | 258 | z->state->sub.marker = 5; /* can't try inflateSync */ |
260 | break; | 259 | break; |
261 | } | 260 | } |
262 | Trace((stderr, "inflate: zlib check ok\n")); | 261 | Tracev((stderr, "inflate: zlib check ok\n")); |
263 | z->state->mode = DONE; | 262 | z->state->mode = DONE; |
264 | case DONE: | 263 | case DONE: |
265 | return Z_STREAM_END; | 264 | return Z_STREAM_END; |
@@ -268,10 +267,13 @@ int f; | |||
268 | default: | 267 | default: |
269 | return Z_STREAM_ERROR; | 268 | return Z_STREAM_ERROR; |
270 | } | 269 | } |
270 | #ifdef NEED_DUMMY_RETURN | ||
271 | return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ | ||
272 | #endif | ||
271 | } | 273 | } |
272 | 274 | ||
273 | 275 | ||
274 | int inflateSetDictionary(z, dictionary, dictLength) | 276 | int EXPORT inflateSetDictionary(z, dictionary, dictLength) |
275 | z_streamp z; | 277 | z_streamp z; |
276 | const Bytef *dictionary; | 278 | const Bytef *dictionary; |
277 | uInt dictLength; | 279 | uInt dictLength; |
@@ -295,7 +297,7 @@ uInt dictLength; | |||
295 | } | 297 | } |
296 | 298 | ||
297 | 299 | ||
298 | int inflateSync(z) | 300 | int EXPORT inflateSync(z) |
299 | z_streamp z; | 301 | z_streamp z; |
300 | { | 302 | { |
301 | uInt n; /* number of bytes to look at */ | 303 | uInt n; /* number of bytes to look at */ |
@@ -343,3 +345,19 @@ z_streamp z; | |||
343 | z->state->mode = BLOCKS; | 345 | z->state->mode = BLOCKS; |
344 | return Z_OK; | 346 | return Z_OK; |
345 | } | 347 | } |
348 | |||
349 | |||
350 | /* Returns true if inflate is currently at the end of a block generated | ||
351 | * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP | ||
352 | * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH | ||
353 | * but removes the length bytes of the resulting empty stored block. When | ||
354 | * decompressing, PPP checks that at the end of input packet, inflate is | ||
355 | * waiting for these length bytes. | ||
356 | */ | ||
357 | int EXPORT inflateSyncPoint(z) | ||
358 | z_streamp z; | ||
359 | { | ||
360 | if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL) | ||
361 | return Z_STREAM_ERROR; | ||
362 | return inflate_blocks_sync_point(z->state->blocks); | ||
363 | } | ||
@@ -6,7 +6,8 @@ | |||
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.5 Copyright 1995-1998 Mark Adler "; | 9 | const char inflate_copyright[] = |
10 | " inflate 1.0.7 Copyright 1995-1998 Mark Adler "; | ||
10 | /* | 11 | /* |
11 | If you use the zlib library in a product, an acknowledgment is welcome | 12 | 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 | 13 | in the documentation of your product. If for some reason you cannot |
@@ -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-1998 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-1998 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 | /* 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-1998 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 | /* 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-1998 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 | ||
@@ -13,7 +13,7 @@ | |||
13 | * or in pipe mode. | 13 | * or in pipe mode. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | /* $Id: minigzip.c,v 1.10 1996/07/24 13:41:04 me Exp $ */ | 16 | /* @(#) $Id$ */ |
17 | 17 | ||
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include "zlib.h" | 19 | #include "zlib.h" |
@@ -47,18 +47,19 @@ | |||
47 | #ifndef GZ_SUFFIX | 47 | #ifndef GZ_SUFFIX |
48 | # define GZ_SUFFIX ".gz" | 48 | # define GZ_SUFFIX ".gz" |
49 | #endif | 49 | #endif |
50 | #define SUFFIX_LEN sizeof(GZ_SUFFIX) | 50 | #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) |
51 | 51 | ||
52 | extern int unlink OF((const char *)); | 52 | extern int unlink OF((const char *)); |
53 | 53 | ||
54 | #define BUFLEN 4096 | 54 | #define BUFLEN 4096 |
55 | #define MAX_NAME_LEN 1024 | 55 | #define MAX_NAME_LEN 1024 |
56 | 56 | ||
57 | #define local static | 57 | #ifdef MAXSEG_64K |
58 | /* For MSDOS and other systems with limitation on stack size. For Unix, | 58 | # define local static |
59 | #define local | 59 | /* Needed for systems with limitation on stack size. */ |
60 | works also. | 60 | #else |
61 | */ | 61 | # define local |
62 | #endif | ||
62 | 63 | ||
63 | char *prog; | 64 | char *prog; |
64 | 65 | ||
@@ -201,7 +202,11 @@ void file_uncompress(file) | |||
201 | 202 | ||
202 | 203 | ||
203 | /* =========================================================================== | 204 | /* =========================================================================== |
204 | * Usage: minigzip [-d] [files...] | 205 | * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...] |
206 | * -d : decompress | ||
207 | * -f : compress with Z_FILTERED | ||
208 | * -h : compress with Z_HUFFMAN_ONLY | ||
209 | * -1 to -9 : compression level | ||
205 | */ | 210 | */ |
206 | 211 | ||
207 | int main(argc, argv) | 212 | int main(argc, argv) |
@@ -210,15 +215,26 @@ int main(argc, argv) | |||
210 | { | 215 | { |
211 | int uncompr = 0; | 216 | int uncompr = 0; |
212 | gzFile file; | 217 | gzFile file; |
218 | char outmode[20]; | ||
219 | |||
220 | strcpy(outmode, "wb6 "); | ||
213 | 221 | ||
214 | prog = argv[0]; | 222 | prog = argv[0]; |
215 | argc--, argv++; | 223 | argc--, argv++; |
216 | 224 | ||
217 | if (argc > 0) { | 225 | while (argc > 0) { |
218 | uncompr = (strcmp(*argv, "-d") == 0); | 226 | if (strcmp(*argv, "-d") == 0) |
219 | if (uncompr) { | 227 | uncompr = 1; |
220 | argc--, argv++; | 228 | else if (strcmp(*argv, "-f") == 0) |
221 | } | 229 | outmode[3] = 'f'; |
230 | else if (strcmp(*argv, "-h") == 0) | ||
231 | outmode[3] = 'h'; | ||
232 | else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && | ||
233 | (*argv)[2] == 0) | ||
234 | outmode[2] = (*argv)[1]; | ||
235 | else | ||
236 | break; | ||
237 | argc--, argv++; | ||
222 | } | 238 | } |
223 | if (argc == 0) { | 239 | if (argc == 0) { |
224 | SET_BINARY_MODE(stdin); | 240 | SET_BINARY_MODE(stdin); |
@@ -228,7 +244,7 @@ int main(argc, argv) | |||
228 | if (file == NULL) error("can't gzdopen stdin"); | 244 | if (file == NULL) error("can't gzdopen stdin"); |
229 | gz_uncompress(file, stdout); | 245 | gz_uncompress(file, stdout); |
230 | } else { | 246 | } else { |
231 | file = gzdopen(fileno(stdout), "wb"); /* "wb9" for max compr. */ | 247 | file = gzdopen(fileno(stdout), outmode); |
232 | if (file == NULL) error("can't gzdopen stdout"); | 248 | if (file == NULL) error("can't gzdopen stdout"); |
233 | gz_compress(stdin, file); | 249 | gz_compress(stdin, file); |
234 | } | 250 | } |
diff --git a/Makefile.b32 b/msdos/Makefile.b32 index fc3ac68..fc3ac68 100644 --- a/Makefile.b32 +++ b/msdos/Makefile.b32 | |||
diff --git a/Makefile.bor b/msdos/Makefile.bor index 2116563..2116563 100644 --- a/Makefile.bor +++ b/msdos/Makefile.bor | |||
diff --git a/Makefile.dj2 b/msdos/Makefile.dj2 index 398f28b..0ab431c 100644 --- a/Makefile.dj2 +++ b/msdos/Makefile.dj2 | |||
@@ -1,5 +1,5 @@ | |||
1 | # Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96. | 1 | # Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96. |
2 | # Copyright (C) 1995-1996 Jean-loup Gailly. | 2 | # Copyright (C) 1995-1998 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, or to compile and test, type: | 5 | # To compile, or to compile and test, type: |
@@ -22,7 +22,8 @@ | |||
22 | # - - - - - | 22 | # - - - - - |
23 | # Alternately, these variables may be defined below, overriding the values | 23 | # Alternately, these variables may be defined below, overriding the values |
24 | # in djgpp.env, as | 24 | # in djgpp.env, as |
25 | INCLUDE_PATH=c:\usr\include | 25 | # INCLUDE_PATH=c:\usr\include |
26 | # LIBRARY_PATH=c:\usr\lib | ||
26 | 27 | ||
27 | CC=gcc | 28 | CC=gcc |
28 | 29 | ||
@@ -32,12 +33,12 @@ CC=gcc | |||
32 | CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ | 33 | CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ |
33 | -Wstrict-prototypes -Wmissing-prototypes | 34 | -Wstrict-prototypes -Wmissing-prototypes |
34 | 35 | ||
35 | # If cp.exe is not found, replace with copy /Y . | 36 | # If cp.exe is available, replace "copy /Y" with "cp -fp" . |
36 | CP=cp -f | 37 | CP=copy /Y |
37 | # If install.exe is not found, replace with $(CP). | 38 | # If gnu install.exe is available, replace $(CP) with ginstall. |
38 | INSTALL=install | 39 | INSTALL=$(CP) |
39 | # The default value of RM is "rm -f." If "rm.exe" is not found, uncomment: | 40 | # The default value of RM is "rm -f." If "rm.exe" is found, comment out: |
40 | # RM=del | 41 | RM=del |
41 | LDLIBS=-L. -lz | 42 | LDLIBS=-L. -lz |
42 | LD=$(CC) -s -o | 43 | LD=$(CC) -s -o |
43 | LDSHARED=$(CC) | 44 | LDSHARED=$(CC) |
@@ -77,15 +78,21 @@ libz.a: $(OBJS) | |||
77 | install: $(INCL) $(LIBS) | 78 | install: $(INCL) $(LIBS) |
78 | -@if not exist $(INCLUDE_PATH)\nul mkdir $(INCLUDE_PATH) | 79 | -@if not exist $(INCLUDE_PATH)\nul mkdir $(INCLUDE_PATH) |
79 | -@if not exist $(LIBRARY_PATH)\nul mkdir $(LIBRARY_PATH) | 80 | -@if not exist $(LIBRARY_PATH)\nul mkdir $(LIBRARY_PATH) |
80 | for %%f in ($(INCL)) do $(INSTALL) %%f $(INCLUDE_PATH) | 81 | $(INSTALL) zlib.h $(INCLUDE_PATH) |
81 | for %%p in ($(LIBS)) do $(INSTALL) %%p $(LIBRARY_PATH) | 82 | $(INSTALL) zconf.h $(INCLUDE_PATH) |
83 | $(INSTALL) libz.a $(LIBRARY_PATH) | ||
82 | 84 | ||
83 | uninstall: | 85 | uninstall: |
84 | for %%f in ($(INCL)) do $(RM) $(INCLUDE_PATH)\%%f | 86 | $(RM) $(INCLUDE_PATH)\zlib.h |
85 | for %%p in ($(LIBS)) do $(RM) $(LIBRARY_PATH)\%%p | 87 | $(RM) $(INCLUDE_PATH)\zconf.h |
88 | $(RM) $(LIBRARY_PATH)\libz.a | ||
86 | 89 | ||
87 | clean: | 90 | clean: |
88 | for %%p in (*.d *.o *.exe libz.a libz.so* foo.gz) do $(RM) %%p | 91 | $(RM) *.d |
92 | $(RM) *.o | ||
93 | $(RM) *.exe | ||
94 | $(RM) libz.a | ||
95 | $(RM) foo.gz | ||
89 | 96 | ||
90 | DEPS := $(wildcard *.d) | 97 | DEPS := $(wildcard *.d) |
91 | ifneq ($(DEPS),) | 98 | ifneq ($(DEPS),) |
diff --git a/Makefile.msc b/msdos/Makefile.msc index 112684a..1a6d663 100644 --- a/Makefile.msc +++ b/msdos/Makefile.msc | |||
@@ -15,7 +15,7 @@ CFLAGS=-Oait -Gs -nologo -W3 $(MODEL) | |||
15 | #-Ox generates bad code with MSC 5.1 | 15 | #-Ox generates bad code with MSC 5.1 |
16 | CC=cl | 16 | CC=cl |
17 | LD=link | 17 | LD=link |
18 | LDFLAGS=/e/st:0x1000/noe | 18 | LDFLAGS=/e/st:0x1500/noe |
19 | O=.obj | 19 | O=.obj |
20 | 20 | ||
21 | # variables | 21 | # variables |
diff --git a/Makefile.tc b/msdos/Makefile.tc index a46ce73..a46ce73 100644 --- a/Makefile.tc +++ b/msdos/Makefile.tc | |||
diff --git a/Makefile.wat b/msdos/Makefile.wat index 2a3b629..2a3b629 100644 --- a/Makefile.wat +++ b/msdos/Makefile.wat | |||
diff --git a/msdos/zlib.def b/msdos/zlib.def new file mode 100644 index 0000000..346cce7 --- /dev/null +++ b/msdos/zlib.def | |||
@@ -0,0 +1,57 @@ | |||
1 | LIBRARY "zlib" | ||
2 | |||
3 | DESCRIPTION '"""zlib data compression library"""' | ||
4 | |||
5 | EXETYPE NT | ||
6 | |||
7 | SUBSYSTEM WINDOWS | ||
8 | |||
9 | STUB 'WINSTUB.EXE' | ||
10 | |||
11 | VERSION 1.07 | ||
12 | |||
13 | CODE EXECUTE READ | ||
14 | |||
15 | DATA READ WRITE | ||
16 | |||
17 | HEAPSIZE 1048576,4096 | ||
18 | |||
19 | EXPORTS | ||
20 | adler32 @1 | ||
21 | compress @2 | ||
22 | crc32 @3 | ||
23 | deflate @4 | ||
24 | deflateCopy @5 | ||
25 | deflateEnd @6 | ||
26 | deflateInit2_ @7 | ||
27 | deflateInit_ @8 | ||
28 | deflateParams @9 | ||
29 | deflateReset @10 | ||
30 | deflateSetDictionary @11 | ||
31 | gzclose @12 | ||
32 | gzdopen @13 | ||
33 | gzerror @14 | ||
34 | gzflush @15 | ||
35 | gzopen @16 | ||
36 | gzread @17 | ||
37 | gzwrite @18 | ||
38 | inflate @19 | ||
39 | inflateEnd @20 | ||
40 | inflateInit2_ @21 | ||
41 | inflateInit_ @22 | ||
42 | inflateReset @23 | ||
43 | inflateSetDictionary @24 | ||
44 | inflateSync @25 | ||
45 | uncompress @26 | ||
46 | zlibVersion @27 | ||
47 | gzprintf @28 | ||
48 | gzputc @29 | ||
49 | gzgetc @30 | ||
50 | gzseek @31 | ||
51 | gzrewind @32 | ||
52 | gztell @33 | ||
53 | gzeof @34 | ||
54 | gzsetparams @35 | ||
55 | zError @36 | ||
56 | inflateSyncPoint @37 | ||
57 | get_crc_table @38 | ||
@@ -2,8 +2,8 @@ | |||
2 | 2 | ||
3 | #define IDR_VERSION1 1 | 3 | #define IDR_VERSION1 1 |
4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE | 4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE |
5 | FILEVERSION 1,0,5,0 | 5 | FILEVERSION 1,0,7,0 |
6 | PRODUCTVERSION 1,0,5,0 | 6 | PRODUCTVERSION 1,0,7,0 |
7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK | 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK |
8 | FILEFLAGS 0 | 8 | FILEFLAGS 0 |
9 | FILEOS VOS_DOS_WINDOWS32 | 9 | FILEOS VOS_DOS_WINDOWS32 |
@@ -17,12 +17,12 @@ BEGIN | |||
17 | 17 | ||
18 | BEGIN | 18 | BEGIN |
19 | VALUE "FileDescription", "zlib data compression library\0" | 19 | VALUE "FileDescription", "zlib data compression library\0" |
20 | VALUE "FileVersion", "1.0.5\0" | 20 | VALUE "FileVersion", "1.0.7\0" |
21 | VALUE "InternalName", "zlib\0" | 21 | VALUE "InternalName", "zlib\0" |
22 | VALUE "OriginalFilename", "zlib.lib\0" | 22 | VALUE "OriginalFilename", "zlib.lib\0" |
23 | VALUE "ProductName", "ZLib.DLL\0" | 23 | VALUE "ProductName", "ZLib.DLL\0" |
24 | VALUE "Comments", "DLL support by Alessandro Iacopetti\0" | 24 | VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" |
25 | VALUE "LegalCopyright", "(C) 1995-1996 Jean-loup Gailly & Mark Adler\0" | 25 | VALUE "LegalCopyright", "(C) 1995-1998 Jean-loup Gailly & Mark Adler\0" |
26 | END | 26 | END |
27 | END | 27 | END |
28 | BLOCK "VarFileInfo" | 28 | BLOCK "VarFileInfo" |
diff --git a/nt/Makefile.nt b/nt/Makefile.nt new file mode 100644 index 0000000..b250f2a --- /dev/null +++ b/nt/Makefile.nt | |||
@@ -0,0 +1,88 @@ | |||
1 | # Makefile for zlib | ||
2 | |||
3 | !include <ntwin32.mak> | ||
4 | |||
5 | CC=cl | ||
6 | LD=link | ||
7 | CFLAGS=-O -nologo | ||
8 | LDFLAGS= | ||
9 | O=.obj | ||
10 | |||
11 | # variables | ||
12 | OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \ | ||
13 | trees$(O) | ||
14 | OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \ | ||
15 | infutil$(O) inffast$(O) | ||
16 | |||
17 | all: zlib.dll example.exe minigzip.exe | ||
18 | |||
19 | adler32.obj: adler32.c zutil.h zlib.h zconf.h | ||
20 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
21 | |||
22 | compress.obj: compress.c zlib.h zconf.h | ||
23 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
24 | |||
25 | crc32.obj: crc32.c zutil.h zlib.h zconf.h | ||
26 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
27 | |||
28 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | ||
29 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
30 | |||
31 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | ||
32 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
33 | |||
34 | infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h\ | ||
35 | infcodes.h infutil.h | ||
36 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
37 | |||
38 | infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h\ | ||
39 | infcodes.h inffast.h | ||
40 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
41 | |||
42 | inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h | ||
43 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
44 | |||
45 | inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h | ||
46 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
47 | |||
48 | infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h | ||
49 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
50 | |||
51 | inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h | ||
52 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
53 | |||
54 | trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h | ||
55 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
56 | |||
57 | uncompr.obj: uncompr.c zlib.h zconf.h | ||
58 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
59 | |||
60 | zutil.obj: zutil.c zutil.h zlib.h zconf.h | ||
61 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
62 | |||
63 | example.obj: example.c zlib.h zconf.h | ||
64 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
65 | |||
66 | minigzip.obj: minigzip.c zlib.h zconf.h | ||
67 | $(CC) -c $(cvarsdll) $(CFLAGS) $*.c | ||
68 | |||
69 | zlib.dll: $(OBJ1) $(OBJ2) zlib.dnt | ||
70 | link $(dlllflags) -out:$@ -def:zlib.dnt $(OBJ1) $(OBJ2) $(guilibsdll) | ||
71 | |||
72 | zlib.lib: zlib.dll | ||
73 | |||
74 | example.exe: example.obj zlib.lib | ||
75 | $(LD) $(LDFLAGS) example.obj zlib.lib | ||
76 | |||
77 | minigzip.exe: minigzip.obj zlib.lib | ||
78 | $(LD) $(LDFLAGS) minigzip.obj zlib.lib | ||
79 | |||
80 | test: example.exe minigzip.exe | ||
81 | example | ||
82 | echo hello world | minigzip | minigzip -d | ||
83 | |||
84 | clean: | ||
85 | del *.obj | ||
86 | del *.exe | ||
87 | del *.dll | ||
88 | del *.lib | ||
diff --git a/nt/zlib.dnt b/nt/zlib.dnt new file mode 100644 index 0000000..18c990c --- /dev/null +++ b/nt/zlib.dnt | |||
@@ -0,0 +1,44 @@ | |||
1 | LIBRARY zlib.dll | ||
2 | EXETYPE WINDOWS | ||
3 | CODE PRELOAD MOVEABLE DISCARDABLE | ||
4 | DATA PRELOAD MOVEABLE MULTIPLE | ||
5 | |||
6 | EXPORTS | ||
7 | adler32 @1 | ||
8 | compress @2 | ||
9 | crc32 @3 | ||
10 | deflate @4 | ||
11 | deflateCopy @5 | ||
12 | deflateEnd @6 | ||
13 | deflateInit2_ @7 | ||
14 | deflateInit_ @8 | ||
15 | deflateParams @9 | ||
16 | deflateReset @10 | ||
17 | deflateSetDictionary @11 | ||
18 | gzclose @12 | ||
19 | gzdopen @13 | ||
20 | gzerror @14 | ||
21 | gzflush @15 | ||
22 | gzopen @16 | ||
23 | gzread @17 | ||
24 | gzwrite @18 | ||
25 | inflate @19 | ||
26 | inflateEnd @20 | ||
27 | inflateInit2_ @21 | ||
28 | inflateInit_ @22 | ||
29 | inflateReset @23 | ||
30 | inflateSetDictionary @24 | ||
31 | inflateSync @25 | ||
32 | uncompress @26 | ||
33 | zlibVersion @27 | ||
34 | gzprintf @28 | ||
35 | gzputc @29 | ||
36 | gzgetc @30 | ||
37 | gzseek @31 | ||
38 | gzrewind @32 | ||
39 | gztell @33 | ||
40 | gzeof @34 | ||
41 | gzsetparams @35 | ||
42 | zError @36 | ||
43 | inflateSyncPoint @37 | ||
44 | get_crc_table @38 | ||
@@ -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-1998 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 | ||
@@ -29,7 +29,7 @@ | |||
29 | * Addison-Wesley, 1983. ISBN 0-201-06672-6. | 29 | * Addison-Wesley, 1983. ISBN 0-201-06672-6. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* $Id: trees.c,v 1.11 1996/07/24 13:41:06 me Exp $ */ | 32 | /* @(#) $Id$ */ |
33 | 33 | ||
34 | #include "deflate.h" | 34 | #include "deflate.h" |
35 | 35 | ||
@@ -56,16 +56,16 @@ | |||
56 | #define REPZ_11_138 18 | 56 | #define REPZ_11_138 18 |
57 | /* repeat a zero length 11-138 times (7 bits of repeat count) */ | 57 | /* repeat a zero length 11-138 times (7 bits of repeat count) */ |
58 | 58 | ||
59 | local int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ | 59 | local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ |
60 | = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; | 60 | = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; |
61 | 61 | ||
62 | local int extra_dbits[D_CODES] /* extra bits for each distance code */ | 62 | local const int extra_dbits[D_CODES] /* extra bits for each distance code */ |
63 | = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; | 63 | = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; |
64 | 64 | ||
65 | local int extra_blbits[BL_CODES]/* extra bits for each bit length code */ | 65 | local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ |
66 | = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; | 66 | = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; |
67 | 67 | ||
68 | local uch bl_order[BL_CODES] | 68 | local const uch bl_order[BL_CODES] |
69 | = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; | 69 | = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; |
70 | /* The lengths of the bit length codes are sent in order of decreasing | 70 | /* The lengths of the bit length codes are sent in order of decreasing |
71 | * probability, to avoid transmitting the lengths for unused bit length codes. | 71 | * probability, to avoid transmitting the lengths for unused bit length codes. |
@@ -109,7 +109,7 @@ local int base_dist[D_CODES]; | |||
109 | 109 | ||
110 | struct static_tree_desc_s { | 110 | struct static_tree_desc_s { |
111 | ct_data *static_tree; /* static tree or NULL */ | 111 | ct_data *static_tree; /* static tree or NULL */ |
112 | intf *extra_bits; /* extra bits for each code or NULL */ | 112 | const intf *extra_bits; /* extra bits for each code or NULL */ |
113 | int extra_base; /* base index for extra_bits */ | 113 | int extra_base; /* base index for extra_bits */ |
114 | int elems; /* max number of elements in the tree */ | 114 | int elems; /* max number of elements in the tree */ |
115 | int max_length; /* max bit length for the codes */ | 115 | int max_length; /* max bit length for the codes */ |
@@ -154,7 +154,7 @@ local void copy_block OF((deflate_state *s, charf *buf, unsigned len, | |||
154 | 154 | ||
155 | #else /* DEBUG */ | 155 | #else /* DEBUG */ |
156 | # define send_code(s, c, tree) \ | 156 | # define send_code(s, c, tree) \ |
157 | { if (verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ | 157 | { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ |
158 | send_bits(s, tree[c].Code, tree[c].Len); } | 158 | send_bits(s, tree[c].Code, tree[c].Len); } |
159 | #endif | 159 | #endif |
160 | 160 | ||
@@ -416,7 +416,7 @@ local void gen_bitlen(s, desc) | |||
416 | ct_data *tree = desc->dyn_tree; | 416 | ct_data *tree = desc->dyn_tree; |
417 | int max_code = desc->max_code; | 417 | int max_code = desc->max_code; |
418 | ct_data *stree = desc->stat_desc->static_tree; | 418 | ct_data *stree = desc->stat_desc->static_tree; |
419 | intf *extra = desc->stat_desc->extra_bits; | 419 | const intf *extra = desc->stat_desc->extra_bits; |
420 | int base = desc->stat_desc->extra_base; | 420 | int base = desc->stat_desc->extra_base; |
421 | int max_length = desc->stat_desc->max_length; | 421 | int max_length = desc->stat_desc->max_length; |
422 | int h; /* heap index */ | 422 | int h; /* heap index */ |
@@ -1,9 +1,9 @@ | |||
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-1998 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 | ||
6 | /* $Id: uncompr.c,v 1.8 1996/01/30 21:59:26 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #include "zlib.h" | 8 | #include "zlib.h" |
9 | 9 | ||
@@ -22,7 +22,7 @@ | |||
22 | enough memory, Z_BUF_ERROR if there was not enough room in the output | 22 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
23 | buffer, or Z_DATA_ERROR if the input data was corrupted. | 23 | buffer, or Z_DATA_ERROR if the input data was corrupted. |
24 | */ | 24 | */ |
25 | int uncompress (dest, destLen, source, sourceLen) | 25 | int EXPORT uncompress (dest, destLen, source, sourceLen) |
26 | Bytef *dest; | 26 | Bytef *dest; |
27 | uLongf *destLen; | 27 | uLongf *destLen; |
28 | const Bytef *source; | 28 | const Bytef *source; |
@@ -49,7 +49,7 @@ int uncompress (dest, destLen, source, sourceLen) | |||
49 | err = inflate(&stream, Z_FINISH); | 49 | err = inflate(&stream, Z_FINISH); |
50 | if (err != Z_STREAM_END) { | 50 | if (err != Z_STREAM_END) { |
51 | inflateEnd(&stream); | 51 | inflateEnd(&stream); |
52 | return err; | 52 | return err == Z_OK ? Z_BUF_ERROR : err; |
53 | } | 53 | } |
54 | *destLen = stream.total_out; | 54 | *destLen = stream.total_out; |
55 | 55 | ||
@@ -1,9 +1,9 @@ | |||
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-1998 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 | ||
6 | /* $Id: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #ifndef _ZCONF_H | 8 | #ifndef _ZCONF_H |
9 | #define _ZCONF_H | 9 | #define _ZCONF_H |
@@ -27,6 +27,7 @@ | |||
27 | # define inflateInit2_ z_inflateInit2_ | 27 | # define inflateInit2_ z_inflateInit2_ |
28 | # define inflateSetDictionary z_inflateSetDictionary | 28 | # define inflateSetDictionary z_inflateSetDictionary |
29 | # define inflateSync z_inflateSync | 29 | # define inflateSync z_inflateSync |
30 | # define inflateSyncPoint z_inflateSyncPoint | ||
30 | # define inflateReset z_inflateReset | 31 | # define inflateReset z_inflateReset |
31 | # define compress z_compress | 32 | # define compress z_compress |
32 | # define uncompress z_uncompress | 33 | # define uncompress z_uncompress |
@@ -72,8 +73,10 @@ | |||
72 | #if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) | 73 | #if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) |
73 | # define STDC | 74 | # define STDC |
74 | #endif | 75 | #endif |
75 | #if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC) | 76 | #if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) |
76 | # define STDC | 77 | # ifndef STDC |
78 | # define STDC | ||
79 | # endif | ||
77 | #endif | 80 | #endif |
78 | 81 | ||
79 | #ifndef STDC | 82 | #ifndef STDC |
@@ -87,6 +90,12 @@ | |||
87 | # define NO_DUMMY_DECL | 90 | # define NO_DUMMY_DECL |
88 | #endif | 91 | #endif |
89 | 92 | ||
93 | /* Borland C incorrectly complains about missing returns: */ | ||
94 | #if defined(__BORLANDC__) | ||
95 | # define NEED_DUMMY_RETURN | ||
96 | #endif | ||
97 | |||
98 | |||
90 | /* Maximum value for memLevel in deflateInit2 */ | 99 | /* Maximum value for memLevel in deflateInit2 */ |
91 | #ifndef MAX_MEM_LEVEL | 100 | #ifndef MAX_MEM_LEVEL |
92 | # ifdef MAXSEG_64K | 101 | # ifdef MAXSEG_64K |
@@ -96,13 +105,17 @@ | |||
96 | # endif | 105 | # endif |
97 | #endif | 106 | #endif |
98 | 107 | ||
99 | /* Maximum value for windowBits in deflateInit2 and inflateInit2 */ | 108 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. |
109 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files | ||
110 | * created by gzip. (Files created by minigzip can still be extracted by | ||
111 | * gzip.) | ||
112 | */ | ||
100 | #ifndef MAX_WBITS | 113 | #ifndef MAX_WBITS |
101 | # define MAX_WBITS 15 /* 32K LZ77 window */ | 114 | # define MAX_WBITS 15 /* 32K LZ77 window */ |
102 | #endif | 115 | #endif |
103 | 116 | ||
104 | /* The memory requirements for deflate are (in bytes): | 117 | /* The memory requirements for deflate are (in bytes): |
105 | 1 << (windowBits+2) + 1 << (memLevel+9) | 118 | (1 << (windowBits+2)) + (1 << (memLevel+9)) |
106 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) | 119 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) |
107 | plus a few kilobytes for small objects. For example, if you want to reduce | 120 | plus a few kilobytes for small objects. For example, if you want to reduce |
108 | the default memory requirements from 256K to 128K, compile with | 121 | the default memory requirements from 256K to 128K, compile with |
@@ -172,13 +185,63 @@ typedef uLong FAR uLongf; | |||
172 | typedef Byte *voidp; | 185 | typedef Byte *voidp; |
173 | #endif | 186 | #endif |
174 | 187 | ||
188 | #ifdef HAVE_UNISTD_H | ||
189 | # include <unistd.h> /* for SEEK_* and off_t */ | ||
190 | # define z_off_t off_t | ||
191 | #endif | ||
192 | #ifndef SEEK_SET | ||
193 | # define SEEK_SET 0 /* Seek from beginning of file. */ | ||
194 | # define SEEK_CUR 1 /* Seek from current position. */ | ||
195 | #endif | ||
196 | #ifndef z_off_t | ||
197 | # define z_off_t long | ||
198 | #endif | ||
175 | 199 | ||
176 | /* Compile with -DZLIB_DLL for Windows DLL support */ | 200 | /* Compile with -DZLIB_DLL for Windows DLL support */ |
177 | #if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL) | 201 | #if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL) |
202 | # undef FAR | ||
178 | # include <windows.h> | 203 | # include <windows.h> |
179 | # define EXPORT WINAPI | 204 | # define EXPORT WINAPI |
205 | # ifdef WIN32 | ||
206 | # define EXPORTVA WINAPIV | ||
207 | # else | ||
208 | # define EXPORTVA FAR _cdecl _export | ||
209 | # endif | ||
180 | #else | 210 | #else |
181 | # define EXPORT | 211 | # if defined (__BORLANDC__) && defined (_Windows) && defined (__DLL__) |
212 | # define EXPORT _export | ||
213 | # define EXPORTVA _export | ||
214 | # else | ||
215 | # define EXPORT | ||
216 | # define EXPORTVA | ||
217 | # endif | ||
218 | #endif | ||
219 | |||
220 | /* MVS linker does not support external names larger than 8 bytes */ | ||
221 | #if defined(__MVS__) | ||
222 | # pragma map(deflateInit_,"DEIN") | ||
223 | # pragma map(deflateInit2_,"DEIN2") | ||
224 | # pragma map(deflateEnd,"DEEND") | ||
225 | # pragma map(inflateInit_,"ININ") | ||
226 | # pragma map(inflateInit2_,"ININ2") | ||
227 | # pragma map(inflateEnd,"INEND") | ||
228 | # pragma map(inflateSync,"INSY") | ||
229 | # pragma map(inflateSetDictionary,"INSEDI") | ||
230 | # pragma map(inflate_blocks,"INBL") | ||
231 | # pragma map(inflate_blocks_new,"INBLNE") | ||
232 | # pragma map(inflate_blocks_free,"INBLFR") | ||
233 | # pragma map(inflate_blocks_reset,"INBLRE") | ||
234 | # pragma map(inflate_codes_free,"INCOFR") | ||
235 | # pragma map(inflate_codes,"INCO") | ||
236 | # pragma map(inflate_fast,"INFA") | ||
237 | # pragma map(inflate_flush,"INFLU") | ||
238 | # pragma map(inflate_mask,"INMA") | ||
239 | # pragma map(inflate_set_dictionary,"INSEDI2") | ||
240 | # pragma map(inflate_copyright,"INCOPY") | ||
241 | # pragma map(inflate_trees_bits,"INTRBI") | ||
242 | # pragma map(inflate_trees_dynamic,"INTRDY") | ||
243 | # pragma map(inflate_trees_fixed,"INTRFI") | ||
244 | # pragma map(inflate_trees_free,"INTRFR") | ||
182 | #endif | 245 | #endif |
183 | 246 | ||
184 | #endif /* _ZCONF_H */ | 247 | #endif /* _ZCONF_H */ |
@@ -0,0 +1,107 @@ | |||
1 | .TH ZLIB 3 "20 January 1998" | ||
2 | .SH NAME | ||
3 | zlib \- compression/decompression library | ||
4 | .SH SYNOPSIS | ||
5 | [see | ||
6 | .I zlib.h | ||
7 | for full descripton] | ||
8 | .SH DESCRIPTION | ||
9 | The | ||
10 | .I zlib | ||
11 | library is a general purpose data compression library. | ||
12 | The code is reentrant (thread safe). | ||
13 | It provides in-memory compression and decompression functions, | ||
14 | including integrity checks of the uncompressed data. | ||
15 | This version of the library supports only one compression method (deflation) | ||
16 | but other algorithms will be added later and will have the same stream interface. | ||
17 | .LP | ||
18 | Compression can be done in a single step if the buffers are large enough | ||
19 | (for example if an input file is mmap'ed), | ||
20 | or can be done by repeated calls of the compression function. | ||
21 | In the latter case, | ||
22 | the application must provide more input and/or consume the output | ||
23 | (providing more output space) before each call. | ||
24 | .LP | ||
25 | The library also supports reading and writing files in | ||
26 | .I gzip | ||
27 | (.gz) format | ||
28 | with an interface similar to that of stdio. | ||
29 | .LP | ||
30 | The library does not install any signal handler. The decoder checks | ||
31 | the consistency of the compressed data, so the library should never | ||
32 | crash even in case of corrupted input. | ||
33 | .LP | ||
34 | All functions of the compression library are documented in the file | ||
35 | .IR zlib.h. | ||
36 | The distribution source includes examples of use of the library | ||
37 | the files | ||
38 | .I example.c | ||
39 | and | ||
40 | .IR minigzip.c . | ||
41 | .LP | ||
42 | A Java implementation of | ||
43 | .IR zlib | ||
44 | is available in the Java Development Kit 1.1 | ||
45 | .IP | ||
46 | http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html | ||
47 | .LP | ||
48 | A Perl interface to | ||
49 | .IR zlib , | ||
50 | written by Paul Marquess (pmarquess@bfsec.bt.co.uk) | ||
51 | is available at CPAN (Comprehensive Perl Archive Network) sites, | ||
52 | such as: | ||
53 | .IP | ||
54 | ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib* | ||
55 | .LP | ||
56 | A Python interface to | ||
57 | .IR zlib | ||
58 | written by A.M. Kuchling <amk@magnet.com> | ||
59 | is available from the Python Software Association sites, such as: | ||
60 | .IP | ||
61 | ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz | ||
62 | .SH "SEE ALSO" | ||
63 | Questions about zlib should be sent to: | ||
64 | .IP | ||
65 | zlib@quest.jpl.nasa.gov | ||
66 | or, if this fails, to the author addresses given below. | ||
67 | The zlib home page is: | ||
68 | .IP | ||
69 | http://www.cdrom.com/infozip/zlib/ | ||
70 | .LP | ||
71 | The data format used by the zlib library is described by RFC | ||
72 | (Request for Comments) 1950 to 1952 in the files: | ||
73 | .IP | ||
74 | ftp://ds.internic.net/rfc/rfc1950.txt (zlib format) | ||
75 | .br | ||
76 | rfc1951.txt (deflate format) | ||
77 | .br | ||
78 | rfc1952.txt (gzip format) | ||
79 | .LP | ||
80 | These documents are also available in other formats from: | ||
81 | .IP | ||
82 | ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html | ||
83 | .SH AUTHORS | ||
84 | Version 1.0.7. | ||
85 | Copyright (C) 1995-1998 Jean-loup Gailly (jloup@gzip.org) | ||
86 | and Mark Adler (madler@alumni.caltech.edu). | ||
87 | .LP | ||
88 | This software is provided "as-is," | ||
89 | without any express or implied warranty. | ||
90 | In no event will the authors be held liable for any damages | ||
91 | arising from the use of this software. | ||
92 | See the distribution directory with respect to requirements | ||
93 | governing redistribution. | ||
94 | The deflate format used by | ||
95 | .I zlib | ||
96 | was defined by Phil Katz. | ||
97 | The deflate and | ||
98 | .I zlib | ||
99 | specifications were written by Peter Deutsch. | ||
100 | Thanks to all the people who reported problems and suggested various | ||
101 | improvements in | ||
102 | .IR zlib ; | ||
103 | who are too numerous to cite here. | ||
104 | .LP | ||
105 | UNIX manual page by R. P. C. Rodgers, | ||
106 | U.S. National Library of Medicine (rodgers@nlm.nih.gov). | ||
107 | .\" end of man page | ||
diff --git a/zlib.def b/zlib.def deleted file mode 100644 index 56365cf..0000000 --- a/zlib.def +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | LIBRARY "zlib" | ||
2 | |||
3 | DESCRIPTION '"""zlib data compression library"""' | ||
4 | |||
5 | EXETYPE NT | ||
6 | |||
7 | SUBSYSTEM WINDOWS | ||
8 | |||
9 | STUB 'WINSTUB.EXE' | ||
10 | |||
11 | VERSION 1.05 | ||
12 | |||
13 | CODE EXECUTE READ | ||
14 | |||
15 | DATA READ WRITE | ||
16 | |||
17 | HEAPSIZE 1048576,4096 | ||
18 | |||
19 | EXPORTS | ||
20 | zlibVersion | ||
21 | deflate | ||
22 | deflateEnd | ||
23 | inflate | ||
24 | inflateEnd | ||
25 | deflateSetDictionary | ||
26 | deflateCopy | ||
27 | deflateReset | ||
28 | deflateParams | ||
29 | inflateSetDictionary | ||
30 | inflateSync | ||
31 | inflateReset | ||
32 | compress | ||
33 | uncompress | ||
34 | gzopen | ||
35 | gzdopen | ||
36 | gzread | ||
37 | gzwrite | ||
38 | gzflush | ||
39 | gzclose | ||
40 | gzerror | ||
41 | adler32 | ||
42 | crc32 | ||
43 | deflateInit_ | ||
44 | inflateInit_ | ||
45 | deflateInit2_ | ||
46 | inflateInit2_ | ||
@@ -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.5, Jan 3rd, 1998. | 2 | version 1.0.7, Jan 20th, 1998 |
3 | 3 | ||
4 | Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler |
5 | 5 | ||
@@ -20,7 +20,7 @@ | |||
20 | 3. This notice may not be removed or altered from any source distribution. | 20 | 3. This notice may not be removed or altered from any source distribution. |
21 | 21 | ||
22 | Jean-loup Gailly Mark Adler | 22 | Jean-loup Gailly Mark Adler |
23 | gzip@prep.ai.mit.edu madler@alumni.caltech.edu | 23 | jloup@gzip.org madler@alumni.caltech.edu |
24 | 24 | ||
25 | 25 | ||
26 | The data format used by the zlib library is described by RFCs (Request for | 26 | The data format used by the zlib library is described by RFCs (Request for |
@@ -37,30 +37,27 @@ extern "C" { | |||
37 | 37 | ||
38 | #include "zconf.h" | 38 | #include "zconf.h" |
39 | 39 | ||
40 | #define ZLIB_VERSION "1.0.5" | 40 | #define ZLIB_VERSION "1.0.7" |
41 | 41 | ||
42 | /* | 42 | /* |
43 | The 'zlib' compression library provides in-memory compression and | 43 | The 'zlib' compression library provides in-memory compression and |
44 | decompression functions, including integrity checks of the uncompressed | 44 | decompression functions, including integrity checks of the uncompressed |
45 | data. This version of the library supports only one compression method | 45 | data. This version of the library supports only one compression method |
46 | (deflation) but other algorithms may be added later and will have the same | 46 | (deflation) but other algorithms will be added later and will have the same |
47 | stream interface. | 47 | stream interface. |
48 | 48 | ||
49 | For compression the application must provide the output buffer and | ||
50 | may optionally provide the input buffer for optimization. For decompression, | ||
51 | the application must provide the input buffer and may optionally provide | ||
52 | the output buffer for optimization. | ||
53 | |||
54 | Compression can be done in a single step if the buffers are large | 49 | Compression can be done in a single step if the buffers are large |
55 | enough (for example if an input file is mmap'ed), or can be done by | 50 | enough (for example if an input file is mmap'ed), or can be done by |
56 | repeated calls of the compression function. In the latter case, the | 51 | repeated calls of the compression function. In the latter case, the |
57 | application must provide more input and/or consume the output | 52 | application must provide more input and/or consume the output |
58 | (providing more output space) before each call. | 53 | (providing more output space) before each call. |
59 | 54 | ||
60 | The library does not install any signal handler. It is recommended to | 55 | The library also supports reading and writing files in gzip (.gz) format |
61 | add at least a handler for SIGSEGV when decompressing; the library checks | 56 | with an interface similar to that of stdio. |
62 | the consistency of the input data whenever possible but may go nuts | 57 | |
63 | for some forms of corrupted input. | 58 | The library does not install any signal handler. The decoder checks |
59 | the consistency of the compressed data, so the library should never | ||
60 | crash even in case of corrupted input. | ||
64 | */ | 61 | */ |
65 | 62 | ||
66 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); | 63 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
@@ -123,7 +120,7 @@ typedef z_stream FAR *z_streamp; | |||
123 | /* constants */ | 120 | /* constants */ |
124 | 121 | ||
125 | #define Z_NO_FLUSH 0 | 122 | #define Z_NO_FLUSH 0 |
126 | #define Z_PARTIAL_FLUSH 1 | 123 | #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ |
127 | #define Z_SYNC_FLUSH 2 | 124 | #define Z_SYNC_FLUSH 2 |
128 | #define Z_FULL_FLUSH 3 | 125 | #define Z_FULL_FLUSH 3 |
129 | #define Z_FINISH 4 | 126 | #define Z_FINISH 4 |
@@ -200,7 +197,13 @@ extern int EXPORT deflateInit OF((z_streamp strm, int level)); | |||
200 | 197 | ||
201 | extern int EXPORT deflate OF((z_streamp strm, int flush)); | 198 | extern int EXPORT deflate OF((z_streamp strm, int flush)); |
202 | /* | 199 | /* |
203 | Performs one or both of the following actions: | 200 | deflate compresses as much data as possible, and stops when the input |
201 | buffer becomes empty or the output buffer becomes full. It may introduce some | ||
202 | output latency (reading input without producing any output) except when | ||
203 | forced to flush. | ||
204 | |||
205 | The detailed semantics are as follows. deflate performs one or both of the | ||
206 | following actions: | ||
204 | 207 | ||
205 | - Compress more input starting at next_in and update next_in and avail_in | 208 | - Compress more input starting at next_in and update next_in and avail_in |
206 | accordingly. If not all input can be processed (because there is not | 209 | accordingly. If not all input can be processed (because there is not |
@@ -222,24 +225,23 @@ extern int EXPORT deflate OF((z_streamp strm, int flush)); | |||
222 | and with zero avail_out, it must be called again after making room in the | 225 | and with zero avail_out, it must be called again after making room in the |
223 | output buffer because there might be more output pending. | 226 | output buffer because there might be more output pending. |
224 | 227 | ||
225 | If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression | 228 | If the parameter flush is set to Z_SYNC_FLUSH, all pending output is |
226 | block is terminated and flushed to the output buffer so that the | 229 | flushed to the output buffer and the output is aligned on a byte boundary, so |
227 | decompressor can get all input data available so far. For method 9, a future | 230 | that the decompressor can get all input data available so far. (In particular |
228 | variant on method 8, the current block will be flushed but not terminated. | 231 | avail_in is zero after the call if enough output space has been provided |
229 | Z_SYNC_FLUSH has the same effect as partial flush except that the compressed | 232 | before the call.) Flushing may degrade compression for some compression |
230 | output is byte aligned (the compressor can clear its internal bit buffer) | 233 | algorithms and so it should be used only when necessary. |
231 | and the current block is always terminated; this can be useful if the | 234 | |
232 | compressor has to be restarted from scratch after an interruption (in which | 235 | If flush is set to Z_FULL_FLUSH, all output is flushed as with |
233 | case the internal state of the compressor may be lost). | 236 | Z_SYNC_FLUSH, and the compression state is reset so that decompression can |
234 | If flush is set to Z_FULL_FLUSH, the compression block is terminated, a | 237 | restart from this point if previous compressed data has been damaged or if |
235 | special marker is output and the compression dictionary is discarded; this | 238 | random access is desired. Using Z_FULL_FLUSH too often can seriously degrade |
236 | is useful to allow the decompressor to synchronize if one compressed block | 239 | the compression. |
237 | has been damaged (see inflateSync below). Flushing degrades compression and | 240 | |
238 | so should be used only when necessary. Using Z_FULL_FLUSH too often can | 241 | If deflate returns with avail_out == 0, this function must be called again |
239 | seriously degrade the compression. If deflate returns with avail_out == 0, | 242 | with the same value of the flush parameter and more output space (updated |
240 | this function must be called again with the same value of the flush | 243 | avail_out), until the flush is complete (deflate returns with non-zero |
241 | parameter and more output space (updated avail_out), until the flush is | 244 | avail_out). |
242 | complete (deflate returns with non-zero avail_out). | ||
243 | 245 | ||
244 | If the parameter flush is set to Z_FINISH, pending input is processed, | 246 | If the parameter flush is set to Z_FINISH, pending input is processed, |
245 | pending output is flushed and deflate returns with Z_STREAM_END if there | 247 | pending output is flushed and deflate returns with Z_STREAM_END if there |
@@ -254,6 +256,9 @@ extern int EXPORT deflate OF((z_streamp strm, int flush)); | |||
254 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return | 256 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return |
255 | Z_STREAM_END, then it must be called again as described above. | 257 | Z_STREAM_END, then it must be called again as described above. |
256 | 258 | ||
259 | deflate() sets strm->adler to the adler32 checksum of all input read | ||
260 | so far (that is, total_in bytes). | ||
261 | |||
257 | deflate() may update data_type if it can make a good guess about | 262 | deflate() may update data_type if it can make a good guess about |
258 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered | 263 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered |
259 | binary. This field is only for information purposes and does not affect | 264 | binary. This field is only for information purposes and does not affect |
@@ -285,21 +290,32 @@ extern int EXPORT deflateEnd OF((z_streamp strm)); | |||
285 | extern int EXPORT inflateInit OF((z_streamp strm)); | 290 | extern int EXPORT inflateInit OF((z_streamp strm)); |
286 | 291 | ||
287 | Initializes the internal stream state for decompression. The fields | 292 | Initializes the internal stream state for decompression. The fields |
288 | zalloc, zfree and opaque must be initialized before by the caller. If | 293 | next_in, avail_in, zalloc, zfree and opaque must be initialized before by |
289 | zalloc and zfree are set to Z_NULL, inflateInit updates them to use default | 294 | the caller. If next_in is not Z_NULL and avail_in is large enough (the exact |
290 | allocation functions. | 295 | value depends on the compression method), inflateInit determines the |
296 | compression method from the zlib header and allocates all data structures | ||
297 | accordingly; otherwise the allocation will be deferred to the first call of | ||
298 | inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to | ||
299 | use default allocation functions. | ||
291 | 300 | ||
292 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | 301 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough |
293 | enough memory, Z_VERSION_ERROR if the zlib library version is incompatible | 302 | memory, Z_VERSION_ERROR if the zlib library version is incompatible with the |
294 | with the version assumed by the caller. msg is set to null if there is no | 303 | version assumed by the caller. msg is set to null if there is no error |
295 | error message. inflateInit does not perform any decompression: this will be | 304 | message. inflateInit does not perform any decompression apart from reading |
296 | done by inflate(). | 305 | the zlib header if present: this will be done by inflate(). (So next_in and |
306 | avail_in may be modified, but next_out and avail_out are unchanged.) | ||
297 | */ | 307 | */ |
298 | 308 | ||
299 | 309 | ||
300 | extern int EXPORT inflate OF((z_streamp strm, int flush)); | 310 | extern int EXPORT inflate OF((z_streamp strm, int flush)); |
301 | /* | 311 | /* |
302 | Performs one or both of the following actions: | 312 | inflate decompresses as much data as possible, and stops when the input |
313 | buffer becomes empty or the output buffer becomes full. It may some | ||
314 | introduce some output latency (reading input without producing any output) | ||
315 | except when forced to flush. | ||
316 | |||
317 | The detailed semantics are as follows. inflate performs one or both of the | ||
318 | following actions: | ||
303 | 319 | ||
304 | - Decompress more input starting at next_in and update next_in and avail_in | 320 | - Decompress more input starting at next_in and update next_in and avail_in |
305 | accordingly. If not all input can be processed (because there is not | 321 | accordingly. If not all input can be processed (because there is not |
@@ -320,9 +336,9 @@ extern int EXPORT inflate OF((z_streamp strm, int flush)); | |||
320 | must be called again after making room in the output buffer because there | 336 | must be called again after making room in the output buffer because there |
321 | might be more output pending. | 337 | might be more output pending. |
322 | 338 | ||
323 | If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much | 339 | If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much |
324 | output as possible to the output buffer. The flushing behavior of inflate is | 340 | output as possible to the output buffer. The flushing behavior of inflate is |
325 | not specified for values of the flush parameter other than Z_PARTIAL_FLUSH | 341 | not specified for values of the flush parameter other than Z_SYNC_FLUSH |
326 | and Z_FINISH, but the current implementation actually flushes as much output | 342 | and Z_FINISH, but the current implementation actually flushes as much output |
327 | as possible anyway. | 343 | as possible anyway. |
328 | 344 | ||
@@ -337,18 +353,26 @@ extern int EXPORT inflate OF((z_streamp strm, int flush)); | |||
337 | is never required, but can be used to inform inflate that a faster routine | 353 | is never required, but can be used to inform inflate that a faster routine |
338 | may be used for the single inflate() call. | 354 | may be used for the single inflate() call. |
339 | 355 | ||
340 | inflate() returns Z_OK if some progress has been made (more input | 356 | If a preset dictionary is needed at this point (see inflateSetDictionary |
341 | processed or more output produced), Z_STREAM_END if the end of the | 357 | below), inflate sets strm-adler to the adler32 checksum of the |
342 | compressed data has been reached and all uncompressed output has been | 358 | dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise |
343 | produced, Z_NEED_DICT if a preset dictionary is needed at this point (see | 359 | it sets strm->adler to the adler32 checksum of all output produced |
344 | inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted, | 360 | so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or |
345 | Z_STREAM_ERROR if the stream structure was inconsistent (for example if | 361 | an error code as described below. At the end of the stream, inflate() |
346 | next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, | 362 | checks that its computed adler32 checksum is equal to that saved by the |
347 | Z_BUF_ERROR if no progress is possible or if there was not enough room in | 363 | compressor and returns Z_STREAM_END only if the checksum is correct. |
348 | the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the | 364 | |
349 | application may then call inflateSync to look for a good compression block. | 365 | inflate() returns Z_OK if some progress has been made (more input processed |
350 | In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the | 366 | or more output produced), Z_STREAM_END if the end of the compressed data has |
351 | dictionary chosen by the compressor. | 367 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a |
368 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was | ||
369 | corrupted (input stream not conforming to the zlib format or incorrect | ||
370 | adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent | ||
371 | (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not | ||
372 | enough memory, Z_BUF_ERROR if no progress is possible or if there was not | ||
373 | enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR | ||
374 | case, the application may then call inflateSync to look for a good | ||
375 | compression block. | ||
352 | */ | 376 | */ |
353 | 377 | ||
354 | 378 | ||
@@ -382,14 +406,13 @@ extern int EXPORT deflateInit2 OF((z_streamp strm, | |||
382 | the caller. | 406 | the caller. |
383 | 407 | ||
384 | The method parameter is the compression method. It must be Z_DEFLATED in | 408 | The method parameter is the compression method. It must be Z_DEFLATED in |
385 | this version of the library. (Method 9 will allow a 64K history buffer and | 409 | this version of the library. |
386 | partial block flushes.) | ||
387 | 410 | ||
388 | The windowBits parameter is the base two logarithm of the window size | 411 | The windowBits parameter is the base two logarithm of the window size |
389 | (the size of the history buffer). It should be in the range 8..15 for this | 412 | (the size of the history buffer). It should be in the range 8..15 for this |
390 | version of the library (the value 16 will be allowed for method 9). Larger | 413 | version of the library. Larger values of this parameter result in better |
391 | values of this parameter result in better compression at the expense of | 414 | compression at the expense of memory usage. The default value is 15 if |
392 | memory usage. The default value is 15 if deflateInit is used instead. | 415 | deflateInit is used instead. |
393 | 416 | ||
394 | The memLevel parameter specifies how much memory should be allocated | 417 | The memLevel parameter specifies how much memory should be allocated |
395 | for the internal compression state. memLevel=1 uses minimum memory but | 418 | for the internal compression state. memLevel=1 uses minimum memory but |
@@ -408,42 +431,35 @@ extern int EXPORT deflateInit2 OF((z_streamp strm, | |||
408 | the compression ratio but not the correctness of the compressed output even | 431 | the compression ratio but not the correctness of the compressed output even |
409 | if it is not set appropriately. | 432 | if it is not set appropriately. |
410 | 433 | ||
411 | If next_in is not null, the library will use this buffer to hold also | 434 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
412 | some history information; the buffer must either hold the entire input | 435 | memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid |
413 | data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in | 436 | method). msg is set to null if there is no error message. deflateInit2 does |
414 | is null, the library will allocate its own history buffer (and leave next_in | 437 | not perform any compression: this will be done by deflate(). |
415 | null). next_out need not be provided here but must be provided by the | ||
416 | application for the next call of deflate(). | ||
417 | |||
418 | If the history buffer is provided by the application, next_in must | ||
419 | must never be changed by the application since the compressor maintains | ||
420 | information inside this buffer from call to call; the application | ||
421 | must provide more input only by increasing avail_in. next_in is always | ||
422 | reset by the library in this case. | ||
423 | |||
424 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was | ||
425 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as | ||
426 | an invalid method). msg is set to null if there is no error message. | ||
427 | deflateInit2 does not perform any compression: this will be done by | ||
428 | deflate(). | ||
429 | */ | 438 | */ |
430 | 439 | ||
431 | extern int EXPORT deflateSetDictionary OF((z_streamp strm, | 440 | extern int EXPORT deflateSetDictionary OF((z_streamp strm, |
432 | const Bytef *dictionary, | 441 | const Bytef *dictionary, |
433 | uInt dictLength)); | 442 | uInt dictLength)); |
434 | /* | 443 | /* |
435 | Initializes the compression dictionary (history buffer) from the given | 444 | Initializes the compression dictionary from the given byte sequence |
436 | byte sequence without producing any compressed output. This function must | 445 | without producing any compressed output. This function must be called |
437 | be called immediately after deflateInit or deflateInit2, before any call | 446 | immediately after deflateInit or deflateInit2, before any call of |
438 | of deflate. The compressor and decompressor must use exactly the same | 447 | deflate. The compressor and decompressor must use exactly the same |
439 | dictionary (see inflateSetDictionary). | 448 | dictionary (see inflateSetDictionary). |
449 | |||
440 | The dictionary should consist of strings (byte sequences) that are likely | 450 | The dictionary should consist of strings (byte sequences) that are likely |
441 | to be encountered later in the data to be compressed, with the most commonly | 451 | to be encountered later in the data to be compressed, with the most commonly |
442 | used strings preferably put towards the end of the dictionary. Using a | 452 | used strings preferably put towards the end of the dictionary. Using a |
443 | dictionary is most useful when the data to be compressed is short and | 453 | dictionary is most useful when the data to be compressed is short and can be |
444 | can be predicted with good accuracy; the data can then be compressed better | 454 | predicted with good accuracy; the data can then be compressed better than |
445 | than with the default empty dictionary. In this version of the library, | 455 | with the default empty dictionary. |
446 | only the last 32K bytes of the dictionary are used. | 456 | |
457 | Depending on the size of the compression data structures selected by | ||
458 | deflateInit or deflateInit2, a part of the dictionary may in effect be | ||
459 | discarded, for example if the dictionary is larger than the window size in | ||
460 | deflate or deflate2. Thus the strings most likely to be useful should be | ||
461 | put at the end of the dictionary, not at the front. | ||
462 | |||
447 | Upon return of this function, strm->adler is set to the Adler32 value | 463 | Upon return of this function, strm->adler is set to the Adler32 value |
448 | of the dictionary; the decompressor may later use this value to determine | 464 | of the dictionary; the decompressor may later use this value to determine |
449 | which dictionary has been used by the compressor. (The Adler32 value | 465 | which dictionary has been used by the compressor. (The Adler32 value |
@@ -451,21 +467,16 @@ extern int EXPORT deflateSetDictionary OF((z_streamp strm, | |||
451 | actually used by the compressor.) | 467 | actually used by the compressor.) |
452 | 468 | ||
453 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a | 469 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a |
454 | parameter is invalid (such as NULL dictionary) or the stream state | 470 | parameter is invalid (such as NULL dictionary) or the stream state is |
455 | is inconsistent (for example if deflate has already been called for this | 471 | inconsistent (for example if deflate has already been called for this stream |
456 | stream). deflateSetDictionary does not perform any compression: this will | 472 | or if the compression method is bsort). deflateSetDictionary does not |
457 | be done by deflate(). | 473 | perform any compression: this will be done by deflate(). |
458 | */ | 474 | */ |
459 | 475 | ||
460 | extern int EXPORT deflateCopy OF((z_streamp dest, | 476 | extern int EXPORT deflateCopy OF((z_streamp dest, |
461 | z_streamp source)); | 477 | z_streamp source)); |
462 | /* | 478 | /* |
463 | Sets the destination stream as a complete copy of the source stream. If | 479 | Sets the destination stream as a complete copy of the source stream. |
464 | the source stream is using an application-supplied history buffer, a new | ||
465 | buffer is allocated for the destination stream. The compressed output | ||
466 | buffer is always application-supplied. It's the responsibility of the | ||
467 | application to provide the correct values of next_out and avail_out for the | ||
468 | next call of deflate. | ||
469 | 480 | ||
470 | This function can be useful when several compression strategies will be | 481 | This function can be useful when several compression strategies will be |
471 | tried, for example when there are several ways of pre-processing the input | 482 | tried, for example when there are several ways of pre-processing the input |
@@ -493,12 +504,13 @@ extern int EXPORT deflateReset OF((z_streamp strm)); | |||
493 | 504 | ||
494 | extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); | 505 | extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); |
495 | /* | 506 | /* |
496 | Dynamically update the compression level and compression strategy. | 507 | Dynamically update the compression level and compression strategy. The |
497 | This can be used to switch between compression and straight copy of | 508 | interpretation of level and strategy is as in deflateInit2. This can be |
498 | the input data, or to switch to a different kind of input data requiring | 509 | used to switch between compression and straight copy of the input data, or |
499 | a different strategy. If the compression level is changed, the input | 510 | to switch to a different kind of input data requiring a different |
500 | available so far is compressed with the old level (and may be flushed); | 511 | strategy. If the compression level is changed, the input available so far |
501 | the new level will take effect only at the next call of deflate(). | 512 | is compressed with the old level (and may be flushed); the new level will |
513 | take effect only at the next call of deflate(). | ||
502 | 514 | ||
503 | Before the call of deflateParams, the stream state must be set as for | 515 | Before the call of deflateParams, the stream state must be set as for |
504 | a call of deflate(), since the currently available input may have to | 516 | a call of deflate(), since the currently available input may have to |
@@ -513,46 +525,34 @@ extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); | |||
513 | extern int EXPORT inflateInit2 OF((z_streamp strm, | 525 | extern int EXPORT inflateInit2 OF((z_streamp strm, |
514 | int windowBits)); | 526 | int windowBits)); |
515 | 527 | ||
516 | This is another version of inflateInit with more compression options. The | 528 | This is another version of inflateInit with an extra parameter. The |
517 | fields next_out, zalloc, zfree and opaque must be initialized before by | 529 | fields next_in, avail_in, zalloc, zfree and opaque must be initialized |
518 | the caller. | 530 | before by the caller. |
519 | 531 | ||
520 | The windowBits parameter is the base two logarithm of the maximum window | 532 | The windowBits parameter is the base two logarithm of the maximum window |
521 | size (the size of the history buffer). It should be in the range 8..15 for | 533 | size (the size of the history buffer). It should be in the range 8..15 for |
522 | this version of the library (the value 16 will be allowed soon). The | 534 | this version of the library. The default value is 15 if inflateInit is used |
523 | default value is 15 if inflateInit is used instead. If a compressed stream | 535 | instead. If a compressed stream with a larger window size is given as |
524 | with a larger window size is given as input, inflate() will return with | 536 | input, inflate() will return with the error code Z_DATA_ERROR instead of |
525 | the error code Z_DATA_ERROR instead of trying to allocate a larger window. | 537 | trying to allocate a larger window. |
526 | 538 | ||
527 | If next_out is not null, the library will use this buffer for the history | 539 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
528 | buffer; the buffer must either be large enough to hold the entire output | 540 | memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative |
529 | data, or have at least 1<<windowBits bytes. If next_out is null, the | 541 | memLevel). msg is set to null if there is no error message. inflateInit2 |
530 | library will allocate its own buffer (and leave next_out null). next_in | 542 | does not perform any decompression apart from reading the zlib header if |
531 | need not be provided here but must be provided by the application for the | 543 | present: this will be done by inflate(). (So next_in and avail_in may be |
532 | next call of inflate(). | 544 | modified, but next_out and avail_out are unchanged.) |
533 | |||
534 | If the history buffer is provided by the application, next_out must | ||
535 | never be changed by the application since the decompressor maintains | ||
536 | history information inside this buffer from call to call; the application | ||
537 | can only reset next_out to the beginning of the history buffer when | ||
538 | avail_out is zero and all output has been consumed. | ||
539 | |||
540 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was | ||
541 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as | ||
542 | windowBits < 8). msg is set to null if there is no error message. | ||
543 | inflateInit2 does not perform any decompression: this will be done by | ||
544 | inflate(). | ||
545 | */ | 545 | */ |
546 | 546 | ||
547 | extern int EXPORT inflateSetDictionary OF((z_streamp strm, | 547 | extern int EXPORT inflateSetDictionary OF((z_streamp strm, |
548 | const Bytef *dictionary, | 548 | const Bytef *dictionary, |
549 | uInt dictLength)); | 549 | uInt dictLength)); |
550 | /* | 550 | /* |
551 | Initializes the decompression dictionary (history buffer) from the given | 551 | Initializes the decompression dictionary from the given uncompressed byte |
552 | uncompressed byte sequence. This function must be called immediately after | 552 | sequence. This function must be called immediately after a call of inflate |
553 | a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen | 553 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor |
554 | by the compressor can be determined from the Adler32 value returned by this | 554 | can be determined from the Adler32 value returned by this call of |
555 | call of inflate. The compressor and decompressor must use exactly the same | 555 | inflate. The compressor and decompressor must use exactly the same |
556 | dictionary (see deflateSetDictionary). | 556 | dictionary (see deflateSetDictionary). |
557 | 557 | ||
558 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a | 558 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
@@ -565,12 +565,12 @@ extern int EXPORT inflateSetDictionary OF((z_streamp strm, | |||
565 | 565 | ||
566 | extern int EXPORT inflateSync OF((z_streamp strm)); | 566 | extern int EXPORT inflateSync OF((z_streamp strm)); |
567 | /* | 567 | /* |
568 | Skips invalid compressed data until the special marker (see deflate() | 568 | Skips invalid compressed data until a full flush point (see above the |
569 | above) can be found, or until all available input is skipped. No output | 569 | description of deflate with Z_FULL_FLUSH) can be found, or until all |
570 | is provided. | 570 | available input is skipped. No output is provided. |
571 | 571 | ||
572 | inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR | 572 | inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR |
573 | if no more input was provided, Z_DATA_ERROR if no marker has been found, | 573 | if no more input was provided, Z_DATA_ERROR if no flush point has been found, |
574 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success | 574 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success |
575 | case, the application may save the current current value of total_in which | 575 | case, the application may save the current current value of total_in which |
576 | indicates where valid compressed data was found. In the error case, the | 576 | indicates where valid compressed data was found. In the error case, the |
@@ -594,7 +594,7 @@ extern int EXPORT inflateReset OF((z_streamp strm)); | |||
594 | /* | 594 | /* |
595 | The following utility functions are implemented on top of the | 595 | The following utility functions are implemented on top of the |
596 | basic stream-oriented functions. To simplify the interface, some | 596 | basic stream-oriented functions. To simplify the interface, some |
597 | default options are assumed (compression level, window size, | 597 | default options are assumed (compression level and memory usage, |
598 | standard memory allocation functions). The source code of these | 598 | standard memory allocation functions). The source code of these |
599 | utility functions can easily be modified if you need special options. | 599 | utility functions can easily be modified if you need special options. |
600 | */ | 600 | */ |
@@ -639,13 +639,17 @@ extern gzFile EXPORT gzopen OF((const char *path, const char *mode)); | |||
639 | /* | 639 | /* |
640 | Opens a gzip (.gz) file for reading or writing. The mode parameter | 640 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
641 | is as in fopen ("rb" or "wb") but can also include a compression level | 641 | is as in fopen ("rb" or "wb") but can also include a compression level |
642 | ("wb9"). gzopen can be used to read a file which is not in gzip format; | 642 | ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for |
643 | in this case gzread will directly read from the file without decompression. | 643 | Huffman only compression as in "wb1h". (See the description |
644 | of deflateInit2 for more information about the strategy parameter.) | ||
645 | |||
646 | gzopen can be used to read a file which is not in gzip format; in this | ||
647 | case gzread will directly read from the file without decompression. | ||
648 | |||
644 | gzopen returns NULL if the file could not be opened or if there was | 649 | gzopen returns NULL if the file could not be opened or if there was |
645 | insufficient memory to allocate the (de)compression state; errno | 650 | insufficient memory to allocate the (de)compression state; errno |
646 | can be checked to distinguish the two cases (if errno is zero, the | 651 | can be checked to distinguish the two cases (if errno is zero, the |
647 | zlib error is Z_MEM_ERROR). | 652 | zlib error is Z_MEM_ERROR). */ |
648 | */ | ||
649 | 653 | ||
650 | extern gzFile EXPORT gzdopen OF((int fd, const char *mode)); | 654 | extern gzFile EXPORT gzdopen OF((int fd, const char *mode)); |
651 | /* | 655 | /* |
@@ -660,6 +664,14 @@ extern gzFile EXPORT gzdopen OF((int fd, const char *mode)); | |||
660 | the (de)compression state. | 664 | the (de)compression state. |
661 | */ | 665 | */ |
662 | 666 | ||
667 | extern int EXPORT gzsetparams OF((gzFile file, int level, int strategy)); | ||
668 | /* | ||
669 | Dynamically update the compression level or strategy. See the description | ||
670 | of deflateInit2 for the meaning of these parameters. | ||
671 | gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not | ||
672 | opened for writing. | ||
673 | */ | ||
674 | |||
663 | extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | 675 | extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len)); |
664 | /* | 676 | /* |
665 | Reads the given number of uncompressed bytes from the compressed file. | 677 | Reads the given number of uncompressed bytes from the compressed file. |
@@ -675,6 +687,25 @@ extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len)); | |||
675 | (0 in case of error). | 687 | (0 in case of error). |
676 | */ | 688 | */ |
677 | 689 | ||
690 | extern int EXPORTVA gzprintf OF((gzFile file, const char *format, ...)); | ||
691 | /* | ||
692 | Converts, formats, and writes the args to the compressed file under | ||
693 | control of the format string, as in fprintf. gzprintf returns the number of | ||
694 | uncompressed bytes actually written (0 in case of error). | ||
695 | */ | ||
696 | |||
697 | extern int EXPORT gzputc OF((gzFile file, int c)); | ||
698 | /* | ||
699 | Writes c, converted to an unsigned char, into the compressed file. | ||
700 | gzputc returns the value that was written, or -1 in case of error. | ||
701 | */ | ||
702 | |||
703 | extern int EXPORT gzgetc OF((gzFile file)); | ||
704 | /* | ||
705 | Reads one byte from the compressed file. gzgetc returns this byte | ||
706 | or -1 in case of end of file or error. | ||
707 | */ | ||
708 | |||
678 | extern int EXPORT gzflush OF((gzFile file, int flush)); | 709 | extern int EXPORT gzflush OF((gzFile file, int flush)); |
679 | /* | 710 | /* |
680 | Flushes all pending output into the compressed file. The parameter | 711 | Flushes all pending output into the compressed file. The parameter |
@@ -685,6 +716,45 @@ extern int EXPORT gzflush OF((gzFile file, int flush)); | |||
685 | degrade compression. | 716 | degrade compression. |
686 | */ | 717 | */ |
687 | 718 | ||
719 | extern z_off_t EXPORT gzseek OF((gzFile file, z_off_t offset, int whence)); | ||
720 | /* | ||
721 | Sets the starting position for the next gzread or gzwrite on the given | ||
722 | compressed file. The offset represents a number of bytes in the | ||
723 | uncompressed data stream. The whence parameter is defined as in lseek(2); | ||
724 | the value SEEK_END is not supported. | ||
725 | If the file is opened for reading, this function is emulated but can be | ||
726 | extremely slow. If the file is opened for writing, only forward seeks are | ||
727 | supported; gzseek then compresses a sequence of zeroes up to the new | ||
728 | starting position. | ||
729 | |||
730 | gzseek returns the resulting offset location as measured in bytes from | ||
731 | the beginning of the uncompressed stream, or -1 in case of error, in | ||
732 | particular if the file is opened for writing and the new starting position | ||
733 | would be before the current position. | ||
734 | */ | ||
735 | |||
736 | extern int EXPORT gzrewind OF((gzFile file)); | ||
737 | /* | ||
738 | Rewinds the given file. This function is supported only for reading. | ||
739 | |||
740 | gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) | ||
741 | */ | ||
742 | |||
743 | extern z_off_t EXPORT gztell OF((gzFile file)); | ||
744 | /* | ||
745 | Returns the starting position for the next gzread or gzwrite on the | ||
746 | given compressed file. This position represents a number of bytes in the | ||
747 | uncompressed data stream. | ||
748 | |||
749 | gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) | ||
750 | */ | ||
751 | |||
752 | extern int EXPORT gzeof OF((gzFile file)); | ||
753 | /* | ||
754 | Returns 1 when EOF has previously been detected reading the given | ||
755 | input stream, otherwise zero. | ||
756 | */ | ||
757 | |||
688 | extern int EXPORT gzclose OF((gzFile file)); | 758 | extern int EXPORT gzclose OF((gzFile file)); |
689 | /* | 759 | /* |
690 | Flushes all pending output if necessary, closes the compressed file | 760 | Flushes all pending output if necessary, closes the compressed file |
@@ -767,11 +837,14 @@ extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | |||
767 | #define inflateInit2(strm, windowBits) \ | 837 | #define inflateInit2(strm, windowBits) \ |
768 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) | 838 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) |
769 | 839 | ||
840 | |||
770 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) | 841 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) |
771 | struct internal_state {int dummy;}; /* hack for buggy compilers */ | 842 | struct internal_state {int dummy;}; /* hack for buggy compilers */ |
772 | #endif | 843 | #endif |
773 | 844 | ||
774 | uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */ | 845 | extern const char * EXPORT zError OF((int err)); |
846 | extern int EXPORT inflateSyncPoint OF((z_streamp z)); | ||
847 | extern uLongf * EXPORT get_crc_table OF((void)); | ||
775 | 848 | ||
776 | #ifdef __cplusplus | 849 | #ifdef __cplusplus |
777 | } | 850 | } |
@@ -1,9 +1,9 @@ | |||
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-1998 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 | ||
6 | /* $Id: zutil.c,v 1.17 1996/07/24 13:41:12 me Exp $ */ | 6 | /* @(#) $Id$ */ |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | 9 | ||
@@ -28,12 +28,18 @@ const char *z_errmsg[10] = { | |||
28 | ""}; | 28 | ""}; |
29 | 29 | ||
30 | 30 | ||
31 | const char *zlibVersion() | 31 | const char * EXPORT zlibVersion() |
32 | { | 32 | { |
33 | return ZLIB_VERSION; | 33 | return ZLIB_VERSION; |
34 | } | 34 | } |
35 | 35 | ||
36 | #ifdef DEBUG | 36 | #ifdef DEBUG |
37 | |||
38 | # ifndef verbose | ||
39 | # define verbose 0 | ||
40 | # endif | ||
41 | int z_verbose = verbose; | ||
42 | |||
37 | void z_error (m) | 43 | void z_error (m) |
38 | char *m; | 44 | char *m; |
39 | { | 45 | { |
@@ -42,6 +48,16 @@ void z_error (m) | |||
42 | } | 48 | } |
43 | #endif | 49 | #endif |
44 | 50 | ||
51 | /* exported to allow conversion of error code to string for compress() and | ||
52 | * uncompress() | ||
53 | */ | ||
54 | const char * EXPORT zError(err) | ||
55 | int err; | ||
56 | { | ||
57 | return ERR_MSG(err); | ||
58 | } | ||
59 | |||
60 | |||
45 | #ifndef HAVE_MEMCPY | 61 | #ifndef HAVE_MEMCPY |
46 | 62 | ||
47 | void zmemcpy(dest, source, len) | 63 | void zmemcpy(dest, source, len) |
@@ -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-1998 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 | ||
@@ -8,23 +8,23 @@ | |||
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 | /* $Id: zutil.h,v 1.16 1996/07/24 13:41:13 me Exp $ */ | 11 | /* @(#) $Id$ */ |
12 | 12 | ||
13 | #ifndef _Z_UTIL_H | 13 | #ifndef _Z_UTIL_H |
14 | #define _Z_UTIL_H | 14 | #define _Z_UTIL_H |
15 | 15 | ||
16 | #include "zlib.h" | 16 | #include "zlib.h" |
17 | 17 | ||
18 | #if defined(MSDOS)||defined(VMS)||defined(CRAY)||defined(WIN32)||defined(RISCOS) | ||
19 | # include <stddef.h> | ||
20 | # include <errno.h> | ||
21 | #else | ||
22 | extern int errno; | ||
23 | #endif | ||
24 | #ifdef STDC | 18 | #ifdef STDC |
19 | # include <stddef.h> | ||
25 | # include <string.h> | 20 | # include <string.h> |
26 | # include <stdlib.h> | 21 | # include <stdlib.h> |
27 | #endif | 22 | #endif |
23 | #ifdef NO_ERRNO_H | ||
24 | extern int errno; | ||
25 | #else | ||
26 | # include <errno.h> | ||
27 | #endif | ||
28 | 28 | ||
29 | #ifndef local | 29 | #ifndef local |
30 | # define local static | 30 | # define local static |
@@ -76,7 +76,13 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
76 | #ifdef MSDOS | 76 | #ifdef MSDOS |
77 | # define OS_CODE 0x00 | 77 | # define OS_CODE 0x00 |
78 | # ifdef __TURBOC__ | 78 | # ifdef __TURBOC__ |
79 | # include <alloc.h> | 79 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) |
80 | /* Allow compilation with ANSI keywords only enabled */ | ||
81 | void _Cdecl farfree( void *block ); | ||
82 | void *_Cdecl farmalloc( unsigned long nbytes ); | ||
83 | # else | ||
84 | # include <alloc.h> | ||
85 | # endif | ||
80 | # else /* MSC or DJGPP */ | 86 | # else /* MSC or DJGPP */ |
81 | # include <malloc.h> | 87 | # include <malloc.h> |
82 | # endif | 88 | # endif |
@@ -92,7 +98,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
92 | 98 | ||
93 | #if defined(VAXC) || defined(VMS) | 99 | #if defined(VAXC) || defined(VMS) |
94 | # define OS_CODE 0x02 | 100 | # define OS_CODE 0x02 |
95 | # define FOPEN(name, mode) \ | 101 | # define F_OPEN(name, mode) \ |
96 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") | 102 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") |
97 | #endif | 103 | #endif |
98 | 104 | ||
@@ -120,14 +126,19 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
120 | # define fdopen(fd,mode) NULL /* No fdopen() */ | 126 | # define fdopen(fd,mode) NULL /* No fdopen() */ |
121 | #endif | 127 | #endif |
122 | 128 | ||
129 | #if (defined(_MSC_VER) && (_MSC_VER >= 600)) | ||
130 | # define fdopen(fd,type) _fdopen(fd,type) | ||
131 | #endif | ||
132 | |||
133 | |||
123 | /* Common defaults */ | 134 | /* Common defaults */ |
124 | 135 | ||
125 | #ifndef OS_CODE | 136 | #ifndef OS_CODE |
126 | # define OS_CODE 0x03 /* assume Unix */ | 137 | # define OS_CODE 0x03 /* assume Unix */ |
127 | #endif | 138 | #endif |
128 | 139 | ||
129 | #ifndef FOPEN | 140 | #ifndef F_OPEN |
130 | # define FOPEN(name, mode) fopen((name), (mode)) | 141 | # define F_OPEN(name, mode) fopen((name), (mode)) |
131 | #endif | 142 | #endif |
132 | 143 | ||
133 | /* functions */ | 144 | /* functions */ |
@@ -142,9 +153,10 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
142 | #if defined(pyr) | 153 | #if defined(pyr) |
143 | # define NO_MEMCPY | 154 | # define NO_MEMCPY |
144 | #endif | 155 | #endif |
145 | #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER) | 156 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) |
146 | /* Use our own functions for small and medium model with MSC <= 5.0. | 157 | /* Use our own functions for small and medium model with MSC <= 5.0. |
147 | * You may have to use the same strategy for Borland C (untested). | 158 | * You may have to use the same strategy for Borland C (untested). |
159 | * The __SC__ check is for Symantec. | ||
148 | */ | 160 | */ |
149 | # define NO_MEMCPY | 161 | # define NO_MEMCPY |
150 | #endif | 162 | #endif |
@@ -170,16 +182,14 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
170 | /* Diagnostic functions */ | 182 | /* Diagnostic functions */ |
171 | #ifdef DEBUG | 183 | #ifdef DEBUG |
172 | # include <stdio.h> | 184 | # include <stdio.h> |
173 | # ifndef verbose | 185 | extern int z_verbose; |
174 | # define verbose 0 | ||
175 | # endif | ||
176 | extern void z_error OF((char *m)); | 186 | extern void z_error OF((char *m)); |
177 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} | 187 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} |
178 | # define Trace(x) fprintf x | 188 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} |
179 | # define Tracev(x) {if (verbose) fprintf x ;} | 189 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} |
180 | # define Tracevv(x) {if (verbose>1) fprintf x ;} | 190 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} |
181 | # define Tracec(c,x) {if (verbose && (c)) fprintf x ;} | 191 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} |
182 | # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;} | 192 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} |
183 | #else | 193 | #else |
184 | # define Assert(cond,msg) | 194 | # define Assert(cond,msg) |
185 | # define Trace(x) | 195 | # define Trace(x) |
@@ -190,8 +200,8 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
190 | #endif | 200 | #endif |
191 | 201 | ||
192 | 202 | ||
193 | typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len)); | 203 | typedef uLong (EXPORT *check_func) OF((uLong check, const Bytef *buf, |
194 | 204 | uInt len)); | |
195 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); | 205 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); |
196 | void zcfree OF((voidpf opaque, voidpf ptr)); | 206 | void zcfree OF((voidpf opaque, voidpf ptr)); |
197 | 207 | ||