1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Zlib: Import sources from 1.3.1

This commit does not build. It's included to show JUCE modifications to
the zlib sources in the following commit.
This commit is contained in:
reuk 2025-02-25 11:37:59 +00:00
parent ae7db80b7b
commit fd05aaf817
No known key found for this signature in database
23 changed files with 20894 additions and 9949 deletions

View file

@ -1,143 +1,164 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream /* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id: adler32.c,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #include "zutil.h"
#include "zlib.h"
#define BASE 65521U /* largest prime smaller than 65536 */
#define BASE 65521UL /* largest prime smaller than 65536 */ #define NMAX 5552
#define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); #define DO16(buf) DO8(buf,0); DO8(buf,8);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware --
/* use NO_DIVIDE if your processor does not do division in hardware */ try it both ways to see which is faster */
#ifdef NO_DIVIDE #ifdef NO_DIVIDE
# define MOD(a) \ /* note that this assumes BASE is 65521, where 65536 % 65521 == 15
do { \ (thank you to John Reiser for pointing this out) */
if (a >= (BASE << 16)) a -= (BASE << 16); \ # define CHOP(a) \
if (a >= (BASE << 15)) a -= (BASE << 15); \ do { \
if (a >= (BASE << 14)) a -= (BASE << 14); \ unsigned long tmp = a >> 16; \
if (a >= (BASE << 13)) a -= (BASE << 13); \ a &= 0xffffUL; \
if (a >= (BASE << 12)) a -= (BASE << 12); \ a += (tmp << 4) - tmp; \
if (a >= (BASE << 11)) a -= (BASE << 11); \ } while (0)
if (a >= (BASE << 10)) a -= (BASE << 10); \ # define MOD28(a) \
if (a >= (BASE << 9)) a -= (BASE << 9); \ do { \
if (a >= (BASE << 8)) a -= (BASE << 8); \ CHOP(a); \
if (a >= (BASE << 7)) a -= (BASE << 7); \ if (a >= BASE) a -= BASE; \
if (a >= (BASE << 6)) a -= (BASE << 6); \ } while (0)
if (a >= (BASE << 5)) a -= (BASE << 5); \ # define MOD(a) \
if (a >= (BASE << 4)) a -= (BASE << 4); \ do { \
if (a >= (BASE << 3)) a -= (BASE << 3); \ CHOP(a); \
if (a >= (BASE << 2)) a -= (BASE << 2); \ MOD28(a); \
if (a >= (BASE << 1)) a -= (BASE << 1); \ } while (0)
if (a >= BASE) a -= BASE; \ # define MOD63(a) \
} while (0) do { /* this assumes a is not negative */ \
# define MOD4(a) \ z_off64_t tmp = a >> 32; \
do { \ a &= 0xffffffffL; \
if (a >= (BASE << 4)) a -= (BASE << 4); \ a += (tmp << 8) - (tmp << 5) + tmp; \
if (a >= (BASE << 3)) a -= (BASE << 3); \ tmp = a >> 16; \
if (a >= (BASE << 2)) a -= (BASE << 2); \ a &= 0xffffL; \
if (a >= (BASE << 1)) a -= (BASE << 1); \ a += (tmp << 4) - tmp; \
if (a >= BASE) a -= BASE; \ tmp = a >> 16; \
} while (0) a &= 0xffffL; \
#else a += (tmp << 4) - tmp; \
# define MOD(a) a %= BASE if (a >= BASE) a -= BASE; \
# define MOD4(a) a %= BASE } while (0)
#endif #else
# define MOD(a) a %= BASE
/* ========================================================================= */ # define MOD28(a) a %= BASE
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) # define MOD63(a) a %= BASE
{ #endif
unsigned long sum2;
unsigned n; /* ========================================================================= */
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
/* split Adler-32 into component sums */ unsigned long sum2;
sum2 = (adler >> 16) & 0xffff; unsigned n;
adler &= 0xffff;
/* split Adler-32 into component sums */
/* in case user likes doing a byte at a time, keep it fast */ sum2 = (adler >> 16) & 0xffff;
if (len == 1) { adler &= 0xffff;
adler += buf[0];
if (adler >= BASE) /* in case user likes doing a byte at a time, keep it fast */
adler -= BASE; if (len == 1) {
sum2 += adler; adler += buf[0];
if (sum2 >= BASE) if (adler >= BASE)
sum2 -= BASE; adler -= BASE;
return adler | (sum2 << 16); sum2 += adler;
} if (sum2 >= BASE)
sum2 -= BASE;
/* initial Adler-32 value (deferred check for len == 1 speed) */ return adler | (sum2 << 16);
if (buf == Z_NULL) }
return 1L;
/* initial Adler-32 value (deferred check for len == 1 speed) */
/* in case short lengths are provided, keep it somewhat fast */ if (buf == Z_NULL)
if (len < 16) { return 1L;
while (len--) {
adler += *buf++; /* in case short lengths are provided, keep it somewhat fast */
sum2 += adler; if (len < 16) {
} while (len--) {
if (adler >= BASE) adler += *buf++;
adler -= BASE; sum2 += adler;
MOD4(sum2); /* only added so many BASE's */ }
return adler | (sum2 << 16); if (adler >= BASE)
} adler -= BASE;
MOD28(sum2); /* only added so many BASE's */
/* do length NMAX blocks -- requires just one modulo operation */ return adler | (sum2 << 16);
while (len >= NMAX) { }
len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */ /* do length NMAX blocks -- requires just one modulo operation */
do { while (len >= NMAX) {
DO16(buf); /* 16 sums unrolled */ len -= NMAX;
buf += 16; n = NMAX / 16; /* NMAX is divisible by 16 */
} while (--n); do {
MOD(adler); DO16(buf); /* 16 sums unrolled */
MOD(sum2); buf += 16;
} } while (--n);
MOD(adler);
/* do remaining bytes (less than NMAX, still just one modulo) */ MOD(sum2);
if (len) { /* avoid modulos if none remaining */ }
while (len >= 16) {
len -= 16; /* do remaining bytes (less than NMAX, still just one modulo) */
DO16(buf); if (len) { /* avoid modulos if none remaining */
buf += 16; while (len >= 16) {
} len -= 16;
while (len--) { DO16(buf);
adler += *buf++; buf += 16;
sum2 += adler; }
} while (len--) {
MOD(adler); adler += *buf++;
MOD(sum2); sum2 += adler;
} }
MOD(adler);
/* return recombined sums */ MOD(sum2);
return adler | (sum2 << 16); }
}
/* return recombined sums */
/* ========================================================================= */ return adler | (sum2 << 16);
uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) }
{
unsigned long sum1; /* ========================================================================= */
unsigned long sum2; uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
unsigned rem; return adler32_z(adler, buf, len);
}
/* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE); /* ========================================================================= */
sum1 = adler1 & 0xffff; local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
sum2 = rem * sum1; unsigned long sum1;
MOD(sum2); unsigned long sum2;
sum1 += (adler2 & 0xffff) + BASE - 1; unsigned rem;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 > BASE) sum1 -= BASE; /* for negative len, return invalid adler32 as a clue for debugging */
if (sum1 > BASE) sum1 -= BASE; if (len2 < 0)
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); return 0xffffffffUL;
if (sum2 > BASE) sum2 -= BASE;
return sum1 | (sum2 << 16); /* the derivation of this formula is left as an exercise for the reader */
} MOD63(len2); /* assumes len2 >= 0 */
rem = (unsigned)len2;
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);
sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 >= BASE) sum1 -= BASE;
if (sum1 >= BASE) sum1 -= BASE;
if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
if (sum2 >= BASE) sum2 -= BASE;
return sum1 | (sum2 << 16);
}
/* ========================================================================= */
uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
return adler32_combine_(adler1, adler2, len2);
}
uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
return adler32_combine_(adler1, adler2, len2);
}

View file

@ -1,70 +1,75 @@
/* compress.c -- compress a memory buffer /* compress.c -- compress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly. * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id: compress.c,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
/* =========================================================================== /* ===========================================================================
Compresses the source buffer into the destination buffer. The level Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer, memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen, int level) uLong sourceLen, int level) {
{ z_stream stream;
z_stream stream; int err;
int err; const uInt max = (uInt)-1;
uLong left;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen; left = *destLen;
#ifdef MAXSEG_64K *destLen = 0;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; stream.zalloc = (alloc_func)0;
#endif stream.zfree = (free_func)0;
stream.next_out = dest; stream.opaque = (voidpf)0;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; err = deflateInit(&stream, level);
if (err != Z_OK) return err;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.next_out = dest;
stream.opaque = (voidpf)0; stream.avail_out = 0;
stream.next_in = (z_const Bytef *)source;
err = deflateInit(&stream, level); stream.avail_in = 0;
if (err != Z_OK) return err;
do {
err = deflate(&stream, Z_FINISH); if (stream.avail_out == 0) {
if (err != Z_STREAM_END) { stream.avail_out = left > (uLong)max ? max : (uInt)left;
deflateEnd(&stream); left -= stream.avail_out;
return err == Z_OK ? Z_BUF_ERROR : err; }
} if (stream.avail_in == 0) {
*destLen = stream.total_out; stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
sourceLen -= stream.avail_in;
err = deflateEnd(&stream); }
return err; err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
} } while (err == Z_OK);
/* =========================================================================== *destLen = stream.total_out;
*/ deflateEnd(&stream);
int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) return err == Z_STREAM_END ? Z_OK : err;
{ }
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
} /* ===========================================================================
*/
/* =========================================================================== int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
If the default memLevel or windowBits for deflateInit() is changed, then uLong sourceLen) {
this function needs to be updated. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
*/ }
uLong ZEXPORT compressBound (uLong sourceLen)
{ /* ===========================================================================
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; If the default memLevel or windowBits for deflateInit() is changed, then
} this function needs to be updated.
*/
uLong ZEXPORT compressBound(uLong sourceLen) {
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,333 +1,377 @@
/* deflate.h -- internal compression state /* deflate.h -- internal compression state
* Copyright (C) 1995-2004 Jean-loup Gailly * Copyright (C) 1995-2024 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
/* @(#) $Id: deflate.h,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#ifndef DEFLATE_H #ifndef DEFLATE_H
#define DEFLATE_H #define DEFLATE_H
#include "zutil.h" #include "zutil.h"
/* define NO_GZIP when compiling if you want to disable gzip header and /* define NO_GZIP when compiling if you want to disable gzip header and
trailer creation by deflate(). NO_GZIP would be used to avoid linking in trailer creation by deflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip encoding the crc code when it is not needed. For shared libraries, gzip encoding
should be left enabled. */ should be left enabled. */
#ifndef NO_GZIP #ifndef NO_GZIP
# define GZIP # define GZIP
#endif #endif
#define NO_DUMMY_DECL /* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
the cost of a larger memory footprint */
/* =========================================================================== /* #define LIT_MEM */
* Internal compression state.
*/ /* ===========================================================================
* Internal compression state.
#define LENGTH_CODES 29 */
/* number of length codes, not counting the special END_BLOCK code */
#define LENGTH_CODES 29
#define LITERALS 256 /* number of length codes, not counting the special END_BLOCK code */
/* number of literal bytes 0..255 */
#define LITERALS 256
#define L_CODES (LITERALS+1+LENGTH_CODES) /* number of literal bytes 0..255 */
/* number of Literal or Length codes, including the END_BLOCK code */
#define L_CODES (LITERALS+1+LENGTH_CODES)
#define D_CODES 30 /* number of Literal or Length codes, including the END_BLOCK code */
/* number of distance codes */
#define D_CODES 30
#define BL_CODES 19 /* number of distance codes */
/* number of codes used to transfer the bit lengths */
#define BL_CODES 19
#define HEAP_SIZE (2*L_CODES+1) /* number of codes used to transfer the bit lengths */
/* maximum heap size */
#define HEAP_SIZE (2*L_CODES+1)
#define MAX_BITS 15 /* maximum heap size */
/* All codes must not exceed MAX_BITS bits */
#define MAX_BITS 15
#define INIT_STATE 42 /* All codes must not exceed MAX_BITS bits */
#define EXTRA_STATE 69
#define NAME_STATE 73 #define Buf_size 16
#define COMMENT_STATE 91 /* size of bit buffer in bi_buf */
#define HCRC_STATE 103
#define BUSY_STATE 113 #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
#define FINISH_STATE 666 #ifdef GZIP
/* Stream status */ # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
#endif
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
/* Data structure describing a single value and its code string. */ #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
typedef struct ct_data_s { #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
union { #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
ush freq; /* frequency count */ #define BUSY_STATE 113 /* deflate -> FINISH_STATE */
ush code; /* bit string */ #define FINISH_STATE 666 /* stream complete */
} fc; /* Stream status */
union {
ush dad; /* father node in Huffman tree */
ush len; /* length of bit string */ /* Data structure describing a single value and its code string. */
} dl; typedef struct ct_data_s {
} FAR ct_data; union {
ush freq; /* frequency count */
#define Freq fc.freq ush code; /* bit string */
#define Code fc.code } fc;
#define Dad dl.dad union {
#define Len dl.len ush dad; /* father node in Huffman tree */
ush len; /* length of bit string */
typedef struct static_tree_desc_s static_tree_desc; } dl;
} FAR ct_data;
typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */ #define Freq fc.freq
int max_code; /* largest code with non zero frequency */ #define Code fc.code
static_tree_desc *stat_desc; /* the corresponding static tree */ #define Dad dl.dad
} FAR tree_desc; #define Len dl.len
typedef ush Pos; typedef struct static_tree_desc_s static_tree_desc;
typedef Pos FAR Posf;
typedef unsigned IPos; typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */
/* A Pos is an index in the character window. We use short instead of int to int max_code; /* largest code with non zero frequency */
* save space in the various tables. IPos is used only for parameter passing. const static_tree_desc *stat_desc; /* the corresponding static tree */
*/ } FAR tree_desc;
typedef struct internal_state { typedef ush Pos;
z_streamp strm; /* pointer back to this zlib stream */ typedef Pos FAR Posf;
int status; /* as the name implies */ typedef unsigned IPos;
Bytef *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */ /* A Pos is an index in the character window. We use short instead of int to
Bytef *pending_out; /* next pending byte to output to the stream */ * save space in the various tables. IPos is used only for parameter passing.
uInt pending; /* nb of bytes in the pending buffer */ */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */ typedef struct internal_state {
uInt gzindex; /* where in extra, name, or comment */ z_streamp strm; /* pointer back to this zlib stream */
Byte method; /* STORED (for zip only) or DEFLATED */ int status; /* as the name implies */
int last_flush; /* value of flush param for previous deflate call */ Bytef *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */
/* used by deflate.c: */ Bytef *pending_out; /* next pending byte to output to the stream */
ulg pending; /* nb of bytes in the pending buffer */
uInt w_size; /* LZ77 window size (32K by default) */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
uInt w_bits; /* log2(w_size) (8..16) */ gz_headerp gzhead; /* gzip header information to write */
uInt w_mask; /* w_size - 1 */ ulg gzindex; /* where in extra, name, or comment */
Byte method; /* can only be DEFLATED */
Bytef *window; int last_flush; /* value of flush param for previous deflate call */
/* Sliding window. Input bytes are read into the second half of the window,
* and move to the first half later to keep a dictionary of at least wSize /* used by deflate.c: */
* bytes. With this organization, matches are limited to a distance of
* wSize-MAX_MATCH bytes, but this ensures that IO is always uInt w_size; /* LZ77 window size (32K by default) */
* performed with a length multiple of the block size. Also, it limits uInt w_bits; /* log2(w_size) (8..16) */
* the window size to 64K, which is quite useful on MSDOS. uInt w_mask; /* w_size - 1 */
* To do: use the user input buffer as sliding window.
*/ Bytef *window;
/* Sliding window. Input bytes are read into the second half of the window,
ulg window_size; * and move to the first half later to keep a dictionary of at least wSize
/* Actual size of window: 2*wSize, except when the user input buffer * bytes. With this organization, matches are limited to a distance of
* is directly used as sliding window. * wSize-MAX_MATCH bytes, but this ensures that IO is always
*/ * performed with a length multiple of the block size. Also, it limits
* the window size to 64K, which is quite useful on MSDOS.
Posf *prev; * To do: use the user input buffer as sliding window.
/* Link to older string with same hash index. To limit the size of this */
* array to 64K, this link is maintained only for the last 32K strings.
* An index in this array is thus a window index modulo 32K. ulg window_size;
*/ /* Actual size of window: 2*wSize, except when the user input buffer
* is directly used as sliding window.
Posf *head; /* Heads of the hash chains or NIL. */ */
uInt ins_h; /* hash index of string to be inserted */ Posf *prev;
uInt hash_size; /* number of elements in hash table */ /* Link to older string with same hash index. To limit the size of this
uInt hash_bits; /* log2(hash_size) */ * array to 64K, this link is maintained only for the last 32K strings.
uInt hash_mask; /* hash_size-1 */ * An index in this array is thus a window index modulo 32K.
*/
uInt hash_shift;
/* Number of bits by which ins_h must be shifted at each input Posf *head; /* Heads of the hash chains or NIL. */
* step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is: uInt ins_h; /* hash index of string to be inserted */
* hash_shift * MIN_MATCH >= hash_bits uInt hash_size; /* number of elements in hash table */
*/ uInt hash_bits; /* log2(hash_size) */
uInt hash_mask; /* hash_size-1 */
long block_start;
/* Window position at the beginning of the current output block. Gets uInt hash_shift;
* negative when the window is moved backwards. /* Number of bits by which ins_h must be shifted at each input
*/ * step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
uInt match_length; /* length of best match */ * hash_shift * MIN_MATCH >= hash_bits
IPos prev_match; /* previous match */ */
int match_available; /* set if previous match exists */
uInt strstart; /* start of string to insert */ long block_start;
uInt match_start; /* start of matching string */ /* Window position at the beginning of the current output block. Gets
uInt lookahead; /* number of valid bytes ahead in window */ * negative when the window is moved backwards.
*/
uInt prev_length;
/* Length of the best match at previous step. Matches not greater than this uInt match_length; /* length of best match */
* are discarded. This is used in the lazy match evaluation. IPos prev_match; /* previous match */
*/ int match_available; /* set if previous match exists */
uInt strstart; /* start of string to insert */
uInt max_chain_length; uInt match_start; /* start of matching string */
/* To speed up deflation, hash chains are never searched beyond this uInt lookahead; /* number of valid bytes ahead in window */
* length. A higher limit improves compression ratio but degrades the
* speed. uInt prev_length;
*/ /* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
uInt max_lazy_match; */
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression uInt max_chain_length;
* levels >= 4. /* To speed up deflation, hash chains are never searched beyond this
*/ * length. A higher limit improves compression ratio but degrades the
# define max_insert_length max_lazy_match * speed.
/* Insert new strings in the hash table only if the match length is not */
* greater than this length. This saves time but degrades compression.
* max_insert_length is used only for compression levels <= 3. uInt max_lazy_match;
*/ /* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
int level; /* compression level (1..9) */ * levels >= 4.
int strategy; /* favor or force Huffman coding*/ */
# define max_insert_length max_lazy_match
uInt good_match; /* Insert new strings in the hash table only if the match length is not
/* Use a faster search when the previous match is longer than this */ * greater than this length. This saves time but degrades compression.
* max_insert_length is used only for compression levels <= 3.
int nice_match; /* Stop searching when current match exceeds this */ */
/* used by trees.c: */ int level; /* compression level (1..9) */
/* Didn't use ct_data typedef below to supress compiler warning */ int strategy; /* favor or force Huffman coding*/
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ uInt good_match;
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ /* Use a faster search when the previous match is longer than this */
struct tree_desc_s l_desc; /* desc. for literal tree */ int nice_match; /* Stop searching when current match exceeds this */
struct tree_desc_s d_desc; /* desc. for distance tree */
struct tree_desc_s bl_desc; /* desc. for bit length tree */ /* used by trees.c: */
/* Didn't use ct_data typedef below to suppress compiler warning */
ush bl_count[MAX_BITS+1]; struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
/* number of codes at each bit length for an optimal tree */ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
int heap_len; /* number of elements in the heap */ struct tree_desc_s l_desc; /* desc. for literal tree */
int heap_max; /* element of largest frequency */ struct tree_desc_s d_desc; /* desc. for distance tree */
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. struct tree_desc_s bl_desc; /* desc. for bit length tree */
* The same heap array is used to build all trees.
*/ ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
uch depth[2*L_CODES+1];
/* Depth of each subtree used as tie breaker for trees of equal frequency int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
*/ int heap_len; /* number of elements in the heap */
int heap_max; /* element of largest frequency */
uchf *l_buf; /* buffer for literals or lengths */ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
* The same heap array is used to build all trees.
uInt lit_bufsize; */
/* Size of match buffer for literals/lengths. There are 4 reasons for
* limiting lit_bufsize to 64K: uch depth[2*L_CODES+1];
* - frequencies can be kept in 16 bit counters /* Depth of each subtree used as tie breaker for trees of equal frequency
* - if compression is not successful for the first block, all input */
* data is still in the window so we can still emit a stored block even
* when input comes from standard input. (This can also be done for #ifdef LIT_MEM
* all blocks if lit_bufsize is not greater than 32K.) # define LIT_BUFS 5
* - if compression is not successful for a file smaller than 64K, we can ushf *d_buf; /* buffer for distances */
* even emit a stored file instead of a stored block (saving 5 bytes). uchf *l_buf; /* buffer for literals/lengths */
* This is applicable only for zip (not gzip or zlib). #else
* - creating new Huffman trees less frequently may not provide fast # define LIT_BUFS 4
* adaptation to changes in the input data statistics. (Take for uchf *sym_buf; /* buffer for distances and literals/lengths */
* example a binary file with poorly compressible code followed by #endif
* a highly compressible string table.) Smaller buffer sizes give
* fast adaptation but have of course the overhead of transmitting uInt lit_bufsize;
* trees more frequently. /* Size of match buffer for literals/lengths. There are 4 reasons for
* - I can't count above 4 * limiting lit_bufsize to 64K:
*/ * - frequencies can be kept in 16 bit counters
* - if compression is not successful for the first block, all input
uInt last_lit; /* running index in l_buf */ * data is still in the window so we can still emit a stored block even
* when input comes from standard input. (This can also be done for
ushf *d_buf; * all blocks if lit_bufsize is not greater than 32K.)
/* Buffer for distances. To simplify the code, d_buf and l_buf have * - if compression is not successful for a file smaller than 64K, we can
* the same number of elements. To use different lengths, an extra flag * even emit a stored file instead of a stored block (saving 5 bytes).
* array would be necessary. * This is applicable only for zip (not gzip or zlib).
*/ * - creating new Huffman trees less frequently may not provide fast
* adaptation to changes in the input data statistics. (Take for
ulg opt_len; /* bit length of current block with optimal trees */ * example a binary file with poorly compressible code followed by
ulg static_len; /* bit length of current block with static trees */ * a highly compressible string table.) Smaller buffer sizes give
uInt matches; /* number of string matches in current block */ * fast adaptation but have of course the overhead of transmitting
int last_eob_len; /* bit length of EOB code for last block */ * trees more frequently.
* - I can't count above 4
#ifdef DEBUG */
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ uInt sym_next; /* running index in symbol buffer */
#endif uInt sym_end; /* symbol table full when sym_next reaches this */
ush bi_buf; ulg opt_len; /* bit length of current block with optimal trees */
/* Output buffer. bits are inserted starting at the bottom (least ulg static_len; /* bit length of current block with static trees */
* significant bits). uInt matches; /* number of string matches in current block */
*/ uInt insert; /* bytes at end of window left to insert */
int bi_valid;
/* Number of valid bits in bi_buf. All bits above the last valid bit #ifdef ZLIB_DEBUG
* are always zero. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
*/ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
} FAR deflate_state;
ush bi_buf;
/* Output a byte on the stream. /* Output buffer. bits are inserted starting at the bottom (least
* IN assertion: there is enough room in pending_buf. * significant bits).
*/ */
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} int bi_valid;
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) */
/* Minimum amount of lookahead, except at the end of the input file.
* See deflate.c for comments about the MIN_MATCH+1. ulg high_water;
*/ /* High water mark offset in window for initialized bytes -- bytes above
* this are set to zero in order to avoid memory check warnings when
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) * longest match routines access bytes past the input. This is then
/* In order to simplify the code, particularly on 16 bit machines, match * updated to the new high water mark.
* distances are limited to MAX_DIST instead of WSIZE. */
*/
} FAR deflate_state;
/* in trees.c */
void _tr_init OF((deflate_state *s)); /* Output a byte on the stream.
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); * IN assertion: there is enough room in pending_buf.
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, */
int eof)); #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
void _tr_align OF((deflate_state *s));
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
int eof)); #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file.
#define d_code(dist) \ * See deflate.c for comments about the MIN_MATCH+1.
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) */
/* Mapping from a distance to a distance code. dist is the distance - 1 and
* must not have side effects. _dist_code[256] and _dist_code[257] are never #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
* used. /* In order to simplify the code, particularly on 16 bit machines, match
*/ * distances are limited to MAX_DIST instead of WSIZE.
*/
#ifndef DEBUG
/* Inline versions of _tr_tally for speed: */ #define WIN_INIT MAX_MATCH
/* Number of bytes after end of data in window to initialize in order to avoid
#if defined(GEN_TREES_H) || !defined(STDC) memory checker errors from longest match routines */
extern uch _length_code[];
extern uch _dist_code[]; /* in trees.c */
#else void ZLIB_INTERNAL _tr_init(deflate_state *s);
extern const uch _length_code[]; int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
extern const uch _dist_code[]; void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
#endif ulg stored_len, int last);
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
# define _tr_tally_lit(s, c, flush) \ void ZLIB_INTERNAL _tr_align(deflate_state *s);
{ uch cc = (c); \ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
s->d_buf[s->last_lit] = 0; \ ulg stored_len, int last);
s->l_buf[s->last_lit++] = cc; \
s->dyn_ltree[cc].Freq++; \ #define d_code(dist) \
flush = (s->last_lit == s->lit_bufsize-1); \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
} /* Mapping from a distance to a distance code. dist is the distance - 1 and
# define _tr_tally_dist(s, distance, length, flush) \ * must not have side effects. _dist_code[256] and _dist_code[257] are never
{ uch len = (length); \ * used.
ush dist = (distance); \ */
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \ #ifndef ZLIB_DEBUG
dist--; \ /* Inline versions of _tr_tally for speed: */
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \ #if defined(GEN_TREES_H) || !defined(STDC)
flush = (s->last_lit == s->lit_bufsize-1); \ extern uch ZLIB_INTERNAL _length_code[];
} extern uch ZLIB_INTERNAL _dist_code[];
#else #else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) extern const uch ZLIB_INTERNAL _length_code[];
# define _tr_tally_dist(s, distance, length, flush) \ extern const uch ZLIB_INTERNAL _dist_code[];
flush = _tr_tally(s, distance, length) #endif
#endif
#ifdef LIT_MEM
#endif /* DEFLATE_H */ # define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->d_buf[s->sym_next] = 0; \
s->l_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (uch)(length); \
ush dist = (ush)(distance); \
s->d_buf[s->sym_next] = dist; \
s->l_buf[s->sym_next++] = len; \
dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
#else
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (uch)(length); \
ush dist = (ush)(distance); \
s->sym_buf[s->sym_next++] = (uch)dist; \
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
s->sym_buf[s->sym_next++] = len; \
dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
#endif
#else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
# define _tr_tally_dist(s, distance, length, flush) \
flush = _tr_tally(s, distance, length)
#endif
#endif /* DEFLATE_H */

View file

@ -0,0 +1,214 @@
/* gzguts.h -- zlib internal header definitions for gz* operations
* Copyright (C) 2004-2024 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifdef _LARGEFILE64_SOURCE
# ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1
# endif
# undef _FILE_OFFSET_BITS
# undef _TIME_BITS
#endif
#ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
# define ZLIB_INTERNAL
#endif
#include <stdio.h>
#include "zlib.h"
#ifdef STDC
# include <string.h>
# include <stdlib.h>
# include <limits.h>
#endif
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include <fcntl.h>
#ifdef _WIN32
# include <stddef.h>
#endif
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
# include <io.h>
#endif
#if defined(_WIN32)
# define WIDECHAR
#endif
#ifdef WINAPI_FAMILY
# define open _open
# define read _read
# define write _write
# define close _close
#endif
#ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS
#endif
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#if defined(__CYGWIN__)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#ifndef HAVE_VSNPRINTF
# ifdef MSDOS
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
but for now we just assume it doesn't. */
# define NO_vsnprintf
# endif
# ifdef __TURBOC__
# define NO_vsnprintf
# endif
# ifdef WIN32
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
# define vsnprintf _vsnprintf
# endif
# endif
# endif
# ifdef __SASC
# define NO_vsnprintf
# endif
# ifdef VMS
# define NO_vsnprintf
# endif
# ifdef __OS400__
# define NO_vsnprintf
# endif
# ifdef __MVS__
# define NO_vsnprintf
# endif
#endif
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
null termination of the result -- however this is only used in gzlib.c where
the result is assured to fit in the space provided */
#if defined(_MSC_VER) && _MSC_VER < 1900
# define snprintf _snprintf
#endif
#ifndef local
# define local static
#endif
/* since "static" is used to mean two completely different things in C, we
define "local" for the non-static meaning of "static", for readability
(compile with -Dlocal if your debugger can't find static symbols) */
/* gz* functions always use library allocation functions */
#ifndef STDC
extern voidp malloc(uInt size);
extern void free(voidpf ptr);
#endif
/* get errno and strerror definition */
#if defined UNDER_CE
# include <windows.h>
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
#else
# ifndef NO_STRERROR
# include <errno.h>
# define zstrerror() strerror(errno)
# else
# define zstrerror() "stdio error (consult errno)"
# endif
#endif
/* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
#endif
/* default memLevel */
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
/* default i/o buffer size -- double this for output when reading (this and
twice this must be able to fit in an unsigned type) */
#define GZBUFSIZE 8192
/* gzip modes, also provide a little integrity check on the passed structure */
#define GZ_NONE 0
#define GZ_READ 7247
#define GZ_WRITE 31153
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
/* values for gz_state how */
#define LOOK 0 /* look for a gzip header */
#define COPY 1 /* copy input directly */
#define GZIP 2 /* decompress a gzip stream */
/* internal gzip file state data structure */
typedef struct {
/* exposed contents for gzgetc() macro */
struct gzFile_s x; /* "x" for exposed */
/* x.have: number of bytes available at x.next */
/* x.next: next output data to deliver or write */
/* x.pos: current position in uncompressed data */
/* used for both reading and writing */
int mode; /* see gzip modes above */
int fd; /* file descriptor */
char *path; /* path or fd for error messages */
unsigned size; /* buffer size, zero if not allocated yet */
unsigned want; /* requested buffer size, default is GZBUFSIZE */
unsigned char *in; /* input buffer (double-sized when writing) */
unsigned char *out; /* output buffer (double-sized when reading) */
int direct; /* 0 if processing gzip, 1 if transparent */
/* just for reading */
int how; /* 0: get header, 1: copy, 2: decompress */
z_off64_t start; /* where the gzip data started, for rewinding */
int eof; /* true if end of input file reached */
int past; /* true if read requested past end */
/* just for writing */
int level; /* compression level */
int strategy; /* compression strategy */
int reset; /* true if a reset is pending after a Z_FINISH */
/* seek request */
z_off64_t skip; /* amount to skip (already rewound if backwards) */
int seek; /* true if seek request pending */
/* error information */
int err; /* error code */
char *msg; /* error message */
/* zlib inflate or deflate stream */
z_stream strm; /* stream structure in-place (not a pointer) */
} gz_state;
typedef gz_state FAR *gz_statep;
/* shared functions */
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
#if defined UNDER_CE
char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
#endif
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
value -- needed when comparing unsigned to z_off64_t, which is signed
(possible z_off64_t types off_t, off64_t, and long are all signed) */
unsigned ZLIB_INTERNAL gz_intmax(void);
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())

File diff suppressed because it is too large Load diff

View file

@ -1,316 +1,320 @@
/* inffast.c -- fast decoding /* inffast.c -- fast decoding
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2017 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
#ifndef ASMINF #ifdef ASMINF
# pragma message("Assembler code may have bugs -- use at your own risk")
/* Allow machine dependent optimization for post-increment or pre-increment. #else
Based on testing to date,
Pre-increment preferred for: /*
- PowerPC G3 (Adler) Decode literal, length, and distance codes and write out the resulting
- MIPS R5000 (Randers-Pehrson) literal and match bytes until either not enough input or output is
Post-increment preferred for: available, an end-of-block is encountered, or a data error is encountered.
- none When large enough input and output buffers are supplied to inflate(), for
No measurable difference: example, a 16K input buffer and a 64K output buffer, more than 95% of the
- Pentium III (Anderson) inflate execution time is spent in this routine.
- M68060 (Nikl)
*/ Entry assumptions:
#ifdef POSTINC
# define OFF 0 state->mode == LEN
# define PUP(a) *(a)++ strm->avail_in >= 6
#else strm->avail_out >= 258
# define OFF 1 start >= strm->avail_out
# define PUP(a) *++(a) state->bits < 8
#endif
On return, state->mode is one of:
/*
Decode literal, length, and distance codes and write out the resulting LEN -- ran out of enough output space or enough available input
literal and match bytes until either not enough input or output is TYPE -- reached end of block code, inflate() to interpret next block
available, an end-of-block is encountered, or a data error is encountered. BAD -- error in block data
When large enough input and output buffers are supplied to inflate(), for
example, a 16K input buffer and a 64K output buffer, more than 95% of the Notes:
inflate execution time is spent in this routine.
- The maximum input bits used by a length/distance pair is 15 bits for the
Entry assumptions: length code, 5 bits for the length extra, 15 bits for the distance code,
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
state->mode == LEN Therefore if strm->avail_in >= 6, then there is enough input to avoid
strm->avail_in >= 6 checking for available input while decoding.
strm->avail_out >= 258
start >= strm->avail_out - The maximum bytes that a single length/distance pair can output is 258
state->bits < 8 bytes, which is the maximum length that can be coded. inflate_fast()
requires strm->avail_out >= 258 for each loop to avoid checking for
On return, state->mode is one of: output space.
*/
LEN -- ran out of enough output space or enough available input void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
TYPE -- reached end of block code, inflate() to interpret next block struct inflate_state FAR *state;
BAD -- error in block data z_const unsigned char FAR *in; /* local strm->next_in */
z_const unsigned char FAR *last; /* have enough input while in < last */
Notes: unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
- The maximum input bits used by a length/distance pair is 15 bits for the unsigned char FAR *end; /* while out < end, enough space available */
length code, 5 bits for the length extra, 15 bits for the distance code, #ifdef INFLATE_STRICT
and 13 bits for the distance extra. This totals 48 bits, or six bytes. unsigned dmax; /* maximum distance from zlib header */
Therefore if strm->avail_in >= 6, then there is enough input to avoid #endif
checking for available input while decoding. unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
- The maximum bytes that a single length/distance pair can output is 258 unsigned wnext; /* window write index */
bytes, which is the maximum length that can be coded. inflate_fast() unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
requires strm->avail_out >= 258 for each loop to avoid checking for unsigned long hold; /* local strm->hold */
output space. unsigned bits; /* local strm->bits */
*/ code const FAR *lcode; /* local strm->lencode */
void inflate_fast (z_streamp strm, unsigned start) code const FAR *dcode; /* local strm->distcode */
{ unsigned lmask; /* mask for first level of length codes */
struct inflate_state FAR *state; unsigned dmask; /* mask for first level of distance codes */
unsigned char FAR *in; /* local strm->next_in */ code const *here; /* retrieved table entry */
unsigned char FAR *last; /* while in < last, enough input available */ unsigned op; /* code bits, operation, extra bits, or */
unsigned char FAR *out; /* local strm->next_out */ /* window position, window bytes to copy */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned len; /* match length, unused bytes */
unsigned char FAR *end; /* while out < end, enough space available */ unsigned dist; /* match distance */
#ifdef INFLATE_STRICT unsigned char FAR *from; /* where to copy match from */
unsigned dmax; /* maximum distance from zlib header */
#endif /* copy state to local variables */
unsigned wsize; /* window size or zero if not using window */ state = (struct inflate_state FAR *)strm->state;
unsigned whave; /* valid bytes in the window */ in = strm->next_in;
unsigned write; /* window write index */ last = in + (strm->avail_in - 5);
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ out = strm->next_out;
unsigned long hold; /* local strm->hold */ beg = out - (start - strm->avail_out);
unsigned bits; /* local strm->bits */ end = out + (strm->avail_out - 257);
code const FAR *lcode; /* local strm->lencode */ #ifdef INFLATE_STRICT
code const FAR *dcode; /* local strm->distcode */ dmax = state->dmax;
unsigned lmask; /* mask for first level of length codes */ #endif
unsigned dmask; /* mask for first level of distance codes */ wsize = state->wsize;
code thisx; /* retrieved table entry */ whave = state->whave;
unsigned op; /* code bits, operation, extra bits, or */ wnext = state->wnext;
/* window position, window bytes to copy */ window = state->window;
unsigned len; /* match length, unused bytes */ hold = state->hold;
unsigned dist; /* match distance */ bits = state->bits;
unsigned char FAR *from; /* where to copy match from */ lcode = state->lencode;
dcode = state->distcode;
/* copy state to local variables */ lmask = (1U << state->lenbits) - 1;
state = (struct inflate_state FAR *)strm->state; dmask = (1U << state->distbits) - 1;
in = strm->next_in - OFF;
last = in + (strm->avail_in - 5); /* decode literals and length/distances until end-of-block or not enough
out = strm->next_out - OFF; input data or output space */
beg = out - (start - strm->avail_out); do {
end = out + (strm->avail_out - 257); if (bits < 15) {
#ifdef INFLATE_STRICT hold += (unsigned long)(*in++) << bits;
dmax = state->dmax; bits += 8;
#endif hold += (unsigned long)(*in++) << bits;
wsize = state->wsize; bits += 8;
whave = state->whave; }
write = state->write; here = lcode + (hold & lmask);
window = state->window; dolen:
hold = state->hold; op = (unsigned)(here->bits);
bits = state->bits; hold >>= op;
lcode = state->lencode; bits -= op;
dcode = state->distcode; op = (unsigned)(here->op);
lmask = (1U << state->lenbits) - 1; if (op == 0) { /* literal */
dmask = (1U << state->distbits) - 1; Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
"inflate: literal '%c'\n" :
/* decode literals and length/distances until end-of-block or not enough "inflate: literal 0x%02x\n", here->val));
input data or output space */ *out++ = (unsigned char)(here->val);
do { }
if (bits < 15) { else if (op & 16) { /* length base */
hold += (unsigned long)(PUP(in)) << bits; len = (unsigned)(here->val);
bits += 8; op &= 15; /* number of extra bits */
hold += (unsigned long)(PUP(in)) << bits; if (op) {
bits += 8; if (bits < op) {
} hold += (unsigned long)(*in++) << bits;
thisx = lcode[hold & lmask]; bits += 8;
dolen: }
op = (unsigned)(thisx.bits); len += (unsigned)hold & ((1U << op) - 1);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(thisx.op); }
if (op == 0) { /* literal */ Tracevv((stderr, "inflate: length %u\n", len));
Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ? if (bits < 15) {
"inflate: literal '%c'\n" : hold += (unsigned long)(*in++) << bits;
"inflate: literal 0x%02x\n", thisx.val)); bits += 8;
PUP(out) = (unsigned char)(thisx.val); hold += (unsigned long)(*in++) << bits;
} bits += 8;
else if (op & 16) { /* length base */ }
len = (unsigned)(thisx.val); here = dcode + (hold & dmask);
op &= 15; /* number of extra bits */ dodist:
if (op) { op = (unsigned)(here->bits);
if (bits < op) { hold >>= op;
hold += (unsigned long)(PUP(in)) << bits; bits -= op;
bits += 8; op = (unsigned)(here->op);
} if (op & 16) { /* distance base */
len += (unsigned)hold & ((1U << op) - 1); dist = (unsigned)(here->val);
hold >>= op; op &= 15; /* number of extra bits */
bits -= op; if (bits < op) {
} hold += (unsigned long)(*in++) << bits;
Tracevv((stderr, "inflate: length %u\n", len)); bits += 8;
if (bits < 15) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; }
bits += 8; }
} dist += (unsigned)hold & ((1U << op) - 1);
thisx = dcode[hold & dmask]; #ifdef INFLATE_STRICT
dodist: if (dist > dmax) {
op = (unsigned)(thisx.bits); strm->msg = (char *)"invalid distance too far back";
hold >>= op; state->mode = BAD;
bits -= op; break;
op = (unsigned)(thisx.op); }
if (op & 16) { /* distance base */ #endif
dist = (unsigned)(thisx.val); hold >>= op;
op &= 15; /* number of extra bits */ bits -= op;
if (bits < op) { Tracevv((stderr, "inflate: distance %u\n", dist));
hold += (unsigned long)(PUP(in)) << bits; op = (unsigned)(out - beg); /* max distance in output */
bits += 8; if (dist > op) { /* see if copy from window */
if (bits < op) { op = dist - op; /* distance back in window */
hold += (unsigned long)(PUP(in)) << bits; if (op > whave) {
bits += 8; if (state->sane) {
} strm->msg =
} (char *)"invalid distance too far back";
dist += (unsigned)hold & ((1U << op) - 1); state->mode = BAD;
#ifdef INFLATE_STRICT break;
if (dist > dmax) { }
strm->msg = (char *)"invalid distance too far back"; #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
state->mode = BAD; if (len <= op - whave) {
break; do {
} *out++ = 0;
#endif } while (--len);
hold >>= op; continue;
bits -= op; }
Tracevv((stderr, "inflate: distance %u\n", dist)); len -= op - whave;
op = (unsigned)(out - beg); /* max distance in output */ do {
if (dist > op) { /* see if copy from window */ *out++ = 0;
op = dist - op; /* distance back in window */ } while (--op > whave);
if (op > whave) { if (op == 0) {
strm->msg = (char *)"invalid distance too far back"; from = out - dist;
state->mode = BAD; do {
break; *out++ = *from++;
} } while (--len);
from = window - OFF; continue;
if (write == 0) { /* very common case */ }
from += wsize - op; #endif
if (op < len) { /* some from window */ }
len -= op; from = window;
do { if (wnext == 0) { /* very common case */
PUP(out) = PUP(from); from += wsize - op;
} while (--op); if (op < len) { /* some from window */
from = out - dist; /* rest from output */ len -= op;
} do {
} *out++ = *from++;
else if (write < op) { /* wrap around window */ } while (--op);
from += wsize + write - op; from = out - dist; /* rest from output */
op -= write; }
if (op < len) { /* some from end of window */ }
len -= op; else if (wnext < op) { /* wrap around window */
do { from += wsize + wnext - op;
PUP(out) = PUP(from); op -= wnext;
} while (--op); if (op < len) { /* some from end of window */
from = window - OFF; len -= op;
if (write < len) { /* some from start of window */ do {
op = write; *out++ = *from++;
len -= op; } while (--op);
do { from = window;
PUP(out) = PUP(from); if (wnext < len) { /* some from start of window */
} while (--op); op = wnext;
from = out - dist; /* rest from output */ len -= op;
} do {
} *out++ = *from++;
} } while (--op);
else { /* contiguous in window */ from = out - dist; /* rest from output */
from += write - op; }
if (op < len) { /* some from window */ }
len -= op; }
do { else { /* contiguous in window */
PUP(out) = PUP(from); from += wnext - op;
} while (--op); if (op < len) { /* some from window */
from = out - dist; /* rest from output */ len -= op;
} do {
} *out++ = *from++;
while (len > 2) { } while (--op);
PUP(out) = PUP(from); from = out - dist; /* rest from output */
PUP(out) = PUP(from); }
PUP(out) = PUP(from); }
len -= 3; while (len > 2) {
} *out++ = *from++;
if (len) { *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
if (len > 1) len -= 3;
PUP(out) = PUP(from); }
} if (len) {
} *out++ = *from++;
else { if (len > 1)
from = out - dist; /* copy direct from output */ *out++ = *from++;
do { /* minimum length is three */ }
PUP(out) = PUP(from); }
PUP(out) = PUP(from); else {
PUP(out) = PUP(from); from = out - dist; /* copy direct from output */
len -= 3; do { /* minimum length is three */
} while (len > 2); *out++ = *from++;
if (len) { *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
if (len > 1) len -= 3;
PUP(out) = PUP(from); } while (len > 2);
} if (len) {
} *out++ = *from++;
} if (len > 1)
else if ((op & 64) == 0) { /* 2nd level distance code */ *out++ = *from++;
thisx = dcode[thisx.val + (hold & ((1U << op) - 1))]; }
goto dodist; }
} }
else { else if ((op & 64) == 0) { /* 2nd level distance code */
strm->msg = (char *)"invalid distance code"; here = dcode + here->val + (hold & ((1U << op) - 1));
state->mode = BAD; goto dodist;
break; }
} else {
} strm->msg = (char *)"invalid distance code";
else if ((op & 64) == 0) { /* 2nd level length code */ state->mode = BAD;
thisx = lcode[thisx.val + (hold & ((1U << op) - 1))]; break;
goto dolen; }
} }
else if (op & 32) { /* end-of-block */ else if ((op & 64) == 0) { /* 2nd level length code */
Tracevv((stderr, "inflate: end of block\n")); here = lcode + here->val + (hold & ((1U << op) - 1));
state->mode = TYPE; goto dolen;
break; }
} else if (op & 32) { /* end-of-block */
else { Tracevv((stderr, "inflate: end of block\n"));
strm->msg = (char *)"invalid literal/length code"; state->mode = TYPE;
state->mode = BAD; break;
break; }
} else {
} while (in < last && out < end); strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ break;
len = bits >> 3; }
in -= len; } while (in < last && out < end);
bits -= len << 3;
hold &= (1U << bits) - 1; /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3;
/* update state and return */ in -= len;
strm->next_in = in + OFF; bits -= len << 3;
strm->next_out = out + OFF; hold &= (1U << bits) - 1;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ? /* update state and return */
257 + (end - out) : 257 - (out - end)); strm->next_in = in;
state->hold = hold; strm->next_out = out;
state->bits = bits; strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
return; strm->avail_out = (unsigned)(out < end ?
} 257 + (end - out) : 257 - (out - end));
state->hold = hold;
/* state->bits = bits;
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): return;
- Using bit fields for code structure }
- Different op definition to avoid & for extra bits (do & for table bits)
- Three separate decoding do-loops for direct, window, and write == 0 /*
- Special case for distance > 1 copies to do overlapped load and store copy inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- Explicit branch predictions (based on measured branch probabilities) - Using bit fields for code structure
- Deferring match copy and interspersed it with decoding subsequent codes - Different op definition to avoid & for extra bits (do & for table bits)
- Swapping literal/length else - Three separate decoding do-loops for direct, window, and wnext == 0
- Swapping window/direct else - Special case for distance > 1 copies to do overlapped load and store copy
- Larger unrolled copy loops (three is about right) - Explicit branch predictions (based on measured branch probabilities)
- Moving len -= 3 statement into middle of loop - Deferring match copy and interspersed it with decoding subsequent codes
*/ - Swapping literal/length else
- Swapping window/direct else
#endif /* !ASMINF */ - Larger unrolled copy loops (three is about right)
- Moving len -= 3 statement into middle of loop
*/
#endif /* !ASMINF */

