Update to zlib 1.3.2 (#852)

This commit is contained in:
TraoX_
2026-03-07 21:56:03 +02:00
committed by GitHub
parent 9cac3e0394
commit bbe396d90d
26 changed files with 23107 additions and 12833 deletions

View File

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

View File

@@ -1,81 +1,99 @@
/* compress.c -- compress a memory buffer /* compress.c -- compress a memory buffer
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2026 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$ */ /* @(#) $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 (dest, destLen, source, sourceLen, level) The _z versions of the functions take size_t length arguments.
Bytef *dest; */
uLongf *destLen; int ZEXPORT compress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
const Bytef *source; z_size_t sourceLen, int level) {
uLong sourceLen; z_stream stream;
int level; int err;
{ const uInt max = (uInt)-1;
z_stream stream; z_size_t left;
int err;
if ((sourceLen > 0 && source == NULL) ||
stream.next_in = (z_const Bytef *)source; destLen == NULL || (*destLen > 0 && dest == NULL))
stream.avail_in = (uInt)sourceLen; return Z_STREAM_ERROR;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */ left = *destLen;
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; *destLen = 0;
#endif
stream.next_out = dest; stream.zalloc = (alloc_func)0;
stream.avail_out = (uInt)*destLen; stream.zfree = (free_func)0;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; stream.opaque = (voidpf)0;
stream.zalloc = (alloc_func)0; err = deflateInit(&stream, level);
stream.zfree = (free_func)0; if (err != Z_OK) return err;
stream.opaque = (voidpf)0;
stream.next_out = dest;
err = deflateInit(&stream, level); stream.avail_out = 0;
if (err != Z_OK) return err; stream.next_in = (z_const Bytef *)source;
stream.avail_in = 0;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) { do {
deflateEnd(&stream); if (stream.avail_out == 0) {
return err == Z_OK ? Z_BUF_ERROR : err; stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
} left -= stream.avail_out;
*destLen = stream.total_out; }
if (stream.avail_in == 0) {
err = deflateEnd(&stream); stream.avail_in = sourceLen > (z_size_t)max ? max :
return err; (uInt)sourceLen;
} sourceLen -= stream.avail_in;
}
/* =========================================================================== err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
*/ } while (err == Z_OK);
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest; *destLen = (z_size_t)(stream.next_out - dest);
uLongf *destLen; deflateEnd(&stream);
const Bytef *source; return err == Z_STREAM_END ? Z_OK : err;
uLong sourceLen; }
{ int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); uLong sourceLen, int level) {
} int ret;
z_size_t got = *destLen;
ret = compress2_z(dest, &got, source, sourceLen, level);
/* =========================================================================== *destLen = (uLong)got;
If the default memLevel or windowBits for deflateInit() is changed, then return ret;
this function needs to be updated. }
*/ /* ===========================================================================
uLong ZEXPORT compressBound (sourceLen) */
uLong sourceLen; int ZEXPORT compress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
{ z_size_t sourceLen) {
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + return compress2_z(dest, destLen, source, sourceLen,
(sourceLen >> 25) + 13; Z_DEFAULT_COMPRESSION);
} }
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen) {
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}
/* ===========================================================================
If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated.
*/
z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) {
z_size_t bound = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13;
return bound < sourceLen ? (z_size_t)-1 : bound;
}
uLong ZEXPORT compressBound(uLong sourceLen) {
z_size_t bound = compressBound_z(sourceLen);
return (uLong)bound != bound ? (uLong)-1 : (uLong)bound;
}

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

@@ -1,25 +1,23 @@
/* gzclose.c -- zlib gzclose() function /* gzclose.c -- zlib gzclose() function
* Copyright (C) 2004, 2010 Mark Adler * Copyright (C) 2004, 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
*/ */
#include "gzguts.h" #include "gzguts.h"
/* gzclose() is in a separate file so that it is linked in only if it is used. /* gzclose() is in a separate file so that it is linked in only if it is used.
That way the other gzclose functions can be used instead to avoid linking in That way the other gzclose functions can be used instead to avoid linking in
unneeded compression or decompression routines. */ unneeded compression or decompression routines. */
int ZEXPORT gzclose(file) int ZEXPORT gzclose(gzFile file) {
gzFile file; #ifndef NO_GZCOMPRESS
{ gz_statep state;
#ifndef NO_GZCOMPRESS
gz_statep state; if (file == NULL)
return Z_STREAM_ERROR;
if (file == NULL) state = (gz_statep)file;
return Z_STREAM_ERROR;
state = (gz_statep)file; return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
#else
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); return gzclose_r(file);
#else #endif
return gzclose_r(file); }
#endif
}

View File

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

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,340 +1,321 @@
/* inffast.c -- fast decoding /* inffast.c -- fast decoding
* Copyright (C) 1995-2008, 2010, 2013 Mark Adler * Copyright (C) 1995-2026 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 ZLIB_INTERNAL inflate_fast(strm, start) code const FAR *dcode; /* local strm->distcode */
z_streamp strm; unsigned lmask; /* mask for first level of length codes */
unsigned start; /* inflate()'s starting value for strm->avail_out */ unsigned dmask; /* mask for first level of distance codes */
{ code const *here; /* retrieved table entry */
struct inflate_state FAR *state; unsigned op; /* code bits, operation, extra bits, or */
z_const unsigned char FAR *in; /* local strm->next_in */ /* window position, window bytes to copy */
z_const unsigned char FAR *last; /* have enough input while in < last */ unsigned len; /* match length, unused bytes */
unsigned char FAR *out; /* local strm->next_out */ unsigned dist; /* match distance */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned char FAR *from; /* where to copy match from */
unsigned char FAR *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT /* copy state to local variables */
unsigned dmax; /* maximum distance from zlib header */ state = (struct inflate_state FAR *)strm->state;
#endif in = strm->next_in;
unsigned wsize; /* window size or zero if not using window */ last = in + (strm->avail_in - 5);
unsigned whave; /* valid bytes in the window */ out = strm->next_out;
unsigned wnext; /* window write index */ beg = out - (start - strm->avail_out);
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ end = out + (strm->avail_out - 257);
unsigned long hold; /* local strm->hold */ #ifdef INFLATE_STRICT
unsigned bits; /* local strm->bits */ dmax = state->dmax;
code const FAR *lcode; /* local strm->lencode */ #endif
code const FAR *dcode; /* local strm->distcode */ wsize = state->wsize;
unsigned lmask; /* mask for first level of length codes */ whave = state->whave;
unsigned dmask; /* mask for first level of distance codes */ wnext = state->wnext;
code here; /* retrieved table entry */ window = state->window;
unsigned op; /* code bits, operation, extra bits, or */ hold = state->hold;
/* window position, window bytes to copy */ bits = state->bits;
unsigned len; /* match length, unused bytes */ lcode = state->lencode;
unsigned dist; /* match distance */ dcode = state->distcode;
unsigned char FAR *from; /* where to copy match from */ lmask = (1U << state->lenbits) - 1;
dmask = (1U << state->distbits) - 1;
/* copy state to local variables */
state = (struct inflate_state FAR *)strm->state; /* decode literals and length/distances until end-of-block or not enough
in = strm->next_in - OFF; input data or output space */
last = in + (strm->avail_in - 5); do {
out = strm->next_out - OFF; if (bits < 15) {
beg = out - (start - strm->avail_out); hold += (unsigned long)(*in++) << bits;
end = out + (strm->avail_out - 257); bits += 8;
#ifdef INFLATE_STRICT hold += (unsigned long)(*in++) << bits;
dmax = state->dmax; bits += 8;
#endif }
wsize = state->wsize; here = lcode + (hold & lmask);
whave = state->whave; dolen:
wnext = state->wnext; op = (unsigned)(here->bits);
window = state->window; hold >>= op;
hold = state->hold; bits -= op;
bits = state->bits; op = (unsigned)(here->op);
lcode = state->lencode; if (op == 0) { /* literal */
dcode = state->distcode; Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
lmask = (1U << state->lenbits) - 1; "inflate: literal '%c'\n" :
dmask = (1U << state->distbits) - 1; "inflate: literal 0x%02x\n", here->val));
*out++ = (unsigned char)(here->val);
/* decode literals and length/distances until end-of-block or not enough }
input data or output space */ else if (op & 16) { /* length base */
do { len = (unsigned)(here->val);
if (bits < 15) { op &= 15; /* number of extra bits */
hold += (unsigned long)(PUP(in)) << bits; if (op) {
bits += 8; if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = lcode[hold & lmask]; len += (unsigned)hold & ((1U << op) - 1);
dolen: hold >>= op;
op = (unsigned)(here.bits); bits -= op;
hold >>= op; }
bits -= op; Tracevv((stderr, "inflate: length %u\n", len));
op = (unsigned)(here.op); if (bits < 15) {
if (op == 0) { /* literal */ hold += (unsigned long)(*in++) << bits;
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? bits += 8;
"inflate: literal '%c'\n" : hold += (unsigned long)(*in++) << bits;
"inflate: literal 0x%02x\n", here.val)); bits += 8;
PUP(out) = (unsigned char)(here.val); }
} here = dcode + (hold & dmask);
else if (op & 16) { /* length base */ dodist:
len = (unsigned)(here.val); op = (unsigned)(here->bits);
op &= 15; /* number of extra bits */ hold >>= op;
if (op) { bits -= op;
if (bits < op) { op = (unsigned)(here->op);
hold += (unsigned long)(PUP(in)) << bits; if (op & 16) { /* distance base */
bits += 8; dist = (unsigned)(here->val);
} op &= 15; /* number of extra bits */
len += (unsigned)hold & ((1U << op) - 1); if (bits < op) {
hold >>= op; hold += (unsigned long)(*in++) << bits;
bits -= op; bits += 8;
} if (bits < op) {
Tracevv((stderr, "inflate: length %u\n", len)); hold += (unsigned long)(*in++) << bits;
if (bits < 15) { bits += 8;
hold += (unsigned long)(PUP(in)) << bits; }
bits += 8; }
hold += (unsigned long)(PUP(in)) << bits; dist += (unsigned)hold & ((1U << op) - 1);
bits += 8; #ifdef INFLATE_STRICT
} if (dist > dmax) {
here = dcode[hold & dmask]; strm->msg = (z_const char *)
dodist: "invalid distance too far back";
op = (unsigned)(here.bits); state->mode = BAD;
hold >>= op; break;
bits -= op; }
op = (unsigned)(here.op); #endif
if (op & 16) { /* distance base */ hold >>= op;
dist = (unsigned)(here.val); bits -= op;
op &= 15; /* number of extra bits */ Tracevv((stderr, "inflate: distance %u\n", dist));
if (bits < op) { op = (unsigned)(out - beg); /* max distance in output */
hold += (unsigned long)(PUP(in)) << bits; if (dist > op) { /* see if copy from window */
bits += 8; op = dist - op; /* distance back in window */
if (bits < op) { if (op > whave) {
hold += (unsigned long)(PUP(in)) << bits; if (state->sane) {
bits += 8; strm->msg = (z_const char *)
} "invalid distance too far back";
} state->mode = BAD;
dist += (unsigned)hold & ((1U << op) - 1); break;
#ifdef INFLATE_STRICT }
if (dist > dmax) { #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
strm->msg = (char *)"invalid distance too far back"; if (len <= op - whave) {
state->mode = BAD; do {
break; *out++ = 0;
} } while (--len);
#endif continue;
hold >>= op; }
bits -= op; len -= op - whave;
Tracevv((stderr, "inflate: distance %u\n", dist)); do {
op = (unsigned)(out - beg); /* max distance in output */ *out++ = 0;
if (dist > op) { /* see if copy from window */ } while (--op > whave);
op = dist - op; /* distance back in window */ if (op == 0) {
if (op > whave) { from = out - dist;
if (state->sane) { do {
strm->msg = *out++ = *from++;
(char *)"invalid distance too far back"; } while (--len);
state->mode = BAD; continue;
break; }
} #endif
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR }
if (len <= op - whave) { from = window;
do { if (wnext == 0) { /* very common case */
PUP(out) = 0; from += wsize - op;
} while (--len); if (op < len) { /* some from window */
continue; len -= op;
} do {
len -= op - whave; *out++ = *from++;
do { } while (--op);
PUP(out) = 0; from = out - dist; /* rest from output */
} while (--op > whave); }
if (op == 0) { }
from = out - dist; else if (wnext < op) { /* wrap around window */
do { from += wsize + wnext - op;
PUP(out) = PUP(from); op -= wnext;
} while (--len); if (op < len) { /* some from end of window */
continue; len -= op;
} do {
#endif *out++ = *from++;
} } while (--op);
from = window - OFF; from = window;
if (wnext == 0) { /* very common case */ if (wnext < len) { /* some from start of window */
from += wsize - op; op = wnext;
if (op < len) { /* some from window */ len -= op;
len -= op; do {
do { *out++ = *from++;
PUP(out) = PUP(from); } while (--op);
} while (--op); from = out - dist; /* rest from output */
from = out - dist; /* rest from output */ }
} }
} }
else if (wnext < op) { /* wrap around window */ else { /* contiguous in window */
from += wsize + wnext - op; from += wnext - op;
op -= wnext; if (op < len) { /* some from window */
if (op < len) { /* some from end of window */ len -= op;
len -= op; do {
do { *out++ = *from++;
PUP(out) = PUP(from); } while (--op);
} while (--op); from = out - dist; /* rest from output */
from = window - OFF; }
if (wnext < len) { /* some from start of window */ }
op = wnext; while (len > 2) {
len -= op; *out++ = *from++;
do { *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); len -= 3;
from = out - dist; /* rest from output */ }
} if (len) {
} *out++ = *from++;
} if (len > 1)
else { /* contiguous in window */ *out++ = *from++;
from += wnext - op; }
if (op < len) { /* some from window */ }
len -= op; else {
do { from = out - dist; /* copy direct from output */
PUP(out) = PUP(from); do { /* minimum length is three */
} while (--op); *out++ = *from++;
from = out - dist; /* rest from output */ *out++ = *from++;
} *out++ = *from++;
} len -= 3;
while (len > 2) { } while (len > 2);
PUP(out) = PUP(from); if (len) {
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); if (len > 1)
len -= 3; *out++ = *from++;
} }
if (len) { }
PUP(out) = PUP(from); }
if (len > 1) else if ((op & 64) == 0) { /* 2nd level distance code */
PUP(out) = PUP(from); here = dcode + here->val + (hold & ((1U << op) - 1));
} goto dodist;
} }
else { else {
from = out - dist; /* copy direct from output */ strm->msg = (z_const char *)"invalid distance code";
do { /* minimum length is three */ state->mode = BAD;
PUP(out) = PUP(from); break;
PUP(out) = PUP(from); }
PUP(out) = PUP(from); }
len -= 3; else if ((op & 64) == 0) { /* 2nd level length code */
} while (len > 2); here = lcode + here->val + (hold & ((1U << op) - 1));
if (len) { goto dolen;
PUP(out) = PUP(from); }
if (len > 1) else if (op & 32) { /* end-of-block */
PUP(out) = PUP(from); Tracevv((stderr, "inflate: end of block\n"));
} state->mode = TYPE;
} break;
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else {
here = dcode[here.val + (hold & ((1U << op) - 1))]; strm->msg = (z_const char *)"invalid literal/length code";
goto dodist; state->mode = BAD;
} break;
else { }
strm->msg = (char *)"invalid distance code"; } while (in < last && out < end);
state->mode = BAD;
break; /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
} len = bits >> 3;
} in -= len;
else if ((op & 64) == 0) { /* 2nd level length code */ bits -= len << 3;
here = lcode[here.val + (hold & ((1U << op) - 1))]; hold &= (1U << bits) - 1;
goto dolen;
} /* update state and return */
else if (op & 32) { /* end-of-block */ strm->next_in = in;
Tracevv((stderr, "inflate: end of block\n")); strm->next_out = out;
state->mode = TYPE; strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
break; strm->avail_out = (unsigned)(out < end ?
} 257 + (end - out) : 257 - (out - end));
else { state->hold = hold;
strm->msg = (char *)"invalid literal/length code"; state->bits = bits;
state->mode = BAD; return;
break; }
}
} while (in < last && out < end); /*
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - Using bit fields for code structure
len = bits >> 3; - Different op definition to avoid & for extra bits (do & for table bits)
in -= len; - Three separate decoding do-loops for direct, window, and wnext == 0
bits -= len << 3; - Special case for distance > 1 copies to do overlapped load and store copy
hold &= (1U << bits) - 1; - Explicit branch predictions (based on measured branch probabilities)
- Deferring match copy and interspersed it with decoding subsequent codes
/* update state and return */ - Swapping literal/length else
strm->next_in = in + OFF; - Swapping window/direct else
strm->next_out = out + OFF; - Larger unrolled copy loops (three is about right)
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); - Moving len -= 3 statement into middle of loop
strm->avail_out = (unsigned)(out < end ? */
257 + (end - out) : 257 - (out - end));
state->hold = hold; #endif /* !ASMINF */
state->bits = bits;
return;
}
/*
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- 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 wnext == 0
- Special case for distance > 1 copies to do overlapped load and store copy
- Explicit branch predictions (based on measured branch probabilities)
- Deferring match copy and interspersed it with decoding subsequent codes
- Swapping literal/length else
- Swapping window/direct else
- 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, 2010 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 ZLIB_INTERNAL 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. /* WARNING: this file should *not* be used by applications.
It is part of the implementation of this library and is It is part of the implementation of this library and 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,122 +1,126 @@
/* inflate.h -- internal inflate state definition /* inflate.h -- internal inflate state definition
* Copyright (C) 1995-2009 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.
*/ */
/* 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 decoding by inflate(). NO_GZIP would be used to avoid linking in 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 the crc code when it is not needed. For shared libraries, gzip decoding
should be left enabled. */ should be left enabled. */
#ifndef NO_GZIP #ifndef NO_GZIP
# define GUNZIP # define GUNZIP
#endif #endif
/* Possible inflate modes between inflate() calls */ /* Possible inflate modes between inflate() calls */
typedef enum { typedef enum {
HEAD, /* i: waiting for magic header */ HEAD = 16180, /* i: waiting for magic header */
FLAGS, /* i: waiting for method and flags (gzip) */ FLAGS, /* i: waiting for method and flags (gzip) */
TIME, /* i: waiting for modification time (gzip) */ TIME, /* i: waiting for modification time (gzip) */
OS, /* i: waiting for extra flags and operating system (gzip) */ OS, /* i: waiting for extra flags and operating system (gzip) */
EXLEN, /* i: waiting for extra length (gzip) */ EXLEN, /* i: waiting for extra length (gzip) */
EXTRA, /* i: waiting for extra bytes (gzip) */ EXTRA, /* i: waiting for extra bytes (gzip) */
NAME, /* i: waiting for end of file name (gzip) */ NAME, /* i: waiting for end of file name (gzip) */
COMMENT, /* i: waiting for end of comment (gzip) */ COMMENT, /* i: waiting for end of comment (gzip) */
HCRC, /* i: waiting for header crc (gzip) */ HCRC, /* i: waiting for header crc (gzip) */
DICTID, /* i: waiting for dictionary check value */ DICTID, /* i: waiting for dictionary check value */
DICT, /* waiting for inflateSetDictionary() call */ DICT, /* waiting for inflateSetDictionary() call */
TYPE, /* i: waiting for type bits, including last-flag bit */ TYPE, /* i: waiting for type bits, including last-flag bit */
TYPEDO, /* i: same, but skip check to exit inflate on new block */ TYPEDO, /* i: same, but skip check to exit inflate on new block */
STORED, /* i: waiting for stored size (length and complement) */ STORED, /* i: waiting for stored size (length and complement) */
COPY_, /* i/o: same as COPY below, but only first time in */ COPY_, /* i/o: same as COPY below, but only first time in */
COPY, /* i/o: waiting for input or output to copy stored block */ COPY, /* i/o: waiting for input or output to copy stored block */
TABLE, /* i: waiting for dynamic block table lengths */ TABLE, /* i: waiting for dynamic block table lengths */
LENLENS, /* i: waiting for code length code lengths */ LENLENS, /* i: waiting for code length code lengths */
CODELENS, /* i: waiting for length/lit and distance code lengths */ CODELENS, /* i: waiting for length/lit and distance code lengths */
LEN_, /* i: same as LEN below, but only first time in */ LEN_, /* i: same as LEN below, but only first time in */
LEN, /* i: waiting for length/lit/eob code */ LEN, /* i: waiting for length/lit/eob 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 BAD or MEM on error -- not shown for clarity)
Process header: Process header:
HEAD -> (gzip) or (zlib) or (raw) HEAD -> (gzip) or (zlib) or (raw)
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
HCRC -> TYPE HCRC -> TYPE
(zlib) -> DICTID or TYPE (zlib) -> DICTID or TYPE
DICTID -> DICT -> TYPE DICTID -> DICT -> TYPE
(raw) -> TYPEDO (raw) -> TYPEDO
Read deflate blocks: Read deflate blocks:
TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
STORED -> COPY_ -> COPY -> TYPE STORED -> COPY_ -> COPY -> TYPE
TABLE -> LENLENS -> CODELENS -> LEN_ TABLE -> LENLENS -> CODELENS -> LEN_
LEN_ -> LEN LEN_ -> LEN
Read deflate codes in fixed or dynamic block: Read deflate codes in fixed or dynamic block:
LEN -> LENEXT or LIT or TYPE LEN -> LENEXT or LIT or TYPE
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
LIT -> LEN LIT -> LEN
Process trailer: Process trailer:
CHECK -> LENGTH -> DONE CHECK -> LENGTH -> DONE
*/ */
/* state maintained between inflate() calls. Approximately 10K bytes. */ /* State maintained between inflate() calls -- approximately 7K bytes, not
struct inflate_state { including the allocated sliding window, which is up to 32K bytes. */
inflate_mode mode; /* current inflate mode */ struct inflate_state {
int last; /* true if processing last block */ z_streamp strm; /* pointer back to this zlib stream */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ inflate_mode mode; /* current inflate mode */
int havedict; /* true if dictionary provided */ int last; /* true if processing last block */
int flags; /* gzip header method and flags (0 if zlib) */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ bit 2 true to validate check value */
unsigned long check; /* protected copy of check value */ int havedict; /* true if dictionary provided */
unsigned long total; /* protected copy of output count */ int flags; /* gzip header method and flags, 0 if zlib, or
gz_headerp head; /* where to save gzip header information */ -1 if raw or no header yet */
/* sliding window */ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned wbits; /* log base 2 of requested window size */ unsigned long check; /* protected copy of check value */
unsigned wsize; /* window size or zero if not using window */ unsigned long total; /* protected copy of output count */
unsigned whave; /* valid bytes in the window */ gz_headerp head; /* where to save gzip header information */
unsigned wnext; /* window write index */ /* sliding window */
unsigned char FAR *window; /* allocated sliding window, if needed */ unsigned wbits; /* log base 2 of requested window size */
/* bit accumulator */ unsigned wsize; /* window size or zero if not using window */
unsigned long hold; /* input bit accumulator */ unsigned whave; /* valid bytes in the window */
unsigned bits; /* number of bits in "in" */ unsigned wnext; /* window write index */
/* for string and stored block copying */ unsigned char FAR *window; /* allocated sliding window, if needed */
unsigned length; /* literal or length of data to copy */ /* bit accumulator */
unsigned offset; /* distance back to copy string from */ unsigned long hold; /* input bit accumulator */
/* for table and code decoding */ unsigned bits; /* number of bits in hold */
unsigned extra; /* extra bits needed */ /* for string and stored block copying */
/* fixed and dynamic code tables */ unsigned length; /* literal or length of data to copy */
code const FAR *lencode; /* starting table for length/literal codes */ unsigned offset; /* distance back to copy string from */
code const FAR *distcode; /* starting table for distance codes */ /* for table and code decoding */
unsigned lenbits; /* index bits for lencode */ unsigned extra; /* extra bits needed */
unsigned distbits; /* index bits for distcode */ /* fixed and dynamic code tables */
/* dynamic table building */ code const FAR *lencode; /* starting table for length/literal codes */
unsigned ncode; /* number of code length code lengths */ code const FAR *distcode; /* starting table for distance codes */
unsigned nlen; /* number of length code lengths */ unsigned lenbits; /* index bits for lencode */
unsigned ndist; /* number of distance code lengths */ unsigned distbits; /* index bits for distcode */
unsigned have; /* number of code lengths in lens[] */ /* dynamic table building */
code FAR *next; /* next available space in codes[] */ unsigned ncode; /* number of code length code lengths */
unsigned short lens[320]; /* temporary storage for code lengths */ unsigned nlen; /* number of length code lengths */
unsigned short work[288]; /* work area for code table building */ unsigned ndist; /* number of distance code lengths */
code codes[ENOUGH]; /* space for code tables */ unsigned have; /* number of code lengths in lens[] */
int sane; /* if false, allow invalid distance too far */ code FAR *next; /* next available space in codes[] */
int back; /* bits back of last unprocessed length/lit */ unsigned short lens[320]; /* temporary storage for code lengths */
unsigned was; /* initial length of match */ 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,306 +1,424 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2013 Mark Adler * Copyright (C) 1995-2026 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" #ifdef MAKEFIXED
#include "inftrees.h" # ifndef BUILDFIXED
# define BUILDFIXED
#define MAXBITS 15 # endif
#endif
const char inflate_copyright[] = #ifdef BUILDFIXED
" inflate 1.2.8 Copyright 1995-2013 Mark Adler "; # define Z_ONCE
/* #endif
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 #include "zutil.h"
include such an acknowledgment, I would appreciate that you keep this #include "inftrees.h"
copyright string in the executable of your product. #include "inflate.h"
*/
#ifndef NULL
/* # define NULL 0
Build a set of tables to decode the provided canonical Huffman code. #endif
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 #define MAXBITS 15
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, const char inflate_copyright[] =
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table " inflate 1.3.2.1 Copyright 1995-2026 Mark Adler ";
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 If you use the zlib library in a product, an acknowledgment is welcome
table index bits. It will differ if the request is greater than the in the documentation of your product. If for some reason you cannot
longest code or if it is less than the shortest code. include such an acknowledgment, I would appreciate that you keep this
*/ copyright string in the executable of your product.
int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) */
codetype type;
unsigned short FAR *lens; /*
unsigned codes; Build a set of tables to decode the provided canonical Huffman code.
code FAR * FAR *table; The code lengths are lens[0..codes-1]. The result starts at *table,
unsigned FAR *bits; whose indices are 0..2^bits-1. work is a writable array of at least
unsigned short FAR *work; 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,
unsigned len; /* a code's length in bits */ -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
unsigned sym; /* index of code symbols */ on return points to the next available entry's address. bits is the
unsigned min, max; /* minimum and maximum code lengths */ requested root table index bits, and on return it is the actual root
unsigned root; /* number of index bits for root table */ table index bits. It will differ if the request is greater than the
unsigned curr; /* number of index bits for current table */ longest code or if it is less than the shortest code.
unsigned drop; /* code bits to drop for sub-table */ */
int left; /* number of prefix codes available */ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
unsigned used; /* code entries in table used */ unsigned codes, code FAR * FAR *table,
unsigned huff; /* Huffman code */ unsigned FAR *bits, unsigned short FAR *work) {
unsigned incr; /* for incrementing code, index */ unsigned len; /* a code's length in bits */
unsigned fill; /* index for replicating entries */ unsigned sym; /* index of code symbols */
unsigned low; /* low bits for current root entry */ unsigned min, max; /* minimum and maximum code lengths */
unsigned mask; /* mask for low root bits */ unsigned root; /* number of index bits for root table */
code here; /* table entry for duplication */ unsigned curr; /* number of index bits for current table */
code FAR *next; /* next available space in table */ unsigned drop; /* code bits to drop for sub-table */
const unsigned short FAR *base; /* base value table to use */ int left; /* number of prefix codes available */
const unsigned short FAR *extra; /* extra bits table to use */ unsigned used; /* code entries in table used */
int end; /* use base and extra for symbol > end */ unsigned huff; /* Huffman code */
unsigned short count[MAXBITS+1]; /* number of codes of each length */ unsigned incr; /* for incrementing code, index */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ unsigned fill; /* index for replicating entries */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ unsigned low; /* low bits for current root entry */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, unsigned mask; /* mask for low root bits */
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; code here; /* table entry for duplication */
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ code FAR *next; /* next available space in table */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, const unsigned short FAR *base = NULL; /* base value table to use */
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; const unsigned short FAR *extra = NULL; /* extra bits table to use */
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ unsigned match = 0; /* use base and extra for symbol >= match */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, unsigned short count[MAXBITS+1]; /* number of codes of each length */
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
8193, 12289, 16385, 24577, 0, 0}; static const unsigned short lbase[31] = { /* Length codes 257..285 base */
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
23, 23, 24, 24, 25, 25, 26, 26, 27, 27, static const unsigned short lext[31] = { /* Length codes 257..285 extra */
28, 28, 29, 29, 64, 64}; 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 68, 193};
/* static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
Process a set of code lengths to create a canonical Huffman code. The 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
code lengths are lens[0..codes-1]. Each length corresponds to the 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
symbols 0..codes-1. The Huffman code is generated by first sorting the 8193, 12289, 16385, 24577, 0, 0};
symbols by length from short to long, and retaining the symbol order static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
for codes with equal lengths. Then the code starts with all zero bits 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
for the first code of the shortest length, and the codes are integer 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
increments for the same length, and zeros are appended as the length 28, 28, 29, 29, 64, 64};
increases. For the deflate format, these bits are stored backwards
from their more natural integer increment ordering, and so when the /*
decoding tables are built in the large loop below, the integer codes Process a set of code lengths to create a canonical Huffman code. The
are incremented backwards. 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
This routine assumes, but does not check, that all of the entries in symbols by length from short to long, and retaining the symbol order
lens[] are in the range 0..MAXBITS. The caller must assure this. for codes with equal lengths. Then the code starts with all zero bits
1..MAXBITS is interpreted as that code length. zero means that that for the first code of the shortest length, and the codes are integer
symbol does not occur in this code. increments for the same length, and zeros are appended as the length
increases. For the deflate format, these bits are stored backwards
The codes are sorted by computing a count of codes for each length, from their more natural integer increment ordering, and so when the
creating from that a table of starting indices for each length in the decoding tables are built in the large loop below, the integer codes
sorted table, and then entering the symbols in order in the sorted are incremented backwards.
table. The sorted table is work[], with that space being provided by
the caller. 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 length counts are used for other purposes as well, i.e. finding 1..MAXBITS is interpreted as that code length. zero means that that
the minimum and maximum length codes, determining if there are any symbol does not occur in this code.
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 codes are sorted by computing a count of codes for each length,
decoding tables. 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
table. The sorted table is work[], with that space being provided by
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ the caller.
for (len = 0; len <= MAXBITS; len++)
count[len] = 0; The length counts are used for other purposes as well, i.e. finding
for (sym = 0; sym < codes; sym++) the minimum and maximum length codes, determining if there are any
count[lens[sym]]++; codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the
/* bound code lengths, force root to be within code lengths */ decoding tables.
root = *bits; */
for (max = MAXBITS; max >= 1; max--)
if (count[max] != 0) break; /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
if (root > max) root = max; for (len = 0; len <= MAXBITS; len++)
if (max == 0) { /* no symbols to code at all */ count[len] = 0;
here.op = (unsigned char)64; /* invalid code marker */ for (sym = 0; sym < codes; sym++)
here.bits = (unsigned char)1; count[lens[sym]]++;
here.val = (unsigned short)0;
*(*table)++ = here; /* make a table to force an error */ /* bound code lengths, force root to be within code lengths */
*(*table)++ = here; root = *bits;
*bits = 1; for (max = MAXBITS; max >= 1; max--)
return 0; /* no symbols, but wait for decoding to report error */ if (count[max] != 0) break;
} if (root > max) root = max;
for (min = 1; min < max; min++) if (max == 0) { /* no symbols to code at all */
if (count[min] != 0) break; here.op = (unsigned char)64; /* invalid code marker */
if (root < min) root = min; here.bits = (unsigned char)1;
here.val = (unsigned short)0;
/* check for an over-subscribed or incomplete set of lengths */ *(*table)++ = here; /* make a table to force an error */
left = 1; *(*table)++ = here;
for (len = 1; len <= MAXBITS; len++) { *bits = 1;
left <<= 1; return 0; /* no symbols, but wait for decoding to report error */
left -= count[len]; }
if (left < 0) return -1; /* over-subscribed */ for (min = 1; min < max; min++)
} if (count[min] != 0) break;
if (left > 0 && (type == CODES || max != 1)) if (root < min) root = min;
return -1; /* incomplete set */
/* check for an over-subscribed or incomplete set of lengths */
/* generate offsets into symbol table for each length for sorting */ left = 1;
offs[1] = 0; for (len = 1; len <= MAXBITS; len++) {
for (len = 1; len < MAXBITS; len++) left <<= 1;
offs[len + 1] = offs[len] + count[len]; left -= count[len];
if (left < 0) return -1; /* over-subscribed */
/* sort symbols by length, by symbol order within each length */ }
for (sym = 0; sym < codes; sym++) if (left > 0 && (type == CODES || max != 1))
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; return -1; /* incomplete set */
/* /* generate offsets into symbol table for each length for sorting */
Create and fill in decoding tables. In this loop, the table being offs[1] = 0;
filled is at next and has curr index bits. The code being used is huff for (len = 1; len < MAXBITS; len++)
with length len. That code is converted to an index by dropping drop offs[len + 1] = offs[len] + count[len];
bits off of the bottom. For codes where len is less than drop + curr,
those top drop + curr - len bits are incremented through all values to /* sort symbols by length, by symbol order within each length */
fill the table with replicated entries. for (sym = 0; sym < codes; sym++)
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
root is the number of index bits for the root table. When len exceeds
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 Create and fill in decoding tables. In this loop, the table being
new sub-table should be started. drop is zero when the root table is filled is at next and has curr index bits. The code being used is huff
being filled, and drop is root when sub-tables are being filled. 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,
When a new sub-table is needed, it is necessary to look ahead in the those top drop + curr - len bits are incremented through all values to
code lengths to determine what size sub-table is needed. The length fill the table with replicated entries.
counts are used for this, and so count[] is decremented as codes are
entered in the tables. root is the number of index bits for the root table. When len exceeds
root, sub-tables are created pointed to by the root entry with an index
used keeps track of how many table entries have been allocated from the of the low root bits of huff. This is saved in low to check for when a
provided *table space. It is checked for LENS and DIST tables against new sub-table should be started. drop is zero when the root table is
the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in being filled, and drop is root when sub-tables are being filled.
the initial root table size constants. See the comments in inftrees.h
for more information. 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
sym increments through all symbols, and the loop terminates when counts are used for this, and so count[] is decremented as codes are
all codes of length max, i.e. all codes, have been processed. This entered in the tables.
routine permits incomplete codes, so another loop after this one fills
in the rest of the decoding tables with invalid code markers. used keeps track of how many table entries have been allocated from the
*/ provided *table space. It is checked for LENS and DIST tables against
the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
/* set up for code type */ the initial root table size constants. See the comments in inftrees.h
switch (type) { for more information.
case CODES:
base = extra = work; /* dummy value--not used */ sym increments through all symbols, and the loop terminates when
end = 19; all codes of length max, i.e. all codes, have been processed. This
break; routine permits incomplete codes, so another loop after this one fills
case LENS: in the rest of the decoding tables with invalid code markers.
base = lbase; */
base -= 257;
extra = lext; /* set up for code type */
extra -= 257; switch (type) {
end = 256; case CODES:
break; match = 20;
default: /* DISTS */ break;
base = dbase; case LENS:
extra = dext; base = lbase;
end = -1; extra = lext;
} match = 257;
break;
/* initialize state for loop */ case DISTS:
huff = 0; /* starting code */ base = dbase;
sym = 0; /* starting code symbol */ extra = dext;
len = min; /* starting code length */ }
next = *table; /* current table to fill in */
curr = root; /* current table index bits */ /* initialize state for loop */
drop = 0; /* current bits to drop from code for index */ huff = 0; /* starting code */
low = (unsigned)(-1); /* trigger new sub-table when len > root */ sym = 0; /* starting code symbol */
used = 1U << root; /* use root table entries */ len = min; /* starting code length */
mask = used - 1; /* mask for comparing low */ next = *table; /* current table to fill in */
curr = root; /* current table index bits */
/* check available table space */ drop = 0; /* current bits to drop from code for index */
if ((type == LENS && used > ENOUGH_LENS) || low = (unsigned)(-1); /* trigger new sub-table when len > root */
(type == DISTS && used > ENOUGH_DISTS)) used = 1U << root; /* use root table entries */
return 1; mask = used - 1; /* mask for comparing low */
/* process all codes and make table entries */ /* check available table space */
for (;;) { if ((type == LENS && used > ENOUGH_LENS) ||
/* create table entry */ (type == DISTS && used > ENOUGH_DISTS))
here.bits = (unsigned char)(len - drop); return 1;
if ((int)(work[sym]) < end) {
here.op = (unsigned char)0; /* process all codes and make table entries */
here.val = work[sym]; for (;;) {
} /* create table entry */
else if ((int)(work[sym]) > end) { here.bits = (unsigned char)(len - drop);
here.op = (unsigned char)(extra[work[sym]]); if (work[sym] + 1U < match) {
here.val = base[work[sym]]; here.op = (unsigned char)0;
} here.val = work[sym];
else { }
here.op = (unsigned char)(32 + 64); /* end of block */ else if (work[sym] >= match) {
here.val = 0; here.op = (unsigned char)(extra[work[sym] - match]);
} here.val = base[work[sym] - match];
}
/* replicate for those indices with low len bits equal to huff */ else {
incr = 1U << (len - drop); here.op = (unsigned char)(32 + 64); /* end of block */
fill = 1U << curr; here.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] = here;
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_LENS) ||
(*table)[low].op = (unsigned char)curr; (type == DISTS && used > ENOUGH_DISTS))
(*table)[low].bits = (unsigned char)root; return 1;
(*table)[low].val = (unsigned short)(next - *table);
} /* point entry in root table to sub-table */
} low = huff & mask;
(*table)[low].op = (unsigned char)curr;
/* fill in remaining table entry if code is incomplete (guaranteed to have (*table)[low].bits = (unsigned char)root;
at most one remaining entry, since if the code is incomplete, the (*table)[low].val = (unsigned short)(next - *table);
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 remaining table entry if code is incomplete (guaranteed to have
here.val = (unsigned short)0; at most one remaining entry, since if the code is incomplete, the
next[huff] = here; maximum code length that was allowed to get this far is one bit) */
} if (huff != 0) {
here.op = (unsigned char)64; /* invalid code marker */
/* set return parameters */ here.bits = (unsigned char)(len - drop);
*table += used; here.val = (unsigned short)0;
*bits = root; next[huff] = here;
return 0; }
}
/* set return parameters */
*table += used;
*bits = root;
return 0;
}
#ifdef BUILDFIXED
/*
If this is compiled with BUILDFIXED defined, and if inflate will be used in
multiple threads, and if atomics are not available, then inflate() must be
called with a fixed block (e.g. 0x03 0x00) to initialize the tables and must
return before any other threads are allowed to call inflate.
*/
static code *lenfix, *distfix;
static code fixed[544];
/* State for z_once(). */
local z_once_t built = Z_ONCE_INIT;
local void buildtables(void) {
unsigned sym, bits;
static code *next;
unsigned short lens[288], work[288];
/* literal/length table */
sym = 0;
while (sym < 144) lens[sym++] = 8;
while (sym < 256) lens[sym++] = 9;
while (sym < 280) lens[sym++] = 7;
while (sym < 288) lens[sym++] = 8;
next = fixed;
lenfix = next;
bits = 9;
inflate_table(LENS, lens, 288, &(next), &(bits), work);
/* distance table */
sym = 0;
while (sym < 32) lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, lens, 32, &(next), &(bits), work);
}
#else /* !BUILDFIXED */
# include "inffixed.h"
#endif /* BUILDFIXED */
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
If BUILDFIXED is defined, then instead this routine builds the tables the
first time it's called, and returns those tables the first time and
thereafter. This reduces the size of the code by about 2K bytes, in
exchange for a little execution time. However, BUILDFIXED should not be
used for threaded applications if atomics are not available, as it will
not be thread-safe.
*/
void inflate_fixed(struct inflate_state FAR *state) {
#ifdef BUILDFIXED
z_once(&built, buildtables);
#endif /* BUILDFIXED */
state->lencode = lenfix;
state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
#ifdef MAKEFIXED
#include <stdio.h>
/*
Write out the inffixed.h that will be #include'd above. Defining MAKEFIXED
also defines BUILDFIXED, so the tables are built on the fly. main() writes
those tables to stdout, which would directed to inffixed.h. Compile this
along with zutil.c:
cc -DMAKEFIXED -o fix inftrees.c zutil.c
./fix > inffixed.h
*/
int main(void) {
unsigned low, size;
struct inflate_state state;
inflate_fixed(&state);
puts("/* inffixed.h -- table for decoding fixed codes");
puts(" * Generated automatically by makefixed().");
puts(" */");
puts("");
puts("/* WARNING: this file should *not* be used by applications.");
puts(" It is part of the implementation of this library and is");
puts(" subject to change. Applications should only use zlib.h.");
puts(" */");
puts("");
size = 1U << 9;
printf("static const code lenfix[%u] = {", size);
low = 0;
for (;;) {
if ((low % 7) == 0) printf("\n ");
printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
state.lencode[low].bits, state.lencode[low].val);
if (++low == size) break;
putchar(',');
}
puts("\n};");
size = 1U << 5;
printf("\nstatic const code distfix[%u] = {", size);
low = 0;
for (;;) {
if ((low % 6) == 0) printf("\n ");
printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
state.distcode[low].val);
if (++low == size) break;
putchar(',');
}
puts("\n};");
return 0;
}
#endif /* MAKEFIXED */

