aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 22:52:17 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 22:52:17 -0700
commit913afb9174bb474104049906c1382dec81826424 (patch)
tree46bb8ca746088f81382b4f33970b9d43c33d9ba3
parentbcf78a20978d76f64b7cd46d1a4d7a79a578c77b (diff)
downloadzlib-913afb9174bb474104049906c1382dec81826424.tar.gz
zlib-913afb9174bb474104049906c1382dec81826424.tar.bz2
zlib-913afb9174bb474104049906c1382dec81826424.zip
zlib 0.79v0.79
-rw-r--r--ChangeLog5
-rw-r--r--Makefile5
-rw-r--r--README16
-rw-r--r--deflate.c4
-rw-r--r--example.c6
-rw-r--r--gzio.c8
-rw-r--r--infblock.c18
-rw-r--r--infblock.h1
-rw-r--r--infcodes.c23
-rw-r--r--inffast.c148
-rw-r--r--inffast.h17
-rw-r--r--inflate-0.72.c230
-rw-r--r--inflate.c56
-rw-r--r--inflate.h22
-rw-r--r--inftrees.c2
-rw-r--r--infutil.c10
-rw-r--r--infutil.h1
-rw-r--r--minigzip.c8
-rw-r--r--trees.c2
-rw-r--r--zconf.h2
-rw-r--r--zlib.h96
-rw-r--r--zutil.c6
-rw-r--r--zutil.h13
23 files changed, 559 insertions, 140 deletions
diff --git a/ChangeLog b/ChangeLog
index 40fc89f..c0536d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
1 ChangeLog file for zlib 1 ChangeLog file for zlib
2 2
3Changes in 0.79 (28 April 95)
4- add fast inflate (inffast.c)
5- In gzio destroy(), don't reference a freed structure
6- avoid many warnings for MSDOS
7
3Changes in 0.71 (14 April 95) 8Changes in 0.71 (14 April 95)
4- Fixed more MSDOS compilation problems :( There is still a bug with 9- Fixed more MSDOS compilation problems :( There is still a bug with
5 TurboC large model. 10 TurboC large model.
diff --git a/Makefile b/Makefile
index 478920a..facba8a 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ LDFLAGS=-L. -lgz
6RANLIB=ranlib 6RANLIB=ranlib
7 7
8OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ 8OBJS = 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 9 zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
10 10
11TEST_OBJS = example.o minigzip.o inftest.o 11TEST_OBJS = example.o minigzip.o inftest.o
12 12
@@ -48,7 +48,8 @@ deflate.o: deflate.h zutil.h zlib.h zconf.h
48example.o: zlib.h zconf.h 48example.o: zlib.h zconf.h
49gzio.o: zutil.h zlib.h zconf.h 49gzio.o: zutil.h zlib.h zconf.h
50infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h 50infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
51infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h 51infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
52inffast.o: zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
52inflate.o: zutil.h zlib.h zconf.h infblock.h 53inflate.o: zutil.h zlib.h zconf.h infblock.h
53inftest.o: zutil.h zlib.h zconf.h 54inftest.o: zutil.h zlib.h zconf.h
54inftrees.o: zutil.h zlib.h zconf.h inftrees.h 55inftrees.o: zutil.h zlib.h zconf.h inftrees.h
diff --git a/README b/README
index 5c42402..5705062 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
1zlib 0.71 is a beta version of a general purpose compression library. 1zlib 0.79 is a beta version of a general purpose compression library.
2 2
3The data format used by the zlib library is described in the 3The data format used by the zlib library is described in the
4file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available 4file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available
@@ -9,16 +9,10 @@ zlib.h. A usage example of the library is given in the file example.c
9which also tests that the library is working correctly. 9which also tests that the library is working correctly.
10To compile all files and run the test program, just type: make test 10To compile all files and run the test program, just type: make test
11 11
12The changes made in version 0.71 are documented in the file ChangeLog. 12The changes made in version 0.79 are documented in the file ChangeLog.
13The main changes since 0.5 are: 13The main changes since 0.71 are:
14- added full inflate support 14- add fast inflate (inffast.c)
15- added minigzip.c 15- In gzio destroy(), don't reference a freed structure
16- added gzdopen to reopen a file descriptor as gzFile
17- added transparent reading of non-gziped files in gzread.
18- fix some MSDOS problems. example and minigzip now work on MSDOS.
19- Simplified the crc32() interface. The pre- and post-conditioning
20 (one's complement) is now done inside crc32(). WARNING: this is
21 incompatible with previous versions; see zlib.h for the new usage.
22 16
23On MSDOS, this version works in large and small model with MSC; in 17On MSDOS, this version works in large and small model with MSC; in
24small model only with TurboC (bug being investigated). For both 18small model only with TurboC (bug being investigated). For both
diff --git a/deflate.c b/deflate.c
index 2409f07..7d44627 100644
--- a/deflate.c
+++ b/deflate.c
@@ -47,7 +47,7 @@
47 * 47 *
48 */ 48 */
49 49
50/* $Id: deflate.c,v 1.3 1995/04/10 16:03:45 jloup Exp $ */ 50/* $Id: deflate.c,v 1.4 1995/04/14 19:49:46 jloup Exp $ */
51 51
52#include "deflate.h" 52#include "deflate.h"
53 53
@@ -195,9 +195,11 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, strategy)
195 s->noheader = noheader; 195 s->noheader = noheader;
196 s->w_bits = windowBits; 196 s->w_bits = windowBits;
197 s->w_size = 1 << s->w_bits; 197 s->w_size = 1 << s->w_bits;
198 s->w_mask = s->w_size - 1;
198 199
199 s->hash_bits = memLevel + 7; 200 s->hash_bits = memLevel + 7;
200 s->hash_size = 1 << s->hash_bits; 201 s->hash_size = 1 << s->hash_bits;
202 s->hash_mask = s->hash_size - 1;
201 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); 203 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
202 204
203 s->window = (Byte*) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 205 s->window = (Byte*) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
diff --git a/example.c b/example.c
index ea1a9eb..86541a7 100644
--- a/example.c
+++ b/example.c
@@ -3,7 +3,7 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* $Id: example.c,v 1.4 1995/04/14 13:32:49 jloup Exp $ */ 6/* $Id: example.c,v 1.5 1995/04/14 20:35:56 jloup Exp $ */
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include "zlib.h" 9#include "zlib.h"
@@ -60,7 +60,7 @@ void test_gzio(out, in)
60 char *in; /* input file */ 60 char *in; /* input file */
61{ 61{
62 local Byte uncompr[BUFLEN]; 62 local Byte uncompr[BUFLEN];
63 uLong uncomprLen = sizeof(uncompr); 63 int uncomprLen = sizeof(uncompr);
64 int err; 64 int err;
65 int len = strlen(hello)+1; 65 int len = strlen(hello)+1;
66 gzFile file; 66 gzFile file;
@@ -114,7 +114,7 @@ uLong test_deflate(compr)
114 c_stream.next_in = (Byte*)hello; 114 c_stream.next_in = (Byte*)hello;
115 c_stream.next_out = compr; 115 c_stream.next_out = compr;
116 116
117 while (c_stream.total_in != len) { 117 while (c_stream.total_in != (uLong)len) {
118 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ 118 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
119 err = deflate(&c_stream, Z_NO_FLUSH); 119 err = deflate(&c_stream, Z_NO_FLUSH);
120 CHECK_ERR(err, "deflate"); 120 CHECK_ERR(err, "deflate");
diff --git a/gzio.c b/gzio.c
index b488e96..365b6f5 100644
--- a/gzio.c
+++ b/gzio.c
@@ -71,8 +71,9 @@ local int destroy (s)
71 if (s->file != NULL && fclose(s->file)) { 71 if (s->file != NULL && fclose(s->file)) {
72 err = Z_ERRNO; 72 err = Z_ERRNO;
73 } 73 }
74 if (s->z_err < 0) err = s->z_err;
74 zcfree((voidp)0, s); 75 zcfree((voidp)0, s);
75 return s->z_err < 0 ? s->z_err : err; 76 return err;
76} 77}
77 78
78/* =========================================================================== 79/* ===========================================================================
@@ -235,9 +236,10 @@ int gzread (file, buf, len)
235 236
236 if (s->transparent) { 237 if (s->transparent) {
237 unsigned n = 0; 238 unsigned n = 0;
239 Byte *b = (Byte*)buf;
238 /* Copy the first two (non-magic) bytes if not done already */ 240 /* Copy the first two (non-magic) bytes if not done already */
239 while (s->stream.avail_in > 0 && len > 0) { 241 while (s->stream.avail_in > 0 && len > 0) {
240 *((Byte*)buf)++ = *s->stream.next_in++; 242 *b++ = *s->stream.next_in++;
241 s->stream.avail_in--; 243 s->stream.avail_in--;
242 len--; n++; 244 len--; n++;
243 } 245 }
@@ -364,7 +366,7 @@ local void putLong (file, x)
364{ 366{
365 int n; 367 int n;
366 for (n = 0; n < 4; n++) { 368 for (n = 0; n < 4; n++) {
367 fputc(x & 0xff, file); 369 fputc((int)(x & 0xff), file);
368 x >>= 8; 370 x >>= 8;
369 } 371 }
370} 372}
diff --git a/infblock.c b/infblock.c
index 3a58280..4d8bd48 100644
--- a/infblock.c
+++ b/infblock.c
@@ -60,16 +60,17 @@ 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
63struct inflate_blocks_state *inflate_blocks_new(z,wsize) 63struct inflate_blocks_state *inflate_blocks_new(z, c, w)
64z_stream *z; 64z_stream *z;
65uInt wsize; 65check_func c;
66uInt w;
66{ 67{
67 struct inflate_blocks_state *s; 68 struct inflate_blocks_state *s;
68 69
69 if ((s = (struct inflate_blocks_state *)ZALLOC 70 if ((s = (struct inflate_blocks_state *)ZALLOC
70 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) 71 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
71 return s; 72 return s;
72 if ((s->window = (Byte *)ZALLOC(z,1,wsize)) == Z_NULL) 73 if ((s->window = (Byte *)ZALLOC(z, 1, w)) == Z_NULL)
73 { 74 {
74 ZFREE(z, s); 75 ZFREE(z, s);
75 return Z_NULL; 76 return Z_NULL;
@@ -77,8 +78,10 @@ uInt wsize;
77 s->mode = TYPE; 78 s->mode = TYPE;
78 s->bitk = 0; 79 s->bitk = 0;
79 s->read = s->write = s->window; 80 s->read = s->write = s->window;
80 s->end = s->window + wsize; 81 s->end = s->window + w;
81 s->check = 1; 82 s->checkfn = c;
83 if (s->checkfn != Z_NULL)
84 s->check = (*s->checkfn)(0L, Z_NULL, 0);
82 return s; 85 return s;
83} 86}
84 87
@@ -312,8 +315,9 @@ z_stream *z;
312uLong *c; 315uLong *c;
313int *e; 316int *e;
314{ 317{
315 *e = s->bitk > 7 ? (s->bitb >> (s->bitk & 7)) & 0xff : -1; 318 *e = (int)(s->bitk > 7 ? (s->bitb >> (s->bitk & 7)) & 0xff : -1);
316 *c = s->check; 319 if (s->checkfn != Z_NULL)
320 *c = s->check;
317 if (s->mode == BTREE || s->mode == DTREE) 321 if (s->mode == BTREE || s->mode == DTREE)
318 ZFREE(z, s->sub.trees.blens); 322 ZFREE(z, s->sub.trees.blens);
319 if (s->mode == CODES) 323 if (s->mode == CODES)
diff --git a/infblock.h b/infblock.h
index f70c471..a21d730 100644
--- a/infblock.h
+++ b/infblock.h
@@ -12,6 +12,7 @@ struct inflate_blocks_state;
12 12
13extern struct inflate_blocks_state * inflate_blocks_new __P(( 13extern struct inflate_blocks_state * inflate_blocks_new __P((
14 z_stream *, 14 z_stream *,
15 check_func checkfn, /* check function */
15 uInt)); /* window size */ 16 uInt)); /* window size */
16 17
17extern int inflate_blocks __P(( 18extern int inflate_blocks __P((
diff --git a/infcodes.c b/infcodes.c
index ffae26d..489f9d6 100644
--- a/infcodes.c
+++ b/infcodes.c
@@ -6,6 +6,7 @@
6#include "zutil.h" 6#include "zutil.h"
7#include "inftrees.h" 7#include "inftrees.h"
8#include "infutil.h" 8#include "infutil.h"
9#include "inffast.h"
9#include "infcodes.h" 10#include "infcodes.h"
10 11
11/* simplify the use of the inflate_huft type with some defines */ 12/* simplify the use of the inflate_huft type with some defines */
@@ -98,7 +99,19 @@ int r;
98 while (1) switch (c->mode) 99 while (1) switch (c->mode)
99 { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ 100 { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
100 case START: /* x: set up for LEN */ 101 case START: /* x: set up for LEN */
101 /* %%% check for avail in and out to do fast loop %%% */ 102#ifndef SLOW
103 if (m >= 258 && n >= 10)
104 {
105 UPDATE
106 r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
107 LOAD
108 if (r != Z_OK)
109 {
110 c->mode = r == Z_STREAM_END ? WASH : BAD;
111 break;
112 }
113 }
114#endif /* !SLOW */
102 c->sub.code.need = c->lbits; 115 c->sub.code.need = c->lbits;
103 c->sub.code.tree = c->ltree; 116 c->sub.code.tree = c->ltree;
104 c->mode = LEN; 117 c->mode = LEN;
@@ -112,14 +125,14 @@ int r;
112 if (e == -128) /* invalid code */ 125 if (e == -128) /* invalid code */
113 { 126 {
114 c->mode = BAD; 127 c->mode = BAD;
115 z->msg = "invalid huffman code"; 128 z->msg = "invalid literal/length code";
116 r = Z_DATA_ERROR; 129 r = Z_DATA_ERROR;
117 LEAVE 130 LEAVE
118 } 131 }
119 e = -e; 132 e = -e;
120 if (e & 64) /* end of block */ 133 if (e & 64) /* end of block */
121 { 134 {
122 c->mode = END; 135 c->mode = WASH;
123 break; 136 break;
124 } 137 }
125 c->sub.code.need = e; 138 c->sub.code.need = e;
@@ -153,7 +166,7 @@ int r;
153 if (e == -128) 166 if (e == -128)
154 { 167 {
155 c->mode = BAD; 168 c->mode = BAD;
156 z->msg = "invalid huffman code"; 169 z->msg = "invalid distance code";
157 r = Z_DATA_ERROR; 170 r = Z_DATA_ERROR;
158 LEAVE 171 LEAVE
159 } 172 }
@@ -171,7 +184,7 @@ int r;
171 DUMPBITS(j) 184 DUMPBITS(j)
172 c->mode = COPY; 185 c->mode = COPY;
173 case COPY: /* o: copying bytes in window, waiting for space */ 186 case COPY: /* o: copying bytes in window, waiting for space */
174 f = q - s->window < c->sub.copy.dist ? 187 f = (uInt)(q - s->window) < c->sub.copy.dist ?
175 s->end - (c->sub.copy.dist - (q - s->window)) : 188 s->end - (c->sub.copy.dist - (q - s->window)) :
176 q - c->sub.copy.dist; 189 q - c->sub.copy.dist;
177 while (c->len) 190 while (c->len)
diff --git a/inffast.c b/inffast.c
new file mode 100644
index 0000000..8c3e4ce
--- /dev/null
+++ b/inffast.c
@@ -0,0 +1,148 @@
1/* inffast.c -- process literals and length/distance pairs fast
2 * Copyright (C) 1995 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8#include "infutil.h"
9#include "inffast.h"
10
11/* simplify the use of the inflate_huft type with some defines */
12#define base more.Base
13#define next more.Next
14#define exop word.what.Exop
15#define bits word.what.Bits
16
17/* macros for bit input with no checking and for returning unused bytes */
18#ifdef DEBUG
19# undef NEXTBYTE
20# define NEXTBYTE (n--?0:fprintf(stderr,"inffast underrun\n"),*p++)
21#endif
22#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
23#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}
24
25/* Called with number of bytes left to write in window at least 258
26 (the maximum string length) and number of input bytes available
27 at least ten. The ten bytes are six bytes for the longest length/
28 distance pair plus four bytes for overloading the bit buffer. */
29
30int inflate_fast(bl, bd, tl, td, s, z)
31uInt bl, bd;
32inflate_huft *tl, *td;
33struct inflate_blocks_state *s;
34z_stream *z;
35{
36 inflate_huft *t; /* temporary pointer */
37 int e; /* extra bits or operation */
38 uLong b; /* bit buffer */
39 uInt k; /* bits in bit buffer */
40 Byte *p; /* input data pointer */
41 uInt n; /* bytes available there */
42 Byte *q; /* output window write pointer */
43 uInt m; /* bytes to end of window or read pointer */
44 uInt ml; /* mask for literal/length tree */
45 uInt md; /* mask for distance tree */
46 uInt c; /* bytes to copy */
47 uInt d; /* distance back to copy from */
48 Byte *r; /* copy source pointer */
49
50 /* load input, output, bit values */
51 LOAD
52
53 /* initialize masks in registers */
54 ml = inflate_mask[bl];
55 md = inflate_mask[bd];
56
57 /* do until not enough input or output space for fast loop */
58 do { /* assume called with m >= 258 && n >= 10 */
59 /* get literal/length code */
60 GRABBITS(20) /* max bits for literal/length code */
61 if ((e = (t = tl + ((uInt)b & ml))->exop) < 0)
62 do {
63 if (e == -128)
64 {
65 z->msg = "invalid literal/length code";
66 UNGRAB
67 UPDATE
68 return Z_DATA_ERROR;
69 }
70 DUMPBITS(t->bits)
71 e = -e;
72 if (e & 64) /* end of block */
73 {
74 UNGRAB
75 UPDATE
76 return Z_STREAM_END;
77 }
78 } while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0);
79 DUMPBITS(t->bits)
80
81 /* process literal or length (end of block already trapped) */
82 if (e & 16) /* then it's a literal */
83 {
84 *q++ = (Byte)t->base;
85 m--;
86 }
87 else /* it's a length */
88 {
89 /* get length of block to copy (already have extra bits) */
90 c = t->base + ((uInt)b & inflate_mask[e]);
91 DUMPBITS(e);
92
93 /* decode distance base of block to copy */
94 GRABBITS(15); /* max bits for distance code */
95 if ((e = (t = td + ((uInt)b & md))->exop) < 0)
96 do {
97 if (e == -128)
98 {
99 z->msg = "invalid distance code";
100 UNGRAB
101 UPDATE
102 return Z_DATA_ERROR;
103 }
104 DUMPBITS(t->bits)
105 e = -e;
106 } while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0);
107 DUMPBITS(t->bits)
108
109 /* get extra bits to add to distance base */
110 GRABBITS(e) /* get extra bits (up to 13) */
111 d = t->base + ((uInt)b & inflate_mask[e]);
112 DUMPBITS(e)
113
114 /* do the copy */
115 m -= c;
116 if (q - s->window >= d) /* if offset before destination, */
117 { /* just copy */
118 r = q - d;
119 *q++ = *r++; c--; /* minimum count is three, */
120 *q++ = *r++; c--; /* so unroll loop a little */
121 do {
122 *q++ = *r++;
123 } while (--c);
124 }
125 else /* else offset after destination */
126 {
127 e = d - (q - s->window); /* bytes from offset to end */
128 r = s->end - e; /* pointer to offset */
129 if (c > e) /* if source crosses, */
130 {
131 c -= e; /* copy to end of window */
132 do {
133 *q++ = *r++;
134 } while (--e);
135 r = s->window; /* copy rest from start of window */
136 }
137 do { /* copy all or what's left */
138 *q++ = *r++;
139 } while (--c);
140 }
141 }
142 } while (m >= 258 && n >= 10);
143
144 /* not enough input or output--restore pointers and return */
145 UNGRAB
146 UPDATE
147 return Z_OK;
148}
diff --git a/inffast.h b/inffast.h
new file mode 100644
index 0000000..2c05820
--- /dev/null
+++ b/inffast.h
@@ -0,0 +1,17 @@
1/* inffast.h -- header to use inffast.c
2 * Copyright (C) 1995 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11extern int inflate_fast __P((
12 uInt,
13 uInt,
14 inflate_huft *,
15 inflate_huft *,
16 struct inflate_blocks_state *,
17 z_stream *));
diff --git a/inflate-0.72.c b/inflate-0.72.c
new file mode 100644
index 0000000..56b0665
--- /dev/null
+++ b/inflate-0.72.c
@@ -0,0 +1,230 @@
1/* inflate.c -- zlib interface to inflate modules
2 * Copyright (C) 1995 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "infblock.h"
8
9struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
10
11/* inflate private state */
12struct internal_state {
13
14 /* mode */
15 enum {
16 METHOD, /* waiting for method byte */
17 FLAG, /* waiting for flag byte */
18 START, /* make new blocks state */
19 BLOCKS, /* decompressing blocks */
20 CHECK4, /* four check bytes to go */
21 CHECK3, /* three check bytes to go */
22 CHECK2, /* two check bytes to go */
23 CHECK1, /* one check byte to go */
24 DONE, /* finished check, done */
25 ERROR} /* got an error--stay here */
26 mode; /* current inflate mode */
27
28 /* mode dependent information */
29 union {
30 uInt method; /* if FLAGS, method byte */
31 struct inflate_blocks_state
32 *blocks; /* if BLOCKS, current state */
33 struct {
34 uLong was; /* computed check value */
35 uLong need; /* stream check value */
36 } check; /* if CHECK, check values to compare */
37 } sub; /* submode */
38
39 /* mode independent information */
40 int nowrap; /* flag for no wrapper */
41 uInt wbits; /* log2(window size) (8..15, defaults to 15) */
42
43};
44
45
46int inflateInit(z)
47z_stream *z;
48{
49 return inflateInit2(z, WBITS);
50}
51
52
53int inflateInit2(z, w)
54z_stream *z;
55int w;
56{
57 /* initialize state */
58 if (z == Z_NULL)
59 return Z_STREAM_ERROR;
60 if (z->zalloc == Z_NULL) z->zalloc = zcalloc;
61 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 *)
65 ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
66 return Z_MEM_ERROR;
67 z->state->mode = METHOD;
68
69 /* handle undocumented nowrap option (no zlib header or check) */
70 z->state->nowrap = 0;
71 if (w < 0)
72 {
73 w = - w;
74 z->state->nowrap = 1;
75 z->state->mode = START;
76 }
77
78 /* set window size */
79 if (w < 8 || w > 15)
80 {
81 inflateEnd(z);
82 return Z_STREAM_ERROR;
83 }
84 z->state->wbits = w;
85 return Z_OK;
86}
87
88
89#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
90
91int inflate(z, f)
92z_stream *z;
93int f;
94{
95 int r;
96 uInt b;
97 uLong c;
98
99 if (z == Z_NULL || z->next_in == Z_NULL)
100 return Z_STREAM_ERROR;
101 r = Z_BUF_ERROR;
102 while (1) switch (z->state->mode)
103 {
104 case METHOD:
105 if (z->avail_in == 0) return r; r = Z_OK;
106 if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED))
107 {
108 z->state->mode = ERROR;
109 z->msg = "unknown compression method";
110 return Z_DATA_ERROR;
111 }
112 if ((z->state->sub.method >> 4) > z->state->wbits)
113 {
114 z->state->mode = ERROR;
115 z->msg = "invalid window size";
116 return Z_DATA_ERROR;
117 }
118 z->state->mode = FLAG;
119 case FLAG:
120 if (z->avail_in == 0) return r; r = Z_OK;
121 if ((b = NEXTBYTE) & 0x20)
122 {
123 z->state->mode = ERROR;
124 z->msg = "invalid reserved bit";
125 return Z_DATA_ERROR;
126 }
127 if (((z->state->sub.method << 8) + b) % 31)
128 {
129 z->state->mode = ERROR;
130 z->msg = "incorrect header check";
131 return Z_DATA_ERROR;
132 }
133 z->state->mode = START;
134 case START:
135 if ((z->state->sub.blocks =
136 inflate_blocks_new(z,1<< z->state->wbits)) == Z_NULL)
137 return Z_MEM_ERROR;
138 z->state->mode = BLOCKS;
139 case BLOCKS:
140 if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END)
141 return r;
142 inflate_blocks_free(z->state->sub.blocks, z, &c, &r);
143 if (z->state->nowrap)
144 {
145 if (r != -1)
146 z->msg = "inflate bug--took one too many bytes";
147 z->state->mode = r == -1 ? DONE : ERROR;
148 break;
149 }
150 z->state->sub.check.was = c;
151 if (r != -1)
152 {
153 z->state->sub.check.need = (uLong)r << 24;
154 z->state->mode = CHECK3;
155 r = Z_OK;
156 break;
157 }
158 r = Z_OK;
159 z->state->mode = CHECK4;
160 case CHECK4:
161 if (z->avail_in == 0) return r; r = Z_OK;
162 z->state->sub.check.need = (uLong)NEXTBYTE << 24;
163 z->state->mode = CHECK3;
164 case CHECK3:
165 if (z->avail_in == 0) return r; r = Z_OK;
166 z->state->sub.check.need += (uLong)NEXTBYTE << 16;
167 z->state->mode = CHECK2;
168 case CHECK2:
169 if (z->avail_in == 0) return r; r = Z_OK;
170 z->state->sub.check.need += (uLong)NEXTBYTE << 8;
171 z->state->mode = CHECK1;
172 case CHECK1:
173 if (z->avail_in == 0) return r; r = Z_OK;
174 z->state->sub.check.need += (uLong)NEXTBYTE;
175 if (z->state->sub.check.was != z->state->sub.check.need)
176 {
177 z->state->mode = ERROR;
178 z->msg = "incorrect data check";
179 return Z_DATA_ERROR;
180 }
181 z->state->mode = DONE;
182 case DONE:
183 return Z_STREAM_END;
184 case ERROR:
185 return Z_DATA_ERROR;
186 default:
187 return Z_STREAM_ERROR;
188 }
189}
190
191
192int inflateEnd(z)
193z_stream *z;
194{
195 uLong c;
196 int e;
197
198 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
199 return Z_STREAM_ERROR;
200 if (z->state->mode == BLOCKS)
201 inflate_blocks_free(z->state->sub.blocks, z, &c, &e);
202 ZFREE(z, z->state);
203 z->state = Z_NULL;
204 return Z_OK;
205}
206
207
208/* inflateSync not implemented yet--this just consumes input */
209int inflateSync(z)
210z_stream *z;
211{
212 if (z == Z_NULL) return Z_STREAM_ERROR;
213 if (z->avail_in == 0) return Z_BUF_ERROR;
214 do {
215 z->total_in++;
216 } while (--z->avail_in);
217 return Z_DATA_ERROR;
218}
219
220
221/* inflateReset not fully implemented yet--this frees and reallocates */
222int inflateReset(z)
223z_stream *z;
224{
225 int r;
226
227 if ((r = inflateEnd(z)) != Z_OK)
228 return r;
229 return inflateInit(z);
230}
diff --git a/inflate.c b/inflate.c
index 478f46d..38d70cc 100644
--- a/inflate.c
+++ b/inflate.c
@@ -25,10 +25,6 @@ struct internal_state {
25 ERROR} /* got an error--stay here */ 25 ERROR} /* got an error--stay here */
26 mode; /* current inflate mode */ 26 mode; /* current inflate mode */
27 27
28 int no_header;
29 uInt w_size; /* LZ77 window size (32K by default) */
30 uInt w_bits; /* log2(w_size) (8..16) */
31
32 /* mode dependent information */ 28 /* mode dependent information */
33 union { 29 union {
34 uInt method; /* if FLAGS, method byte */ 30 uInt method; /* if FLAGS, method byte */
@@ -39,19 +35,26 @@ struct internal_state {
39 uLong need; /* stream check value */ 35 uLong need; /* stream check value */
40 } check; /* if CHECK, check values to compare */ 36 } check; /* if CHECK, check values to compare */
41 } sub; /* submode */ 37 } sub; /* submode */
38
39 /* mode independent information */
40 int nowrap; /* flag for no wrapper */
41 uInt wbits; /* log2(window size) (8..15, defaults to 15) */
42
42}; 43};
43 44
44 45
45int inflateInit (strm) 46int inflateInit(z)
46z_stream *strm; 47z_stream *z;
47{ 48{
48 return inflateInit2(strm, WBITS); 49 return inflateInit2(z, WBITS);
49} 50}
50 51
51int inflateInit2(z, windowBits) 52
53int inflateInit2(z, w)
52z_stream *z; 54z_stream *z;
53int windowBits; 55int w;
54{ 56{
57 /* initialize state */
55 if (z == Z_NULL) 58 if (z == Z_NULL)
56 return Z_STREAM_ERROR; 59 return Z_STREAM_ERROR;
57 if (z->zalloc == Z_NULL) z->zalloc = zcalloc; 60 if (z->zalloc == Z_NULL) z->zalloc = zcalloc;
@@ -63,19 +66,22 @@ int windowBits;
63 return Z_MEM_ERROR; 66 return Z_MEM_ERROR;
64 z->state->mode = METHOD; 67 z->state->mode = METHOD;
65 68
66 z->state->no_header = 0; 69 /* handle undocumented nowrap option (no zlib header or check) */
67 if (windowBits < 0) { /* undocumented feature: no zlib header */ 70 z->state->nowrap = 0;
68 windowBits = - windowBits; 71 if (w < 0)
69 z->state->no_header = 1; 72 {
70 z->state->sub.method = DEFLATED; 73 w = - w;
74 z->state->nowrap = 1;
71 z->state->mode = START; 75 z->state->mode = START;
72 } 76 }
73 if (windowBits < 8 || windowBits > 15) { 77
78 /* set window size */
79 if (w < 8 || w > 15)
80 {
74 inflateEnd(z); 81 inflateEnd(z);
75 return Z_STREAM_ERROR; 82 return Z_STREAM_ERROR;
76 } 83 }
77 z->state->w_bits = windowBits; 84 z->state->wbits = w;
78 z->state->w_size = 1<<windowBits;
79 return Z_OK; 85 return Z_OK;
80} 86}
81 87
@@ -103,7 +109,7 @@ int f;
103 z->msg = "unknown compression method"; 109 z->msg = "unknown compression method";
104 return Z_DATA_ERROR; 110 return Z_DATA_ERROR;
105 } 111 }
106 if ((z->state->sub.method >> 4) > z->state->w_bits) 112 if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
107 { 113 {
108 z->state->mode = ERROR; 114 z->state->mode = ERROR;
109 z->msg = "invalid window size"; 115 z->msg = "invalid window size";
@@ -126,17 +132,21 @@ int f;
126 } 132 }
127 z->state->mode = START; 133 z->state->mode = START;
128 case START: 134 case START:
129 if ((z->state->sub.blocks = inflate_blocks_new(z,z->state->w_size)) 135 if ((z->state->sub.blocks = inflate_blocks_new(z,
130 == Z_NULL) 136 z->state->nowrap ? Z_NULL : adler32,
137 1<< z->state->wbits)) == Z_NULL)
131 return Z_MEM_ERROR; 138 return Z_MEM_ERROR;
132 z->state->mode = BLOCKS; 139 z->state->mode = BLOCKS;
133 case BLOCKS: 140 case BLOCKS:
134 if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END) 141 if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END)
135 return r; 142 return r;
136 inflate_blocks_free(z->state->sub.blocks, z, &c, &r); 143 inflate_blocks_free(z->state->sub.blocks, z, &c, &r);
137 if (z->state->no_header) { 144 if (z->state->nowrap)
138 z->state->mode = DONE; 145 {
139 return Z_STREAM_END; 146 if (r != -1)
147 z->msg = "inflate bug--took one too many bytes";
148 z->state->mode = r == -1 ? DONE : ERROR;
149 break;
140 } 150 }
141 z->state->sub.check.was = c; 151 z->state->sub.check.was = c;
142 if (r != -1) 152 if (r != -1)
diff --git a/inflate.h b/inflate.h
deleted file mode 100644
index 843224f..0000000
--- a/inflate.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/* temporary kludge assuming single pass decompression */
2
3/* $Id: inflate.h,v 1.2 1995/04/11 14:47:32 jloup Exp $ */
4
5#include <stdio.h>
6
7#define NEXTBYTE \
8 (istrm->total_in++, istrm->avail_in-- == 0 ? \
9 (z_error("too small"), 0) : *istrm->next_in++)
10
11#define FLUSH(n) { \
12 if (istrm->avail_out < n) z_error("too big"); \
13 istrm->avail_out -= n; \
14 memcpy(istrm->next_out, slide, n); \
15 istrm->next_out += n; \
16 istrm->total_out += n; \
17}
18#define WSIZE istrm->state->w_size
19#define slide istrm->state->window
20#define memzero(a,s) memset((a),0,(s))
21#define inflate z_inflate
22#define qflag 1
diff --git a/inftrees.c b/inftrees.c
index 4b00e3c..54c7c8e 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -246,7 +246,7 @@ z_stream *zs; /* for zalloc function */
246 { 246 {
247 x[h] = i; /* save pattern for backing up */ 247 x[h] = i; /* save pattern for backing up */
248 r.bits = (char)l; /* bits to dump before this table */ 248 r.bits = (char)l; /* bits to dump before this table */
249 r.exop = (char)(-j); /* bits in this table */ 249 r.exop = -(char)j; /* bits in this table */
250 r.next = q; /* pointer to this table */ 250 r.next = q; /* pointer to this table */
251 j = i >> (w - l); /* (get around Turbo C bug) */ 251 j = i >> (w - l); /* (get around Turbo C bug) */
252 u[h-1][j] = r; /* connect to last table */ 252 u[h-1][j] = r; /* connect to last table */
diff --git a/infutil.c b/infutil.c
index 92d115f..1adadbf 100644
--- a/infutil.c
+++ b/infutil.c
@@ -40,7 +40,8 @@ int r;
40 z->total_out += n; 40 z->total_out += n;
41 41
42 /* update check information */ 42 /* update check information */
43 s->check = adler32(s->check, q, n); 43 if (s->checkfn != Z_NULL)
44 s->check = (*s->checkfn)(s->check, q, n);
44 45
45 /* copy as far as end of window */ 46 /* copy as far as end of window */
46 while (n--) *p++ = *q++; 47 while (n--) *p++ = *q++;
@@ -48,8 +49,10 @@ int r;
48 /* see if more to copy at beginning of window */ 49 /* see if more to copy at beginning of window */
49 if (q == s->end) 50 if (q == s->end)
50 { 51 {
51 /* wrap source pointer */ 52 /* wrap pointers */
52 q = s->window; 53 q = s->window;
54 if (s->write == s->end)
55 s->write = s->window;
53 56
54 /* compute bytes to copy */ 57 /* compute bytes to copy */
55 n = s->write - q; 58 n = s->write - q;
@@ -61,7 +64,8 @@ int r;
61 z->total_out += n; 64 z->total_out += n;
62 65
63 /* update check information */ 66 /* update check information */
64 s->check = adler32(s->check, q, n); 67 if (s->checkfn != Z_NULL)
68 s->check = (*s->checkfn)(s->check, q, n);
65 69
66 /* copy */ 70 /* copy */
67 while (n--) *p++ = *q++; 71 while (n--) *p++ = *q++;
diff --git a/infutil.h b/infutil.h
index af07372..30b230d 100644
--- a/infutil.h
+++ b/infutil.h
@@ -47,6 +47,7 @@ struct inflate_blocks_state {
47 Byte *end; /* one byte after sliding window */ 47 Byte *end; /* one byte after sliding window */
48 Byte *read; /* window read pointer */ 48 Byte *read; /* window read pointer */
49 Byte *write; /* window write pointer */ 49 Byte *write; /* window write pointer */
50 check_func checkfn; /* check function */
50 uLong check; /* check on output */ 51 uLong check; /* check on output */
51 52
52}; 53};
diff --git a/minigzip.c b/minigzip.c
index 688b3a1..4936d64 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -13,13 +13,15 @@
13 * or in pipe mode. 13 * or in pipe mode.
14 */ 14 */
15 15
16/* $Id: minigzip.c,v 1.1 1995/04/14 13:35:59 jloup Exp $ */ 16/* $Id: minigzip.c,v 1.2 1995/04/14 20:03:12 jloup Exp $ */
17 17
18#include <stdio.h> 18#include <stdio.h>
19#include "zlib.h" 19#include "zlib.h"
20 20
21extern void exit __P((int));
22
21#ifdef MSDOS 23#ifdef MSDOS
22# include <fcntl.h> 24# include <fcntl.h> /* ??? find where setmode declared */
23# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 25# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
24#else 26#else
25# define SET_BINARY_MODE(file) 27# define SET_BINARY_MODE(file)
@@ -87,7 +89,7 @@ void gz_uncompress(in, out)
87 if (len < 0) error (gzerror(in, &err)); 89 if (len < 0) error (gzerror(in, &err));
88 if (len == 0) break; 90 if (len == 0) break;
89 91
90 if (fwrite(buf, 1, len, out) != len) error("failed fwrite"); 92 if (fwrite(buf, 1, len, out) != (uInt)len) error("failed fwrite");
91 } 93 }
92 if (fclose(out)) error("failed fclose"); 94 if (fclose(out)) error("failed fclose");
93 95
diff --git a/trees.c b/trees.c
index 79cab9f..62411a7 100644
--- a/trees.c
+++ b/trees.c
@@ -1011,7 +1011,7 @@ local void bi_windup(s)
1011 if (s->bi_valid > 8) { 1011 if (s->bi_valid > 8) {
1012 put_short(s, s->bi_buf); 1012 put_short(s, s->bi_buf);
1013 } else if (s->bi_valid > 0) { 1013 } else if (s->bi_valid > 0) {
1014 put_byte(s, s->bi_buf); 1014 put_byte(s, (Byte)s->bi_buf);
1015 } 1015 }
1016 s->bi_buf = 0; 1016 s->bi_buf = 0;
1017 s->bi_valid = 0; 1017 s->bi_valid = 0;
diff --git a/zconf.h b/zconf.h
index 29496d7..f08793b 100644
--- a/zconf.h
+++ b/zconf.h
@@ -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.7 1995/04/12 20:42:28 jloup Exp $ */ 6/* $Id: zconf.h,v 1.8 1995/04/14 20:59:22 jloup Exp $ */
7 7
8#ifndef _ZCONF_H 8#ifndef _ZCONF_H
9#define _ZCONF_H 9#define _ZCONF_H
diff --git a/zlib.h b/zlib.h
index d1f2ca9..6983fb7 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 0.7 April 14th, 1995. 2 version 0.79 April 28th, 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.7" 31#define ZLIB_VERSION "0.79"
32 32
33/* 33/*
34 The 'zlib' compression library provides in-memory compression and 34 The 'zlib' compression library provides in-memory compression and
@@ -88,7 +88,7 @@ typedef struct z_stream_s {
88 88
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 require 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).
93 93
94 The fields total_in and total_out can be used for statistics or 94 The fields total_in and total_out can be used for statistics or
@@ -152,10 +152,10 @@ extern int deflateInit __P((z_stream *strm, int level));
152 to level 6). 152 to level 6).
153 153
154 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 154 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
155 enough memory, Z_STREAM_ERROR if the stream state was inconsistent (such 155 enough memory, Z_STREAM_ERROR if level is not a valid compression level.
156 as zalloc being NULL). msg is set to null if there is no error message. 156 msg is set to null if there is no error message. deflateInit does not
157 deflateInit does not perform any compression: this will be done by 157 perform any compression: this will be done by deflate().
158 deflate(). */ 158*/
159 159
160 160
161extern int deflate __P((z_stream *strm, int flush)); 161extern int deflate __P((z_stream *strm, int flush));
@@ -164,8 +164,8 @@ extern int deflate __P((z_stream *strm, int flush));
164 164
165 - Compress more input starting at next_in and update next_in and avail_in 165 - Compress more input starting at next_in and update next_in and avail_in
166 accordingly. If not all input can be processed (because there is not 166 accordingly. If not all input can be processed (because there is not
167 enough room in the output buffer), next_in is updated and processing 167 enough room in the output buffer), next_in and avail_in are updated and
168 will resume at this point for the next call of deflate(). 168 processing will resume at this point for the next call of deflate().
169 169
170 - Provide more output starting at next_out and update next_out and avail_out 170 - Provide more output starting at next_out and update next_out and avail_out
171 accordingly. This action is forced if the parameter flush is non zero. 171 accordingly. This action is forced if the parameter flush is non zero.
@@ -175,20 +175,21 @@ extern int deflate __P((z_stream *strm, int flush));
175 175
176 Before the call of deflate(), the application should ensure that at least 176 Before the call of deflate(), the application should ensure that at least
177 one of the actions is possible, by providing more input and/or consuming 177 one of the actions is possible, by providing more input and/or consuming
178 more output, and updating avail_in or avail_out accordingly. 178 more output, and updating avail_in or avail_out accordingly; avail_out
179 The application can consume the compressed output when the output 179 should never be zero before the call. The application can consume the
180 buffer is full (avail_out == 0), or after each call of deflate(). 180 compressed output when it wants, for example when the output buffer is full
181 (avail_out == 0), or after each call of deflate().
181 182
182 If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression 183 If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
183 block is byte aligned and flushed to the output buffer so that the 184 block is terminated and flushed to the output buffer so that the
184 decompressor can get all input data available so far; if the compression 185 decompressor can get all input data available so far. For method 9, a future
185 method is 8 (deflate without partial flush capability), the current block 186 variant on method 8, the current block will be flushed but not terminated.
186 is terminated. If flush is set to Z_FULL_FLUSH, the compression block is 187 If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
187 terminated, a special marker is output and the compression dictionary is 188 special marker is output and the compression dictionary is discarded; this
188 discarded; this is useful to allow the decompressor to synchronize if one 189 is useful to allow the decompressor to synchronize if one compressed block
189 compressed block has been damaged. 190 has been damaged (see inflateSync below). Flushing degrades compression and
190 Flushing degrades compression and so should be used only when necessary. 191 so should be used only when necessary. Using Z_FULL_FLUSH too often can
191 Using Z_FULL_FLUSH too often can seriously degrade the compression. 192 seriously degrade the compression.
192 193
193 If the parameter flush is set to Z_FINISH, all pending input is 194 If the parameter flush is set to Z_FINISH, all pending input is
194 processed and all pending output is flushed. The next operation on this 195 processed and all pending output is flushed. The next operation on this
@@ -197,19 +198,18 @@ extern int deflate __P((z_stream *strm, int flush));
197 or a call of deflateEnd to deallocate the compression state. Z_FINISH can 198 or a call of deflateEnd to deallocate the compression state. Z_FINISH can
198 be used immediately after deflateInit if all the compression is to be 199 be used immediately after deflateInit if all the compression is to be
199 done in a single step. In this case, avail_out must be at least 0.1% 200 done in a single step. In this case, avail_out must be at least 0.1%
200 larger than avail_in plus 8 bytes. 201 larger than avail_in plus 12 bytes.
201 202
202 deflate() may update strm->data_type if it can make a good guess about 203 deflate() may update data_type if it can make a good guess about
203 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered 204 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
204 binary. This field is only for information purposes and does not affect 205 binary. This field is only for information purposes and does not affect
205 the compression algorithm in any manner. 206 the compression algorithm in any manner.
206 207
207 deflate() return Z_OK if some progress has been made (more input processed 208 deflate() returns Z_OK if some progress has been made (more input processed
208 or more output produced), Z_STREAM_ERROR if the stream state was 209 or more output produced), Z_STREAM_ERROR if the stream state was
209 inconsistent (for example if next_in or next_out was NULL), Z_BUF_ERROR if 210 inconsistent (for example if next_in or next_out was NULL), Z_BUF_ERROR if
210 no progress is possible or if there was not enough room in the output buffer 211 no progress is possible or if there was not enough room in the output buffer
211 when Z_FINISH is used. 212 when Z_FINISH is used. ??? to be changed (use Z_STEAM_END) */
212*/
213 213
214 214
215extern int deflateEnd __P((z_stream *strm)); 215extern int deflateEnd __P((z_stream *strm));
@@ -232,8 +232,7 @@ extern int inflateInit __P((z_stream *strm));
232 functions. 232 functions.
233 233
234 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 234 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
235 enough memory, Z_STREAM_ERROR if the stream state was inconsistent (such 235 enough memory. msg is set to null if there is no error message.
236 as zalloc being NULL). msg is set to null if there is no error message.
237 inflateInit does not perform any decompression: this will be done by 236 inflateInit does not perform any decompression: this will be done by
238 inflate(). 237 inflate().
239*/ 238*/
@@ -255,8 +254,9 @@ extern int inflate __P((z_stream *strm, int flush));
255 Before the call of inflate(), the application should ensure that at least 254 Before the call of inflate(), the application should ensure that at least
256 one of the actions is possible, by providing more input and/or consuming 255 one of the actions is possible, by providing more input and/or consuming
257 more output, and updating the next_* and avail_* values accordingly. 256 more output, and updating the next_* and avail_* values accordingly.
258 The application can consume the uncompressed output when the output 257 The application can consume the uncompressed output when it wants, for
259 buffer is full (avail_out == 0), or after each call of inflate(). 258 example when the output buffer is full (avail_out == 0), or after each
259 call of inflate().
260 260
261 If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much 261 If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
262 output as possible to the output buffer. The flushing behavior of inflate is 262 output as possible to the output buffer. The flushing behavior of inflate is
@@ -275,13 +275,13 @@ extern int inflate __P((z_stream *strm, int flush));
275 275
276 inflate() returns Z_OK if some progress has been made (more input 276 inflate() returns Z_OK if some progress has been made (more input
277 processed or more output produced), Z_STREAM_END if the end of the 277 processed or more output produced), Z_STREAM_END if the end of the
278 compressed data has been reached, Z_DATA_ERROR if the input data was 278 compressed data has been reached and all uncompressed output has been
279 corrupted, Z_STREAM_ERROR if the stream structure was inconsistent (for 279 produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
280 example if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough 280 the stream structure was inconsistent (for example if next_in or next_out
281 memory, Z_BUF_ERROR if no progress is possible or if there was not enough 281 was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
282 room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, 282 progress is possible or if there was not enough room in the output buffer
283 the application may then call inflateSync to look for a good compression 283 when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
284 block. 284 call inflateSync to look for a good compression block.
285*/ 285*/
286 286
287 287
@@ -318,9 +318,9 @@ extern int deflateInit2 __P((z_stream *strm,
318 318
319 The windowBits parameter is the base two logarithm of the window size 319 The windowBits parameter is the base two logarithm of the window size
320 (the size of the history buffer). It should be in the range 8..15 for this 320 (the size of the history buffer). It should be in the range 8..15 for this
321 version of the library (the value 16 will be allowed soon). Larger values 321 version of the library (the value 16 will be allowed for method 9). Larger
322 of this parameter result in better compression at the expense of memory 322 values of this parameter result in better compression at the expense of
323 usage. The default value is 15 if deflateInit is used instead. 323 memory usage. The default value is 15 if deflateInit is used instead.
324 324
325 The memLevel parameter specifies how much memory should be allocated 325 The memLevel parameter specifies how much memory should be allocated
326 for the internal compression state. memLevel=1 uses minimum memory but 326 for the internal compression state. memLevel=1 uses minimum memory but
@@ -338,8 +338,8 @@ extern int deflateInit2 __P((z_stream *strm,
338 338
339 If next_in is not null, the library will use this buffer to hold also 339 If next_in is not null, the library will use this buffer to hold also
340 some history information; the buffer must either hold the entire input 340 some history information; the buffer must either hold the entire input
341 data, or have at least (1<<windowBits) bytes and be writable. If next_in is 341 data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
342 null, the library will allocate its own history buffer (and leave next_in 342 is null, the library will allocate its own history buffer (and leave next_in
343 null). next_out need not be provided here but must be provided by the 343 null). next_out need not be provided here but must be provided by the
344 application for the next call of deflate(). 344 application for the next call of deflate().
345 345
@@ -350,8 +350,7 @@ extern int deflateInit2 __P((z_stream *strm,
350 reset by the library in this case. 350 reset by the library in this case.
351 351
352 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 352 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
353 not enough memory, Z_STREAM_ERROR if the stream state was inconsistent 353 not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
354 (such as zalloc being NULL) or the parameters are invalid (such as
355 an invalid method). msg is set to null if there is no error message. 354 an invalid method). msg is set to null if there is no error message.
356 deflateInit2 does not perform any compression: this will be done by 355 deflateInit2 does not perform any compression: this will be done by
357 deflate(). 356 deflate().
@@ -406,7 +405,7 @@ extern int inflateInit2 __P((z_stream *strm,
406 405
407 If next_out is not null, the library will use this buffer for the history 406 If next_out is not null, the library will use this buffer for the history
408 buffer; the buffer must either be large enough to hold the entire output 407 buffer; the buffer must either be large enough to hold the entire output
409 data, or have at least 1<<(windowBits-1) bytes. If next_out is null, the 408 data, or have at least 1<<windowBits bytes. If next_out is null, the
410 library will allocate its own buffer (and leave next_out null). next_in 409 library will allocate its own buffer (and leave next_out null). next_in
411 need not be provided here but must be provided by the application for the 410 need not be provided here but must be provided by the application for the
412 next call of inflate(). 411 next call of inflate().
@@ -418,9 +417,8 @@ extern int inflateInit2 __P((z_stream *strm,
418 avail_out is zero and all output has been consumed. 417 avail_out is zero and all output has been consumed.
419 418
420 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 419 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
421 not enough memory, Z_STREAM_ERROR if the stream state was inconsistent 420 not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
422 (such as zalloc being NULL) or the parameters are invalid (such as 421 windowBits < 8). msg is set to null if there is no error message.
423 windowBits < 9). msg is set to null if there is no error message.
424 inflateInit2 does not perform any compression: this will be done by 422 inflateInit2 does not perform any compression: this will be done by
425 inflate(). 423 inflate().
426*/ 424*/
@@ -585,7 +583,7 @@ extern uLong crc32 __P((uLong crc, Byte *buf, uInt len));
585/* 583/*
586 Update a running crc with the bytes buf[0..len-1] and return the updated 584 Update a running crc with the bytes buf[0..len-1] and return the updated
587 crc. If buf is NULL, this function returns the required initial value 585 crc. If buf is NULL, this function returns the required initial value
588 for the crc (0). Pre- and post-conditioning (one's complement) is performed 586 for the crc. Pre- and post-conditioning (one's complement) is performed
589 within this function so it shouldn't be done by the application. 587 within this function so it shouldn't be done by the application.
590 Usage example: 588 Usage example:
591 589
diff --git a/zutil.c b/zutil.c
index 1a2e7ef..9fd4ecc 100644
--- a/zutil.c
+++ b/zutil.c
@@ -3,12 +3,14 @@
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.3 1995/04/10 09:52:26 jloup Exp $ */ 6/* $Id: zutil.c,v 1.5 1995/04/14 21:30:23 jloup Exp $ */
7 7
8#include <stdio.h> 8#include <stdio.h>
9 9
10#include "zutil.h" 10#include "zutil.h"
11 11
12extern void exit __P((int));
13
12char *zlib_version = ZLIB_VERSION; 14char *zlib_version = ZLIB_VERSION;
13 15
14char *z_errmsg[] = { 16char *z_errmsg[] = {
@@ -136,7 +138,7 @@ voidp zcalloc (voidp opaque, unsigned items, unsigned size)
136 138
137void zcfree (voidp opaque, voidp ptr) 139void zcfree (voidp opaque, voidp ptr)
138{ 140{
139 return _hfree(ptr); 141 _hfree(ptr);
140} 142}
141 143
142# endif /* __TURBOC__ ? */ 144# endif /* __TURBOC__ ? */
diff --git a/zutil.h b/zutil.h
index a1108e6..20b20f5 100644
--- a/zutil.h
+++ b/zutil.h
@@ -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.4 1995/04/14 10:22:17 jloup Exp $ */ 11/* $Id: zutil.h,v 1.5 1995/04/14 21:22:38 jloup Exp $ */
12 12
13#ifndef _Z_UTIL_H 13#ifndef _Z_UTIL_H
14#define _Z_UTIL_H 14#define _Z_UTIL_H
@@ -20,6 +20,10 @@
20#else 20#else
21 extern int errno; 21 extern int errno;
22#endif 22#endif
23#ifdef __STDC__
24# include <string.h>
25# include <memory.h>
26#endif
23 27
24#ifndef local 28#ifndef local
25# define local static 29# define local static
@@ -154,13 +158,16 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
154#endif 158#endif
155 159
156 160
161typedef uLong (*check_func) __P((uLong check, Byte *buf, uInt len));
162
157extern void z_error __P((char *m)); 163extern void z_error __P((char *m));
158 164
159voidp zcalloc __P((voidp opaque, unsigned items, unsigned size)); 165voidp zcalloc __P((voidp opaque, unsigned items, unsigned size));
160void zcfree __P((voidp opaque, voidp ptr)); 166void zcfree __P((voidp opaque, voidp ptr));
161 167
162#define ZALLOC(strm, items, size) (*strm->zalloc)(strm->opaque, items, size) 168#define ZALLOC(strm, items, size) \
163#define ZFREE(strm, addr) (*strm->zfree) (strm->opaque, (voidp)addr) 169 (*((strm)->zalloc))((strm)->opaque, (items), (size))
170#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidp)(addr))
164#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 171#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
165 172
166#endif /* _Z_UTIL_H */ 173#endif /* _Z_UTIL_H */