View file

@ -1,11 +1,11 @@
/* inffast.h -- header to use inffast.c /* inffast.h -- header to use inffast.c
* Copyright (C) 1995-2003 Mark Adler * Copyright (C) 1995-2003, 2010 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
void inflate_fast OF((z_streamp strm, unsigned start)); void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);

View file

@ -1,94 +1,94 @@
/* inffixed.h -- table for decoding fixed codes /* inffixed.h -- table for decoding fixed codes
* Generated automatically by makefixed(). * Generated automatically by makefixed().
*/ */
/* WARNING: this file should *not* be used by applications. It /* WARNING: this file should *not* be used by applications.
is part of the implementation of the compression library and It is part of the implementation of this library and is
is subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
static const code lenfix[512] = { static const code lenfix[512] = {
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
{0,9,255} {0,9,255}
}; };
static const code distfix[32] = { static const code distfix[32] = {
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
{22,5,193},{64,5,0} {22,5,193},{64,5,0}
}; };

File diff suppressed because it is too large Load diff

View file

@ -1,121 +1,126 @@
/* inflate.h -- internal inflate state definition /* inflate.h -- internal inflate state definition
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
#ifndef _INFLATE_H_ /* define NO_GZIP when compiling if you want to disable gzip header and
#define _INFLATE_H_ trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip decoding
/* define NO_GZIP when compiling if you want to disable gzip header and should be left enabled. */
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in #ifndef NO_GZIP
the crc code when it is not needed. For shared libraries, gzip decoding # define GUNZIP
should be left enabled. */ #endif
#ifndef NO_GZIP
# define GUNZIP /* Possible inflate modes between inflate() calls */
#endif typedef enum {
HEAD = 16180, /* i: waiting for magic header */
/* Possible inflate modes between inflate() calls */ FLAGS, /* i: waiting for method and flags (gzip) */
typedef enum { TIME, /* i: waiting for modification time (gzip) */
HEAD, /* i: waiting for magic header */ OS, /* i: waiting for extra flags and operating system (gzip) */
FLAGS, /* i: waiting for method and flags (gzip) */ EXLEN, /* i: waiting for extra length (gzip) */
TIME, /* i: waiting for modification time (gzip) */ EXTRA, /* i: waiting for extra bytes (gzip) */
OS, /* i: waiting for extra flags and operating system (gzip) */ NAME, /* i: waiting for end of file name (gzip) */
EXLEN, /* i: waiting for extra length (gzip) */ COMMENT, /* i: waiting for end of comment (gzip) */
EXTRA, /* i: waiting for extra bytes (gzip) */ HCRC, /* i: waiting for header crc (gzip) */
NAME, /* i: waiting for end of file name (gzip) */ DICTID, /* i: waiting for dictionary check value */
COMMENT, /* i: waiting for end of comment (gzip) */ DICT, /* waiting for inflateSetDictionary() call */
HCRC, /* i: waiting for header crc (gzip) */ TYPE, /* i: waiting for type bits, including last-flag bit */
DICTID, /* i: waiting for dictionary check value */ TYPEDO, /* i: same, but skip check to exit inflate on new block */
DICT, /* waiting for inflateSetDictionary() call */ STORED, /* i: waiting for stored size (length and complement) */
TYPE, /* i: waiting for type bits, including last-flag bit */ COPY_, /* i/o: same as COPY below, but only first time in */
TYPEDO, /* i: same, but skip check to exit inflate on new block */ COPY, /* i/o: waiting for input or output to copy stored block */
STORED, /* i: waiting for stored size (length and complement) */ TABLE, /* i: waiting for dynamic block table lengths */
COPY, /* i/o: waiting for input or output to copy stored block */ LENLENS, /* i: waiting for code length code lengths */
TABLE, /* i: waiting for dynamic block table lengths */ CODELENS, /* i: waiting for length/lit and distance code lengths */
LENLENS, /* i: waiting for code length code lengths */ LEN_, /* i: same as LEN below, but only first time in */
CODELENS, /* i: waiting for length/lit and distance code lengths */ LEN, /* i: waiting for length/lit/eob code */
LEN, /* i: waiting for length/lit code */ LENEXT, /* i: waiting for length extra bits */
LENEXT, /* i: waiting for length extra bits */ DIST, /* i: waiting for distance code */
DIST, /* i: waiting for distance code */ DISTEXT, /* i: waiting for distance extra bits */
DISTEXT, /* i: waiting for distance extra bits */ MATCH, /* o: waiting for output space to copy string */
MATCH, /* o: waiting for output space to copy string */ LIT, /* o: waiting for output space to write literal */
LIT, /* o: waiting for output space to write literal */ CHECK, /* i: waiting for 32-bit check value */
CHECK, /* i: waiting for 32-bit check value */ LENGTH, /* i: waiting for 32-bit length (gzip) */
LENGTH, /* i: waiting for 32-bit length (gzip) */ DONE, /* finished check, done -- remain here until reset */
DONE, /* finished check, done -- remain here until reset */ BAD, /* got a data error -- remain here until reset */
BAD, /* got a data error -- remain here until reset */ MEM, /* got an inflate() memory error -- remain here until reset */
MEM, /* got an inflate() memory error -- remain here until reset */ SYNC /* looking for synchronization bytes to restart inflate() */
SYNC /* looking for synchronization bytes to restart inflate() */ } inflate_mode;
} inflate_mode;
/*
/* State transitions between above modes -
State transitions between above modes -
(most modes can go to BAD or MEM on error -- not shown for clarity)
(most modes can go to the BAD or MEM mode -- not shown for clarity)
Process header:
Process header: HEAD -> (gzip) or (zlib) or (raw)
HEAD -> (gzip) or (zlib) (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME HCRC -> TYPE
NAME -> COMMENT -> HCRC -> TYPE (zlib) -> DICTID or TYPE
(zlib) -> DICTID or TYPE DICTID -> DICT -> TYPE
DICTID -> DICT -> TYPE (raw) -> TYPEDO
Read deflate blocks: Read deflate blocks:
TYPE -> STORED or TABLE or LEN or CHECK TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
STORED -> COPY -> TYPE STORED -> COPY_ -> COPY -> TYPE
TABLE -> LENLENS -> CODELENS -> LEN TABLE -> LENLENS -> CODELENS -> LEN_
Read deflate codes: LEN_ -> LEN
LEN -> LENEXT or LIT or TYPE Read deflate codes in fixed or dynamic block:
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN LEN -> LENEXT or LIT or TYPE
LIT -> LEN LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
Process trailer: LIT -> LEN
CHECK -> LENGTH -> DONE Process trailer:
*/ CHECK -> LENGTH -> DONE
*/
/* state maintained between inflate() calls. Approximately 7K bytes. */
struct inflate_state { /* State maintained between inflate() calls -- approximately 7K bytes, not
inflate_mode mode; /* current inflate mode */ including the allocated sliding window, which is up to 32K bytes. */
int last; /* true if processing last block */ struct inflate_state {
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ z_streamp strm; /* pointer back to this zlib stream */
int havedict; /* true if dictionary provided */ inflate_mode mode; /* current inflate mode */
int flags; /* gzip header method and flags (0 if zlib) */ int last; /* true if processing last block */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
unsigned long check; /* protected copy of check value */ bit 2 true to validate check value */
unsigned long total; /* protected copy of output count */ int havedict; /* true if dictionary provided */
gz_headerp head; /* where to save gzip header information */ int flags; /* gzip header method and flags, 0 if zlib, or
/* sliding window */ -1 if raw or no header yet */
unsigned wbits; /* log base 2 of requested window size */ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned wsize; /* window size or zero if not using window */ unsigned long check; /* protected copy of check value */
unsigned whave; /* valid bytes in the window */ unsigned long total; /* protected copy of output count */
unsigned write; /* window write index */ gz_headerp head; /* where to save gzip header information */
unsigned char FAR *window; /* allocated sliding window, if needed */ /* sliding window */
/* bit accumulator */ unsigned wbits; /* log base 2 of requested window size */
unsigned long hold; /* input bit accumulator */ unsigned wsize; /* window size or zero if not using window */
unsigned bits; /* number of bits in "in" */ unsigned whave; /* valid bytes in the window */
/* for string and stored block copying */ unsigned wnext; /* window write index */
unsigned length; /* literal or length of data to copy */ unsigned char FAR *window; /* allocated sliding window, if needed */
unsigned offset; /* distance back to copy string from */ /* bit accumulator */
/* for table and code decoding */ unsigned long hold; /* input bit accumulator */
unsigned extra; /* extra bits needed */ unsigned bits; /* number of bits in "in" */
/* fixed and dynamic code tables */ /* for string and stored block copying */
code const FAR *lencode; /* starting table for length/literal codes */ unsigned length; /* literal or length of data to copy */
code const FAR *distcode; /* starting table for distance codes */ unsigned offset; /* distance back to copy string from */
unsigned lenbits; /* index bits for lencode */ /* for table and code decoding */
unsigned distbits; /* index bits for distcode */ unsigned extra; /* extra bits needed */
/* dynamic table building */ /* fixed and dynamic code tables */
unsigned ncode; /* number of code length code lengths */ code const FAR *lencode; /* starting table for length/literal codes */
unsigned nlen; /* number of length code lengths */ code const FAR *distcode; /* starting table for distance codes */
unsigned ndist; /* number of distance code lengths */ unsigned lenbits; /* index bits for lencode */
unsigned have; /* number of code lengths in lens[] */ unsigned distbits; /* index bits for distcode */
code FAR *next; /* next available space in codes[] */ /* dynamic table building */
unsigned short lens[320]; /* temporary storage for code lengths */ unsigned ncode; /* number of code length code lengths */
unsigned short work[288]; /* work area for code table building */ unsigned nlen; /* number of length code lengths */
code codes[ENOUGH]; /* space for code tables */ unsigned ndist; /* number of distance code lengths */
}; unsigned have; /* number of code lengths in lens[] */
code FAR *next; /* next available space in codes[] */
unsigned short lens[320]; /* temporary storage for code lengths */
#endif unsigned short work[288]; /* work area for code table building */
code codes[ENOUGH]; /* space for code tables */
int sane; /* if false, allow invalid distance too far */
int back; /* bits back of last unprocessed length/lit */
unsigned was; /* initial length of match */
};

View file

