diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:10:21 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:10:21 -0700 |
| commit | 25e5325501edade156e897f95afdaa2be78ad9a3 (patch) | |
| tree | 82687eec194357f9f94f6f137697ffd7a600c1cf | |
| parent | 23c69f10698301ae97709eb0bbfb371d66b99a08 (diff) | |
| download | zlib-25e5325501edade156e897f95afdaa2be78ad9a3.tar.gz zlib-25e5325501edade156e897f95afdaa2be78ad9a3.tar.bz2 zlib-25e5325501edade156e897f95afdaa2be78ad9a3.zip | |
zlib 0.95v0.95
Diffstat (limited to '')
| -rw-r--r-- | ChangeLog | 11 | ||||
| -rw-r--r-- | Makefile.bor | 1 | ||||
| -rw-r--r-- | Makefile.msc | 1 | ||||
| -rw-r--r-- | Makefile.tc | 4 | ||||
| -rw-r--r-- | README | 39 | ||||
| -rw-r--r-- | deflate.c | 18 | ||||
| -rw-r--r-- | deflate.h | 1 | ||||
| -rw-r--r-- | example.c | 2 | ||||
| -rw-r--r-- | gzio.c | 4 | ||||
| -rw-r--r-- | inftrees.c | 18 | ||||
| -rw-r--r-- | trees.c | 140 | ||||
| -rw-r--r-- | zconf.h | 43 | ||||
| -rw-r--r-- | zlib.h | 14 | ||||
| -rw-r--r-- | zutil.c | 43 | ||||
| -rw-r--r-- | zutil.h | 26 |
15 files changed, 225 insertions, 140 deletions
| @@ -1,6 +1,16 @@ | |||
| 1 | 1 | ||
| 2 | ChangeLog file for zlib | 2 | ChangeLog file for zlib |
| 3 | 3 | ||
| 4 | Changes 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 | |||
| 4 | Changes in 0.94 (13 Aug 95) | 14 | Changes 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 ------------- |
| 15 | MODEL=-ml | 16 | MODEL=-ml |
| 17 | # CFLAGS=-O2 -G -Z $(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 | ||
| 16 | CFLAGS=-O2 -G -Z $(MODEL) | 18 | CFLAGS=-O2 -G -Z $(MODEL) |
| 17 | CC=tcc -I\tc\include | 19 | CC=tcc -I\tc\include |
| 18 | LD=tcc -L\tc\lib | 20 | LD=tcc -L\tc\lib |
| @@ -1,6 +1,7 @@ | |||
| 1 | zlib 0.94 is a beta version of a general purpose compression library. | 1 | zlib 0.95 is a beta version of a general purpose compression library. |
| 2 | Unless new bugs are found it will be released again as the first official | 2 | This should be the last version before the first official |
| 3 | version (1.0). This version has no known bugs. | 3 | version (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 | ||
| 5 | The data format used by the zlib library is described in the | 6 | The data format used by the zlib library is described in the |
| 6 | files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available | 7 | files 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 | ||
| 9 | All functions of the compression library are documented in the file | 10 | All functions of the compression library are documented in the file |
| 10 | zlib.h. A usage example of the library is given in the file example.c | 11 | zlib.h. A usage example of the library is given in the file example.c |
| 11 | which also tests that the library is working correctly. | 12 | which also tests that the library is working correctly. Another |
| 13 | example is given in the file minigzip.c. | ||
| 12 | 14 | ||
| 13 | To compile all files and run the test program, just type: make test | 15 | To 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; |
| 17 | for VMS, use Make_vms.com or descrip.mms.) | ||
| 15 | To install the zlib library (libz.a) in /usr/local/lib, type: make install | 18 | To install the zlib library (libz.a) in /usr/local/lib, type: make install |
| 16 | To install in a different directory, use for example: | 19 | To install in a different directory, use for example: |
| 17 | make install prefix=$HOME | 20 | make install prefix=$HOME |
| 18 | This will install in $HOME/lib instead of /usr/local/lib. | 21 | This will install in $HOME/lib instead of /usr/local/lib. |
| 19 | 22 | ||
| 20 | The changes made in version 0.94 are documented in the file ChangeLog. | 23 | The changes made in version 0.95 are documented in the file ChangeLog. |
| 21 | The main changes since 0.93 are: | 24 | The 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 | ||
| 31 | For MSDOS, the small and medium models are supported only for Microsoft C. | 30 | For 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 |
| 33 | a recent Borland compiler to test with.) The small model currently works | 32 | compiler to test with.) The small model was tested with Turbo C but only with |
| 34 | for Turbo/Borland C but only with reduced performance to avoid any far | 33 | reduced performance to avoid any far allocation; it was tested with |
| 35 | allocation (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 |
| @@ -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]; |
| @@ -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 */ |
| @@ -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(); |
| @@ -234,7 +234,7 @@ gzFile gzdopen (fd, mode) | |||
| 234 | */ | 234 | */ |
| 235 | int gzread (file, buf, len) | 235 | int 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 | */ |
| 293 | int gzwrite (file, buf, len) | 293 | int 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; |
| @@ -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 | ||
| 28 | local voidp falloc OF(( | 28 | local 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 | ||
| 33 | local void ffree OF(( | 33 | local 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. */ |
| 38 | local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */ | 38 | local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */ |
| @@ -377,8 +377,8 @@ local inflate_huft *fixed_tl; | |||
| 377 | local inflate_huft *fixed_td; | 377 | local inflate_huft *fixed_td; |
| 378 | 378 | ||
| 379 | 379 | ||
| 380 | local voidp falloc(q, n, s) | 380 | local voidpf falloc(q, n, s) |
| 381 | voidp q; /* opaque pointer (not used) */ | 381 | voidpf q; /* opaque pointer (not used) */ |
| 382 | uInt n; /* number of items */ | 382 | uInt n; /* number of items */ |
| 383 | uInt s; /* size of item */ | 383 | uInt 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 | ||
| 393 | local void ffree(q, p) | 393 | local void ffree(q, p) |
| 394 | voidp q; | 394 | voidpf q; |
| 395 | voidp p; | 395 | voidpf 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 */ |
| @@ -143,9 +143,9 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, | |||
| 143 | local void compress_block OF((deflate_state *s, ct_data *ltree, | 143 | local void compress_block OF((deflate_state *s, ct_data *ltree, |
| 144 | ct_data *dtree)); | 144 | ct_data *dtree)); |
| 145 | local void set_data_type OF((deflate_state *s)); | 145 | local void set_data_type OF((deflate_state *s)); |
| 146 | local void send_bits OF((deflate_state *s, int value, int length)); | ||
| 147 | local unsigned bi_reverse OF((unsigned value, int length)); | 146 | local unsigned bi_reverse OF((unsigned value, int length)); |
| 148 | local void bi_windup OF((deflate_state *s)); | 147 | local void bi_windup OF((deflate_state *s)); |
| 148 | local void bi_flush OF((deflate_state *s)); | ||
| 149 | local void copy_block OF((deflate_state *s, charf *buf, unsigned len, | 149 | local 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 | ||
| 183 | local void send_bits OF((deflate_state *s, int value, int length)); | ||
| 184 | |||
| 185 | local 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 | */ |
| 744 | void ct_align(s) | 807 | void 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 | */ | ||
| 986 | local 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 | */ | ||
| 1069 | local 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 | */ |
| 1031 | local void bi_windup(s) | 1086 | local 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); |
| @@ -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 | ||
| 102 | typedef unsigned char Byte; /* 8 bits */ | 108 | typedef unsigned char Byte; /* 8 bits */ |
| 103 | typedef unsigned int uInt; /* 16 bits or more */ | 109 | typedef unsigned int uInt; /* 16 bits or more */ |
| 104 | typedef unsigned long uLong; /* 32 bits or more */ | 110 | typedef unsigned long uLong; /* 32 bits or more */ |
| 105 | 111 | ||
| 106 | typedef Byte FAR Bytef; | 112 | typedef Byte FAR Bytef; |
| 107 | typedef char FAR charf; | 113 | typedef char FAR charf; |
| 108 | typedef int FAR intf; | 114 | typedef int FAR intf; |
| 109 | typedef uInt FAR uIntf; | 115 | typedef uInt FAR uIntf; |
| 110 | typedef uLong FAR uLongf; | 116 | typedef 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 | |||
| @@ -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 | ||
| 52 | typedef voidp (*alloc_func) OF((voidp opaque, uInt items, uInt size)); | 52 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
| 53 | typedef void (*free_func) OF((voidp opaque, voidp address)); | 53 | typedef void (*free_func) OF((voidpf opaque, voidpf address)); |
| 54 | 54 | ||
| 55 | struct internal_state; | 55 | struct internal_state; |
| 56 | 56 | ||
| @@ -510,7 +510,7 @@ extern int uncompress OF((Bytef *dest, uLongf *destLen, | |||
| 510 | */ | 510 | */ |
| 511 | 511 | ||
| 512 | 512 | ||
| 513 | typedef voidnp gzFile; | 513 | typedef voidp gzFile; |
| 514 | 514 | ||
| 515 | extern gzFile gzopen OF((char *path, char *mode)); | 515 | extern 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 | ||
| 536 | extern int gzread OF((gzFile file, voidnp buf, unsigned len)); | 536 | extern 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 | ||
| 544 | extern int gzwrite OF((gzFile file, voidnp buf, unsigned len)); | 544 | extern 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 |
| @@ -38,8 +38,8 @@ void z_error (m) | |||
| 38 | #ifndef HAVE_MEMCPY | 38 | #ifndef HAVE_MEMCPY |
| 39 | 39 | ||
| 40 | void zmemcpy(dest, source, len) | 40 | void 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 | ||
| 51 | void zmemzero(dest, len) | 51 | void 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) | |||
| 75 | local int next_ptr = 0; | 77 | local int next_ptr = 0; |
| 76 | 78 | ||
| 77 | typedef struct ptr_table_s { | 79 | typedef 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 | ||
| 82 | local ptr_table table[MAX_PTR]; | 84 | local 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 | ||
| 90 | voidp zcalloc (voidp opaque, unsigned items, unsigned size) | 92 | voidpf 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 | ||
| 111 | void zcfree (voidp opaque, voidp ptr) | 113 | void 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 | ||
| 143 | voidp zcalloc (voidp opaque, unsigned items, unsigned size) | 146 | voidpf 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 | ||
| 149 | void zcfree (voidp opaque, voidp ptr) | 152 | void 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__ |
| 161 | extern voidp calloc OF((uInt items, uInt size)); | 164 | extern voidp calloc OF((uInt items, uInt size)); |
| 162 | extern void free OF((voidp ptr)); | 165 | extern void free OF((voidpf ptr)); |
| 163 | #endif | 166 | #endif |
| 164 | 167 | ||
| 165 | voidp zcalloc (opaque, items, size) | 168 | voidpf 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 | ||
| 173 | void zcfree (opaque, ptr) | 176 | void 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 | } |
| @@ -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 | ||
| 176 | extern void z_error OF((char *m)); | 182 | extern void z_error OF((char *m)); |
| 177 | 183 | ||
| 178 | voidp zcalloc OF((voidp opaque, unsigned items, unsigned size)); | 184 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); |
| 179 | void zcfree OF((voidp opaque, voidp ptr)); | 185 | void 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 */ |