View File

@@ -1,62 +1,64 @@
/* inftrees.h -- header to use inftrees.c /* inftrees.h -- header to use inftrees.c
* Copyright (C) 1995-2005, 2010 Mark Adler * Copyright (C) 1995-2026 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.
*/ */
/* Structure for decoding tables. Each entry provides either the /* Structure for decoding tables. Each entry provides either the
information needed to do the operation requested by the code that information needed to do the operation requested by the code that
indexed that table entry, or it provides a pointer to another indexed that table entry, or it provides a pointer to another
table that indexes more bits of the code. op indicates whether table that indexes more bits of the code. op indicates whether
the entry is a pointer to another table, a literal, a length or the entry is a pointer to another table, a literal, a length or
distance, an end-of-block, or an invalid code. For a table distance, an end-of-block, or an invalid code. For a table
pointer, the low four bits of op is the number of index bits of pointer, the low four bits of op is the number of index bits of
that table. For a length or distance, the low four bits of op that table. For a length or distance, the low four bits of op
is the number of extra bits to get after the code. bits is is the number of extra bits to get after the code. bits is
the number of bits in this code or part of the code to drop off the number of bits in this code or part of the code to drop off
of the bit buffer. val is the actual byte to output in the case of the bit buffer. val is the actual byte to output in the case
of a literal, the base length or distance, or the offset from of a literal, the base length or distance, or the offset from
the current table to the next table. Each entry is four bytes. */ the current table to the next table. Each entry is four bytes. */
typedef struct { typedef struct {
unsigned char op; /* operation, extra bits, table bits */ unsigned char op; /* operation, extra bits, table bits */
unsigned char bits; /* bits in this part of the code */ unsigned char bits; /* bits in this part of the code */
unsigned short val; /* offset in table or code value */ unsigned short val; /* offset in table or code value */
} code; } code;
/* op values as set by inflate_table(): /* op values as set by inflate_table():
00000000 - literal 00000000 - literal
0000tttt - table link, tttt != 0 is the number of table index bits 0000tttt - table link, tttt != 0 is the number of table index bits
0001eeee - length or distance, eeee is the number of extra bits 0001eeee - length or distance, eeee is the number of extra bits
01100000 - end of block 01100000 - end of block
01000000 - invalid code 01000000 - invalid code
*/ */
/* Maximum size of the dynamic table. The maximum number of code structures is /* 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 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 codes. These values were found by exhaustive searches using the program
examples/enough.c found in the zlib distribtution. The arguments to that examples/enough.c found in the zlib distribution. The arguments to that
program are the number of symbols, the initial root table size, and the program are the number of symbols, the initial root table size, and the
maximum bit length of a code. "enough 286 9 15" for literal/length codes maximum bit length of a code. "enough 286 9 15" for literal/length codes
returns returns 852, and "enough 30 6 15" for distance codes returns 592. returns 852, and "enough 30 6 15" for distance codes returns 592. The
The initial root table size (9 or 6) is found in the fifth argument of the initial root table size (9 or 6) is found in the fifth argument of the
inflate_table() calls in inflate.c and infback.c. If the root table size is inflate_table() calls in inflate.c and infback.c. If the root table size is
changed, then these maximum sizes would be need to be recalculated and changed, then these maximum sizes would be need to be recalculated and
updated. */ updated. */
#define ENOUGH_LENS 852 #define ENOUGH_LENS 852
#define ENOUGH_DISTS 592 #define ENOUGH_DISTS 592
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
/* Type of code to build for inflate_table() */ /* Type of code to build for inflate_table() */
typedef enum { typedef enum {
CODES, CODES,
LENS, LENS,
DISTS DISTS
} codetype; } codetype;
int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table, unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work)); unsigned FAR *bits, unsigned short FAR *work);
struct inflate_state;
void ZLIB_INTERNAL inflate_fixed(struct inflate_state FAR *state);