@ -1,328 +1,299 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2005 Mark Adler * Copyright (C) 1995-2024 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.3 Copyright 1995-2005 Mark Adler "; " inflate 1.3.1 Copyright 1995-2024 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
include such an acknowledgment, I would appreciate that you keep this include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product. copyright string in the executable of your product.
*/ */
/* /*
Build a set of tables to decode the provided canonical Huffman code. Build a set of tables to decode the provided canonical Huffman code.
The code lengths are lens[0..codes-1]. The result starts at *table, The code lengths are lens[0..codes-1]. The result starts at *table,
whose indices are 0..2^bits-1. work is a writable array of at least whose indices are 0..2^bits-1. work is a writable array of at least
lens shorts, which is used as a work area. type is the type of code lens shorts, which is used as a work area. type is the type of code
to be generated, CODES, LENS, or DISTS. On return, zero is success, to be generated, CODES, LENS, or DISTS. On return, zero is success,
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
on return points to the next available entry's address. bits is the on return points to the next available entry's address. bits is the
requested root table index bits, and on return it is the actual root requested root table index bits, and on return it is the actual root
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int inflate_table (codetype type, int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
unsigned short FAR *lens, unsigned codes, code FAR * FAR *table,
unsigned codes, unsigned FAR *bits, unsigned short FAR *work) {
code FAR * FAR *table, unsigned len; /* a code's length in bits */
unsigned FAR *bits, unsigned sym; /* index of code symbols */
unsigned short FAR *work) unsigned min, max; /* minimum and maximum code lengths */
{ unsigned root; /* number of index bits for root table */
unsigned len; /* a code's length in bits */ unsigned curr; /* number of index bits for current table */
unsigned sym; /* index of code symbols */ unsigned drop; /* code bits to drop for sub-table */
unsigned min, max; /* minimum and maximum code lengths */ int left; /* number of prefix codes available */
unsigned root; /* number of index bits for root table */ unsigned used; /* code entries in table used */
unsigned curr; /* number of index bits for current table */ unsigned huff; /* Huffman code */
unsigned drop; /* code bits to drop for sub-table */ unsigned incr; /* for incrementing code, index */
int left; /* number of prefix codes available */ unsigned fill; /* index for replicating entries */
unsigned used; /* code entries in table used */ unsigned low; /* low bits for current root entry */
unsigned huff; /* Huffman code */ unsigned mask; /* mask for low root bits */
unsigned incr; /* for incrementing code, index */ code here; /* table entry for duplication */
unsigned fill; /* index for replicating entries */ code FAR *next; /* next available space in table */
unsigned low; /* low bits for current root entry */ const unsigned short FAR *base; /* base value table to use */
unsigned mask; /* mask for low root bits */ const unsigned short FAR *extra; /* extra bits table to use */
code thisx; /* table entry for duplication */ unsigned match; /* use base and extra for symbol >= match */
code FAR *next; /* next available space in table */ unsigned short count[MAXBITS+1]; /* number of codes of each length */
const unsigned short FAR *base; /* base value table to use */ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
const unsigned short FAR *extra; /* extra bits table to use */ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
int end; /* use base and extra for symbol > end */ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
unsigned short count[MAXBITS+1]; /* number of codes of each length */ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77};
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196}; 8193, 12289, 16385, 24577, 0, 0};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
8193, 12289, 16385, 24577, 0, 0}; 28, 28, 29, 29, 64, 64};
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, /*
23, 23, 24, 24, 25, 25, 26, 26, 27, 27, Process a set of code lengths to create a canonical Huffman code. The
28, 28, 29, 29, 64, 64}; code lengths are lens[0..codes-1]. Each length corresponds to the
symbols 0..codes-1. The Huffman code is generated by first sorting the
/* symbols by length from short to long, and retaining the symbol order
Process a set of code lengths to create a canonical Huffman code. The for codes with equal lengths. Then the code starts with all zero bits
code lengths are lens[0..codes-1]. Each length corresponds to the for the first code of the shortest length, and the codes are integer
symbols 0..codes-1. The Huffman code is generated by first sorting the increments for the same length, and zeros are appended as the length
symbols by length from short to long, and retaining the symbol order increases. For the deflate format, these bits are stored backwards
for codes with equal lengths. Then the code starts with all zero bits from their more natural integer increment ordering, and so when the
for the first code of the shortest length, and the codes are integer decoding tables are built in the large loop below, the integer codes
increments for the same length, and zeros are appended as the length are incremented backwards.
increases. For the deflate format, these bits are stored backwards
from their more natural integer increment ordering, and so when the This routine assumes, but does not check, that all of the entries in
decoding tables are built in the large loop below, the integer codes lens[] are in the range 0..MAXBITS. The caller must assure this.
are incremented backwards. 1..MAXBITS is interpreted as that code length. zero means that that
symbol does not occur in this code.
This routine assumes, but does not check, that all of the entries in
lens[] are in the range 0..MAXBITS. The caller must assure this. The codes are sorted by computing a count of codes for each length,
1..MAXBITS is interpreted as that code length. zero means that that creating from that a table of starting indices for each length in the
symbol does not occur in this code. sorted table, and then entering the symbols in order in the sorted
table. The sorted table is work[], with that space being provided by
The codes are sorted by computing a count of codes for each length, the caller.
creating from that a table of starting indices for each length in the
sorted table, and then entering the symbols in order in the sorted The length counts are used for other purposes as well, i.e. finding
table. The sorted table is work[], with that space being provided by the minimum and maximum length codes, determining if there are any
the caller. codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the
The length counts are used for other purposes as well, i.e. finding decoding tables.
the minimum and maximum length codes, determining if there are any */
codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
decoding tables. for (len = 0; len <= MAXBITS; len++)
*/ count[len] = 0;
for (sym = 0; sym < codes; sym++)
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ count[lens[sym]]++;
for (len = 0; len <= MAXBITS; len++)
count[len] = 0; /* bound code lengths, force root to be within code lengths */
for (sym = 0; sym < codes; sym++) root = *bits;
count[lens[sym]]++; for (max = MAXBITS; max >= 1; max--)
if (count[max] != 0) break;
/* bound code lengths, force root to be within code lengths */ if (root > max) root = max;
root = *bits; if (max == 0) { /* no symbols to code at all */
for (max = MAXBITS; max >= 1; max--) here.op = (unsigned char)64; /* invalid code marker */
if (count[max] != 0) break; here.bits = (unsigned char)1;
if (root > max) root = max; here.val = (unsigned short)0;
if (max == 0) { /* no symbols to code at all */ *(*table)++ = here; /* make a table to force an error */
thisx.op = (unsigned char)64; /* invalid code marker */ *(*table)++ = here;
thisx.bits = (unsigned char)1; *bits = 1;
thisx.val = (unsigned short)0; return 0; /* no symbols, but wait for decoding to report error */
*(*table)++ = thisx; /* make a table to force an error */ }
*(*table)++ = thisx; for (min = 1; min < max; min++)
*bits = 1; if (count[min] != 0) break;
return 0; /* no symbols, but wait for decoding to report error */ if (root < min) root = min;
}
for (min = 1; min <= MAXBITS; min++) /* check for an over-subscribed or incomplete set of lengths */
if (count[min] != 0) break; left = 1;
if (root < min) root = min; for (len = 1; len <= MAXBITS; len++) {
left <<= 1;
/* check for an over-subscribed or incomplete set of lengths */ left -= count[len];
left = 1; if (left < 0) return -1; /* over-subscribed */
for (len = 1; len <= MAXBITS; len++) { }
left <<= 1; if (left > 0 && (type == CODES || max != 1))
left -= count[len]; return -1; /* incomplete set */
if (left < 0) return -1; /* over-subscribed */
} /* generate offsets into symbol table for each length for sorting */
if (left > 0 && (type == CODES || max != 1)) offs[1] = 0;
return -1; /* incomplete set */ for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + count[len];
/* generate offsets into symbol table for each length for sorting */
offs[1] = 0; /* sort symbols by length, by symbol order within each length */
for (len = 1; len < MAXBITS; len++) for (sym = 0; sym < codes; sym++)
offs[len + 1] = offs[len] + count[len]; if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
/* sort symbols by length, by symbol order within each length */ /*
for (sym = 0; sym < codes; sym++) Create and fill in decoding tables. In this loop, the table being
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; filled is at next and has curr index bits. The code being used is huff
with length len. That code is converted to an index by dropping drop
/* bits off of the bottom. For codes where len is less than drop + curr,
Create and fill in decoding tables. In this loop, the table being those top drop + curr - len bits are incremented through all values to
filled is at next and has curr index bits. The code being used is huff fill the table with replicated entries.
with length len. That code is converted to an index by dropping drop
bits off of the bottom. For codes where len is less than drop + curr, root is the number of index bits for the root table. When len exceeds
those top drop + curr - len bits are incremented through all values to root, sub-tables are created pointed to by the root entry with an index
fill the table with replicated entries. of the low root bits of huff. This is saved in low to check for when a
new sub-table should be started. drop is zero when the root table is
root is the number of index bits for the root table. When len exceeds being filled, and drop is root when sub-tables are being filled.
root, sub-tables are created pointed to by the root entry with an index
of the low root bits of huff. This is saved in low to check for when a When a new sub-table is needed, it is necessary to look ahead in the
new sub-table should be started. drop is zero when the root table is code lengths to determine what size sub-table is needed. The length
being filled, and drop is root when sub-tables are being filled. counts are used for this, and so count[] is decremented as codes are
entered in the tables.
When a new sub-table is needed, it is necessary to look ahead in the
code lengths to determine what size sub-table is needed. The length used keeps track of how many table entries have been allocated from the
counts are used for this, and so count[] is decremented as codes are provided *table space. It is checked for LENS and DIST tables against
entered in the tables. the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
the initial root table size constants. See the comments in inftrees.h
used keeps track of how many table entries have been allocated from the for more information.
provided *table space. It is checked when a LENS table is being made
against the space in *table, ENOUGH, minus the maximum space needed by sym increments through all symbols, and the loop terminates when
the worst case distance code, MAXD. This should never happen, but the all codes of length max, i.e. all codes, have been processed. This
sufficiency of ENOUGH has not been proven exhaustively, hence the check. routine permits incomplete codes, so another loop after this one fills
This assumes that when type == LENS, bits == 9. in the rest of the decoding tables with invalid code markers.
*/
sym increments through all symbols, and the loop terminates when
all codes of length max, i.e. all codes, have been processed. This /* set up for code type */
routine permits incomplete codes, so another loop after this one fills switch (type) {
in the rest of the decoding tables with invalid code markers. case CODES:
*/ base = extra = work; /* dummy value--not used */
match = 20;
/* set up for code type */ break;
switch (type) { case LENS:
case CODES: base = lbase;
base = extra = work; /* dummy value--not used */ extra = lext;
end = 19; match = 257;
break; break;
case LENS: default: /* DISTS */
base = lbase; base = dbase;
base -= 257; extra = dext;
extra = lext; match = 0;
extra -= 257; }
end = 256;
break; /* initialize state for loop */
default: /* DISTS */ huff = 0; /* starting code */
base = dbase; sym = 0; /* starting code symbol */
extra = dext; len = min; /* starting code length */
end = -1; next = *table; /* current table to fill in */
} curr = root; /* current table index bits */
drop = 0; /* current bits to drop from code for index */
/* initialize state for loop */ low = (unsigned)(-1); /* trigger new sub-table when len > root */
huff = 0; /* starting code */ used = 1U << root; /* use root table entries */
sym = 0; /* starting code symbol */ mask = used - 1; /* mask for comparing low */
len = min; /* starting code length */
next = *table; /* current table to fill in */ /* check available table space */
curr = root; /* current table index bits */ if ((type == LENS && used > ENOUGH_LENS) ||
drop = 0; /* current bits to drop from code for index */ (type == DISTS && used > ENOUGH_DISTS))
low = (unsigned)(-1); /* trigger new sub-table when len > root */ return 1;
used = 1U << root; /* use root table entries */
mask = used - 1; /* mask for comparing low */ /* process all codes and make table entries */
for (;;) {
/* check available table space */ /* create table entry */
if (type == LENS && used >= ENOUGH - MAXD) here.bits = (unsigned char)(len - drop);
return 1; if (work[sym] + 1U < match) {
here.op = (unsigned char)0;
/* process all codes and make table entries */ here.val = work[sym];
for (;;) { }
/* create table entry */ else if (work[sym] >= match) {
thisx.bits = (unsigned char)(len - drop); here.op = (unsigned char)(extra[work[sym] - match]);
if ((int)(work[sym]) < end) { here.val = base[work[sym] - match];
thisx.op = (unsigned char)0; }
thisx.val = work[sym]; else {
} here.op = (unsigned char)(32 + 64); /* end of block */
else if ((int)(work[sym]) > end) { here.val = 0;
thisx.op = (unsigned char)(extra[work[sym]]); }
thisx.val = base[work[sym]];
} /* replicate for those indices with low len bits equal to huff */
else { incr = 1U << (len - drop);
thisx.op = (unsigned char)(32 + 64); /* end of block */ fill = 1U << curr;
thisx.val = 0; min = fill; /* save offset to next table */
} do {
fill -= incr;
/* replicate for those indices with low len bits equal to huff */ next[(huff >> drop) + fill] = here;
incr = 1U << (len - drop); } while (fill != 0);
fill = 1U << curr;
min = fill; /* save offset to next table */ /* backwards increment the len-bit code huff */
do { incr = 1U << (len - 1);
fill -= incr; while (huff & incr)
next[(huff >> drop) + fill] = thisx; incr >>= 1;
} while (fill != 0); if (incr != 0) {
huff &= incr - 1;
/* backwards increment the len-bit code huff */ huff += incr;
incr = 1U << (len - 1); }
while (huff & incr) else
incr >>= 1; huff = 0;
if (incr != 0) {
huff &= incr - 1; /* go to next symbol, update count, len */
huff += incr; sym++;
} if (--(count[len]) == 0) {
else if (len == max) break;
huff = 0; len = lens[work[sym]];
}
/* go to next symbol, update count, len */
sym++; /* create new sub-table if needed */
if (--(count[len]) == 0) { if (len > root && (huff & mask) != low) {
if (len == max) break; /* if first time, transition to sub-tables */
len = lens[work[sym]]; if (drop == 0)
} drop = root;
/* create new sub-table if needed */ /* increment past last table */
if (len > root && (huff & mask) != low) { next += min; /* here min is 1 << curr */
/* if first time, transition to sub-tables */
if (drop == 0) /* determine length of next table */
drop = root; curr = len - drop;
left = (int)(1 << curr);
/* increment past last table */ while (curr + drop < max) {
next += min; /* here min is 1 << curr */ left -= count[curr + drop];
if (left <= 0) break;
/* determine length of next table */ curr++;
curr = len - drop; left <<= 1;
left = (int)(1 << curr); }
while (curr + drop < max) {
left -= count[curr + drop]; /* check for enough space */
if (left <= 0) break; used += 1U << curr;
curr++; if ((type == LENS && used > ENOUGH_LENS) ||
left <<= 1; (type == DISTS && used > ENOUGH_DISTS))
} return 1;
/* check for enough space */ /* point entry in root table to sub-table */
used += 1U << curr; low = huff & mask;
if (type == LENS && used >= ENOUGH - MAXD) (*table)[low].op = (unsigned char)curr;
return 1; (*table)[low].bits = (unsigned char)root;
(*table)[low].val = (unsigned short)(next - *table);
/* point entry in root table to sub-table */ }
low = huff & mask; }
(*table)[low].op = (unsigned char)curr;
(*table)[low].bits = (unsigned char)root; /* fill in remaining table entry if code is incomplete (guaranteed to have
(*table)[low].val = (unsigned short)(next - *table); at most one remaining entry, since if the code is incomplete, the
} maximum code length that was allowed to get this far is one bit) */
} if (huff != 0) {
here.op = (unsigned char)64; /* invalid code marker */
/* here.bits = (unsigned char)(len - drop);
Fill in rest of table for incomplete codes. This loop is similar to the here.val = (unsigned short)0;
loop above in incrementing huff for table indices. It is assumed that next[huff] = here;
len is equal to curr + drop, so there is no loop needed to increment }
through high index bits. When the current sub-table is filled, the loop
drops back to the root table to fill in any remaining entries there. /* set return parameters */
*/ *table += used;
thisx.op = (unsigned char)64; /* invalid code marker */ *bits = root;
thisx.bits = (unsigned char)(len - drop); return 0;
thisx.val = (unsigned short)0; }
while (huff != 0) {
/* when done with sub-table, drop back to root table */
if (drop != 0 && (huff & mask) != low) {
drop = 0;
len = root;
next = *table;
thisx.bits = (unsigned char)len;
}
/* put invalid code marker in table */
next[huff >> drop] = thisx;
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
incr >>= 1;
if (incr != 0) {
huff &= incr - 1;
huff += incr;
}
else
huff = 0;
}
/* set return parameters */
*table += used;
*bits = root;
return 0;
}

View file

@ -1,61 +1,62 @@
/* inftrees.h -- header to use inftrees.c /* inftrees.h -- header to use inftrees.c
* Copyright (C) 1995-2005 Mark Adler * Copyright (C) 1995-2005, 2010 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
#ifndef _INFTREES_H_ /* Structure for decoding tables. Each entry provides either the
#define _INFTREES_H_ information needed to do the operation requested by the code that
indexed that table entry, or it provides a pointer to another
/* Structure for decoding tables. Each entry provides either the table that indexes more bits of the code. op indicates whether
information needed to do the operation requested by the code that the entry is a pointer to another table, a literal, a length or
indexed that table entry, or it provides a pointer to another distance, an end-of-block, or an invalid code. For a table
table that indexes more bits of the code. op indicates whether pointer, the low four bits of op is the number of index bits of
the entry is a pointer to another table, a literal, a length or that table. For a length or distance, the low four bits of op
distance, an end-of-block, or an invalid code. For a table is the number of extra bits to get after the code. bits is
pointer, the low four bits of op is the number of index bits of the number of bits in this code or part of the code to drop off
that table. For a length or distance, the low four bits of op of the bit buffer. val is the actual byte to output in the case
is the number of extra bits to get after the code. bits is of a literal, the base length or distance, or the offset from
the number of bits in this code or part of the code to drop off the current table to the next table. Each entry is four bytes. */
of the bit buffer. val is the actual byte to output in the case typedef struct {
of a literal, the base length or distance, or the offset from unsigned char op; /* operation, extra bits, table bits */
the current table to the next table. Each entry is four bytes. */ unsigned char bits; /* bits in this part of the code */
typedef struct { unsigned short val; /* offset in table or code value */
unsigned char op; /* operation, extra bits, table bits */ } code;
unsigned char bits; /* bits in this part of the code */
unsigned short val; /* offset in table or code value */ /* op values as set by inflate_table():
} code; 00000000 - literal
0000tttt - table link, tttt != 0 is the number of table index bits
/* op values as set by inflate_table(): 0001eeee - length or distance, eeee is the number of extra bits
00000000 - literal 01100000 - end of block
0000tttt - table link, tttt != 0 is the number of table index bits 01000000 - invalid code
0001eeee - length or distance, eeee is the number of extra bits */
01100000 - end of block
01000000 - invalid code /* Maximum size of the dynamic table. The maximum number of code structures is
*/ 1444, which is the sum of 852 for literal/length codes and 592 for distance
codes. These values were found by exhaustive searches using the program
/* Maximum size of dynamic tree. The maximum found in a long but non- examples/enough.c found in the zlib distribution. The arguments to that
exhaustive search was 1444 code structures (852 for length/literals program are the number of symbols, the initial root table size, and the
and 592 for distances, the latter actually the result of an maximum bit length of a code. "enough 286 9 15" for literal/length codes
exhaustive search). The true maximum is not known, but the value returns 852, and "enough 30 6 15" for distance codes returns 592. The
below is more than safe. */ initial root table size (9 or 6) is found in the fifth argument of the
#define ENOUGH 2048 inflate_table() calls in inflate.c and infback.c. If the root table size is
#define MAXD 592 changed, then these maximum sizes would be need to be recalculated and
updated. */
/* Type of code to build for inftable() */ #define ENOUGH_LENS 852
typedef enum { #define ENOUGH_DISTS 592
CODES, #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
LENS,
DISTS /* Type of code to build for inflate_table() */
} codetype; typedef enum {
CODES,
extern int inflate_table OF((codetype type, unsigned short FAR *lens, LENS,
unsigned codes, code FAR * FAR *table, DISTS
unsigned FAR *bits, unsigned short FAR *work)); } codetype;
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
#endif unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work);

File diff suppressed because it is too large Load diff

View file

@ -1,127 +1,128 @@
/* header created automatically with -DGEN_TREES_H */ /* header created automatically with -DGEN_TREES_H */
local const ct_data static_ltree[L_CODES+2] = { local const ct_data static_ltree[L_CODES+2] = {
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
}; };
local const ct_data static_dtree[D_CODES] = { local const ct_data static_dtree[D_CODES] = {
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
}; };
const uch _dist_code[DIST_CODE_LEN] = { const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
}; };
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
}; };
local const int base_length[LENGTH_CODES] = { local const int base_length[LENGTH_CODES] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
64, 80, 96, 112, 128, 160, 192, 224, 0 64, 80, 96, 112, 128, 160, 192, 224, 0
}; };
local const int base_dist[D_CODES] = { local const int base_dist[D_CODES] = {
0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
}; };

View file

