summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--Makefile.bor1
-rw-r--r--Makefile.msc1
-rw-r--r--Makefile.tc4
-rw-r--r--README39
-rw-r--r--deflate.c18
-rw-r--r--deflate.h1
-rw-r--r--example.c2
-rw-r--r--gzio.c4
-rw-r--r--inftrees.c18
-rw-r--r--trees.c140
-rw-r--r--zconf.h43
-rw-r--r--zlib.h14
-rw-r--r--zutil.c43
-rw-r--r--zutil.h26
15 files changed, 225 insertions, 140 deletions
diff --git a/ChangeLog b/ChangeLog
index d6733c5..4c69f88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,16 @@
1 1
2 ChangeLog file for zlib 2 ChangeLog file for zlib
3 3
4Changes in 0.95 (16 Aug 95)
5- fix MSDOS small and medium model (now easier to adapt to any compiler)
6- inlined send_bits
7- fix the final (:-) bug for deflate with flush (output was correct but
8 not completely flushed in rare occasions).
9- default window size is same for compression and decompression
10 (it's now sufficient to set MAX_WBITS in zconf.h).
11- voidp -> voidpf and voidnp -> voidp (for consistency with other
12 typedefs and because voidnp was not near in large model).
13
4Changes in 0.94 (13 Aug 95) 14Changes in 0.94 (13 Aug 95)
5- support MSDOS medium model 15- support MSDOS medium model
6- fix deflate with flush (could sometimes generate bad output) 16- fix deflate with flush (could sometimes generate bad output)
@@ -10,6 +20,7 @@ Changes in 0.94 (13 Aug 95)
10- gzflush now calls fflush 20- gzflush now calls fflush
11- For deflate with flush, flush even if no more input is provided. 21- For deflate with flush, flush even if no more input is provided.
12- rename libgz.a as libz.a 22- rename libgz.a as libz.a
23- avoid complex expression in infcodes.c triggering Turbo C bug
13- work around a problem with gcc on Alpha (in INSERT_STRING) 24- work around a problem with gcc on Alpha (in INSERT_STRING)
14- don't use inline functions (problem with some gcc versions) 25- don't use inline functions (problem with some gcc versions)
15- allow renaming of Byte, uInt, etc... with #define. 26- allow renaming of Byte, uInt, etc... with #define.
diff --git a/Makefile.bor b/Makefile.bor
index 3a823d0..536b76d 100644
--- a/Makefile.bor
+++ b/Makefile.bor
@@ -2,6 +2,7 @@
2# Borland C++ ************ UNTESTED *********** 2# Borland C++ ************ UNTESTED ***********
3 3
4# To use, do "make -fmakefile.bor" 4# To use, do "make -fmakefile.bor"
5# To compile in small model, set below: MODEL=-ms
5 6
6# WARNING: the small model is supported but only for small values of 7# WARNING: the small model is supported but only for small values of
7# MAX_WBITS and MAX_MEM_LEVEL. For example: 8# MAX_WBITS and MAX_MEM_LEVEL. For example:
diff --git a/Makefile.msc b/Makefile.msc
index 335a4e1..3b7aabd 100644
--- a/Makefile.msc
+++ b/Makefile.msc
@@ -2,6 +2,7 @@
2# Microsoft C 5.1 or later 2# Microsoft C 5.1 or later
3 3
4# To use, do "make makefile.msc" 4# To use, do "make makefile.msc"
5# To compile in small model, set below: MODEL=-AS
5 6
6# If you wish to reduce the memory requirements (default 256K for big 7# If you wish to reduce the memory requirements (default 256K for big
7# objects plus a few K), you can add to CFLAGS below: 8# objects plus a few K), you can add to CFLAGS below:
diff --git a/Makefile.tc b/Makefile.tc
index ceed87d..a46ce73 100644
--- a/Makefile.tc
+++ b/Makefile.tc
@@ -2,10 +2,11 @@
2# TurboC 2.0 2# TurboC 2.0
3 3
4# To use, do "make -fmakefile.tc" 4# To use, do "make -fmakefile.tc"
5# To compile in small model, set below: MODEL=-ms
5 6
6# WARNING: the small model is supported but only for small values of 7# WARNING: the small model is supported but only for small values of
7# MAX_WBITS and MAX_MEM_LEVEL. For example: 8# MAX_WBITS and MAX_MEM_LEVEL. For example:
8# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3 9# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
9# If you wish to reduce the memory requirements (default 256K for big 10# If you wish to reduce the memory requirements (default 256K for big
10# objects plus a few K), you can add to CFLAGS below: 11# objects plus a few K), you can add to CFLAGS below:
11# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 12# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
@@ -13,6 +14,7 @@
13 14
14# ------------- Turbo C 2.0 ------------- 15# ------------- Turbo C 2.0 -------------
15MODEL=-ml 16MODEL=-ml
17# CFLAGS=-O2 -G -Z $(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
16CFLAGS=-O2 -G -Z $(MODEL) 18CFLAGS=-O2 -G -Z $(MODEL)
17CC=tcc -I\tc\include 19CC=tcc -I\tc\include
18LD=tcc -L\tc\lib 20LD=tcc -L\tc\lib
diff --git a/README b/README
index 1cbd6be..1810978 100644
--- a/README
+++ b/README
@@ -1,6 +1,7 @@
1zlib 0.94 is a beta version of a general purpose compression library. 1zlib 0.95 is a beta version of a general purpose compression library.
2Unless new bugs are found it will be released again as the first official 2This should be the last version before the first official
3version (1.0). This version has no known bugs. 3version (1.0), so please test it now. (At least compile and run it with
4"make test"). This version has no known bugs.
4 5
5The data format used by the zlib library is described in the 6The data format used by the zlib library is described in the
6files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available 7files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available
@@ -8,31 +9,29 @@ in ftp.uu.net:/pub/archiving/zip/doc.
8 9
9All functions of the compression library are documented in the file 10All functions of the compression library are documented in the file
10zlib.h. A usage example of the library is given in the file example.c 11zlib.h. A usage example of the library is given in the file example.c
11which also tests that the library is working correctly. 12which also tests that the library is working correctly. Another
13example is given in the file minigzip.c.
12 14
13To compile all files and run the test program, just type: make test 15To compile all files and run the test program, just type: make test
14(For MSDOS, use one of the special makefiles such as Makefile.msc.) 16(For MSDOS, use one of the special makefiles such as Makefile.msc;
17for VMS, use Make_vms.com or descrip.mms.)
15To install the zlib library (libz.a) in /usr/local/lib, type: make install 18To install the zlib library (libz.a) in /usr/local/lib, type: make install
16To install in a different directory, use for example: 19To install in a different directory, use for example:
17 make install prefix=$HOME 20 make install prefix=$HOME
18This will install in $HOME/lib instead of /usr/local/lib. 21This will install in $HOME/lib instead of /usr/local/lib.
19 22
20The changes made in version 0.94 are documented in the file ChangeLog. 23The changes made in version 0.95 are documented in the file ChangeLog.
21The main changes since 0.93 are: 24The main changes since 0.94 are:
22- support MSDOS small and medium model 25- fix MSDOS small and medium model (now easier to adapt to any compiler)
23- fix deflate with flush (could sometimes generate bad output) 26- inlined send_bits
24- fix deflateReset (zlib header was incorrectly suppressed) 27- fix the final (:-) bug for deflate with flush (output was correct but
25- added support for VMS 28 not completely flushed in rare occasions).
26- allow a compression level in gzopen()
27- gzflush now calls fflush
28- For deflate with flush, flush even if no more input is provided.
29- rename libgz.a as libz.a
30 29
31For MSDOS, the small and medium models are supported only for Microsoft C. 30For MSDOS, the small and medium models have been tested only with Microsoft C.
32(It should be easy to support them for Borland C also, but I don't have 31(This should now work for Borland C also, but I don't have a recent Borland
33a recent Borland compiler to test with.) The small model currently works 32compiler to test with.) The small model was tested with Turbo C but only with
34for Turbo/Borland C but only with reduced performance to avoid any far 33reduced performance to avoid any far allocation; it was tested with
35allocation (tested with -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3). 34 -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
36 35
37 36
38 (C) 1995 Jean-loup Gailly and Mark Adler 37 (C) 1995 Jean-loup Gailly and Mark Adler
diff --git a/deflate.c b/deflate.c
index 70095e6..c531856 100644
--- a/deflate.c
+++ b/deflate.c
@@ -524,8 +524,8 @@ local int longest_match(s, cur_match)
524 * Try with and without -DUNALIGNED_OK to check. 524 * Try with and without -DUNALIGNED_OK to check.
525 */ 525 */
526 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; 526 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
527 register ush scan_start = *(ush*)scan; 527 register ush scan_start = *(ushf*)scan;
528 register ush scan_end = *(ush*)(scan+best_len-1); 528 register ush scan_end = *(ushf*)(scan+best_len-1);
529#else 529#else
530 register Bytef *strend = s->window + s->strstart + MAX_MATCH; 530 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
531 register Byte scan_end1 = scan[best_len-1]; 531 register Byte scan_end1 = scan[best_len-1];
@@ -554,8 +554,8 @@ local int longest_match(s, cur_match)
554 /* This code assumes sizeof(unsigned short) == 2. Do not use 554 /* This code assumes sizeof(unsigned short) == 2. Do not use
555 * UNALIGNED_OK if your compiler uses a different size. 555 * UNALIGNED_OK if your compiler uses a different size.
556 */ 556 */
557 if (*(ush*)(match+best_len-1) != scan_end || 557 if (*(ushf*)(match+best_len-1) != scan_end ||
558 *(ush*)match != scan_start) continue; 558 *(ushf*)match != scan_start) continue;
559 559
560 /* It is not necessary to compare scan[2] and match[2] since they are 560 /* It is not necessary to compare scan[2] and match[2] since they are
561 * always equal when the other bytes match, given that the hash keys 561 * always equal when the other bytes match, given that the hash keys
@@ -569,10 +569,10 @@ local int longest_match(s, cur_match)
569 Assert(scan[2] == match[2], "scan[2]?"); 569 Assert(scan[2] == match[2], "scan[2]?");
570 scan++, match++; 570 scan++, match++;
571 do { 571 do {
572 } while (*(ush*)(scan+=2) == *(ush*)(match+=2) && 572 } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
573 *(ush*)(scan+=2) == *(ush*)(match+=2) && 573 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
574 *(ush*)(scan+=2) == *(ush*)(match+=2) && 574 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
575 *(ush*)(scan+=2) == *(ush*)(match+=2) && 575 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
576 scan < strend); 576 scan < strend);
577 /* The funny "do {}" generates better code on most compilers */ 577 /* The funny "do {}" generates better code on most compilers */
578 578
@@ -621,7 +621,7 @@ local int longest_match(s, cur_match)
621 best_len = len; 621 best_len = len;
622 if (len >= s->nice_match) break; 622 if (len >= s->nice_match) break;
623#ifdef UNALIGNED_OK 623#ifdef UNALIGNED_OK
624 scan_end = *(ush*)(scan+best_len-1); 624 scan_end = *(ushf*)(scan+best_len-1);
625#else 625#else
626 scan_end1 = scan[best_len-1]; 626 scan_end1 = scan[best_len-1];
627 scan_end = scan[best_len]; 627 scan_end = scan[best_len];
diff --git a/deflate.h b/deflate.h
index eada3ba..f3b4c38 100644
--- a/deflate.h
+++ b/deflate.h
@@ -233,6 +233,7 @@ typedef struct internal_state {
233 ulg static_len; /* bit length of current block with static trees */ 233 ulg static_len; /* bit length of current block with static trees */
234 ulg compressed_len; /* total bit length of compressed file */ 234 ulg compressed_len; /* total bit length of compressed file */
235 uInt matches; /* number of string matches in current block */ 235 uInt matches; /* number of string matches in current block */
236 int last_eob_len; /* bit length of EOB code for last block */
236 237
237#ifdef DEBUG 238#ifdef DEBUG
238 ulg bits_sent; /* bit length of the compressed data */ 239 ulg bits_sent; /* bit length of the compressed data */
diff --git a/example.c b/example.c
index d362c7a..c18a583 100644
--- a/example.c
+++ b/example.c
@@ -277,7 +277,7 @@ int main(argc, argv)
277 fprintf(stderr, "incompatible zlib version\n"); 277 fprintf(stderr, "incompatible zlib version\n");
278 exit(1); 278 exit(1);
279 279
280 } else if (zstrcmp(zlib_version, ZLIB_VERSION) != 0) { 280 } else if (strcmp(zlib_version, ZLIB_VERSION) != 0) {
281 fprintf(stderr, "warning: different zlib version\n"); 281 fprintf(stderr, "warning: different zlib version\n");
282 } 282 }
283 test_compress(); 283 test_compress();
diff --git a/gzio.c b/gzio.c
index 1f0f9fc..cd932d3 100644
--- a/gzio.c
+++ b/gzio.c
@@ -234,7 +234,7 @@ gzFile gzdopen (fd, mode)
234*/ 234*/
235int gzread (file, buf, len) 235int gzread (file, buf, len)
236 gzFile file; 236 gzFile file;
237 voidnp buf; 237 voidp buf;
238 unsigned len; 238 unsigned len;
239{ 239{
240 gz_stream *s = (gz_stream*)file; 240 gz_stream *s = (gz_stream*)file;
@@ -292,7 +292,7 @@ int gzread (file, buf, len)
292*/ 292*/
293int gzwrite (file, buf, len) 293int gzwrite (file, buf, len)
294 gzFile file; 294 gzFile file;
295 voidnp buf; 295 voidp buf;
296 unsigned len; 296 unsigned len;
297{ 297{
298 gz_stream *s = (gz_stream*)file; 298 gz_stream *s = (gz_stream*)file;
diff --git a/inftrees.c b/inftrees.c
index 7a45e92..ab9d74f 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -25,14 +25,14 @@ local int huft_build OF((
25 uIntf *, /* maximum lookup bits (returns actual) */ 25 uIntf *, /* maximum lookup bits (returns actual) */
26 z_stream *)); /* for zalloc function */ 26 z_stream *)); /* for zalloc function */
27 27
28local voidp falloc OF(( 28local voidpf falloc OF((
29 voidp, /* opaque pointer (not used) */ 29 voidpf, /* opaque pointer (not used) */
30 uInt, /* number of items */ 30 uInt, /* number of items */
31 uInt)); /* size of item */ 31 uInt)); /* size of item */
32 32
33local void ffree OF(( 33local void ffree OF((
34 voidp q, /* opaque pointer (not used) */ 34 voidpf q, /* opaque pointer (not used) */
35 voidp p)); /* what to free (not used) */ 35 voidpf p)); /* what to free (not used) */
36 36
37/* Tables for deflate from PKZIP's appnote.txt. */ 37/* Tables for deflate from PKZIP's appnote.txt. */
38local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */ 38local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */
@@ -377,8 +377,8 @@ local inflate_huft *fixed_tl;
377local inflate_huft *fixed_td; 377local inflate_huft *fixed_td;
378 378
379 379
380local voidp falloc(q, n, s) 380local voidpf falloc(q, n, s)
381voidp q; /* opaque pointer (not used) */ 381voidpf q; /* opaque pointer (not used) */
382uInt n; /* number of items */ 382uInt n; /* number of items */
383uInt s; /* size of item */ 383uInt s; /* size of item */
384{ 384{
@@ -386,13 +386,13 @@ uInt s; /* size of item */
386 "inflate_trees falloc overflow"); 386 "inflate_trees falloc overflow");
387 if (q) s++; /* to make some compilers happy */ 387 if (q) s++; /* to make some compilers happy */
388 fixed_left -= n; 388 fixed_left -= n;
389 return (voidp)(fixed_mem + fixed_left); 389 return (voidpf)(fixed_mem + fixed_left);
390} 390}
391 391
392 392
393local void ffree(q, p) 393local void ffree(q, p)
394voidp q; 394voidpf q;
395voidp p; 395voidpf p;
396{ 396{
397 Assert(0, "inflate_trees ffree called!"); 397 Assert(0, "inflate_trees ffree called!");
398 if (q) q = p; /* to make some compilers happy */ 398 if (q) q = p; /* to make some compilers happy */
diff --git a/trees.c b/trees.c
index f6b97ff..4cb5454 100644
--- a/trees.c
+++ b/trees.c
@@ -143,9 +143,9 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
143local void compress_block OF((deflate_state *s, ct_data *ltree, 143local void compress_block OF((deflate_state *s, ct_data *ltree,
144 ct_data *dtree)); 144 ct_data *dtree));
145local void set_data_type OF((deflate_state *s)); 145local void set_data_type OF((deflate_state *s));
146local void send_bits OF((deflate_state *s, int value, int length));
147local unsigned bi_reverse OF((unsigned value, int length)); 146local unsigned bi_reverse OF((unsigned value, int length));
148local void bi_windup OF((deflate_state *s)); 147local void bi_windup OF((deflate_state *s));
148local void bi_flush OF((deflate_state *s));
149local void copy_block OF((deflate_state *s, charf *buf, unsigned len, 149local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
150 int header)); 150 int header));
151 151
@@ -166,6 +166,63 @@ local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
166 * used. 166 * used.
167 */ 167 */
168 168
169/* ===========================================================================
170 * Output a short LSB first on the stream.
171 * IN assertion: there is enough room in pendingBuf.
172 */
173#define put_short(s, w) { \
174 put_byte(s, (uch)((w) & 0xff)); \
175 put_byte(s, (uch)((ush)(w) >> 8)); \
176}
177
178/* ===========================================================================
179 * Send a value on a given number of bits.
180 * IN assertion: length <= 16 and value fits in length bits.
181 */
182#ifdef DEBUG
183local void send_bits OF((deflate_state *s, int value, int length));
184
185local void send_bits(s, value, length)
186 deflate_state *s;
187 int value; /* value to send */
188 int length; /* number of bits */
189{
190 Tracev((stderr," l %2d v %4x ", length, value));
191 Assert(length > 0 && length <= 15, "invalid length");
192 s->bits_sent += (ulg)length;
193
194 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
195 * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
196 * unused bits in value.
197 */
198 if (s->bi_valid > (int)Buf_size - length) {
199 s->bi_buf |= (value << s->bi_valid);
200 put_short(s, s->bi_buf);
201 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
202 s->bi_valid += length - Buf_size;
203 } else {
204 s->bi_buf |= value << s->bi_valid;
205 s->bi_valid += length;
206 }
207}
208#else /* !DEBUG */
209
210#define send_bits(s, value, length) \
211{ int len = length;\
212 if (s->bi_valid > (int)Buf_size - len) {\
213 int val = value;\
214 s->bi_buf |= (val << s->bi_valid);\
215 put_short(s, s->bi_buf);\
216 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
217 s->bi_valid += len - Buf_size;\
218 } else {\
219 s->bi_buf |= (value) << s->bi_valid;\
220 s->bi_valid += len;\
221 }\
222}
223#endif /* DEBUG */
224
225
169#define MAX(a,b) (a >= b ? a : b) 226#define MAX(a,b) (a >= b ? a : b)
170/* the arguments must not have side effects */ 227/* the arguments must not have side effects */
171 228
@@ -259,6 +316,7 @@ void ct_init(s)
259 316
260 s->bi_buf = 0; 317 s->bi_buf = 0;
261 s->bi_valid = 0; 318 s->bi_valid = 0;
319 s->last_eob_len = 8; /* enough lookahead for inflate */
262#ifdef DEBUG 320#ifdef DEBUG
263 s->bits_sent = 0L; 321 s->bits_sent = 0L;
264#endif 322#endif
@@ -739,7 +797,12 @@ void ct_stored_block(s, buf, stored_len, eof)
739} 797}
740 798
741/* =========================================================================== 799/* ===========================================================================
742 * Send one empty static block to give enough lookahead for inflate 800 * Send one empty static block to give enough lookahead for inflate.
801 * This takes 10 bits, of which 7 may remain in the bit buffer.
802 * The current inflate code requires 9 bits of lookahead. If the EOB
803 * code for the previous block was coded on 5 bits or less, inflate
804 * may have only 5+3 bits of lookahead to decode this EOB.
805 * (There are no problems if the previous block is stored or fixed.)
743 */ 806 */
744void ct_align(s) 807void ct_align(s)
745 deflate_state *s; 808 deflate_state *s;
@@ -747,6 +810,18 @@ void ct_align(s)
747 send_bits(s, STATIC_TREES<<1, 3); 810 send_bits(s, STATIC_TREES<<1, 3);
748 send_code(s, END_BLOCK, static_ltree); 811 send_code(s, END_BLOCK, static_ltree);
749 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ 812 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
813 bi_flush(s);
814 /* Of the 10 bits for the empty block, we have already sent
815 * (10 - bi_valid) bits. The lookahead for the EOB of the previous
816 * block was thus its length plus what we have just sent.
817 */
818 if (s->last_eob_len + 10 - s->bi_valid < 9) {
819 send_bits(s, STATIC_TREES<<1, 3);
820 send_code(s, END_BLOCK, static_ltree);
821 s->compressed_len += 10L;
822 bi_flush(s);
823 }
824 s->last_eob_len = 7;
750} 825}
751 826
752/* =========================================================================== 827/* ===========================================================================
@@ -950,6 +1025,7 @@ local void compress_block(s, ltree, dtree)
950 } while (lx < s->last_lit); 1025 } while (lx < s->last_lit);
951 1026
952 send_code(s, END_BLOCK, ltree); 1027 send_code(s, END_BLOCK, ltree);
1028 s->last_eob_len = ltree[END_BLOCK].Len;
953} 1029}
954 1030
955/* =========================================================================== 1031/* ===========================================================================
@@ -971,44 +1047,6 @@ local void set_data_type(s)
971} 1047}
972 1048
973/* =========================================================================== 1049/* ===========================================================================
974 * Output a short LSB first on the stream.
975 * IN assertion: there is enough room in pendingBuf.
976 */
977#define put_short(s, w) { \
978 put_byte(s, (uch)((w) & 0xff)); \
979 put_byte(s, (uch)((ush)(w) >> 8)); \
980}
981
982/* ===========================================================================
983 * Send a value on a given number of bits.
984 * IN assertion: length <= 16 and value fits in length bits.
985 */
986local void send_bits(s, value, length)
987 deflate_state *s;
988 int value; /* value to send */
989 int length; /* number of bits */
990{
991#ifdef DEBUG
992 Tracev((stderr," l %2d v %4x ", length, value));
993 Assert(length > 0 && length <= 15, "invalid length");
994 s->bits_sent += (ulg)length;
995#endif
996 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
997 * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
998 * unused bits in value.
999 */
1000 if (s->bi_valid > (int)Buf_size - length) {
1001 s->bi_buf |= (value << s->bi_valid);
1002 put_short(s, s->bi_buf);
1003 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
1004 s->bi_valid += length - Buf_size;
1005 } else {
1006 s->bi_buf |= value << s->bi_valid;
1007 s->bi_valid += length;
1008 }
1009}
1010
1011/* ===========================================================================
1012 * Reverse the first len bits of a code, using straightforward code (a faster 1050 * Reverse the first len bits of a code, using straightforward code (a faster
1013 * method would use a table) 1051 * method would use a table)
1014 * IN assertion: 1 <= len <= 15 1052 * IN assertion: 1 <= len <= 15
@@ -1026,7 +1064,24 @@ local unsigned bi_reverse(code, len)
1026} 1064}
1027 1065
1028/* =========================================================================== 1066/* ===========================================================================
1029 * Write out any remaining bits in an incomplete byte. 1067 * Flush the bit buffer, keeping at most 7 bits in it.
1068 */
1069local void bi_flush(s)
1070 deflate_state *s;
1071{
1072 if (s->bi_valid == 16) {
1073 put_short(s, s->bi_buf);
1074 s->bi_buf = 0;
1075 s->bi_valid = 0;
1076 } else if (s->bi_valid >= 8) {
1077 put_byte(s, (Byte)s->bi_buf);
1078 s->bi_buf >>= 8;
1079 s->bi_valid -= 8;
1080 }
1081}
1082
1083/* ===========================================================================
1084 * Flush the bit buffer and align the output on a byte boundary
1030 */ 1085 */
1031local void bi_windup(s) 1086local void bi_windup(s)
1032 deflate_state *s; 1087 deflate_state *s;
@@ -1053,7 +1108,8 @@ local void copy_block(s, buf, len, header)
1053 unsigned len; /* its length */ 1108 unsigned len; /* its length */
1054 int header; /* true if block header must be written */ 1109 int header; /* true if block header must be written */
1055{ 1110{
1056 bi_windup(s); /* align on byte boundary */ 1111 bi_windup(s); /* align on byte boundary */
1112 s->last_eob_len = 8; /* enough lookahead for inflate */
1057 1113
1058 if (header) { 1114 if (header) {
1059 put_short(s, (ush)len); 1115 put_short(s, (ush)len);
diff --git a/zconf.h b/zconf.h
index 92fdbbc..3898094 100644
--- a/zconf.h
+++ b/zconf.h
@@ -85,37 +85,42 @@
85# endif 85# endif
86#endif 86#endif
87 87
88#if defined(M_I86SM) || defined(M_I86MM) /* model independent MSC functions */ 88/* The following definitions for FAR are needed only for MSDOS mixed
89# define zstrcpy _fstrcpy 89 * model programming (small or medium model with some far allocations).
90# define zstrcat _fstrcat 90 * This was tested only with MSC; for other MSDOS compilers you may have
91# define zstrlen _fstrlen 91 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
92# define zstrcmp _fstrcmp 92 * just define FAR to be empty.
93# define FAR __far 93 */
94#else 94#if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */
95# define zstrcpy strcpy 95# ifdef _MSC_VER
96# define zstrcat strcat 96# define FAR __far
97# define zstrlen strlen 97# else
98# define zstrcmp strcmp 98# define FAR far
99# endif
100#endif
101#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
102# define FAR __far /* completely untested, just a best guess */
103#endif
104#ifndef FAR
99# define FAR 105# define FAR
100#endif 106#endif
101 107
102typedef unsigned char Byte; /* 8 bits */ 108typedef unsigned char Byte; /* 8 bits */
103typedef unsigned int uInt; /* 16 bits or more */ 109typedef unsigned int uInt; /* 16 bits or more */
104typedef unsigned long uLong; /* 32 bits or more */ 110typedef unsigned long uLong; /* 32 bits or more */
105 111
106typedef Byte FAR Bytef; 112typedef Byte FAR Bytef;
107typedef char FAR charf; 113typedef char FAR charf;
108typedef int FAR intf; 114typedef int FAR intf;
109typedef uInt FAR uIntf; 115typedef uInt FAR uIntf;
110typedef uLong FAR uLongf; 116typedef uLong FAR uLongf;
111 117
112#ifdef STDC 118#ifdef STDC
113 typedef void FAR *voidp; 119 typedef void FAR *voidpf;
114 typedef void *voidnp; 120 typedef void *voidp;
115#else 121#else
116 typedef Byte FAR *voidp; 122 typedef Byte FAR *voidpf;
117 typedef Byte *voidnp; 123 typedef Byte *voidp;
118#endif 124#endif
119 125
120#endif /* _ZCONF_H */ 126#endif /* _ZCONF_H */
121
diff --git a/zlib.h b/zlib.h
index 56ad7f7..73185ec 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.94, Aug 13th, 1995. 2 version 0.95, Aug 16th, 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.94" 31#define ZLIB_VERSION "0.95"
32 32
33/* 33/*
34 The 'zlib' compression library provides in-memory compression and 34 The 'zlib' compression library provides in-memory compression and
@@ -49,8 +49,8 @@
49 (providing more output space) before each call. 49 (providing more output space) before each call.
50*/ 50*/
51 51
52typedef voidp (*alloc_func) OF((voidp opaque, uInt items, uInt size)); 52typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
53typedef void (*free_func) OF((voidp opaque, voidp address)); 53typedef void (*free_func) OF((voidpf opaque, voidpf address));
54 54
55struct internal_state; 55struct internal_state;
56 56
@@ -510,7 +510,7 @@ extern int uncompress OF((Bytef *dest, uLongf *destLen,
510*/ 510*/
511 511
512 512
513typedef voidnp gzFile; 513typedef voidp gzFile;
514 514
515extern gzFile gzopen OF((char *path, char *mode)); 515extern gzFile gzopen OF((char *path, char *mode));
516/* 516/*
@@ -533,7 +533,7 @@ extern gzFile gzdopen OF((int fd, char *mode));
533 the (de)compression state. 533 the (de)compression state.
534*/ 534*/
535 535
536extern int gzread OF((gzFile file, voidnp buf, unsigned len)); 536extern int gzread OF((gzFile file, voidp buf, unsigned len));
537/* 537/*
538 Reads the given number of uncompressed bytes from the compressed file. 538 Reads the given number of uncompressed bytes from the compressed file.
539 If the input file was not in gzip format, gzread copies the given number 539 If the input file was not in gzip format, gzread copies the given number
@@ -541,7 +541,7 @@ extern int gzread OF((gzFile file, voidnp buf, unsigned len));
541 gzread returns the number of uncompressed bytes actually read (0 for 541 gzread returns the number of uncompressed bytes actually read (0 for
542 end of file, -1 for error). */ 542 end of file, -1 for error). */
543 543
544extern int gzwrite OF((gzFile file, voidnp buf, unsigned len)); 544extern int gzwrite OF((gzFile file, voidp buf, unsigned len));
545/* 545/*
546 Writes the given number of uncompressed bytes into the compressed file. 546 Writes the given number of uncompressed bytes into the compressed file.
547 gzwrite returns the number of uncompressed bytes actually written 547 gzwrite returns the number of uncompressed bytes actually written
diff --git a/zutil.c b/zutil.c
index 1dce6fb..67c4e54 100644
--- a/zutil.c
+++ b/zutil.c
@@ -38,8 +38,8 @@ void z_error (m)
38#ifndef HAVE_MEMCPY 38#ifndef HAVE_MEMCPY
39 39
40void zmemcpy(dest, source, len) 40void zmemcpy(dest, source, len)
41 Byte* dest; 41 Bytef* dest;
42 Byte* source; 42 Bytef* source;
43 uInt len; 43 uInt len;
44{ 44{
45 if (len == 0) return; 45 if (len == 0) return;
@@ -49,7 +49,7 @@ void zmemcpy(dest, source, len)
49} 49}
50 50
51void zmemzero(dest, len) 51void zmemzero(dest, len)
52 Byte* dest; 52 Bytef* dest;
53 uInt len; 53 uInt len;
54{ 54{
55 if (len == 0) return; 55 if (len == 0) return;
@@ -59,8 +59,10 @@ void zmemzero(dest, len)
59} 59}
60#endif 60#endif
61 61
62#if defined(__TURBOC__) && !defined(__SMALL__) 62#if defined( __TURBOC__) && !defined(__SMALL__) && !defined(__MEDIUM__)
63 63/* Small and medium model are for now limited to near allocation with
64 * reduced MAX_WBITS and MAX_MEM_LEVEL
65 */
64# define MY_ZCALLOC 66# define MY_ZCALLOC
65 67
66/* Turbo C malloc() does not allow dynamic allocation of 64K bytes 68/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
@@ -75,8 +77,8 @@ void zmemzero(dest, len)
75local int next_ptr = 0; 77local int next_ptr = 0;
76 78
77typedef struct ptr_table_s { 79typedef struct ptr_table_s {
78 voidp org_ptr; 80 voidpf org_ptr;
79 voidp new_ptr; 81 voidpf new_ptr;
80} ptr_table; 82} ptr_table;
81 83
82local ptr_table table[MAX_PTR]; 84local ptr_table table[MAX_PTR];
@@ -87,9 +89,9 @@ local ptr_table table[MAX_PTR];
87 * a protected system like OS/2. Use Microsoft C instead. 89 * a protected system like OS/2. Use Microsoft C instead.
88 */ 90 */
89 91
90voidp zcalloc (voidp opaque, unsigned items, unsigned size) 92voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
91{ 93{
92 voidp buf = opaque; /* just to make some compilers happy */ 94 voidpf buf = opaque; /* just to make some compilers happy */
93 ulg bsize = (ulg)items*size; 95 ulg bsize = (ulg)items*size;
94 96
95 if (bsize < 65536L) { 97 if (bsize < 65536L) {
@@ -108,7 +110,7 @@ voidp zcalloc (voidp opaque, unsigned items, unsigned size)
108 return buf; 110 return buf;
109} 111}
110 112
111void zcfree (voidp opaque, voidp ptr) 113void zcfree (voidpf opaque, voidpf ptr)
112{ 114{
113 int n; 115 int n;
114 if (*(ush*)&ptr != 0) { /* object < 64K */ 116 if (*(ush*)&ptr != 0) { /* object < 64K */
@@ -131,7 +133,8 @@ void zcfree (voidp opaque, voidp ptr)
131} 133}
132#endif /* __TURBOC__ */ 134#endif /* __TURBOC__ */
133 135
134#if defined(MSDOS) && !defined(__TURBOC__) /* MSC */ 136#if defined(M_I86SM)||defined(M_I86MM)||defined(M_I86CM)||defined(M_I86LM)
137/* Microsoft C */
135 138
136# define MY_ZCALLOC 139# define MY_ZCALLOC
137 140
@@ -140,13 +143,13 @@ void zcfree (voidp opaque, voidp ptr)
140# define _hfree hfree 143# define _hfree hfree
141#endif 144#endif
142 145
143voidp zcalloc (voidp opaque, unsigned items, unsigned size) 146voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
144{ 147{
145 if (opaque) opaque = 0; /* to make compiler happy */ 148 if (opaque) opaque = 0; /* to make compiler happy */
146 return _halloc((long)items, size); 149 return _halloc((long)items, size);
147} 150}
148 151
149void zcfree (voidp opaque, voidp ptr) 152void zcfree (voidpf opaque, voidpf ptr)
150{ 153{
151 if (opaque) opaque = 0; /* to make compiler happy */ 154 if (opaque) opaque = 0; /* to make compiler happy */
152 _hfree(ptr); 155 _hfree(ptr);
@@ -158,21 +161,21 @@ void zcfree (voidp opaque, voidp ptr)
158#ifndef MY_ZCALLOC /* Any system without a special alloc function */ 161#ifndef MY_ZCALLOC /* Any system without a special alloc function */
159 162
160#ifndef __GO32__ 163#ifndef __GO32__
161extern voidp calloc OF((uInt items, uInt size)); 164extern voidp calloc OF((uInt items, uInt size));
162extern void free OF((voidp ptr)); 165extern void free OF((voidpf ptr));
163#endif 166#endif
164 167
165voidp zcalloc (opaque, items, size) 168voidpf zcalloc (opaque, items, size)
166 voidp opaque; 169 voidpf opaque;
167 unsigned items; 170 unsigned items;
168 unsigned size; 171 unsigned size;
169{ 172{
170 return calloc(items, size); 173 return (voidpf)calloc(items, size);
171} 174}
172 175
173void zcfree (opaque, ptr) 176void zcfree (opaque, ptr)
174 voidp opaque; 177 voidpf opaque;
175 voidp ptr; 178 voidpf ptr;
176{ 179{
177 free(ptr); 180 free(ptr);
178} 181}
diff --git a/zutil.h b/zutil.h
index 053eb8c..4d1b59e 100644
--- a/zutil.h
+++ b/zutil.h
@@ -46,7 +46,7 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
46#define DEFLATED 8 46#define DEFLATED 8
47 47
48#ifndef DEF_WBITS 48#ifndef DEF_WBITS
49# define DEF_WBITS 15 49# define DEF_WBITS MAX_WBITS
50#endif 50#endif
51/* default windowBits for decompression. MAX_WBITS is for compression only */ 51/* default windowBits for decompression. MAX_WBITS is for compression only */
52 52
@@ -72,7 +72,7 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
72# define OS_CODE 0x00 72# define OS_CODE 0x00
73# ifdef __TURBOC__ 73# ifdef __TURBOC__
74# include <alloc.h> 74# include <alloc.h>
75# else /* MSC */ 75# else /* MSC or DJGPP */
76# include <malloc.h> 76# include <malloc.h>
77# endif 77# endif
78#endif 78#endif
@@ -130,23 +130,29 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
130# define zstrerror(errnum) "" 130# define zstrerror(errnum) ""
131#endif 131#endif
132 132
133#if defined(pyr) && !defined(NO_MEMCPY) 133#if defined(pyr)
134# define NO_MEMCPY
135#endif
136#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER)
137 /* Use our own functions for small and medium model with MSC <= 5.0.
138 * You may have to use the same strategy for Borland C (untested).
139 */
134# define NO_MEMCPY 140# define NO_MEMCPY
135#endif 141#endif
136#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 142#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
137# define HAVE_MEMCPY 143# define HAVE_MEMCPY
138#endif 144#endif
139#ifdef HAVE_MEMCPY 145#ifdef HAVE_MEMCPY
140# ifdef M_I86MM /* MSC medium model */ 146# if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */
141# define zmemcpy _fmemcpy 147# define zmemcpy _fmemcpy
142# define zmemzero(dest, len) _fmemset(dest, 0, len) 148# define zmemzero(dest, len) _fmemset(dest, 0, len)
143# else 149# else
144# define zmemcpy memcpy 150# define zmemcpy memcpy
145# define zmemzero(dest, len) memset(dest, 0, len) 151# define zmemzero(dest, len) memset(dest, 0, len)
146# endif 152# endif
147#else 153#else
148 extern void zmemcpy OF((Byte* dest, Byte* source, uInt len)); 154 extern void zmemcpy OF((Bytef* dest, Bytef* source, uInt len));
149 extern void zmemzero OF((Byte* dest, uInt len)); 155 extern void zmemzero OF((Bytef* dest, uInt len));
150#endif 156#endif
151 157
152/* Diagnostic functions */ 158/* Diagnostic functions */
@@ -175,12 +181,12 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
175 181
176extern void z_error OF((char *m)); 182extern void z_error OF((char *m));
177 183
178voidp zcalloc OF((voidp opaque, unsigned items, unsigned size)); 184voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
179void zcfree OF((voidp opaque, voidp ptr)); 185void zcfree OF((voidpf opaque, voidpf ptr));
180 186
181#define ZALLOC(strm, items, size) \ 187#define ZALLOC(strm, items, size) \
182 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 188 (*((strm)->zalloc))((strm)->opaque, (items), (size))
183#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidp)(addr)) 189#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
184#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 190#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
185 191
186#endif /* _Z_UTIL_H */ 192#endif /* _Z_UTIL_H */