Unverified Commit 2dee5bd8 by Edward Thomson Committed by GitHub

Merge pull request #6698 from libgit2/ethomson/deps

zlib: upgrade bundled zlib to v1.3
parents 156e0899 d83fccc9
...@@ -365,7 +365,7 @@ Public License instead of this License. ...@@ -365,7 +365,7 @@ Public License instead of this License.
The bundled ZLib code is licensed under the ZLib license: The bundled ZLib code is licensed under the ZLib license:
Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler (C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
......
disable_warnings(implicit-fallthrough) disable_warnings(implicit-fallthrough)
add_definitions(-DNO_VIZ -DSTDC -DNO_GZIP) add_definitions(-DNO_VIZ -DSTDC -DNO_GZIP -DHAVE_SYS_TYPES_H -DHAVE_STDINT_H -DHAVE_STDDEF_H)
if(MINGW OR MSYS)
add_definitions(-DZ_HAVE_UNISTD_H -D_LFS64_LARGEFILE -D_LARGEFILE64_SOURCE=1)
endif()
file(GLOB SRC_ZLIB "*.c" "*.h") file(GLOB SRC_ZLIB "*.c" "*.h")
list(SORT SRC_ZLIB) list(SORT SRC_ZLIB)
include_directories(".") include_directories(".")
......
Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you
use this software in a product, an acknowledgment in the
product documentation would be appreciated but is not
required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Jean-loup Gailly Mark Adler
The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files rfc1950 (zlib
format), rfc1951 (deflate format) and rfc1952 (gzip format).
Copyright notice:
(C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include "zutil.h" #include "zutil.h"
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#define BASE 65521U /* largest prime smaller than 65536 */ #define BASE 65521U /* largest prime smaller than 65536 */
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
...@@ -60,11 +58,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); ...@@ -60,11 +58,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_z(adler, buf, len) uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
uLong adler;
const Bytef *buf;
z_size_t len;
{
unsigned long sum2; unsigned long sum2;
unsigned n; unsigned n;
...@@ -131,20 +125,12 @@ uLong ZEXPORT adler32_z(adler, buf, len) ...@@ -131,20 +125,12 @@ uLong ZEXPORT adler32_z(adler, buf, len)
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len) uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
uLong adler;
const Bytef *buf;
uInt len;
{
return adler32_z(adler, buf, len); return adler32_z(adler, buf, len);
} }
/* ========================================================================= */ /* ========================================================================= */
local uLong adler32_combine_(adler1, adler2, len2) local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
uLong adler1;
uLong adler2;
z_off64_t len2;
{
unsigned long sum1; unsigned long sum1;
unsigned long sum2; unsigned long sum2;
unsigned rem; unsigned rem;
...@@ -169,18 +155,10 @@ local uLong adler32_combine_(adler1, adler2, len2) ...@@ -169,18 +155,10 @@ local uLong adler32_combine_(adler1, adler2, len2)
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2) uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
uLong adler1;
uLong adler2;
z_off_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
uLong ZEXPORT adler32_combine64(adler1, adler2, len2) uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
uLong adler1;
uLong adler2;
z_off64_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
...@@ -98,10 +98,6 @@ ...@@ -98,10 +98,6 @@
# endif # endif
#endif #endif
/* Local functions. */
local z_crc_t multmodp OF((z_crc_t a, z_crc_t b));
local z_crc_t x2nmodp OF((z_off64_t n, unsigned k));
/* If available, use the ARM processor CRC32 instruction. */ /* If available, use the ARM processor CRC32 instruction. */
#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8 #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8
# define ARMCRC32 # define ARMCRC32
...@@ -114,12 +110,7 @@ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); ...@@ -114,12 +110,7 @@ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k));
instruction, if one is available. This assumes that word_t is either 32 bits instruction, if one is available. This assumes that word_t is either 32 bits
or 64 bits. or 64 bits.
*/ */
local z_word_t byte_swap(z_word_t word) {
local z_word_t byte_swap(z_word_t word);
local z_word_t byte_swap(word)
z_word_t word;
{
# if W == 8 # if W == 8
return return
(word & 0xff00000000000000) >> 56 | (word & 0xff00000000000000) >> 56 |
...@@ -140,24 +131,77 @@ local z_word_t byte_swap(word) ...@@ -140,24 +131,77 @@ local z_word_t byte_swap(word)
} }
#endif #endif
#ifdef DYNAMIC_CRC_TABLE
/* =========================================================================
* Table of powers of x for combining CRC-32s, filled in by make_crc_table()
* below.
*/
local z_crc_t FAR x2n_table[32];
#else
/* =========================================================================
* Tables for byte-wise and braided CRC-32 calculations, and a table of powers
* of x for combining CRC-32s, all made by make_crc_table().
*/
# include "crc32.h"
#endif
/* CRC polynomial. */ /* CRC polynomial. */
#define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
#ifdef DYNAMIC_CRC_TABLE /*
Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
reflected. For speed, this requires that a not be zero.
*/
local z_crc_t multmodp(z_crc_t a, z_crc_t b) {
z_crc_t m, p;
m = (z_crc_t)1 << 31;
p = 0;
for (;;) {
if (a & m) {
p ^= b;
if ((a & (m - 1)) == 0)
break;
}
m >>= 1;
b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
}
return p;
}
/*
Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
initialized.
*/
local z_crc_t x2nmodp(z_off64_t n, unsigned k) {
z_crc_t p;
p = (z_crc_t)1 << 31; /* x^0 == 1 */
while (n) {
if (n & 1)
p = multmodp(x2n_table[k & 31], p);
n >>= 1;
k++;
}
return p;
}
#ifdef DYNAMIC_CRC_TABLE
/* =========================================================================
* Build the tables for byte-wise and braided CRC-32 calculations, and a table
* of powers of x for combining CRC-32s.
*/
local z_crc_t FAR crc_table[256]; local z_crc_t FAR crc_table[256];
local z_crc_t FAR x2n_table[32];
local void make_crc_table OF((void));
#ifdef W #ifdef W
local z_word_t FAR crc_big_table[256]; local z_word_t FAR crc_big_table[256];
local z_crc_t FAR crc_braid_table[W][256]; local z_crc_t FAR crc_braid_table[W][256];
local z_word_t FAR crc_braid_big_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256];
local void braid OF((z_crc_t [][256], z_word_t [][256], int, int)); local void braid(z_crc_t [][256], z_word_t [][256], int, int);
#endif #endif
#ifdef MAKECRCH #ifdef MAKECRCH
local void write_table OF((FILE *, const z_crc_t FAR *, int)); local void write_table(FILE *, const z_crc_t FAR *, int);
local void write_table32hi OF((FILE *, const z_word_t FAR *, int)); local void write_table32hi(FILE *, const z_word_t FAR *, int);
local void write_table64 OF((FILE *, const z_word_t FAR *, int)); local void write_table64(FILE *, const z_word_t FAR *, int);
#endif /* MAKECRCH */ #endif /* MAKECRCH */
/* /*
...@@ -170,7 +214,6 @@ local void make_crc_table OF((void)); ...@@ -170,7 +214,6 @@ local void make_crc_table OF((void));
/* Definition of once functionality. */ /* Definition of once functionality. */
typedef struct once_s once_t; typedef struct once_s once_t;
local void once OF((once_t *, void (*)(void)));
/* Check for the availability of atomics. */ /* Check for the availability of atomics. */
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
...@@ -190,10 +233,7 @@ struct once_s { ...@@ -190,10 +233,7 @@ struct once_s {
invoke once() at the same time. The state must be a once_t initialized with invoke once() at the same time. The state must be a once_t initialized with
ONCE_INIT. ONCE_INIT.
*/ */
local void once(state, init) local void once(once_t *state, void (*init)(void)) {
once_t *state;
void (*init)(void);
{
if (!atomic_load(&state->done)) { if (!atomic_load(&state->done)) {
if (atomic_flag_test_and_set(&state->begun)) if (atomic_flag_test_and_set(&state->begun))
while (!atomic_load(&state->done)) while (!atomic_load(&state->done))
...@@ -216,10 +256,7 @@ struct once_s { ...@@ -216,10 +256,7 @@ struct once_s {
/* Test and set. Alas, not atomic, but tries to minimize the period of /* Test and set. Alas, not atomic, but tries to minimize the period of
vulnerability. */ vulnerability. */
local int test_and_set OF((int volatile *)); local int test_and_set(int volatile *flag) {
local int test_and_set(flag)
int volatile *flag;
{
int was; int was;
was = *flag; was = *flag;
...@@ -228,10 +265,7 @@ local int test_and_set(flag) ...@@ -228,10 +265,7 @@ local int test_and_set(flag)
} }
/* Run the provided init() function once. This is not thread-safe. */ /* Run the provided init() function once. This is not thread-safe. */
local void once(state, init) local void once(once_t *state, void (*init)(void)) {
once_t *state;
void (*init)(void);
{
if (!state->done) { if (!state->done) {
if (test_and_set(&state->begun)) if (test_and_set(&state->begun))
while (!state->done) while (!state->done)
...@@ -273,8 +307,7 @@ local once_t made = ONCE_INIT; ...@@ -273,8 +307,7 @@ local once_t made = ONCE_INIT;
combinations of CRC register values and incoming bytes. combinations of CRC register values and incoming bytes.
*/ */
local void make_crc_table() local void make_crc_table(void) {
{
unsigned i, j, n; unsigned i, j, n;
z_crc_t p; z_crc_t p;
...@@ -441,11 +474,7 @@ local void make_crc_table() ...@@ -441,11 +474,7 @@ local void make_crc_table()
Write the 32-bit values in table[0..k-1] to out, five per line in Write the 32-bit values in table[0..k-1] to out, five per line in
hexadecimal separated by commas. hexadecimal separated by commas.
*/ */
local void write_table(out, table, k) local void write_table(FILE *out, const z_crc_t FAR *table, int k) {
FILE *out;
const z_crc_t FAR *table;
int k;
{
int n; int n;
for (n = 0; n < k; n++) for (n = 0; n < k; n++)
...@@ -458,11 +487,7 @@ local void write_table(out, table, k) ...@@ -458,11 +487,7 @@ local void write_table(out, table, k)
Write the high 32-bits of each value in table[0..k-1] to out, five per line Write the high 32-bits of each value in table[0..k-1] to out, five per line
in hexadecimal separated by commas. in hexadecimal separated by commas.
*/ */
local void write_table32hi(out, table, k) local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) {
FILE *out;
const z_word_t FAR *table;
int k;
{
int n; int n;
for (n = 0; n < k; n++) for (n = 0; n < k; n++)
...@@ -478,11 +503,7 @@ int k; ...@@ -478,11 +503,7 @@ int k;
bits. If not, then the type cast and format string can be adjusted bits. If not, then the type cast and format string can be adjusted
accordingly. accordingly.
*/ */
local void write_table64(out, table, k) local void write_table64(FILE *out, const z_word_t FAR *table, int k) {
FILE *out;
const z_word_t FAR *table;
int k;
{
int n; int n;
for (n = 0; n < k; n++) for (n = 0; n < k; n++)
...@@ -492,8 +513,7 @@ local void write_table64(out, table, k) ...@@ -492,8 +513,7 @@ local void write_table64(out, table, k)
} }
/* Actually do the deed. */ /* Actually do the deed. */
int main() int main(void) {
{
make_crc_table(); make_crc_table();
return 0; return 0;
} }
...@@ -505,12 +525,7 @@ int main() ...@@ -505,12 +525,7 @@ int main()
Generate the little and big-endian braid tables for the given n and z_word_t Generate the little and big-endian braid tables for the given n and z_word_t
size w. Each array must have room for w blocks of 256 elements. size w. Each array must have room for w blocks of 256 elements.
*/ */
local void braid(ltl, big, n, w) local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) {
z_crc_t ltl[][256];
z_word_t big[][256];
int n;
int w;
{
int k; int k;
z_crc_t i, p, q; z_crc_t i, p, q;
for (k = 0; k < w; k++) { for (k = 0; k < w; k++) {
...@@ -525,69 +540,13 @@ local void braid(ltl, big, n, w) ...@@ -525,69 +540,13 @@ local void braid(ltl, big, n, w)
} }
#endif #endif
#else /* !DYNAMIC_CRC_TABLE */
/* ========================================================================
* Tables for byte-wise and braided CRC-32 calculations, and a table of powers
* of x for combining CRC-32s, all made by make_crc_table().
*/
#include "crc32.h"
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
/* ========================================================================
* Routines used for CRC calculation. Some are also required for the table
* generation above.
*/
/*
Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
reflected. For speed, this requires that a not be zero.
*/
local z_crc_t multmodp(a, b)
z_crc_t a;
z_crc_t b;
{
z_crc_t m, p;
m = (z_crc_t)1 << 31;
p = 0;
for (;;) {
if (a & m) {
p ^= b;
if ((a & (m - 1)) == 0)
break;
}
m >>= 1;
b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
}
return p;
}
/*
Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
initialized.
*/
local z_crc_t x2nmodp(n, k)
z_off64_t n;
unsigned k;
{
z_crc_t p;
p = (z_crc_t)1 << 31; /* x^0 == 1 */
while (n) {
if (n & 1)
p = multmodp(x2n_table[k & 31], p);
n >>= 1;
k++;
}
return p;
}
/* ========================================================================= /* =========================================================================
* This function can be used by asm versions of crc32(), and to force the * This function can be used by asm versions of crc32(), and to force the
* generation of the CRC tables in a threaded application. * generation of the CRC tables in a threaded application.
*/ */
const z_crc_t FAR * ZEXPORT get_crc_table() const z_crc_t FAR * ZEXPORT get_crc_table(void) {
{
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
once(&made, make_crc_table); once(&made, make_crc_table);
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
...@@ -613,11 +572,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table() ...@@ -613,11 +572,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
#define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */
#define Z_BATCH_MIN 800 /* fewest words in a final batch */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */
unsigned long ZEXPORT crc32_z(crc, buf, len) unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
unsigned long crc; z_size_t len) {
const unsigned char FAR *buf;
z_size_t len;
{
z_crc_t val; z_crc_t val;
z_word_t crc1, crc2; z_word_t crc1, crc2;
const z_word_t *word; const z_word_t *word;
...@@ -633,7 +589,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) ...@@ -633,7 +589,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
/* Pre-condition the CRC */ /* Pre-condition the CRC */
crc ^= 0xffffffff; crc = (~crc) & 0xffffffff;
/* Compute the CRC up to a word boundary. */ /* Compute the CRC up to a word boundary. */
while (len && ((z_size_t)buf & 7) != 0) { while (len && ((z_size_t)buf & 7) != 0) {
...@@ -648,8 +604,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) ...@@ -648,8 +604,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
len &= 7; len &= 7;
/* Do three interleaved CRCs to realize the throughput of one crc32x /* Do three interleaved CRCs to realize the throughput of one crc32x
instruction per cycle. Each CRC is calcuated on Z_BATCH words. The three instruction per cycle. Each CRC is calculated on Z_BATCH words. The
CRCs are combined into a single CRC after each set of batches. */ three CRCs are combined into a single CRC after each set of batches. */
while (num >= 3 * Z_BATCH) { while (num >= 3 * Z_BATCH) {
crc1 = 0; crc1 = 0;
crc2 = 0; crc2 = 0;
...@@ -712,26 +668,19 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) ...@@ -712,26 +668,19 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
#ifdef W #ifdef W
local z_crc_t crc_word(z_word_t data);
local z_word_t crc_word_big(z_word_t data);
/* /*
Return the CRC of the W bytes in the word_t data, taking the Return the CRC of the W bytes in the word_t data, taking the
least-significant byte of the word as the first byte of data, without any pre least-significant byte of the word as the first byte of data, without any pre
or post conditioning. This is used to combine the CRCs of each braid. or post conditioning. This is used to combine the CRCs of each braid.
*/ */
local z_crc_t crc_word(data) local z_crc_t crc_word(z_word_t data) {
z_word_t data;
{
int k; int k;
for (k = 0; k < W; k++) for (k = 0; k < W; k++)
data = (data >> 8) ^ crc_table[data & 0xff]; data = (data >> 8) ^ crc_table[data & 0xff];
return (z_crc_t)data; return (z_crc_t)data;
} }
local z_word_t crc_word_big(data) local z_word_t crc_word_big(z_word_t data) {
z_word_t data;
{
int k; int k;
for (k = 0; k < W; k++) for (k = 0; k < W; k++)
data = (data << 8) ^ data = (data << 8) ^
...@@ -742,11 +691,8 @@ local z_word_t crc_word_big(data) ...@@ -742,11 +691,8 @@ local z_word_t crc_word_big(data)
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
unsigned long ZEXPORT crc32_z(crc, buf, len) unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
unsigned long crc; z_size_t len) {
const unsigned char FAR *buf;
z_size_t len;
{
/* Return initial CRC, if requested. */ /* Return initial CRC, if requested. */
if (buf == Z_NULL) return 0; if (buf == Z_NULL) return 0;
...@@ -755,7 +701,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) ...@@ -755,7 +701,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
/* Pre-condition the CRC */ /* Pre-condition the CRC */
crc ^= 0xffffffff; crc = (~crc) & 0xffffffff;
#ifdef W #ifdef W
...@@ -778,8 +724,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) ...@@ -778,8 +724,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
words = (z_word_t const *)buf; words = (z_word_t const *)buf;
/* Do endian check at execution time instead of compile time, since ARM /* Do endian check at execution time instead of compile time, since ARM
processors can change the endianess at execution time. If the processors can change the endianness at execution time. If the
compiler knows what the endianess will be, it can optimize out the compiler knows what the endianness will be, it can optimize out the
check and the unused branch. */ check and the unused branch. */
endian = 1; endian = 1;
if (*(unsigned char *)&endian) { if (*(unsigned char *)&endian) {
...@@ -1066,39 +1012,26 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) ...@@ -1066,39 +1012,26 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len) unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf,
unsigned long crc; uInt len) {
const unsigned char FAR *buf;
uInt len;
{
return crc32_z(crc, buf, len); return crc32_z(crc, buf, len);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine64(crc1, crc2, len2) uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) {
uLong crc1;
uLong crc2;
z_off64_t len2;
{
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
once(&made, make_crc_table); once(&made, make_crc_table);
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
return multmodp(x2nmodp(len2, 3), crc1) ^ crc2; return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine(crc1, crc2, len2) uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) {
uLong crc1; return crc32_combine64(crc1, crc2, (z_off64_t)len2);
uLong crc2;
z_off_t len2;
{
return crc32_combine64(crc1, crc2, len2);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine_gen64(len2) uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) {
z_off64_t len2;
{
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
once(&made, make_crc_table); once(&made, make_crc_table);
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
...@@ -1106,17 +1039,11 @@ uLong ZEXPORT crc32_combine_gen64(len2) ...@@ -1106,17 +1039,11 @@ uLong ZEXPORT crc32_combine_gen64(len2)
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine_gen(len2) uLong ZEXPORT crc32_combine_gen(z_off_t len2) {
z_off_t len2; return crc32_combine_gen64((z_off64_t)len2);
{
return crc32_combine_gen64(len2);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine_op(crc1, crc2, op) uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) {
uLong crc1; return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
uLong crc2;
uLong op;
{
return multmodp(op, crc1) ^ crc2;
} }
/* deflate.c -- compress data using the deflation algorithm /* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler * Copyright (C) 1995-2023 Jean-loup Gailly and 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
*/ */
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#include "deflate.h" #include "deflate.h"
const char deflate_copyright[] = const char deflate_copyright[] =
" deflate 1.2.12 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
...@@ -60,9 +60,6 @@ const char deflate_copyright[] = ...@@ -60,9 +60,6 @@ const char deflate_copyright[] =
copyright string in the executable of your product. copyright string in the executable of your product.
*/ */
/* ===========================================================================
* Function prototypes.
*/
typedef enum { typedef enum {
need_more, /* block not completed, need more input or more output */ need_more, /* block not completed, need more input or more output */
block_done, /* block flush performed */ block_done, /* block flush performed */
...@@ -70,35 +67,16 @@ typedef enum { ...@@ -70,35 +67,16 @@ typedef enum {
finish_done /* finish done, accept no more input or output */ finish_done /* finish done, accept no more input or output */
} block_state; } block_state;
typedef block_state (*compress_func) OF((deflate_state *s, int flush)); typedef block_state (*compress_func)(deflate_state *s, int flush);
/* Compression function. Returns the block state after the call. */ /* Compression function. Returns the block state after the call. */
local int deflateStateCheck OF((z_streamp strm)); local block_state deflate_stored(deflate_state *s, int flush);
local void slide_hash OF((deflate_state *s)); local block_state deflate_fast(deflate_state *s, int flush);
local void fill_window OF((deflate_state *s));
local block_state deflate_stored OF((deflate_state *s, int flush));
local block_state deflate_fast OF((deflate_state *s, int flush));
#ifndef FASTEST #ifndef FASTEST
local block_state deflate_slow OF((deflate_state *s, int flush)); local block_state deflate_slow(deflate_state *s, int flush);
#endif
local block_state deflate_rle OF((deflate_state *s, int flush));
local block_state deflate_huff OF((deflate_state *s, int flush));
local void lm_init OF((deflate_state *s));
local void putShortMSB OF((deflate_state *s, uInt b));
local void flush_pending OF((z_streamp strm));
local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
#ifdef ASMV
# pragma message("Assembler code may have bugs -- use at your own risk")
void match_init OF((void)); /* asm code initialization */
uInt longest_match OF((deflate_state *s, IPos cur_match));
#else
local uInt longest_match OF((deflate_state *s, IPos cur_match));
#endif
#ifdef ZLIB_DEBUG
local void check_match OF((deflate_state *s, IPos start, IPos match,
int length));
#endif #endif
local block_state deflate_rle(deflate_state *s, int flush);
local block_state deflate_huff(deflate_state *s, int flush);
/* =========================================================================== /* ===========================================================================
* Local data * Local data
...@@ -160,7 +138,7 @@ local const config configuration_table[10] = { ...@@ -160,7 +138,7 @@ local const config configuration_table[10] = {
* characters, so that a running hash key can be computed from the previous * characters, so that a running hash key can be computed from the previous
* key instead of complete recalculation each time. * key instead of complete recalculation each time.
*/ */
#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) #define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask)
/* =========================================================================== /* ===========================================================================
...@@ -191,9 +169,9 @@ local const config configuration_table[10] = { ...@@ -191,9 +169,9 @@ local const config configuration_table[10] = {
*/ */
#define CLEAR_HASH(s) \ #define CLEAR_HASH(s) \
do { \ do { \
s->head[s->hash_size-1] = NIL; \ s->head[s->hash_size - 1] = NIL; \
zmemzero((Bytef *)s->head, \ zmemzero((Bytef *)s->head, \
(unsigned)(s->hash_size-1)*sizeof(*s->head)); \ (unsigned)(s->hash_size - 1)*sizeof(*s->head)); \
} while (0) } while (0)
/* =========================================================================== /* ===========================================================================
...@@ -203,12 +181,10 @@ local const config configuration_table[10] = { ...@@ -203,12 +181,10 @@ local const config configuration_table[10] = {
*/ */
#if defined(__has_feature) #if defined(__has_feature)
# if __has_feature(memory_sanitizer) # if __has_feature(memory_sanitizer)
__attribute__((no_sanitize("memory"))) __attribute__((no_sanitize("memory")))
# endif # endif
#endif #endif
local void slide_hash(s) local void slide_hash(deflate_state *s) {
deflate_state *s;
{
unsigned n, m; unsigned n, m;
Posf *p; Posf *p;
uInt wsize = s->w_size; uInt wsize = s->w_size;
...@@ -232,30 +208,177 @@ local void slide_hash(s) ...@@ -232,30 +208,177 @@ local void slide_hash(s)
#endif #endif
} }
/* ===========================================================================
* Read a new buffer from the current input stream, update the adler32
* and total number of bytes read. All deflate() input goes through
* this function so some applications may wish to modify it to avoid
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) {
unsigned len = strm->avail_in;
if (len > size) len = size;
if (len == 0) return 0;
strm->avail_in -= len;
zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
strm->adler = crc32(strm->adler, buf, len);
}
#endif
strm->next_in += len;
strm->total_in += len;
return len;
}
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead.
*
* IN assertion: lookahead < MIN_LOOKAHEAD
* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
* At least one byte has been read, or avail_in == 0; reads are
* performed for at least two bytes (required for the zip translate_eol
* option -- not supported here).
*/
local void fill_window(deflate_state *s) {
unsigned n;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* Deal with !@#$% 64K limit: */
if (sizeof(int) <= 2) {
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
more = wsize;
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if
* strstart == 0 && lookahead == 1 (input done a byte at time)
*/
more--;
}
}
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (s->strstart >= wsize + MAX_DIST(s)) {
zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
if (s->insert > s->strstart)
s->insert = s->strstart;
slide_hash(s);
more += wsize;
}
if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
* => more >= window_size - 2*WSIZE + 2
* In the BIG_MEM or MMAP case (not yet supported),
* window_size == input_size + MIN_LOOKAHEAD &&
* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
* Otherwise, window_size == 2*WSIZE so more >= 2.
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
if (s->lookahead + s->insert >= MIN_MATCH) {
uInt str = s->strstart - s->insert;
s->ins_h = s->window[str];
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
while (s->insert) {
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
s->head[s->ins_h] = (Pos)str;
str++;
s->insert--;
if (s->lookahead + s->insert < MIN_MATCH)
break;
}
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
*/
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
/* If the WIN_INIT bytes after the end of the current data have never been
* written, then zero those bytes in order to avoid memory check reports of
* the use of uninitialized (or uninitialised as Julian writes) bytes by
* the longest match routines. Update the high water mark for the next
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
*/
if (s->high_water < s->window_size) {
ulg curr = s->strstart + (ulg)(s->lookahead);
ulg init;
if (s->high_water < curr) {
/* Previous high water mark below current data -- zero WIN_INIT
* bytes or up to end of window, whichever is less.
*/
init = s->window_size - curr;
if (init > WIN_INIT)
init = WIN_INIT;
zmemzero(s->window + curr, (unsigned)init);
s->high_water = curr + init;
}
else if (s->high_water < (ulg)curr + WIN_INIT) {
/* High water mark at or above current data, but below current data
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
* to end of window, whichever is less.
*/
init = (ulg)curr + WIN_INIT - s->high_water;
if (init > s->window_size - s->high_water)
init = s->window_size - s->high_water;
zmemzero(s->window + s->high_water, (unsigned)init);
s->high_water += init;
}
}
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"not enough room for search");
}
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateInit_(strm, level, version, stream_size) int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version,
z_streamp strm; int stream_size) {
int level;
const char *version;
int stream_size;
{
return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, version, stream_size); Z_DEFAULT_STRATEGY, version, stream_size);
/* To do: ignore strm->next_in if we use it as window */ /* To do: ignore strm->next_in if we use it as window */
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
version, stream_size) int windowBits, int memLevel, int strategy,
z_streamp strm; const char *version, int stream_size) {
int level;
int method;
int windowBits;
int memLevel;
int strategy;
const char *version;
int stream_size;
{
deflate_state *s; deflate_state *s;
int wrap = 1; int wrap = 1;
static const char my_version[] = ZLIB_VERSION; static const char my_version[] = ZLIB_VERSION;
...@@ -290,6 +413,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, ...@@ -290,6 +413,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
if (windowBits < 0) { /* suppress zlib wrapper */ if (windowBits < 0) { /* suppress zlib wrapper */
wrap = 0; wrap = 0;
if (windowBits < -15)
return Z_STREAM_ERROR;
windowBits = -windowBits; windowBits = -windowBits;
} }
#ifdef GZIP #ifdef GZIP
...@@ -319,7 +444,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, ...@@ -319,7 +444,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
s->hash_bits = (uInt)memLevel + 7; s->hash_bits = (uInt)memLevel + 7;
s->hash_size = 1 << s->hash_bits; s->hash_size = 1 << s->hash_bits;
s->hash_mask = s->hash_size - 1; s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
...@@ -345,11 +470,11 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, ...@@ -345,11 +470,11 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
* sym_buf value to read moves forward three bytes. From that symbol, up to * sym_buf value to read moves forward three bytes. From that symbol, up to
* 31 bits are written to pending_buf. The closest the written pending_buf * 31 bits are written to pending_buf. The closest the written pending_buf
* bits gets to the next sym_buf symbol to read is just before the last * bits gets to the next sym_buf symbol to read is just before the last
* code is written. At that time, 31*(n-2) bits have been written, just * code is written. At that time, 31*(n - 2) bits have been written, just
* after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at
* 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1 * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1
* symbols are written.) The closest the writing gets to what is unread is * symbols are written.) The closest the writing gets to what is unread is
* then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and
* can range from 128 to 32768. * can range from 128 to 32768.
* *
* Therefore, at a minimum, there are 142 bits of space between what is * Therefore, at a minimum, there are 142 bits of space between what is
...@@ -395,9 +520,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, ...@@ -395,9 +520,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
/* ========================================================================= /* =========================================================================
* Check for a valid deflate stream state. Return 0 if ok, 1 if not. * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
*/ */
local int deflateStateCheck (strm) local int deflateStateCheck(z_streamp strm) {
z_streamp strm;
{
deflate_state *s; deflate_state *s;
if (strm == Z_NULL || if (strm == Z_NULL ||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
...@@ -418,11 +541,8 @@ local int deflateStateCheck (strm) ...@@ -418,11 +541,8 @@ local int deflateStateCheck (strm)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
z_streamp strm; uInt dictLength) {
const Bytef *dictionary;
uInt dictLength;
{
deflate_state *s; deflate_state *s;
uInt str, n; uInt str, n;
int wrap; int wrap;
...@@ -487,11 +607,8 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) ...@@ -487,11 +607,8 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary,
z_streamp strm; uInt *dictLength) {
Bytef *dictionary;
uInt *dictLength;
{
deflate_state *s; deflate_state *s;
uInt len; uInt len;
...@@ -509,9 +626,7 @@ int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) ...@@ -509,9 +626,7 @@ int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateResetKeep (strm) int ZEXPORT deflateResetKeep(z_streamp strm) {
z_streamp strm;
{
deflate_state *s; deflate_state *s;
if (deflateStateCheck(strm)) { if (deflateStateCheck(strm)) {
...@@ -546,10 +661,32 @@ int ZEXPORT deflateResetKeep (strm) ...@@ -546,10 +661,32 @@ int ZEXPORT deflateResetKeep (strm)
return Z_OK; return Z_OK;
} }
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
local void lm_init(deflate_state *s) {
s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
}
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateReset (strm) int ZEXPORT deflateReset(z_streamp strm) {
z_streamp strm;
{
int ret; int ret;
ret = deflateResetKeep(strm); ret = deflateResetKeep(strm);
...@@ -559,10 +696,7 @@ int ZEXPORT deflateReset (strm) ...@@ -559,10 +696,7 @@ int ZEXPORT deflateReset (strm)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateSetHeader (strm, head) int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) {
z_streamp strm;
gz_headerp head;
{
if (deflateStateCheck(strm) || strm->state->wrap != 2) if (deflateStateCheck(strm) || strm->state->wrap != 2)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
strm->state->gzhead = head; strm->state->gzhead = head;
...@@ -570,11 +704,7 @@ int ZEXPORT deflateSetHeader (strm, head) ...@@ -570,11 +704,7 @@ int ZEXPORT deflateSetHeader (strm, head)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflatePending (strm, pending, bits) int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
unsigned *pending;
int *bits;
z_streamp strm;
{
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
if (pending != Z_NULL) if (pending != Z_NULL)
*pending = strm->state->pending; *pending = strm->state->pending;
...@@ -584,11 +714,7 @@ int ZEXPORT deflatePending (strm, pending, bits) ...@@ -584,11 +714,7 @@ int ZEXPORT deflatePending (strm, pending, bits)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflatePrime (strm, bits, value) int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
z_streamp strm;
int bits;
int value;
{
deflate_state *s; deflate_state *s;
int put; int put;
...@@ -611,11 +737,7 @@ int ZEXPORT deflatePrime (strm, bits, value) ...@@ -611,11 +737,7 @@ int ZEXPORT deflatePrime (strm, bits, value)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateParams(strm, level, strategy) int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) {
z_streamp strm;
int level;
int strategy;
{
deflate_state *s; deflate_state *s;
compress_func func; compress_func func;
...@@ -660,13 +782,8 @@ int ZEXPORT deflateParams(strm, level, strategy) ...@@ -660,13 +782,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy,
z_streamp strm; int nice_length, int max_chain) {
int good_length;
int max_lazy;
int nice_length;
int max_chain;
{
deflate_state *s; deflate_state *s;
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -679,36 +796,47 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) ...@@ -679,36 +796,47 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
} }
/* ========================================================================= /* =========================================================================
* For the default windowBits of 15 and memLevel of 8, this function returns * For the default windowBits of 15 and memLevel of 8, this function returns a
* a close to exact, as well as small, upper bound on the compressed size. * close to exact, as well as small, upper bound on the compressed size. This
* They are coded as constants here for a reason--if the #define's are * is an expansion of ~0.03%, plus a small constant.
* changed, then this function needs to be changed as well. The return
* value for 15 and 8 only works for those exact settings.
* *
* For any setting other than those defaults for windowBits and memLevel, * For any setting other than those defaults for windowBits and memLevel, one
* the value returned is a conservative worst case for the maximum expansion * of two worst case bounds is returned. This is at most an expansion of ~4% or
* resulting from using fixed blocks instead of stored blocks, which deflate * ~13%, plus a small constant.
* can emit on compressed data for some combinations of the parameters.
* *
* This function could be more sophisticated to provide closer upper bounds for * Both the 0.03% and 4% derive from the overhead of stored blocks. The first
* every combination of windowBits and memLevel. But even the conservative * one is for stored blocks of 16383 bytes (memLevel == 8), whereas the second
* upper bound of about 14% expansion does not seem onerous for output buffer * is for stored blocks of 127 bytes (the worst case memLevel == 1). The
* allocation. * expansion results from five bytes of header for each stored block.
*
* The larger expansion of 13% results from a window size less than or equal to
* the symbols buffer size (windowBits <= memLevel + 7). In that case some of
* the data being compressed may have slid out of the sliding window, impeding
* a stored block from being emitted. Then the only choice is a fixed or
* dynamic block, where a fixed block limits the maximum expansion to 9 bits
* per 8-bit byte, plus 10 bits for every block. The smallest block size for
* which this can occur is 255 (memLevel == 2).
*
* Shifts are used to approximate divisions, for speed.
*/ */
uLong ZEXPORT deflateBound(strm, sourceLen) uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
z_streamp strm;
uLong sourceLen;
{
deflate_state *s; deflate_state *s;
uLong complen, wraplen; uLong fixedlen, storelen, wraplen;
/* upper bound for fixed blocks with 9-bit literals and length 255
(memLevel == 2, which is the lowest that may not use stored blocks) --
~13% overhead plus a small constant */
fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) +
(sourceLen >> 9) + 4;
/* conservative upper bound for compressed data */ /* upper bound for stored blocks with length 127 (memLevel == 1) --
complen = sourceLen + ~4% overhead plus a small constant */
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) +
(sourceLen >> 11) + 7;
/* if can't get parameters, return conservative bound plus zlib wrapper */ /* if can't get parameters, return larger bound plus a zlib wrapper */
if (deflateStateCheck(strm)) if (deflateStateCheck(strm))
return complen + 6; return (fixedlen > storelen ? fixedlen : storelen) + 6;
/* compute wrapper length */ /* compute wrapper length */
s = strm->state; s = strm->state;
...@@ -745,11 +873,13 @@ uLong ZEXPORT deflateBound(strm, sourceLen) ...@@ -745,11 +873,13 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
wraplen = 6; wraplen = 6;
} }
/* if not default parameters, return conservative bound */ /* if not default parameters, return one of the conservative bounds */
if (s->w_bits != 15 || s->hash_bits != 8 + 7) if (s->w_bits != 15 || s->hash_bits != 8 + 7)
return complen + wraplen; return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) +
wraplen;
/* default settings: return tight bound for that case */ /* default settings: return tight bound for that case -- ~0.03% overhead
plus a small constant */
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13 - 6 + wraplen; (sourceLen >> 25) + 13 - 6 + wraplen;
} }
...@@ -759,10 +889,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen) ...@@ -759,10 +889,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
* IN assertion: the stream state is correct and there is enough room in * IN assertion: the stream state is correct and there is enough room in
* pending_buf. * pending_buf.
*/ */
local void putShortMSB (s, b) local void putShortMSB(deflate_state *s, uInt b) {
deflate_state *s;
uInt b;
{
put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b >> 8));
put_byte(s, (Byte)(b & 0xff)); put_byte(s, (Byte)(b & 0xff));
} }
...@@ -773,9 +900,7 @@ local void putShortMSB (s, b) ...@@ -773,9 +900,7 @@ local void putShortMSB (s, b)
* applications may wish to modify it to avoid allocating a large * applications may wish to modify it to avoid allocating a large
* strm->next_out buffer and copying into it. (See also read_buf()). * strm->next_out buffer and copying into it. (See also read_buf()).
*/ */
local void flush_pending(strm) local void flush_pending(z_streamp strm) {
z_streamp strm;
{
unsigned len; unsigned len;
deflate_state *s = strm->state; deflate_state *s = strm->state;
...@@ -806,10 +931,7 @@ local void flush_pending(strm) ...@@ -806,10 +931,7 @@ local void flush_pending(strm)
} while (0) } while (0)
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflate (strm, flush) int ZEXPORT deflate(z_streamp strm, int flush) {
z_streamp strm;
int flush;
{
int old_flush; /* value of flush param for previous deflate call */ int old_flush; /* value of flush param for previous deflate call */
deflate_state *s; deflate_state *s;
...@@ -861,7 +983,7 @@ int ZEXPORT deflate (strm, flush) ...@@ -861,7 +983,7 @@ int ZEXPORT deflate (strm, flush)
s->status = BUSY_STATE; s->status = BUSY_STATE;
if (s->status == INIT_STATE) { if (s->status == INIT_STATE) {
/* zlib header */ /* zlib header */
uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8;
uInt level_flags; uInt level_flags;
if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
...@@ -1121,9 +1243,7 @@ int ZEXPORT deflate (strm, flush) ...@@ -1121,9 +1243,7 @@ int ZEXPORT deflate (strm, flush)
} }
/* ========================================================================= */ /* ========================================================================= */
int ZEXPORT deflateEnd (strm) int ZEXPORT deflateEnd(z_streamp strm) {
z_streamp strm;
{
int status; int status;
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -1147,11 +1267,10 @@ int ZEXPORT deflateEnd (strm) ...@@ -1147,11 +1267,10 @@ int ZEXPORT deflateEnd (strm)
* To simplify the source, this is not supported for 16-bit MSDOS (which * To simplify the source, this is not supported for 16-bit MSDOS (which
* doesn't have enough memory anyway to duplicate compression states). * doesn't have enough memory anyway to duplicate compression states).
*/ */
int ZEXPORT deflateCopy (dest, source) int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
z_streamp dest;
z_streamp source;
{
#ifdef MAXSEG_64K #ifdef MAXSEG_64K
(void)dest;
(void)source;
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
#else #else
deflate_state *ds; deflate_state *ds;
...@@ -1199,71 +1318,6 @@ int ZEXPORT deflateCopy (dest, source) ...@@ -1199,71 +1318,6 @@ int ZEXPORT deflateCopy (dest, source)
#endif /* MAXSEG_64K */ #endif /* MAXSEG_64K */
} }
/* ===========================================================================
* Read a new buffer from the current input stream, update the adler32
* and total number of bytes read. All deflate() input goes through
* this function so some applications may wish to modify it to avoid
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
local unsigned read_buf(strm, buf, size)
z_streamp strm;
Bytef *buf;
unsigned size;
{
unsigned len = strm->avail_in;
if (len > size) len = size;
if (len == 0) return 0;
strm->avail_in -= len;
zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
strm->adler = crc32(strm->adler, buf, len);
}
#endif
strm->next_in += len;
strm->total_in += len;
return len;
}
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
local void lm_init (s)
deflate_state *s;
{
s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
#ifndef FASTEST
#ifdef ASMV
match_init(); /* initialize the asm code */
#endif
#endif
}
#ifndef FASTEST #ifndef FASTEST
/* =========================================================================== /* ===========================================================================
* Set match_start to the longest match starting at the given string and * Set match_start to the longest match starting at the given string and
...@@ -1274,14 +1328,7 @@ local void lm_init (s) ...@@ -1274,14 +1328,7 @@ local void lm_init (s)
* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
* OUT assertion: the match length is not greater than s->lookahead. * OUT assertion: the match length is not greater than s->lookahead.
*/ */
#ifndef ASMV local uInt longest_match(deflate_state *s, IPos cur_match) {
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
* match.S. The code will be functionally equivalent.
*/
local uInt longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
{
unsigned chain_length = s->max_chain_length;/* max hash chain length */ unsigned chain_length = s->max_chain_length;/* max hash chain length */
register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */ register Bytef *match; /* matched string */
...@@ -1302,10 +1349,10 @@ local uInt longest_match(s, cur_match) ...@@ -1302,10 +1349,10 @@ local uInt longest_match(s, cur_match)
*/ */
register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
register ush scan_start = *(ushf*)scan; register ush scan_start = *(ushf*)scan;
register ush scan_end = *(ushf*)(scan+best_len-1); register ush scan_end = *(ushf*)(scan + best_len - 1);
#else #else
register Bytef *strend = s->window + s->strstart + MAX_MATCH; register Bytef *strend = s->window + s->strstart + MAX_MATCH;
register Byte scan_end1 = scan[best_len-1]; register Byte scan_end1 = scan[best_len - 1];
register Byte scan_end = scan[best_len]; register Byte scan_end = scan[best_len];
#endif #endif
...@@ -1323,7 +1370,8 @@ local uInt longest_match(s, cur_match) ...@@ -1323,7 +1370,8 @@ local uInt longest_match(s, cur_match)
*/ */
if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"need lookahead");
do { do {
Assert(cur_match < s->strstart, "no future"); Assert(cur_match < s->strstart, "no future");
...@@ -1341,43 +1389,44 @@ local uInt longest_match(s, cur_match) ...@@ -1341,43 +1389,44 @@ local uInt longest_match(s, cur_match)
/* This code assumes sizeof(unsigned short) == 2. Do not use /* This code assumes sizeof(unsigned short) == 2. Do not use
* UNALIGNED_OK if your compiler uses a different size. * UNALIGNED_OK if your compiler uses a different size.
*/ */
if (*(ushf*)(match+best_len-1) != scan_end || if (*(ushf*)(match + best_len - 1) != scan_end ||
*(ushf*)match != scan_start) continue; *(ushf*)match != scan_start) continue;
/* It is not necessary to compare scan[2] and match[2] since they are /* It is not necessary to compare scan[2] and match[2] since they are
* always equal when the other bytes match, given that the hash keys * always equal when the other bytes match, given that the hash keys
* are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
* strstart+3, +5, ... up to strstart+257. We check for insufficient * strstart + 3, + 5, up to strstart + 257. We check for insufficient
* lookahead only every 4th comparison; the 128th check will be made * lookahead only every 4th comparison; the 128th check will be made
* at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is * at strstart + 257. If MAX_MATCH-2 is not a multiple of 8, it is
* necessary to put more guard bytes at the end of the window, or * necessary to put more guard bytes at the end of the window, or
* to check more often for insufficient lookahead. * to check more often for insufficient lookahead.
*/ */
Assert(scan[2] == match[2], "scan[2]?"); Assert(scan[2] == match[2], "scan[2]?");
scan++, match++; scan++, match++;
do { do {
} while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && } while (*(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
*(ushf*)(scan+=2) == *(ushf*)(match+=2) && *(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
*(ushf*)(scan+=2) == *(ushf*)(match+=2) && *(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
*(ushf*)(scan+=2) == *(ushf*)(match+=2) && *(ushf*)(scan += 2) == *(ushf*)(match += 2) &&
scan < strend); scan < strend);
/* The funny "do {}" generates better code on most compilers */ /* The funny "do {}" generates better code on most compilers */
/* Here, scan <= window+strstart+257 */ /* Here, scan <= window + strstart + 257 */
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); Assert(scan <= s->window + (unsigned)(s->window_size - 1),
"wild scan");
if (*scan == *match) scan++; if (*scan == *match) scan++;
len = (MAX_MATCH - 1) - (int)(strend-scan); len = (MAX_MATCH - 1) - (int)(strend - scan);
scan = strend - (MAX_MATCH-1); scan = strend - (MAX_MATCH-1);
#else /* UNALIGNED_OK */ #else /* UNALIGNED_OK */
if (match[best_len] != scan_end || if (match[best_len] != scan_end ||
match[best_len-1] != scan_end1 || match[best_len - 1] != scan_end1 ||
*match != *scan || *match != *scan ||
*++match != scan[1]) continue; *++match != scan[1]) continue;
/* The check at best_len-1 can be removed because it will be made /* The check at best_len - 1 can be removed because it will be made
* again later. (This heuristic is not always a win.) * again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they * It is not necessary to compare scan[2] and match[2] since they
* are always equal when the other bytes match, given that * are always equal when the other bytes match, given that
...@@ -1387,7 +1436,7 @@ local uInt longest_match(s, cur_match) ...@@ -1387,7 +1436,7 @@ local uInt longest_match(s, cur_match)
Assert(*scan == *match, "match[2]?"); Assert(*scan == *match, "match[2]?");
/* We check for insufficient lookahead only every 8th comparison; /* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258. * the 256th check will be made at strstart + 258.
*/ */
do { do {
} while (*++scan == *++match && *++scan == *++match && } while (*++scan == *++match && *++scan == *++match &&
...@@ -1396,7 +1445,8 @@ local uInt longest_match(s, cur_match) ...@@ -1396,7 +1445,8 @@ local uInt longest_match(s, cur_match)
*++scan == *++match && *++scan == *++match && *++scan == *++match && *++scan == *++match &&
scan < strend); scan < strend);
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); Assert(scan <= s->window + (unsigned)(s->window_size - 1),
"wild scan");
len = MAX_MATCH - (int)(strend - scan); len = MAX_MATCH - (int)(strend - scan);
scan = strend - MAX_MATCH; scan = strend - MAX_MATCH;
...@@ -1408,9 +1458,9 @@ local uInt longest_match(s, cur_match) ...@@ -1408,9 +1458,9 @@ local uInt longest_match(s, cur_match)
best_len = len; best_len = len;
if (len >= nice_match) break; if (len >= nice_match) break;
#ifdef UNALIGNED_OK #ifdef UNALIGNED_OK
scan_end = *(ushf*)(scan+best_len-1); scan_end = *(ushf*)(scan + best_len - 1);
#else #else
scan_end1 = scan[best_len-1]; scan_end1 = scan[best_len - 1];
scan_end = scan[best_len]; scan_end = scan[best_len];
#endif #endif
} }
...@@ -1420,17 +1470,13 @@ local uInt longest_match(s, cur_match) ...@@ -1420,17 +1470,13 @@ local uInt longest_match(s, cur_match)
if ((uInt)best_len <= s->lookahead) return (uInt)best_len; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
return s->lookahead; return s->lookahead;
} }
#endif /* ASMV */
#else /* FASTEST */ #else /* FASTEST */
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Optimized version for FASTEST only * Optimized version for FASTEST only
*/ */
local uInt longest_match(s, cur_match) local uInt longest_match(deflate_state *s, IPos cur_match) {
deflate_state *s;
IPos cur_match; /* current match */
{
register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */ register Bytef *match; /* matched string */
register int len; /* length of current match */ register int len; /* length of current match */
...@@ -1441,7 +1487,8 @@ local uInt longest_match(s, cur_match) ...@@ -1441,7 +1487,8 @@ local uInt longest_match(s, cur_match)
*/ */
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"need lookahead");
Assert(cur_match < s->strstart, "no future"); Assert(cur_match < s->strstart, "no future");
...@@ -1451,7 +1498,7 @@ local uInt longest_match(s, cur_match) ...@@ -1451,7 +1498,7 @@ local uInt longest_match(s, cur_match)
*/ */
if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
/* The check at best_len-1 can be removed because it will be made /* The check at best_len - 1 can be removed because it will be made
* again later. (This heuristic is not always a win.) * again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they * It is not necessary to compare scan[2] and match[2] since they
* are always equal when the other bytes match, given that * are always equal when the other bytes match, given that
...@@ -1461,7 +1508,7 @@ local uInt longest_match(s, cur_match) ...@@ -1461,7 +1508,7 @@ local uInt longest_match(s, cur_match)
Assert(*scan == *match, "match[2]?"); Assert(*scan == *match, "match[2]?");
/* We check for insufficient lookahead only every 8th comparison; /* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258. * the 256th check will be made at strstart + 258.
*/ */
do { do {
} while (*++scan == *++match && *++scan == *++match && } while (*++scan == *++match && *++scan == *++match &&
...@@ -1470,7 +1517,7 @@ local uInt longest_match(s, cur_match) ...@@ -1470,7 +1517,7 @@ local uInt longest_match(s, cur_match)
*++scan == *++match && *++scan == *++match && *++scan == *++match && *++scan == *++match &&
scan < strend); scan < strend);
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan");
len = MAX_MATCH - (int)(strend - scan); len = MAX_MATCH - (int)(strend - scan);
...@@ -1490,11 +1537,7 @@ local uInt longest_match(s, cur_match) ...@@ -1490,11 +1537,7 @@ local uInt longest_match(s, cur_match)
/* =========================================================================== /* ===========================================================================
* Check that the match at match_start is indeed a match. * Check that the match at match_start is indeed a match.
*/ */
local void check_match(s, start, match, length) local void check_match(deflate_state *s, IPos start, IPos match, int length) {
deflate_state *s;
IPos start, match;
int length;
{
/* check that the match is indeed a match */ /* check that the match is indeed a match */
if (zmemcmp(s->window + match, if (zmemcmp(s->window + match,
s->window + start, length) != EQUAL) { s->window + start, length) != EQUAL) {
...@@ -1506,7 +1549,7 @@ local void check_match(s, start, match, length) ...@@ -1506,7 +1549,7 @@ local void check_match(s, start, match, length)
z_error("invalid match"); z_error("invalid match");
} }
if (z_verbose > 1) { if (z_verbose > 1) {
fprintf(stderr,"\\[%d,%d]", start-match, length); fprintf(stderr,"\\[%d,%d]", start - match, length);
do { putc(s->window[start++], stderr); } while (--length != 0); do { putc(s->window[start++], stderr); } while (--length != 0);
} }
} }
...@@ -1515,137 +1558,6 @@ local void check_match(s, start, match, length) ...@@ -1515,137 +1558,6 @@ local void check_match(s, start, match, length)
#endif /* ZLIB_DEBUG */ #endif /* ZLIB_DEBUG */
/* =========================================================================== /* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead.
*
* IN assertion: lookahead < MIN_LOOKAHEAD
* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
* At least one byte has been read, or avail_in == 0; reads are
* performed for at least two bytes (required for the zip translate_eol
* option -- not supported here).
*/
local void fill_window(s)
deflate_state *s;
{
unsigned n;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* Deal with !@#$% 64K limit: */
if (sizeof(int) <= 2) {
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
more = wsize;
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if
* strstart == 0 && lookahead == 1 (input done a byte at time)
*/
more--;
}
}
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (s->strstart >= wsize+MAX_DIST(s)) {
zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more);
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
if (s->insert > s->strstart)
s->insert = s->strstart;
slide_hash(s);
more += wsize;
}
if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
* => more >= window_size - 2*WSIZE + 2
* In the BIG_MEM or MMAP case (not yet supported),
* window_size == input_size + MIN_LOOKAHEAD &&
* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
* Otherwise, window_size == 2*WSIZE so more >= 2.
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
if (s->lookahead + s->insert >= MIN_MATCH) {
uInt str = s->strstart - s->insert;
s->ins_h = s->window[str];
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
while (s->insert) {
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
s->head[s->ins_h] = (Pos)str;
str++;
s->insert--;
if (s->lookahead + s->insert < MIN_MATCH)
break;
}
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
*/
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
/* If the WIN_INIT bytes after the end of the current data have never been
* written, then zero those bytes in order to avoid memory check reports of
* the use of uninitialized (or uninitialised as Julian writes) bytes by
* the longest match routines. Update the high water mark for the next
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
*/
if (s->high_water < s->window_size) {
ulg curr = s->strstart + (ulg)(s->lookahead);
ulg init;
if (s->high_water < curr) {
/* Previous high water mark below current data -- zero WIN_INIT
* bytes or up to end of window, whichever is less.
*/
init = s->window_size - curr;
if (init > WIN_INIT)
init = WIN_INIT;
zmemzero(s->window + curr, (unsigned)init);
s->high_water = curr + init;
}
else if (s->high_water < (ulg)curr + WIN_INIT) {
/* High water mark at or above current data, but below current data
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
* to end of window, whichever is less.
*/
init = (ulg)curr + WIN_INIT - s->high_water;
if (init > s->window_size - s->high_water)
init = s->window_size - s->high_water;
zmemzero(s->window + s->high_water, (unsigned)init);
s->high_water += init;
}
}
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"not enough room for search");
}
/* ===========================================================================
* Flush the current block, with given end-of-file flag. * Flush the current block, with given end-of-file flag.
* IN assertion: strstart is set to the end of the current match. * IN assertion: strstart is set to the end of the current match.
*/ */
...@@ -1685,12 +1597,9 @@ local void fill_window(s) ...@@ -1685,12 +1597,9 @@ local void fill_window(s)
* *
* deflate_stored() is written to minimize the number of times an input byte is * deflate_stored() is written to minimize the number of times an input byte is
* copied. It is most efficient with large input and output buffers, which * copied. It is most efficient with large input and output buffers, which
* maximizes the opportunites to have a single copy from next_in to next_out. * maximizes the opportunities to have a single copy from next_in to next_out.
*/ */
local block_state deflate_stored(s, flush) local block_state deflate_stored(deflate_state *s, int flush) {
deflate_state *s;
int flush;
{
/* Smallest worthy block size when not flushing or finishing. By default /* Smallest worthy block size when not flushing or finishing. By default
* this is 32K. This can be as small as 507 bytes for memLevel == 1. For * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
* large input and output buffers, the stored block size will be larger. * large input and output buffers, the stored block size will be larger.
...@@ -1874,10 +1783,7 @@ local block_state deflate_stored(s, flush) ...@@ -1874,10 +1783,7 @@ local block_state deflate_stored(s, flush)
* new strings in the dictionary only for unmatched strings or for short * new strings in the dictionary only for unmatched strings or for short
* matches. It is used only for the fast compression options. * matches. It is used only for the fast compression options.
*/ */
local block_state deflate_fast(s, flush) local block_state deflate_fast(deflate_state *s, int flush) {
deflate_state *s;
int flush;
{
IPos hash_head; /* head of the hash chain */ IPos hash_head; /* head of the hash chain */
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
...@@ -1895,7 +1801,7 @@ local block_state deflate_fast(s, flush) ...@@ -1895,7 +1801,7 @@ local block_state deflate_fast(s, flush)
if (s->lookahead == 0) break; /* flush the current block */ if (s->lookahead == 0) break; /* flush the current block */
} }
/* Insert the string window[strstart .. strstart+2] in the /* Insert the string window[strstart .. strstart + 2] in the
* dictionary, and set hash_head to the head of the hash chain: * dictionary, and set hash_head to the head of the hash chain:
*/ */
hash_head = NIL; hash_head = NIL;
...@@ -1943,7 +1849,7 @@ local block_state deflate_fast(s, flush) ...@@ -1943,7 +1849,7 @@ local block_state deflate_fast(s, flush)
s->strstart += s->match_length; s->strstart += s->match_length;
s->match_length = 0; s->match_length = 0;
s->ins_h = s->window[s->strstart]; s->ins_h = s->window[s->strstart];
UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]);
#if MIN_MATCH != 3 #if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times Call UPDATE_HASH() MIN_MATCH-3 more times
#endif #endif
...@@ -1954,7 +1860,7 @@ local block_state deflate_fast(s, flush) ...@@ -1954,7 +1860,7 @@ local block_state deflate_fast(s, flush)
} else { } else {
/* No match, output a literal byte */ /* No match, output a literal byte */
Tracevv((stderr,"%c", s->window[s->strstart])); Tracevv((stderr,"%c", s->window[s->strstart]));
_tr_tally_lit (s, s->window[s->strstart], bflush); _tr_tally_lit(s, s->window[s->strstart], bflush);
s->lookahead--; s->lookahead--;
s->strstart++; s->strstart++;
} }
...@@ -1976,10 +1882,7 @@ local block_state deflate_fast(s, flush) ...@@ -1976,10 +1882,7 @@ local block_state deflate_fast(s, flush)
* evaluation for matches: a match is finally adopted only if there is * evaluation for matches: a match is finally adopted only if there is
* no better match at the next window position. * no better match at the next window position.
*/ */
local block_state deflate_slow(s, flush) local block_state deflate_slow(deflate_state *s, int flush) {
deflate_state *s;
int flush;
{
IPos hash_head; /* head of hash chain */ IPos hash_head; /* head of hash chain */
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
...@@ -1998,7 +1901,7 @@ local block_state deflate_slow(s, flush) ...@@ -1998,7 +1901,7 @@ local block_state deflate_slow(s, flush)
if (s->lookahead == 0) break; /* flush the current block */ if (s->lookahead == 0) break; /* flush the current block */
} }
/* Insert the string window[strstart .. strstart+2] in the /* Insert the string window[strstart .. strstart + 2] in the
* dictionary, and set hash_head to the head of the hash chain: * dictionary, and set hash_head to the head of the hash chain:
*/ */
hash_head = NIL; hash_head = NIL;
...@@ -2040,17 +1943,17 @@ local block_state deflate_slow(s, flush) ...@@ -2040,17 +1943,17 @@ local block_state deflate_slow(s, flush)
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
/* Do not insert strings in hash table beyond this. */ /* Do not insert strings in hash table beyond this. */
check_match(s, s->strstart-1, s->prev_match, s->prev_length); check_match(s, s->strstart - 1, s->prev_match, s->prev_length);
_tr_tally_dist(s, s->strstart -1 - s->prev_match, _tr_tally_dist(s, s->strstart - 1 - s->prev_match,
s->prev_length - MIN_MATCH, bflush); s->prev_length - MIN_MATCH, bflush);
/* Insert in hash table all strings up to the end of the match. /* Insert in hash table all strings up to the end of the match.
* strstart-1 and strstart are already inserted. If there is not * strstart - 1 and strstart are already inserted. If there is not
* enough lookahead, the last two strings are not inserted in * enough lookahead, the last two strings are not inserted in
* the hash table. * the hash table.
*/ */
s->lookahead -= s->prev_length-1; s->lookahead -= s->prev_length - 1;
s->prev_length -= 2; s->prev_length -= 2;
do { do {
if (++s->strstart <= max_insert) { if (++s->strstart <= max_insert) {
...@@ -2068,8 +1971,8 @@ local block_state deflate_slow(s, flush) ...@@ -2068,8 +1971,8 @@ local block_state deflate_slow(s, flush)
* single literal. If there was a match but the current match * single literal. If there was a match but the current match
* is longer, truncate the previous match to a single literal. * is longer, truncate the previous match to a single literal.
*/ */
Tracevv((stderr,"%c", s->window[s->strstart-1])); Tracevv((stderr,"%c", s->window[s->strstart - 1]));
_tr_tally_lit(s, s->window[s->strstart-1], bflush); _tr_tally_lit(s, s->window[s->strstart - 1], bflush);
if (bflush) { if (bflush) {
FLUSH_BLOCK_ONLY(s, 0); FLUSH_BLOCK_ONLY(s, 0);
} }
...@@ -2087,8 +1990,8 @@ local block_state deflate_slow(s, flush) ...@@ -2087,8 +1990,8 @@ local block_state deflate_slow(s, flush)
} }
Assert (flush != Z_NO_FLUSH, "no flush?"); Assert (flush != Z_NO_FLUSH, "no flush?");
if (s->match_available) { if (s->match_available) {
Tracevv((stderr,"%c", s->window[s->strstart-1])); Tracevv((stderr,"%c", s->window[s->strstart - 1]));
_tr_tally_lit(s, s->window[s->strstart-1], bflush); _tr_tally_lit(s, s->window[s->strstart - 1], bflush);
s->match_available = 0; s->match_available = 0;
} }
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
...@@ -2107,10 +2010,7 @@ local block_state deflate_slow(s, flush) ...@@ -2107,10 +2010,7 @@ local block_state deflate_slow(s, flush)
* one. Do not maintain a hash table. (It will be regenerated if this run of * one. Do not maintain a hash table. (It will be regenerated if this run of
* deflate switches away from Z_RLE.) * deflate switches away from Z_RLE.)
*/ */
local block_state deflate_rle(s, flush) local block_state deflate_rle(deflate_state *s, int flush) {
deflate_state *s;
int flush;
{
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
uInt prev; /* byte at distance one to match */ uInt prev; /* byte at distance one to match */
Bytef *scan, *strend; /* scan goes up to strend for length of run */ Bytef *scan, *strend; /* scan goes up to strend for length of run */
...@@ -2145,7 +2045,8 @@ local block_state deflate_rle(s, flush) ...@@ -2145,7 +2045,8 @@ local block_state deflate_rle(s, flush)
if (s->match_length > s->lookahead) if (s->match_length > s->lookahead)
s->match_length = s->lookahead; s->match_length = s->lookahead;
} }
Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); Assert(scan <= s->window + (uInt)(s->window_size - 1),
"wild scan");
} }
/* Emit match if have run of MIN_MATCH or longer, else emit literal */ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
...@@ -2160,7 +2061,7 @@ local block_state deflate_rle(s, flush) ...@@ -2160,7 +2061,7 @@ local block_state deflate_rle(s, flush)
} else { } else {
/* No match, output a literal byte */ /* No match, output a literal byte */
Tracevv((stderr,"%c", s->window[s->strstart])); Tracevv((stderr,"%c", s->window[s->strstart]));
_tr_tally_lit (s, s->window[s->strstart], bflush); _tr_tally_lit(s, s->window[s->strstart], bflush);
s->lookahead--; s->lookahead--;
s->strstart++; s->strstart++;
} }
...@@ -2180,10 +2081,7 @@ local block_state deflate_rle(s, flush) ...@@ -2180,10 +2081,7 @@ local block_state deflate_rle(s, flush)
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
* (It will be regenerated if this run of deflate switches away from Huffman.) * (It will be regenerated if this run of deflate switches away from Huffman.)
*/ */
local block_state deflate_huff(s, flush) local block_state deflate_huff(deflate_state *s, int flush) {
deflate_state *s;
int flush;
{
int bflush; /* set if current block must be flushed */ int bflush; /* set if current block must be flushed */
for (;;) { for (;;) {
...@@ -2200,7 +2098,7 @@ local block_state deflate_huff(s, flush) ...@@ -2200,7 +2098,7 @@ local block_state deflate_huff(s, flush)
/* Output a literal byte */ /* Output a literal byte */
s->match_length = 0; s->match_length = 0;
Tracevv((stderr,"%c", s->window[s->strstart])); Tracevv((stderr,"%c", s->window[s->strstart]));
_tr_tally_lit (s, s->window[s->strstart], bflush); _tr_tally_lit(s, s->window[s->strstart], bflush);
s->lookahead--; s->lookahead--;
s->strstart++; s->strstart++;
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
......
...@@ -291,14 +291,14 @@ typedef struct internal_state { ...@@ -291,14 +291,14 @@ typedef struct internal_state {
memory checker errors from longest match routines */ memory checker errors from longest match routines */
/* in trees.c */ /* in trees.c */
void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); void ZLIB_INTERNAL _tr_init(deflate_state *s);
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
ulg stored_len, int last)); ulg stored_len, int last);
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); void ZLIB_INTERNAL _tr_align(deflate_state *s);
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
ulg stored_len, int last)); ulg stored_len, int last);
#define d_code(dist) \ #define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
# 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
...@@ -119,8 +118,8 @@ ...@@ -119,8 +118,8 @@
/* gz* functions always use library allocation functions */ /* gz* functions always use library allocation functions */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
/* get errno and strerror definition */ /* get errno and strerror definition */
...@@ -138,10 +137,10 @@ ...@@ -138,10 +137,10 @@
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
#endif #endif
/* default memLevel */ /* default memLevel */
...@@ -203,9 +202,9 @@ typedef struct { ...@@ -203,9 +202,9 @@ typedef struct {
typedef gz_state FAR *gz_statep; typedef gz_state FAR *gz_statep;
/* shared functions */ /* shared functions */
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
#if defined UNDER_CE #if defined UNDER_CE
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
#endif #endif
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
...@@ -214,6 +213,6 @@ char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); ...@@ -214,6 +213,6 @@ char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
#ifdef INT_MAX #ifdef INT_MAX
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
#else #else
unsigned ZLIB_INTERNAL gz_intmax OF((void)); unsigned ZLIB_INTERNAL gz_intmax(void);
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif #endif
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
/* /*
strm provides memory allocation functions in zalloc and zfree, or strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions. Z_NULL to use the library memory allocation functions.
...@@ -25,13 +22,9 @@ local void fixedtables OF((struct inflate_state FAR *state)); ...@@ -25,13 +22,9 @@ local void fixedtables OF((struct inflate_state FAR *state));
windowBits is in the range 8..15, and window is a user-supplied windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes. window and output buffer that is 2**windowBits bytes.
*/ */
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
z_streamp strm; unsigned char FAR *window, const char *version,
int windowBits; int stream_size) {
unsigned char FAR *window;
const char *version;
int stream_size;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
...@@ -66,6 +59,7 @@ int stream_size; ...@@ -66,6 +59,7 @@ int stream_size;
state->window = window; state->window = window;
state->wnext = 0; state->wnext = 0;
state->whave = 0; state->whave = 0;
state->sane = 1;
return Z_OK; return Z_OK;
} }
...@@ -79,9 +73,7 @@ int stream_size; ...@@ -79,9 +73,7 @@ int stream_size;
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(state) local void fixedtables(struct inflate_state FAR *state) {
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
...@@ -247,13 +239,8 @@ struct inflate_state FAR *state; ...@@ -247,13 +239,8 @@ struct inflate_state FAR *state;
inflateBack() can also return Z_STREAM_ERROR if the input parameters inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized. are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/ */
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
z_streamp strm; out_func out, void FAR *out_desc) {
in_func in;
void FAR *in_desc;
out_func out;
void FAR *out_desc;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
...@@ -605,33 +592,33 @@ void FAR *out_desc; ...@@ -605,33 +592,33 @@ void FAR *out_desc;
break; break;
case DONE: case DONE:
/* inflate stream terminated properly -- write leftover output */ /* inflate stream terminated properly */
ret = Z_STREAM_END; ret = Z_STREAM_END;
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR;
}
goto inf_leave; goto inf_leave;
case BAD: case BAD:
ret = Z_DATA_ERROR; ret = Z_DATA_ERROR;
goto inf_leave; goto inf_leave;
default: /* can't happen, but makes compilers happy */ default:
/* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR; ret = Z_STREAM_ERROR;
goto inf_leave; goto inf_leave;
} }
/* Return unused input */ /* Write leftover output and return unused input */
inf_leave: inf_leave:
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left) &&
ret == Z_STREAM_END)
ret = Z_BUF_ERROR;
}
strm->next_in = next; strm->next_in = next;
strm->avail_in = have; strm->avail_in = have;
return ret; return ret;
} }
int ZEXPORT inflateBackEnd(strm) int ZEXPORT inflateBackEnd(z_streamp strm) {
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
ZFREE(strm, strm->state); ZFREE(strm, strm->state);
......
...@@ -47,10 +47,7 @@ ...@@ -47,10 +47,7 @@
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void ZLIB_INTERNAL inflate_fast(strm, start) void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *in; /* local strm->next_in */
z_const unsigned char FAR *last; /* have enough input while in < last */ z_const unsigned char FAR *last; /* have enough input while in < last */
......
...@@ -8,4 +8,4 @@ ...@@ -8,4 +8,4 @@
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);
...@@ -91,20 +91,7 @@ ...@@ -91,20 +91,7 @@
# endif # endif
#endif #endif
/* function prototypes */ local int inflateStateCheck(z_streamp strm) {
local int inflateStateCheck OF((z_streamp strm));
local void fixedtables OF((struct inflate_state FAR *state));
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
unsigned copy));
#ifdef BUILDFIXED
void makefixed OF((void));
#endif
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
unsigned len));
local int inflateStateCheck(strm)
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || if (strm == Z_NULL ||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
...@@ -116,9 +103,7 @@ z_streamp strm; ...@@ -116,9 +103,7 @@ z_streamp strm;
return 0; return 0;
} }
int ZEXPORT inflateResetKeep(strm) int ZEXPORT inflateResetKeep(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -142,9 +127,7 @@ z_streamp strm; ...@@ -142,9 +127,7 @@ z_streamp strm;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateReset(strm) int ZEXPORT inflateReset(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -155,10 +138,7 @@ z_streamp strm; ...@@ -155,10 +138,7 @@ z_streamp strm;
return inflateResetKeep(strm); return inflateResetKeep(strm);
} }
int ZEXPORT inflateReset2(strm, windowBits) int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
z_streamp strm;
int windowBits;
{
int wrap; int wrap;
struct inflate_state FAR *state; struct inflate_state FAR *state;
...@@ -168,6 +148,8 @@ int windowBits; ...@@ -168,6 +148,8 @@ int windowBits;
/* extract wrap request from windowBits parameter */ /* extract wrap request from windowBits parameter */
if (windowBits < 0) { if (windowBits < 0) {
if (windowBits < -15)
return Z_STREAM_ERROR;
wrap = 0; wrap = 0;
windowBits = -windowBits; windowBits = -windowBits;
} }
...@@ -193,12 +175,8 @@ int windowBits; ...@@ -193,12 +175,8 @@ int windowBits;
return inflateReset(strm); return inflateReset(strm);
} }
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
z_streamp strm; const char *version, int stream_size) {
int windowBits;
const char *version;
int stream_size;
{
int ret; int ret;
struct inflate_state FAR *state; struct inflate_state FAR *state;
...@@ -237,22 +215,17 @@ int stream_size; ...@@ -237,22 +215,17 @@ int stream_size;
return ret; return ret;
} }
int ZEXPORT inflateInit_(strm, version, stream_size) int ZEXPORT inflateInit_(z_streamp strm, const char *version,
z_streamp strm; int stream_size) {
const char *version;
int stream_size;
{
return inflateInit2_(strm, DEF_WBITS, version, stream_size); return inflateInit2_(strm, DEF_WBITS, version, stream_size);
} }
int ZEXPORT inflatePrime(strm, bits, value) int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
z_streamp strm;
int bits;
int value;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
if (bits == 0)
return Z_OK;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (bits < 0) { if (bits < 0) {
state->hold = 0; state->hold = 0;
...@@ -276,9 +249,7 @@ int value; ...@@ -276,9 +249,7 @@ int value;
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(state) local void fixedtables(struct inflate_state FAR *state) {
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
...@@ -340,7 +311,7 @@ struct inflate_state FAR *state; ...@@ -340,7 +311,7 @@ struct inflate_state FAR *state;
a.out > inffixed.h a.out > inffixed.h
*/ */
void makefixed() void makefixed(void)
{ {
unsigned low, size; unsigned low, size;
struct inflate_state state; struct inflate_state state;
...@@ -394,11 +365,7 @@ void makefixed() ...@@ -394,11 +365,7 @@ void makefixed()
output will fall in the output data, making match copies simpler and faster. output will fall in the output data, making match copies simpler and faster.
The advantage may be dependent on the size of the processor's data caches. The advantage may be dependent on the size of the processor's data caches.
*/ */
local int updatewindow(strm, end, copy) local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
z_streamp strm;
const Bytef *end;
unsigned copy;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned dist; unsigned dist;
...@@ -620,10 +587,7 @@ unsigned copy; ...@@ -620,10 +587,7 @@ unsigned copy;
will return Z_BUF_ERROR if it has not reached the end of the stream. will return Z_BUF_ERROR if it has not reached the end of the stream.
*/ */
int ZEXPORT inflate(strm, flush) int ZEXPORT inflate(z_streamp strm, int flush) {
z_streamp strm;
int flush;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
...@@ -764,8 +728,9 @@ int flush; ...@@ -764,8 +728,9 @@ int flush;
if (copy > have) copy = have; if (copy > have) copy = have;
if (copy) { if (copy) {
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->extra != Z_NULL) { state->head->extra != Z_NULL &&
len = state->head->extra_len - state->length; (len = state->head->extra_len - state->length) <
state->head->extra_max) {
zmemcpy(state->head->extra + len, next, zmemcpy(state->head->extra + len, next,
len + copy > state->head->extra_max ? len + copy > state->head->extra_max ?
state->head->extra_max - len : copy); state->head->extra_max - len : copy);
...@@ -1298,9 +1263,7 @@ int flush; ...@@ -1298,9 +1263,7 @@ int flush;
return ret; return ret;
} }
int ZEXPORT inflateEnd(strm) int ZEXPORT inflateEnd(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) if (inflateStateCheck(strm))
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
...@@ -1312,11 +1275,8 @@ z_streamp strm; ...@@ -1312,11 +1275,8 @@ z_streamp strm;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
z_streamp strm; uInt *dictLength) {
Bytef *dictionary;
uInt *dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
...@@ -1335,11 +1295,8 @@ uInt *dictLength; ...@@ -1335,11 +1295,8 @@ uInt *dictLength;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
z_streamp strm; uInt dictLength) {
const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned long dictid; unsigned long dictid;
int ret; int ret;
...@@ -1370,10 +1327,7 @@ uInt dictLength; ...@@ -1370,10 +1327,7 @@ uInt dictLength;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetHeader(strm, head) int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
z_streamp strm;
gz_headerp head;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
...@@ -1398,11 +1352,8 @@ gz_headerp head; ...@@ -1398,11 +1352,8 @@ gz_headerp head;
called again with more data and the *have state. *have is initialized to called again with more data and the *have state. *have is initialized to
zero for the first call. zero for the first call.
*/ */
local unsigned syncsearch(have, buf, len) local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
unsigned FAR *have; unsigned len) {
const unsigned char FAR *buf;
unsigned len;
{
unsigned got; unsigned got;
unsigned next; unsigned next;
...@@ -1421,9 +1372,7 @@ unsigned len; ...@@ -1421,9 +1372,7 @@ unsigned len;
return next; return next;
} }
int ZEXPORT inflateSync(strm) int ZEXPORT inflateSync(z_streamp strm) {
z_streamp strm;
{
unsigned len; /* number of bytes to look at or looked at */ unsigned len; /* number of bytes to look at or looked at */
int flags; /* temporary to save header status */ int flags; /* temporary to save header status */
unsigned long in, out; /* temporary to save total_in and total_out */ unsigned long in, out; /* temporary to save total_in and total_out */
...@@ -1479,9 +1428,7 @@ z_streamp strm; ...@@ -1479,9 +1428,7 @@ z_streamp strm;
block. When decompressing, PPP checks that at the end of input packet, block. When decompressing, PPP checks that at the end of input packet,
inflate is waiting for these length bytes. inflate is waiting for these length bytes.
*/ */
int ZEXPORT inflateSyncPoint(strm) int ZEXPORT inflateSyncPoint(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -1489,10 +1436,7 @@ z_streamp strm; ...@@ -1489,10 +1436,7 @@ z_streamp strm;
return state->mode == STORED && state->bits == 0; return state->mode == STORED && state->bits == 0;
} }
int ZEXPORT inflateCopy(dest, source) int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
z_streamp dest;
z_streamp source;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
struct inflate_state FAR *copy; struct inflate_state FAR *copy;
unsigned char FAR *window; unsigned char FAR *window;
...@@ -1536,10 +1480,7 @@ z_streamp source; ...@@ -1536,10 +1480,7 @@ z_streamp source;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateUndermine(strm, subvert) int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
z_streamp strm;
int subvert;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -1554,10 +1495,7 @@ int subvert; ...@@ -1554,10 +1495,7 @@ int subvert;
#endif #endif
} }
int ZEXPORT inflateValidate(strm, check) int ZEXPORT inflateValidate(z_streamp strm, int check) {
z_streamp strm;
int check;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
...@@ -1569,9 +1507,7 @@ int check; ...@@ -1569,9 +1507,7 @@ int check;
return Z_OK; return Z_OK;
} }
long ZEXPORT inflateMark(strm) long ZEXPORT inflateMark(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) if (inflateStateCheck(strm))
...@@ -1582,9 +1518,7 @@ z_streamp strm; ...@@ -1582,9 +1518,7 @@ z_streamp strm;
(state->mode == MATCH ? state->was - state->length : 0)); (state->mode == MATCH ? state->was - state->length : 0));
} }
unsigned long ZEXPORT inflateCodesUsed(strm) unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return (unsigned long)-1; if (inflateStateCheck(strm)) return (unsigned long)-1;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
......
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2022 Mark Adler * Copyright (C) 1995-2023 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
*/ */
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.12 Copyright 1995-2022 Mark Adler "; " inflate 1.3 Copyright 1995-2023 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
...@@ -29,14 +29,9 @@ const char inflate_copyright[] = ...@@ -29,14 +29,9 @@ const char inflate_copyright[] =
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
codetype type; unsigned codes, code FAR * FAR *table,
unsigned short FAR *lens; unsigned FAR *bits, unsigned short FAR *work) {
unsigned codes;
code FAR * FAR *table;
unsigned FAR *bits;
unsigned short FAR *work;
{
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
...@@ -62,7 +57,7 @@ unsigned short FAR *work; ...@@ -62,7 +57,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 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, 199, 202}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
......
...@@ -38,7 +38,7 @@ typedef struct { ...@@ -38,7 +38,7 @@ typedef struct {
/* 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 returns 852, and "enough 30 6 15" for distance codes returns 592.
...@@ -57,6 +57,6 @@ typedef enum { ...@@ -57,6 +57,6 @@ typedef enum {
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);
...@@ -122,39 +122,116 @@ struct static_tree_desc_s { ...@@ -122,39 +122,116 @@ struct static_tree_desc_s {
int max_length; /* max bit length for the codes */ int max_length; /* max bit length for the codes */
}; };
local const static_tree_desc static_l_desc = #ifdef NO_INIT_GLOBAL_POINTERS
# define TCONST
#else
# define TCONST const
#endif
local TCONST static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
local const static_tree_desc static_d_desc = local TCONST static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
local const static_tree_desc static_bl_desc = local TCONST static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
/* =========================================================================== /* ===========================================================================
* Local (static) routines in this file. * Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf.
*/ */
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
local void tr_static_init OF((void)); /* ===========================================================================
local void init_block OF((deflate_state *s)); * Reverse the first len bits of a code, using straightforward code (a faster
local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); * method would use a table)
local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); * IN assertion: 1 <= len <= 15
local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); */
local void build_tree OF((deflate_state *s, tree_desc *desc)); local unsigned bi_reverse(unsigned code, int len) {
local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); register unsigned res = 0;
local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); do {
local int build_bl_tree OF((deflate_state *s)); res |= code & 1;
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, code >>= 1, res <<= 1;
int blcodes)); } while (--len > 0);
local void compress_block OF((deflate_state *s, const ct_data *ltree, return res >> 1;
const ct_data *dtree)); }
local int detect_data_type OF((deflate_state *s));
local unsigned bi_reverse OF((unsigned code, int len)); /* ===========================================================================
local void bi_windup OF((deflate_state *s)); * Flush the bit buffer, keeping at most 7 bits in it.
local void bi_flush OF((deflate_state *s)); */
local void bi_flush(deflate_state *s) {
if (s->bi_valid == 16) {
put_short(s, s->bi_buf);
s->bi_buf = 0;
s->bi_valid = 0;
} else if (s->bi_valid >= 8) {
put_byte(s, (Byte)s->bi_buf);
s->bi_buf >>= 8;
s->bi_valid -= 8;
}
}
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/
local void bi_windup(deflate_state *s) {
if (s->bi_valid > 8) {
put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
s->bits_sent = (s->bits_sent + 7) & ~7;
#endif
}
/* ===========================================================================
* Generate the codes for a given tree and bit counts (which need not be
* optimal).
* IN assertion: the array bl_count contains the bit length statistics for
* the given tree and the field len is set for all tree elements.
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) {
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
code = (code + bl_count[bits - 1]) << 1;
next_code[bits] = (ush)code;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
*/
Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
"inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
}
}
#ifdef GEN_TREES_H #ifdef GEN_TREES_H
local void gen_trees_header OF((void)); local void gen_trees_header(void);
#endif #endif
#ifndef ZLIB_DEBUG #ifndef ZLIB_DEBUG
...@@ -168,32 +245,17 @@ local void gen_trees_header OF((void)); ...@@ -168,32 +245,17 @@ local void gen_trees_header OF((void));
#endif #endif
/* =========================================================================== /* ===========================================================================
* Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf.
*/
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
/* ===========================================================================
* Send a value on a given number of bits. * Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits. * IN assertion: length <= 16 and value fits in length bits.
*/ */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
local void send_bits OF((deflate_state *s, int value, int length)); local void send_bits(deflate_state *s, int value, int length) {
local void send_bits(s, value, length)
deflate_state *s;
int value; /* value to send */
int length; /* number of bits */
{
Tracevv((stderr," l %2d v %4x ", length, value)); Tracevv((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length"); Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length; s->bits_sent += (ulg)length;
/* If not enough room in bi_buf, use (valid) bits from bi_buf and /* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) * (16 - bi_valid) bits from value, leaving (width - (16 - bi_valid))
* unused bits in value. * unused bits in value.
*/ */
if (s->bi_valid > (int)Buf_size - length) { if (s->bi_valid > (int)Buf_size - length) {
...@@ -229,8 +291,7 @@ local void send_bits(s, value, length) ...@@ -229,8 +291,7 @@ local void send_bits(s, value, length)
/* =========================================================================== /* ===========================================================================
* Initialize the various 'constant' tables. * Initialize the various 'constant' tables.
*/ */
local void tr_static_init() local void tr_static_init(void) {
{
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
static int static_init_done = 0; static int static_init_done = 0;
int n; /* iterates over tree elements */ int n; /* iterates over tree elements */
...@@ -256,7 +317,7 @@ local void tr_static_init() ...@@ -256,7 +317,7 @@ local void tr_static_init()
length = 0; length = 0;
for (code = 0; code < LENGTH_CODES-1; code++) { for (code = 0; code < LENGTH_CODES-1; code++) {
base_length[code] = length; base_length[code] = length;
for (n = 0; n < (1<<extra_lbits[code]); n++) { for (n = 0; n < (1 << extra_lbits[code]); n++) {
_length_code[length++] = (uch)code; _length_code[length++] = (uch)code;
} }
} }
...@@ -265,13 +326,13 @@ local void tr_static_init() ...@@ -265,13 +326,13 @@ local void tr_static_init()
* in two different ways: code 284 + 5 bits or code 285, so we * in two different ways: code 284 + 5 bits or code 285, so we
* overwrite length_code[255] to use the best encoding: * overwrite length_code[255] to use the best encoding:
*/ */
_length_code[length-1] = (uch)code; _length_code[length - 1] = (uch)code;
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0; dist = 0;
for (code = 0 ; code < 16; code++) { for (code = 0 ; code < 16; code++) {
base_dist[code] = dist; base_dist[code] = dist;
for (n = 0; n < (1<<extra_dbits[code]); n++) { for (n = 0; n < (1 << extra_dbits[code]); n++) {
_dist_code[dist++] = (uch)code; _dist_code[dist++] = (uch)code;
} }
} }
...@@ -279,11 +340,11 @@ local void tr_static_init() ...@@ -279,11 +340,11 @@ local void tr_static_init()
dist >>= 7; /* from now on, all distances are divided by 128 */ dist >>= 7; /* from now on, all distances are divided by 128 */
for ( ; code < D_CODES; code++) { for ( ; code < D_CODES; code++) {
base_dist[code] = dist << 7; base_dist[code] = dist << 7;
for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
_dist_code[256 + dist++] = (uch)code; _dist_code[256 + dist++] = (uch)code;
} }
} }
Assert (dist == 256, "tr_static_init: 256+dist != 512"); Assert (dist == 256, "tr_static_init: 256 + dist != 512");
/* Construct the codes of the static literal tree */ /* Construct the codes of the static literal tree */
for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
...@@ -312,7 +373,7 @@ local void tr_static_init() ...@@ -312,7 +373,7 @@ local void tr_static_init()
} }
/* =========================================================================== /* ===========================================================================
* Genererate the file trees.h describing the static trees. * Generate the file trees.h describing the static trees.
*/ */
#ifdef GEN_TREES_H #ifdef GEN_TREES_H
# ifndef ZLIB_DEBUG # ifndef ZLIB_DEBUG
...@@ -321,10 +382,9 @@ local void tr_static_init() ...@@ -321,10 +382,9 @@ local void tr_static_init()
# define SEPARATOR(i, last, width) \ # define SEPARATOR(i, last, width) \
((i) == (last)? "\n};\n\n" : \ ((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width)-1 ? ",\n" : ", ")) ((i) % (width) == (width) - 1 ? ",\n" : ", "))
void gen_trees_header() void gen_trees_header(void) {
{
FILE *header = fopen("trees.h", "w"); FILE *header = fopen("trees.h", "w");
int i; int i;
...@@ -374,11 +434,25 @@ void gen_trees_header() ...@@ -374,11 +434,25 @@ void gen_trees_header()
#endif /* GEN_TREES_H */ #endif /* GEN_TREES_H */
/* =========================================================================== /* ===========================================================================
* Initialize a new block.
*/
local void init_block(deflate_state *s) {
int n; /* iterates over tree elements */
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L;
s->sym_next = s->matches = 0;
}
/* ===========================================================================
* Initialize the tree data structures for a new zlib stream. * Initialize the tree data structures for a new zlib stream.
*/ */
void ZLIB_INTERNAL _tr_init(s) void ZLIB_INTERNAL _tr_init(deflate_state *s) {
deflate_state *s;
{
tr_static_init(); tr_static_init();
s->l_desc.dyn_tree = s->dyn_ltree; s->l_desc.dyn_tree = s->dyn_ltree;
...@@ -401,24 +475,6 @@ void ZLIB_INTERNAL _tr_init(s) ...@@ -401,24 +475,6 @@ void ZLIB_INTERNAL _tr_init(s)
init_block(s); init_block(s);
} }
/* ===========================================================================
* Initialize a new block.
*/
local void init_block(s)
deflate_state *s;
{
int n; /* iterates over tree elements */
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L;
s->sym_next = s->matches = 0;
}
#define SMALLEST 1 #define SMALLEST 1
/* Index within the heap array of least frequent node in the Huffman tree */ /* Index within the heap array of least frequent node in the Huffman tree */
...@@ -448,17 +504,13 @@ local void init_block(s) ...@@ -448,17 +504,13 @@ local void init_block(s)
* when the heap property is re-established (each father smaller than its * when the heap property is re-established (each father smaller than its
* two sons). * two sons).
*/ */
local void pqdownheap(s, tree, k) local void pqdownheap(deflate_state *s, ct_data *tree, int k) {
deflate_state *s;
ct_data *tree; /* the tree to restore */
int k; /* node to move down */
{
int v = s->heap[k]; int v = s->heap[k];
int j = k << 1; /* left son of k */ int j = k << 1; /* left son of k */
while (j <= s->heap_len) { while (j <= s->heap_len) {
/* Set j to the smallest of the two sons: */ /* Set j to the smallest of the two sons: */
if (j < s->heap_len && if (j < s->heap_len &&
smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { smaller(tree, s->heap[j + 1], s->heap[j], s->depth)) {
j++; j++;
} }
/* Exit if v is smaller than both sons */ /* Exit if v is smaller than both sons */
...@@ -483,10 +535,7 @@ local void pqdownheap(s, tree, k) ...@@ -483,10 +535,7 @@ local void pqdownheap(s, tree, k)
* The length opt_len is updated; static_len is also updated if stree is * The length opt_len is updated; static_len is also updated if stree is
* not null. * not null.
*/ */
local void gen_bitlen(s, desc) local void gen_bitlen(deflate_state *s, tree_desc *desc) {
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree; ct_data *tree = desc->dyn_tree;
int max_code = desc->max_code; int max_code = desc->max_code;
const ct_data *stree = desc->stat_desc->static_tree; const ct_data *stree = desc->stat_desc->static_tree;
...@@ -507,7 +556,7 @@ local void gen_bitlen(s, desc) ...@@ -507,7 +556,7 @@ local void gen_bitlen(s, desc)
*/ */
tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
for (h = s->heap_max+1; h < HEAP_SIZE; h++) { for (h = s->heap_max + 1; h < HEAP_SIZE; h++) {
n = s->heap[h]; n = s->heap[h];
bits = tree[tree[n].Dad].Len + 1; bits = tree[tree[n].Dad].Len + 1;
if (bits > max_length) bits = max_length, overflow++; if (bits > max_length) bits = max_length, overflow++;
...@@ -518,7 +567,7 @@ local void gen_bitlen(s, desc) ...@@ -518,7 +567,7 @@ local void gen_bitlen(s, desc)
s->bl_count[bits]++; s->bl_count[bits]++;
xbits = 0; xbits = 0;
if (n >= base) xbits = extra[n-base]; if (n >= base) xbits = extra[n - base];
f = tree[n].Freq; f = tree[n].Freq;
s->opt_len += (ulg)f * (unsigned)(bits + xbits); s->opt_len += (ulg)f * (unsigned)(bits + xbits);
if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits); if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits);
...@@ -530,10 +579,10 @@ local void gen_bitlen(s, desc) ...@@ -530,10 +579,10 @@ local void gen_bitlen(s, desc)
/* Find the first bit length which could increase: */ /* Find the first bit length which could increase: */
do { do {
bits = max_length-1; bits = max_length - 1;
while (s->bl_count[bits] == 0) bits--; while (s->bl_count[bits] == 0) bits--;
s->bl_count[bits]--; /* move one leaf down the tree */ s->bl_count[bits]--; /* move one leaf down the tree */
s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ s->bl_count[bits + 1] += 2; /* move one overflow item as its brother */
s->bl_count[max_length]--; s->bl_count[max_length]--;
/* The brother of the overflow item also moves one step up, /* The brother of the overflow item also moves one step up,
* but this does not affect bl_count[max_length] * but this does not affect bl_count[max_length]
...@@ -561,48 +610,9 @@ local void gen_bitlen(s, desc) ...@@ -561,48 +610,9 @@ local void gen_bitlen(s, desc)
} }
} }
/* =========================================================================== #ifdef DUMP_BL_TREE
* Generate the codes for a given tree and bit counts (which need not be # include <stdio.h>
* optimal). #endif
* IN assertion: the array bl_count contains the bit length statistics for
* the given tree and the field len is set for all tree elements.
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
local void gen_codes (tree, max_code, bl_count)
ct_data *tree; /* the tree to decorate */
int max_code; /* largest code with non zero frequency */
ushf *bl_count; /* number of codes at each bit length */
{
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
code = (code + bl_count[bits-1]) << 1;
next_code[bits] = (ush)code;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
*/
Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
"inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
}
}
/* =========================================================================== /* ===========================================================================
* Construct one Huffman tree and assigns the code bit strings and lengths. * Construct one Huffman tree and assigns the code bit strings and lengths.
...@@ -612,10 +622,7 @@ local void gen_codes (tree, max_code, bl_count) ...@@ -612,10 +622,7 @@ local void gen_codes (tree, max_code, bl_count)
* and corresponding code. The length opt_len is updated; static_len is * and corresponding code. The length opt_len is updated; static_len is
* also updated if stree is not null. The field max_code is set. * also updated if stree is not null. The field max_code is set.
*/ */
local void build_tree(s, desc) local void build_tree(deflate_state *s, tree_desc *desc) {
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree; ct_data *tree = desc->dyn_tree;
const ct_data *stree = desc->stat_desc->static_tree; const ct_data *stree = desc->stat_desc->static_tree;
int elems = desc->stat_desc->elems; int elems = desc->stat_desc->elems;
...@@ -624,7 +631,7 @@ local void build_tree(s, desc) ...@@ -624,7 +631,7 @@ local void build_tree(s, desc)
int node; /* new node being created */ int node; /* new node being created */
/* Construct the initial heap, with least frequent element in /* Construct the initial heap, with least frequent element in
* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n + 1].
* heap[0] is not used. * heap[0] is not used.
*/ */
s->heap_len = 0, s->heap_max = HEAP_SIZE; s->heap_len = 0, s->heap_max = HEAP_SIZE;
...@@ -652,7 +659,7 @@ local void build_tree(s, desc) ...@@ -652,7 +659,7 @@ local void build_tree(s, desc)
} }
desc->max_code = max_code; desc->max_code = max_code;
/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, /* The elements heap[heap_len/2 + 1 .. heap_len] are leaves of the tree,
* establish sub-heaps of increasing lengths: * establish sub-heaps of increasing lengths:
*/ */
for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
...@@ -700,11 +707,7 @@ local void build_tree(s, desc) ...@@ -700,11 +707,7 @@ local void build_tree(s, desc)
* Scan a literal or distance tree to determine the frequencies of the codes * Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree. * in the bit length tree.
*/ */
local void scan_tree (s, tree, max_code) local void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
deflate_state *s;
ct_data *tree; /* the tree to be scanned */
int max_code; /* and its largest code of non zero frequency */
{
int n; /* iterates over all tree elements */ int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */ int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */ int curlen; /* length of current code */
...@@ -714,10 +717,10 @@ local void scan_tree (s, tree, max_code) ...@@ -714,10 +717,10 @@ local void scan_tree (s, tree, max_code)
int min_count = 4; /* min repeat count */ int min_count = 4; /* min repeat count */
if (nextlen == 0) max_count = 138, min_count = 3; if (nextlen == 0) max_count = 138, min_count = 3;
tree[max_code+1].Len = (ush)0xffff; /* guard */ tree[max_code + 1].Len = (ush)0xffff; /* guard */
for (n = 0; n <= max_code; n++) { for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len; curlen = nextlen; nextlen = tree[n + 1].Len;
if (++count < max_count && curlen == nextlen) { if (++count < max_count && curlen == nextlen) {
continue; continue;
} else if (count < min_count) { } else if (count < min_count) {
...@@ -745,11 +748,7 @@ local void scan_tree (s, tree, max_code) ...@@ -745,11 +748,7 @@ local void scan_tree (s, tree, max_code)
* Send a literal or distance tree in compressed form, using the codes in * Send a literal or distance tree in compressed form, using the codes in
* bl_tree. * bl_tree.
*/ */
local void send_tree (s, tree, max_code) local void send_tree(deflate_state *s, ct_data *tree, int max_code) {
deflate_state *s;
ct_data *tree; /* the tree to be scanned */
int max_code; /* and its largest code of non zero frequency */
{
int n; /* iterates over all tree elements */ int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */ int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */ int curlen; /* length of current code */
...@@ -758,11 +757,11 @@ local void send_tree (s, tree, max_code) ...@@ -758,11 +757,11 @@ local void send_tree (s, tree, max_code)
int max_count = 7; /* max repeat count */ int max_count = 7; /* max repeat count */
int min_count = 4; /* min repeat count */ int min_count = 4; /* min repeat count */
/* tree[max_code+1].Len = -1; */ /* guard already set */ /* tree[max_code + 1].Len = -1; */ /* guard already set */
if (nextlen == 0) max_count = 138, min_count = 3; if (nextlen == 0) max_count = 138, min_count = 3;
for (n = 0; n <= max_code; n++) { for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len; curlen = nextlen; nextlen = tree[n + 1].Len;
if (++count < max_count && curlen == nextlen) { if (++count < max_count && curlen == nextlen) {
continue; continue;
} else if (count < min_count) { } else if (count < min_count) {
...@@ -773,13 +772,13 @@ local void send_tree (s, tree, max_code) ...@@ -773,13 +772,13 @@ local void send_tree (s, tree, max_code)
send_code(s, curlen, s->bl_tree); count--; send_code(s, curlen, s->bl_tree); count--;
} }
Assert(count >= 3 && count <= 6, " 3_6?"); Assert(count >= 3 && count <= 6, " 3_6?");
send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); send_code(s, REP_3_6, s->bl_tree); send_bits(s, count - 3, 2);
} else if (count <= 10) { } else if (count <= 10) {
send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count - 3, 3);
} else { } else {
send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count - 11, 7);
} }
count = 0; prevlen = curlen; count = 0; prevlen = curlen;
if (nextlen == 0) { if (nextlen == 0) {
...@@ -796,9 +795,7 @@ local void send_tree (s, tree, max_code) ...@@ -796,9 +795,7 @@ local void send_tree (s, tree, max_code)
* Construct the Huffman tree for the bit lengths and return the index in * Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send. * bl_order of the last bit length code to send.
*/ */
local int build_bl_tree(s) local int build_bl_tree(deflate_state *s) {
deflate_state *s;
{
int max_blindex; /* index of last bit length code of non zero freq */ int max_blindex; /* index of last bit length code of non zero freq */
/* Determine the bit length frequencies for literal and distance trees */ /* Determine the bit length frequencies for literal and distance trees */
...@@ -807,8 +804,8 @@ local int build_bl_tree(s) ...@@ -807,8 +804,8 @@ local int build_bl_tree(s)
/* Build the bit length tree: */ /* Build the bit length tree: */
build_tree(s, (tree_desc *)(&(s->bl_desc))); build_tree(s, (tree_desc *)(&(s->bl_desc)));
/* opt_len now includes the length of the tree representations, except /* opt_len now includes the length of the tree representations, except the
* the lengths of the bit lengths codes and the 5+5+4 bits for the counts. * lengths of the bit lengths codes and the 5 + 5 + 4 bits for the counts.
*/ */
/* Determine the number of bit length codes to send. The pkzip format /* Determine the number of bit length codes to send. The pkzip format
...@@ -819,7 +816,7 @@ local int build_bl_tree(s) ...@@ -819,7 +816,7 @@ local int build_bl_tree(s)
if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
} }
/* Update opt_len to include the bit length tree and counts */ /* Update opt_len to include the bit length tree and counts */
s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4; s->opt_len += 3*((ulg)max_blindex + 1) + 5 + 5 + 4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
s->opt_len, s->static_len)); s->opt_len, s->static_len));
...@@ -831,42 +828,36 @@ local int build_bl_tree(s) ...@@ -831,42 +828,36 @@ local int build_bl_tree(s)
* lengths of the bit length codes, the literal tree and the distance tree. * lengths of the bit length codes, the literal tree and the distance tree.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/ */
local void send_all_trees(s, lcodes, dcodes, blcodes) local void send_all_trees(deflate_state *s, int lcodes, int dcodes,
deflate_state *s; int blcodes) {
int lcodes, dcodes, blcodes; /* number of codes for each tree */
{
int rank; /* index in bl_order */ int rank; /* index in bl_order */
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
"too many codes"); "too many codes");
Tracev((stderr, "\nbl counts: ")); Tracev((stderr, "\nbl counts: "));
send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
send_bits(s, dcodes-1, 5); send_bits(s, dcodes - 1, 5);
send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
for (rank = 0; rank < blcodes; rank++) { for (rank = 0; rank < blcodes; rank++) {
Tracev((stderr, "\nbl code %2d ", bl_order[rank])); Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
} }
Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ send_tree(s, (ct_data *)s->dyn_ltree, lcodes - 1); /* literal tree */
Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ send_tree(s, (ct_data *)s->dyn_dtree, dcodes - 1); /* distance tree */
Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
} }
/* =========================================================================== /* ===========================================================================
* Send a stored block * Send a stored block
*/ */
void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
deflate_state *s; ulg stored_len, int last) {
charf *buf; /* input block */ send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */
ulg stored_len; /* length of input block */
int last; /* one if this is the last block for a file */
{
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
bi_windup(s); /* align on byte boundary */ bi_windup(s); /* align on byte boundary */
put_short(s, (ush)stored_len); put_short(s, (ush)stored_len);
put_short(s, (ush)~stored_len); put_short(s, (ush)~stored_len);
...@@ -877,16 +868,14 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) ...@@ -877,16 +868,14 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3; s->compressed_len += (stored_len + 4) << 3;
s->bits_sent += 2*16; s->bits_sent += 2*16;
s->bits_sent += stored_len<<3; s->bits_sent += stored_len << 3;
#endif #endif
} }
/* =========================================================================== /* ===========================================================================
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits) * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
*/ */
void ZLIB_INTERNAL _tr_flush_bits(s) void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
deflate_state *s;
{
bi_flush(s); bi_flush(s);
} }
...@@ -894,9 +883,7 @@ void ZLIB_INTERNAL _tr_flush_bits(s) ...@@ -894,9 +883,7 @@ void ZLIB_INTERNAL _tr_flush_bits(s)
* Send one empty static block to give enough lookahead for inflate. * Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer. * This takes 10 bits, of which 7 may remain in the bit buffer.
*/ */
void ZLIB_INTERNAL _tr_align(s) void ZLIB_INTERNAL _tr_align(deflate_state *s) {
deflate_state *s;
{
send_bits(s, STATIC_TREES<<1, 3); send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree); send_code(s, END_BLOCK, static_ltree);
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
...@@ -906,15 +893,98 @@ void ZLIB_INTERNAL _tr_align(s) ...@@ -906,15 +893,98 @@ void ZLIB_INTERNAL _tr_align(s)
} }
/* =========================================================================== /* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
local void compress_block(deflate_state *s, const ct_data *ltree,
const ct_data *dtree) {
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned sx = 0; /* running index in sym_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
if (s->sym_next != 0) do {
dist = s->sym_buf[sx++] & 0xff;
dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
lc = s->sym_buf[sx++];
if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */
Tracecv(isgraph(lc), (stderr," '%c' ", lc));
} else {
/* Here, lc is the match length - MIN_MATCH */
code = _length_code[lc];
send_code(s, code + LITERALS + 1, ltree); /* send length code */
extra = extra_lbits[code];
if (extra != 0) {
lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */
}
dist--; /* dist is now the match distance - 1 */
code = d_code(dist);
Assert (code < D_CODES, "bad d_code");
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
dist -= (unsigned)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and sym_buf is ok: */
Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
} while (sx < s->sym_next);
send_code(s, END_BLOCK, ltree);
}
/* ===========================================================================
* Check if the data type is TEXT or BINARY, using the following algorithm:
* - TEXT if the two conditions below are satisfied:
* a) There are no non-portable control characters belonging to the
* "block list" (0..6, 14..25, 28..31).
* b) There is at least one printable character belonging to the
* "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* - BINARY otherwise.
* - The following partially-portable control characters form a
* "gray list" that is ignored in this detection algorithm:
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
* IN assertion: the fields Freq of dyn_ltree are set.
*/
local int detect_data_type(deflate_state *s) {
/* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
unsigned long block_mask = 0xf3ffc07fUL;
int n;
/* Check for non-textual ("block-listed") bytes. */
for (n = 0; n <= 31; n++, block_mask >>= 1)
if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
return Z_BINARY;
/* Check for textual ("allow-listed") bytes. */
if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
|| s->dyn_ltree[13].Freq != 0)
return Z_TEXT;
for (n = 32; n < LITERALS; n++)
if (s->dyn_ltree[n].Freq != 0)
return Z_TEXT;
/* There are no "block-listed" or "allow-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only.
*/
return Z_BINARY;
}
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static * Determine the best encoding for the current block: dynamic trees, static
* trees or store, and write out the encoded block. * trees or store, and write out the encoded block.
*/ */
void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
deflate_state *s; ulg stored_len, int last) {
charf *buf; /* input block, or NULL if too old */
ulg stored_len; /* length of input block */
int last; /* one if this is the last block for a file */
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex = 0; /* index of last bit length code of non zero freq */ int max_blindex = 0; /* index of last bit length code of non zero freq */
...@@ -943,14 +1013,17 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) ...@@ -943,14 +1013,17 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
max_blindex = build_bl_tree(s); max_blindex = build_bl_tree(s);
/* Determine the best encoding. Compute the block lengths in bytes. */ /* Determine the best encoding. Compute the block lengths in bytes. */
opt_lenb = (s->opt_len+3+7)>>3; opt_lenb = (s->opt_len + 3 + 7) >> 3;
static_lenb = (s->static_len+3+7)>>3; static_lenb = (s->static_len + 3 + 7) >> 3;
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->sym_next / 3)); s->sym_next / 3));
if (static_lenb <= opt_lenb) opt_lenb = static_lenb; #ifndef FORCE_STATIC
if (static_lenb <= opt_lenb || s->strategy == Z_FIXED)
#endif
opt_lenb = static_lenb;
} else { } else {
Assert(buf != (char*)0, "lost buf"); Assert(buf != (char*)0, "lost buf");
...@@ -960,7 +1033,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) ...@@ -960,7 +1033,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
#ifdef FORCE_STORED #ifdef FORCE_STORED
if (buf != (char*)0) { /* force stored block */ if (buf != (char*)0) { /* force stored block */
#else #else
if (stored_len+4 <= opt_lenb && buf != (char*)0) { if (stored_len + 4 <= opt_lenb && buf != (char*)0) {
/* 4: two words for the lengths */ /* 4: two words for the lengths */
#endif #endif
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
...@@ -971,21 +1044,17 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) ...@@ -971,21 +1044,17 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
*/ */
_tr_stored_block(s, buf, stored_len, last); _tr_stored_block(s, buf, stored_len, last);
#ifdef FORCE_STATIC } else if (static_lenb == opt_lenb) {
} else if (static_lenb >= 0) { /* force static trees */ send_bits(s, (STATIC_TREES<<1) + last, 3);
#else
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
#endif
send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree, compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree); (const ct_data *)static_dtree);
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
s->compressed_len += 3 + s->static_len; s->compressed_len += 3 + s->static_len;
#endif #endif
} else { } else {
send_bits(s, (DYN_TREES<<1)+last, 3); send_bits(s, (DYN_TREES<<1) + last, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, send_all_trees(s, s->l_desc.max_code + 1, s->d_desc.max_code + 1,
max_blindex+1); max_blindex + 1);
compress_block(s, (const ct_data *)s->dyn_ltree, compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree); (const ct_data *)s->dyn_dtree);
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
...@@ -1004,19 +1073,15 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) ...@@ -1004,19 +1073,15 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
s->compressed_len += 7; /* align on byte boundary */ s->compressed_len += 7; /* align on byte boundary */
#endif #endif
} }
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len >> 3,
s->compressed_len-7*last)); s->compressed_len - 7*last));
} }
/* =========================================================================== /* ===========================================================================
* Save the match info and tally the frequency counts. Return true if * Save the match info and tally the frequency counts. Return true if
* the current block must be flushed. * the current block must be flushed.
*/ */
int ZLIB_INTERNAL _tr_tally (s, dist, lc) int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) {
deflate_state *s;
unsigned dist; /* distance of matched string */
unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
{
s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)dist;
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)(dist >> 8);
s->sym_buf[s->sym_next++] = (uch)lc; s->sym_buf[s->sym_next++] = (uch)lc;
...@@ -1031,152 +1096,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc) ...@@ -1031,152 +1096,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
(ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
(ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; s->dyn_ltree[_length_code[lc] + LITERALS + 1].Freq++;
s->dyn_dtree[d_code(dist)].Freq++; s->dyn_dtree[d_code(dist)].Freq++;
} }
return (s->sym_next == s->sym_end); return (s->sym_next == s->sym_end);
} }
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
local void compress_block(s, ltree, dtree)
deflate_state *s;
const ct_data *ltree; /* literal tree */
const ct_data *dtree; /* distance tree */
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned sx = 0; /* running index in sym_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
if (s->sym_next != 0) do {
dist = s->sym_buf[sx++] & 0xff;
dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
lc = s->sym_buf[sx++];
if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */
Tracecv(isgraph(lc), (stderr," '%c' ", lc));
} else {
/* Here, lc is the match length - MIN_MATCH */
code = _length_code[lc];
send_code(s, code+LITERALS+1, ltree); /* send the length code */
extra = extra_lbits[code];
if (extra != 0) {
lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */
}
dist--; /* dist is now the match distance - 1 */
code = d_code(dist);
Assert (code < D_CODES, "bad d_code");
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
dist -= (unsigned)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and sym_buf is ok: */
Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
} while (sx < s->sym_next);
send_code(s, END_BLOCK, ltree);
}
/* ===========================================================================
* Check if the data type is TEXT or BINARY, using the following algorithm:
* - TEXT if the two conditions below are satisfied:
* a) There are no non-portable control characters belonging to the
* "block list" (0..6, 14..25, 28..31).
* b) There is at least one printable character belonging to the
* "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* - BINARY otherwise.
* - The following partially-portable control characters form a
* "gray list" that is ignored in this detection algorithm:
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
* IN assertion: the fields Freq of dyn_ltree are set.
*/
local int detect_data_type(s)
deflate_state *s;
{
/* block_mask is the bit mask of block-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
unsigned long block_mask = 0xf3ffc07fUL;
int n;
/* Check for non-textual ("block-listed") bytes. */
for (n = 0; n <= 31; n++, block_mask >>= 1)
if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
return Z_BINARY;
/* Check for textual ("allow-listed") bytes. */
if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
|| s->dyn_ltree[13].Freq != 0)
return Z_TEXT;
for (n = 32; n < LITERALS; n++)
if (s->dyn_ltree[n].Freq != 0)
return Z_TEXT;
/* There are no "block-listed" or "allow-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only.
*/
return Z_BINARY;
}
/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table)
* IN assertion: 1 <= len <= 15
*/
local unsigned bi_reverse(code, len)
unsigned code; /* the value to invert */
int len; /* its bit length */
{
register unsigned res = 0;
do {
res |= code & 1;
code >>= 1, res <<= 1;
} while (--len > 0);
return res >> 1;
}
/* ===========================================================================
* Flush the bit buffer, keeping at most 7 bits in it.
*/
local void bi_flush(s)
deflate_state *s;
{
if (s->bi_valid == 16) {
put_short(s, s->bi_buf);
s->bi_buf = 0;
s->bi_valid = 0;
} else if (s->bi_valid >= 8) {
put_byte(s, (Byte)s->bi_buf);
s->bi_buf >>= 8;
s->bi_valid -= 8;
}
}
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/
local void bi_windup(s)
deflate_state *s;
{
if (s->bi_valid > 8) {
put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
s->bits_sent = (s->bits_sent+7) & ~7;
#endif
}
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
# define crc32 z_crc32 # define crc32 z_crc32
# define crc32_combine z_crc32_combine # define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64 # define crc32_combine64 z_crc32_combine64
# define crc32_combine_gen z_crc32_combine_gen
# define crc32_combine_gen64 z_crc32_combine_gen64
# define crc32_combine_op z_crc32_combine_op
# define crc32_z z_crc32_z # define crc32_z z_crc32_z
# define deflate z_deflate # define deflate z_deflate
# define deflateBound z_deflateBound # define deflateBound z_deflateBound
...@@ -238,7 +241,11 @@ ...@@ -238,7 +241,11 @@
#endif #endif
#ifdef Z_SOLO #ifdef Z_SOLO
typedef unsigned long z_size_t; # ifdef _WIN64
typedef unsigned long long z_size_t;
# else
typedef unsigned long z_size_t;
# endif
#else #else
# define z_longlong long long # define z_longlong long long
# if defined(NO_SIZE_T) # if defined(NO_SIZE_T)
...@@ -349,6 +356,9 @@ ...@@ -349,6 +356,9 @@
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
...@@ -467,11 +477,18 @@ typedef uLong FAR uLongf; ...@@ -467,11 +477,18 @@ typedef uLong FAR uLongf;
# undef _LARGEFILE64_SOURCE # undef _LARGEFILE64_SOURCE
#endif #endif
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) #ifndef Z_HAVE_UNISTD_H
# define Z_HAVE_UNISTD_H # ifdef __WATCOMC__
# define Z_HAVE_UNISTD_H
# endif
#endif
#ifndef Z_HAVE_UNISTD_H
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
# define Z_HAVE_UNISTD_H
# endif
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) # if defined(Z_HAVE_UNISTD_H)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# ifdef VMS # ifdef VMS
# include <unixio.h> /* for off_t */ # include <unixio.h> /* for off_t */
...@@ -507,7 +524,7 @@ typedef uLong FAR uLongf; ...@@ -507,7 +524,7 @@ typedef uLong FAR uLongf;
#if !defined(_WIN32) && defined(Z_LARGE64) #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#else #else
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) # if defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64 # define z_off64_t __int64
# else # else
# define z_off64_t z_off_t # define z_off64_t z_off_t
......
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.12, March 11th, 2022 version 1.3, August 18th, 2023
Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
...@@ -37,11 +37,11 @@ ...@@ -37,11 +37,11 @@
extern "C" { extern "C" {
#endif #endif
#define ZLIB_VERSION "1.2.12" #define ZLIB_VERSION "1.3"
#define ZLIB_VERNUM 0x12c0 #define ZLIB_VERNUM 0x1300
#define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2 #define ZLIB_VER_MINOR 3
#define ZLIB_VER_REVISION 12 #define ZLIB_VER_REVISION 0
#define ZLIB_VER_SUBREVISION 0 #define ZLIB_VER_SUBREVISION 0
/* /*
...@@ -78,8 +78,8 @@ extern "C" { ...@@ -78,8 +78,8 @@ extern "C" {
even in the case of corrupted input. even in the case of corrupted input.
*/ */
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func) OF((voidpf opaque, voidpf address)); typedef void (*free_func)(voidpf opaque, voidpf address);
struct internal_state; struct internal_state;
...@@ -217,7 +217,7 @@ typedef gz_header FAR *gz_headerp; ...@@ -217,7 +217,7 @@ typedef gz_header FAR *gz_headerp;
/* basic functions */ /* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion OF((void)); ZEXTERN const char * ZEXPORT zlibVersion(void);
/* The application can compare zlibVersion and ZLIB_VERSION for consistency. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is not If the first character differs, the library code actually used is not
compatible with the zlib.h header file used by the application. This check compatible with the zlib.h header file used by the application. This check
...@@ -225,12 +225,12 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void)); ...@@ -225,12 +225,12 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void));
*/ */
/* /*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level);
Initializes the internal stream state for compression. The fields Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller. If zalloc, zfree and opaque must be initialized before by the caller. If
zalloc and zfree are set to Z_NULL, deflateInit updates them to use default zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
allocation functions. allocation functions. total_in, total_out, adler, and msg are initialized.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at all 1 gives best speed, 9 gives best compression, 0 gives no compression at all
...@@ -247,7 +247,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); ...@@ -247,7 +247,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
*/ */
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush);
/* /*
deflate compresses as much data as possible, and stops when the input deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce buffer becomes empty or the output buffer becomes full. It may introduce
...@@ -276,7 +276,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ...@@ -276,7 +276,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
== 0), or after each call of deflate(). If deflate returns Z_OK and with == 0), or after each call of deflate(). If deflate returns Z_OK and with
zero avail_out, it must be called again after making room in the output zero avail_out, it must be called again after making room in the output
buffer because there might be more output pending. See deflatePending(), buffer because there might be more output pending. See deflatePending(),
which can be used if desired to determine whether or not there is more ouput which can be used if desired to determine whether or not there is more output
in that case. in that case.
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
...@@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ...@@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
with the same value of the flush parameter and more output space (updated with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero avail_out), until the flush is complete (deflate returns with non-zero
avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
avail_out is greater than six to avoid repeated flush markers due to avail_out is greater than six when the flush marker begins, in order to avoid
avail_out == 0 on return. repeated flush markers upon calling deflate() again when avail_out == 0.
If the parameter flush is set to Z_FINISH, pending input is processed, If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there was pending output is flushed and deflate returns with Z_STREAM_END if there was
...@@ -360,7 +360,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ...@@ -360,7 +360,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
*/ */
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); ZEXTERN int ZEXPORT deflateEnd(z_streamp strm);
/* /*
All dynamically allocated data structures for this stream are freed. All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any pending This function discards any unprocessed input and does not flush any pending
...@@ -375,7 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); ...@@ -375,7 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/* /*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateInit(z_streamp strm);
Initializes the internal stream state for decompression. The fields Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by next_in, avail_in, zalloc, zfree and opaque must be initialized before by
...@@ -383,7 +383,8 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); ...@@ -383,7 +383,8 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
read or consumed. The allocation of a sliding window will be deferred to read or consumed. The allocation of a sliding window will be deferred to
the first call of inflate (if the decompression does not complete on the the first call of inflate (if the decompression does not complete on the
first call). If zalloc and zfree are set to Z_NULL, inflateInit updates first call). If zalloc and zfree are set to Z_NULL, inflateInit updates
them to use default allocation functions. them to use default allocation functions. total_in, total_out, adler, and
msg are initialized.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
...@@ -397,7 +398,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); ...@@ -397,7 +398,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
*/ */
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush);
/* /*
inflate decompresses as much data as possible, and stops when the input inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce buffer becomes empty or the output buffer becomes full. It may introduce
...@@ -517,7 +518,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); ...@@ -517,7 +518,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
*/ */
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateEnd(z_streamp strm);
/* /*
All dynamically allocated data structures for this stream are freed. All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any pending This function discards any unprocessed input and does not flush any pending
...@@ -535,12 +536,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); ...@@ -535,12 +536,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
*/ */
/* /*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
int level, int level,
int method, int method,
int windowBits, int windowBits,
int memLevel, int memLevel,
int strategy)); int strategy);
This is another version of deflateInit with more compression options. The This is another version of deflateInit with more compression options. The
fields zalloc, zfree and opaque must be initialized before by the caller. fields zalloc, zfree and opaque must be initialized before by the caller.
...@@ -607,9 +608,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, ...@@ -607,9 +608,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
compression: this will be done by deflate(). compression: this will be done by deflate().
*/ */
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
const Bytef *dictionary, const Bytef *dictionary,
uInt dictLength)); uInt dictLength);
/* /*
Initializes the compression dictionary from the given byte sequence Initializes the compression dictionary from the given byte sequence
without producing any compressed output. When using the zlib format, this without producing any compressed output. When using the zlib format, this
...@@ -651,16 +652,16 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, ...@@ -651,16 +652,16 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
not perform any compression: this will be done by deflate(). not perform any compression: this will be done by deflate().
*/ */
ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm,
Bytef *dictionary, Bytef *dictionary,
uInt *dictLength)); uInt *dictLength);
/* /*
Returns the sliding dictionary being maintained by deflate. dictLength is Returns the sliding dictionary being maintained by deflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied set to the number of bytes in the dictionary, and that many bytes are copied
to dictionary. dictionary must have enough space, where 32768 bytes is to dictionary. dictionary must have enough space, where 32768 bytes is
always enough. If deflateGetDictionary() is called with dictionary equal to always enough. If deflateGetDictionary() is called with dictionary equal to
Z_NULL, then only the dictionary length is returned, and nothing is copied. Z_NULL, then only the dictionary length is returned, and nothing is copied.
Similary, if dictLength is Z_NULL, then it is not set. Similarly, if dictLength is Z_NULL, then it is not set.
deflateGetDictionary() may return a length less than the window size, even deflateGetDictionary() may return a length less than the window size, even
when more than the window size in input has been provided. It may return up when more than the window size in input has been provided. It may return up
...@@ -673,8 +674,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, ...@@ -673,8 +674,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm,
stream state is inconsistent. stream state is inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
z_streamp source)); z_streamp source);
/* /*
Sets the destination stream as a complete copy of the source stream. Sets the destination stream as a complete copy of the source stream.
...@@ -691,20 +692,20 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, ...@@ -691,20 +692,20 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
destination. destination.
*/ */
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); ZEXTERN int ZEXPORT deflateReset(z_streamp strm);
/* /*
This function is equivalent to deflateEnd followed by deflateInit, but This function is equivalent to deflateEnd followed by deflateInit, but
does not free and reallocate the internal compression state. The stream does not free and reallocate the internal compression state. The stream
will leave the compression level and any other attributes that may have been will leave the compression level and any other attributes that may have been
set unchanged. set unchanged. total_in, total_out, adler, and msg are initialized.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL). stream state was inconsistent (such as zalloc or state being Z_NULL).
*/ */
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, ZEXTERN int ZEXPORT deflateParams(z_streamp strm,
int level, int level,
int strategy)); int strategy);
/* /*
Dynamically update the compression level and compression strategy. The Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2(). This can be interpretation of level and strategy is as in deflateInit2(). This can be
...@@ -729,7 +730,7 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, ...@@ -729,7 +730,7 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
Then no more input data should be provided before the deflateParams() call. Then no more input data should be provided before the deflateParams() call.
If this is done, the old level and strategy will be applied to the data If this is done, the old level and strategy will be applied to the data
compressed before deflateParams(), and the new level and strategy will be compressed before deflateParams(), and the new level and strategy will be
applied to the the data compressed after deflateParams(). applied to the data compressed after deflateParams().
deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
...@@ -740,11 +741,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, ...@@ -740,11 +741,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
retried with more output space. retried with more output space.
*/ */
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, ZEXTERN int ZEXPORT deflateTune(z_streamp strm,
int good_length, int good_length,
int max_lazy, int max_lazy,
int nice_length, int nice_length,
int max_chain)); int max_chain);
/* /*
Fine tune deflate's internal compression parameters. This should only be Fine tune deflate's internal compression parameters. This should only be
used by someone who understands the algorithm used by zlib's deflate for used by someone who understands the algorithm used by zlib's deflate for
...@@ -757,8 +758,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, ...@@ -757,8 +758,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
*/ */
ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm,
uLong sourceLen)); uLong sourceLen);
/* /*
deflateBound() returns an upper bound on the compressed size after deflateBound() returns an upper bound on the compressed size after
deflation of sourceLen bytes. It must be called after deflateInit() or deflation of sourceLen bytes. It must be called after deflateInit() or
...@@ -772,9 +773,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, ...@@ -772,9 +773,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
than Z_FINISH or Z_NO_FLUSH are used. than Z_FINISH or Z_NO_FLUSH are used.
*/ */
ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
unsigned *pending, unsigned *pending,
int *bits)); int *bits);
/* /*
deflatePending() returns the number of bytes and bits of output that have deflatePending() returns the number of bytes and bits of output that have
been generated, but not yet provided in the available output. The bytes not been generated, but not yet provided in the available output. The bytes not
...@@ -787,9 +788,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, ...@@ -787,9 +788,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
int bits, int bits,
int value)); int value);
/* /*
deflatePrime() inserts bits in the deflate output stream. The intent deflatePrime() inserts bits in the deflate output stream. The intent
is that this function is used to start off the deflate output with the bits is that this function is used to start off the deflate output with the bits
...@@ -804,8 +805,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, ...@@ -804,8 +805,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
source stream state was inconsistent. source stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm,
gz_headerp head)); gz_headerp head);
/* /*
deflateSetHeader() provides gzip header information for when a gzip deflateSetHeader() provides gzip header information for when a gzip
stream is requested by deflateInit2(). deflateSetHeader() may be called stream is requested by deflateInit2(). deflateSetHeader() may be called
...@@ -821,16 +822,17 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, ...@@ -821,16 +822,17 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
gzip file" and give up. gzip file" and give up.
If deflateSetHeader is not used, the default gzip header has text false, If deflateSetHeader is not used, the default gzip header has text false,
the time set to zero, and os set to 255, with no extra, name, or comment the time set to zero, and os set to the current operating system, with no
fields. The gzip header is returned to the default state by deflateReset(). extra, name, or comment fields. The gzip header is returned to the default
state by deflateReset().
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent.
*/ */
/* /*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
int windowBits)); int windowBits);
This is another version of inflateInit with an extra parameter. The This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized fields next_in, avail_in, zalloc, zfree and opaque must be initialized
...@@ -883,9 +885,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, ...@@ -883,9 +885,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
deferred until inflate() is called. deferred until inflate() is called.
*/ */
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
const Bytef *dictionary, const Bytef *dictionary,
uInt dictLength)); uInt dictLength);
/* /*
Initializes the decompression dictionary from the given uncompressed byte Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate, sequence. This function must be called immediately after a call of inflate,
...@@ -906,22 +908,22 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, ...@@ -906,22 +908,22 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
inflate(). inflate().
*/ */
ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm,
Bytef *dictionary, Bytef *dictionary,
uInt *dictLength)); uInt *dictLength);
/* /*
Returns the sliding dictionary being maintained by inflate. dictLength is Returns the sliding dictionary being maintained by inflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied set to the number of bytes in the dictionary, and that many bytes are copied
to dictionary. dictionary must have enough space, where 32768 bytes is to dictionary. dictionary must have enough space, where 32768 bytes is
always enough. If inflateGetDictionary() is called with dictionary equal to always enough. If inflateGetDictionary() is called with dictionary equal to
Z_NULL, then only the dictionary length is returned, and nothing is copied. Z_NULL, then only the dictionary length is returned, and nothing is copied.
Similary, if dictLength is Z_NULL, then it is not set. Similarly, if dictLength is Z_NULL, then it is not set.
inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
stream state is inconsistent. stream state is inconsistent.
*/ */
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateSync(z_streamp strm);
/* /*
Skips invalid compressed data until a possible full flush point (see above Skips invalid compressed data until a possible full flush point (see above
for the description of deflate with Z_FULL_FLUSH) can be found, or until all for the description of deflate with Z_FULL_FLUSH) can be found, or until all
...@@ -940,8 +942,8 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); ...@@ -940,8 +942,8 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
input each time, until success or end of the input data. input each time, until success or end of the input data.
*/ */
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
z_streamp source)); z_streamp source);
/* /*
Sets the destination stream as a complete copy of the source stream. Sets the destination stream as a complete copy of the source stream.
...@@ -956,18 +958,19 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, ...@@ -956,18 +958,19 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
destination. destination.
*/ */
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateReset(z_streamp strm);
/* /*
This function is equivalent to inflateEnd followed by inflateInit, This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate the internal decompression state. The but does not free and reallocate the internal decompression state. The
stream will keep attributes that may have been set by inflateInit2. stream will keep attributes that may have been set by inflateInit2.
total_in, total_out, adler, and msg are initialized.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL). stream state was inconsistent (such as zalloc or state being Z_NULL).
*/ */
ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, ZEXTERN int ZEXPORT inflateReset2(z_streamp strm,
int windowBits)); int windowBits);
/* /*
This function is the same as inflateReset, but it also permits changing This function is the same as inflateReset, but it also permits changing
the wrap and window size requests. The windowBits parameter is interpreted the wrap and window size requests. The windowBits parameter is interpreted
...@@ -980,9 +983,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, ...@@ -980,9 +983,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
the windowBits parameter is invalid. the windowBits parameter is invalid.
*/ */
ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
int bits, int bits,
int value)); int value);
/* /*
This function inserts bits in the inflate input stream. The intent is This function inserts bits in the inflate input stream. The intent is
that this function is used to start inflating at a bit position in the that this function is used to start inflating at a bit position in the
...@@ -1001,7 +1004,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, ...@@ -1001,7 +1004,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); ZEXTERN long ZEXPORT inflateMark(z_streamp strm);
/* /*
This function returns two values, one in the lower 16 bits of the return This function returns two values, one in the lower 16 bits of the return
value, and the other in the remaining upper bits, obtained by shifting the value, and the other in the remaining upper bits, obtained by shifting the
...@@ -1029,8 +1032,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); ...@@ -1029,8 +1032,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
source stream state was inconsistent. source stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
gz_headerp head)); gz_headerp head);
/* /*
inflateGetHeader() requests that gzip header information be stored in the inflateGetHeader() requests that gzip header information be stored in the
provided gz_header structure. inflateGetHeader() may be called after provided gz_header structure. inflateGetHeader() may be called after
...@@ -1070,8 +1073,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, ...@@ -1070,8 +1073,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
*/ */
/* /*
ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits,
unsigned char FAR *window)); unsigned char FAR *window);
Initialize the internal stream state for decompression using inflateBack() Initialize the internal stream state for decompression using inflateBack()
calls. The fields zalloc, zfree and opaque in strm must be initialized calls. The fields zalloc, zfree and opaque in strm must be initialized
...@@ -1091,13 +1094,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, ...@@ -1091,13 +1094,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
the version of the header file. the version of the header file.
*/ */
typedef unsigned (*in_func) OF((void FAR *, typedef unsigned (*in_func)(void FAR *,
z_const unsigned char FAR * FAR *)); z_const unsigned char FAR * FAR *);
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned);
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, ZEXTERN int ZEXPORT inflateBack(z_streamp strm,
in_func in, void FAR *in_desc, in_func in, void FAR *in_desc,
out_func out, void FAR *out_desc)); out_func out, void FAR *out_desc);
/* /*
inflateBack() does a raw inflate with a single call using a call-back inflateBack() does a raw inflate with a single call using a call-back
interface for input and output. This is potentially more efficient than interface for input and output. This is potentially more efficient than
...@@ -1165,7 +1168,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, ...@@ -1165,7 +1168,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
cannot return Z_OK. cannot return Z_OK.
*/ */
ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm);
/* /*
All memory allocated by inflateBackInit() is freed. All memory allocated by inflateBackInit() is freed.
...@@ -1173,7 +1176,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); ...@@ -1173,7 +1176,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
state was inconsistent. state was inconsistent.
*/ */
ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); ZEXTERN uLong ZEXPORT zlibCompileFlags(void);
/* Return flags indicating compile-time options. /* Return flags indicating compile-time options.
Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
...@@ -1226,8 +1229,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); ...@@ -1226,8 +1229,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
you need special options. you need special options.
*/ */
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen)); const Bytef *source, uLong sourceLen);
/* /*
Compresses the source buffer into the destination buffer. sourceLen is Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total size the byte length of the source buffer. Upon entry, destLen is the total size
...@@ -1241,9 +1244,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, ...@@ -1241,9 +1244,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
buffer. buffer.
*/ */
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen, const Bytef *source, uLong sourceLen,
int level)); int level);
/* /*
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
...@@ -1257,15 +1260,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, ...@@ -1257,15 +1260,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen);
/* /*
compressBound() returns an upper bound on the compressed size after compressBound() returns an upper bound on the compressed size after
compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() on sourceLen bytes. It would be used before a
compress() or compress2() call to allocate the destination buffer. compress() or compress2() call to allocate the destination buffer.
*/ */
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen)); const Bytef *source, uLong sourceLen);
/* /*
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 size the byte length of the source buffer. Upon entry, destLen is the total size
...@@ -1282,8 +1285,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, ...@@ -1282,8 +1285,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
buffer with the uncompressed data up to that point. buffer with the uncompressed data up to that point.
*/ */
ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen,
const Bytef *source, uLong *sourceLen)); const Bytef *source, uLong *sourceLen);
/* /*
Same as uncompress, except that sourceLen is a pointer, where the Same as uncompress, except that sourceLen is a pointer, where the
length of the source is *sourceLen. On return, *sourceLen is the number of length of the source is *sourceLen. On return, *sourceLen is the number of
...@@ -1302,7 +1305,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, ...@@ -1302,7 +1305,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/* /*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
Open the gzip (.gz) file at path for reading and decompressing, or Open the gzip (.gz) file at path for reading and decompressing, or
compressing and writing. The mode parameter is as in fopen ("rb" or "wb") compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
...@@ -1339,7 +1342,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); ...@@ -1339,7 +1342,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
file could not be opened. file could not be opened.
*/ */
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode);
/* /*
Associate a gzFile with the file descriptor fd. File descriptors are Associate a gzFile with the file descriptor fd. File descriptors are
obtained from calls like open, dup, creat, pipe or fileno (if the file has obtained from calls like open, dup, creat, pipe or fileno (if the file has
...@@ -1362,7 +1365,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); ...@@ -1362,7 +1365,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
will not detect if fd is invalid (unless fd is -1). will not detect if fd is invalid (unless fd is -1).
*/ */
ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size);
/* /*
Set the internal buffer size used by this library's functions for file to Set the internal buffer size used by this library's functions for file to
size. The default buffer size is 8192 bytes. This function must be called size. The default buffer size is 8192 bytes. This function must be called
...@@ -1378,7 +1381,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); ...@@ -1378,7 +1381,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
too late. too late.
*/ */
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy);
/* /*
Dynamically update the compression level and strategy for file. See the Dynamically update the compression level and strategy for file. See the
description of deflateInit2 for the meaning of these parameters. Previously description of deflateInit2 for the meaning of these parameters. Previously
...@@ -1389,7 +1392,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); ...@@ -1389,7 +1392,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
or Z_MEM_ERROR if there is a memory allocation error. or Z_MEM_ERROR if there is a memory allocation error.
*/ */
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len);
/* /*
Read and decompress up to len uncompressed bytes from file into buf. If Read and decompress up to len uncompressed bytes from file into buf. If
the input file is not in gzip format, gzread copies the given number of the input file is not in gzip format, gzread copies the given number of
...@@ -1419,8 +1422,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); ...@@ -1419,8 +1422,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
Z_STREAM_ERROR. Z_STREAM_ERROR.
*/ */
ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
gzFile file)); gzFile file);
/* /*
Read and decompress up to nitems items of size size from file into buf, Read and decompress up to nitems items of size size from file into buf,
otherwise operating as gzread() does. This duplicates the interface of otherwise operating as gzread() does. This duplicates the interface of
...@@ -1437,22 +1440,22 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, ...@@ -1437,22 +1440,22 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
In the event that the end of file is reached and only a partial item is In the event that the end of file is reached and only a partial item is
available at the end, i.e. the remaining uncompressed data length is not a available at the end, i.e. the remaining uncompressed data length is not a
multiple of size, then the final partial item is nevetheless read into buf multiple of size, then the final partial item is nevertheless read into buf
and the end-of-file flag is set. The length of the partial item read is not and the end-of-file flag is set. The length of the partial item read is not
provided, but could be inferred from the result of gztell(). This behavior provided, but could be inferred from the result of gztell(). This behavior
is the same as the behavior of fread() implementations in common libraries, is the same as the behavior of fread() implementations in common libraries,
but it prevents the direct use of gzfread() to read a concurrently written but it prevents the direct use of gzfread() to read a concurrently written
file, reseting and retrying on end-of-file, when size is not 1. file, resetting and retrying on end-of-file, when size is not 1.
*/ */
ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len);
/* /*
Compress and write the len uncompressed bytes at buf to file. gzwrite Compress and write the len uncompressed bytes at buf to file. gzwrite
returns the number of uncompressed bytes written or 0 in case of error. returns the number of uncompressed bytes written or 0 in case of error.
*/ */
ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
z_size_t nitems, gzFile file)); z_size_t nitems, gzFile file);
/* /*
Compress and write nitems items of size size from buf to file, duplicating Compress and write nitems items of size size from buf to file, duplicating
the interface of stdio's fwrite(), with size_t request and return types. If the interface of stdio's fwrite(), with size_t request and return types. If
...@@ -1465,7 +1468,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, ...@@ -1465,7 +1468,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
is returned, and the error state is set to Z_STREAM_ERROR. is returned, and the error state is set to Z_STREAM_ERROR.
*/ */
ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
/* /*
Convert, format, compress, and write the arguments (...) to file under Convert, format, compress, and write the arguments (...) to file under
control of the string format, as in fprintf. gzprintf returns the number of control of the string format, as in fprintf. gzprintf returns the number of
...@@ -1480,7 +1483,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); ...@@ -1480,7 +1483,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
This can be determined using zlibCompileFlags(). This can be determined using zlibCompileFlags().
*/ */
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
/* /*
Compress and write the given null-terminated string s to file, excluding Compress and write the given null-terminated string s to file, excluding
the terminating null character. the terminating null character.
...@@ -1488,7 +1491,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); ...@@ -1488,7 +1491,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
gzputs returns the number of characters written, or -1 in case of error. gzputs returns the number of characters written, or -1 in case of error.
*/ */
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
/* /*
Read and decompress bytes from file into buf, until len-1 characters are Read and decompress bytes from file into buf, until len-1 characters are
read, or until a newline character is read and transferred to buf, or an read, or until a newline character is read and transferred to buf, or an
...@@ -1502,13 +1505,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); ...@@ -1502,13 +1505,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
buf are indeterminate. buf are indeterminate.
*/ */
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); ZEXTERN int ZEXPORT gzputc(gzFile file, int c);
/* /*
Compress and write c, converted to an unsigned char, into file. gzputc Compress and write c, converted to an unsigned char, into file. gzputc
returns the value that was written, or -1 in case of error. returns the value that was written, or -1 in case of error.
*/ */
ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); ZEXTERN int ZEXPORT gzgetc(gzFile file);
/* /*
Read and decompress one byte from file. gzgetc returns this byte or -1 Read and decompress one byte from file. gzgetc returns this byte or -1
in case of end of file or error. This is implemented as a macro for speed. in case of end of file or error. This is implemented as a macro for speed.
...@@ -1517,7 +1520,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); ...@@ -1517,7 +1520,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
points to has been clobbered or not. points to has been clobbered or not.
*/ */
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
/* /*
Push c back onto the stream for file to be read as the first character on Push c back onto the stream for file to be read as the first character on
the next read. At least one character of push-back is always allowed. the next read. At least one character of push-back is always allowed.
...@@ -1529,7 +1532,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); ...@@ -1529,7 +1532,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
gzseek() or gzrewind(). gzseek() or gzrewind().
*/ */
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); ZEXTERN int ZEXPORT gzflush(gzFile file, int flush);
/* /*
Flush all pending output to file. The parameter flush is as in the Flush all pending output to file. The parameter flush is as in the
deflate() function. The return value is the zlib error number (see function deflate() function. The return value is the zlib error number (see function
...@@ -1545,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); ...@@ -1545,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
z_off_t offset, int whence)); z_off_t offset, int whence);
Set the starting position to offset relative to whence for the next gzread Set the starting position to offset relative to whence for the next gzread
or gzwrite on file. The offset represents a number of bytes in the or gzwrite on file. The offset represents a number of bytes in the
...@@ -1564,7 +1567,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, ...@@ -1564,7 +1567,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
would be before the current position. would be before the current position.
*/ */
ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); ZEXTERN int ZEXPORT gzrewind(gzFile file);
/* /*
Rewind file. This function is supported only for reading. Rewind file. This function is supported only for reading.
...@@ -1572,7 +1575,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); ...@@ -1572,7 +1575,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); ZEXTERN z_off_t ZEXPORT gztell(gzFile file);
Return the starting position for the next gzread or gzwrite on file. Return the starting position for the next gzread or gzwrite on file.
This position represents a number of bytes in the uncompressed data stream, This position represents a number of bytes in the uncompressed data stream,
...@@ -1583,7 +1586,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); ...@@ -1583,7 +1586,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file);
Return the current compressed (actual) read or write offset of file. This Return the current compressed (actual) read or write offset of file. This
offset includes the count of bytes that precede the gzip stream, for example offset includes the count of bytes that precede the gzip stream, for example
...@@ -1592,7 +1595,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); ...@@ -1592,7 +1595,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
be used for a progress indicator. On error, gzoffset() returns -1. be used for a progress indicator. On error, gzoffset() returns -1.
*/ */
ZEXTERN int ZEXPORT gzeof OF((gzFile file)); ZEXTERN int ZEXPORT gzeof(gzFile file);
/* /*
Return true (1) if the end-of-file indicator for file has been set while Return true (1) if the end-of-file indicator for file has been set while
reading, false (0) otherwise. Note that the end-of-file indicator is set reading, false (0) otherwise. Note that the end-of-file indicator is set
...@@ -1607,7 +1610,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); ...@@ -1607,7 +1610,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
has grown since the previous end of file was detected. has grown since the previous end of file was detected.
*/ */
ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); ZEXTERN int ZEXPORT gzdirect(gzFile file);
/* /*
Return true (1) if file is being copied directly while reading, or false Return true (1) if file is being copied directly while reading, or false
(0) if file is a gzip stream being decompressed. (0) if file is a gzip stream being decompressed.
...@@ -1628,7 +1631,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); ...@@ -1628,7 +1631,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
gzip file reading and decompression, which may not be desired.) gzip file reading and decompression, which may not be desired.)
*/ */
ZEXTERN int ZEXPORT gzclose OF((gzFile file)); ZEXTERN int ZEXPORT gzclose(gzFile file);
/* /*
Flush all pending output for file, if necessary, close file and Flush all pending output for file, if necessary, close file and
deallocate the (de)compression state. Note that once file is closed, you deallocate the (de)compression state. Note that once file is closed, you
...@@ -1641,8 +1644,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); ...@@ -1641,8 +1644,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
last read ended in the middle of a gzip stream, or Z_OK on success. last read ended in the middle of a gzip stream, or Z_OK on success.
*/ */
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); ZEXTERN int ZEXPORT gzclose_r(gzFile file);
ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); ZEXTERN int ZEXPORT gzclose_w(gzFile file);
/* /*
Same as gzclose(), but gzclose_r() is only for use when reading, and Same as gzclose(), but gzclose_r() is only for use when reading, and
gzclose_w() is only for use when writing or appending. The advantage to gzclose_w() is only for use when writing or appending. The advantage to
...@@ -1653,7 +1656,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); ...@@ -1653,7 +1656,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
zlib library. zlib library.
*/ */
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
/* /*
Return the error message for the last error which occurred on file. Return the error message for the last error which occurred on file.
errnum is set to zlib error number. If an error occurred in the file system errnum is set to zlib error number. If an error occurred in the file system
...@@ -1669,7 +1672,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); ...@@ -1669,7 +1672,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
functions above that do not distinguish those cases in their return values. functions above that do not distinguish those cases in their return values.
*/ */
ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); ZEXTERN void ZEXPORT gzclearerr(gzFile file);
/* /*
Clear the error and end-of-file flags for file. This is analogous to the Clear the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip clearerr() function in stdio. This is useful for continuing to read a gzip
...@@ -1686,7 +1689,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); ...@@ -1686,7 +1689,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
library. library.
*/ */
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len);
/* /*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. An Adler-32 value is in the range of a 32-bit return the updated checksum. An Adler-32 value is in the range of a 32-bit
...@@ -1706,15 +1709,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); ...@@ -1706,15 +1709,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
if (adler != original_adler) error(); if (adler != original_adler) error();
*/ */
ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf,
z_size_t len)); z_size_t len);
/* /*
Same as adler32(), but with a size_t length. Same as adler32(), but with a size_t length.
*/ */
/* /*
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2,
z_off_t len2)); z_off_t len2);
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
...@@ -1724,7 +1727,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, ...@@ -1724,7 +1727,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
negative, the result has no meaning or utility. negative, the result has no meaning or utility.
*/ */
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len);
/* /*
Update a running CRC-32 with the bytes buf[0..len-1] and return the Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
...@@ -1742,14 +1745,14 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); ...@@ -1742,14 +1745,14 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
if (crc != original_crc) error(); if (crc != original_crc) error();
*/ */
ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf,
z_size_t len)); z_size_t len);
/* /*
Same as crc32(), but with a size_t length. Same as crc32(), but with a size_t length.
*/ */
/* /*
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
Combine two CRC-32 check values into one. For two sequences of bytes, Combine two CRC-32 check values into one. For two sequences of bytes,
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
...@@ -1759,13 +1762,13 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); ...@@ -1759,13 +1762,13 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
*/ */
/* /*
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2);
Return the operator corresponding to length len2, to be used with Return the operator corresponding to length len2, to be used with
crc32_combine_op(). crc32_combine_op().
*/ */
ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
/* /*
Give the same result as crc32_combine(), using op in place of len2. op is Give the same result as crc32_combine(), using op in place of len2. op is
is generated from len2 by crc32_combine_gen(). This will be faster than is generated from len2 by crc32_combine_gen(). This will be faster than
...@@ -1778,20 +1781,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); ...@@ -1778,20 +1781,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op));
/* deflateInit and inflateInit are macros to allow checking the zlib version /* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream: * and the compiler's view of z_stream:
*/ */
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level,
const char *version, int stream_size)); const char *version, int stream_size);
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, ZEXTERN int ZEXPORT inflateInit_(z_streamp strm,
const char *version, int stream_size)); const char *version, int stream_size);
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
int windowBits, int memLevel, int windowBits, int memLevel,
int strategy, const char *version, int strategy, const char *version,
int stream_size)); int stream_size);
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
const char *version, int stream_size)); const char *version, int stream_size);
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
unsigned char FAR *window, unsigned char FAR *window,
const char *version, const char *version,
int stream_size)); int stream_size);
#ifdef Z_PREFIX_SET #ifdef Z_PREFIX_SET
# define z_deflateInit(strm, level) \ # define z_deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
...@@ -1836,7 +1839,7 @@ struct gzFile_s { ...@@ -1836,7 +1839,7 @@ struct gzFile_s {
unsigned char *next; unsigned char *next;
z_off64_t pos; z_off64_t pos;
}; };
ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
#ifdef Z_PREFIX_SET #ifdef Z_PREFIX_SET
# undef z_gzgetc # undef z_gzgetc
# define z_gzgetc(g) \ # define z_gzgetc(g) \
...@@ -1853,13 +1856,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ ...@@ -1853,13 +1856,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
* without large file support, _LFS64_LARGEFILE must also be true * without large file support, _LFS64_LARGEFILE must also be true
*/ */
#ifdef Z_LARGE64 #ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
#endif #endif
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
...@@ -1881,53 +1884,50 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ ...@@ -1881,53 +1884,50 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# define crc32_combine_gen crc32_combine_gen64 # define crc32_combine_gen crc32_combine_gen64
# endif # endif
# ifndef Z_LARGE64 # ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int);
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile);
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
# endif # endif
#else #else
ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *);
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int);
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); ZEXTERN z_off_t ZEXPORT gztell(gzFile);
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); ZEXTERN z_off_t ZEXPORT gzoffset(gzFile);
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t));
#endif #endif
#else /* Z_SOLO */ #else /* Z_SOLO */
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
#endif /* !Z_SOLO */ #endif /* !Z_SOLO */
/* undocumented functions */ /* undocumented functions */
ZEXTERN const char * ZEXPORT zError OF((int)); ZEXTERN const char * ZEXPORT zError(int);
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp);
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void);
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int);
ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); ZEXTERN int ZEXPORT inflateValidate(z_streamp, int);
ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp);
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); ZEXTERN int ZEXPORT inflateResetKeep(z_streamp);
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); ZEXTERN int ZEXPORT deflateResetKeep(z_streamp);
#if defined(_WIN32) && !defined(Z_SOLO) #if defined(_WIN32) && !defined(Z_SOLO)
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path,
const char *mode)); const char *mode);
#endif #endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H) #if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO # ifndef Z_SOLO
ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, ZEXTERN int ZEXPORTVA gzvprintf(gzFile file,
const char *format, const char *format,
va_list va)); va_list va);
# endif # endif
#endif #endif
......
...@@ -24,13 +24,11 @@ z_const char * const z_errmsg[10] = { ...@@ -24,13 +24,11 @@ z_const char * const z_errmsg[10] = {
}; };
const char * ZEXPORT zlibVersion() const char * ZEXPORT zlibVersion(void) {
{
return ZLIB_VERSION; return ZLIB_VERSION;
} }
uLong ZEXPORT zlibCompileFlags() uLong ZEXPORT zlibCompileFlags(void) {
{
uLong flags; uLong flags;
flags = 0; flags = 0;
...@@ -61,9 +59,11 @@ uLong ZEXPORT zlibCompileFlags() ...@@ -61,9 +59,11 @@ uLong ZEXPORT zlibCompileFlags()
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
flags += 1 << 8; flags += 1 << 8;
#endif #endif
/*
#if defined(ASMV) || defined(ASMINF) #if defined(ASMV) || defined(ASMINF)
flags += 1 << 9; flags += 1 << 9;
#endif #endif
*/
#ifdef ZLIB_WINAPI #ifdef ZLIB_WINAPI
flags += 1 << 10; flags += 1 << 10;
#endif #endif
...@@ -119,9 +119,7 @@ uLong ZEXPORT zlibCompileFlags() ...@@ -119,9 +119,7 @@ uLong ZEXPORT zlibCompileFlags()
# endif # endif
int ZLIB_INTERNAL z_verbose = verbose; int ZLIB_INTERNAL z_verbose = verbose;
void ZLIB_INTERNAL z_error (m) void ZLIB_INTERNAL z_error(char *m) {
char *m;
{
fprintf(stderr, "%s\n", m); fprintf(stderr, "%s\n", m);
exit(1); exit(1);
} }
...@@ -130,9 +128,7 @@ void ZLIB_INTERNAL z_error (m) ...@@ -130,9 +128,7 @@ void ZLIB_INTERNAL z_error (m)
/* exported to allow conversion of error code to string for compress() and /* exported to allow conversion of error code to string for compress() and
* uncompress() * uncompress()
*/ */
const char * ZEXPORT zError(err) const char * ZEXPORT zError(int err) {
int err;
{
return ERR_MSG(err); return ERR_MSG(err);
} }
...@@ -146,22 +142,14 @@ const char * ZEXPORT zError(err) ...@@ -146,22 +142,14 @@ const char * ZEXPORT zError(err)
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void ZLIB_INTERNAL zmemcpy(dest, source, len) void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
Bytef* dest;
const Bytef* source;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = *source++; /* ??? to be unrolled */ *dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0); } while (--len != 0);
} }
int ZLIB_INTERNAL zmemcmp(s1, s2, len) int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j; uInt j;
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
...@@ -170,10 +158,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len) ...@@ -170,10 +158,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len)
return 0; return 0;
} }
void ZLIB_INTERNAL zmemzero(dest, len) void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
Bytef* dest;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = 0; /* ??? to be unrolled */ *dest++ = 0; /* ??? to be unrolled */
...@@ -214,8 +199,7 @@ local ptr_table table[MAX_PTR]; ...@@ -214,8 +199,7 @@ local ptr_table table[MAX_PTR];
* a protected system like OS/2. Use Microsoft C instead. * a protected system like OS/2. Use Microsoft C instead.
*/ */
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
{
voidpf buf; voidpf buf;
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
...@@ -240,8 +224,7 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) ...@@ -240,8 +224,7 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
return buf; return buf;
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{
int n; int n;
(void)opaque; (void)opaque;
...@@ -277,14 +260,12 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) ...@@ -277,14 +260,12 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
# define _hfree hfree # define _hfree hfree
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
{
(void)opaque; (void)opaque;
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{
(void)opaque; (void)opaque;
_hfree(ptr); _hfree(ptr);
} }
...@@ -297,25 +278,18 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) ...@@ -297,25 +278,18 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc(uInt items, uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
voidpf opaque;
unsigned items;
unsigned size;
{
(void)opaque; (void)opaque;
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size); (voidpf)calloc(items, size);
} }
void ZLIB_INTERNAL zcfree (opaque, ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
voidpf opaque;
voidpf ptr;
{
(void)opaque; (void)opaque;
free(ptr); free(ptr);
} }
......
...@@ -191,8 +191,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ ...@@ -191,8 +191,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_WIN32) && \ #if !defined(_WIN32) && \
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
#endif #endif
/* common defaults */ /* common defaults */
...@@ -231,16 +232,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ ...@@ -231,16 +232,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define zmemzero(dest, len) memset(dest, 0, len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
# include <stdio.h> # include <stdio.h>
extern int ZLIB_INTERNAL z_verbose; extern int ZLIB_INTERNAL z_verbose;
extern void ZLIB_INTERNAL z_error OF((char *m)); extern void ZLIB_INTERNAL z_error(char *m);
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;}
...@@ -257,9 +258,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ ...@@ -257,9 +258,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
unsigned size)); unsigned size);
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
#endif #endif
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment