summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--README23
-rw-r--r--compress.c6
-rw-r--r--deflate.c21
-rw-r--r--example.c42
-rw-r--r--gzio.c26
-rw-r--r--infblock.c31
-rw-r--r--infblock.h9
-rw-r--r--inffast.c2
-rw-r--r--inflate-0.72.c230
-rw-r--r--inflate.c33
-rw-r--r--inftest.c4
-rw-r--r--inftrees.c2
-rw-r--r--infutil.c4
-rw-r--r--infutil.h10
-rw-r--r--minigzip.c19
-rw-r--r--trees.c4
-rw-r--r--zconf.h9
-rw-r--r--zlib.h38
-rw-r--r--zutil.c9
-rw-r--r--zutil.h8
21 files changed, 186 insertions, 353 deletions
diff --git a/ChangeLog b/ChangeLog
index c0536d2..668d036 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,14 @@
1 ChangeLog file for zlib 1 ChangeLog file for zlib
2 2
3Changes in 0.79 (28 April 95) 3Changes in 0.8 (29 April 95)
4- add fast inflate (inffast.c) 4- added fast inflate (inffast.c)
5- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
6 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)
8- gzread no longer reads one extra byte in certain cases
5- In gzio destroy(), don't reference a freed structure 9- In gzio destroy(), don't reference a freed structure
6- avoid many warnings for MSDOS 10- avoid many warnings for MSDOS
11- avoid the ERROR symbol which is used by MS Windows
7 12
8Changes in 0.71 (14 April 95) 13Changes in 0.71 (14 April 95)
9- Fixed more MSDOS compilation problems :( There is still a bug with 14- Fixed more MSDOS compilation problems :( There is still a bug with
diff --git a/README b/README
index 5705062..a8d5788 100644
--- a/README
+++ b/README
@@ -1,4 +1,6 @@
1zlib 0.79 is a beta version of a general purpose compression library. 1zlib 0.8 is a beta version of a general purpose compression library.
2This is the first version with no known bugs. (There may still be
3problem on SGI, to be checked.)
2 4
3The data format used by the zlib library is described in the 5The data format used by the zlib library is described in the
4file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available 6file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available
@@ -9,15 +11,18 @@ zlib.h. A usage example of the library is given in the file example.c
9which also tests that the library is working correctly. 11which also tests that the library is working correctly.
10To compile all files and run the test program, just type: make test 12To compile all files and run the test program, just type: make test
11 13
12The changes made in version 0.79 are documented in the file ChangeLog. 14The changes made in version 0.8 are documented in the file ChangeLog.
13The main changes since 0.71 are: 15The main changes since 0.71 are:
14- add fast inflate (inffast.c) 16- added fast inflate (inffast.c)
15- In gzio destroy(), don't reference a freed structure 17- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
16 18 is incompatible with previous versions of zlib which returned Z_OK.
17On MSDOS, this version works in large and small model with MSC; in 19- work around a nasty TurboC compiler bug
18small model only with TurboC (bug being investigated). For both 20
19compilers, small model compression works only for small values of 21On MSDOS, this version works in both large and small model. However
20MEM_LEVEL and WBITS (see zutil.h), and requires -DUSE_CALLOC. 22small model compression works only for small values of MEM_LEVEL and
23WBITS (see zutil.h). Small model decompression should work up to WBITS=15.
24This version of zlib does not yet support small or medium model with
25far allocation of big objects.
21 26
22 27
23 Copyright (C) 1995 Jean-loup Gailly and Mark Adler 28 Copyright (C) 1995 Jean-loup Gailly and Mark Adler
diff --git a/compress.c b/compress.c
index 8edcb2a..762a9df 100644
--- a/compress.c
+++ b/compress.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: compress.c,v 1.4 1995/04/10 15:52:04 jloup Exp $ */ 6/* $Id: compress.c,v 1.5 1995/04/29 17:18:43 jloup Exp $ */
7 7
8#include "zlib.h" 8#include "zlib.h"
9 9
@@ -44,9 +44,9 @@ int compress (dest, destLen, source, sourceLen)
44 if (err != Z_OK) return err; 44 if (err != Z_OK) return err;
45 45
46 err = deflate(&stream, Z_FINISH); 46 err = deflate(&stream, Z_FINISH);
47 if (err != Z_OK) { 47 if (err != Z_STREAM_END) {
48 deflateEnd(&stream); 48 deflateEnd(&stream);
49 return err; 49 return err == Z_OK ? Z_BUF_ERROR : err;
50 } 50 }
51 *destLen = stream.total_out; 51 *destLen = stream.total_out;
52 52
diff --git a/deflate.c b/deflate.c
index 7d44627..e7e52af 100644
--- a/deflate.c
+++ b/deflate.c
@@ -47,7 +47,7 @@
47 * 47 *
48 */ 48 */
49 49
50/* $Id: deflate.c,v 1.4 1995/04/14 19:49:46 jloup Exp $ */ 50/* $Id: deflate.c,v 1.5 1995/04/29 16:52:05 jloup Exp $ */
51 51
52#include "deflate.h" 52#include "deflate.h"
53 53
@@ -117,8 +117,10 @@ local void fill_window __P((deflate_state *s));
117local int deflate_fast __P((deflate_state *s, int flush)); 117local int deflate_fast __P((deflate_state *s, int flush));
118local int deflate_slow __P((deflate_state *s, int flush)); 118local int deflate_slow __P((deflate_state *s, int flush));
119local void lm_init __P((deflate_state *s)); 119local void lm_init __P((deflate_state *s));
120
121local int longest_match __P((deflate_state *s, IPos cur_match)); 120local int longest_match __P((deflate_state *s, IPos cur_match));
121local void putShortMSB __P((deflate_state *s, uInt b));
122local void flush_pending __P((z_stream *strm));
123local int read_buf __P((z_stream *strm, char *buf, unsigned size));
122#ifdef ASMV 124#ifdef ASMV
123 void match_init __P((void)); /* asm code initialization */ 125 void match_init __P((void)); /* asm code initialization */
124#endif 126#endif
@@ -225,7 +227,7 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, strategy)
225 227
226 s->level = level; 228 s->level = level;
227 s->strategy = strategy; 229 s->strategy = strategy;
228 s->method = method; 230 s->method = (Byte)method;
229 231
230 return deflateReset(strm); 232 return deflateReset(strm);
231} 233}
@@ -265,8 +267,8 @@ local void putShortMSB (s, b)
265 deflate_state *s; 267 deflate_state *s;
266 uInt b; 268 uInt b;
267{ 269{
268 put_byte(s, b >> 8); 270 put_byte(s, (Byte)(b >> 8));
269 put_byte(s, b & 0xff); 271 put_byte(s, (Byte)(b & 0xff));
270} 272}
271 273
272/* ========================================================================= 274/* =========================================================================
@@ -346,17 +348,18 @@ int deflate (strm, flush)
346 } 348 }
347 Assert(strm->avail_out > 0, "bug2"); 349 Assert(strm->avail_out > 0, "bug2");
348 350
349 if (flush != Z_FINISH || strm->state->noheader) return Z_OK; 351 if (flush != Z_FINISH) return Z_OK;
352 if (strm->state->noheader) return Z_STREAM_END;
350 353
351 /* Write the zlib trailer (adler32) */ 354 /* Write the zlib trailer (adler32) */
352 putShortMSB(strm->state, strm->state->adler >> 16); 355 putShortMSB(strm->state, (uInt)(strm->state->adler >> 16));
353 putShortMSB(strm->state, strm->state->adler & 0xffff); 356 putShortMSB(strm->state, (uInt)(strm->state->adler & 0xffff));
354 flush_pending(strm); 357 flush_pending(strm);
355 /* If avail_out is zero, the application will call deflate again 358 /* If avail_out is zero, the application will call deflate again
356 * to flush the rest. 359 * to flush the rest.
357 */ 360 */
358 strm->state->noheader = 1; /* write the trailer only once! */ 361 strm->state->noheader = 1; /* write the trailer only once! */
359 return Z_OK; 362 return strm->state->pending != 0 ? Z_OK : Z_STREAM_END;
360} 363}
361 364
362/* ========================================================================= */ 365/* ========================================================================= */
diff --git a/example.c b/example.c
index 86541a7..5b482b8 100644
--- a/example.c
+++ b/example.c
@@ -3,11 +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: example.c,v 1.5 1995/04/14 20:35:56 jloup Exp $ */ 6/* $Id: example.c,v 1.6 1995/04/29 16:53:46 jloup Exp $ */
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include "zlib.h" 9#include "zlib.h"
10 10
11#ifdef STDC
12# include <string.h>
13#endif
14
15extern void exit __P((int));
16
11#define BUFLEN 4096 17#define BUFLEN 4096
12 18
13#define local static 19#define local static
@@ -25,6 +31,12 @@
25 31
26char *hello = "hello world"; 32char *hello = "hello world";
27 33
34void test_compress __P((void));
35void test_gzio __P((char *out, char *in));
36void test_deflate __P((Byte compr[]));
37void test_inflate __P((Byte compr[]));
38void main __P((int argc, char *argv[]));
39
28/* =========================================================================== 40/* ===========================================================================
29 * Test compress() and uncompress() 41 * Test compress() and uncompress()
30 */ 42 */
@@ -37,15 +49,15 @@ void test_compress()
37 int err; 49 int err;
38 uLong len = strlen(hello)+1; 50 uLong len = strlen(hello)+1;
39 51
40 err = compress(compr, &comprLen, hello, len); 52 err = compress(compr, &comprLen, (Byte*)hello, len);
41 CHECK_ERR(err, "compress"); 53 CHECK_ERR(err, "compress");
42 54
43 strcpy(uncompr, "garbage"); 55 strcpy((char*)uncompr, "garbage");
44 56
45 err = uncompress(uncompr, &uncomprLen, compr, comprLen); 57 err = uncompress(uncompr, &uncomprLen, compr, comprLen);
46 CHECK_ERR(err, "uncompress"); 58 CHECK_ERR(err, "uncompress");
47 59
48 if (strcmp(uncompr, hello)) { 60 if (strcmp((char*)uncompr, hello)) {
49 fprintf(stderr, "bad uncompress\n"); 61 fprintf(stderr, "bad uncompress\n");
50 } else { 62 } else {
51 printf("uncompress(): %s\n", uncompr); 63 printf("uncompress(): %s\n", uncompr);
@@ -80,7 +92,7 @@ void test_gzio(out, in)
80 if (file == NULL) { 92 if (file == NULL) {
81 fprintf(stderr, "gzopen error\n"); 93 fprintf(stderr, "gzopen error\n");
82 } 94 }
83 strcpy(uncompr, "garbage"); 95 strcpy((char*)uncompr, "garbage");
84 96
85 uncomprLen = gzread(file, uncompr, uncomprLen); 97 uncomprLen = gzread(file, uncompr, uncomprLen);
86 if (uncomprLen != len) { 98 if (uncomprLen != len) {
@@ -88,7 +100,7 @@ void test_gzio(out, in)
88 } 100 }
89 gzclose(file); 101 gzclose(file);
90 102
91 if (strcmp(uncompr, hello)) { 103 if (strcmp((char*)uncompr, hello)) {
92 fprintf(stderr, "bad gzread\n"); 104 fprintf(stderr, "bad gzread\n");
93 } else { 105 } else {
94 printf("gzread(): %s\n", uncompr); 106 printf("gzread(): %s\n", uncompr);
@@ -96,9 +108,9 @@ void test_gzio(out, in)
96} 108}
97 109
98/* =========================================================================== 110/* ===========================================================================
99 * Test deflate() with small buffers, return the compressed length. 111 * Test deflate() with small buffers
100 */ 112 */
101uLong test_deflate(compr) 113void test_deflate(compr)
102 Byte compr[]; 114 Byte compr[];
103{ 115{
104 z_stream c_stream; /* compression stream */ 116 z_stream c_stream; /* compression stream */
@@ -120,16 +132,15 @@ uLong test_deflate(compr)
120 CHECK_ERR(err, "deflate"); 132 CHECK_ERR(err, "deflate");
121 } 133 }
122 /* Finish the stream, still forcing small buffers: */ 134 /* Finish the stream, still forcing small buffers: */
123 do { 135 for (;;) {
124 c_stream.avail_out = 1; 136 c_stream.avail_out = 1;
125 err = deflate(&c_stream, Z_FINISH); 137 err = deflate(&c_stream, Z_FINISH);
138 if (err == Z_STREAM_END) break;
126 CHECK_ERR(err, "deflate"); 139 CHECK_ERR(err, "deflate");
127 } while (c_stream.avail_out == 0); 140 }
128 141
129 err = deflateEnd(&c_stream); 142 err = deflateEnd(&c_stream);
130 CHECK_ERR(err, "deflateEnd"); 143 CHECK_ERR(err, "deflateEnd");
131
132 return c_stream.total_out;
133} 144}
134 145
135/* =========================================================================== 146/* ===========================================================================
@@ -142,7 +153,7 @@ void test_inflate(compr)
142 int err; 153 int err;
143 z_stream d_stream; /* decompression stream */ 154 z_stream d_stream; /* decompression stream */
144 155
145 strcpy(uncompr, "garbage"); 156 strcpy((char*)uncompr, "garbage");
146 157
147 d_stream.zalloc = (alloc_func)0; 158 d_stream.zalloc = (alloc_func)0;
148 d_stream.zfree = (free_func)0; 159 d_stream.zfree = (free_func)0;
@@ -163,7 +174,7 @@ void test_inflate(compr)
163 err = inflateEnd(&d_stream); 174 err = inflateEnd(&d_stream);
164 CHECK_ERR(err, "inflateEnd"); 175 CHECK_ERR(err, "inflateEnd");
165 176
166 if (strcmp(uncompr, hello)) { 177 if (strcmp((char*)uncompr, hello)) {
167 fprintf(stderr, "bad inflate\n"); 178 fprintf(stderr, "bad inflate\n");
168 } else { 179 } else {
169 printf("inflate(): %s\n", uncompr); 180 printf("inflate(): %s\n", uncompr);
@@ -179,7 +190,6 @@ void main(argc, argv)
179 char *argv[]; 190 char *argv[];
180{ 191{
181 local Byte compr[BUFLEN]; 192 local Byte compr[BUFLEN];
182 uLong comprLen;
183 193
184 if (zlib_version[0] != ZLIB_VERSION[0]) { 194 if (zlib_version[0] != ZLIB_VERSION[0]) {
185 fprintf(stderr, "incompatible zlib version\n"); 195 fprintf(stderr, "incompatible zlib version\n");
@@ -193,7 +203,7 @@ void main(argc, argv)
193 test_gzio((argc > 1 ? argv[1] : "foo.gz"), 203 test_gzio((argc > 1 ? argv[1] : "foo.gz"),
194 (argc > 2 ? argv[2] : "foo.gz")); 204 (argc > 2 ? argv[2] : "foo.gz"));
195 205
196 comprLen = test_deflate(compr); 206 test_deflate(compr);
197 207
198 test_inflate(compr); 208 test_inflate(compr);
199 209
diff --git a/gzio.c b/gzio.c
index 365b6f5..6c3211a 100644
--- a/gzio.c
+++ b/gzio.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: gzio.c,v 1.4 1995/04/14 14:50:52 jloup Exp $ */ 6/* $Id: gzio.c,v 1.5 1995/04/29 17:13:56 jloup Exp $ */
7 7
8#include <stdio.h> 8#include <stdio.h>
9 9
@@ -46,7 +46,12 @@ typedef struct gz_stream {
46} gz_stream; 46} gz_stream;
47 47
48 48
49/* =========================================================================== 49local int destroy __P((gz_stream *s));
50local gzFile gz_open __P((char *path, char *mode, int fd));
51local void putLong __P((FILE *file, uLong x));
52local uLong getLong __P((Byte *buf));
53
54 /* ===========================================================================
50 * Cleanup then free the given gz_stream. Return a zlib error code. 55 * Cleanup then free the given gz_stream. Return a zlib error code.
51 */ 56 */
52local int destroy (s) 57local int destroy (s)
@@ -339,7 +344,7 @@ int gzflush (file, flush)
339 if (len != 0) { 344 if (len != 0) {
340 if (fwrite(s->outbuf, 1, len, s->file) != len) { 345 if (fwrite(s->outbuf, 1, len, s->file) != len) {
341 s->z_err = Z_ERRNO; 346 s->z_err = Z_ERRNO;
342 break; 347 return Z_ERRNO;
343 } 348 }
344 s->stream.next_out = s->outbuf; 349 s->stream.next_out = s->outbuf;
345 s->stream.avail_out = Z_BUFSIZE; 350 s->stream.avail_out = Z_BUFSIZE;
@@ -347,14 +352,14 @@ int gzflush (file, flush)
347 if (done) break; 352 if (done) break;
348 s->z_err = deflate(&(s->stream), flush); 353 s->z_err = deflate(&(s->stream), flush);
349 354
350 if (s->z_err != Z_OK) break; 355 /* deflate has finished flushing only when it hasn't used up
351
352 /* deflate has finished flushing only when it hasn't used up
353 * all the available space in the output buffer: 356 * all the available space in the output buffer:
354 */ 357 */
355 done = (s->stream.avail_out != 0); 358 done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
359
360 if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
356 } 361 }
357 return s->z_err; 362 return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
358} 363}
359 364
360/* =========================================================================== 365/* ===========================================================================
@@ -395,12 +400,15 @@ int gzclose (file)
395 gzFile file; 400 gzFile file;
396{ 401{
397 uInt n; 402 uInt n;
403 int err;
398 gz_stream *s = (gz_stream*)file; 404 gz_stream *s = (gz_stream*)file;
399 405
400 if (s == NULL) return Z_STREAM_ERROR; 406 if (s == NULL) return Z_STREAM_ERROR;
401 407
402 if (s->mode == 'w') { 408 if (s->mode == 'w') {
403 gzflush (file, Z_FINISH); 409 err = gzflush (file, Z_FINISH);
410 if (err != Z_OK) return destroy(file);
411
404 putLong (s->file, s->crc); 412 putLong (s->file, s->crc);
405 putLong (s->file, s->stream.total_in); 413 putLong (s->file, s->stream.total_in);
406 414
diff --git a/infblock.c b/infblock.c
index 4d8bd48..2c2f8dd 100644
--- a/infblock.c
+++ b/infblock.c
@@ -139,7 +139,7 @@ int r;
139 break; 139 break;
140 case 3: /* illegal */ 140 case 3: /* illegal */
141 DUMPBITS(3) 141 DUMPBITS(3)
142 s->mode = ERROR; 142 s->mode = INF_ERROR;
143 z->msg = "invalid block type"; 143 z->msg = "invalid block type";
144 r = Z_DATA_ERROR; 144 r = Z_DATA_ERROR;
145 LEAVE 145 LEAVE
@@ -149,7 +149,7 @@ int r;
149 NEEDBITS(32) 149 NEEDBITS(32)
150 if ((~b) >> 16 != (b & 0xffff)) 150 if ((~b) >> 16 != (b & 0xffff))
151 { 151 {
152 s->mode = ERROR; 152 s->mode = INF_ERROR;
153 z->msg = "invalid stored block lengths"; 153 z->msg = "invalid stored block lengths";
154 r = Z_DATA_ERROR; 154 r = Z_DATA_ERROR;
155 LEAVE 155 LEAVE
@@ -172,7 +172,7 @@ int r;
172#ifndef PKZIP_BUG_WORKAROUND 172#ifndef PKZIP_BUG_WORKAROUND
173 if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) 173 if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
174 { 174 {
175 s->mode = ERROR; 175 s->mode = INF_ERROR;
176 z->msg = "too many length or distance symbols"; 176 z->msg = "too many length or distance symbols";
177 r = Z_DATA_ERROR; 177 r = Z_DATA_ERROR;
178 LEAVE 178 LEAVE
@@ -205,7 +205,7 @@ int r;
205 { 205 {
206 r = t; 206 r = t;
207 if (r == Z_DATA_ERROR) 207 if (r == Z_DATA_ERROR)
208 s->mode = ERROR; 208 s->mode = INF_ERROR;
209 LEAVE 209 LEAVE
210 } 210 }
211 s->sub.trees.index = 0; 211 s->sub.trees.index = 0;
@@ -240,7 +240,7 @@ int r;
240 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || 240 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
241 (c == 16 && i < 1)) 241 (c == 16 && i < 1))
242 { 242 {
243 s->mode = ERROR; 243 s->mode = INF_ERROR;
244 z->msg = "invalid bit length repeat"; 244 z->msg = "invalid bit length repeat";
245 r = Z_DATA_ERROR; 245 r = Z_DATA_ERROR;
246 LEAVE 246 LEAVE
@@ -267,7 +267,7 @@ int r;
267 if (t != Z_OK) 267 if (t != Z_OK)
268 { 268 {
269 if (t == (uInt)Z_DATA_ERROR) 269 if (t == (uInt)Z_DATA_ERROR)
270 s->mode = ERROR; 270 s->mode = INF_ERROR;
271 r = t; 271 r = t;
272 LEAVE 272 LEAVE
273 } 273 }
@@ -289,8 +289,19 @@ int r;
289 r = Z_OK; 289 r = Z_OK;
290 inflate_codes_free(s->sub.codes, z); 290 inflate_codes_free(s->sub.codes, z);
291 LOAD 291 LOAD
292 s->mode = s->last ? DRY : TYPE; 292 if (!s->last)
293 {
294 s->mode = TYPE;
293 break; 295 break;
296 }
297 if (k > 7) /* return unused byte, if any */
298 {
299 Assert(k < 16, "inflate_codes grabbed too many bytes")
300 k -= 8;
301 n++;
302 p--; /* can always return one */
303 }
304 s->mode = DRY;
294 case DRY: 305 case DRY:
295 FLUSH 306 FLUSH
296 if (s->read != s->write) 307 if (s->read != s->write)
@@ -299,7 +310,7 @@ int r;
299 case DONE: 310 case DONE:
300 r = Z_STREAM_END; 311 r = Z_STREAM_END;
301 LEAVE 312 LEAVE
302 case ERROR: 313 case INF_ERROR:
303 r = Z_DATA_ERROR; 314 r = Z_DATA_ERROR;
304 LEAVE 315 LEAVE
305 default: 316 default:
@@ -309,13 +320,11 @@ int r;
309} 320}
310 321
311 322
312int inflate_blocks_free(s, z, c, e) 323int inflate_blocks_free(s, z, c)
313struct inflate_blocks_state *s; 324struct inflate_blocks_state *s;
314z_stream *z; 325z_stream *z;
315uLong *c; 326uLong *c;
316int *e;
317{ 327{
318 *e = (int)(s->bitk > 7 ? (s->bitb >> (s->bitk & 7)) & 0xff : -1);
319 if (s->checkfn != Z_NULL) 328 if (s->checkfn != Z_NULL)
320 *c = s->check; 329 *c = s->check;
321 if (s->mode == BTREE || s->mode == DTREE) 330 if (s->mode == BTREE || s->mode == DTREE)
diff --git a/infblock.h b/infblock.h
index a21d730..4a9e0e2 100644
--- a/infblock.h
+++ b/infblock.h
@@ -11,9 +11,9 @@
11struct inflate_blocks_state; 11struct 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 *z,
15 check_func checkfn, /* check function */ 15 check_func c, /* check function */
16 uInt)); /* window size */ 16 uInt w)); /* window size */
17 17
18extern int inflate_blocks __P(( 18extern int inflate_blocks __P((
19 struct inflate_blocks_state *, 19 struct inflate_blocks_state *,
@@ -23,5 +23,4 @@ extern int inflate_blocks __P((
23extern int inflate_blocks_free __P(( 23extern int inflate_blocks_free __P((
24 struct inflate_blocks_state *, 24 struct inflate_blocks_state *,
25 z_stream *, 25 z_stream *,
26 uLong *, /* check value on output */ 26 uLong *)); /* check value on output */
27 int *)); /* possible leftover byte to return */
diff --git a/inffast.c b/inffast.c
index 8c3e4ce..29c97e2 100644
--- a/inffast.c
+++ b/inffast.c
@@ -8,6 +8,8 @@
8#include "infutil.h" 8#include "infutil.h"
9#include "inffast.h" 9#include "inffast.h"
10 10
11struct inflate_codes_state {int dummy;}; /* for buggy compilers */
12
11/* simplify the use of the inflate_huft type with some defines */ 13/* simplify the use of the inflate_huft type with some defines */
12#define base more.Base 14#define base more.Base
13#define next more.Next 15#define next more.Next
diff --git a/inflate-0.72.c b/inflate-0.72.c
deleted file mode 100644
index 56b0665..0000000
--- a/inflate-0.72.c
+++ /dev/null
@@ -1,230 +0,0 @@
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 38d70cc..b76e246 100644
--- a/inflate.c
+++ b/inflate.c
@@ -22,7 +22,7 @@ struct internal_state {
22 CHECK2, /* two check bytes to go */ 22 CHECK2, /* two check bytes to go */
23 CHECK1, /* one check byte to go */ 23 CHECK1, /* one check byte to go */
24 DONE, /* finished check, done */ 24 DONE, /* finished check, done */
25 ERROR} /* got an error--stay here */ 25 INF_ERROR}/* got an error--stay here */
26 mode; /* current inflate mode */ 26 mode; /* current inflate mode */
27 27
28 /* mode dependent information */ 28 /* mode dependent information */
@@ -92,7 +92,7 @@ int inflate(z, f)
92z_stream *z; 92z_stream *z;
93int f; 93int f;
94{ 94{
95 int r; 95 int r = f; /* to avoid warning about unused f */
96 uInt b; 96 uInt b;
97 uLong c; 97 uLong c;
98 98
@@ -105,13 +105,13 @@ int f;
105 if (z->avail_in == 0) return r; r = Z_OK; 105 if (z->avail_in == 0) return r; r = Z_OK;
106 if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED)) 106 if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED))
107 { 107 {
108 z->state->mode = ERROR; 108 z->state->mode = INF_ERROR;
109 z->msg = "unknown compression method"; 109 z->msg = "unknown compression method";
110 return Z_DATA_ERROR; 110 return Z_DATA_ERROR;
111 } 111 }
112 if ((z->state->sub.method >> 4) + 8 > z->state->wbits) 112 if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
113 { 113 {
114 z->state->mode = ERROR; 114 z->state->mode = INF_ERROR;
115 z->msg = "invalid window size"; 115 z->msg = "invalid window size";
116 return Z_DATA_ERROR; 116 return Z_DATA_ERROR;
117 } 117 }
@@ -120,13 +120,13 @@ int f;
120 if (z->avail_in == 0) return r; r = Z_OK; 120 if (z->avail_in == 0) return r; r = Z_OK;
121 if ((b = NEXTBYTE) & 0x20) 121 if ((b = NEXTBYTE) & 0x20)
122 { 122 {
123 z->state->mode = ERROR; 123 z->state->mode = INF_ERROR;
124 z->msg = "invalid reserved bit"; 124 z->msg = "invalid reserved bit";
125 return Z_DATA_ERROR; 125 return Z_DATA_ERROR;
126 } 126 }
127 if (((z->state->sub.method << 8) + b) % 31) 127 if (((z->state->sub.method << 8) + b) % 31)
128 { 128 {
129 z->state->mode = ERROR; 129 z->state->mode = INF_ERROR;
130 z->msg = "incorrect header check"; 130 z->msg = "incorrect header check";
131 return Z_DATA_ERROR; 131 return Z_DATA_ERROR;
132 } 132 }
@@ -140,23 +140,13 @@ int f;
140 case BLOCKS: 140 case BLOCKS:
141 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)
142 return r; 142 return r;
143 inflate_blocks_free(z->state->sub.blocks, z, &c, &r); 143 inflate_blocks_free(z->state->sub.blocks, z, &c);
144 if (z->state->nowrap) 144 if (z->state->nowrap)
145 { 145 {
146 if (r != -1) 146 z->state->mode = DONE;
147 z->msg = "inflate bug--took one too many bytes";
148 z->state->mode = r == -1 ? DONE : ERROR;
149 break; 147 break;
150 } 148 }
151 z->state->sub.check.was = c; 149 z->state->sub.check.was = c;
152 if (r != -1)
153 {
154 z->state->sub.check.need = (uLong)r << 24;
155 z->state->mode = CHECK3;
156 r = Z_OK;
157 break;
158 }
159 r = Z_OK;
160 z->state->mode = CHECK4; 150 z->state->mode = CHECK4;
161 case CHECK4: 151 case CHECK4:
162 if (z->avail_in == 0) return r; r = Z_OK; 152 if (z->avail_in == 0) return r; r = Z_OK;
@@ -175,14 +165,14 @@ int f;
175 z->state->sub.check.need += (uLong)NEXTBYTE; 165 z->state->sub.check.need += (uLong)NEXTBYTE;
176 if (z->state->sub.check.was != z->state->sub.check.need) 166 if (z->state->sub.check.was != z->state->sub.check.need)
177 { 167 {
178 z->state->mode = ERROR; 168 z->state->mode = INF_ERROR;
179 z->msg = "incorrect data check"; 169 z->msg = "incorrect data check";
180 return Z_DATA_ERROR; 170 return Z_DATA_ERROR;
181 } 171 }
182 z->state->mode = DONE; 172 z->state->mode = DONE;
183 case DONE: 173 case DONE:
184 return Z_STREAM_END; 174 return Z_STREAM_END;
185 case ERROR: 175 case INF_ERROR:
186 return Z_DATA_ERROR; 176 return Z_DATA_ERROR;
187 default: 177 default:
188 return Z_STREAM_ERROR; 178 return Z_STREAM_ERROR;
@@ -194,12 +184,11 @@ int inflateEnd(z)
194z_stream *z; 184z_stream *z;
195{ 185{
196 uLong c; 186 uLong c;
197 int e;
198 187
199 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) 188 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
200 return Z_STREAM_ERROR; 189 return Z_STREAM_ERROR;
201 if (z->state->mode == BLOCKS) 190 if (z->state->mode == BLOCKS)
202 inflate_blocks_free(z->state->sub.blocks, z, &c, &e); 191 inflate_blocks_free(z->state->sub.blocks, z, &c);
203 ZFREE(z, z->state); 192 ZFREE(z, z->state);
204 z->state = Z_NULL; 193 z->state = Z_NULL;
205 return Z_OK; 194 return Z_OK;
diff --git a/inftest.c b/inftest.c
index 7dc2907..d711bfa 100644
--- a/inftest.c
+++ b/inftest.c
@@ -2,6 +2,8 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include "zutil.h" 3#include "zutil.h"
4 4
5void main __P((void));
6
5/* This test is in honor of Ed Hamrick who suggested that the interface 7/* This test is in honor of Ed Hamrick who suggested that the interface
6 to inflate be a byte at a time--this implements that, and is, of course, 8 to inflate be a byte at a time--this implements that, and is, of course,
7 monumentally slow. It has the virtue though of stressing the push-pull 9 monumentally slow. It has the virtue though of stressing the push-pull
@@ -61,7 +63,7 @@ void main()
61 break; 63 break;
62 } 64 }
63 inflateEnd(&z); 65 inflateEnd(&z);
64 fprintf(stderr, "%d bytes in, %d bytes out\n", z.total_in, z.total_out); 66 fprintf(stderr, "%ld bytes in, %ld bytes out\n", z.total_in, z.total_out);
65 if (z.msg != NULL) 67 if (z.msg != NULL)
66 fprintf(stderr, "msg is <%s>\n", z.msg); 68 fprintf(stderr, "msg is <%s>\n", z.msg);
67} 69}
diff --git a/inftrees.c b/inftrees.c
index 54c7c8e..ab0ed2c 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -383,6 +383,7 @@ uInt s; /* size of item */
383{ 383{
384 Assert(s == sizeof(inflate_huft) && n <= fixed_left, 384 Assert(s == sizeof(inflate_huft) && n <= fixed_left,
385 "inflate_trees falloc overflow"); 385 "inflate_trees falloc overflow");
386 if (q) s++; /* to make some compilers happy */
386 fixed_left -= n; 387 fixed_left -= n;
387 return (voidp)(fixed_mem + fixed_left); 388 return (voidp)(fixed_mem + fixed_left);
388} 389}
@@ -393,6 +394,7 @@ voidp q;
393voidp p; 394voidp p;
394{ 395{
395 Assert(0, "inflate_trees ffree called!"); 396 Assert(0, "inflate_trees ffree called!");
397 if (q) q = p; /* to make some compilers happy */
396} 398}
397 399
398 400
diff --git a/infutil.c b/infutil.c
index 1adadbf..3f687e6 100644
--- a/infutil.c
+++ b/infutil.c
@@ -31,7 +31,7 @@ int r;
31 q = s->read; 31 q = s->read;
32 32
33 /* compute number of bytes to copy as far as end of window */ 33 /* compute number of bytes to copy as far as end of window */
34 n = (q <= s->write ? s->write : s->end) - q; 34 n = (uInt)((q <= s->write ? s->write : s->end) - q);
35 if (n > z->avail_out) n = z->avail_out; 35 if (n > z->avail_out) n = z->avail_out;
36 if (n && r == Z_BUF_ERROR) r = Z_OK; 36 if (n && r == Z_BUF_ERROR) r = Z_OK;
37 37
@@ -55,7 +55,7 @@ int r;
55 s->write = s->window; 55 s->write = s->window;
56 56
57 /* compute bytes to copy */ 57 /* compute bytes to copy */
58 n = s->write - q; 58 n = (uInt)(s->write - q);
59 if (n > z->avail_out) n = z->avail_out; 59 if (n > z->avail_out) n = z->avail_out;
60 if (n && r == Z_BUF_ERROR) r = Z_OK; 60 if (n && r == Z_BUF_ERROR) r = Z_OK;
61 61
diff --git a/infutil.h b/infutil.h
index 30b230d..2aabf3c 100644
--- a/infutil.h
+++ b/infutil.h
@@ -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 ERROR} /* got a data error--stuck here */ 25 INF_ERROR}/* 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,7 +63,13 @@ 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#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}} 66#ifdef __TURBOC__ /* bug in TurboC compiler, bad code for b << 0 */
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
67#define DUMPBITS(j) {b>>=(j);k-=(j);} 73#define DUMPBITS(j) {b>>=(j);k-=(j);}
68/* output bytes */ 74/* output bytes */
69#define WAVAIL (q<s->read?s->read-q-1:s->end-q) 75#define WAVAIL (q<s->read?s->read-q-1:s->end-q)
diff --git a/minigzip.c b/minigzip.c
index 4936d64..d3d2fe9 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -13,15 +13,21 @@
13 * or in pipe mode. 13 * or in pipe mode.
14 */ 14 */
15 15
16/* $Id: minigzip.c,v 1.2 1995/04/14 20:03:12 jloup Exp $ */ 16/* $Id: minigzip.c,v 1.3 1995/04/29 14:27:21 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)); 21extern void exit __P((int));
22extern int unlink __P((const char *));
23
24#ifdef STDC
25# include <string.h>
26#endif
22 27
23#ifdef MSDOS 28#ifdef MSDOS
24# include <fcntl.h> /* ??? find where setmode declared */ 29# include <fcntl.h>
30# include <io.h>
25# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 31# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
26#else 32#else
27# define SET_BINARY_MODE(file) 33# define SET_BINARY_MODE(file)
@@ -38,6 +44,13 @@ extern void exit __P((int));
38 44
39char *prog; 45char *prog;
40 46
47void error __P((char *msg));
48void gz_compress __P((FILE *in, gzFile out));
49void gz_uncompress __P((gzFile in, FILE *out));
50void file_compress __P((char *file));
51void file_uncompress __P((char *file));
52void main __P((int argc, char *argv[]));
53
41/* =========================================================================== 54/* ===========================================================================
42 * Display error message and exit 55 * Display error message and exit
43 */ 56 */
diff --git a/trees.c b/trees.c
index 62411a7..9234add 100644
--- a/trees.c
+++ b/trees.c
@@ -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.2 1995/04/10 16:21:44 jloup Exp $ */ 32/* $Id: trees.c,v 1.3 1995/04/29 13:49:46 jloup Exp $ */
33 33
34#include "deflate.h" 34#include "deflate.h"
35 35
@@ -944,7 +944,7 @@ local void set_data_type(s)
944 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; 944 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
945 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; 945 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
946 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; 946 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
947 s->data_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; 947 s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII);
948} 948}
949 949
950/* =========================================================================== 950/* ===========================================================================
diff --git a/zconf.h b/zconf.h
index f08793b..bcd8510 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.8 1995/04/14 20:59:22 jloup Exp $ */ 6/* $Id: zconf.h,v 1.9 1995/04/29 12:02:14 jloup Exp $ */
7 7
8#ifndef _ZCONF_H 8#ifndef _ZCONF_H
9#define _ZCONF_H 9#define _ZCONF_H
@@ -28,6 +28,9 @@
28#if defined(MSDOS) && !defined(__32BIT__) 28#if defined(MSDOS) && !defined(__32BIT__)
29# define MAXSEG_64K 29# define MAXSEG_64K
30#endif 30#endif
31#if !defined(STDC) && (defined(MSDOS) || defined(__STDC__))
32# define STDC
33#endif
31 34
32#ifdef MAXSEG_64K 35#ifdef MAXSEG_64K
33# define MAX_MEM_LEVEL 8 36# define MAX_MEM_LEVEL 8
@@ -38,7 +41,7 @@
38 /* Type declarations */ 41 /* Type declarations */
39 42
40#ifndef __P /* function prototypes */ 43#ifndef __P /* function prototypes */
41# if defined(__STDC__) || defined(MSDOS) 44# ifdef STDC
42# define __P(args) args 45# define __P(args) args
43# else 46# else
44# define __P(args) () 47# define __P(args) ()
@@ -55,7 +58,7 @@
55 typedef unsigned long uLong; /* 32 bits or more */ 58 typedef unsigned long uLong; /* 32 bits or more */
56#endif 59#endif
57#ifndef voidp 60#ifndef voidp
58# if defined(__STDC__) || defined(MSDOS) 61# ifdef STDC
59 typedef void *voidp; 62 typedef void *voidp;
60# else 63# else
61 typedef Byte *voidp; 64 typedef Byte *voidp;
diff --git a/zlib.h b/zlib.h
index 6983fb7..f72fff8 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.79 April 28th, 1995. 2 version 0.8 April 29th, 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.79" 31#define ZLIB_VERSION "0.8"
32 32
33/* 33/*
34 The 'zlib' compression library provides in-memory compression and 34 The 'zlib' compression library provides in-memory compression and
@@ -191,25 +191,30 @@ extern int deflate __P((z_stream *strm, int flush));
191 so should be used only when necessary. Using Z_FULL_FLUSH too often can 191 so should be used only when necessary. Using Z_FULL_FLUSH too often can
192 seriously degrade the compression. 192 seriously degrade the compression.
193 193
194 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 processed,
195 processed and all pending output is flushed. The next operation on this 195 all pending output is flushed and deflate returns with Z_STREAM_END if there
196 stream must be another call of deflate with Z_FINISH but no more input data 196 was enough output space; if deflate returns with Z_OK, this function must be
197 (unchanged avail_in) if this call returned with avail_out equal to zero, 197 called again with Z_FINISH and more output space (updated avail_out) but no
198 or a call of deflateEnd to deallocate the compression state. Z_FINISH can 198 more input data, until it returns with Z_STREAM_END or an error. After
199 be used immediately after deflateInit if all the compression is to be 199 deflate has returned Z_STREAM_END, the only possible operations on the
200 done in a single step. In this case, avail_out must be at least 0.1% 200 stream are deflateReset or deflateEnd.
201 larger than avail_in plus 12 bytes. 201
202 Z_FINISH can be used immediately after deflateInit if all the compression
203 is to be done in a single step. In this case, avail_out must be at least
204 0.1% larger than avail_in plus 12 bytes. If deflate does not return
205 Z_STREAM_END, then it must be called again as described above.
202 206
203 deflate() may update data_type if it can make a good guess about 207 deflate() may update data_type if it can make a good guess about
204 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered 208 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
205 binary. This field is only for information purposes and does not affect 209 binary. This field is only for information purposes and does not affect
206 the compression algorithm in any manner. 210 the compression algorithm in any manner.
207 211
208 deflate() returns Z_OK if some progress has been made (more input processed 212 deflate() returns Z_OK if some progress has been made (more input
209 or more output produced), Z_STREAM_ERROR if the stream state was 213 processed or more output produced), Z_STREAM_END if all input has been
210 inconsistent (for example if next_in or next_out was NULL), Z_BUF_ERROR if 214 consumed and all output has been produced (only when flush is set to
211 no progress is possible or if there was not enough room in the output buffer 215 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
212 when Z_FINISH is used. ??? to be changed (use Z_STEAM_END) */ 216 if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
217*/
213 218
214 219
215extern int deflateEnd __P((z_stream *strm)); 220extern int deflateEnd __P((z_stream *strm));
@@ -534,7 +539,8 @@ extern int gzflush __P((gzFile file, int flush));
534/* 539/*
535 Flushes all pending output into the compressed file. The parameter 540 Flushes all pending output into the compressed file. The parameter
536 flush is as in the deflate() function. The return value is the zlib 541 flush is as in the deflate() function. The return value is the zlib
537 error number (see function gzerror below). 542 error number (see function gzerror below). gzflush returns Z_OK if
543 the flush parameter is Z_FINISH and all output could be flushed.
538 gzflush should be called only when strictly necessary because it can 544 gzflush should be called only when strictly necessary because it can
539 degrade compression. 545 degrade compression.
540*/ 546*/
diff --git a/zutil.c b/zutil.c
index 9fd4ecc..4ceb89f 100644
--- a/zutil.c
+++ b/zutil.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: zutil.c,v 1.5 1995/04/14 21:30:23 jloup Exp $ */ 6/* $Id: zutil.c,v 1.6 1995/04/29 14:54:02 jloup Exp $ */
7 7
8#include <stdio.h> 8#include <stdio.h>
9 9
@@ -55,7 +55,7 @@ void zmemzero(dest, len)
55} 55}
56#endif 56#endif
57 57
58#if defined(MSDOS) && !defined(USE_CALLOC) 58#if defined(MSDOS) && !defined(__SMALL__) && !defined(M_I86SM)
59# ifdef __TURBOC__ 59# ifdef __TURBOC__
60 60
61/* Turbo C malloc() does not allow dynamic allocation of 64K bytes 61/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
@@ -84,7 +84,7 @@ local ptr_table table[MAX_PTR];
84 84
85voidp zcalloc (voidp opaque, unsigned items, unsigned size) 85voidp zcalloc (voidp opaque, unsigned items, unsigned size)
86{ 86{
87 voidp buf; 87 voidp buf = opaque; /* just to make some compilers happy */
88 ulg bsize = (ulg)items*size; 88 ulg bsize = (ulg)items*size;
89 89
90 if (bsize < 65536L) { 90 if (bsize < 65536L) {
@@ -121,6 +121,7 @@ void zcfree (voidp opaque, voidp ptr)
121 next_ptr--; 121 next_ptr--;
122 return; 122 return;
123 } 123 }
124 ptr = opaque; /* just to make some compilers happy */
124 z_error("zcfree: ptr not found"); 125 z_error("zcfree: ptr not found");
125} 126}
126 127
@@ -133,11 +134,13 @@ void zcfree (voidp opaque, voidp ptr)
133 134
134voidp zcalloc (voidp opaque, unsigned items, unsigned size) 135voidp zcalloc (voidp opaque, unsigned items, unsigned size)
135{ 136{
137 if (opaque) opaque = 0; /* to make compiler happy */
136 return _halloc((long)items, size); 138 return _halloc((long)items, size);
137} 139}
138 140
139void zcfree (voidp opaque, voidp ptr) 141void zcfree (voidp opaque, voidp ptr)
140{ 142{
143 if (opaque) opaque = 0; /* to make compiler happy */
141 _hfree(ptr); 144 _hfree(ptr);
142} 145}
143 146
diff --git a/zutil.h b/zutil.h
index 20b20f5..88f5961 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.5 1995/04/14 21:22:38 jloup Exp $ */ 11/* $Id: zutil.h,v 1.6 1995/04/29 15:52:16 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,9 +20,8 @@
20#else 20#else
21 extern int errno; 21 extern int errno;
22#endif 22#endif
23#ifdef __STDC__ 23#ifdef STDC
24# include <string.h> 24# include <string.h>
25# include <memory.h>
26#endif 25#endif
27 26
28#ifndef local 27#ifndef local
@@ -66,7 +65,6 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
66# define OS_CODE 0x00 65# define OS_CODE 0x00
67# ifdef __TURBOC__ 66# ifdef __TURBOC__
68# include <alloc.h> 67# include <alloc.h>
69# define exit(n) _exit(n)
70# else /* MSC */ 68# else /* MSC */
71# include <malloc.h> 69# include <malloc.h>
72# endif 70# endif
@@ -125,7 +123,7 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
125# define zstrerror(errnum) "" 123# define zstrerror(errnum) ""
126#endif 124#endif
127 125
128#if defined(__STDC__) && !defined(HAVE_MEMCPY) 126#if defined(STDC) && !defined(HAVE_MEMCPY)
129# define HAVE_MEMCPY 127# define HAVE_MEMCPY
130#endif 128#endif
131#ifdef HAVE_MEMCPY 129#ifdef HAVE_MEMCPY