@ -1,60 +1,85 @@
/* uncompr.c -- decompress a memory buffer /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly. * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id: uncompr.c,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
/* =========================================================================== /* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is Decompresses the source buffer into the destination buffer. *sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total the byte length of the source buffer. Upon entry, *destLen is the total size
size of the destination buffer, which must be large enough to hold the of the destination buffer, which must be large enough to hold the entire
entire uncompressed data. (The size of the uncompressed data must have uncompressed data. (The size of the uncompressed data must have been saved
been saved previously by the compressor and transmitted to the decompressor previously by the compressor and transmitted to the decompressor by some
by some mechanism outside the scope of this compression library.) mechanism outside the scope of this compression library.) Upon exit,
Upon exit, destLen is the actual size of the compressed buffer. *destLen is the size of the decompressed data and *sourceLen is the number
This function can be used to decompress a whole file at once if the of source bytes consumed. Upon return, source + *sourceLen points to the
input file is mmap'ed. first unused input byte.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
enough memory, Z_BUF_ERROR if there was not enough room in the output memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
buffer, or Z_DATA_ERROR if the input data was corrupted. Z_DATA_ERROR if the input data was corrupted, including if the input data is
*/ an incomplete zlib stream.
int ZEXPORT uncompress (Bytef *dest, */
uLongf *destLen, int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
const Bytef *source, uLong *sourceLen) {
uLong sourceLen) z_stream stream;
{ int err;
z_stream stream; const uInt max = (uInt)-1;
int err; uLong len, left;
Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen; len = *sourceLen;
/* Check for source > 64K on 16-bit machine: */ if (*destLen) {
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; left = *destLen;
*destLen = 0;
stream.next_out = dest; }
stream.avail_out = (uInt)*destLen; else {
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; left = 1;
dest = buf;
stream.zalloc = (alloc_func)0; }
stream.zfree = (free_func)0;
stream.next_in = (z_const Bytef *)source;
err = inflateInit(&stream); stream.avail_in = 0;
if (err != Z_OK) return err; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
err = inflate(&stream, Z_FINISH); stream.opaque = (voidpf)0;
if (err != Z_STREAM_END) {
inflateEnd(&stream); err = inflateInit(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) if (err != Z_OK) return err;
return Z_DATA_ERROR;
return err; stream.next_out = dest;
} stream.avail_out = 0;
*destLen = stream.total_out;
do {
err = inflateEnd(&stream); if (stream.avail_out == 0) {
return err; stream.avail_out = left > (uLong)max ? max : (uInt)left;
} left -= stream.avail_out;
}
if (stream.avail_in == 0) {
stream.avail_in = len > (uLong)max ? max : (uInt)len;
len -= stream.avail_in;
}
err = inflate(&stream, Z_NO_FLUSH);
} while (err == Z_OK);
*sourceLen -= len + stream.avail_in;
if (dest != buf)
*destLen = stream.total_out;
else if (stream.total_out && err == Z_BUF_ERROR)
left = 1;
inflateEnd(&stream);
return err == Z_STREAM_END ? Z_OK :
err == Z_NEED_DICT ? Z_DATA_ERROR :
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
err;
}
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen) {
return uncompress2(dest, destLen, source, &sourceLen);
}

View file

@ -1,345 +1,543 @@
/* zconf.h -- configuration of the zlib compression library /* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id: zconf.h,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#ifndef ZCONF_H #ifndef ZCONF_H
#define ZCONF_H #define ZCONF_H
// *** Just a few hacks here to make it compile nicely with Juce.. /*
#define Z_PREFIX 1 * If you *really* need a unique prefix for all types and library functions,
#undef __MACTYPES__ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
* Even better than compiling with -DZ_PREFIX would be to use configure to set
#ifdef _MSC_VER * this permanently in zconf.h using "./configure --zprefix".
#pragma warning (disable : 4131 4127 4244 4267) */
#endif #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
# define Z_PREFIX_SET
/* /* all linked symbols and init macros */
* If you *really* need a unique prefix for all types and library functions, # define _dist_code z__dist_code
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. # define _length_code z__length_code
*/ # define _tr_align z__tr_align
#ifdef Z_PREFIX # define _tr_flush_bits z__tr_flush_bits
# define deflateInit_ z_deflateInit_ # define _tr_flush_block z__tr_flush_block
# define deflate z_deflate # define _tr_init z__tr_init
# define deflateEnd z_deflateEnd # define _tr_stored_block z__tr_stored_block
# define inflateInit_ z_inflateInit_ # define _tr_tally z__tr_tally
# define inflate z_inflate # define adler32 z_adler32
# define inflateEnd z_inflateEnd # define adler32_combine z_adler32_combine
# define inflatePrime z_inflatePrime # define adler32_combine64 z_adler32_combine64
# define inflateGetHeader z_inflateGetHeader # define adler32_z z_adler32_z
# define adler32_combine z_adler32_combine # ifndef Z_SOLO
# define crc32_combine z_crc32_combine # define compress z_compress
# define deflateInit2_ z_deflateInit2_ # define compress2 z_compress2
# define deflateSetDictionary z_deflateSetDictionary # define compressBound z_compressBound
# define deflateCopy z_deflateCopy # endif
# define deflateReset z_deflateReset # define crc32 z_crc32
# define deflateParams z_deflateParams # define crc32_combine z_crc32_combine
# define deflateBound z_deflateBound # define crc32_combine64 z_crc32_combine64
# define deflatePrime z_deflatePrime # define crc32_combine_gen z_crc32_combine_gen
# define inflateInit2_ z_inflateInit2_ # define crc32_combine_gen64 z_crc32_combine_gen64
# define inflateSetDictionary z_inflateSetDictionary # define crc32_combine_op z_crc32_combine_op
# define inflateSync z_inflateSync # define crc32_z z_crc32_z
# define inflateSyncPoint z_inflateSyncPoint # define deflate z_deflate
# define inflateCopy z_inflateCopy # define deflateBound z_deflateBound
# define inflateReset z_inflateReset # define deflateCopy z_deflateCopy
# define inflateBack z_inflateBack # define deflateEnd z_deflateEnd
# define inflateBackEnd z_inflateBackEnd # define deflateGetDictionary z_deflateGetDictionary
# define compress z_compress # define deflateInit z_deflateInit
# define compress2 z_compress2 # define deflateInit2 z_deflateInit2
# define compressBound z_compressBound # define deflateInit2_ z_deflateInit2_
# define uncompress z_uncompress # define deflateInit_ z_deflateInit_
# define adler32 z_adler32 # define deflateParams z_deflateParams
# define crc32 z_crc32 # define deflatePending z_deflatePending
# define get_crc_table z_get_crc_table # define deflatePrime z_deflatePrime
# define zError z_zError # define deflateReset z_deflateReset
# define deflateResetKeep z_deflateResetKeep
# define alloc_func z_alloc_func # define deflateSetDictionary z_deflateSetDictionary
# define free_func z_free_func # define deflateSetHeader z_deflateSetHeader
# define in_func z_in_func # define deflateTune z_deflateTune
# define out_func z_out_func # define deflate_copyright z_deflate_copyright
# define Byte z_Byte # define get_crc_table z_get_crc_table
# define uInt z_uInt # ifndef Z_SOLO
# define uLong z_uLong # define gz_error z_gz_error
# define Bytef z_Bytef # define gz_intmax z_gz_intmax
# define charf z_charf # define gz_strwinerror z_gz_strwinerror
# define intf z_intf # define gzbuffer z_gzbuffer
# define uIntf z_uIntf # define gzclearerr z_gzclearerr
# define uLongf z_uLongf # define gzclose z_gzclose
# define voidpf z_voidpf # define gzclose_r z_gzclose_r
# define voidp z_voidp # define gzclose_w z_gzclose_w
#endif # define gzdirect z_gzdirect
# define gzdopen z_gzdopen
#if defined(__MSDOS__) && !defined(MSDOS) # define gzeof z_gzeof
# define MSDOS # define gzerror z_gzerror
#endif # define gzflush z_gzflush
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) # define gzfread z_gzfread
# define OS2 # define gzfwrite z_gzfwrite
#endif # define gzgetc z_gzgetc
#if defined(_WINDOWS) && !defined(WINDOWS) # define gzgetc_ z_gzgetc_
# define WINDOWS # define gzgets z_gzgets
#endif # define gzoffset z_gzoffset
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) # define gzoffset64 z_gzoffset64
# ifndef WIN32 # define gzopen z_gzopen
# define WIN32 # define gzopen64 z_gzopen64
# endif # ifdef _WIN32
#endif # define gzopen_w z_gzopen_w
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) # endif
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) # define gzprintf z_gzprintf
# ifndef SYS16BIT # define gzputc z_gzputc
# define SYS16BIT # define gzputs z_gzputs
# endif # define gzread z_gzread
# endif # define gzrewind z_gzrewind
#endif # define gzseek z_gzseek
# define gzseek64 z_gzseek64
/* # define gzsetparams z_gzsetparams
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more # define gztell z_gztell
* than 64k bytes at a time (needed on systems with 16-bit int). # define gztell64 z_gztell64
*/ # define gzungetc z_gzungetc
#ifdef SYS16BIT # define gzvprintf z_gzvprintf
# define MAXSEG_64K # define gzwrite z_gzwrite
#endif # endif
#ifdef MSDOS # define inflate z_inflate
# define UNALIGNED_OK # define inflateBack z_inflateBack
#endif # define inflateBackEnd z_inflateBackEnd
# define inflateBackInit z_inflateBackInit
#ifdef __STDC_VERSION__ # define inflateBackInit_ z_inflateBackInit_
# ifndef STDC # define inflateCodesUsed z_inflateCodesUsed
# define STDC # define inflateCopy z_inflateCopy
# endif # define inflateEnd z_inflateEnd
# if __STDC_VERSION__ >= 199901L # define inflateGetDictionary z_inflateGetDictionary
# ifndef STDC99 # define inflateGetHeader z_inflateGetHeader
# define STDC99 # define inflateInit z_inflateInit
# endif # define inflateInit2 z_inflateInit2
# endif # define inflateInit2_ z_inflateInit2_
#endif # define inflateInit_ z_inflateInit_
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) # define inflateMark z_inflateMark
# define STDC # define inflatePrime z_inflatePrime
#endif # define inflateReset z_inflateReset
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) # define inflateReset2 z_inflateReset2
# define STDC # define inflateResetKeep z_inflateResetKeep
#endif # define inflateSetDictionary z_inflateSetDictionary
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) # define inflateSync z_inflateSync
# define STDC # define inflateSyncPoint z_inflateSyncPoint
#endif # define inflateUndermine z_inflateUndermine
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) # define inflateValidate z_inflateValidate
# define STDC # define inflate_copyright z_inflate_copyright
#endif # define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ # ifndef Z_SOLO
# define STDC # define uncompress z_uncompress
#endif # define uncompress2 z_uncompress2
# endif
#ifndef STDC # define zError z_zError
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ # ifndef Z_SOLO
# define const /* note: need a more gentle solution here */ # define zcalloc z_zcalloc
# endif # define zcfree z_zcfree
#endif # endif
# define zlibCompileFlags z_zlibCompileFlags
/* Some Mac compilers merge all .h files incorrectly: */ # define zlibVersion z_zlibVersion
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL /* all zlib typedefs in zlib.h and zconf.h */
#endif # define Byte z_Byte
# define Bytef z_Bytef
/* Maximum value for memLevel in deflateInit2 */ # define alloc_func z_alloc_func
#ifndef MAX_MEM_LEVEL # define charf z_charf
# ifdef MAXSEG_64K # define free_func z_free_func
# define MAX_MEM_LEVEL 8 # ifndef Z_SOLO
# else # define gzFile z_gzFile
# define MAX_MEM_LEVEL 9 # endif
# endif # define gz_header z_gz_header
#endif # define gz_headerp z_gz_headerp
# define in_func z_in_func
/* Maximum value for windowBits in deflateInit2 and inflateInit2. # define intf z_intf
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files # define out_func z_out_func
* created by gzip. (Files created by minigzip can still be extracted by # define uInt z_uInt
* gzip.) # define uIntf z_uIntf
*/ # define uLong z_uLong
#ifndef MAX_WBITS # define uLongf z_uLongf
# define MAX_WBITS 15 /* 32K LZ77 window */ # define voidp z_voidp
#endif # define voidpc z_voidpc
# define voidpf z_voidpf
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9)) /* all zlib structs in zlib.h and zconf.h */
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) # define gz_header_s z_gz_header_s
plus a few kilobytes for small objects. For example, if you want to reduce # define internal_state z_internal_state
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" #endif
Of course this will generally degrade compression (there's no free lunch).
#if defined(__MSDOS__) && !defined(MSDOS)
The memory requirements for inflate are (in bytes) 1 << windowBits # define MSDOS
that is, 32K for windowBits=15 (default value) plus a few kilobytes #endif
for small objects. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
*/ # define OS2
#endif
/* Type declarations */ #if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#ifndef OF /* function prototypes */ #endif
# ifdef STDC #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
# define OF(args) args # ifndef WIN32
# else # define WIN32
# define OF(args) () # endif
# endif #endif
#endif #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
/* The following definitions for FAR are needed only for MSDOS mixed # ifndef SYS16BIT
* model programming (small or medium model with some far allocations). # define SYS16BIT
* This was tested only with MSC; for other MSDOS compilers you may have # endif
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model, # endif
* just define FAR to be empty. #endif
*/
#ifdef SYS16BIT /*
# if defined(M_I86SM) || defined(M_I86MM) * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
/* MSC small or medium model */ * than 64k bytes at a time (needed on systems with 16-bit int).
# define SMALL_MEDIUM */
# ifdef _MSC_VER #ifdef SYS16BIT
# define FAR _far # define MAXSEG_64K
# else #endif
# define FAR far #ifdef MSDOS
# endif # define UNALIGNED_OK
# endif #endif
# if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */ #ifdef __STDC_VERSION__
# define SMALL_MEDIUM # ifndef STDC
# ifdef __BORLANDC__ # define STDC
# define FAR _far # endif
# else # if __STDC_VERSION__ >= 199901L
# define FAR far # ifndef STDC99
# endif # define STDC99
# endif # endif
#endif # endif
#endif
#if defined(WINDOWS) || defined(WIN32) #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
/* If building or using zlib as a DLL, define ZLIB_DLL. # define STDC
* This is not mandatory, but it offers a little performance increase. #endif
*/ #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
# ifdef ZLIB_DLL # define STDC
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) #endif
# ifdef ZLIB_INTERNAL #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
# define ZEXTERN extern __declspec(dllexport) # define STDC
# else #endif
# define ZEXTERN extern __declspec(dllimport) #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# endif # define STDC
# endif #endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention, #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
* define ZLIB_WINAPI. # define STDC
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. #endif
*/
# ifdef ZLIB_WINAPI #ifndef STDC
# ifdef FAR # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# undef FAR # define const /* note: need a more gentle solution here */
# endif # endif
# include <windows.h> #endif
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ #if defined(ZLIB_CONST) && !defined(z_const)
# define ZEXPORT WINAPI # define z_const const
# ifdef WIN32 #else
# define ZEXPORTVA WINAPIV # define z_const
# else #endif
# define ZEXPORTVA FAR CDECL
# endif #ifdef Z_SOLO
# endif # ifdef _WIN64
#endif typedef unsigned long long z_size_t;
# else
#if defined (__BEOS__) typedef unsigned long z_size_t;
# ifdef ZLIB_DLL # endif
# ifdef ZLIB_INTERNAL #else
# define ZEXPORT __declspec(dllexport) # define z_longlong long long
# define ZEXPORTVA __declspec(dllexport) # if defined(NO_SIZE_T)
# else typedef unsigned NO_SIZE_T z_size_t;
# define ZEXPORT __declspec(dllimport) # elif defined(STDC)
# define ZEXPORTVA __declspec(dllimport) # include <stddef.h>
# endif typedef size_t z_size_t;
# endif # else
#endif typedef unsigned long z_size_t;
# endif
#ifndef ZEXTERN # undef z_longlong
# define ZEXTERN extern #endif
#endif
#ifndef ZEXPORT /* Maximum value for memLevel in deflateInit2 */
# define ZEXPORT #ifndef MAX_MEM_LEVEL
#endif # ifdef MAXSEG_64K
#ifndef ZEXPORTVA # define MAX_MEM_LEVEL 8
# define ZEXPORTVA # else
#endif # define MAX_MEM_LEVEL 9
# endif
#ifndef FAR #endif
# define FAR
#endif /* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
#if !defined(__MACTYPES__) * created by gzip. (Files created by minigzip can still be extracted by
typedef unsigned char Byte; /* 8 bits */ * gzip.)
#endif */
typedef unsigned int uInt; /* 16 bits or more */ #ifndef MAX_WBITS
typedef unsigned long uLong; /* 32 bits or more */ # define MAX_WBITS 15 /* 32K LZ77 window */
#endif
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ /* The memory requirements for deflate are (in bytes):
# define Bytef Byte FAR (1 << (windowBits+2)) + (1 << (memLevel+9))
#else that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
typedef Byte FAR Bytef; plus a few kilobytes for small objects. For example, if you want to reduce
#endif the default memory requirements from 256K to 128K, compile with
typedef char FAR charf; make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
typedef int FAR intf; Of course this will generally degrade compression (there's no free lunch).
typedef uInt FAR uIntf;
typedef uLong FAR uLongf; The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
#ifdef STDC for small objects.
typedef void const *voidpc; */
typedef void FAR *voidpf;
typedef void *voidp; /* Type declarations */
#else
typedef Byte const *voidpc; #ifndef OF /* function prototypes */
typedef Byte FAR *voidpf; # ifdef STDC
typedef Byte *voidp; # define OF(args) args
#endif # else
# define OF(args) ()
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ # endif
# include <sys/types.h> /* for off_t */ #endif
# include <unistd.h> /* for SEEK_* and off_t */
# ifdef VMS /* The following definitions for FAR are needed only for MSDOS mixed
# include <unixio.h> /* for off_t */ * model programming (small or medium model with some far allocations).
# endif * This was tested only with MSC; for other MSDOS compilers you may have
# define z_off_t off_t * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
#endif * just define FAR to be empty.
#ifndef SEEK_SET */
# define SEEK_SET 0 /* Seek from beginning of file. */ #ifdef SYS16BIT
# define SEEK_CUR 1 /* Seek from current position. */ # if defined(M_I86SM) || defined(M_I86MM)
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ /* MSC small or medium model */
#endif # define SMALL_MEDIUM
#ifndef z_off_t # ifdef _MSC_VER
# define z_off_t long # define FAR _far
#endif # else
# define FAR far
#if defined(__OS400__) # endif
# define NO_vsnprintf # endif
#endif # if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */
#if defined(__MVS__) # define SMALL_MEDIUM
# define NO_vsnprintf # ifdef __BORLANDC__
# ifdef FAR # define FAR _far
# undef FAR # else
# endif # define FAR far
#endif # endif
# endif
/* MVS linker does not support external names larger than 8 bytes */ #endif
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN") #if defined(WINDOWS) || defined(WIN32)
# pragma map(deflateInit2_,"DEIN2") /* If building or using zlib as a DLL, define ZLIB_DLL.
# pragma map(deflateEnd,"DEEND") * This is not mandatory, but it offers a little performance increase.
# pragma map(deflateBound,"DEBND") */
# pragma map(inflateInit_,"ININ") # ifdef ZLIB_DLL
# pragma map(inflateInit2_,"ININ2") # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# pragma map(inflateEnd,"INEND") # ifdef ZLIB_INTERNAL
# pragma map(inflateSync,"INSY") # define ZEXTERN extern __declspec(dllexport)
# pragma map(inflateSetDictionary,"INSEDI") # else
# pragma map(compressBound,"CMBND") # define ZEXTERN extern __declspec(dllimport)
# pragma map(inflate_table,"INTABL") # endif
# pragma map(inflate_fast,"INFA") # endif
# pragma map(inflate_copyright,"INCOPY") # endif /* ZLIB_DLL */
#endif /* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
#endif /* ZCONF_H */ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# ifdef FAR
# undef FAR
# endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR CDECL
# endif
# endif
#endif
#if defined (__BEOS__)
# ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL
# define ZEXPORT __declspec(dllexport)
# define ZEXPORTVA __declspec(dllexport)
# else
# define ZEXPORT __declspec(dllimport)
# define ZEXPORTVA __declspec(dllimport)
# endif
# endif
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void const *voidpc;
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte const *voidpc;
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
# if (UINT_MAX == 0xffffffffUL)
# define Z_U4 unsigned
# elif (ULONG_MAX == 0xffffffffUL)
# define Z_U4 unsigned long
# elif (USHRT_MAX == 0xffffffffUL)
# define Z_U4 unsigned short
# endif
#endif
#ifdef Z_U4
typedef Z_U4 z_crc_t;
#else
typedef unsigned long z_crc_t;
#endif
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
# define Z_HAVE_UNISTD_H
#endif
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
# define Z_HAVE_STDARG_H
#endif
#ifdef STDC
# ifndef Z_SOLO
# include <sys/types.h> /* for off_t */
# endif
#endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO
# include <stdarg.h> /* for va_list */
# endif
#endif
#ifdef _WIN32
# ifndef Z_SOLO
# include <stddef.h> /* for wchar_t */
# endif
#endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
* though the former does not conform to the LFS document), but considering
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
* equivalently requesting no 64-bit operations
*/
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
# undef _LARGEFILE64_SOURCE
#endif
#ifndef Z_HAVE_UNISTD_H
# ifdef __WATCOMC__
# define Z_HAVE_UNISTD_H
# endif
#endif
#ifndef Z_HAVE_UNISTD_H
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
# define Z_HAVE_UNISTD_H
# endif
#endif
#ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# ifdef VMS
# include <unixio.h> /* for off_t */
# endif
# ifndef z_off_t
# define z_off_t off_t
# endif
# endif
#endif
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
# define Z_LFS64
#endif
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
# define Z_LARGE64
#endif
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
# define Z_WANT64
#endif
#if !defined(SEEK_SET) && !defined(Z_SOLO)
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
#if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t
#else
# if defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64
# else
# define z_off64_t z_off_t
# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
#pragma map(deflateInit_,"DEIN")
#pragma map(deflateInit2_,"DEIN2")
#pragma map(deflateEnd,"DEEND")
#pragma map(deflateBound,"DEBND")
#pragma map(inflateInit_,"ININ")
#pragma map(inflateInit2_,"ININ2")
#pragma map(inflateEnd,"INEND")
#pragma map(inflateSync,"INSY")
#pragma map(inflateSetDictionary,"INSEDI")
#pragma map(compressBound,"CMBND")
#pragma map(inflate_table,"INTABL")
#pragma map(inflate_fast,"INFA")
#pragma map(inflate_copyright,"INCOPY")
#endif
#endif /* ZCONF_H */