File diff suppressed because it is too large Load Diff

View File

@@ -1,128 +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 ZLIB_INTERNAL _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 ZLIB_INTERNAL _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,59 +1,101 @@
/* uncompr.c -- decompress a memory buffer /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003, 2010 Jean-loup Gailly. * Copyright (C) 1995-2026 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$ */ /* @(#) $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
of source bytes consumed. Upon return, source + *sourceLen points to the
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not first unused input byte.
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted. uncompress 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, or
int ZEXPORT uncompress (dest, destLen, source, sourceLen) Z_DATA_ERROR if the input data was corrupted, including if the input data is
Bytef *dest; an incomplete zlib stream.
uLongf *destLen;
const Bytef *source; The _z versions of the functions take size_t length arguments.
uLong sourceLen; */
{ int ZEXPORT uncompress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
z_stream stream; z_size_t *sourceLen) {
int err; z_stream stream;
int err;
stream.next_in = (z_const Bytef *)source; const uInt max = (uInt)-1;
stream.avail_in = (uInt)sourceLen; z_size_t len, left;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; if (sourceLen == NULL || (*sourceLen > 0 && source == NULL) ||
destLen == NULL || (*destLen > 0 && dest == NULL))
stream.next_out = dest; return Z_STREAM_ERROR;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; len = *sourceLen;
left = *destLen;
stream.zalloc = (alloc_func)0; if (left == 0 && dest == Z_NULL)
stream.zfree = (free_func)0; dest = (Bytef *)&stream.reserved; /* next_out cannot be NULL */
err = inflateInit(&stream); stream.next_in = (z_const Bytef *)source;
if (err != Z_OK) return err; stream.avail_in = 0;
stream.zalloc = (alloc_func)0;
err = inflate(&stream, Z_FINISH); stream.zfree = (free_func)0;
if (err != Z_STREAM_END) { stream.opaque = (voidpf)0;
inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) err = inflateInit(&stream);
return Z_DATA_ERROR; if (err != Z_OK) return err;
return err;
} stream.next_out = dest;
*destLen = stream.total_out; stream.avail_out = 0;
err = inflateEnd(&stream); do {
return err; if (stream.avail_out == 0) {
} stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
left -= stream.avail_out;
}
if (stream.avail_in == 0) {
stream.avail_in = len > (z_size_t)max ? max : (uInt)len;
len -= stream.avail_in;
}
err = inflate(&stream, Z_NO_FLUSH);
} while (err == Z_OK);
/* Set len and left to the unused input data and unused output space. Set
*sourceLen to the amount of input consumed. Set *destLen to the amount
of data produced. */
len += stream.avail_in;
left += stream.avail_out;
*sourceLen -= len;
*destLen -= left;
inflateEnd(&stream);
return err == Z_STREAM_END ? Z_OK :
err == Z_NEED_DICT ? Z_DATA_ERROR :
err == Z_BUF_ERROR && len == 0 ? Z_DATA_ERROR :
err;
}
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong *sourceLen) {
int ret;
z_size_t got = *destLen, used = *sourceLen;
ret = uncompress2_z(dest, &got, source, &used);
*sourceLen = (uLong)used;
*destLen = (uLong)got;
return ret;
}
int ZEXPORT uncompress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
z_size_t sourceLen) {
z_size_t used = sourceLen;
return uncompress2_z(dest, destLen, source, &used);
}
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen) {
uLong used = sourceLen;
return uncompress2(dest, destLen, source, &used);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,253 +1,331 @@
/* zutil.h -- internal interface and configuration of the compression library /* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2013 Jean-loup Gailly. * Copyright (C) 1995-2026 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$ */ /* @(#) $Id$ */
#ifndef ZUTIL_H #ifndef ZUTIL_H
#define ZUTIL_H #define ZUTIL_H
#ifdef HAVE_HIDDEN #ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else #else
# define ZLIB_INTERNAL # define ZLIB_INTERNAL
#endif #endif
#include "zlib.h" #include "zlib.h"
#if defined(STDC) && !defined(Z_SOLO) #if defined(STDC) && !defined(Z_SOLO)
# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
# include <stddef.h> # include <stddef.h>
# endif # endif
# include <string.h> # include <string.h>
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef Z_SOLO #ifndef local
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ # define local static
#endif #endif
/* since "static" is used to mean two completely different things in C, we
#ifndef local define "local" for the non-static meaning of "static", for readability
# define local static (compile with -Dlocal if your debugger can't find static symbols) */
#endif
/* compile with -Dlocal if your debugger can't find static symbols */ extern const char deflate_copyright[];
extern const char inflate_copyright[];
typedef unsigned char uch; extern const char inflate9_copyright[];
typedef uch FAR uchf;
typedef unsigned short ush; typedef unsigned char uch;
typedef ush FAR ushf; typedef uch FAR uchf;
typedef unsigned long ulg; typedef unsigned short ush;
typedef ush FAR ushf;
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ typedef unsigned long ulg;
/* (size given to avoid silly warnings with Visual C++) */
#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] # include <limits.h>
# if (ULONG_MAX == 0xffffffffffffffff)
#define ERR_RETURN(strm,err) \ # define Z_U8 unsigned long
return (strm->msg = ERR_MSG(err), (err)) # elif (ULLONG_MAX == 0xffffffffffffffff)
/* To be used only when the state is known to be valid */ # define Z_U8 unsigned long long
# elif (ULONG_LONG_MAX == 0xffffffffffffffff)
/* common constants */ # define Z_U8 unsigned long long
# elif (UINT_MAX == 0xffffffffffffffff)
#ifndef DEF_WBITS # define Z_U8 unsigned
# define DEF_WBITS MAX_WBITS # endif
#endif #endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if MAX_MEM_LEVEL >= 8 /* (size given to avoid silly warnings with Visual C++) */
# define DEF_MEM_LEVEL 8
#else #define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif #define ERR_RETURN(strm,err) \
/* default memLevel */ return (strm->msg = ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */
#define STORED_BLOCK 0
#define STATIC_TREES 1 /* common constants */
#define DYN_TREES 2 #if MAX_WBITS < 9 || MAX_WBITS > 15
/* The three kinds of block type */ # error MAX_WBITS must be in 9..15
#endif
#define MIN_MATCH 3 #ifndef DEF_WBITS
#define MAX_MATCH 258 # define DEF_WBITS MAX_WBITS
/* The minimum and maximum match lengths */ #endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
#if MAX_MEM_LEVEL >= 8
/* target dependencies */ # define DEF_MEM_LEVEL 8
#else
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) # define DEF_MEM_LEVEL MAX_MEM_LEVEL
# define OS_CODE 0x00 #endif
# ifndef Z_SOLO /* default memLevel */
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) #define STORED_BLOCK 0
/* Allow compilation with ANSI keywords only enabled */ #define STATIC_TREES 1
void _Cdecl farfree( void *block ); #define DYN_TREES 2
void *_Cdecl farmalloc( unsigned long nbytes ); /* The three kinds of block type */
# else
# include <alloc.h> #define MIN_MATCH 3
# endif #define MAX_MATCH 258
# else /* MSC or DJGPP */ /* The minimum and maximum match lengths */
# include <malloc.h>
# endif #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
# endif
#endif /* target dependencies */
#ifdef AMIGA #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x01 # define OS_CODE 0x00
#endif # ifndef Z_SOLO
# if defined(__TURBOC__) || defined(__BORLANDC__)
#if defined(VAXC) || defined(VMS) # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
# define OS_CODE 0x02 /* Allow compilation with ANSI keywords only enabled */
# define F_OPEN(name, mode) \ void _Cdecl farfree( void *block );
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") void *_Cdecl farmalloc( unsigned long nbytes );
#endif # else
# include <alloc.h>
#if defined(ATARI) || defined(atarist) # endif
# define OS_CODE 0x05 # else /* MSC or DJGPP */
#endif # include <malloc.h>
# endif
#ifdef OS2 # endif
# define OS_CODE 0x06 #endif
# if defined(M_I86) && !defined(Z_SOLO)
# include <malloc.h> #ifdef AMIGA
# endif # define OS_CODE 1
#endif #endif
#if defined(MACOS) || defined(TARGET_OS_MAC) #if defined(VAXC) || defined(VMS)
# define OS_CODE 0x07 # define OS_CODE 2
# ifndef Z_SOLO # define F_OPEN(name, mode) \
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
# include <unix.h> /* for fdopen */ #endif
# else
# ifndef fdopen #ifdef __370__
# define fdopen(fd,mode) NULL /* No fdopen() */ # if __TARGET_LIB__ < 0x20000000
# endif # define OS_CODE 4
# endif # elif __TARGET_LIB__ < 0x40000000
# endif # define OS_CODE 11
#endif # else
# define OS_CODE 8
#ifdef TOPS20 # endif
# define OS_CODE 0x0a #endif
#endif
#if defined(ATARI) || defined(atarist)
#ifdef WIN32 # define OS_CODE 5
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ #endif
# define OS_CODE 0x0b
# endif #ifdef OS2
#endif # define OS_CODE 6
# if defined(M_I86) && !defined(Z_SOLO)
#ifdef __50SERIES /* Prime/PRIMOS */ # include <malloc.h>
# define OS_CODE 0x0f # endif
#endif #endif
#if defined(_BEOS_) || defined(RISCOS) #if defined(MACOS)
# define fdopen(fd,mode) NULL /* No fdopen() */ # define OS_CODE 7
#endif #endif
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX #if defined(__acorn) || defined(__riscos)
# if defined(_WIN32_WCE) # define OS_CODE 13
# define fdopen(fd,mode) NULL /* No fdopen() */ #endif
# ifndef _PTRDIFF_T_DEFINED
typedef int ptrdiff_t; #if defined(WIN32) && !defined(__CYGWIN__)
# define _PTRDIFF_T_DEFINED # define OS_CODE 10
# endif #endif
# else
# define fdopen(fd,type) _fdopen(fd,type) #ifdef _BEOS_
# endif # define OS_CODE 16
#endif #endif
#if defined(__BORLANDC__) && !defined(MSDOS) #ifdef __TOS_OS400__
#pragma warn -8004 # define OS_CODE 18
#pragma warn -8008 #endif
#pragma warn -8066
#endif #ifdef __APPLE__
# define OS_CODE 19
/* provide prototypes for these when building zlib without LFS */ #endif
#if !defined(_WIN32) && \
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) #if defined(__BORLANDC__) && !defined(MSDOS)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); #pragma warn -8004
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); #pragma warn -8008
#endif #pragma warn -8066
#endif
/* common defaults */
/* provide prototypes for these when building zlib without LFS */
#ifndef OS_CODE #ifndef Z_LARGE64
# define OS_CODE 0x03 /* assume Unix */ ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
#endif ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
#ifndef F_OPEN #endif
# define F_OPEN(name, mode) fopen((name), (mode))
#endif /* common defaults */
/* functions */ #ifndef OS_CODE
# define OS_CODE 3 /* assume Unix */
#if defined(pyr) || defined(Z_SOLO) #endif
# define NO_MEMCPY
#endif #ifndef F_OPEN
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) # define F_OPEN(name, mode) fopen((name), (mode))
/* Use our own functions for small and medium model with MSC <= 5.0. #endif
* You may have to use the same strategy for Borland C (untested).
* The __SC__ check is for Symantec. /* functions */
*/
# define NO_MEMCPY #if defined(pyr) || defined(Z_SOLO)
#endif # define NO_MEMCPY
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) #endif
# define HAVE_MEMCPY #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
#endif /* Use our own functions for small and medium model with MSC <= 5.0.
#ifdef HAVE_MEMCPY * You may have to use the same strategy for Borland C (untested).
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ * The __SC__ check is for Symantec.
# define zmemcpy _fmemcpy */
# define zmemcmp _fmemcmp # define NO_MEMCPY
# define zmemzero(dest, len) _fmemset(dest, 0, len) #endif
# else #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# define zmemcpy memcpy # define HAVE_MEMCPY
# define zmemcmp memcmp #endif
# define zmemzero(dest, len) memset(dest, 0, len) #ifdef HAVE_MEMCPY
# endif # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
#else # define zmemcpy _fmemcpy
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); # define zmemcmp _fmemcmp
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); # define zmemzero(dest, len) _fmemset(dest, 0, len)
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); # else
#endif # define zmemcpy memcpy
# define zmemcmp memcmp
/* Diagnostic functions */ # define zmemzero(dest, len) memset(dest, 0, len)
#ifdef DEBUG # endif
# include <stdio.h> #else
extern int ZLIB_INTERNAL z_verbose; void ZLIB_INTERNAL zmemcpy(void FAR *, const void FAR *, z_size_t);
extern void ZLIB_INTERNAL z_error OF((char *m)); int ZLIB_INTERNAL zmemcmp(const void FAR *, const void FAR *, z_size_t);
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} void ZLIB_INTERNAL zmemzero(void FAR *, z_size_t);
# define Trace(x) {if (z_verbose>=0) fprintf x ;} #endif
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
# define Tracevv(x) {if (z_verbose>1) fprintf x ;} /* Diagnostic functions */
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} #ifdef ZLIB_DEBUG
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} # include <stdio.h>
#else extern int ZLIB_INTERNAL z_verbose;
# define Assert(cond,msg) extern void ZLIB_INTERNAL z_error(char *m);
# define Trace(x) # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Tracev(x) # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracevv(x) # define Tracev(x) {if (z_verbose>0) fprintf x ;}
# define Tracec(c,x) # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
# define Tracecv(c,x) # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
#endif # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
#else
#ifndef Z_SOLO # define Assert(cond,msg)
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, # define Trace(x)
unsigned size)); # define Tracev(x)
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); # define Tracevv(x)
#endif # define Tracec(c,x)
# define Tracecv(c,x)
#define ZALLOC(strm, items, size) \ #endif
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) #ifndef Z_SOLO
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
unsigned size);
/* Reverse the bytes in a 32-bit value */ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ #endif
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
#define ZALLOC(strm, items, size) \
#endif /* ZUTIL_H */ (*((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);}
/* Reverse the bytes in a 32-bit value */
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
#ifdef Z_ONCE
/*
Create a local z_once() function depending on the availability of atomics.
*/
/* Check for the availability of atomics. */
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
!defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
typedef struct {
atomic_flag begun;
atomic_int done;
} z_once_t;
#define Z_ONCE_INIT {ATOMIC_FLAG_INIT, 0}
/*
Run the provided init() function exactly once, even if multiple threads
invoke once() at the same time. The state must be a once_t initialized with
Z_ONCE_INIT.
*/
local void z_once(z_once_t *state, void (*init)(void)) {
if (!atomic_load(&state->done)) {
if (atomic_flag_test_and_set(&state->begun))
while (!atomic_load(&state->done))
;
else {
init();
atomic_store(&state->done, 1);
}
}
}
#else /* no atomics */
#warning zlib not thread-safe
typedef struct z_once_s {
volatile int begun;
volatile int done;
} z_once_t;
#define Z_ONCE_INIT {0, 0}
/* Test and set. Alas, not atomic, but tries to limit the period of
vulnerability. */
local int test_and_set(int volatile *flag) {
int was;
was = *flag;
*flag = 1;
return was;
}
/* Run the provided init() function once. This is not thread-safe. */
local void z_once(z_once_t *state, void (*init)(void)) {
if (!state->done) {
if (test_and_set(&state->begun))
while (!state->done)
;
else {
init();
state->done = 1;
}
}
}
#endif /* ?atomics */
#endif /* Z_ONCE */
#endif /* ZUTIL_H */