Compare commits

..

1 Commits
v0.94 ... v0.95

Author SHA1 Message Date
Mark Adler
25e5325501 zlib 0.95 2011-09-09 23:10:21 -07:00
15 changed files with 225 additions and 140 deletions

View File

@@ -1,6 +1,16 @@
ChangeLog file for zlib ChangeLog file for zlib
Changes in 0.95 (16 Aug 95)
- fix MSDOS small and medium model (now easier to adapt to any compiler)
- inlined send_bits
- fix the final (:-) bug for deflate with flush (output was correct but
not completely flushed in rare occasions).
- default window size is same for compression and decompression
(it's now sufficient to set MAX_WBITS in zconf.h).
- voidp -> voidpf and voidnp -> voidp (for consistency with other
typedefs and because voidnp was not near in large model).
Changes in 0.94 (13 Aug 95) Changes in 0.94 (13 Aug 95)
- support MSDOS medium model - support MSDOS medium model
- fix deflate with flush (could sometimes generate bad output) - fix deflate with flush (could sometimes generate bad output)
@@ -10,6 +20,7 @@ Changes in 0.94 (13 Aug 95)
- gzflush now calls fflush - gzflush now calls fflush
- For deflate with flush, flush even if no more input is provided. - For deflate with flush, flush even if no more input is provided.
- rename libgz.a as libz.a - rename libgz.a as libz.a
- avoid complex expression in infcodes.c triggering Turbo C bug
- work around a problem with gcc on Alpha (in INSERT_STRING) - work around a problem with gcc on Alpha (in INSERT_STRING)
- don't use inline functions (problem with some gcc versions) - don't use inline functions (problem with some gcc versions)
- allow renaming of Byte, uInt, etc... with #define. - allow renaming of Byte, uInt, etc... with #define.

View File

@@ -2,6 +2,7 @@
# Borland C++ ************ UNTESTED *********** # Borland C++ ************ UNTESTED ***********
# To use, do "make -fmakefile.bor" # To use, do "make -fmakefile.bor"
# To compile in small model, set below: MODEL=-ms
# WARNING: the small model is supported but only for small values of # WARNING: the small model is supported but only for small values of
# MAX_WBITS and MAX_MEM_LEVEL. For example: # MAX_WBITS and MAX_MEM_LEVEL. For example:

View File

@@ -2,6 +2,7 @@
# Microsoft C 5.1 or later # Microsoft C 5.1 or later
# To use, do "make makefile.msc" # To use, do "make makefile.msc"
# To compile in small model, set below: MODEL=-AS
# If you wish to reduce the memory requirements (default 256K for big # If you wish to reduce the memory requirements (default 256K for big
# objects plus a few K), you can add to CFLAGS below: # objects plus a few K), you can add to CFLAGS below:

View File

@@ -2,10 +2,11 @@
# TurboC 2.0 # TurboC 2.0
# To use, do "make -fmakefile.tc" # To use, do "make -fmakefile.tc"
# To compile in small model, set below: MODEL=-ms
# WARNING: the small model is supported but only for small values of # WARNING: the small model is supported but only for small values of
# MAX_WBITS and MAX_MEM_LEVEL. For example: # MAX_WBITS and MAX_MEM_LEVEL. For example:
# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3 # -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
# If you wish to reduce the memory requirements (default 256K for big # If you wish to reduce the memory requirements (default 256K for big
# objects plus a few K), you can add to CFLAGS below: # objects plus a few K), you can add to CFLAGS below:
# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 # -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
@@ -13,6 +14,7 @@
# ------------- Turbo C 2.0 ------------- # ------------- Turbo C 2.0 -------------
MODEL=-ml MODEL=-ml
# CFLAGS=-O2 -G -Z $(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
CFLAGS=-O2 -G -Z $(MODEL) CFLAGS=-O2 -G -Z $(MODEL)
CC=tcc -I\tc\include CC=tcc -I\tc\include
LD=tcc -L\tc\lib LD=tcc -L\tc\lib

39
README
View File

@@ -1,6 +1,7 @@
zlib 0.94 is a beta version of a general purpose compression library. zlib 0.95 is a beta version of a general purpose compression library.
Unless new bugs are found it will be released again as the first official This should be the last version before the first official
version (1.0). This version has no known bugs. version (1.0), so please test it now. (At least compile and run it with
"make test"). This version has no known bugs.
The data format used by the zlib library is described in the The data format used by the zlib library is described in the
files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available 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.
All functions of the compression library are documented in the file All functions of the compression library are documented in the file
zlib.h. A usage example of the library is given in the file example.c zlib.h. A usage example of the library is given in the file example.c
which also tests that the library is working correctly. which also tests that the library is working correctly. Another
example is given in the file minigzip.c.
To compile all files and run the test program, just type: make test To compile all files and run the test program, just type: make test
(For MSDOS, use one of the special makefiles such as Makefile.msc.) (For MSDOS, use one of the special makefiles such as Makefile.msc;
for VMS, use Make_vms.com or descrip.mms.)
To install the zlib library (libz.a) in /usr/local/lib, type: make install To install the zlib library (libz.a) in /usr/local/lib, type: make install
To install in a different directory, use for example: To install in a different directory, use for example:
make install prefix=$HOME make install prefix=$HOME
This will install in $HOME/lib instead of /usr/local/lib. This will install in $HOME/lib instead of /usr/local/lib.
The changes made in version 0.94 are documented in the file ChangeLog. The changes made in version 0.95 are documented in the file ChangeLog.
The main changes since 0.93 are: The main changes since 0.94 are:
- support MSDOS small and medium model - fix MSDOS small and medium model (now easier to adapt to any compiler)
- fix deflate with flush (could sometimes generate bad output) - inlined send_bits
- fix deflateReset (zlib header was incorrectly suppressed) - fix the final (:-) bug for deflate with flush (output was correct but
- added support for VMS not completely flushed in rare occasions).
- allow a compression level in gzopen()
- gzflush now calls fflush
- For deflate with flush, flush even if no more input is provided.
- rename libgz.a as libz.a
For MSDOS, the small and medium models are supported only for Microsoft C. For MSDOS, the small and medium models have been tested only with Microsoft C.
(It should be easy to support them for Borland C also, but I don't have (This should now work for Borland C also, but I don't have a recent Borland
a recent Borland compiler to test with.) The small model currently works compiler to test with.) The small model was tested with Turbo C but only with
for Turbo/Borland C but only with reduced performance to avoid any far reduced performance to avoid any far allocation; it was tested with
allocation (tested with -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3). -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
(C) 1995 Jean-loup Gailly and Mark Adler (C) 1995 Jean-loup Gailly and Mark Adler

View File

@@ -524,8 +524,8 @@ local int longest_match(s, cur_match)
* Try with and without -DUNALIGNED_OK to check. * Try with and without -DUNALIGNED_OK to check.
*/ */
register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
register ush scan_start = *(ush*)scan; register ush scan_start = *(ushf*)scan;
register ush scan_end = *(ush*)(scan+best_len-1); register ush scan_end = *(ushf*)(scan+best_len-1);
#else #else
register Bytef *strend = s->window + s->strstart + MAX_MATCH; register Bytef *strend = s->window + s->strstart + MAX_MATCH;
register Byte scan_end1 = scan[best_len-1]; register Byte scan_end1 = scan[best_len-1];
@@ -554,8 +554,8 @@ local int longest_match(s, cur_match)
/* This code assumes sizeof(unsigned short) == 2. Do not use /* This code assumes sizeof(unsigned short) == 2. Do not use
* UNALIGNED_OK if your compiler uses a different size. * UNALIGNED_OK if your compiler uses a different size.
*/ */
if (*(ush*)(match+best_len-1) != scan_end || if (*(ushf*)(match+best_len-1) != scan_end ||
*(ush*)match != scan_start) continue; *(ushf*)match != scan_start) continue;
/* It is not necessary to compare scan[2] and match[2] since they are /* It is not necessary to compare scan[2] and match[2] since they are
* always equal when the other bytes match, given that the hash keys * always equal when the other bytes match, given that the hash keys
@@ -569,10 +569,10 @@ local int longest_match(s, cur_match)
Assert(scan[2] == match[2], "scan[2]?"); Assert(scan[2] == match[2], "scan[2]?");
scan++, match++; scan++, match++;
do { do {
} while (*(ush*)(scan+=2) == *(ush*)(match+=2) && } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
*(ush*)(scan+=2) == *(ush*)(match+=2) && *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
*(ush*)(scan+=2) == *(ush*)(match+=2) && *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
*(ush*)(scan+=2) == *(ush*)(match+=2) && *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
scan < strend); scan < strend);
/* The funny "do {}" generates better code on most compilers */ /* The funny "do {}" generates better code on most compilers */
@@ -621,7 +621,7 @@ local int longest_match(s, cur_match)
best_len = len; best_len = len;
if (len >= s->nice_match) break; if (len >= s->nice_match) break;
#ifdef UNALIGNED_OK #ifdef UNALIGNED_OK
scan_end = *(ush*)(scan+best_len-1); scan_end = *(ushf*)(scan+best_len-1);
#else #else
scan_end1 = scan[best_len-1]; scan_end1 = scan[best_len-1];
scan_end = scan[best_len]; scan_end = scan[best_len];

View File

@@ -233,6 +233,7 @@ typedef struct internal_state {
ulg static_len; /* bit length of current block with static trees */ ulg static_len; /* bit length of current block with static trees */
ulg compressed_len; /* total bit length of compressed file */ ulg compressed_len; /* total bit length of compressed file */
uInt matches; /* number of string matches in current block */ uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
#ifdef DEBUG #ifdef DEBUG
ulg bits_sent; /* bit length of the compressed data */ ulg bits_sent; /* bit length of the compressed data */

View File

@@ -277,7 +277,7 @@ int main(argc, argv)
fprintf(stderr, "incompatible zlib version\n"); fprintf(stderr, "incompatible zlib version\n");
exit(1); exit(1);
} else if (zstrcmp(zlib_version, ZLIB_VERSION) != 0) { } else if (strcmp(zlib_version, ZLIB_VERSION) != 0) {
fprintf(stderr, "warning: different zlib version\n"); fprintf(stderr, "warning: different zlib version\n");
} }
test_compress(); test_compress();

4
gzio.c
View File

@@ -234,7 +234,7 @@ gzFile gzdopen (fd, mode)
*/ */
int gzread (file, buf, len) int gzread (file, buf, len)
gzFile file; gzFile file;
voidnp buf; voidp buf;
unsigned len; unsigned len;
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;
@@ -292,7 +292,7 @@ int gzread (file, buf, len)
*/ */
int gzwrite (file, buf, len) int gzwrite (file, buf, len)
gzFile file; gzFile file;
voidnp buf; voidp buf;
unsigned len; unsigned len;
{ {
gz_stream *s = (gz_stream*)file; gz_stream *s = (gz_stream*)file;

View File

@@ -25,14 +25,14 @@ local int huft_build OF((
uIntf *, /* maximum lookup bits (returns actual) */ uIntf *, /* maximum lookup bits (returns actual) */
z_stream *)); /* for zalloc function */ z_stream *)); /* for zalloc function */
local voidp falloc OF(( local voidpf falloc OF((
voidp, /* opaque pointer (not used) */ voidpf, /* opaque pointer (not used) */
uInt, /* number of items */ uInt, /* number of items */
uInt)); /* size of item */ uInt)); /* size of item */
local void ffree OF(( local void ffree OF((
voidp q, /* opaque pointer (not used) */ voidpf q, /* opaque pointer (not used) */
voidp p)); /* what to free (not used) */ voidpf p)); /* what to free (not used) */
/* Tables for deflate from PKZIP's appnote.txt. */ /* Tables for deflate from PKZIP's appnote.txt. */
local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */ local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */
@@ -377,8 +377,8 @@ local inflate_huft *fixed_tl;
local inflate_huft *fixed_td; local inflate_huft *fixed_td;
local voidp falloc(q, n, s) local voidpf falloc(q, n, s)
voidp q; /* opaque pointer (not used) */ voidpf q; /* opaque pointer (not used) */
uInt n; /* number of items */ uInt n; /* number of items */
uInt s; /* size of item */ uInt s; /* size of item */
{ {
@@ -386,13 +386,13 @@ uInt s; /* size of item */
"inflate_trees falloc overflow"); "inflate_trees falloc overflow");
if (q) s++; /* to make some compilers happy */ if (q) s++; /* to make some compilers happy */
fixed_left -= n; fixed_left -= n;
return (voidp)(fixed_mem + fixed_left); return (voidpf)(fixed_mem + fixed_left);
} }
local void ffree(q, p) local void ffree(q, p)
voidp q; voidpf q;
voidp p; voidpf p;
{ {
Assert(0, "inflate_trees ffree called!"); Assert(0, "inflate_trees ffree called!");
if (q) q = p; /* to make some compilers happy */ if (q) q = p; /* to make some compilers happy */

138
trees.c
View File

@@ -143,9 +143,9 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
local void compress_block OF((deflate_state *s, ct_data *ltree, local void compress_block OF((deflate_state *s, ct_data *ltree,
ct_data *dtree)); ct_data *dtree));
local void set_data_type OF((deflate_state *s)); local void set_data_type OF((deflate_state *s));
local void send_bits OF((deflate_state *s, int value, int length));
local unsigned bi_reverse OF((unsigned value, int length)); local unsigned bi_reverse OF((unsigned value, int length));
local void bi_windup OF((deflate_state *s)); local void bi_windup OF((deflate_state *s));
local void bi_flush OF((deflate_state *s));
local void copy_block OF((deflate_state *s, charf *buf, unsigned len, local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
int header)); int header));
@@ -166,6 +166,63 @@ local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
* used. * used.
*/ */
/* ===========================================================================
* Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf.
*/
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
/* ===========================================================================
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
#ifdef DEBUG
local void send_bits OF((deflate_state *s, int value, int length));
local void send_bits(s, value, length)
deflate_state *s;
int value; /* value to send */
int length; /* number of bits */
{
Tracev((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length;
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
* unused bits in value.
*/
if (s->bi_valid > (int)Buf_size - length) {
s->bi_buf |= (value << s->bi_valid);
put_short(s, s->bi_buf);
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
s->bi_valid += length - Buf_size;
} else {
s->bi_buf |= value << s->bi_valid;
s->bi_valid += length;
}
}
#else /* !DEBUG */
#define send_bits(s, value, length) \
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
int val = value;\
s->bi_buf |= (val << s->bi_valid);\
put_short(s, s->bi_buf);\
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
s->bi_valid += len - Buf_size;\
} else {\
s->bi_buf |= (value) << s->bi_valid;\
s->bi_valid += len;\
}\
}
#endif /* DEBUG */
#define MAX(a,b) (a >= b ? a : b) #define MAX(a,b) (a >= b ? a : b)
/* the arguments must not have side effects */ /* the arguments must not have side effects */
@@ -259,6 +316,7 @@ void ct_init(s)
s->bi_buf = 0; s->bi_buf = 0;
s->bi_valid = 0; s->bi_valid = 0;
s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG #ifdef DEBUG
s->bits_sent = 0L; s->bits_sent = 0L;
#endif #endif
@@ -739,7 +797,12 @@ void ct_stored_block(s, buf, stored_len, eof)
} }
/* =========================================================================== /* ===========================================================================
* Send one empty static block to give enough lookahead for inflate * Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer.
* The current inflate code requires 9 bits of lookahead. If the EOB
* code for the previous block was coded on 5 bits or less, inflate
* may have only 5+3 bits of lookahead to decode this EOB.
* (There are no problems if the previous block is stored or fixed.)
*/ */
void ct_align(s) void ct_align(s)
deflate_state *s; deflate_state *s;
@@ -747,6 +810,18 @@ void ct_align(s)
send_bits(s, STATIC_TREES<<1, 3); send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree); send_code(s, END_BLOCK, static_ltree);
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
bi_flush(s);
/* Of the 10 bits for the empty block, we have already sent
* (10 - bi_valid) bits. The lookahead for the EOB of the previous
* block was thus its length plus what we have just sent.
*/
if (s->last_eob_len + 10 - s->bi_valid < 9) {
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
s->compressed_len += 10L;
bi_flush(s);
}
s->last_eob_len = 7;
} }
/* =========================================================================== /* ===========================================================================
@@ -950,6 +1025,7 @@ local void compress_block(s, ltree, dtree)
} while (lx < s->last_lit); } while (lx < s->last_lit);
send_code(s, END_BLOCK, ltree); send_code(s, END_BLOCK, ltree);
s->last_eob_len = ltree[END_BLOCK].Len;
} }
/* =========================================================================== /* ===========================================================================
@@ -970,44 +1046,6 @@ local void set_data_type(s)
s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII); s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII);
} }
/* ===========================================================================
* Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf.
*/
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
/* ===========================================================================
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
local void send_bits(s, value, length)
deflate_state *s;
int value; /* value to send */
int length; /* number of bits */
{
#ifdef DEBUG
Tracev((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length;
#endif
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
* unused bits in value.
*/
if (s->bi_valid > (int)Buf_size - length) {
s->bi_buf |= (value << s->bi_valid);
put_short(s, s->bi_buf);
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
s->bi_valid += length - Buf_size;
} else {
s->bi_buf |= value << s->bi_valid;
s->bi_valid += length;
}
}
/* =========================================================================== /* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster * Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table) * method would use a table)
@@ -1026,7 +1064,24 @@ local unsigned bi_reverse(code, len)
} }
/* =========================================================================== /* ===========================================================================
* Write out any remaining bits in an incomplete byte. * Flush the bit buffer, keeping at most 7 bits in it.
*/
local void bi_flush(s)
deflate_state *s;
{
if (s->bi_valid == 16) {
put_short(s, s->bi_buf);
s->bi_buf = 0;
s->bi_valid = 0;
} else if (s->bi_valid >= 8) {
put_byte(s, (Byte)s->bi_buf);
s->bi_buf >>= 8;
s->bi_valid -= 8;
}
}
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/ */
local void bi_windup(s) local void bi_windup(s)
deflate_state *s; deflate_state *s;
@@ -1054,6 +1109,7 @@ local void copy_block(s, buf, len, header)
int header; /* true if block header must be written */ int header; /* true if block header must be written */
{ {
bi_windup(s); /* align on byte boundary */ bi_windup(s); /* align on byte boundary */
s->last_eob_len = 8; /* enough lookahead for inflate */
if (header) { if (header) {
put_short(s, (ush)len); put_short(s, (ush)len);

35
zconf.h
View File

@@ -85,17 +85,23 @@
# endif # endif
#endif #endif
#if defined(M_I86SM) || defined(M_I86MM) /* model independent MSC functions */ /* The following definitions for FAR are needed only for MSDOS mixed
# define zstrcpy _fstrcpy * model programming (small or medium model with some far allocations).
# define zstrcat _fstrcat * This was tested only with MSC; for other MSDOS compilers you may have
# define zstrlen _fstrlen * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
# define zstrcmp _fstrcmp * just define FAR to be empty.
*/
#if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */
# ifdef _MSC_VER
# define FAR __far # define FAR __far
#else # else
# define zstrcpy strcpy # define FAR far
# define zstrcat strcat # endif
# define zstrlen strlen #endif
# define zstrcmp strcmp #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# define FAR __far /* completely untested, just a best guess */
#endif
#ifndef FAR
# define FAR # define FAR
#endif #endif
@@ -110,12 +116,11 @@ typedef uInt FAR uIntf;
typedef uLong FAR uLongf; typedef uLong FAR uLongf;
#ifdef STDC #ifdef STDC
typedef void FAR *voidp; typedef void FAR *voidpf;
typedef void *voidnp; typedef void *voidp;
#else #else
typedef Byte FAR *voidp; typedef Byte FAR *voidpf;
typedef Byte *voidnp; typedef Byte *voidp;
#endif #endif
#endif /* _ZCONF_H */ #endif /* _ZCONF_H */

14
zlib.h
View File

@@ -1,5 +1,5 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 0.94, Aug 13th, 1995. version 0.95, Aug 16th, 1995.
Copyright (C) 1995 Jean-loup Gailly and Mark Adler Copyright (C) 1995 Jean-loup Gailly and Mark Adler
@@ -28,7 +28,7 @@
#include "zconf.h" #include "zconf.h"
#define ZLIB_VERSION "0.94" #define ZLIB_VERSION "0.95"
/* /*
The 'zlib' compression library provides in-memory compression and The 'zlib' compression library provides in-memory compression and
@@ -49,8 +49,8 @@
(providing more output space) before each call. (providing more output space) before each call.
*/ */
typedef voidp (*alloc_func) OF((voidp opaque, uInt items, uInt size)); typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidp opaque, voidp address)); typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state; struct internal_state;
@@ -510,7 +510,7 @@ extern int uncompress OF((Bytef *dest, uLongf *destLen,
*/ */
typedef voidnp gzFile; typedef voidp gzFile;
extern gzFile gzopen OF((char *path, char *mode)); extern gzFile gzopen OF((char *path, char *mode));
/* /*
@@ -533,7 +533,7 @@ extern gzFile gzdopen OF((int fd, char *mode));
the (de)compression state. the (de)compression state.
*/ */
extern int gzread OF((gzFile file, voidnp buf, unsigned len)); extern int gzread OF((gzFile file, voidp buf, unsigned len));
/* /*
Reads the given number of uncompressed bytes from the compressed file. Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number 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));
gzread returns the number of uncompressed bytes actually read (0 for gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */ end of file, -1 for error). */
extern int gzwrite OF((gzFile file, voidnp buf, unsigned len)); extern int gzwrite OF((gzFile file, voidp buf, unsigned len));
/* /*
Writes the given number of uncompressed bytes into the compressed file. Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written gzwrite returns the number of uncompressed bytes actually written

41
zutil.c
View File

@@ -38,8 +38,8 @@ void z_error (m)
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void zmemcpy(dest, source, len) void zmemcpy(dest, source, len)
Byte* dest; Bytef* dest;
Byte* source; Bytef* source;
uInt len; uInt len;
{ {
if (len == 0) return; if (len == 0) return;
@@ -49,7 +49,7 @@ void zmemcpy(dest, source, len)
} }
void zmemzero(dest, len) void zmemzero(dest, len)
Byte* dest; Bytef* dest;
uInt len; uInt len;
{ {
if (len == 0) return; if (len == 0) return;
@@ -59,8 +59,10 @@ void zmemzero(dest, len)
} }
#endif #endif
#if defined(__TURBOC__) && !defined(__SMALL__) #if defined( __TURBOC__) && !defined(__SMALL__) && !defined(__MEDIUM__)
/* Small and medium model are for now limited to near allocation with
* reduced MAX_WBITS and MAX_MEM_LEVEL
*/
# define MY_ZCALLOC # define MY_ZCALLOC
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
@@ -75,8 +77,8 @@ void zmemzero(dest, len)
local int next_ptr = 0; local int next_ptr = 0;
typedef struct ptr_table_s { typedef struct ptr_table_s {
voidp org_ptr; voidpf org_ptr;
voidp new_ptr; voidpf new_ptr;
} ptr_table; } ptr_table;
local ptr_table table[MAX_PTR]; local ptr_table table[MAX_PTR];
@@ -87,9 +89,9 @@ local ptr_table table[MAX_PTR];
* a protected system like OS/2. Use Microsoft C instead. * a protected system like OS/2. Use Microsoft C instead.
*/ */
voidp zcalloc (voidp opaque, unsigned items, unsigned size) voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{ {
voidp buf = opaque; /* just to make some compilers happy */ voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
if (bsize < 65536L) { if (bsize < 65536L) {
@@ -108,7 +110,7 @@ voidp zcalloc (voidp opaque, unsigned items, unsigned size)
return buf; return buf;
} }
void zcfree (voidp opaque, voidp ptr) void zcfree (voidpf opaque, voidpf ptr)
{ {
int n; int n;
if (*(ush*)&ptr != 0) { /* object < 64K */ if (*(ush*)&ptr != 0) { /* object < 64K */
@@ -131,7 +133,8 @@ void zcfree (voidp opaque, voidp ptr)
} }
#endif /* __TURBOC__ */ #endif /* __TURBOC__ */
#if defined(MSDOS) && !defined(__TURBOC__) /* MSC */ #if defined(M_I86SM)||defined(M_I86MM)||defined(M_I86CM)||defined(M_I86LM)
/* Microsoft C */
# define MY_ZCALLOC # define MY_ZCALLOC
@@ -140,13 +143,13 @@ void zcfree (voidp opaque, voidp ptr)
# define _hfree hfree # define _hfree hfree
#endif #endif
voidp zcalloc (voidp opaque, unsigned items, unsigned size) voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{ {
if (opaque) opaque = 0; /* to make compiler happy */ if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void zcfree (voidp opaque, voidp ptr) void zcfree (voidpf opaque, voidpf ptr)
{ {
if (opaque) opaque = 0; /* to make compiler happy */ if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr); _hfree(ptr);
@@ -159,20 +162,20 @@ void zcfree (voidp opaque, voidp ptr)
#ifndef __GO32__ #ifndef __GO32__
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidp ptr)); extern void free OF((voidpf ptr));
#endif #endif
voidp zcalloc (opaque, items, size) voidpf zcalloc (opaque, items, size)
voidp opaque; voidpf opaque;
unsigned items; unsigned items;
unsigned size; unsigned size;
{ {
return calloc(items, size); return (voidpf)calloc(items, size);
} }
void zcfree (opaque, ptr) void zcfree (opaque, ptr)
voidp opaque; voidpf opaque;
voidp ptr; voidpf ptr;
{ {
free(ptr); free(ptr);
} }

24
zutil.h
View File

@@ -46,7 +46,7 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
#define DEFLATED 8 #define DEFLATED 8
#ifndef DEF_WBITS #ifndef DEF_WBITS
# define DEF_WBITS 15 # define DEF_WBITS MAX_WBITS
#endif #endif
/* default windowBits for decompression. MAX_WBITS is for compression only */ /* default windowBits for decompression. MAX_WBITS is for compression only */
@@ -72,7 +72,7 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
# define OS_CODE 0x00 # define OS_CODE 0x00
# ifdef __TURBOC__ # ifdef __TURBOC__
# include <alloc.h> # include <alloc.h>
# else /* MSC */ # else /* MSC or DJGPP */
# include <malloc.h> # include <malloc.h>
# endif # endif
#endif #endif
@@ -130,14 +130,20 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
# define zstrerror(errnum) "" # define zstrerror(errnum) ""
#endif #endif
#if defined(pyr) && !defined(NO_MEMCPY) #if defined(pyr)
# define NO_MEMCPY
#endif
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER)
/* Use our own functions for small and medium model with MSC <= 5.0.
* You may have to use the same strategy for Borland C (untested).
*/
# define NO_MEMCPY # define NO_MEMCPY
#endif #endif
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# define HAVE_MEMCPY # define HAVE_MEMCPY
#endif #endif
#ifdef HAVE_MEMCPY #ifdef HAVE_MEMCPY
# ifdef M_I86MM /* MSC medium model */ # if defined(M_I86SM) || defined(M_I86MM) /* MSC small or medium model */
# define zmemcpy _fmemcpy # define zmemcpy _fmemcpy
# define zmemzero(dest, len) _fmemset(dest, 0, len) # define zmemzero(dest, len) _fmemset(dest, 0, len)
# else # else
@@ -145,8 +151,8 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
# define zmemzero(dest, len) memset(dest, 0, len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
extern void zmemcpy OF((Byte* dest, Byte* source, uInt len)); extern void zmemcpy OF((Bytef* dest, Bytef* source, uInt len));
extern void zmemzero OF((Byte* dest, uInt len)); extern void zmemzero OF((Bytef* dest, uInt len));
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
@@ -175,12 +181,12 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
extern void z_error OF((char *m)); extern void z_error OF((char *m));
voidp zcalloc OF((voidp opaque, unsigned items, unsigned size)); voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidp opaque, voidp ptr)); void zcfree OF((voidpf opaque, voidpf ptr));
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size)) (*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidp)(addr)) #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
#endif /* _Z_UTIL_H */ #endif /* _Z_UTIL_H */