diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | Makefile.bak | 59 | ||||
-rw-r--r-- | Makefile.bor | 98 | ||||
-rw-r--r-- | Makefile.msc | 95 | ||||
-rw-r--r-- | Makefile.tc | 97 | ||||
-rw-r--r-- | README | 19 | ||||
-rw-r--r-- | crc32.c | 16 | ||||
-rw-r--r-- | deflate.c | 32 | ||||
-rw-r--r-- | deflate.h | 4 | ||||
-rw-r--r-- | example.c | 81 | ||||
-rw-r--r-- | gzio.c | 8 | ||||
-rw-r--r-- | infblock.c | 74 | ||||
-rw-r--r-- | infblock.h | 13 | ||||
-rw-r--r-- | infcodes.c | 18 | ||||
-rw-r--r-- | inffast.c | 12 | ||||
-rw-r--r-- | inflate.c | 204 | ||||
-rw-r--r-- | infutil.c | 8 | ||||
-rw-r--r-- | infutil.h | 10 | ||||
-rw-r--r-- | trees.c | 36 | ||||
-rw-r--r-- | zconf.h | 18 | ||||
-rw-r--r-- | zlib.h | 36 | ||||
-rw-r--r-- | zutil.h | 11 |
23 files changed, 774 insertions, 191 deletions
@@ -1,10 +1,22 @@ | |||
1 | ChangeLog file for zlib | 1 | ChangeLog file for zlib |
2 | 2 | ||
3 | Changes in 0.9 (1 May 95) | ||
4 | - don't assume that zalloc clears the allocated memory (the TurboC bug | ||
5 | was Mark's bug after all :) | ||
6 | - let again gzread copy uncompressed data unchanged (was working in 0.71) | ||
7 | - deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented | ||
8 | - added a test of inflateSync in example.c | ||
9 | - moved MAX_WBITS to zconf.h because users might want to change that. | ||
10 | - document explicitly that zalloc(64K) on MSDOS must return a normalized | ||
11 | pointer (zero offset) | ||
12 | - added Makefiles for Microsoft C, Turbo C, Borland C++ | ||
13 | |||
3 | Changes in 0.8 (29 April 95) | 14 | Changes in 0.8 (29 April 95) |
4 | - added fast inflate (inffast.c) | 15 | - added fast inflate (inffast.c) |
5 | - deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this | 16 | - deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this |
6 | is incompatible with previous versions of zlib which returned Z_OK. | 17 | is incompatible with previous versions of zlib which returned Z_OK. |
7 | - work around a TurboC compiler bug (bad code for b << 0, see infutil.h) | 18 | - work around a TurboC compiler bug (bad code for b << 0, see infutil.h) |
19 | (actually that was not a compiler bug, see 0.81 above) | ||
8 | - gzread no longer reads one extra byte in certain cases | 20 | - gzread no longer reads one extra byte in certain cases |
9 | - In gzio destroy(), don't reference a freed structure | 21 | - In gzio destroy(), don't reference a freed structure |
10 | - avoid many warnings for MSDOS | 22 | - avoid many warnings for MSDOS |
@@ -33,11 +33,11 @@ clean: | |||
33 | rm -f *.o example minigzip inftest libgz.a foo.gz | 33 | rm -f *.o example minigzip inftest libgz.a foo.gz |
34 | 34 | ||
35 | zip: | 35 | zip: |
36 | zip -ul9 zlib README ChangeLog Makefile *.[ch] | 36 | zip -ul9 zlib README ChangeLog Makefile Makefile.??? Makefile.?? *.[ch] |
37 | 37 | ||
38 | tgz: | 38 | tgz: |
39 | cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ | 39 | cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ |
40 | zlib/*.[ch] | 40 | zlib/Makefile.??? zlib/Makefile.?? zlib/*.[ch] |
41 | 41 | ||
42 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 42 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
43 | 43 | ||
diff --git a/Makefile.bak b/Makefile.bak new file mode 100644 index 0000000..bfe1b74 --- /dev/null +++ b/Makefile.bak | |||
@@ -0,0 +1,59 @@ | |||
1 | CC=gcc | ||
2 | CFLAGS=-O2 | ||
3 | #CFLAGS=-g -DDEBUG | ||
4 | LDFLAGS=-L. -lgz | ||
5 | |||
6 | RANLIB=ranlib | ||
7 | |||
8 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | ||
9 | zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o | ||
10 | |||
11 | TEST_OBJS = example.o minigzip.o inftest.o | ||
12 | |||
13 | all: example minigzip inftest | ||
14 | |||
15 | test: all | ||
16 | ./example | ||
17 | echo hello world | ./minigzip | ./minigzip -d | ||
18 | |||
19 | libgz.a: $(OBJS) | ||
20 | ar rc $@ $(OBJS) | ||
21 | $(RANLIB) $@ | ||
22 | |||
23 | example: example.o libgz.a | ||
24 | $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) | ||
25 | |||
26 | minigzip: minigzip.o libgz.a | ||
27 | $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) | ||
28 | |||
29 | inftest: inftest.o libgz.a | ||
30 | $(CC) $(CFLAGS) -o $@ inftest.o $(LDFLAGS) | ||
31 | |||
32 | clean: | ||
33 | rm -f *.o example minigzip inftest libgz.a foo.gz | ||
34 | |||
35 | zip: | ||
36 | zip -ul9 zlib README ChangeLog Makefile *.[ch] | ||
37 | |||
38 | tgz: | ||
39 | cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ | ||
40 | zlib/*.[ch] | ||
41 | |||
42 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
43 | |||
44 | adler32.o: zutil.h zlib.h zconf.h | ||
45 | compress.o: zlib.h zconf.h | ||
46 | crc32.o: zutil.h zlib.h zconf.h | ||
47 | deflate.o: deflate.h zutil.h zlib.h zconf.h | ||
48 | example.o: zlib.h zconf.h | ||
49 | gzio.o: zutil.h zlib.h zconf.h | ||
50 | infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h | ||
51 | infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h | ||
52 | inflate.o: zutil.h zlib.h zconf.h infblock.h | ||
53 | inftest.o: zutil.h zlib.h zconf.h | ||
54 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h | ||
55 | infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h | ||
56 | minigzip.o: zlib.h zconf.h | ||
57 | trees.o: deflate.h zutil.h zlib.h zconf.h | ||
58 | uncompr.o: zlib.h zconf.h | ||
59 | zutil.o: zutil.h zlib.h zconf.h | ||
diff --git a/Makefile.bor b/Makefile.bor new file mode 100644 index 0000000..877ed62 --- /dev/null +++ b/Makefile.bor | |||
@@ -0,0 +1,98 @@ | |||
1 | # Makefile for zlib | ||
2 | # Borland C++ ************ UNTESTED *********** | ||
3 | |||
4 | # To use, do "make -fmakefile.bor" | ||
5 | |||
6 | # WARNING: the small model is supported but only for small values of | ||
7 | # MAX_WBITS and MAX_MEM_LEVEL | ||
8 | |||
9 | # ------------- Turbo C++, Borland C++ ------------- | ||
10 | MODEL=-ml | ||
11 | CFLAGS=-O2 -Z $(MODEL) | ||
12 | CC=bcc | ||
13 | LD=bcc | ||
14 | LIB=tlib | ||
15 | # replace bcc with tcc for Turbo C++ 1.0 | ||
16 | LDFLAGS=$(MODEL) | ||
17 | O=.obj | ||
18 | |||
19 | # variables | ||
20 | OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \ | ||
21 | trees$(O) | ||
22 | OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\ | ||
23 | trees$(O) | ||
24 | OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \ | ||
25 | infutil$(O) inffast$(O) | ||
26 | OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\ | ||
27 | infutil$(O)+inffast$(O) | ||
28 | |||
29 | all: test | ||
30 | |||
31 | adler32.obj: adler32.c zutil.h zlib.h zconf.h | ||
32 | $(CC) -c $(CFLAGS) $*.c | ||
33 | |||
34 | compress.obj: compress.c zlib.h zconf.h | ||
35 | $(CC) -c $(CFLAGS) $*.c | ||
36 | |||
37 | crc32.obj: crc32.c zutil.h zlib.h zconf.h | ||
38 | $(CC) -c $(CFLAGS) $*.c | ||
39 | |||
40 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | ||
41 | $(CC) -c $(CFLAGS) $*.c | ||
42 | |||
43 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | ||
44 | $(CC) -c $(CFLAGS) $*.c | ||
45 | |||
46 | infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h\ | ||
47 | infcodes.h infutil.h | ||
48 | $(CC) -c $(CFLAGS) $*.c | ||
49 | |||
50 | infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h\ | ||
51 | infcodes.h inffast.h | ||
52 | $(CC) -c $(CFLAGS) $*.c | ||
53 | |||
54 | inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h | ||
55 | $(CC) -c $(CFLAGS) $*.c | ||
56 | |||
57 | inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h | ||
58 | $(CC) -c $(CFLAGS) $*.c | ||
59 | |||
60 | infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h | ||
61 | $(CC) -c $(CFLAGS) $*.c | ||
62 | |||
63 | inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h | ||
64 | $(CC) -c $(CFLAGS) $*.c | ||
65 | |||
66 | trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h | ||
67 | $(CC) -c $(CFLAGS) $*.c | ||
68 | |||
69 | uncompr.obj: uncompr.c zlib.h zconf.h | ||
70 | $(CC) -c $(CFLAGS) $*.c | ||
71 | |||
72 | zutil.obj: zutil.c zutil.h zlib.h zconf.h | ||
73 | $(CC) -c $(CFLAGS) $*.c | ||
74 | |||
75 | example.obj: example.c zlib.h zconf.h | ||
76 | $(CC) -c $(CFLAGS) $*.c | ||
77 | |||
78 | minigzip.obj: minigzip.c zlib.h zconf.h | ||
79 | $(CC) -c $(CFLAGS) $*.c | ||
80 | |||
81 | # we must cut the command line to fit in the MS/DOS 128 byte limit: | ||
82 | zlib.lib: $(OBJ1) $(OBJ2) | ||
83 | $(LIB) zlib +$(OBJP1) | ||
84 | $(LIB) zlib +$(OBJP2) | ||
85 | |||
86 | example.exe: example.obj zlib.lib | ||
87 | $(LD) $(LDFLAGS) example.obj zlib.lib | ||
88 | |||
89 | minigzip.exe: minigzip.obj zlib.lib | ||
90 | $(LD) $(LDFLAGS) minigzip.obj zlib.lib | ||
91 | |||
92 | test: example.exe minigzip.exe | ||
93 | example | ||
94 | echo hello world | minigzip | minigzip -d | ||
95 | |||
96 | #clean: | ||
97 | # del *.obj | ||
98 | # del *.exe | ||
diff --git a/Makefile.msc b/Makefile.msc new file mode 100644 index 0000000..375d21c --- /dev/null +++ b/Makefile.msc | |||
@@ -0,0 +1,95 @@ | |||
1 | # Makefile for zlib | ||
2 | # Microsoft C 5.1 or later | ||
3 | |||
4 | # To use, do "make makefile.msc" | ||
5 | |||
6 | # WARNING: the small model is supported but only for small values of | ||
7 | # MAX_WBITS and MAX_MEM_LEVEL | ||
8 | |||
9 | # ------------- Microsoft C 5.1 and later ------------- | ||
10 | MODEL=-AL | ||
11 | CFLAGS=-Oait -Gs -nologo -W3 $(MODEL) | ||
12 | #-Ox generates bad code with MSC 5.1 | ||
13 | CC=cl | ||
14 | LD=link | ||
15 | LDFLAGS=/e/st:0x1000/noe | ||
16 | O=.obj | ||
17 | |||
18 | # variables | ||
19 | OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \ | ||
20 | trees$(O) | ||
21 | OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\ | ||
22 | trees$(O) | ||
23 | OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \ | ||
24 | infutil$(O) inffast$(O) | ||
25 | OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\ | ||
26 | infutil$(O)+inffast$(O) | ||
27 | |||
28 | adler32.obj: adler32.c zutil.h zlib.h zconf.h | ||
29 | $(CC) -c $(CFLAGS) $*.c | ||
30 | |||
31 | compress.obj: compress.c zlib.h zconf.h | ||
32 | $(CC) -c $(CFLAGS) $*.c | ||
33 | |||
34 | crc32.obj: crc32.c zutil.h zlib.h zconf.h | ||
35 | $(CC) -c $(CFLAGS) $*.c | ||
36 | |||
37 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | ||
38 | $(CC) -c $(CFLAGS) $*.c | ||
39 | |||
40 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | ||
41 | $(CC) -c $(CFLAGS) $*.c | ||
42 | |||
43 | infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h\ | ||
44 | infcodes.h infutil.h | ||
45 | $(CC) -c $(CFLAGS) $*.c | ||
46 | |||
47 | infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h\ | ||
48 | infcodes.h inffast.h | ||
49 | $(CC) -c $(CFLAGS) $*.c | ||
50 | |||
51 | inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h | ||
52 | $(CC) -c $(CFLAGS) $*.c | ||
53 | |||
54 | inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h | ||
55 | $(CC) -c $(CFLAGS) $*.c | ||
56 | |||
57 | infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h | ||
58 | $(CC) -c $(CFLAGS) $*.c | ||
59 | |||
60 | inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h | ||
61 | $(CC) -c $(CFLAGS) $*.c | ||
62 | |||
63 | trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h | ||
64 | $(CC) -c $(CFLAGS) $*.c | ||
65 | |||
66 | uncompr.obj: uncompr.c zlib.h zconf.h | ||
67 | $(CC) -c $(CFLAGS) $*.c | ||
68 | |||
69 | zutil.obj: zutil.c zutil.h zlib.h zconf.h | ||
70 | $(CC) -c $(CFLAGS) $*.c | ||
71 | |||
72 | example.obj: example.c zlib.h zconf.h | ||
73 | $(CC) -c $(CFLAGS) $*.c | ||
74 | |||
75 | minigzip.obj: minigzip.c zlib.h zconf.h | ||
76 | $(CC) -c $(CFLAGS) $*.c | ||
77 | |||
78 | # we must cut the command line to fit in the MS/DOS 128 byte limit: | ||
79 | zlib.lib: $(OBJ1) $(OBJ2) | ||
80 | lib zlib $(OBJ1); | ||
81 | lib zlib $(OBJ2); | ||
82 | |||
83 | example.exe: example.obj zlib.lib | ||
84 | $(LD) $(LDFLAGS) example.obj,,,zlib.lib; | ||
85 | |||
86 | minigzip.exe: minigzip.obj zlib.lib | ||
87 | $(LD) $(LDFLAGS) minigzip.obj,,,zlib.lib; | ||
88 | |||
89 | test: example.exe minigzip.exe | ||
90 | example | ||
91 | echo hello world | minigzip | minigzip -d | ||
92 | |||
93 | #clean: | ||
94 | # del *.obj | ||
95 | # del *.exe | ||
diff --git a/Makefile.tc b/Makefile.tc new file mode 100644 index 0000000..51075f7 --- /dev/null +++ b/Makefile.tc | |||
@@ -0,0 +1,97 @@ | |||
1 | # Makefile for zlib | ||
2 | # TurboC 2.0 | ||
3 | |||
4 | # To use, do "make -fmakefile.tc" | ||
5 | |||
6 | # WARNING: the small model is supported but only for small values of | ||
7 | # MAX_WBITS and MAX_MEM_LEVEL | ||
8 | |||
9 | # ------------- Turbo C 2.0 ------------- | ||
10 | MODEL=-ml | ||
11 | CFLAGS=-O2 -Z $(MODEL) | ||
12 | CC=tcc | ||
13 | LD=tcc | ||
14 | LIB=tlib | ||
15 | LDFLAGS=$(MODEL) | ||
16 | O=.obj | ||
17 | |||
18 | # variables | ||
19 | OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \ | ||
20 | trees$(O) | ||
21 | OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\ | ||
22 | trees$(O) | ||
23 | OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \ | ||
24 | infutil$(O) inffast$(O) | ||
25 | OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\ | ||
26 | infutil$(O)+inffast$(O) | ||
27 | |||
28 | all: test | ||
29 | |||
30 | adler32.obj: adler32.c zutil.h zlib.h zconf.h | ||
31 | $(CC) -c $(CFLAGS) $*.c | ||
32 | |||
33 | compress.obj: compress.c zlib.h zconf.h | ||
34 | $(CC) -c $(CFLAGS) $*.c | ||
35 | |||
36 | crc32.obj: crc32.c zutil.h zlib.h zconf.h | ||
37 | $(CC) -c $(CFLAGS) $*.c | ||
38 | |||
39 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | ||
40 | $(CC) -c $(CFLAGS) $*.c | ||
41 | |||
42 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | ||
43 | $(CC) -c $(CFLAGS) $*.c | ||
44 | |||
45 | infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h\ | ||
46 | infcodes.h infutil.h | ||
47 | $(CC) -c $(CFLAGS) $*.c | ||
48 | |||
49 | infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h\ | ||
50 | infcodes.h inffast.h | ||
51 | $(CC) -c $(CFLAGS) $*.c | ||
52 | |||
53 | inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h | ||
54 | $(CC) -c $(CFLAGS) $*.c | ||
55 | |||
56 | inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h | ||
57 | $(CC) -c $(CFLAGS) $*.c | ||
58 | |||
59 | infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h | ||
60 | $(CC) -c $(CFLAGS) $*.c | ||
61 | |||
62 | inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h | ||
63 | $(CC) -c $(CFLAGS) $*.c | ||
64 | |||
65 | trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h | ||
66 | $(CC) -c $(CFLAGS) $*.c | ||
67 | |||
68 | uncompr.obj: uncompr.c zlib.h zconf.h | ||
69 | $(CC) -c $(CFLAGS) $*.c | ||
70 | |||
71 | zutil.obj: zutil.c zutil.h zlib.h zconf.h | ||
72 | $(CC) -c $(CFLAGS) $*.c | ||
73 | |||
74 | example.obj: example.c zlib.h zconf.h | ||
75 | $(CC) -c $(CFLAGS) $*.c | ||
76 | |||
77 | minigzip.obj: minigzip.c zlib.h zconf.h | ||
78 | $(CC) -c $(CFLAGS) $*.c | ||
79 | |||
80 | # we must cut the command line to fit in the MS/DOS 128 byte limit: | ||
81 | zlib.lib: $(OBJ1) $(OBJ2) | ||
82 | $(LIB) zlib +$(OBJP1) | ||
83 | $(LIB) zlib +$(OBJP2) | ||
84 | |||
85 | example.exe: example.obj zlib.lib | ||
86 | $(LD) $(LDFLAGS) -eexample.exe example.obj zlib.lib | ||
87 | |||
88 | minigzip.exe: minigzip.obj zlib.lib | ||
89 | $(LD) $(LDFLAGS) -eminigzip.exe minigzip.obj zlib.lib | ||
90 | |||
91 | test: example.exe minigzip.exe | ||
92 | example | ||
93 | echo hello world | minigzip | minigzip -d | ||
94 | |||
95 | #clean: | ||
96 | # del *.obj | ||
97 | # del *.exe | ||
@@ -1,6 +1,4 @@ | |||
1 | zlib 0.8 is a beta version of a general purpose compression library. | 1 | zlib 0.9 is a beta version of a general purpose compression library. |
2 | This is the first version with no known bugs. (There may still be | ||
3 | problem on SGI, to be checked.) | ||
4 | 2 | ||
5 | The data format used by the zlib library is described in the | 3 | The data format used by the zlib library is described in the |
6 | file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available | 4 | file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available |
@@ -11,18 +9,17 @@ zlib.h. A usage example of the library is given in the file example.c | |||
11 | which also tests that the library is working correctly. | 9 | which also tests that the library is working correctly. |
12 | To compile all files and run the test program, just type: make test | 10 | To compile all files and run the test program, just type: make test |
13 | 11 | ||
14 | The changes made in version 0.8 are documented in the file ChangeLog. | 12 | The changes made in version 0.9 are documented in the file ChangeLog. |
15 | The main changes since 0.71 are: | 13 | The main changes since 0.8 are: |
16 | - added fast inflate (inffast.c) | 14 | - don't assume that zalloc clears the allocated memory |
17 | - deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this | 15 | - let again gzread copy uncompressed data unchanged (was working in 0.71) |
18 | is incompatible with previous versions of zlib which returned Z_OK. | 16 | - deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented |
19 | - work around a nasty TurboC compiler bug | ||
20 | 17 | ||
21 | On MSDOS, this version works in both large and small model. However | 18 | On MSDOS, this version works in both large and small model. However |
22 | small model compression works only for small values of MEM_LEVEL and | 19 | small model compression works only for small values of MEM_LEVEL and |
23 | WBITS (see zutil.h). Small model decompression should work up to WBITS=15. | 20 | WBITS (see zutil.h). Small model decompression should work up to WBITS=15. |
24 | This version of zlib does not yet support small or medium model with | 21 | This version of zlib does not support small or medium model with far |
25 | far allocation of big objects. | 22 | allocation of big objects. |
26 | 23 | ||
27 | 24 | ||
28 | Copyright (C) 1995 Jean-loup Gailly and Mark Adler | 25 | Copyright (C) 1995 Jean-loup Gailly and Mark Adler |
@@ -3,12 +3,17 @@ | |||
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.4 1995/04/14 14:55:12 jloup Exp $ */ | 6 | /* $Id: crc32.c,v 1.5 1995/05/01 13:55:46 jloup Exp $ */ |
7 | 7 | ||
8 | #include "zlib.h" | 8 | #include "zlib.h" |
9 | 9 | ||
10 | extern uLong crc_table[]; /* crc table, defined below */ | 10 | extern uLong crc_table[]; /* crc table, defined below */ |
11 | 11 | ||
12 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); | ||
13 | #define DO2(buf) DO1(buf); DO1(buf); | ||
14 | #define DO4(buf) DO2(buf); DO2(buf); | ||
15 | #define DO8(buf) DO4(buf); DO4(buf); | ||
16 | |||
12 | /* ========================================================================= */ | 17 | /* ========================================================================= */ |
13 | uLong crc32(crc, buf, len) | 18 | uLong crc32(crc, buf, len) |
14 | uLong crc; | 19 | uLong crc; |
@@ -17,8 +22,13 @@ uLong crc32(crc, buf, len) | |||
17 | { | 22 | { |
18 | if (buf == Z_NULL) return 0L; | 23 | if (buf == Z_NULL) return 0L; |
19 | crc = crc ^ 0xffffffffL; | 24 | crc = crc ^ 0xffffffffL; |
25 | while (len >= 8) | ||
26 | { | ||
27 | DO8(buf); | ||
28 | len -= 8; | ||
29 | } | ||
20 | if (len) do { | 30 | if (len) do { |
21 | crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); | 31 | DO1(buf); |
22 | } while (--len); | 32 | } while (--len); |
23 | return crc ^ 0xffffffffL; | 33 | return crc ^ 0xffffffffL; |
24 | } | 34 | } |
@@ -29,7 +39,7 @@ uLong crc32(crc, buf, len) | |||
29 | */ | 39 | */ |
30 | #ifdef DYNAMIC_CRC_TABLE | 40 | #ifdef DYNAMIC_CRC_TABLE |
31 | 41 | ||
32 | void make_crc_table() | 42 | local void make_crc_table() |
33 | { | 43 | { |
34 | uLong c; | 44 | uLong c; |
35 | int n, k; | 45 | int n, k; |
@@ -47,7 +47,7 @@ | |||
47 | * | 47 | * |
48 | */ | 48 | */ |
49 | 49 | ||
50 | /* $Id: deflate.c,v 1.5 1995/04/29 16:52:05 jloup Exp $ */ | 50 | /* $Id: deflate.c,v 1.6 1995/05/01 17:23:57 jloup Exp $ */ |
51 | 51 | ||
52 | #include "deflate.h" | 52 | #include "deflate.h" |
53 | 53 | ||
@@ -152,12 +152,20 @@ local void check_match __P((deflate_state *s, IPos start, IPos match, | |||
152 | s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ | 152 | s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ |
153 | s->head[s->ins_h] = (str)) | 153 | s->head[s->ins_h] = (str)) |
154 | 154 | ||
155 | /* =========================================================================== | ||
156 | * Initialize the hash table (avoiding 64K overflow for 16 bit systems). | ||
157 | * prev[] will be initialized on the fly. | ||
158 | */ | ||
159 | #define CLEAR_HASH(s) \ | ||
160 | s->head[s->hash_size-1] = NIL; \ | ||
161 | zmemzero((char*)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); | ||
162 | |||
155 | /* ========================================================================= */ | 163 | /* ========================================================================= */ |
156 | int deflateInit (strm, level) | 164 | int deflateInit (strm, level) |
157 | z_stream *strm; | 165 | z_stream *strm; |
158 | int level; | 166 | int level; |
159 | { | 167 | { |
160 | return deflateInit2 (strm, level, DEFLATED, WBITS, MEM_LEVEL, 0); | 168 | return deflateInit2 (strm, level, DEFLATED, MAX_WBITS, MAX_MEM_LEVEL, 0); |
161 | /* To do: ignore strm->next_in if we use it as window */ | 169 | /* To do: ignore strm->next_in if we use it as window */ |
162 | } | 170 | } |
163 | 171 | ||
@@ -345,6 +353,13 @@ int deflate (strm, flush) | |||
345 | } else { | 353 | } else { |
346 | if (deflate_slow(strm->state, flush)) return Z_OK; | 354 | if (deflate_slow(strm->state, flush)) return Z_OK; |
347 | } | 355 | } |
356 | /* ??? remember Z_FULL_FLUSH if we didn't have enough space */ | ||
357 | if (flush == Z_FULL_FLUSH) { | ||
358 | ct_stored_block(strm->state, (char*)0, 0L, 0); /* special marker */ | ||
359 | flush_pending(strm); | ||
360 | CLEAR_HASH(strm->state); /* forget history */ | ||
361 | if (strm->avail_out == 0) return Z_OK; | ||
362 | } | ||
348 | } | 363 | } |
349 | Assert(strm->avail_out > 0, "bug2"); | 364 | Assert(strm->avail_out > 0, "bug2"); |
350 | 365 | ||
@@ -435,12 +450,7 @@ local void lm_init (s) | |||
435 | 450 | ||
436 | s->window_size = (ulg)2L*s->w_size; | 451 | s->window_size = (ulg)2L*s->w_size; |
437 | 452 | ||
438 | 453 | CLEAR_HASH(s); | |
439 | /* Initialize the hash table (avoiding 64K overflow for 16 bit systems). | ||
440 | * prev[] will be initialized on the fly. | ||
441 | */ | ||
442 | s->head[s->hash_size-1] = NIL; | ||
443 | zmemzero((char*)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); | ||
444 | 454 | ||
445 | /* Set the default configuration parameters: | 455 | /* Set the default configuration parameters: |
446 | */ | 456 | */ |
@@ -930,8 +940,10 @@ local int deflate_slow(s, flush) | |||
930 | s->lookahead--; | 940 | s->lookahead--; |
931 | } | 941 | } |
932 | } | 942 | } |
933 | if (s->match_available) ct_tally (s, 0, s->window[s->strstart-1]); | 943 | if (s->match_available) { |
934 | 944 | ct_tally (s, 0, s->window[s->strstart-1]); | |
945 | s->match_available = 0; | ||
946 | } | ||
935 | FLUSH_BLOCK(s, flush == Z_FINISH); | 947 | FLUSH_BLOCK(s, flush == Z_FINISH); |
936 | return 0; | 948 | return 0; |
937 | } | 949 | } |
@@ -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.3 1995/04/14 12:39:45 jloup Exp $ */ | 11 | /* $Id: deflate.h,v 1.4 1995/05/01 15:08:45 jloup Exp $ */ |
12 | 12 | ||
13 | #include "zutil.h" | 13 | #include "zutil.h" |
14 | 14 | ||
@@ -268,3 +268,5 @@ typedef struct internal_state { | |||
268 | void ct_init __P((deflate_state *s)); | 268 | void ct_init __P((deflate_state *s)); |
269 | int ct_tally __P((deflate_state *s, int dist, int lc)); | 269 | int ct_tally __P((deflate_state *s, int dist, int lc)); |
270 | ulg ct_flush_block __P((deflate_state *s, char *buf, ulg stored_len, int eof)); | 270 | ulg ct_flush_block __P((deflate_state *s, char *buf, ulg stored_len, int eof)); |
271 | void ct_stored_block __P((deflate_state *s, char *buf, ulg stored_len, | ||
272 | int eof)); | ||
@@ -3,7 +3,7 @@ | |||
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
6 | /* $Id: example.c,v 1.6 1995/04/29 16:53:46 jloup Exp $ */ | 6 | /* $Id: example.c,v 1.7 1995/05/01 16:57:22 jloup Exp $ */ |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include "zlib.h" | 9 | #include "zlib.h" |
@@ -182,6 +182,81 @@ void test_inflate(compr) | |||
182 | } | 182 | } |
183 | 183 | ||
184 | /* =========================================================================== | 184 | /* =========================================================================== |
185 | * Test deflate() with full flush | ||
186 | */ | ||
187 | void test_flush(compr) | ||
188 | Byte compr[]; | ||
189 | { | ||
190 | z_stream c_stream; /* compression stream */ | ||
191 | int err; | ||
192 | int len = strlen(hello)+1; | ||
193 | |||
194 | c_stream.zalloc = (alloc_func)0; | ||
195 | c_stream.zfree = (free_func)0; | ||
196 | |||
197 | err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); | ||
198 | CHECK_ERR(err, "deflateInit"); | ||
199 | |||
200 | c_stream.next_in = (Byte*)hello; | ||
201 | c_stream.next_out = compr; | ||
202 | c_stream.avail_in = 3; | ||
203 | c_stream.avail_out = BUFLEN; | ||
204 | err = deflate(&c_stream, Z_FULL_FLUSH); | ||
205 | CHECK_ERR(err, "deflate"); | ||
206 | |||
207 | compr[3]++; /* force an error in first compressed block */ | ||
208 | c_stream.avail_in = len - 3; | ||
209 | |||
210 | err = deflate(&c_stream, Z_FINISH); | ||
211 | if (err != Z_STREAM_END) { | ||
212 | CHECK_ERR(err, "deflate"); | ||
213 | } | ||
214 | err = deflateEnd(&c_stream); | ||
215 | CHECK_ERR(err, "deflateEnd"); | ||
216 | } | ||
217 | |||
218 | /* =========================================================================== | ||
219 | * Test inflateSync() | ||
220 | */ | ||
221 | void test_sync(compr) | ||
222 | Byte compr[]; | ||
223 | { | ||
224 | local Byte uncompr[BUFLEN]; | ||
225 | int err; | ||
226 | z_stream d_stream; /* decompression stream */ | ||
227 | |||
228 | strcpy((char*)uncompr, "garbage"); | ||
229 | |||
230 | d_stream.zalloc = (alloc_func)0; | ||
231 | d_stream.zfree = (free_func)0; | ||
232 | |||
233 | err = inflateInit(&d_stream); | ||
234 | CHECK_ERR(err, "inflateInit"); | ||
235 | |||
236 | d_stream.next_in = compr; | ||
237 | d_stream.next_out = uncompr; | ||
238 | d_stream.avail_in = 2; /* just read the zlib header */ | ||
239 | d_stream.avail_out = sizeof(uncompr); | ||
240 | |||
241 | inflate(&d_stream, Z_NO_FLUSH); | ||
242 | CHECK_ERR(err, "inflate"); | ||
243 | |||
244 | d_stream.avail_in = BUFLEN-2; /* let inflate read all compressed data */ | ||
245 | err = inflateSync(&d_stream); /* skip the damaged part */ | ||
246 | CHECK_ERR(err, "inflateSync"); | ||
247 | |||
248 | err = inflate(&d_stream, Z_FINISH); | ||
249 | if (err != Z_DATA_ERROR) { | ||
250 | fprintf(stderr, "inflate should report DATA_ERROR\n"); | ||
251 | /* Because of incorrect adler32 */ | ||
252 | } | ||
253 | err = inflateEnd(&d_stream); | ||
254 | CHECK_ERR(err, "inflateEnd"); | ||
255 | |||
256 | printf("after inflateSync(): %s\n", uncompr); | ||
257 | } | ||
258 | |||
259 | /* =========================================================================== | ||
185 | * Usage: example [output.gz [input.gz]] | 260 | * Usage: example [output.gz [input.gz]] |
186 | */ | 261 | */ |
187 | 262 | ||
@@ -204,8 +279,10 @@ void main(argc, argv) | |||
204 | (argc > 2 ? argv[2] : "foo.gz")); | 279 | (argc > 2 ? argv[2] : "foo.gz")); |
205 | 280 | ||
206 | test_deflate(compr); | 281 | test_deflate(compr); |
207 | |||
208 | test_inflate(compr); | 282 | test_inflate(compr); |
209 | 283 | ||
284 | test_flush(compr); | ||
285 | test_sync(compr); | ||
286 | |||
210 | exit(0); | 287 | exit(0); |
211 | } | 288 | } |
@@ -3,7 +3,7 @@ | |||
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
6 | /* $Id: gzio.c,v 1.5 1995/04/29 17:13:56 jloup Exp $ */ | 6 | /* $Id: gzio.c,v 1.6 1995/04/30 19:52:21 jloup Exp $ */ |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | 9 | ||
@@ -128,7 +128,7 @@ local gzFile gz_open (path, mode, fd) | |||
128 | 128 | ||
129 | if (s->mode == 'w') { | 129 | if (s->mode == 'w') { |
130 | err = deflateInit2(&(s->stream), Z_DEFAULT_COMPRESSION, | 130 | err = deflateInit2(&(s->stream), Z_DEFAULT_COMPRESSION, |
131 | DEFLATED, -WBITS, MEM_LEVEL, 0); | 131 | DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, 0); |
132 | /* windowBits is passed < 0 to suppress zlib header */ | 132 | /* windowBits is passed < 0 to suppress zlib header */ |
133 | 133 | ||
134 | s->stream.next_out = s->outbuf = ALLOC(Z_BUFSIZE); | 134 | s->stream.next_out = s->outbuf = ALLOC(Z_BUFSIZE); |
@@ -137,7 +137,7 @@ local gzFile gz_open (path, mode, fd) | |||
137 | return destroy(s), (gzFile)Z_NULL; | 137 | return destroy(s), (gzFile)Z_NULL; |
138 | } | 138 | } |
139 | } else { | 139 | } else { |
140 | err = inflateInit2(&(s->stream), -WBITS); | 140 | err = inflateInit2(&(s->stream), -MAX_WBITS); |
141 | s->stream.next_in = s->inbuf = ALLOC(Z_BUFSIZE); | 141 | s->stream.next_in = s->inbuf = ALLOC(Z_BUFSIZE); |
142 | 142 | ||
143 | if (err != Z_OK || s->inbuf == Z_NULL) { | 143 | if (err != Z_OK || s->inbuf == Z_NULL) { |
@@ -249,7 +249,7 @@ int gzread (file, buf, len) | |||
249 | len--; n++; | 249 | len--; n++; |
250 | } | 250 | } |
251 | if (len == 0) return n; | 251 | if (len == 0) return n; |
252 | return n + fread(buf, 1, len, s->file); | 252 | return n + fread(b, 1, len, s->file); |
253 | } | 253 | } |
254 | if (s->z_err == Z_DATA_ERROR) return -1; /* bad .gz file */ | 254 | if (s->z_err == Z_DATA_ERROR) return -1; /* bad .gz file */ |
255 | if (s->z_err == Z_STREAM_END) return 0; /* don't read crc as data */ | 255 | if (s->z_err == Z_STREAM_END) return 0; /* don't read crc as data */ |
@@ -60,6 +60,28 @@ local uInt border[] = { /* Order of the bit length code lengths */ | |||
60 | the two sets of lengths. | 60 | the two sets of lengths. |
61 | */ | 61 | */ |
62 | 62 | ||
63 | |||
64 | void inflate_blocks_reset(s, z, c) | ||
65 | struct inflate_blocks_state *s; | ||
66 | z_stream *z; | ||
67 | uLong *c; | ||
68 | { | ||
69 | if (s->checkfn != Z_NULL) | ||
70 | *c = s->check; | ||
71 | if (s->mode == BTREE || s->mode == DTREE) | ||
72 | ZFREE(z, s->sub.trees.blens); | ||
73 | if (s->mode == CODES) | ||
74 | inflate_codes_free(s->sub.codes, z); | ||
75 | s->mode = TYPE; | ||
76 | s->bitk = 0; | ||
77 | s->bitb = 0; | ||
78 | s->read = s->write = s->window; | ||
79 | if (s->checkfn != Z_NULL) | ||
80 | s->check = (*s->checkfn)(0L, Z_NULL, 0); | ||
81 | Trace((stderr, "inflate: blocks reset\n")); | ||
82 | } | ||
83 | |||
84 | |||
63 | struct inflate_blocks_state *inflate_blocks_new(z, c, w) | 85 | struct inflate_blocks_state *inflate_blocks_new(z, c, w) |
64 | z_stream *z; | 86 | z_stream *z; |
65 | check_func c; | 87 | check_func c; |
@@ -75,13 +97,11 @@ uInt w; | |||
75 | ZFREE(z, s); | 97 | ZFREE(z, s); |
76 | return Z_NULL; | 98 | return Z_NULL; |
77 | } | 99 | } |
78 | s->mode = TYPE; | ||
79 | s->bitk = 0; | ||
80 | s->read = s->write = s->window; | ||
81 | s->end = s->window + w; | 100 | s->end = s->window + w; |
82 | s->checkfn = c; | 101 | s->checkfn = c; |
83 | if (s->checkfn != Z_NULL) | 102 | s->mode = TYPE; |
84 | s->check = (*s->checkfn)(0L, Z_NULL, 0); | 103 | Trace((stderr, "inflate: blocks allocated\n")); |
104 | inflate_blocks_reset(s, z, &s->check); | ||
85 | return s; | 105 | return s; |
86 | } | 106 | } |
87 | 107 | ||
@@ -112,12 +132,16 @@ int r; | |||
112 | switch (t >> 1) | 132 | switch (t >> 1) |
113 | { | 133 | { |
114 | case 0: /* stored */ | 134 | case 0: /* stored */ |
135 | Trace((stderr, "inflate: stored block%s\n", | ||
136 | s->last ? " (last)" : "")); | ||
115 | DUMPBITS(3) | 137 | DUMPBITS(3) |
116 | t = k & 7; /* go to byte boundary */ | 138 | t = k & 7; /* go to byte boundary */ |
117 | DUMPBITS(t) | 139 | DUMPBITS(t) |
118 | s->mode = LENS; /* get length of stored block */ | 140 | s->mode = LENS; /* get length of stored block */ |
119 | break; | 141 | break; |
120 | case 1: /* fixed */ | 142 | case 1: /* fixed */ |
143 | Trace((stderr, "inflate: fixed codes block%s\n", | ||
144 | s->last ? " (last)" : "")); | ||
121 | { | 145 | { |
122 | uInt bl, bd; | 146 | uInt bl, bd; |
123 | inflate_huft *tl, *td; | 147 | inflate_huft *tl, *td; |
@@ -134,12 +158,14 @@ int r; | |||
134 | s->mode = CODES; | 158 | s->mode = CODES; |
135 | break; | 159 | break; |
136 | case 2: /* dynamic */ | 160 | case 2: /* dynamic */ |
161 | Trace((stderr, "inflate: dynamic codes block%s\n", | ||
162 | s->last ? " (last)" : "")); | ||
137 | DUMPBITS(3) | 163 | DUMPBITS(3) |
138 | s->mode = TABLE; | 164 | s->mode = TABLE; |
139 | break; | 165 | break; |
140 | case 3: /* illegal */ | 166 | case 3: /* illegal */ |
141 | DUMPBITS(3) | 167 | DUMPBITS(3) |
142 | s->mode = INF_ERROR; | 168 | s->mode = BAD; |
143 | z->msg = "invalid block type"; | 169 | z->msg = "invalid block type"; |
144 | r = Z_DATA_ERROR; | 170 | r = Z_DATA_ERROR; |
145 | LEAVE | 171 | LEAVE |
@@ -149,13 +175,14 @@ int r; | |||
149 | NEEDBITS(32) | 175 | NEEDBITS(32) |
150 | if ((~b) >> 16 != (b & 0xffff)) | 176 | if ((~b) >> 16 != (b & 0xffff)) |
151 | { | 177 | { |
152 | s->mode = INF_ERROR; | 178 | s->mode = BAD; |
153 | z->msg = "invalid stored block lengths"; | 179 | z->msg = "invalid stored block lengths"; |
154 | r = Z_DATA_ERROR; | 180 | r = Z_DATA_ERROR; |
155 | LEAVE | 181 | LEAVE |
156 | } | 182 | } |
157 | k = 0; /* dump bits */ | 183 | k = 0; /* dump bits */ |
158 | s->sub.left = (uInt)b & 0xffff; | 184 | s->sub.left = (uInt)b & 0xffff; |
185 | Tracev((stderr, "inflate: stored length %u\n", s->sub.left)); | ||
159 | s->mode = s->sub.left ? STORED : TYPE; | 186 | s->mode = s->sub.left ? STORED : TYPE; |
160 | break; | 187 | break; |
161 | case STORED: | 188 | case STORED: |
@@ -164,6 +191,9 @@ int r; | |||
164 | NEEDOUT | 191 | NEEDOUT |
165 | OUTBYTE(NEXTBYTE) | 192 | OUTBYTE(NEXTBYTE) |
166 | } while (--s->sub.left); | 193 | } while (--s->sub.left); |
194 | Tracev((stderr, "inflate: stored end, %lu total out\n", | ||
195 | z->total_out + (q >= s->read ? q - s->read : | ||
196 | (s->end - s->read) + (q - s->window)))); | ||
167 | s->mode = s->last ? DRY : TYPE; | 197 | s->mode = s->last ? DRY : TYPE; |
168 | break; | 198 | break; |
169 | case TABLE: | 199 | case TABLE: |
@@ -172,7 +202,7 @@ int r; | |||
172 | #ifndef PKZIP_BUG_WORKAROUND | 202 | #ifndef PKZIP_BUG_WORKAROUND |
173 | if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) | 203 | if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) |
174 | { | 204 | { |
175 | s->mode = INF_ERROR; | 205 | s->mode = BAD; |
176 | z->msg = "too many length or distance symbols"; | 206 | z->msg = "too many length or distance symbols"; |
177 | r = Z_DATA_ERROR; | 207 | r = Z_DATA_ERROR; |
178 | LEAVE | 208 | LEAVE |
@@ -188,6 +218,7 @@ int r; | |||
188 | } | 218 | } |
189 | DUMPBITS(14) | 219 | DUMPBITS(14) |
190 | s->sub.trees.index = 0; | 220 | s->sub.trees.index = 0; |
221 | Tracev((stderr, "inflate: table sizes ok\n")); | ||
191 | s->mode = BTREE; | 222 | s->mode = BTREE; |
192 | case BTREE: | 223 | case BTREE: |
193 | while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) | 224 | while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) |
@@ -205,10 +236,11 @@ int r; | |||
205 | { | 236 | { |
206 | r = t; | 237 | r = t; |
207 | if (r == Z_DATA_ERROR) | 238 | if (r == Z_DATA_ERROR) |
208 | s->mode = INF_ERROR; | 239 | s->mode = BAD; |
209 | LEAVE | 240 | LEAVE |
210 | } | 241 | } |
211 | s->sub.trees.index = 0; | 242 | s->sub.trees.index = 0; |
243 | Tracev((stderr, "inflate: bits tree ok\n")); | ||
212 | s->mode = DTREE; | 244 | s->mode = DTREE; |
213 | case DTREE: | 245 | case DTREE: |
214 | while (t = s->sub.trees.table, | 246 | while (t = s->sub.trees.table, |
@@ -240,7 +272,7 @@ int r; | |||
240 | if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || | 272 | if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || |
241 | (c == 16 && i < 1)) | 273 | (c == 16 && i < 1)) |
242 | { | 274 | { |
243 | s->mode = INF_ERROR; | 275 | s->mode = BAD; |
244 | z->msg = "invalid bit length repeat"; | 276 | z->msg = "invalid bit length repeat"; |
245 | r = Z_DATA_ERROR; | 277 | r = Z_DATA_ERROR; |
246 | LEAVE | 278 | LEAVE |
@@ -267,10 +299,11 @@ int r; | |||
267 | if (t != Z_OK) | 299 | if (t != Z_OK) |
268 | { | 300 | { |
269 | if (t == (uInt)Z_DATA_ERROR) | 301 | if (t == (uInt)Z_DATA_ERROR) |
270 | s->mode = INF_ERROR; | 302 | s->mode = BAD; |
271 | r = t; | 303 | r = t; |
272 | LEAVE | 304 | LEAVE |
273 | } | 305 | } |
306 | Tracev((stderr, "inflate: trees ok\n")); | ||
274 | if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) | 307 | if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) |
275 | { | 308 | { |
276 | inflate_trees_free(td, z); | 309 | inflate_trees_free(td, z); |
@@ -289,17 +322,20 @@ int r; | |||
289 | r = Z_OK; | 322 | r = Z_OK; |
290 | inflate_codes_free(s->sub.codes, z); | 323 | inflate_codes_free(s->sub.codes, z); |
291 | LOAD | 324 | LOAD |
325 | Tracev((stderr, "inflate: codes end, %lu total out\n", | ||
326 | z->total_out + (q >= s->read ? q - s->read : | ||
327 | (s->end - s->read) + (q - s->window)))); | ||
292 | if (!s->last) | 328 | if (!s->last) |
293 | { | 329 | { |
294 | s->mode = TYPE; | 330 | s->mode = TYPE; |
295 | break; | 331 | break; |
296 | } | 332 | } |
297 | if (k > 7) /* return unused byte, if any */ | 333 | if (k > 7) /* return unused byte, if any */ |
298 | { | 334 | { |
299 | Assert(k < 16, "inflate_codes grabbed too many bytes") | 335 | Assert(k < 16, "inflate_codes grabbed too many bytes") |
300 | k -= 8; | 336 | k -= 8; |
301 | n++; | 337 | n++; |
302 | p--; /* can always return one */ | 338 | p--; /* can always return one */ |
303 | } | 339 | } |
304 | s->mode = DRY; | 340 | s->mode = DRY; |
305 | case DRY: | 341 | case DRY: |
@@ -310,7 +346,7 @@ int r; | |||
310 | case DONE: | 346 | case DONE: |
311 | r = Z_STREAM_END; | 347 | r = Z_STREAM_END; |
312 | LEAVE | 348 | LEAVE |
313 | case INF_ERROR: | 349 | case BAD: |
314 | r = Z_DATA_ERROR; | 350 | r = Z_DATA_ERROR; |
315 | LEAVE | 351 | LEAVE |
316 | default: | 352 | default: |
@@ -325,13 +361,9 @@ struct inflate_blocks_state *s; | |||
325 | z_stream *z; | 361 | z_stream *z; |
326 | uLong *c; | 362 | uLong *c; |
327 | { | 363 | { |
328 | if (s->checkfn != Z_NULL) | 364 | inflate_blocks_reset(s, z, c); |
329 | *c = s->check; | ||
330 | if (s->mode == BTREE || s->mode == DTREE) | ||
331 | ZFREE(z, s->sub.trees.blens); | ||
332 | if (s->mode == CODES) | ||
333 | inflate_codes_free(s->sub.codes, z); | ||
334 | ZFREE(z, s->window); | 365 | ZFREE(z, s->window); |
335 | ZFREE(z, s); | 366 | ZFREE(z, s); |
367 | Trace((stderr, "inflate: blocks freed\n")); | ||
336 | return Z_OK; | 368 | return Z_OK; |
337 | } | 369 | } |
@@ -11,16 +11,21 @@ | |||
11 | struct inflate_blocks_state; | 11 | struct inflate_blocks_state; |
12 | 12 | ||
13 | extern struct inflate_blocks_state * inflate_blocks_new __P(( | 13 | extern struct inflate_blocks_state * inflate_blocks_new __P(( |
14 | z_stream *z, | 14 | z_stream *, |
15 | check_func c, /* check function */ | 15 | check_func, /* check function */ |
16 | uInt w)); /* window size */ | 16 | uInt)); /* window size */ |
17 | 17 | ||
18 | extern int inflate_blocks __P(( | 18 | extern int inflate_blocks __P(( |
19 | struct inflate_blocks_state *, | 19 | struct inflate_blocks_state *, |
20 | z_stream *, | 20 | z_stream *, |
21 | int)); /* initial return code */ | 21 | int)); /* initial return code */ |
22 | 22 | ||
23 | extern void inflate_blocks_reset __P(( | ||
24 | struct inflate_blocks_state *, | ||
25 | z_stream *, | ||
26 | uLong *)); /* check value on output */ | ||
27 | |||
23 | extern int inflate_blocks_free __P(( | 28 | extern int inflate_blocks_free __P(( |
24 | struct inflate_blocks_state *, | 29 | struct inflate_blocks_state *, |
25 | z_stream *, | 30 | z_stream *, |
26 | uLong *)); /* check value on output */ | 31 | uLong *)); /* check value on output */ |
@@ -29,7 +29,7 @@ struct inflate_codes_state { | |||
29 | LIT, /* o: got literal, waiting for output space */ | 29 | LIT, /* o: got literal, waiting for output space */ |
30 | WASH, /* o: got eob, possibly still output waiting */ | 30 | WASH, /* o: got eob, possibly still output waiting */ |
31 | END, /* x: got eob and all data flushed */ | 31 | END, /* x: got eob and all data flushed */ |
32 | BAD} /* x: got error */ | 32 | BADCODE} /* x: got error */ |
33 | mode; /* current inflate_codes mode */ | 33 | mode; /* current inflate_codes mode */ |
34 | 34 | ||
35 | /* mode dependent information */ | 35 | /* mode dependent information */ |
@@ -70,6 +70,7 @@ z_stream *z; | |||
70 | c->dbits = (Byte)bd; | 70 | c->dbits = (Byte)bd; |
71 | c->ltree = tl; | 71 | c->ltree = tl; |
72 | c->dtree = td; | 72 | c->dtree = td; |
73 | Tracev((stderr, "inflate: codes new\n")); | ||
73 | } | 74 | } |
74 | return c; | 75 | return c; |
75 | } | 76 | } |
@@ -107,7 +108,7 @@ int r; | |||
107 | LOAD | 108 | LOAD |
108 | if (r != Z_OK) | 109 | if (r != Z_OK) |
109 | { | 110 | { |
110 | c->mode = r == Z_STREAM_END ? WASH : BAD; | 111 | c->mode = r == Z_STREAM_END ? WASH : BADCODE; |
111 | break; | 112 | break; |
112 | } | 113 | } |
113 | } | 114 | } |
@@ -124,7 +125,7 @@ int r; | |||
124 | { | 125 | { |
125 | if (e == -128) /* invalid code */ | 126 | if (e == -128) /* invalid code */ |
126 | { | 127 | { |
127 | c->mode = BAD; | 128 | c->mode = BADCODE; |
128 | z->msg = "invalid literal/length code"; | 129 | z->msg = "invalid literal/length code"; |
129 | r = Z_DATA_ERROR; | 130 | r = Z_DATA_ERROR; |
130 | LEAVE | 131 | LEAVE |
@@ -132,6 +133,7 @@ int r; | |||
132 | e = -e; | 133 | e = -e; |
133 | if (e & 64) /* end of block */ | 134 | if (e & 64) /* end of block */ |
134 | { | 135 | { |
136 | Tracevv((stderr, "inflate: end of block\n")); | ||
135 | c->mode = WASH; | 137 | c->mode = WASH; |
136 | break; | 138 | break; |
137 | } | 139 | } |
@@ -142,6 +144,9 @@ int r; | |||
142 | if (e & 16) /* literal */ | 144 | if (e & 16) /* literal */ |
143 | { | 145 | { |
144 | c->sub.lit = t->base; | 146 | c->sub.lit = t->base; |
147 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? | ||
148 | "inflate: literal '%c'\n" : | ||
149 | "inflate: literal 0x%02x\n", t->base)); | ||
145 | c->mode = LIT; | 150 | c->mode = LIT; |
146 | break; | 151 | break; |
147 | } | 152 | } |
@@ -155,6 +160,7 @@ int r; | |||
155 | DUMPBITS(j) | 160 | DUMPBITS(j) |
156 | c->sub.code.need = c->dbits; | 161 | c->sub.code.need = c->dbits; |
157 | c->sub.code.tree = c->dtree; | 162 | c->sub.code.tree = c->dtree; |
163 | Tracevv((stderr, "inflate: length %u\n", c->len)); | ||
158 | c->mode = DIST; | 164 | c->mode = DIST; |
159 | case DIST: /* i: get distance next */ | 165 | case DIST: /* i: get distance next */ |
160 | j = c->sub.code.need; | 166 | j = c->sub.code.need; |
@@ -165,7 +171,7 @@ int r; | |||
165 | { | 171 | { |
166 | if (e == -128) | 172 | if (e == -128) |
167 | { | 173 | { |
168 | c->mode = BAD; | 174 | c->mode = BADCODE; |
169 | z->msg = "invalid distance code"; | 175 | z->msg = "invalid distance code"; |
170 | r = Z_DATA_ERROR; | 176 | r = Z_DATA_ERROR; |
171 | LEAVE | 177 | LEAVE |
@@ -182,6 +188,7 @@ int r; | |||
182 | NEEDBITS(j) | 188 | NEEDBITS(j) |
183 | c->sub.copy.dist += (uInt)b & inflate_mask[j]; | 189 | c->sub.copy.dist += (uInt)b & inflate_mask[j]; |
184 | DUMPBITS(j) | 190 | DUMPBITS(j) |
191 | Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); | ||
185 | c->mode = COPY; | 192 | c->mode = COPY; |
186 | case COPY: /* o: copying bytes in window, waiting for space */ | 193 | case COPY: /* o: copying bytes in window, waiting for space */ |
187 | f = (uInt)(q - s->window) < c->sub.copy.dist ? | 194 | f = (uInt)(q - s->window) < c->sub.copy.dist ? |
@@ -210,7 +217,7 @@ int r; | |||
210 | case END: | 217 | case END: |
211 | r = Z_STREAM_END; | 218 | r = Z_STREAM_END; |
212 | LEAVE | 219 | LEAVE |
213 | case BAD: /* x: got error */ | 220 | case BADCODE: /* x: got error */ |
214 | r = Z_DATA_ERROR; | 221 | r = Z_DATA_ERROR; |
215 | LEAVE | 222 | LEAVE |
216 | default: | 223 | default: |
@@ -227,4 +234,5 @@ z_stream *z; | |||
227 | inflate_trees_free(c->dtree, z); | 234 | inflate_trees_free(c->dtree, z); |
228 | inflate_trees_free(c->ltree, z); | 235 | inflate_trees_free(c->ltree, z); |
229 | ZFREE(z, c); | 236 | ZFREE(z, c); |
237 | Tracev((stderr, "inflate: codes free\n")); | ||
230 | } | 238 | } |
@@ -73,6 +73,7 @@ z_stream *z; | |||
73 | e = -e; | 73 | e = -e; |
74 | if (e & 64) /* end of block */ | 74 | if (e & 64) /* end of block */ |
75 | { | 75 | { |
76 | Tracevv((stderr, "inflate: * end of block\n")); | ||
76 | UNGRAB | 77 | UNGRAB |
77 | UPDATE | 78 | UPDATE |
78 | return Z_STREAM_END; | 79 | return Z_STREAM_END; |
@@ -83,6 +84,9 @@ z_stream *z; | |||
83 | /* process literal or length (end of block already trapped) */ | 84 | /* process literal or length (end of block already trapped) */ |
84 | if (e & 16) /* then it's a literal */ | 85 | if (e & 16) /* then it's a literal */ |
85 | { | 86 | { |
87 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? | ||
88 | "inflate: * literal '%c'\n" : | ||
89 | "inflate: * literal 0x%02x\n", t->base)); | ||
86 | *q++ = (Byte)t->base; | 90 | *q++ = (Byte)t->base; |
87 | m--; | 91 | m--; |
88 | } | 92 | } |
@@ -91,6 +95,7 @@ z_stream *z; | |||
91 | /* get length of block to copy (already have extra bits) */ | 95 | /* get length of block to copy (already have extra bits) */ |
92 | c = t->base + ((uInt)b & inflate_mask[e]); | 96 | c = t->base + ((uInt)b & inflate_mask[e]); |
93 | DUMPBITS(e); | 97 | DUMPBITS(e); |
98 | Tracevv((stderr, "inflate: * length %u\n", c)); | ||
94 | 99 | ||
95 | /* decode distance base of block to copy */ | 100 | /* decode distance base of block to copy */ |
96 | GRABBITS(15); /* max bits for distance code */ | 101 | GRABBITS(15); /* max bits for distance code */ |
@@ -109,13 +114,14 @@ z_stream *z; | |||
109 | DUMPBITS(t->bits) | 114 | DUMPBITS(t->bits) |
110 | 115 | ||
111 | /* get extra bits to add to distance base */ | 116 | /* get extra bits to add to distance base */ |
112 | GRABBITS(e) /* get extra bits (up to 13) */ | 117 | GRABBITS((uInt)e) /* get extra bits (up to 13) */ |
113 | d = t->base + ((uInt)b & inflate_mask[e]); | 118 | d = t->base + ((uInt)b & inflate_mask[e]); |
114 | DUMPBITS(e) | 119 | DUMPBITS(e) |
120 | Tracevv((stderr, "inflate: * distance %u\n", d)); | ||
115 | 121 | ||
116 | /* do the copy */ | 122 | /* do the copy */ |
117 | m -= c; | 123 | m -= c; |
118 | if (q - s->window >= d) /* if offset before destination, */ | 124 | if ((uInt)(q - s->window) >= d) /* if offset before destination, */ |
119 | { /* just copy */ | 125 | { /* just copy */ |
120 | r = q - d; | 126 | r = q - d; |
121 | *q++ = *r++; c--; /* minimum count is three, */ | 127 | *q++ = *r++; c--; /* minimum count is three, */ |
@@ -128,7 +134,7 @@ z_stream *z; | |||
128 | { | 134 | { |
129 | e = d - (q - s->window); /* bytes from offset to end */ | 135 | e = d - (q - s->window); /* bytes from offset to end */ |
130 | r = s->end - e; /* pointer to offset */ | 136 | r = s->end - e; /* pointer to offset */ |
131 | if (c > e) /* if source crosses, */ | 137 | if (c > (uInt)e) /* if source crosses, */ |
132 | { | 138 | { |
133 | c -= e; /* copy to end of window */ | 139 | c -= e; /* copy to end of window */ |
134 | do { | 140 | do { |
@@ -15,38 +15,63 @@ struct internal_state { | |||
15 | enum { | 15 | enum { |
16 | METHOD, /* waiting for method byte */ | 16 | METHOD, /* waiting for method byte */ |
17 | FLAG, /* waiting for flag byte */ | 17 | FLAG, /* waiting for flag byte */ |
18 | START, /* make new blocks state */ | ||
19 | BLOCKS, /* decompressing blocks */ | 18 | BLOCKS, /* decompressing blocks */ |
20 | CHECK4, /* four check bytes to go */ | 19 | CHECK4, /* four check bytes to go */ |
21 | CHECK3, /* three check bytes to go */ | 20 | CHECK3, /* three check bytes to go */ |
22 | CHECK2, /* two check bytes to go */ | 21 | CHECK2, /* two check bytes to go */ |
23 | CHECK1, /* one check byte to go */ | 22 | CHECK1, /* one check byte to go */ |
24 | DONE, /* finished check, done */ | 23 | DONE, /* finished check, done */ |
25 | INF_ERROR}/* got an error--stay here */ | 24 | BAD} /* got an error--stay here */ |
26 | mode; /* current inflate mode */ | 25 | mode; /* current inflate mode */ |
27 | 26 | ||
28 | /* mode dependent information */ | 27 | /* mode dependent information */ |
29 | union { | 28 | union { |
30 | uInt method; /* if FLAGS, method byte */ | 29 | uInt method; /* if FLAGS, method byte */ |
31 | struct inflate_blocks_state | ||
32 | *blocks; /* if BLOCKS, current state */ | ||
33 | struct { | 30 | struct { |
34 | uLong was; /* computed check value */ | 31 | uLong was; /* computed check value */ |
35 | uLong need; /* stream check value */ | 32 | uLong need; /* stream check value */ |
36 | } check; /* if CHECK, check values to compare */ | 33 | } check; /* if CHECK, check values to compare */ |
34 | uInt marker; /* if BAD, inflateSync's marker bytes count */ | ||
37 | } sub; /* submode */ | 35 | } sub; /* submode */ |
38 | 36 | ||
39 | /* mode independent information */ | 37 | /* mode independent information */ |
40 | int nowrap; /* flag for no wrapper */ | 38 | int nowrap; /* flag for no wrapper */ |
41 | uInt wbits; /* log2(window size) (8..15, defaults to 15) */ | 39 | uInt wbits; /* log2(window size) (8..15, defaults to 15) */ |
40 | struct inflate_blocks_state | ||
41 | *blocks; /* current inflate_blocks state */ | ||
42 | 42 | ||
43 | }; | 43 | }; |
44 | 44 | ||
45 | 45 | ||
46 | int inflateInit(z) | 46 | int inflateReset(z) |
47 | z_stream *z; | 47 | z_stream *z; |
48 | { | 48 | { |
49 | return inflateInit2(z, WBITS); | 49 | uLong c; |
50 | |||
51 | if (z == Z_NULL || z->state == Z_NULL) | ||
52 | return Z_STREAM_ERROR; | ||
53 | z->total_in = z->total_out = 0; | ||
54 | z->msg = Z_NULL; | ||
55 | z->state->mode = z->state->nowrap ? BLOCKS : METHOD; | ||
56 | inflate_blocks_reset(z->state->blocks, z, &c); | ||
57 | Trace((stderr, "inflate: reset\n")); | ||
58 | return Z_OK; | ||
59 | } | ||
60 | |||
61 | |||
62 | int inflateEnd(z) | ||
63 | z_stream *z; | ||
64 | { | ||
65 | uLong c; | ||
66 | |||
67 | if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) | ||
68 | return Z_STREAM_ERROR; | ||
69 | if (z->state->blocks != Z_NULL) | ||
70 | inflate_blocks_free(z->state->blocks, z, &c); | ||
71 | ZFREE(z, z->state); | ||
72 | z->state = Z_NULL; | ||
73 | Trace((stderr, "inflate: end\n")); | ||
74 | return Z_OK; | ||
50 | } | 75 | } |
51 | 76 | ||
52 | 77 | ||
@@ -59,12 +84,10 @@ int w; | |||
59 | return Z_STREAM_ERROR; | 84 | return Z_STREAM_ERROR; |
60 | if (z->zalloc == Z_NULL) z->zalloc = zcalloc; | 85 | if (z->zalloc == Z_NULL) z->zalloc = zcalloc; |
61 | if (z->zfree == Z_NULL) z->zfree = zcfree; | 86 | if (z->zfree == Z_NULL) z->zfree = zcfree; |
62 | z->total_in = z->total_out = 0; | ||
63 | z->msg = Z_NULL; | ||
64 | if ((z->state = (struct internal_state *) | 87 | if ((z->state = (struct internal_state *) |
65 | ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) | 88 | ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) |
66 | return Z_MEM_ERROR; | 89 | return Z_MEM_ERROR; |
67 | z->state->mode = METHOD; | 90 | z->state->blocks = Z_NULL; |
68 | 91 | ||
69 | /* handle undocumented nowrap option (no zlib header or check) */ | 92 | /* handle undocumented nowrap option (no zlib header or check) */ |
70 | z->state->nowrap = 0; | 93 | z->state->nowrap = 0; |
@@ -72,7 +95,6 @@ int w; | |||
72 | { | 95 | { |
73 | w = - w; | 96 | w = - w; |
74 | z->state->nowrap = 1; | 97 | z->state->nowrap = 1; |
75 | z->state->mode = START; | ||
76 | } | 98 | } |
77 | 99 | ||
78 | /* set window size */ | 100 | /* set window size */ |
@@ -81,20 +103,40 @@ int w; | |||
81 | inflateEnd(z); | 103 | inflateEnd(z); |
82 | return Z_STREAM_ERROR; | 104 | return Z_STREAM_ERROR; |
83 | } | 105 | } |
84 | z->state->wbits = w; | 106 | z->state->wbits = (uInt)w; |
107 | |||
108 | /* create inflate_blocks state */ | ||
109 | if ((z->state->blocks = | ||
110 | inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w)) | ||
111 | == Z_NULL) | ||
112 | { | ||
113 | inflateEnd(z); | ||
114 | return Z_MEM_ERROR; | ||
115 | } | ||
116 | Trace((stderr, "inflate: allocated\n")); | ||
117 | |||
118 | /* reset state */ | ||
119 | inflateReset(z); | ||
85 | return Z_OK; | 120 | return Z_OK; |
86 | } | 121 | } |
87 | 122 | ||
88 | 123 | ||
124 | int inflateInit(z) | ||
125 | z_stream *z; | ||
126 | { | ||
127 | return inflateInit2(z, DEF_WBITS); | ||
128 | } | ||
129 | |||
130 | |||
131 | #define NEEDBYTE {if(z->avail_in==0)return r;r=Z_OK;} | ||
89 | #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) | 132 | #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) |
90 | 133 | ||
91 | int inflate(z, f) | 134 | int inflate(z, f) |
92 | z_stream *z; | 135 | z_stream *z; |
93 | int f; | 136 | int f; |
94 | { | 137 | { |
95 | int r = f; /* to avoid warning about unused f */ | 138 | int r = f; /* to avoid warning about unused f */ |
96 | uInt b; | 139 | uInt b; |
97 | uLong c; | ||
98 | 140 | ||
99 | if (z == Z_NULL || z->next_in == Z_NULL) | 141 | if (z == Z_NULL || z->next_in == Z_NULL) |
100 | return Z_STREAM_ERROR; | 142 | return Z_STREAM_ERROR; |
@@ -102,77 +144,86 @@ int f; | |||
102 | while (1) switch (z->state->mode) | 144 | while (1) switch (z->state->mode) |
103 | { | 145 | { |
104 | case METHOD: | 146 | case METHOD: |
105 | if (z->avail_in == 0) return r; r = Z_OK; | 147 | NEEDBYTE |
106 | if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED)) | 148 | if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED)) |
107 | { | 149 | { |
108 | z->state->mode = INF_ERROR; | 150 | z->state->mode = BAD; |
109 | z->msg = "unknown compression method"; | 151 | z->msg = "unknown compression method"; |
110 | return Z_DATA_ERROR; | 152 | z->state->sub.marker = 5; /* can't try inflateSync */ |
153 | break; | ||
111 | } | 154 | } |
112 | if ((z->state->sub.method >> 4) + 8 > z->state->wbits) | 155 | if ((z->state->sub.method >> 4) + 8 > z->state->wbits) |
113 | { | 156 | { |
114 | z->state->mode = INF_ERROR; | 157 | z->state->mode = BAD; |
115 | z->msg = "invalid window size"; | 158 | z->msg = "invalid window size"; |
116 | return Z_DATA_ERROR; | 159 | z->state->sub.marker = 5; /* can't try inflateSync */ |
160 | break; | ||
117 | } | 161 | } |
118 | z->state->mode = FLAG; | 162 | z->state->mode = FLAG; |
119 | case FLAG: | 163 | case FLAG: |
120 | if (z->avail_in == 0) return r; r = Z_OK; | 164 | NEEDBYTE |
121 | if ((b = NEXTBYTE) & 0x20) | 165 | if ((b = NEXTBYTE) & 0x20) |
122 | { | 166 | { |
123 | z->state->mode = INF_ERROR; | 167 | z->state->mode = BAD; |
124 | z->msg = "invalid reserved bit"; | 168 | z->msg = "invalid reserved bit"; |
125 | return Z_DATA_ERROR; | 169 | z->state->sub.marker = 5; /* can't try inflateSync */ |
170 | break; | ||
126 | } | 171 | } |
127 | if (((z->state->sub.method << 8) + b) % 31) | 172 | if (((z->state->sub.method << 8) + b) % 31) |
128 | { | 173 | { |
129 | z->state->mode = INF_ERROR; | 174 | z->state->mode = BAD; |
130 | z->msg = "incorrect header check"; | 175 | z->msg = "incorrect header check"; |
131 | return Z_DATA_ERROR; | 176 | z->state->sub.marker = 5; /* can't try inflateSync */ |
177 | break; | ||
132 | } | 178 | } |
133 | z->state->mode = START; | 179 | Trace((stderr, "inflate: zlib header ok\n")); |
134 | case START: | ||
135 | if ((z->state->sub.blocks = inflate_blocks_new(z, | ||
136 | z->state->nowrap ? Z_NULL : adler32, | ||
137 | 1<< z->state->wbits)) == Z_NULL) | ||
138 | return Z_MEM_ERROR; | ||
139 | z->state->mode = BLOCKS; | 180 | z->state->mode = BLOCKS; |
140 | case BLOCKS: | 181 | case BLOCKS: |
141 | if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END) | 182 | r = inflate_blocks(z->state->blocks, z, r); |
142 | return r; | 183 | if (r == Z_DATA_ERROR) |
143 | inflate_blocks_free(z->state->sub.blocks, z, &c); | 184 | { |
185 | z->state->mode = BAD; | ||
186 | z->state->sub.marker = 0; /* can try inflateSync */ | ||
187 | break; | ||
188 | } | ||
189 | if (r != Z_STREAM_END) | ||
190 | return r; | ||
191 | r = Z_OK; | ||
192 | inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); | ||
144 | if (z->state->nowrap) | 193 | if (z->state->nowrap) |
145 | { | 194 | { |
146 | z->state->mode = DONE; | 195 | z->state->mode = DONE; |
147 | break; | 196 | break; |
148 | } | 197 | } |
149 | z->state->sub.check.was = c; | ||
150 | z->state->mode = CHECK4; | 198 | z->state->mode = CHECK4; |
151 | case CHECK4: | 199 | case CHECK4: |
152 | if (z->avail_in == 0) return r; r = Z_OK; | 200 | NEEDBYTE |
153 | z->state->sub.check.need = (uLong)NEXTBYTE << 24; | 201 | z->state->sub.check.need = (uLong)NEXTBYTE << 24; |
154 | z->state->mode = CHECK3; | 202 | z->state->mode = CHECK3; |
155 | case CHECK3: | 203 | case CHECK3: |
156 | if (z->avail_in == 0) return r; r = Z_OK; | 204 | NEEDBYTE |
157 | z->state->sub.check.need += (uLong)NEXTBYTE << 16; | 205 | z->state->sub.check.need += (uLong)NEXTBYTE << 16; |
158 | z->state->mode = CHECK2; | 206 | z->state->mode = CHECK2; |
159 | case CHECK2: | 207 | case CHECK2: |
160 | if (z->avail_in == 0) return r; r = Z_OK; | 208 | NEEDBYTE |
161 | z->state->sub.check.need += (uLong)NEXTBYTE << 8; | 209 | z->state->sub.check.need += (uLong)NEXTBYTE << 8; |
162 | z->state->mode = CHECK1; | 210 | z->state->mode = CHECK1; |
163 | case CHECK1: | 211 | case CHECK1: |
164 | if (z->avail_in == 0) return r; r = Z_OK; | 212 | NEEDBYTE |
165 | z->state->sub.check.need += (uLong)NEXTBYTE; | 213 | z->state->sub.check.need += (uLong)NEXTBYTE; |
214 | |||
166 | if (z->state->sub.check.was != z->state->sub.check.need) | 215 | if (z->state->sub.check.was != z->state->sub.check.need) |
167 | { | 216 | { |
168 | z->state->mode = INF_ERROR; | 217 | z->state->mode = BAD; |
169 | z->msg = "incorrect data check"; | 218 | z->msg = "incorrect data check"; |
170 | return Z_DATA_ERROR; | 219 | z->state->sub.marker = 5; /* can't try inflateSync */ |
220 | break; | ||
171 | } | 221 | } |
222 | Trace((stderr, "inflate: zlib check ok\n")); | ||
172 | z->state->mode = DONE; | 223 | z->state->mode = DONE; |
173 | case DONE: | 224 | case DONE: |
174 | return Z_STREAM_END; | 225 | return Z_STREAM_END; |
175 | case INF_ERROR: | 226 | case BAD: |
176 | return Z_DATA_ERROR; | 227 | return Z_DATA_ERROR; |
177 | default: | 228 | default: |
178 | return Z_STREAM_ERROR; | 229 | return Z_STREAM_ERROR; |
@@ -180,41 +231,46 @@ int f; | |||
180 | } | 231 | } |
181 | 232 | ||
182 | 233 | ||
183 | int inflateEnd(z) | 234 | int inflateSync(z) |
184 | z_stream *z; | 235 | z_stream *z; |
185 | { | 236 | { |
186 | uLong c; | 237 | uInt n; /* number of bytes to look at */ |
238 | Byte *p; /* pointer to bytes */ | ||
239 | uInt m; /* number of marker bytes found in a row */ | ||
240 | uLong r, w; /* temporaries to save total_in and total_out */ | ||
187 | 241 | ||
188 | if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) | 242 | /* set up */ |
243 | if (z == Z_NULL || z->state == Z_NULL) | ||
189 | return Z_STREAM_ERROR; | 244 | return Z_STREAM_ERROR; |
190 | if (z->state->mode == BLOCKS) | 245 | if (z->state->mode != BAD) |
191 | inflate_blocks_free(z->state->sub.blocks, z, &c); | 246 | z->state->sub.marker = 0; |
192 | ZFREE(z, z->state); | 247 | if ((n = z->avail_in) == 0) |
193 | z->state = Z_NULL; | 248 | return Z_BUF_ERROR; |
194 | return Z_OK; | 249 | p = z->next_in; |
195 | } | 250 | m = z->state->sub.marker; |
196 | |||
197 | |||
198 | /* inflateSync not implemented yet--this just consumes input */ | ||
199 | int inflateSync(z) | ||
200 | z_stream *z; | ||
201 | { | ||
202 | if (z == Z_NULL) return Z_STREAM_ERROR; | ||
203 | if (z->avail_in == 0) return Z_BUF_ERROR; | ||
204 | do { | ||
205 | z->total_in++; | ||
206 | } while (--z->avail_in); | ||
207 | return Z_DATA_ERROR; | ||
208 | } | ||
209 | 251 | ||
252 | /* search */ | ||
253 | while (n && m < 4) | ||
254 | { | ||
255 | if (*p == (m < 2 ? 0 : 0xff)) | ||
256 | m++; | ||
257 | else if (*p || m > 2) | ||
258 | m = 0; | ||
259 | p++, n--; | ||
260 | } | ||
210 | 261 | ||
211 | /* inflateReset not fully implemented yet--this frees and reallocates */ | 262 | /* restore */ |
212 | int inflateReset(z) | 263 | z->total_in += p - z->next_in; |
213 | z_stream *z; | 264 | z->next_in = p; |
214 | { | 265 | z->avail_in = n; |
215 | int r; | 266 | z->state->sub.marker = m; |
216 | 267 | ||
217 | if ((r = inflateEnd(z)) != Z_OK) | 268 | /* return no joy or set up to restart on a new block */ |
218 | return r; | 269 | if (m != 4) |
219 | return inflateInit(z); | 270 | return Z_DATA_ERROR; |
271 | r = z->total_in; w = z->total_out; | ||
272 | inflateReset(z); | ||
273 | z->total_in = r; z->total_out = w; | ||
274 | z->state->mode = BLOCKS; | ||
275 | return Z_OK; | ||
220 | } | 276 | } |
@@ -44,7 +44,9 @@ int r; | |||
44 | s->check = (*s->checkfn)(s->check, q, n); | 44 | s->check = (*s->checkfn)(s->check, q, n); |
45 | 45 | ||
46 | /* copy as far as end of window */ | 46 | /* copy as far as end of window */ |
47 | while (n--) *p++ = *q++; | 47 | zmemcpy(p, q, n); |
48 | p += n; | ||
49 | q += n; | ||
48 | 50 | ||
49 | /* see if more to copy at beginning of window */ | 51 | /* see if more to copy at beginning of window */ |
50 | if (q == s->end) | 52 | if (q == s->end) |
@@ -68,7 +70,9 @@ int r; | |||
68 | s->check = (*s->checkfn)(s->check, q, n); | 70 | s->check = (*s->checkfn)(s->check, q, n); |
69 | 71 | ||
70 | /* copy */ | 72 | /* copy */ |
71 | while (n--) *p++ = *q++; | 73 | zmemcpy(p, q, n); |
74 | p += n; | ||
75 | q += n; | ||
72 | } | 76 | } |
73 | 77 | ||
74 | /* update pointers */ | 78 | /* update pointers */ |
@@ -22,7 +22,7 @@ struct inflate_blocks_state { | |||
22 | CODES, /* processing fixed or dynamic block */ | 22 | CODES, /* processing fixed or dynamic block */ |
23 | DRY, /* output remaining window bytes */ | 23 | DRY, /* output remaining window bytes */ |
24 | DONE, /* finished last block, done */ | 24 | DONE, /* finished last block, done */ |
25 | INF_ERROR}/* got a data error--stuck here */ | 25 | BAD} /* got a data error--stuck here */ |
26 | mode; /* current inflate_block mode */ | 26 | mode; /* current inflate_block mode */ |
27 | 27 | ||
28 | /* mode dependent information */ | 28 | /* mode dependent information */ |
@@ -63,13 +63,7 @@ struct inflate_blocks_state { | |||
63 | #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} | 63 | #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} |
64 | #define NEEDBYTE {if(n)r=Z_OK;else LEAVE} | 64 | #define NEEDBYTE {if(n)r=Z_OK;else LEAVE} |
65 | #define NEXTBYTE (n--,*p++) | 65 | #define NEXTBYTE (n--,*p++) |
66 | #ifdef __TURBOC__ /* bug in TurboC compiler, bad code for b << 0 */ | 66 | #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}} |
67 | # define NEEDBITS(j) {\ | ||
68 | while(k<(j)){NEEDBYTE;b=k?b|(((uLong)NEXTBYTE)<<k):NEXTBYTE;k+=8;}\ | ||
69 | } | ||
70 | #else | ||
71 | # define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}} | ||
72 | #endif | ||
73 | #define DUMPBITS(j) {b>>=(j);k-=(j);} | 67 | #define DUMPBITS(j) {b>>=(j);k-=(j);} |
74 | /* output bytes */ | 68 | /* output bytes */ |
75 | #define WAVAIL (q<s->read?s->read-q-1:s->end-q) | 69 | #define WAVAIL (q<s->read?s->read-q-1:s->end-q) |
@@ -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.3 1995/04/29 13:49:46 jloup Exp $ */ | 32 | /* $Id: trees.c,v 1.4 1995/05/01 16:53:44 jloup Exp $ */ |
33 | 33 | ||
34 | #include "deflate.h" | 34 | #include "deflate.h" |
35 | 35 | ||
@@ -723,6 +723,22 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) | |||
723 | } | 723 | } |
724 | 724 | ||
725 | /* =========================================================================== | 725 | /* =========================================================================== |
726 | * Send a stored block | ||
727 | */ | ||
728 | void ct_stored_block(s, buf, stored_len, eof) | ||
729 | deflate_state *s; | ||
730 | char *buf; /* input block */ | ||
731 | ulg stored_len; /* length of input block */ | ||
732 | int eof; /* true if this is the last block for a file */ | ||
733 | { | ||
734 | send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ | ||
735 | s->compressed_len = (s->compressed_len + 3 + 7) & ~7L; | ||
736 | s->compressed_len += (stored_len + 4) << 3; | ||
737 | |||
738 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ | ||
739 | } | ||
740 | |||
741 | /* =========================================================================== | ||
726 | * Determine the best encoding for the current block: dynamic trees, static | 742 | * Determine the best encoding for the current block: dynamic trees, static |
727 | * trees or store, and output the encoded block to the zip file. This function | 743 | * trees or store, and output the encoded block to the zip file. This function |
728 | * returns the total compressed length for the file so far. | 744 | * returns the total compressed length for the file so far. |
@@ -771,8 +787,8 @@ ulg ct_flush_block(s, buf, stored_len, eof) | |||
771 | * the whole file is transformed into a stored file: | 787 | * the whole file is transformed into a stored file: |
772 | */ | 788 | */ |
773 | #ifdef STORED_FILE_OK | 789 | #ifdef STORED_FILE_OK |
774 | # ifdef FORCE_METHOD | 790 | # ifdef FORCE_STORED_FILE |
775 | if (level == 1 && eof && compressed_len == 0L) { /* force stored file */ | 791 | if (eof && compressed_len == 0L) { /* force stored file */ |
776 | # else | 792 | # else |
777 | if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) { | 793 | if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) { |
778 | # endif | 794 | # endif |
@@ -785,8 +801,8 @@ ulg ct_flush_block(s, buf, stored_len, eof) | |||
785 | } else | 801 | } else |
786 | #endif /* STORED_FILE_OK */ | 802 | #endif /* STORED_FILE_OK */ |
787 | 803 | ||
788 | #ifdef FORCE_METHOD | 804 | #ifdef FORCE_STORED |
789 | if (level == 2 && buf != (char*)0) { /* force stored block */ | 805 | if (buf != (char*)0) { /* force stored block */ |
790 | #else | 806 | #else |
791 | if (stored_len+4 <= opt_lenb && buf != (char*)0) { | 807 | if (stored_len+4 <= opt_lenb && buf != (char*)0) { |
792 | /* 4: two words for the lengths */ | 808 | /* 4: two words for the lengths */ |
@@ -797,14 +813,10 @@ ulg ct_flush_block(s, buf, stored_len, eof) | |||
797 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to | 813 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to |
798 | * transform a block into a stored block. | 814 | * transform a block into a stored block. |
799 | */ | 815 | */ |
800 | send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ | 816 | ct_stored_block(s, buf, stored_len, eof); |
801 | s->compressed_len = (s->compressed_len + 3 + 7) & ~7L; | ||
802 | s->compressed_len += (stored_len + 4) << 3; | ||
803 | |||
804 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ | ||
805 | 817 | ||
806 | #ifdef FORCE_METHOD | 818 | #ifdef FORCE_STATIC |
807 | } else if (level == 3) { /* force static trees */ | 819 | } else if (static_lenb >= 0) { /* force static trees */ |
808 | #else | 820 | #else |
809 | } else if (static_lenb == opt_lenb) { | 821 | } else if (static_lenb == opt_lenb) { |
810 | #endif | 822 | #endif |
@@ -3,7 +3,7 @@ | |||
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
6 | /* $Id: zconf.h,v 1.9 1995/04/29 12:02:14 jloup Exp $ */ | 6 | /* $Id: zconf.h,v 1.10 1995/04/30 19:27:14 jloup Exp $ */ |
7 | 7 | ||
8 | #ifndef _ZCONF_H | 8 | #ifndef _ZCONF_H |
9 | #define _ZCONF_H | 9 | #define _ZCONF_H |
@@ -32,10 +32,16 @@ | |||
32 | # define STDC | 32 | # define STDC |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #ifdef MAXSEG_64K | 35 | #ifndef MAX_MEM_LEVEL |
36 | # define MAX_MEM_LEVEL 8 | 36 | # ifdef MAXSEG_64K |
37 | #else | 37 | # define MAX_MEM_LEVEL 8 |
38 | # define MAX_MEM_LEVEL 9 | 38 | # else |
39 | # define MAX_MEM_LEVEL 9 | ||
40 | # endif | ||
41 | #endif | ||
42 | |||
43 | #ifndef MAX_WBITS | ||
44 | # define MAX_WBITS 15 /* 32K LZ77 window */ | ||
39 | #endif | 45 | #endif |
40 | 46 | ||
41 | /* Type declarations */ | 47 | /* Type declarations */ |
@@ -52,7 +58,7 @@ | |||
52 | typedef unsigned char Byte; /* 8 bits */ | 58 | typedef unsigned char Byte; /* 8 bits */ |
53 | #endif | 59 | #endif |
54 | #ifndef uInt | 60 | #ifndef uInt |
55 | typedef unsigned int uInt; /* may be 16 or 32 bits */ | 61 | typedef unsigned int uInt; /* 16 bits or more */ |
56 | #endif | 62 | #endif |
57 | #ifndef uLong | 63 | #ifndef uLong |
58 | typedef unsigned long uLong; /* 32 bits or more */ | 64 | typedef unsigned long uLong; /* 32 bits or more */ |
@@ -1,5 +1,5 @@ | |||
1 | /* zlib.h -- interface of the 'zlib' general purpose compression library | 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
2 | version 0.8 April 29th, 1995. | 2 | version 0.9 April 30th, 1995. |
3 | 3 | ||
4 | Copyright (C) 1995 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995 Jean-loup Gailly and Mark Adler |
5 | 5 | ||
@@ -28,7 +28,7 @@ | |||
28 | 28 | ||
29 | #include "zconf.h" | 29 | #include "zconf.h" |
30 | 30 | ||
31 | #define ZLIB_VERSION "0.8" | 31 | #define ZLIB_VERSION "0.9" |
32 | 32 | ||
33 | /* | 33 | /* |
34 | The 'zlib' compression library provides in-memory compression and | 34 | The 'zlib' compression library provides in-memory compression and |
@@ -81,7 +81,7 @@ typedef struct z_stream_s { | |||
81 | opaque before calling the init function. All other fields are set by the | 81 | opaque before calling the init function. All other fields are set by the |
82 | compression library and must not be updated by the application. | 82 | compression library and must not be updated by the application. |
83 | 83 | ||
84 | The opaque value provided by the application will be passed as first | 84 | The opaque value provided by the application will be passed as the first |
85 | parameter for calls of zalloc and zfree. This can be useful for custom | 85 | parameter for calls of zalloc and zfree. This can be useful for custom |
86 | memory management. The compression library attaches no meaning to the | 86 | memory management. The compression library attaches no meaning to the |
87 | opaque value. | 87 | opaque value. |
@@ -89,7 +89,12 @@ typedef struct z_stream_s { | |||
89 | zalloc must return Z_NULL if there is not enough memory for the object. | 89 | zalloc must return Z_NULL if there is not enough memory for the object. |
90 | On 16-bit systems, the functions zalloc and zfree must be able to allocate | 90 | On 16-bit systems, the functions zalloc and zfree must be able to allocate |
91 | exactly 65536 bytes, but will not be required to allocate more than this | 91 | exactly 65536 bytes, but will not be required to allocate more than this |
92 | if the symbol MAXSEG_64K is defined (see zconf.h). | 92 | if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, |
93 | pointers returned by zalloc for objects of exactly 65536 bytes *must* | ||
94 | have their offset normalized to zero. The default allocation function | ||
95 | provided by this library ensures this (see zutil.c). To reduce memory | ||
96 | requirements and avoid any allocation of 64K objects, at the expense of | ||
97 | compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). | ||
93 | 98 | ||
94 | The fields total_in and total_out can be used for statistics or | 99 | The fields total_in and total_out can be used for statistics or |
95 | progress reports. After compression, total_in holds the total size of | 100 | progress reports. After compression, total_in holds the total size of |
@@ -265,7 +270,7 @@ extern int inflate __P((z_stream *strm, int flush)); | |||
265 | 270 | ||
266 | If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much | 271 | If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much |
267 | output as possible to the output buffer. The flushing behavior of inflate is | 272 | output as possible to the output buffer. The flushing behavior of inflate is |
268 | not specified for values of the flush paramater other than Z_PARTIAL_FLUSH | 273 | not specified for values of the flush parameter other than Z_PARTIAL_FLUSH |
269 | and Z_FINISH, but the current implementation actually flushes as much output | 274 | and Z_FINISH, but the current implementation actually flushes as much output |
270 | as possible anyway. | 275 | as possible anyway. |
271 | 276 | ||
@@ -367,7 +372,7 @@ extern int deflateCopy __P((z_stream *dest, | |||
367 | Sets the destination stream as a complete copy of the source stream. If | 372 | Sets the destination stream as a complete copy of the source stream. If |
368 | the source stream is using an application-supplied history buffer, a new | 373 | the source stream is using an application-supplied history buffer, a new |
369 | buffer is allocated for the destination stream. The compressed output | 374 | buffer is allocated for the destination stream. The compressed output |
370 | buffer is always application-supplied. It's the responsability of the | 375 | buffer is always application-supplied. It's the responsibility of the |
371 | application to provide the correct values of next_out and avail_out for the | 376 | application to provide the correct values of next_out and avail_out for the |
372 | next call of deflate. | 377 | next call of deflate. |
373 | 378 | ||
@@ -430,12 +435,13 @@ extern int inflateInit2 __P((z_stream *strm, | |||
430 | 435 | ||
431 | extern int inflateSync __P((z_stream *strm)); | 436 | extern int inflateSync __P((z_stream *strm)); |
432 | /* | 437 | /* |
433 | Skips invalid compressed data until the special marker and a valid block | 438 | Skips invalid compressed data until the special marker (see deflate() |
434 | can be found, or until all available input is skipped. No output is provided. | 439 | above) can be found, or until all available input is skipped. No output |
440 | is provided. | ||
435 | 441 | ||
436 | inflateSync returns Z_OK if a valid block has been found, Z_BUF_ERROR if | 442 | inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR |
437 | no more input was provided, Z_DATA_ERROR if not valid block has been found, | 443 | if no more input was provided, Z_DATA_ERROR if no marker has been found, |
438 | Z_STREAM_ERROR if the stream structure was inconsistent. In the success | 444 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success |
439 | case, the application may save the current current value of total_in which | 445 | case, the application may save the current current value of total_in which |
440 | indicates where valid compressed data was found. In the error case, the | 446 | indicates where valid compressed data was found. In the error case, the |
441 | application may repeatedly call inflateSync, providing more input each time, | 447 | application may repeatedly call inflateSync, providing more input each time, |
@@ -469,7 +475,7 @@ extern int compress __P((Byte *dest, uLong *destLen, | |||
469 | Compresses the source buffer into the destination buffer. sourceLen is | 475 | Compresses the source buffer into the destination buffer. sourceLen is |
470 | the byte length of the source buffer. Upon entry, destLen is the total | 476 | the byte length of the source buffer. Upon entry, destLen is the total |
471 | size of the destination buffer, which must be at least 0.1% larger than | 477 | size of the destination buffer, which must be at least 0.1% larger than |
472 | sourceLen plus 8 bytes. Upon exit, destLen is the actual size of the | 478 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the |
473 | compressed buffer. | 479 | compressed buffer. |
474 | This function can be used to compress a whole file at once if the | 480 | This function can be used to compress a whole file at once if the |
475 | input file is mmap'ed. | 481 | input file is mmap'ed. |
@@ -505,7 +511,7 @@ extern gzFile gzopen __P((char *path, char *mode)); | |||
505 | is as in fopen ("rb" or "wb"). gzopen can also be used to read a file | 511 | is as in fopen ("rb" or "wb"). gzopen can also be used to read a file |
506 | which is not in gzip format; in this case gzread will directly read from | 512 | which is not in gzip format; in this case gzread will directly read from |
507 | the file without decompression. | 513 | the file without decompression. |
508 | gzopen return NULL if the file could not be opened or if there was | 514 | gzopen returns NULL if the file could not be opened or if there was |
509 | insufficient memory to allocate the (de)compression state; errno | 515 | insufficient memory to allocate the (de)compression state; errno |
510 | can be checked to distinguish the two cases (if errno is zero, the | 516 | can be checked to distinguish the two cases (if errno is zero, the |
511 | zlib error is Z_MEM_ERROR). | 517 | zlib error is Z_MEM_ERROR). |
@@ -516,7 +522,7 @@ extern gzFile gzdopen __P((int fd, char *mode)); | |||
516 | gzdopen() associates a gzFile with the file descriptor fd. File | 522 | gzdopen() associates a gzFile with the file descriptor fd. File |
517 | descriptors are obtained from calls like open, dup, creat, or pipe. | 523 | descriptors are obtained from calls like open, dup, creat, or pipe. |
518 | The mode parameter is as in fopen ("rb" or "wb"). | 524 | The mode parameter is as in fopen ("rb" or "wb"). |
519 | gzdopen return NULL if there was insufficient memory to allocate | 525 | gzdopen returns NULL if there was insufficient memory to allocate |
520 | the (de)compression state. | 526 | the (de)compression state. |
521 | */ | 527 | */ |
522 | 528 | ||
@@ -574,7 +580,7 @@ extern uLong adler32 __P((uLong adler, Byte *buf, uInt len)); | |||
574 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and | 580 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
575 | return the updated checksum. If buf is NULL, this function returns | 581 | return the updated checksum. If buf is NULL, this function returns |
576 | the required initial value for the checksum. | 582 | the required initial value for the checksum. |
577 | An Adler-32 cheksum is almost as reliable as a CRC32 but can be computed | 583 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed |
578 | much faster. Usage example: | 584 | much faster. Usage example: |
579 | 585 | ||
580 | uLong adler = adler32(0L, Z_NULL, 0); | 586 | uLong adler = adler32(0L, Z_NULL, 0); |
@@ -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: zutil.h,v 1.6 1995/04/29 15:52:16 jloup Exp $ */ | 11 | /* $Id: zutil.h,v 1.7 1995/04/30 10:55:33 jloup Exp $ */ |
12 | 12 | ||
13 | #ifndef _Z_UTIL_H | 13 | #ifndef _Z_UTIL_H |
14 | #define _Z_UTIL_H | 14 | #define _Z_UTIL_H |
@@ -42,13 +42,8 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */ | |||
42 | 42 | ||
43 | #define DEFLATED 8 | 43 | #define DEFLATED 8 |
44 | 44 | ||
45 | #ifndef WBITS | 45 | #define DEF_WBITS 15 |
46 | # define WBITS 15 /* 32K window */ | 46 | /* default WBITS for decompression. MAX_WBITS is useful for compression only */ |
47 | #endif | ||
48 | |||
49 | #ifndef MEM_LEVEL | ||
50 | # define MEM_LEVEL 8 | ||
51 | #endif | ||
52 | 47 | ||
53 | #define STORED_BLOCK 0 | 48 | #define STORED_BLOCK 0 |
54 | #define STATIC_TREES 1 | 49 | #define STATIC_TREES 1 |