View file

@ -1,332 +0,0 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id: zconf.in.h,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */
#ifndef ZCONF_H
#define ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define deflateBound z_deflateBound
# define deflatePrime z_deflatePrime
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateCopy z_inflateCopy
# define inflateReset z_inflateReset
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
# define compress z_compress
# define compress2 z_compress2
# define compressBound z_compressBound
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define zError z_zError
# define alloc_func z_alloc_func
# define free_func z_free_func
# define in_func z_in_func
# define out_func z_out_func
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
# define OS2
#endif
#if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#endif
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
# ifndef WIN32
# define WIN32
# endif
#endif
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
# ifndef SYS16BIT
# define SYS16BIT
# endif
# endif
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#ifdef SYS16BIT
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#ifdef __STDC_VERSION__
# ifndef STDC
# define STDC
# endif
# if __STDC_VERSION__ >= 199901L
# ifndef STDC99
# define STDC99
# endif
# endif
#endif
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
# define STDC
#endif
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
# define STDC
#endif
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
# define STDC
#endif
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# define STDC
#endif
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#ifdef SYS16BIT
# if defined(M_I86SM) || defined(M_I86MM)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
# endif
# if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */
# define SMALL_MEDIUM
# ifdef __BORLANDC__
# define FAR _far
# else
# define FAR far
# endif
# endif
#endif
#if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
# ifdef ZLIB_DLL
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR CDECL
# endif
# endif
#endif
#if defined (__BEOS__)
# ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL
# define ZEXPORT __declspec(dllexport)
# define ZEXPORTVA __declspec(dllexport)
# else
# define ZEXPORT __declspec(dllimport)
# define ZEXPORTVA __declspec(dllimport)
# endif
# endif
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void const *voidpc;
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte const *voidpc;
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# ifdef VMS
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
#if defined(__OS400__)
# define NO_vsnprintf
#endif
#if defined(__MVS__)
# define NO_vsnprintf
# ifdef FAR
# undef FAR
# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(deflateBound,"DEBND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(compressBound,"CMBND")
# pragma map(inflate_table,"INTABL")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_copyright,"INCOPY")
#endif
#endif /* ZCONF_H */

File diff suppressed because it is too large Load diff

View file

@ -1,311 +1,299 @@
/* zutil.c -- target dependent utility functions for the compression library /* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2017 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id: zutil.c,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#include "zutil.h" #include "zutil.h"
#ifndef Z_SOLO
#ifndef NO_DUMMY_DECL # include "gzguts.h"
struct internal_state {int dummy;}; /* for buggy compilers */ #endif
#endif
z_const char * const z_errmsg[10] = {
const char * const z_errmsg[10] = { (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
"need dictionary", /* Z_NEED_DICT 2 */ (z_const char *)"stream end", /* Z_STREAM_END 1 */
"stream end", /* Z_STREAM_END 1 */ (z_const char *)"", /* Z_OK 0 */
"", /* Z_OK 0 */ (z_const char *)"file error", /* Z_ERRNO (-1) */
"file error", /* Z_ERRNO (-1) */ (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
"stream error", /* Z_STREAM_ERROR (-2) */ (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
"data error", /* Z_DATA_ERROR (-3) */ (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
"insufficient memory", /* Z_MEM_ERROR (-4) */ (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
"buffer error", /* Z_BUF_ERROR (-5) */ (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
"incompatible version",/* Z_VERSION_ERROR (-6) */ (z_const char *)""
""}; };
/*const char * ZEXPORT zlibVersion() const char * ZEXPORT zlibVersion(void) {
{ return ZLIB_VERSION;
return ZLIB_VERSION; }
}
uLong ZEXPORT zlibCompileFlags(void) {
uLong ZEXPORT zlibCompileFlags() uLong flags;
{
uLong flags; flags = 0;
switch ((int)(sizeof(uInt))) {
flags = 0; case 2: break;
switch (sizeof(uInt)) { case 4: flags += 1; break;
case 2: break; case 8: flags += 2; break;
case 4: flags += 1; break; default: flags += 3;
case 8: flags += 2; break; }
default: flags += 3; switch ((int)(sizeof(uLong))) {
} case 2: break;
switch (sizeof(uLong)) { case 4: flags += 1 << 2; break;
case 2: break; case 8: flags += 2 << 2; break;
case 4: flags += 1 << 2; break; default: flags += 3 << 2;
case 8: flags += 2 << 2; break; }
default: flags += 3 << 2; switch ((int)(sizeof(voidpf))) {
} case 2: break;
switch (sizeof(voidpf)) { case 4: flags += 1 << 4; break;
case 2: break; case 8: flags += 2 << 4; break;
case 4: flags += 1 << 4; break; default: flags += 3 << 4;
case 8: flags += 2 << 4; break; }
default: flags += 3 << 4; switch ((int)(sizeof(z_off_t))) {
} case 2: break;
switch (sizeof(z_off_t)) { case 4: flags += 1 << 6; break;
case 2: break; case 8: flags += 2 << 6; break;
case 4: flags += 1 << 6; break; default: flags += 3 << 6;
case 8: flags += 2 << 6; break; }
default: flags += 3 << 6; #ifdef ZLIB_DEBUG
} flags += 1 << 8;
#ifdef DEBUG #endif
flags += 1 << 8; /*
#endif #if defined(ASMV) || defined(ASMINF)
#if defined(ASMV) || defined(ASMINF) flags += 1 << 9;
flags += 1 << 9; #endif
#endif */
#ifdef ZLIB_WINAPI #ifdef ZLIB_WINAPI
flags += 1 << 10; flags += 1 << 10;
#endif #endif
#ifdef BUILDFIXED #ifdef BUILDFIXED
flags += 1 << 12; flags += 1 << 12;
#endif #endif
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
flags += 1 << 13; flags += 1 << 13;
#endif #endif
#ifdef NO_GZCOMPRESS #ifdef NO_GZCOMPRESS
flags += 1L << 16; flags += 1L << 16;
#endif #endif
#ifdef NO_GZIP #ifdef NO_GZIP
flags += 1L << 17; flags += 1L << 17;
#endif #endif
#ifdef PKZIP_BUG_WORKAROUND #ifdef PKZIP_BUG_WORKAROUND
flags += 1L << 20; flags += 1L << 20;
#endif #endif
#ifdef FASTEST #ifdef FASTEST
flags += 1L << 21; flags += 1L << 21;
#endif #endif
#ifdef STDC #if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifdef NO_vsnprintf # ifdef NO_vsnprintf
flags += 1L << 25; flags += 1L << 25;
# ifdef HAS_vsprintf_void # ifdef HAS_vsprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# else # else
# ifdef HAS_vsnprintf_void # ifdef HAS_vsnprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# endif # endif
#else #else
flags += 1L << 24; flags += 1L << 24;
# ifdef NO_snprintf # ifdef NO_snprintf
flags += 1L << 25; flags += 1L << 25;
# ifdef HAS_sprintf_void # ifdef HAS_sprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# else # else
# ifdef HAS_snprintf_void # ifdef HAS_snprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# endif # endif
#endif #endif
return flags; return flags;
}*/ }
#if 0 #ifdef ZLIB_DEBUG
#include <stdlib.h>
# ifndef verbose # ifndef verbose
# define verbose 0 # define verbose 0
# endif # endif
int z_verbose = verbose; int ZLIB_INTERNAL z_verbose = verbose;
void z_error (const char *m) void ZLIB_INTERNAL z_error(char *m) {
{ fprintf(stderr, "%s\n", m);
fprintf(stderr, "%s\n", m); exit(1);
exit(1); }
} #endif
#endif
/* exported to allow conversion of error code to string for compress() and
/* exported to allow conversion of error code to string for compress() and * uncompress()
* uncompress() */
*/ const char * ZEXPORT zError(int err) {
const char * ZEXPORT zError(int err) return ERR_MSG(err);
{ }
return ERR_MSG(err);
} #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
/* The older Microsoft C Run-Time Library for Windows CE doesn't have
#if defined(_WIN32_WCE) * errno. We define it as a global variable to simplify porting.
/* The Microsoft C Run-Time Library for Windows CE doesn't have * Its value is always 0 and should not be used.
* errno. We define it as a global variable to simplify porting. */
* Its value is always 0 and should not be used. int errno = 0;
*/ #endif
int errno = 0;
#endif #ifndef HAVE_MEMCPY
#ifndef HAVE_MEMCPY void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
if (len == 0) return;
void zmemcpy(dest, source, len) do {
Bytef* dest; *dest++ = *source++; /* ??? to be unrolled */
const Bytef* source; } while (--len != 0);
uInt len; }
{
if (len == 0) return; int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
do { uInt j;
*dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0); for (j = 0; j < len; j++) {
} if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
}
int zmemcmp(s1, s2, len) return 0;
const Bytef* s1; }
const Bytef* s2;
uInt len; void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
{ if (len == 0) return;
uInt j; do {
*dest++ = 0; /* ??? to be unrolled */
for (j = 0; j < len; j++) { } while (--len != 0);
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; }
} #endif
return 0;
} #ifndef Z_SOLO
void zmemzero(dest, len) #ifdef SYS16BIT
Bytef* dest;
uInt len; #ifdef __TURBOC__
{ /* Turbo C in 16-bit mode */
if (len == 0) return;
do { # define MY_ZCALLOC
*dest++ = 0; /* ??? to be unrolled */
} while (--len != 0); /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
} * and farmalloc(64K) returns a pointer with an offset of 8, so we
#endif * must fix the pointer. Warning: the pointer must be put back to its
* original form in order to free it, use zcfree().
*/
#ifdef SYS16BIT
#define MAX_PTR 10
#ifdef __TURBOC__ /* 10*64K = 640K */
/* Turbo C in 16-bit mode */
local int next_ptr = 0;
# define MY_ZCALLOC
typedef struct ptr_table_s {
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes voidpf org_ptr;
* and farmalloc(64K) returns a pointer with an offset of 8, so we voidpf new_ptr;
* must fix the pointer. Warning: the pointer must be put back to its } ptr_table;
* original form in order to free it, use zcfree().
*/ local ptr_table table[MAX_PTR];
/* This table is used to remember the original form of pointers
#define MAX_PTR 10 * to large buffers (64K). Such pointers are normalized with a zero offset.
/* 10*64K = 640K */ * Since MSDOS is not a preemptive multitasking OS, this table is not
* protected from concurrent access. This hack doesn't work anyway on
local int next_ptr = 0; * a protected system like OS/2. Use Microsoft C instead.
*/
typedef struct ptr_table_s {
voidpf org_ptr; voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
voidpf new_ptr; voidpf buf;
} ptr_table; ulg bsize = (ulg)items*size;
local ptr_table table[MAX_PTR]; (void)opaque;
/* This table is used to remember the original form of pointers
* to large buffers (64K). Such pointers are normalized with a zero offset. /* If we allocate less than 65520 bytes, we assume that farmalloc
* Since MSDOS is not a preemptive multitasking OS, this table is not * will return a usable pointer which doesn't have to be normalized.
* protected from concurrent access. This hack doesn't work anyway on */
* a protected system like OS/2. Use Microsoft C instead. if (bsize < 65520L) {
*/ buf = farmalloc(bsize);
if (*(ush*)&buf != 0) return buf;
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) } else {
{ buf = farmalloc(bsize + 16L);
voidpf buf = opaque; /* just to make some compilers happy */ }
ulg bsize = (ulg)items*size; if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
table[next_ptr].org_ptr = buf;
/* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized. /* Normalize the pointer to seg:0 */
*/ *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
if (bsize < 65520L) { *(ush*)&buf = 0;
buf = farmalloc(bsize); table[next_ptr++].new_ptr = buf;
if (*(ush*)&buf != 0) return buf; return buf;
} else { }
buf = farmalloc(bsize + 16L);
} void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
if (buf == NULL || next_ptr >= MAX_PTR) return NULL; int n;
table[next_ptr].org_ptr = buf;
(void)opaque;
/* Normalize the pointer to seg:0 */
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; if (*(ush*)&ptr != 0) { /* object < 64K */
*(ush*)&buf = 0; farfree(ptr);
table[next_ptr++].new_ptr = buf; return;
return buf; }
} /* Find the original pointer */
for (n = 0; n < next_ptr; n++) {
void zcfree (voidpf opaque, voidpf ptr) if (ptr != table[n].new_ptr) continue;
{
int n; farfree(table[n].org_ptr);
if (*(ush*)&ptr != 0) { /* object < 64K */ while (++n < next_ptr) {
farfree(ptr); table[n-1] = table[n];
return; }
} next_ptr--;
/* Find the original pointer */ return;
for (n = 0; n < next_ptr; n++) { }
if (ptr != table[n].new_ptr) continue; Assert(0, "zcfree: ptr not found");
}
farfree(table[n].org_ptr);
while (++n < next_ptr) { #endif /* __TURBOC__ */
table[n-1] = table[n];
}
next_ptr--; #ifdef M_I86
return; /* Microsoft C in 16-bit mode */
}
ptr = opaque; /* just to make some compilers happy */ # define MY_ZCALLOC
Assert(0, "zcfree: ptr not found");
} #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
# define _halloc halloc
#endif /* __TURBOC__ */ # define _hfree hfree
#endif
#ifdef M_I86 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
/* Microsoft C in 16-bit mode */ (void)opaque;
return _halloc((long)items, size);
# define MY_ZCALLOC }
#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
# define _halloc halloc (void)opaque;
# define _hfree hfree _hfree(ptr);
#endif }
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) #endif /* M_I86 */
{
if (opaque) opaque = 0; /* to make compiler happy */ #endif /* SYS16BIT */
return _halloc((long)items, size);
}
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
void zcfree (voidpf opaque, voidpf ptr)
{ #ifndef STDC
if (opaque) opaque = 0; /* to make compiler happy */ extern voidp malloc(uInt size);
_hfree(ptr); extern voidp calloc(uInt items, uInt size);
} extern void free(voidpf ptr);
#endif
#endif /* M_I86 */
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
#endif /* SYS16BIT */ (void)opaque;
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size);
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ }
#ifndef STDC void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
extern voidp malloc OF((uInt size)); (void)opaque;
extern voidp calloc OF((uInt items, uInt size)); free(ptr);
extern void free OF((voidpf ptr)); }
#endif
#endif /* MY_ZCALLOC */
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{ #endif /* !Z_SOLO */
if (opaque) items += size - size; /* make compiler happy */
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size);
}
void zcfree (voidpf opaque, voidpf ptr)
{
free(ptr);
if (opaque) return; /* make compiler happy */
}
#endif /* MY_ZCALLOC */

View file

@ -1,271 +1,254 @@
/* zutil.h -- internal interface and configuration of the compression library /* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
/* @(#) $Id: zutil.h,v 1.1 2007/06/07 17:54:37 jules_rms Exp $ */ /* @(#) $Id$ */
#ifndef ZUTIL_H #ifndef ZUTIL_H
#define ZUTIL_H #define ZUTIL_H
#define ZLIB_INTERNAL #ifdef HAVE_HIDDEN
#include "zlib.h" # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
#ifdef STDC # define ZLIB_INTERNAL
# ifndef _WIN32_WCE #endif
# include <stddef.h>
# endif #include "zlib.h"
# include <string.h>
# include <stdlib.h> #if defined(STDC) && !defined(Z_SOLO)
#endif # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
#ifdef NO_ERRNO_H # include <stddef.h>
# ifdef _WIN32_WCE # endif
/* The Microsoft C Run-Time Library for Windows CE doesn't have # include <string.h>
* errno. We define it as a global variable to simplify porting. # include <stdlib.h>
* Its value is always 0 and should not be used. We rename it to #endif
* avoid conflict with other libraries that use the same workaround.
*/ #ifndef local
# define errno z_errno # define local static
# endif #endif
extern int errno; /* since "static" is used to mean two completely different things in C, we
#else define "local" for the non-static meaning of "static", for readability
# ifndef _WIN32_WCE (compile with -Dlocal if your debugger can't find static symbols) */
# include <errno.h>
# endif typedef unsigned char uch;
#endif typedef uch FAR uchf;
typedef unsigned short ush;
#ifndef local typedef ush FAR ushf;
# define local static typedef unsigned long ulg;
#endif
/* compile with -Dlocal if your debugger can't find static symbols */ #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
typedef unsigned char uch; # if (ULONG_MAX == 0xffffffffffffffff)
typedef uch FAR uchf; # define Z_U8 unsigned long
typedef unsigned short ush; # elif (ULLONG_MAX == 0xffffffffffffffff)
typedef ush FAR ushf; # define Z_U8 unsigned long long
typedef unsigned long ulg; # elif (UINT_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # endif
/* (size given to avoid silly warnings with Visual C++) */ #endif
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */
#define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err)) #define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
/* To be used only when the state is known to be valid */
#define ERR_RETURN(strm,err) \
/* common constants */ return (strm->msg = ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */
#ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS /* common constants */
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */ #ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#if MAX_MEM_LEVEL >= 8 #endif
# define DEF_MEM_LEVEL 8 /* default windowBits for decompression. MAX_WBITS is for compression only */
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL #if MAX_MEM_LEVEL >= 8
#endif # define DEF_MEM_LEVEL 8
/* default memLevel */ #else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#define STORED_BLOCK 0 #endif
#define STATIC_TREES 1 /* default memLevel */
#define DYN_TREES 2
/* The three kinds of block type */ #define STORED_BLOCK 0
#define STATIC_TREES 1
#define MIN_MATCH 3 #define DYN_TREES 2
#define MAX_MATCH 258 /* The three kinds of block type */
/* The minimum and maximum match lengths */
#define MIN_MATCH 3
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ #define MAX_MATCH 258
/* The minimum and maximum match lengths */
/* target dependencies */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00 /* target dependencies */
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
/* Allow compilation with ANSI keywords only enabled */ # define OS_CODE 0x00
void _Cdecl farfree( void *block ); # ifndef Z_SOLO
void *_Cdecl farmalloc( unsigned long nbytes ); # if defined(__TURBOC__) || defined(__BORLANDC__)
# else # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
# include <alloc.h> /* Allow compilation with ANSI keywords only enabled */
# endif void _Cdecl farfree( void *block );
# else /* MSC or DJGPP */ void *_Cdecl farmalloc( unsigned long nbytes );
# include <malloc.h> # else
# endif # include <alloc.h>
#endif # endif
# else /* MSC or DJGPP */
#ifdef AMIGA # include <malloc.h>
# define OS_CODE 0x01 # endif
#endif # endif
#endif
#if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02 #ifdef AMIGA
# define F_OPEN(name, mode) \ # define OS_CODE 1
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") #endif
#endif
#if defined(VAXC) || defined(VMS)
#if defined(ATARI) || defined(atarist) # define OS_CODE 2
# define OS_CODE 0x05 # define F_OPEN(name, mode) \
#endif fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
#ifdef OS2
# define OS_CODE 0x06 #ifdef __370__
# ifdef M_I86 # if __TARGET_LIB__ < 0x20000000
#include <malloc.h> # define OS_CODE 4
# endif # elif __TARGET_LIB__ < 0x40000000
#endif # define OS_CODE 11
# else
#if defined(MACOS) || TARGET_OS_MAC # define OS_CODE 8
# define OS_CODE 0x07 # endif
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os #endif
# include <unix.h> /* for fdopen */
# else #if defined(ATARI) || defined(atarist)
# ifndef fdopen # define OS_CODE 5
# define fdopen(fd,mode) NULL /* No fdopen() */ #endif
# endif
# endif #ifdef OS2
#endif # define OS_CODE 6
# if defined(M_I86) && !defined(Z_SOLO)
#ifdef TOPS20 # include <malloc.h>
# define OS_CODE 0x0a # endif
#endif #endif
#ifdef WIN32 #if defined(MACOS)
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ # define OS_CODE 7
# define OS_CODE 0x0b #endif
# endif
#endif #ifdef __acorn
# define OS_CODE 13
#ifdef __50SERIES /* Prime/PRIMOS */ #endif
# define OS_CODE 0x0f
#endif #if defined(WIN32) && !defined(__CYGWIN__)
# define OS_CODE 10
#if defined(_BEOS_) || defined(RISCOS) #endif
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif #ifdef _BEOS_
# define OS_CODE 16
#if (defined(_MSC_VER) && (_MSC_VER > 600)) #endif
# if defined(_WIN32_WCE)
# define fdopen(fd,mode) NULL /* No fdopen() */ #ifdef __TOS_OS400__
# ifndef _PTRDIFF_T_DEFINED # define OS_CODE 18
typedef int ptrdiff_t; #endif
# define _PTRDIFF_T_DEFINED
# endif #ifdef __APPLE__
# else # define OS_CODE 19
# define fdopen(fd,type) _fdopen(fd,type) #endif
# endif
#endif #if defined(__BORLANDC__) && !defined(MSDOS)
#pragma warn -8004
/* common defaults */ #pragma warn -8008
#pragma warn -8066
#ifndef OS_CODE #endif
# define OS_CODE 0x03 /* assume Unix */
#endif /* provide prototypes for these when building zlib without LFS */
#if !defined(_WIN32) && \
#ifndef F_OPEN (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
# define F_OPEN(name, mode) fopen((name), (mode)) ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
#endif ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
/* functions */ #endif
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) /* common defaults */
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF #ifndef OS_CODE
# endif # define OS_CODE 3 /* assume Unix */
#endif #endif
#if defined(__CYGWIN__)
# ifndef HAVE_VSNPRINTF #ifndef F_OPEN
# define HAVE_VSNPRINTF # define F_OPEN(name, mode) fopen((name), (mode))
# endif #endif
#endif
#ifndef HAVE_VSNPRINTF /* functions */
# ifdef MSDOS
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), #if defined(pyr) || defined(Z_SOLO)
but for now we just assume it doesn't. */ # define NO_MEMCPY
# define NO_vsnprintf #endif
# endif #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
# ifdef __TURBOC__ /* Use our own functions for small and medium model with MSC <= 5.0.
# define NO_vsnprintf * You may have to use the same strategy for Borland C (untested).
# endif * The __SC__ check is for Symantec.
# ifdef WIN32 */
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ # define NO_MEMCPY
# if !defined(vsnprintf) && !defined(NO_vsnprintf) #endif
# define vsnprintf _vsnprintf #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# endif # define HAVE_MEMCPY
# endif #endif
# ifdef __SASC #ifdef HAVE_MEMCPY
# define NO_vsnprintf # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
# endif # define zmemcpy _fmemcpy
#endif # define zmemcmp _fmemcmp
#ifdef VMS # define zmemzero(dest, len) _fmemset(dest, 0, len)
# define NO_vsnprintf # else
#endif # define zmemcpy memcpy
# define zmemcmp memcmp
#if defined(pyr) # define zmemzero(dest, len) memset(dest, 0, len)
# define NO_MEMCPY # endif
#endif #else
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
/* Use our own functions for small and medium model with MSC <= 5.0. int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
* You may have to use the same strategy for Borland C (untested). void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
* The __SC__ check is for Symantec. #endif
*/
# define NO_MEMCPY /* Diagnostic functions */
#endif #ifdef ZLIB_DEBUG
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) # include <stdio.h>
# define HAVE_MEMCPY extern int ZLIB_INTERNAL z_verbose;
#endif extern void ZLIB_INTERNAL z_error(char *m);
#ifdef HAVE_MEMCPY # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define zmemcpy _fmemcpy # define Tracev(x) {if (z_verbose>0) fprintf x ;}
# define zmemcmp _fmemcmp # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
# define zmemzero(dest, len) _fmemset(dest, 0, len) # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
# else # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
# define zmemcpy memcpy #else
# define zmemcmp memcmp # define Assert(cond,msg)
# define zmemzero(dest, len) memset(dest, 0, len) # define Trace(x)
# endif # define Tracev(x)
#else # define Tracevv(x)
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); # define Tracec(c,x)
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); # define Tracecv(c,x)
extern void zmemzero OF((Bytef* dest, uInt len)); #endif
#endif
#ifndef Z_SOLO
/* Diagnostic functions */ voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
#if 0 unsigned size);
# include <stdio.h> void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
extern int z_verbose; #endif
extern void z_error OF((const char *m));
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} #define ZALLOC(strm, items, size) \
# define Trace(x) {if (z_verbose>=0) fprintf x ;} (*((strm)->zalloc))((strm)->opaque, (items), (size))
# define Tracev(x) {if (z_verbose>0) fprintf x ;} #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
# define Tracevv(x) {if (z_verbose>1) fprintf x ;} #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} /* Reverse the bytes in a 32-bit value */
#else #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
# define Assert(cond,msg) (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
# define Trace(x)
# define Tracev(x) #endif /* ZUTIL_H */
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
# define z_error(x)
# define z_verbose 0
#endif
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidpf opaque, voidpf ptr));
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
#endif /* ZUTIL_H */