Update to zlib 1.3.2 (#852)
This commit is contained in:
@@ -1,16 +1,13 @@
|
|||||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||||
* Copyright (C) 1995-2011 Mark Adler
|
* Copyright (C) 1995-2011, 2016 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
#include "zutil.h"
|
#include "zutil.h"
|
||||||
|
|
||||||
#define local static
|
#define BASE 65521U /* largest prime smaller than 65536 */
|
||||||
|
|
||||||
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
|
||||||
|
|
||||||
#define BASE 65521 /* 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 */
|
||||||
|
|
||||||
@@ -61,11 +58,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
uLong ZEXPORT adler32(adler, buf, len)
|
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
|
||||||
uLong adler;
|
|
||||||
const Bytef *buf;
|
|
||||||
uInt len;
|
|
||||||
{
|
|
||||||
unsigned long sum2;
|
unsigned long sum2;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
@@ -132,11 +125,12 @@ uLong ZEXPORT adler32(adler, buf, len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
local uLong adler32_combine_(adler1, adler2, len2)
|
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
|
||||||
uLong adler1;
|
return adler32_z(adler, buf, len);
|
||||||
uLong adler2;
|
}
|
||||||
z_off64_t len2;
|
|
||||||
{
|
/* ========================================================================= */
|
||||||
|
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||||
unsigned long sum1;
|
unsigned long sum1;
|
||||||
unsigned long sum2;
|
unsigned long sum2;
|
||||||
unsigned rem;
|
unsigned rem;
|
||||||
@@ -155,24 +149,16 @@ local uLong adler32_combine_(adler1, adler2, len2)
|
|||||||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||||
if (sum1 >= BASE) sum1 -= BASE;
|
if (sum1 >= BASE) sum1 -= BASE;
|
||||||
if (sum1 >= BASE) sum1 -= BASE;
|
if (sum1 >= BASE) sum1 -= BASE;
|
||||||
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
|
if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
|
||||||
if (sum2 >= BASE) sum2 -= BASE;
|
if (sum2 >= BASE) sum2 -= BASE;
|
||||||
return sum1 | (sum2 << 16);
|
return sum1 | (sum2 << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* compress.c -- compress a memory buffer
|
/* compress.c -- compress a memory buffer
|
||||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
* Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -18,26 +18,22 @@
|
|||||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||||
Z_STREAM_ERROR if the level parameter is invalid.
|
Z_STREAM_ERROR if the level parameter is invalid.
|
||||||
|
|
||||||
|
The _z versions of the functions take size_t length arguments.
|
||||||
*/
|
*/
|
||||||
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
int ZEXPORT compress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
|
||||||
Bytef *dest;
|
z_size_t sourceLen, int level) {
|
||||||
uLongf *destLen;
|
|
||||||
const Bytef *source;
|
|
||||||
uLong sourceLen;
|
|
||||||
int level;
|
|
||||||
{
|
|
||||||
z_stream stream;
|
z_stream stream;
|
||||||
int err;
|
int err;
|
||||||
|
const uInt max = (uInt)-1;
|
||||||
|
z_size_t left;
|
||||||
|
|
||||||
stream.next_in = (z_const Bytef *)source;
|
if ((sourceLen > 0 && source == NULL) ||
|
||||||
stream.avail_in = (uInt)sourceLen;
|
destLen == NULL || (*destLen > 0 && dest == NULL))
|
||||||
#ifdef MAXSEG_64K
|
return Z_STREAM_ERROR;
|
||||||
/* Check for source > 64K on 16-bit machine: */
|
|
||||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
left = *destLen;
|
||||||
#endif
|
*destLen = 0;
|
||||||
stream.next_out = dest;
|
|
||||||
stream.avail_out = (uInt)*destLen;
|
|
||||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
|
||||||
|
|
||||||
stream.zalloc = (alloc_func)0;
|
stream.zalloc = (alloc_func)0;
|
||||||
stream.zfree = (free_func)0;
|
stream.zfree = (free_func)0;
|
||||||
@@ -46,36 +42,58 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
|||||||
err = deflateInit(&stream, level);
|
err = deflateInit(&stream, level);
|
||||||
if (err != Z_OK) return err;
|
if (err != Z_OK) return err;
|
||||||
|
|
||||||
err = deflate(&stream, Z_FINISH);
|
stream.next_out = dest;
|
||||||
if (err != Z_STREAM_END) {
|
stream.avail_out = 0;
|
||||||
deflateEnd(&stream);
|
stream.next_in = (z_const Bytef *)source;
|
||||||
return err == Z_OK ? Z_BUF_ERROR : err;
|
stream.avail_in = 0;
|
||||||
}
|
|
||||||
*destLen = stream.total_out;
|
|
||||||
|
|
||||||
err = deflateEnd(&stream);
|
do {
|
||||||
return err;
|
if (stream.avail_out == 0) {
|
||||||
|
stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
|
||||||
|
left -= stream.avail_out;
|
||||||
|
}
|
||||||
|
if (stream.avail_in == 0) {
|
||||||
|
stream.avail_in = sourceLen > (z_size_t)max ? max :
|
||||||
|
(uInt)sourceLen;
|
||||||
|
sourceLen -= stream.avail_in;
|
||||||
|
}
|
||||||
|
err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
|
||||||
|
} while (err == Z_OK);
|
||||||
|
|
||||||
|
*destLen = (z_size_t)(stream.next_out - dest);
|
||||||
|
deflateEnd(&stream);
|
||||||
|
return err == Z_STREAM_END ? Z_OK : err;
|
||||||
|
}
|
||||||
|
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||||
|
uLong sourceLen, int level) {
|
||||||
|
int ret;
|
||||||
|
z_size_t got = *destLen;
|
||||||
|
ret = compress2_z(dest, &got, source, sourceLen, level);
|
||||||
|
*destLen = (uLong)got;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
*/
|
*/
|
||||||
int ZEXPORT compress (dest, destLen, source, sourceLen)
|
int ZEXPORT compress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
|
||||||
Bytef *dest;
|
z_size_t sourceLen) {
|
||||||
uLongf *destLen;
|
return compress2_z(dest, destLen, source, sourceLen,
|
||||||
const Bytef *source;
|
Z_DEFAULT_COMPRESSION);
|
||||||
uLong sourceLen;
|
}
|
||||||
{
|
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||||
|
uLong sourceLen) {
|
||||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
If the default memLevel or windowBits for deflateInit() is changed, then
|
If the default memLevel or windowBits for deflateInit() is changed, then
|
||||||
this function needs to be updated.
|
this function needs to be updated.
|
||||||
*/
|
*/
|
||||||
uLong ZEXPORT compressBound (sourceLen)
|
z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) {
|
||||||
uLong sourceLen;
|
z_size_t bound = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||||
{
|
(sourceLen >> 25) + 13;
|
||||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
return bound < sourceLen ? (z_size_t)-1 : bound;
|
||||||
(sourceLen >> 25) + 13;
|
}
|
||||||
|
uLong ZEXPORT compressBound(uLong sourceLen) {
|
||||||
|
z_size_t bound = compressBound_z(sourceLen);
|
||||||
|
return (uLong)bound != bound ? (uLong)-1 : (uLong)bound;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/* deflate.h -- internal compression state
|
/* deflate.h -- internal compression state
|
||||||
* Copyright (C) 1995-2012 Jean-loup Gailly
|
* Copyright (C) 1995-2026 Jean-loup Gailly
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -23,6 +23,10 @@
|
|||||||
# define GZIP
|
# define GZIP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
|
||||||
|
the cost of a larger memory footprint */
|
||||||
|
/* #define LIT_MEM */
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Internal compression state.
|
* Internal compression state.
|
||||||
*/
|
*/
|
||||||
@@ -51,13 +55,16 @@
|
|||||||
#define Buf_size 16
|
#define Buf_size 16
|
||||||
/* size of bit buffer in bi_buf */
|
/* size of bit buffer in bi_buf */
|
||||||
|
|
||||||
#define INIT_STATE 42
|
#define INIT_STATE 42 /* zlib header -> BUSY_STATE */
|
||||||
#define EXTRA_STATE 69
|
#ifdef GZIP
|
||||||
#define NAME_STATE 73
|
# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
|
||||||
#define COMMENT_STATE 91
|
#endif
|
||||||
#define HCRC_STATE 103
|
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
|
||||||
#define BUSY_STATE 113
|
#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
|
||||||
#define FINISH_STATE 666
|
#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
|
||||||
|
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
|
||||||
|
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
|
||||||
|
#define FINISH_STATE 666 /* stream complete */
|
||||||
/* Stream status */
|
/* Stream status */
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +90,7 @@ typedef struct static_tree_desc_s static_tree_desc;
|
|||||||
typedef struct tree_desc_s {
|
typedef struct tree_desc_s {
|
||||||
ct_data *dyn_tree; /* the dynamic tree */
|
ct_data *dyn_tree; /* the dynamic tree */
|
||||||
int max_code; /* largest code with non zero frequency */
|
int max_code; /* largest code with non zero frequency */
|
||||||
static_tree_desc *stat_desc; /* the corresponding static tree */
|
const static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||||
} FAR tree_desc;
|
} FAR tree_desc;
|
||||||
|
|
||||||
typedef ush Pos;
|
typedef ush Pos;
|
||||||
@@ -100,10 +107,10 @@ typedef struct internal_state {
|
|||||||
Bytef *pending_buf; /* output still pending */
|
Bytef *pending_buf; /* output still pending */
|
||||||
ulg pending_buf_size; /* size of pending_buf */
|
ulg pending_buf_size; /* size of pending_buf */
|
||||||
Bytef *pending_out; /* next pending byte to output to the stream */
|
Bytef *pending_out; /* next pending byte to output to the stream */
|
||||||
uInt pending; /* nb of bytes in the pending buffer */
|
ulg pending; /* nb of bytes in the pending buffer */
|
||||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||||
gz_headerp gzhead; /* gzip header information to write */
|
gz_headerp gzhead; /* gzip header information to write */
|
||||||
uInt gzindex; /* where in extra, name, or comment */
|
ulg gzindex; /* where in extra, name, or comment */
|
||||||
Byte method; /* can only be DEFLATED */
|
Byte method; /* can only be DEFLATED */
|
||||||
int last_flush; /* value of flush param for previous deflate call */
|
int last_flush; /* value of flush param for previous deflate call */
|
||||||
|
|
||||||
@@ -214,7 +221,14 @@ typedef struct internal_state {
|
|||||||
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uchf *l_buf; /* buffer for literals or lengths */
|
#ifdef LIT_MEM
|
||||||
|
# define LIT_BUFS 5
|
||||||
|
ushf *d_buf; /* buffer for distances */
|
||||||
|
uchf *l_buf; /* buffer for literals/lengths */
|
||||||
|
#else
|
||||||
|
# define LIT_BUFS 4
|
||||||
|
uchf *sym_buf; /* buffer for distances and literals/lengths */
|
||||||
|
#endif
|
||||||
|
|
||||||
uInt lit_bufsize;
|
uInt lit_bufsize;
|
||||||
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
||||||
@@ -236,20 +250,15 @@ typedef struct internal_state {
|
|||||||
* - I can't count above 4
|
* - I can't count above 4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uInt last_lit; /* running index in l_buf */
|
uInt sym_next; /* running index in symbol buffer */
|
||||||
|
uInt sym_end; /* symbol table full when sym_next reaches this */
|
||||||
ushf *d_buf;
|
|
||||||
/* Buffer for distances. To simplify the code, d_buf and l_buf have
|
|
||||||
* the same number of elements. To use different lengths, an extra flag
|
|
||||||
* array would be necessary.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ulg opt_len; /* bit length of current block with optimal trees */
|
ulg opt_len; /* bit length of current block with optimal trees */
|
||||||
ulg static_len; /* bit length of current block with static trees */
|
ulg static_len; /* bit length of current block with static trees */
|
||||||
uInt matches; /* number of string matches in current block */
|
uInt matches; /* number of string matches in current block */
|
||||||
uInt insert; /* bytes at end of window left to insert */
|
uInt insert; /* bytes at end of window left to insert */
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef ZLIB_DEBUG
|
||||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||||
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||||
#endif
|
#endif
|
||||||
@@ -262,6 +271,9 @@ typedef struct internal_state {
|
|||||||
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
||||||
* are always zero.
|
* are always zero.
|
||||||
*/
|
*/
|
||||||
|
int bi_used;
|
||||||
|
/* Last number of used bits when going to a byte boundary.
|
||||||
|
*/
|
||||||
|
|
||||||
ulg high_water;
|
ulg high_water;
|
||||||
/* High water mark offset in window for initialized bytes -- bytes above
|
/* High water mark offset in window for initialized bytes -- bytes above
|
||||||
@@ -270,12 +282,15 @@ typedef struct internal_state {
|
|||||||
* updated to the new high water mark.
|
* updated to the new high water mark.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int slid;
|
||||||
|
/* True if the hash table has been slid since it was cleared. */
|
||||||
|
|
||||||
} FAR deflate_state;
|
} FAR deflate_state;
|
||||||
|
|
||||||
/* Output a byte on the stream.
|
/* Output a byte on the stream.
|
||||||
* IN assertion: there is enough room in pending_buf.
|
* IN assertion: there is enough room in pending_buf.
|
||||||
*/
|
*/
|
||||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
|
#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
|
||||||
|
|
||||||
|
|
||||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||||
@@ -293,14 +308,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)])
|
||||||
@@ -309,7 +324,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
|||||||
* used.
|
* used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef ZLIB_DEBUG
|
||||||
/* Inline versions of _tr_tally for speed: */
|
/* Inline versions of _tr_tally for speed: */
|
||||||
|
|
||||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||||
@@ -320,24 +335,46 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
|||||||
extern const uch ZLIB_INTERNAL _dist_code[];
|
extern const uch ZLIB_INTERNAL _dist_code[];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LIT_MEM
|
||||||
# define _tr_tally_lit(s, c, flush) \
|
# define _tr_tally_lit(s, c, flush) \
|
||||||
{ uch cc = (c); \
|
{ uch cc = (c); \
|
||||||
s->d_buf[s->last_lit] = 0; \
|
s->d_buf[s->sym_next] = 0; \
|
||||||
s->l_buf[s->last_lit++] = cc; \
|
s->l_buf[s->sym_next++] = cc; \
|
||||||
s->dyn_ltree[cc].Freq++; \
|
s->dyn_ltree[cc].Freq++; \
|
||||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
flush = (s->sym_next == s->sym_end); \
|
||||||
}
|
}
|
||||||
# define _tr_tally_dist(s, distance, length, flush) \
|
# define _tr_tally_dist(s, distance, length, flush) \
|
||||||
{ uch len = (length); \
|
{ uch len = (uch)(length); \
|
||||||
ush dist = (distance); \
|
ush dist = (ush)(distance); \
|
||||||
s->d_buf[s->last_lit] = dist; \
|
s->d_buf[s->sym_next] = dist; \
|
||||||
s->l_buf[s->last_lit++] = len; \
|
s->l_buf[s->sym_next++] = len; \
|
||||||
dist--; \
|
dist--; \
|
||||||
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
flush = (s->sym_next == s->sym_end); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
# define _tr_tally_lit(s, c, flush) \
|
||||||
|
{ uch cc = (c); \
|
||||||
|
s->sym_buf[s->sym_next++] = 0; \
|
||||||
|
s->sym_buf[s->sym_next++] = 0; \
|
||||||
|
s->sym_buf[s->sym_next++] = cc; \
|
||||||
|
s->dyn_ltree[cc].Freq++; \
|
||||||
|
flush = (s->sym_next == s->sym_end); \
|
||||||
|
}
|
||||||
|
# define _tr_tally_dist(s, distance, length, flush) \
|
||||||
|
{ uch len = (uch)(length); \
|
||||||
|
ush dist = (ush)(distance); \
|
||||||
|
s->sym_buf[s->sym_next++] = (uch)dist; \
|
||||||
|
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
|
||||||
|
s->sym_buf[s->sym_next++] = len; \
|
||||||
|
dist--; \
|
||||||
|
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||||
|
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||||
|
flush = (s->sym_next == s->sym_end); \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||||
# define _tr_tally_dist(s, distance, length, flush) \
|
# define _tr_tally_dist(s, distance, length, flush) \
|
||||||
flush = _tr_tally(s, distance, length)
|
flush = _tr_tally(s, distance, length)
|
||||||
|
|||||||
@@ -8,9 +8,7 @@
|
|||||||
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
||||||
That way the other gzclose functions can be used instead to avoid linking in
|
That way the other gzclose functions can be used instead to avoid linking in
|
||||||
unneeded compression or decompression routines. */
|
unneeded compression or decompression routines. */
|
||||||
int ZEXPORT gzclose(file)
|
int ZEXPORT gzclose(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
#ifndef NO_GZCOMPRESS
|
#ifndef NO_GZCOMPRESS
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* gzguts.h -- zlib internal header definitions for gz* operations
|
/* gzguts.h -- zlib internal header definitions for gz* operations
|
||||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
* Copyright (C) 2004-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -18,6 +17,18 @@
|
|||||||
# define ZLIB_INTERNAL
|
# define ZLIB_INTERNAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
# ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
# define WIN32_LEAN_AND_MEAN
|
||||||
|
# endif
|
||||||
|
# ifndef _CRT_SECURE_NO_WARNINGS
|
||||||
|
# define _CRT_SECURE_NO_WARNINGS
|
||||||
|
# endif
|
||||||
|
# ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||||
|
# define _CRT_NONSTDC_NO_DEPRECATE
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#ifdef STDC
|
#ifdef STDC
|
||||||
@@ -25,6 +36,10 @@
|
|||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _POSIX_C_SOURCE
|
||||||
|
# define _POSIX_C_SOURCE 200112L
|
||||||
|
#endif
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -33,13 +48,11 @@
|
|||||||
|
|
||||||
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WINAPI_FAMILY
|
#if defined(_WIN32) && !defined(WIDECHAR)
|
||||||
# define open _open
|
# define WIDECHAR
|
||||||
# define read _read
|
|
||||||
# define write _write
|
|
||||||
# define close _close
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
||||||
@@ -65,53 +78,49 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_VSNPRINTF
|
#ifndef HAVE_VSNPRINTF
|
||||||
# ifdef MSDOS
|
# if !defined(NO_vsnprintf) && \
|
||||||
|
(defined(MSDOS) || defined(__TURBOC__) || defined(__SASC) || \
|
||||||
|
defined(VMS) || defined(__OS400) || defined(__MVS__))
|
||||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||||
but for now we just assume it doesn't. */
|
but for now we just assume it doesn't. */
|
||||||
# define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
# endif
|
# endif
|
||||||
# ifdef __TURBOC__
|
|
||||||
# define NO_vsnprintf
|
|
||||||
# endif
|
|
||||||
# ifdef WIN32
|
# ifdef WIN32
|
||||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
# ifndef vsnprintf
|
||||||
# define vsnprintf _vsnprintf
|
# define vsnprintf _vsnprintf
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L
|
||||||
# ifdef __SASC
|
/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */
|
||||||
# define NO_vsnprintf
|
# ifndef NO_snprintf
|
||||||
# endif
|
# define NO_snprintf
|
||||||
# ifdef VMS
|
# endif
|
||||||
# define NO_vsnprintf
|
# ifndef NO_vsnprintf
|
||||||
# endif
|
# define NO_vsnprintf
|
||||||
# ifdef __OS400__
|
# endif
|
||||||
# define NO_vsnprintf
|
|
||||||
# endif
|
|
||||||
# ifdef __MVS__
|
|
||||||
# define NO_vsnprintf
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* unlike snprintf (which is required in C99, yet still not supported by
|
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
|
||||||
Microsoft more than a decade later!), _snprintf does not guarantee null
|
null termination of the result -- however this is only used in gzlib.c where
|
||||||
termination of the result -- however this is only used in gzlib.c where
|
|
||||||
the result is assured to fit in the space provided */
|
the result is assured to fit in the space provided */
|
||||||
#ifdef _MSC_VER
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
# define snprintf _snprintf
|
# define snprintf _snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef local
|
#ifndef local
|
||||||
# define local static
|
# define local static
|
||||||
#endif
|
#endif
|
||||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
/* since "static" is used to mean two completely different things in C, we
|
||||||
|
define "local" for the non-static meaning of "static", for readability
|
||||||
|
(compile with -Dlocal if your debugger can't find static symbols) */
|
||||||
|
|
||||||
/* gz* functions always use library allocation functions */
|
/* 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 */
|
||||||
@@ -129,10 +138,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 */
|
||||||
@@ -170,20 +179,22 @@ typedef struct {
|
|||||||
char *path; /* path or fd for error messages */
|
char *path; /* path or fd for error messages */
|
||||||
unsigned size; /* buffer size, zero if not allocated yet */
|
unsigned size; /* buffer size, zero if not allocated yet */
|
||||||
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
||||||
unsigned char *in; /* input buffer */
|
unsigned char *in; /* input buffer (double-sized when writing) */
|
||||||
unsigned char *out; /* output buffer (double-sized when reading) */
|
unsigned char *out; /* output buffer (double-sized when reading) */
|
||||||
int direct; /* 0 if processing gzip, 1 if transparent */
|
int direct; /* 0 if processing gzip, 1 if transparent */
|
||||||
/* just for reading */
|
/* just for reading */
|
||||||
|
int junk; /* -1 = start, 1 = junk candidate, 0 = in gzip */
|
||||||
int how; /* 0: get header, 1: copy, 2: decompress */
|
int how; /* 0: get header, 1: copy, 2: decompress */
|
||||||
|
int again; /* true if EAGAIN or EWOULDBLOCK on last i/o */
|
||||||
z_off64_t start; /* where the gzip data started, for rewinding */
|
z_off64_t start; /* where the gzip data started, for rewinding */
|
||||||
int eof; /* true if end of input file reached */
|
int eof; /* true if end of input file reached */
|
||||||
int past; /* true if read requested past end */
|
int past; /* true if read requested past end */
|
||||||
/* just for writing */
|
/* just for writing */
|
||||||
int level; /* compression level */
|
int level; /* compression level */
|
||||||
int strategy; /* compression strategy */
|
int strategy; /* compression strategy */
|
||||||
|
int reset; /* true if a reset is pending after a Z_FINISH */
|
||||||
/* seek request */
|
/* seek request */
|
||||||
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
||||||
int seek; /* true if seek request pending */
|
|
||||||
/* error information */
|
/* error information */
|
||||||
int err; /* error code */
|
int err; /* error code */
|
||||||
char *msg; /* error message */
|
char *msg; /* error message */
|
||||||
@@ -193,17 +204,13 @@ 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
|
||||||
value -- needed when comparing unsigned to z_off64_t, which is signed
|
value -- needed when comparing unsigned to z_off64_t, which is signed
|
||||||
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
||||||
#ifdef INT_MAX
|
unsigned ZLIB_INTERNAL gz_intmax(void);
|
||||||
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
||||||
#else
|
|
||||||
unsigned ZLIB_INTERNAL gz_intmax OF((void));
|
|
||||||
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
||||||
* Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
|
* Copyright (C) 2004-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gzguts.h"
|
#include "gzguts.h"
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__BORLANDC__)
|
#if defined(__DJGPP__)
|
||||||
|
# define LSEEK llseek
|
||||||
|
#elif defined(_WIN32) && !defined(__BORLANDC__) && !defined(UNDER_CE)
|
||||||
# define LSEEK _lseeki64
|
# define LSEEK _lseeki64
|
||||||
#else
|
#elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
|
||||||
# define LSEEK lseek64
|
# define LSEEK lseek64
|
||||||
#else
|
#else
|
||||||
# define LSEEK lseek
|
# define LSEEK lseek
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Local functions */
|
|
||||||
local void gz_reset OF((gz_statep));
|
|
||||||
local gzFile gz_open OF((const void *, int, const char *));
|
|
||||||
|
|
||||||
#if defined UNDER_CE
|
#if defined UNDER_CE
|
||||||
|
|
||||||
@@ -30,9 +26,7 @@ local gzFile gz_open OF((const void *, int, const char *));
|
|||||||
|
|
||||||
The gz_strwinerror function does not change the current setting of
|
The gz_strwinerror function does not change the current setting of
|
||||||
GetLastError. */
|
GetLastError. */
|
||||||
char ZLIB_INTERNAL *gz_strwinerror (error)
|
char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
|
||||||
DWORD error;
|
|
||||||
{
|
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
|
|
||||||
wchar_t *msgbuf;
|
wchar_t *msgbuf;
|
||||||
@@ -58,7 +52,7 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
|
|||||||
msgbuf[chars] = 0;
|
msgbuf[chars] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcstombs(buf, msgbuf, chars + 1);
|
wcstombs(buf, msgbuf, chars + 1); /* assumes buf is big enough */
|
||||||
LocalFree(msgbuf);
|
LocalFree(msgbuf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -72,39 +66,34 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
|
|||||||
#endif /* UNDER_CE */
|
#endif /* UNDER_CE */
|
||||||
|
|
||||||
/* Reset gzip file state */
|
/* Reset gzip file state */
|
||||||
local void gz_reset(state)
|
local void gz_reset(gz_statep state) {
|
||||||
gz_statep state;
|
|
||||||
{
|
|
||||||
state->x.have = 0; /* no output data available */
|
state->x.have = 0; /* no output data available */
|
||||||
if (state->mode == GZ_READ) { /* for reading ... */
|
if (state->mode == GZ_READ) { /* for reading ... */
|
||||||
state->eof = 0; /* not at end of file */
|
state->eof = 0; /* not at end of file */
|
||||||
state->past = 0; /* have not read past end yet */
|
state->past = 0; /* have not read past end yet */
|
||||||
state->how = LOOK; /* look for gzip header */
|
state->how = LOOK; /* look for gzip header */
|
||||||
|
state->junk = -1; /* mark first member */
|
||||||
}
|
}
|
||||||
state->seek = 0; /* no seek request pending */
|
else /* for writing ... */
|
||||||
|
state->reset = 0; /* no deflateReset pending */
|
||||||
|
state->again = 0; /* no stalled i/o yet */
|
||||||
|
state->skip = 0; /* no seek request pending */
|
||||||
gz_error(state, Z_OK, NULL); /* clear error */
|
gz_error(state, Z_OK, NULL); /* clear error */
|
||||||
state->x.pos = 0; /* no uncompressed data yet */
|
state->x.pos = 0; /* no uncompressed data yet */
|
||||||
state->strm.avail_in = 0; /* no input data yet */
|
state->strm.avail_in = 0; /* no input data yet */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open a gzip file either by name or file descriptor. */
|
/* Open a gzip file either by name or file descriptor. */
|
||||||
local gzFile gz_open(path, fd, mode)
|
local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||||
const void *path;
|
|
||||||
int fd;
|
|
||||||
const char *mode;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
size_t len;
|
z_size_t len;
|
||||||
int oflag;
|
int oflag = 0;
|
||||||
#ifdef O_CLOEXEC
|
|
||||||
int cloexec = 0;
|
|
||||||
#endif
|
|
||||||
#ifdef O_EXCL
|
#ifdef O_EXCL
|
||||||
int exclusive = 0;
|
int exclusive = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check input */
|
/* check input */
|
||||||
if (path == NULL)
|
if (path == NULL || mode == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* allocate gzFile structure to return */
|
/* allocate gzFile structure to return */
|
||||||
@@ -113,6 +102,7 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
return NULL;
|
return NULL;
|
||||||
state->size = 0; /* no buffers allocated yet */
|
state->size = 0; /* no buffers allocated yet */
|
||||||
state->want = GZBUFSIZE; /* requested buffer size */
|
state->want = GZBUFSIZE; /* requested buffer size */
|
||||||
|
state->err = Z_OK; /* no error yet */
|
||||||
state->msg = NULL; /* no error message yet */
|
state->msg = NULL; /* no error message yet */
|
||||||
|
|
||||||
/* interpret mode */
|
/* interpret mode */
|
||||||
@@ -143,7 +133,7 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
break;
|
break;
|
||||||
#ifdef O_CLOEXEC
|
#ifdef O_CLOEXEC
|
||||||
case 'e':
|
case 'e':
|
||||||
cloexec = 1;
|
oflag |= O_CLOEXEC;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef O_EXCL
|
#ifdef O_EXCL
|
||||||
@@ -163,6 +153,14 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
case 'F':
|
case 'F':
|
||||||
state->strategy = Z_FIXED;
|
state->strategy = Z_FIXED;
|
||||||
break;
|
break;
|
||||||
|
case 'G':
|
||||||
|
state->direct = -1;
|
||||||
|
break;
|
||||||
|
#ifdef O_NONBLOCK
|
||||||
|
case 'N':
|
||||||
|
oflag |= O_NONBLOCK;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case 'T':
|
case 'T':
|
||||||
state->direct = 1;
|
state->direct = 1;
|
||||||
break;
|
break;
|
||||||
@@ -178,22 +176,30 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* can't force transparent read */
|
/* direct is 0, 1 if "T", or -1 if "G" (last "G" or "T" wins) */
|
||||||
if (state->mode == GZ_READ) {
|
if (state->mode == GZ_READ) {
|
||||||
if (state->direct) {
|
if (state->direct == 1) {
|
||||||
|
/* can't force a transparent read */
|
||||||
free(state);
|
free(state);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
state->direct = 1; /* for empty file */
|
if (state->direct == 0)
|
||||||
|
/* default when reading is auto-detect of gzip vs. transparent --
|
||||||
|
start with a transparent assumption in case of an empty file */
|
||||||
|
state->direct = 1;
|
||||||
}
|
}
|
||||||
|
else if (state->direct == -1) {
|
||||||
|
/* "G" has no meaning when writing -- disallow it */
|
||||||
|
free(state);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* if reading, direct == 1 for auto-detect, -1 for gzip only; if writing or
|
||||||
|
appending, direct == 0 for gzip, 1 for transparent (copy in to out) */
|
||||||
|
|
||||||
/* save the path name for error messages */
|
/* save the path name for error messages */
|
||||||
#ifdef _WIN32
|
#ifdef WIDECHAR
|
||||||
if (fd == -2) {
|
if (fd == -2)
|
||||||
len = wcstombs(NULL, path, 0);
|
len = wcstombs(NULL, path, 0);
|
||||||
if (len == (size_t)-1)
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
len = strlen((const char *)path);
|
len = strlen((const char *)path);
|
||||||
@@ -202,30 +208,30 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
free(state);
|
free(state);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef WIDECHAR
|
||||||
if (fd == -2)
|
if (fd == -2) {
|
||||||
if (len)
|
if (len)
|
||||||
wcstombs(state->path, path, len + 1);
|
wcstombs(state->path, path, len + 1);
|
||||||
else
|
else
|
||||||
*(state->path) = 0;
|
*(state->path) = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||||
snprintf(state->path, len + 1, "%s", (const char *)path);
|
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
|
||||||
#else
|
#else
|
||||||
strcpy(state->path, path);
|
strcpy(state->path, path);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* compute the flags for open() */
|
/* compute the flags for open() */
|
||||||
oflag =
|
oflag |=
|
||||||
#ifdef O_LARGEFILE
|
#ifdef O_LARGEFILE
|
||||||
O_LARGEFILE |
|
O_LARGEFILE |
|
||||||
#endif
|
#endif
|
||||||
#ifdef O_BINARY
|
#ifdef O_BINARY
|
||||||
O_BINARY |
|
O_BINARY |
|
||||||
#endif
|
|
||||||
#ifdef O_CLOEXEC
|
|
||||||
(cloexec ? O_CLOEXEC : 0) |
|
|
||||||
#endif
|
#endif
|
||||||
(state->mode == GZ_READ ?
|
(state->mode == GZ_READ ?
|
||||||
O_RDONLY :
|
O_RDONLY :
|
||||||
@@ -238,18 +244,32 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
O_APPEND)));
|
O_APPEND)));
|
||||||
|
|
||||||
/* open the file with the appropriate flags (or just use fd) */
|
/* open the file with the appropriate flags (or just use fd) */
|
||||||
state->fd = fd > -1 ? fd : (
|
if (fd == -1)
|
||||||
#ifdef _WIN32
|
state->fd = open((const char *)path, oflag, 0666);
|
||||||
fd == -2 ? _wopen(path, oflag, 0666) :
|
#ifdef WIDECHAR
|
||||||
|
else if (fd == -2)
|
||||||
|
state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE);
|
||||||
#endif
|
#endif
|
||||||
open((const char *)path, oflag, 0666));
|
else {
|
||||||
|
#ifdef O_NONBLOCK
|
||||||
|
if (oflag & O_NONBLOCK)
|
||||||
|
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
|
||||||
|
#endif
|
||||||
|
#ifdef O_CLOEXEC
|
||||||
|
if (oflag & O_CLOEXEC)
|
||||||
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | O_CLOEXEC);
|
||||||
|
#endif
|
||||||
|
state->fd = fd;
|
||||||
|
}
|
||||||
if (state->fd == -1) {
|
if (state->fd == -1) {
|
||||||
free(state->path);
|
free(state->path);
|
||||||
free(state);
|
free(state);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (state->mode == GZ_APPEND)
|
if (state->mode == GZ_APPEND) {
|
||||||
|
LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
|
||||||
state->mode = GZ_WRITE; /* simplify later checks */
|
state->mode = GZ_WRITE; /* simplify later checks */
|
||||||
|
}
|
||||||
|
|
||||||
/* save the current position for rewinding (only if reading) */
|
/* save the current position for rewinding (only if reading) */
|
||||||
if (state->mode == GZ_READ) {
|
if (state->mode == GZ_READ) {
|
||||||
@@ -265,33 +285,24 @@ local gzFile gz_open(path, fd, mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
gzFile ZEXPORT gzopen(path, mode)
|
gzFile ZEXPORT gzopen(const char *path, const char *mode) {
|
||||||
const char *path;
|
|
||||||
const char *mode;
|
|
||||||
{
|
|
||||||
return gz_open(path, -1, mode);
|
return gz_open(path, -1, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
gzFile ZEXPORT gzopen64(path, mode)
|
gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
|
||||||
const char *path;
|
|
||||||
const char *mode;
|
|
||||||
{
|
|
||||||
return gz_open(path, -1, mode);
|
return gz_open(path, -1, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
gzFile ZEXPORT gzdopen(fd, mode)
|
gzFile ZEXPORT gzdopen(int fd, const char *mode) {
|
||||||
int fd;
|
|
||||||
const char *mode;
|
|
||||||
{
|
|
||||||
char *path; /* identifier for error messages */
|
char *path; /* identifier for error messages */
|
||||||
gzFile gz;
|
gzFile gz;
|
||||||
|
|
||||||
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
|
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||||
snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
|
(void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
|
||||||
#else
|
#else
|
||||||
sprintf(path, "<fd:%d>", fd); /* for debugging */
|
sprintf(path, "<fd:%d>", fd); /* for debugging */
|
||||||
#endif
|
#endif
|
||||||
@@ -301,20 +312,14 @@ gzFile ZEXPORT gzdopen(fd, mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
#ifdef _WIN32
|
#ifdef WIDECHAR
|
||||||
gzFile ZEXPORT gzopen_w(path, mode)
|
gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
|
||||||
const wchar_t *path;
|
|
||||||
const char *mode;
|
|
||||||
{
|
|
||||||
return gz_open(path, -2, mode);
|
return gz_open(path, -2, mode);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzbuffer(file, size)
|
int ZEXPORT gzbuffer(gzFile file, unsigned size) {
|
||||||
gzFile file;
|
|
||||||
unsigned size;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure and check integrity */
|
/* get internal structure and check integrity */
|
||||||
@@ -329,16 +334,16 @@ int ZEXPORT gzbuffer(file, size)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* check and set requested size */
|
/* check and set requested size */
|
||||||
if (size < 2)
|
if ((size << 1) < size)
|
||||||
size = 2; /* need two bytes to check magic header */
|
return -1; /* need to be able to double it */
|
||||||
|
if (size < 8)
|
||||||
|
size = 8; /* needed to behave well with flushing */
|
||||||
state->want = size;
|
state->want = size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzrewind(file)
|
int ZEXPORT gzrewind(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure */
|
||||||
@@ -359,11 +364,7 @@ int ZEXPORT gzrewind(file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||||
gzFile file;
|
|
||||||
z_off64_t offset;
|
|
||||||
int whence;
|
|
||||||
{
|
|
||||||
unsigned n;
|
unsigned n;
|
||||||
z_off64_t ret;
|
z_off64_t ret;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
@@ -386,20 +387,21 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||||||
/* normalize offset to a SEEK_CUR specification */
|
/* normalize offset to a SEEK_CUR specification */
|
||||||
if (whence == SEEK_SET)
|
if (whence == SEEK_SET)
|
||||||
offset -= state->x.pos;
|
offset -= state->x.pos;
|
||||||
else if (state->seek)
|
else {
|
||||||
offset += state->skip;
|
offset += state->past ? 0 : state->skip;
|
||||||
state->seek = 0;
|
state->skip = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* if within raw area while reading, just go there */
|
/* if within raw area while reading, just go there */
|
||||||
if (state->mode == GZ_READ && state->how == COPY &&
|
if (state->mode == GZ_READ && state->how == COPY &&
|
||||||
state->x.pos + offset >= 0) {
|
state->x.pos + offset >= 0) {
|
||||||
ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
|
ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return -1;
|
return -1;
|
||||||
state->x.have = 0;
|
state->x.have = 0;
|
||||||
state->eof = 0;
|
state->eof = 0;
|
||||||
state->past = 0;
|
state->past = 0;
|
||||||
state->seek = 0;
|
state->skip = 0;
|
||||||
gz_error(state, Z_OK, NULL);
|
gz_error(state, Z_OK, NULL);
|
||||||
state->strm.avail_in = 0;
|
state->strm.avail_in = 0;
|
||||||
state->x.pos += offset;
|
state->x.pos += offset;
|
||||||
@@ -428,19 +430,12 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* request skip (if not zero) */
|
/* request skip (if not zero) */
|
||||||
if (offset) {
|
state->skip = offset;
|
||||||
state->seek = 1;
|
|
||||||
state->skip = offset;
|
|
||||||
}
|
|
||||||
return state->x.pos + offset;
|
return state->x.pos + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
z_off_t ZEXPORT gzseek(file, offset, whence)
|
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
|
||||||
gzFile file;
|
|
||||||
z_off_t offset;
|
|
||||||
int whence;
|
|
||||||
{
|
|
||||||
z_off64_t ret;
|
z_off64_t ret;
|
||||||
|
|
||||||
ret = gzseek64(file, (z_off64_t)offset, whence);
|
ret = gzseek64(file, (z_off64_t)offset, whence);
|
||||||
@@ -448,9 +443,7 @@ z_off_t ZEXPORT gzseek(file, offset, whence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
z_off64_t ZEXPORT gztell64(file)
|
z_off64_t ZEXPORT gztell64(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure and check integrity */
|
/* get internal structure and check integrity */
|
||||||
@@ -461,13 +454,11 @@ z_off64_t ZEXPORT gztell64(file)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* return position */
|
/* return position */
|
||||||
return state->x.pos + (state->seek ? state->skip : 0);
|
return state->x.pos + (state->past ? 0 : state->skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
z_off_t ZEXPORT gztell(file)
|
z_off_t ZEXPORT gztell(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
z_off64_t ret;
|
z_off64_t ret;
|
||||||
|
|
||||||
ret = gztell64(file);
|
ret = gztell64(file);
|
||||||
@@ -475,9 +466,7 @@ z_off_t ZEXPORT gztell(file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
z_off64_t ZEXPORT gzoffset64(file)
|
z_off64_t ZEXPORT gzoffset64(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
z_off64_t offset;
|
z_off64_t offset;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
@@ -498,9 +487,7 @@ z_off64_t ZEXPORT gzoffset64(file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
z_off_t ZEXPORT gzoffset(file)
|
z_off_t ZEXPORT gzoffset(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
z_off64_t ret;
|
z_off64_t ret;
|
||||||
|
|
||||||
ret = gzoffset64(file);
|
ret = gzoffset64(file);
|
||||||
@@ -508,9 +495,7 @@ z_off_t ZEXPORT gzoffset(file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzeof(file)
|
int ZEXPORT gzeof(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure and check integrity */
|
/* get internal structure and check integrity */
|
||||||
@@ -525,10 +510,7 @@ int ZEXPORT gzeof(file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
const char * ZEXPORT gzerror(file, errnum)
|
const char * ZEXPORT gzerror(gzFile file, int *errnum) {
|
||||||
gzFile file;
|
|
||||||
int *errnum;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure and check integrity */
|
/* get internal structure and check integrity */
|
||||||
@@ -546,9 +528,7 @@ const char * ZEXPORT gzerror(file, errnum)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
void ZEXPORT gzclearerr(file)
|
void ZEXPORT gzclearerr(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure and check integrity */
|
/* get internal structure and check integrity */
|
||||||
@@ -572,11 +552,7 @@ void ZEXPORT gzclearerr(file)
|
|||||||
memory). Simply save the error message as a static string. If there is an
|
memory). Simply save the error message as a static string. If there is an
|
||||||
allocation failure constructing the error message, then convert the error to
|
allocation failure constructing the error message, then convert the error to
|
||||||
out of memory. */
|
out of memory. */
|
||||||
void ZLIB_INTERNAL gz_error(state, err, msg)
|
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
|
||||||
gz_statep state;
|
|
||||||
int err;
|
|
||||||
const char *msg;
|
|
||||||
{
|
|
||||||
/* free previously allocated message and clear */
|
/* free previously allocated message and clear */
|
||||||
if (state->msg != NULL) {
|
if (state->msg != NULL) {
|
||||||
if (state->err != Z_MEM_ERROR)
|
if (state->err != Z_MEM_ERROR)
|
||||||
@@ -585,7 +561,7 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
|
/* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
|
||||||
if (err != Z_OK && err != Z_BUF_ERROR)
|
if (err != Z_OK && err != Z_BUF_ERROR && !state->again)
|
||||||
state->x.have = 0;
|
state->x.have = 0;
|
||||||
|
|
||||||
/* set error code, and if no message, then done */
|
/* set error code, and if no message, then done */
|
||||||
@@ -604,31 +580,30 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||||
snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
|
(void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
|
||||||
"%s%s%s", state->path, ": ", msg);
|
"%s%s%s", state->path, ": ", msg);
|
||||||
#else
|
#else
|
||||||
strcpy(state->msg, state->path);
|
strcpy(state->msg, state->path);
|
||||||
strcat(state->msg, ": ");
|
strcat(state->msg, ": ");
|
||||||
strcat(state->msg, msg);
|
strcat(state->msg, msg);
|
||||||
#endif
|
#endif
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef INT_MAX
|
|
||||||
/* portably return maximum value for an int (when limits.h presumed not
|
/* portably return maximum value for an int (when limits.h presumed not
|
||||||
available) -- we need to do this to cover cases where 2's complement not
|
available) -- we need to do this to cover cases where 2's complement not
|
||||||
used, since C standard permits 1's complement and sign-bit representations,
|
used, since C standard permits 1's complement and sign-bit representations,
|
||||||
otherwise we could just use ((unsigned)-1) >> 1 */
|
otherwise we could just use ((unsigned)-1) >> 1 */
|
||||||
unsigned ZLIB_INTERNAL gz_intmax()
|
unsigned ZLIB_INTERNAL gz_intmax(void) {
|
||||||
{
|
#ifdef INT_MAX
|
||||||
unsigned p, q;
|
return INT_MAX;
|
||||||
|
#else
|
||||||
|
unsigned p = 1, q;
|
||||||
|
|
||||||
p = 1;
|
|
||||||
do {
|
do {
|
||||||
q = p;
|
q = p;
|
||||||
p <<= 1;
|
p <<= 1;
|
||||||
p++;
|
p++;
|
||||||
} while (p > q);
|
} while (p > q);
|
||||||
return q >> 1;
|
return q >> 1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,38 +1,43 @@
|
|||||||
/* gzread.c -- zlib functions for reading gzip files
|
/* gzread.c -- zlib functions for reading gzip files
|
||||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
* Copyright (C) 2004-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gzguts.h"
|
#include "gzguts.h"
|
||||||
|
|
||||||
/* Local functions */
|
|
||||||
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
|
|
||||||
local int gz_avail OF((gz_statep));
|
|
||||||
local int gz_look OF((gz_statep));
|
|
||||||
local int gz_decomp OF((gz_statep));
|
|
||||||
local int gz_fetch OF((gz_statep));
|
|
||||||
local int gz_skip OF((gz_statep, z_off64_t));
|
|
||||||
|
|
||||||
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
||||||
state->fd, and update state->eof, state->err, and state->msg as appropriate.
|
state->fd, and update state->eof, state->err, and state->msg as appropriate.
|
||||||
This function needs to loop on read(), since read() is not guaranteed to
|
This function needs to loop on read(), since read() is not guaranteed to
|
||||||
read the number of bytes requested, depending on the type of descriptor. */
|
read the number of bytes requested, depending on the type of descriptor. It
|
||||||
local int gz_load(state, buf, len, have)
|
also needs to loop to manage the fact that read() returns an int. If the
|
||||||
gz_statep state;
|
descriptor is non-blocking and read() returns with no data in order to avoid
|
||||||
unsigned char *buf;
|
blocking, then gz_load() will return 0 if some data has been read, or -1 if
|
||||||
unsigned len;
|
no data has been read. Either way, state->again is set true to indicate a
|
||||||
unsigned *have;
|
non-blocking event. If errno is non-zero on return, then there was an error
|
||||||
{
|
signaled from read(). *have is set to the number of bytes read. */
|
||||||
|
local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
|
||||||
|
unsigned *have) {
|
||||||
int ret;
|
int ret;
|
||||||
|
unsigned get, max = ((unsigned)-1 >> 2) + 1;
|
||||||
|
|
||||||
|
state->again = 0;
|
||||||
|
errno = 0;
|
||||||
*have = 0;
|
*have = 0;
|
||||||
do {
|
do {
|
||||||
ret = read(state->fd, buf + *have, len - *have);
|
get = len - *have;
|
||||||
|
if (get > max)
|
||||||
|
get = max;
|
||||||
|
ret = (int)read(state->fd, buf + *have, get);
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
break;
|
break;
|
||||||
*have += ret;
|
*have += (unsigned)ret;
|
||||||
} while (*have < len);
|
} while (*have < len);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
|
state->again = 1;
|
||||||
|
if (*have != 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
gz_error(state, Z_ERRNO, zstrerror());
|
gz_error(state, Z_ERRNO, zstrerror());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -48,9 +53,7 @@ local int gz_load(state, buf, len, have)
|
|||||||
If strm->avail_in != 0, then the current data is moved to the beginning of
|
If strm->avail_in != 0, then the current data is moved to the beginning of
|
||||||
the input buffer, and then the remainder of the buffer is loaded with the
|
the input buffer, and then the remainder of the buffer is loaded with the
|
||||||
available data from the input file. */
|
available data from the input file. */
|
||||||
local int gz_avail(state)
|
local int gz_avail(gz_statep state) {
|
||||||
gz_statep state;
|
|
||||||
{
|
|
||||||
unsigned got;
|
unsigned got;
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
|
|
||||||
@@ -60,10 +63,14 @@ local int gz_avail(state)
|
|||||||
if (strm->avail_in) { /* copy what's there to the start */
|
if (strm->avail_in) { /* copy what's there to the start */
|
||||||
unsigned char *p = state->in;
|
unsigned char *p = state->in;
|
||||||
unsigned const char *q = strm->next_in;
|
unsigned const char *q = strm->next_in;
|
||||||
unsigned n = strm->avail_in;
|
|
||||||
do {
|
if (q != p) {
|
||||||
*p++ = *q++;
|
unsigned n = strm->avail_in;
|
||||||
} while (--n);
|
|
||||||
|
do {
|
||||||
|
*p++ = *q++;
|
||||||
|
} while (--n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (gz_load(state, state->in + strm->avail_in,
|
if (gz_load(state, state->in + strm->avail_in,
|
||||||
state->size - strm->avail_in, &got) == -1)
|
state->size - strm->avail_in, &got) == -1)
|
||||||
@@ -83,9 +90,7 @@ local int gz_avail(state)
|
|||||||
case, all further file reads will be directly to either the output buffer or
|
case, all further file reads will be directly to either the output buffer or
|
||||||
a user buffer. If decompressing, the inflate state will be initialized.
|
a user buffer. If decompressing, the inflate state will be initialized.
|
||||||
gz_look() will return 0 on success or -1 on failure. */
|
gz_look() will return 0 on success or -1 on failure. */
|
||||||
local int gz_look(state)
|
local int gz_look(gz_statep state) {
|
||||||
gz_statep state;
|
|
||||||
{
|
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
|
|
||||||
/* allocate read buffers and inflate memory */
|
/* allocate read buffers and inflate memory */
|
||||||
@@ -94,10 +99,8 @@ local int gz_look(state)
|
|||||||
state->in = (unsigned char *)malloc(state->want);
|
state->in = (unsigned char *)malloc(state->want);
|
||||||
state->out = (unsigned char *)malloc(state->want << 1);
|
state->out = (unsigned char *)malloc(state->want << 1);
|
||||||
if (state->in == NULL || state->out == NULL) {
|
if (state->in == NULL || state->out == NULL) {
|
||||||
if (state->out != NULL)
|
free(state->out);
|
||||||
free(state->out);
|
free(state->in);
|
||||||
if (state->in != NULL)
|
|
||||||
free(state->in);
|
|
||||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -118,60 +121,63 @@ local int gz_look(state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get at least the magic bytes in the input buffer */
|
/* if transparent reading is disabled, which would only be at the start, or
|
||||||
if (strm->avail_in < 2) {
|
if we're looking for a gzip member after the first one, which is not at
|
||||||
if (gz_avail(state) == -1)
|
the start, then proceed directly to look for a gzip member next */
|
||||||
return -1;
|
if (state->direct == -1 || state->junk == 0) {
|
||||||
if (strm->avail_in == 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* look for gzip magic bytes -- if there, do gzip decoding (note: there is
|
|
||||||
a logical dilemma here when considering the case of a partially written
|
|
||||||
gzip file, to wit, if a single 31 byte is written, then we cannot tell
|
|
||||||
whether this is a single-byte file, or just a partially written gzip
|
|
||||||
file -- for here we assume that if a gzip file is being written, then
|
|
||||||
the header will be written in a single operation, so that reading a
|
|
||||||
single byte is sufficient indication that it is not a gzip file) */
|
|
||||||
if (strm->avail_in > 1 &&
|
|
||||||
strm->next_in[0] == 31 && strm->next_in[1] == 139) {
|
|
||||||
inflateReset(strm);
|
inflateReset(strm);
|
||||||
state->how = GZIP;
|
state->how = GZIP;
|
||||||
|
state->junk = state->junk != -1;
|
||||||
state->direct = 0;
|
state->direct = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no gzip header -- if we were decoding gzip before, then this is trailing
|
/* otherwise we're at the start with auto-detect -- we check to see if the
|
||||||
garbage. Ignore the trailing garbage and finish. */
|
first four bytes could be gzip header in order to decide whether or not
|
||||||
if (state->direct == 0) {
|
this will be a transparent read */
|
||||||
strm->avail_in = 0;
|
|
||||||
state->eof = 1;
|
/* load any header bytes into the input buffer -- if the input is empty,
|
||||||
state->x.have = 0;
|
then it's not an error as this is a transparent read of zero bytes */
|
||||||
|
if (gz_avail(state) == -1)
|
||||||
|
return -1;
|
||||||
|
if (strm->avail_in == 0 || (state->again && strm->avail_in < 4))
|
||||||
|
/* if non-blocking input stalled before getting four bytes, then
|
||||||
|
return and wait until a later call has accumulated enough */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* see if this is (likely) gzip input -- if the first four bytes are
|
||||||
|
consistent with a gzip header, then go look for the first gzip member,
|
||||||
|
otherwise proceed to copy the input transparently */
|
||||||
|
if (strm->avail_in > 3 &&
|
||||||
|
strm->next_in[0] == 31 && strm->next_in[1] == 139 &&
|
||||||
|
strm->next_in[2] == 8 && strm->next_in[3] < 32) {
|
||||||
|
inflateReset(strm);
|
||||||
|
state->how = GZIP;
|
||||||
|
state->junk = 1;
|
||||||
|
state->direct = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* doing raw i/o, copy any leftover input to output -- this assumes that
|
/* doing raw i/o: copy any leftover input to output -- this assumes that
|
||||||
the output buffer is larger than the input buffer, which also assures
|
the output buffer is larger than the input buffer, which also assures
|
||||||
space for gzungetc() */
|
space for gzungetc() */
|
||||||
state->x.next = state->out;
|
state->x.next = state->out;
|
||||||
if (strm->avail_in) {
|
memcpy(state->x.next, strm->next_in, strm->avail_in);
|
||||||
memcpy(state->x.next, strm->next_in, strm->avail_in);
|
state->x.have = strm->avail_in;
|
||||||
state->x.have = strm->avail_in;
|
strm->avail_in = 0;
|
||||||
strm->avail_in = 0;
|
|
||||||
}
|
|
||||||
state->how = COPY;
|
state->how = COPY;
|
||||||
state->direct = 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decompress from input to the provided next_out and avail_out in the state.
|
/* Decompress from input to the provided next_out and avail_out in the state.
|
||||||
On return, state->x.have and state->x.next point to the just decompressed
|
On return, state->x.have and state->x.next point to the just decompressed
|
||||||
data. If the gzip stream completes, state->how is reset to LOOK to look for
|
data. If the gzip stream completes, state->how is reset to LOOK to look for
|
||||||
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
|
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
|
||||||
on success, -1 on failure. */
|
on success, -1 on failure. If EOF is reached when looking for more input to
|
||||||
local int gz_decomp(state)
|
complete the gzip member, then an unexpected end of file error is raised.
|
||||||
gz_statep state;
|
If there is no more input, but state->again is true, then EOF has not been
|
||||||
{
|
reached, and no error is raised. */
|
||||||
|
local int gz_decomp(gz_statep state) {
|
||||||
int ret = Z_OK;
|
int ret = Z_OK;
|
||||||
unsigned had;
|
unsigned had;
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
@@ -180,28 +186,41 @@ local int gz_decomp(state)
|
|||||||
had = strm->avail_out;
|
had = strm->avail_out;
|
||||||
do {
|
do {
|
||||||
/* get more input for inflate() */
|
/* get more input for inflate() */
|
||||||
if (strm->avail_in == 0 && gz_avail(state) == -1)
|
if (strm->avail_in == 0 && gz_avail(state) == -1) {
|
||||||
return -1;
|
ret = state->err;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (strm->avail_in == 0) {
|
if (strm->avail_in == 0) {
|
||||||
gz_error(state, Z_BUF_ERROR, "unexpected end of file");
|
if (!state->again)
|
||||||
|
gz_error(state, Z_BUF_ERROR, "unexpected end of file");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decompress and handle errors */
|
/* decompress and handle errors */
|
||||||
ret = inflate(strm, Z_NO_FLUSH);
|
ret = inflate(strm, Z_NO_FLUSH);
|
||||||
|
if (strm->avail_out < had)
|
||||||
|
/* any decompressed data marks this as a real gzip stream */
|
||||||
|
state->junk = 0;
|
||||||
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
|
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
|
||||||
gz_error(state, Z_STREAM_ERROR,
|
gz_error(state, Z_STREAM_ERROR,
|
||||||
"internal error: inflate stream corrupt");
|
"internal error: inflate stream corrupt");
|
||||||
return -1;
|
break;
|
||||||
}
|
}
|
||||||
if (ret == Z_MEM_ERROR) {
|
if (ret == Z_MEM_ERROR) {
|
||||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||||
return -1;
|
break;
|
||||||
}
|
}
|
||||||
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
|
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
|
||||||
|
if (state->junk == 1) { /* trailing garbage is ok */
|
||||||
|
strm->avail_in = 0;
|
||||||
|
state->eof = 1;
|
||||||
|
state->how = LOOK;
|
||||||
|
ret = Z_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
gz_error(state, Z_DATA_ERROR,
|
gz_error(state, Z_DATA_ERROR,
|
||||||
strm->msg == NULL ? "compressed data error" : strm->msg);
|
strm->msg == NULL ? "compressed data error" : strm->msg);
|
||||||
return -1;
|
break;
|
||||||
}
|
}
|
||||||
} while (strm->avail_out && ret != Z_STREAM_END);
|
} while (strm->avail_out && ret != Z_STREAM_END);
|
||||||
|
|
||||||
@@ -210,11 +229,14 @@ local int gz_decomp(state)
|
|||||||
state->x.next = strm->next_out - state->x.have;
|
state->x.next = strm->next_out - state->x.have;
|
||||||
|
|
||||||
/* if the gzip stream completed successfully, look for another */
|
/* if the gzip stream completed successfully, look for another */
|
||||||
if (ret == Z_STREAM_END)
|
if (ret == Z_STREAM_END) {
|
||||||
|
state->junk = 0;
|
||||||
state->how = LOOK;
|
state->how = LOOK;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* good decompression */
|
/* return decompression status */
|
||||||
return 0;
|
return ret != Z_OK ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
|
/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
|
||||||
@@ -223,9 +245,7 @@ local int gz_decomp(state)
|
|||||||
looked for to determine whether to copy or decompress. Returns -1 on error,
|
looked for to determine whether to copy or decompress. Returns -1 on error,
|
||||||
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
|
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
|
||||||
end of the input file has been reached and all data has been processed. */
|
end of the input file has been reached and all data has been processed. */
|
||||||
local int gz_fetch(state)
|
local int gz_fetch(gz_statep state) {
|
||||||
gz_statep state;
|
|
||||||
{
|
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -247,28 +267,31 @@ local int gz_fetch(state)
|
|||||||
strm->next_out = state->out;
|
strm->next_out = state->out;
|
||||||
if (gz_decomp(state) == -1)
|
if (gz_decomp(state) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gz_error(state, Z_STREAM_ERROR, "state corrupt");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
} while (state->x.have == 0 && (!state->eof || strm->avail_in));
|
} while (state->x.have == 0 && (!state->eof || strm->avail_in));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
|
/* Skip state->skip (> 0) uncompressed bytes of output. Return -1 on error, 0
|
||||||
local int gz_skip(state, len)
|
on success. */
|
||||||
gz_statep state;
|
local int gz_skip(gz_statep state) {
|
||||||
z_off64_t len;
|
|
||||||
{
|
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
/* skip over len bytes or reach end-of-file, whichever comes first */
|
/* skip over len bytes or reach end-of-file, whichever comes first */
|
||||||
while (len)
|
do {
|
||||||
/* skip over whatever is in output buffer */
|
/* skip over whatever is in output buffer */
|
||||||
if (state->x.have) {
|
if (state->x.have) {
|
||||||
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
|
n = GT_OFF(state->x.have) ||
|
||||||
(unsigned)len : state->x.have;
|
(z_off64_t)state->x.have > state->skip ?
|
||||||
|
(unsigned)state->skip : state->x.have;
|
||||||
state->x.have -= n;
|
state->x.have -= n;
|
||||||
state->x.next += n;
|
state->x.next += n;
|
||||||
state->x.pos += n;
|
state->x.pos += n;
|
||||||
len -= n;
|
state->skip -= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* output buffer empty -- return if we're at the end of the input */
|
/* output buffer empty -- return if we're at the end of the input */
|
||||||
@@ -281,88 +304,75 @@ local int gz_skip(state, len)
|
|||||||
if (gz_fetch(state) == -1)
|
if (gz_fetch(state) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
} while (state->skip);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* Read len bytes into buf from file, or less than len up to the end of the
|
||||||
int ZEXPORT gzread(file, buf, len)
|
input. Return the number of bytes read. If zero is returned, either the end
|
||||||
gzFile file;
|
of file was reached, or there was an error. state->err must be consulted in
|
||||||
voidp buf;
|
that case to determine which. If there was an error, but some uncompressed
|
||||||
unsigned len;
|
bytes were read before the error, then that count is returned. The error is
|
||||||
{
|
still recorded, and so is deferred until the next call. */
|
||||||
unsigned got, n;
|
local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
|
||||||
gz_statep state;
|
z_size_t got;
|
||||||
z_streamp strm;
|
unsigned n;
|
||||||
|
int err;
|
||||||
/* get internal structure */
|
|
||||||
if (file == NULL)
|
|
||||||
return -1;
|
|
||||||
state = (gz_statep)file;
|
|
||||||
strm = &(state->strm);
|
|
||||||
|
|
||||||
/* check that we're reading and that there's no (serious) error */
|
|
||||||
if (state->mode != GZ_READ ||
|
|
||||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* since an int is returned, make sure len fits in one, otherwise return
|
|
||||||
with an error (this avoids the flaw in the interface) */
|
|
||||||
if ((int)len < 0) {
|
|
||||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if len is zero, avoid unnecessary operations */
|
/* if len is zero, avoid unnecessary operations */
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* process a skip request */
|
/* process a skip request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_skip(state) == -1)
|
||||||
state->seek = 0;
|
return 0;
|
||||||
if (gz_skip(state, state->skip) == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get len bytes to buf, or less than len if at the end */
|
/* get len bytes to buf, or less than len if at the end */
|
||||||
got = 0;
|
got = 0;
|
||||||
|
err = 0;
|
||||||
do {
|
do {
|
||||||
|
/* set n to the maximum amount of len that fits in an unsigned int */
|
||||||
|
n = (unsigned)-1;
|
||||||
|
if (n > len)
|
||||||
|
n = (unsigned)len;
|
||||||
|
|
||||||
/* first just try copying data from the output buffer */
|
/* first just try copying data from the output buffer */
|
||||||
if (state->x.have) {
|
if (state->x.have) {
|
||||||
n = state->x.have > len ? len : state->x.have;
|
if (state->x.have < n)
|
||||||
|
n = state->x.have;
|
||||||
memcpy(buf, state->x.next, n);
|
memcpy(buf, state->x.next, n);
|
||||||
state->x.next += n;
|
state->x.next += n;
|
||||||
state->x.have -= n;
|
state->x.have -= n;
|
||||||
|
if (state->err != Z_OK)
|
||||||
|
/* caught deferred error from gz_fetch() */
|
||||||
|
err = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* output buffer empty -- return if we're at the end of the input */
|
/* output buffer empty -- return if we're at the end of the input */
|
||||||
else if (state->eof && strm->avail_in == 0) {
|
else if (state->eof && state->strm.avail_in == 0)
|
||||||
state->past = 1; /* tried to read past end */
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
/* need output data -- for small len or new stream load up our output
|
/* need output data -- for small len or new stream load up our output
|
||||||
buffer */
|
buffer, so that gzgetc() can be fast */
|
||||||
else if (state->how == LOOK || len < (state->size << 1)) {
|
else if (state->how == LOOK || n < (state->size << 1)) {
|
||||||
/* get more output, looking for header if required */
|
/* get more output, looking for header if required */
|
||||||
if (gz_fetch(state) == -1)
|
if (gz_fetch(state) == -1 && state->x.have == 0)
|
||||||
return -1;
|
/* if state->x.have != 0, error will be caught after copy */
|
||||||
|
err = -1;
|
||||||
continue; /* no progress yet -- go back to copy above */
|
continue; /* no progress yet -- go back to copy above */
|
||||||
/* the copy above assures that we will leave with space in the
|
/* the copy above assures that we will leave with space in the
|
||||||
output buffer, allowing at least one gzungetc() to succeed */
|
output buffer, allowing at least one gzungetc() to succeed */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* large len -- read directly into user buffer */
|
/* large len -- read directly into user buffer */
|
||||||
else if (state->how == COPY) { /* read directly */
|
else if (state->how == COPY) /* read directly */
|
||||||
if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
|
err = gz_load(state, (unsigned char *)buf, n, &n);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* large len -- decompress directly into user buffer */
|
/* large len -- decompress directly into user buffer */
|
||||||
else { /* state->how == GZIP */
|
else { /* state->how == GZIP */
|
||||||
strm->avail_out = len;
|
state->strm.avail_out = n;
|
||||||
strm->next_out = (unsigned char *)buf;
|
state->strm.next_out = (unsigned char *)buf;
|
||||||
if (gz_decomp(state) == -1)
|
err = gz_decomp(state);
|
||||||
return -1;
|
|
||||||
n = state->x.have;
|
n = state->x.have;
|
||||||
state->x.have = 0;
|
state->x.have = 0;
|
||||||
}
|
}
|
||||||
@@ -372,10 +382,86 @@ int ZEXPORT gzread(file, buf, len)
|
|||||||
buf = (char *)buf + n;
|
buf = (char *)buf + n;
|
||||||
got += n;
|
got += n;
|
||||||
state->x.pos += n;
|
state->x.pos += n;
|
||||||
} while (len);
|
} while (len && !err);
|
||||||
|
|
||||||
/* return number of bytes read into user buffer (will fit in int) */
|
/* note read past eof */
|
||||||
return (int)got;
|
if (len && state->eof)
|
||||||
|
state->past = 1;
|
||||||
|
|
||||||
|
/* return number of bytes read into user buffer */
|
||||||
|
return got;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- see zlib.h -- */
|
||||||
|
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
|
||||||
|
gz_statep state;
|
||||||
|
|
||||||
|
/* get internal structure and check that it's for reading */
|
||||||
|
if (file == NULL)
|
||||||
|
return -1;
|
||||||
|
state = (gz_statep)file;
|
||||||
|
if (state->mode != GZ_READ)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* check that there was no (serious) error */
|
||||||
|
if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
|
||||||
|
return -1;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
|
/* since an int is returned, make sure len fits in one, otherwise return
|
||||||
|
with an error (this avoids a flaw in the interface) */
|
||||||
|
if ((int)len < 0) {
|
||||||
|
gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read len or fewer bytes to buf */
|
||||||
|
len = (unsigned)gz_read(state, buf, len);
|
||||||
|
|
||||||
|
/* check for an error */
|
||||||
|
if (len == 0) {
|
||||||
|
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
|
||||||
|
return -1;
|
||||||
|
if (state->again) {
|
||||||
|
/* non-blocking input stalled after some input was read, but no
|
||||||
|
uncompressed bytes were produced -- let the application know
|
||||||
|
this isn't EOF */
|
||||||
|
gz_error(state, Z_ERRNO, zstrerror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* return the number of bytes read */
|
||||||
|
return (int)len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- see zlib.h -- */
|
||||||
|
z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
|
||||||
|
gzFile file) {
|
||||||
|
z_size_t len;
|
||||||
|
gz_statep state;
|
||||||
|
|
||||||
|
/* get internal structure and check that it's for reading */
|
||||||
|
if (file == NULL)
|
||||||
|
return 0;
|
||||||
|
state = (gz_statep)file;
|
||||||
|
if (state->mode != GZ_READ)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* check that there was no (serious) error */
|
||||||
|
if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
|
||||||
|
return 0;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
|
/* compute bytes to read -- error on overflow */
|
||||||
|
len = nitems * size;
|
||||||
|
if (size && len / size != nitems) {
|
||||||
|
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read len or fewer bytes to buf, return the number of full items read */
|
||||||
|
return len ? gz_read(state, buf, len) / size : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
@@ -384,23 +470,22 @@ int ZEXPORT gzread(file, buf, len)
|
|||||||
#else
|
#else
|
||||||
# undef gzgetc
|
# undef gzgetc
|
||||||
#endif
|
#endif
|
||||||
int ZEXPORT gzgetc(file)
|
int ZEXPORT gzgetc(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
unsigned char buf[1];
|
unsigned char buf[1];
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure and check that it's for reading */
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
|
if (state->mode != GZ_READ)
|
||||||
/* check that we're reading and that there's no (serious) error */
|
|
||||||
if (state->mode != GZ_READ ||
|
|
||||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* check that there was no (serious) error */
|
||||||
|
if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
|
||||||
|
return -1;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* try output buffer (no need to check for skip request) */
|
/* try output buffer (no need to check for skip request) */
|
||||||
if (state->x.have) {
|
if (state->x.have) {
|
||||||
state->x.have--;
|
state->x.have--;
|
||||||
@@ -408,40 +493,37 @@ int ZEXPORT gzgetc(file)
|
|||||||
return *(state->x.next)++;
|
return *(state->x.next)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nothing there -- try gzread() */
|
/* nothing there -- try gz_read() */
|
||||||
ret = gzread(file, buf, 1);
|
return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
|
||||||
return ret < 1 ? -1 : buf[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZEXPORT gzgetc_(file)
|
int ZEXPORT gzgetc_(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
return gzgetc(file);
|
return gzgetc(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzungetc(c, file)
|
int ZEXPORT gzungetc(int c, gzFile file) {
|
||||||
int c;
|
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure and check that it's for reading */
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
|
if (state->mode != GZ_READ)
|
||||||
/* check that we're reading and that there's no (serious) error */
|
|
||||||
if (state->mode != GZ_READ ||
|
|
||||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* in case this was just opened, set up the input buffer */
|
||||||
|
if (state->how == LOOK && state->x.have == 0)
|
||||||
|
(void)gz_look(state);
|
||||||
|
|
||||||
|
/* check that there was no (serious) error */
|
||||||
|
if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
|
||||||
|
return -1;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* process a skip request */
|
/* process a skip request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_skip(state) == -1)
|
||||||
state->seek = 0;
|
return -1;
|
||||||
if (gz_skip(state, state->skip) == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* can't push EOF */
|
/* can't push EOF */
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
@@ -451,7 +533,7 @@ int ZEXPORT gzungetc(c, file)
|
|||||||
if (state->x.have == 0) {
|
if (state->x.have == 0) {
|
||||||
state->x.have = 1;
|
state->x.have = 1;
|
||||||
state->x.next = state->out + (state->size << 1) - 1;
|
state->x.next = state->out + (state->size << 1) - 1;
|
||||||
state->x.next[0] = c;
|
state->x.next[0] = (unsigned char)c;
|
||||||
state->x.pos--;
|
state->x.pos--;
|
||||||
state->past = 0;
|
state->past = 0;
|
||||||
return c;
|
return c;
|
||||||
@@ -467,55 +549,51 @@ int ZEXPORT gzungetc(c, file)
|
|||||||
if (state->x.next == state->out) {
|
if (state->x.next == state->out) {
|
||||||
unsigned char *src = state->out + state->x.have;
|
unsigned char *src = state->out + state->x.have;
|
||||||
unsigned char *dest = state->out + (state->size << 1);
|
unsigned char *dest = state->out + (state->size << 1);
|
||||||
|
|
||||||
while (src > state->out)
|
while (src > state->out)
|
||||||
*--dest = *--src;
|
*--dest = *--src;
|
||||||
state->x.next = dest;
|
state->x.next = dest;
|
||||||
}
|
}
|
||||||
state->x.have++;
|
state->x.have++;
|
||||||
state->x.next--;
|
state->x.next--;
|
||||||
state->x.next[0] = c;
|
state->x.next[0] = (unsigned char)c;
|
||||||
state->x.pos--;
|
state->x.pos--;
|
||||||
state->past = 0;
|
state->past = 0;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
char * ZEXPORT gzgets(file, buf, len)
|
char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
|
||||||
gzFile file;
|
|
||||||
char *buf;
|
|
||||||
int len;
|
|
||||||
{
|
|
||||||
unsigned left, n;
|
unsigned left, n;
|
||||||
char *str;
|
char *str;
|
||||||
unsigned char *eol;
|
unsigned char *eol;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* check parameters and get internal structure */
|
/* check parameters, get internal structure, and check that it's for
|
||||||
|
reading */
|
||||||
if (file == NULL || buf == NULL || len < 1)
|
if (file == NULL || buf == NULL || len < 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
|
if (state->mode != GZ_READ)
|
||||||
/* check that we're reading and that there's no (serious) error */
|
|
||||||
if (state->mode != GZ_READ ||
|
|
||||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* process a skip request */
|
/* check that there was no (serious) error */
|
||||||
if (state->seek) {
|
if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
|
||||||
state->seek = 0;
|
return NULL;
|
||||||
if (gz_skip(state, state->skip) == -1)
|
gz_error(state, Z_OK, NULL);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy output bytes up to new line or len - 1, whichever comes first --
|
/* process a skip request */
|
||||||
append a terminating zero to the string (we don't check for a zero in
|
if (state->skip && gz_skip(state) == -1)
|
||||||
the contents, let the user worry about that) */
|
return NULL;
|
||||||
|
|
||||||
|
/* copy output up to a new line, len-1 bytes, or there is no more output,
|
||||||
|
whichever comes first */
|
||||||
str = buf;
|
str = buf;
|
||||||
left = (unsigned)len - 1;
|
left = (unsigned)len - 1;
|
||||||
if (left) do {
|
if (left) do {
|
||||||
/* assure that something is in the output buffer */
|
/* assure that something is in the output buffer */
|
||||||
if (state->x.have == 0 && gz_fetch(state) == -1)
|
if (state->x.have == 0 && gz_fetch(state) == -1)
|
||||||
return NULL; /* error */
|
break; /* error */
|
||||||
if (state->x.have == 0) { /* end of file */
|
if (state->x.have == 0) { /* end of file */
|
||||||
state->past = 1; /* read past end */
|
state->past = 1; /* read past end */
|
||||||
break; /* return what we have */
|
break; /* return what we have */
|
||||||
@@ -536,7 +614,9 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||||||
buf += n;
|
buf += n;
|
||||||
} while (left && eol == NULL);
|
} while (left && eol == NULL);
|
||||||
|
|
||||||
/* return terminated string, or if nothing, end of file */
|
/* append a terminating zero to the string (we don't check for a zero in
|
||||||
|
the contents, let the user worry about that) -- return the terminated
|
||||||
|
string, or if nothing was read, NULL */
|
||||||
if (buf == str)
|
if (buf == str)
|
||||||
return NULL;
|
return NULL;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
@@ -544,9 +624,7 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzdirect(file)
|
int ZEXPORT gzdirect(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure */
|
||||||
@@ -560,22 +638,18 @@ int ZEXPORT gzdirect(file)
|
|||||||
(void)gz_look(state);
|
(void)gz_look(state);
|
||||||
|
|
||||||
/* return 1 if transparent, 0 if processing a gzip stream */
|
/* return 1 if transparent, 0 if processing a gzip stream */
|
||||||
return state->direct;
|
return state->direct == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzclose_r(file)
|
int ZEXPORT gzclose_r(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
int ret, err;
|
int ret, err;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure and check that it's for reading */
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
|
|
||||||
/* check that we're reading */
|
|
||||||
if (state->mode != GZ_READ)
|
if (state->mode != GZ_READ)
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,19 @@
|
|||||||
/* gzwrite.c -- zlib functions for writing gzip files
|
/* gzwrite.c -- zlib functions for writing gzip files
|
||||||
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
|
* Copyright (C) 2004-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gzguts.h"
|
#include "gzguts.h"
|
||||||
|
|
||||||
/* Local functions */
|
|
||||||
local int gz_init OF((gz_statep));
|
|
||||||
local int gz_comp OF((gz_statep, int));
|
|
||||||
local int gz_zero OF((gz_statep, z_off64_t));
|
|
||||||
|
|
||||||
/* Initialize state for writing a gzip file. Mark initialization by setting
|
/* Initialize state for writing a gzip file. Mark initialization by setting
|
||||||
state->size to non-zero. Return -1 on failure or 0 on success. */
|
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
|
||||||
local int gz_init(state)
|
success. */
|
||||||
gz_statep state;
|
local int gz_init(gz_statep state) {
|
||||||
{
|
|
||||||
int ret;
|
int ret;
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
|
|
||||||
/* allocate input buffer */
|
/* allocate input buffer (double size for gzprintf) */
|
||||||
state->in = (unsigned char *)malloc(state->want);
|
state->in = (unsigned char *)malloc(state->want << 1);
|
||||||
if (state->in == NULL) {
|
if (state->in == NULL) {
|
||||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -47,6 +41,7 @@ local int gz_init(state)
|
|||||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
strm->next_in = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mark state as initialized */
|
/* mark state as initialized */
|
||||||
@@ -62,17 +57,14 @@ local int gz_init(state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compress whatever is at avail_in and next_in and write to the output file.
|
/* Compress whatever is at avail_in and next_in and write to the output file.
|
||||||
Return -1 if there is an error writing to the output file, otherwise 0.
|
Return -1 if there is an error writing to the output file or if gz_init()
|
||||||
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
|
fails to allocate memory, otherwise 0. flush is assumed to be a valid
|
||||||
then the deflate() state is reset to start a new gzip stream. If gz->direct
|
deflate() flush value. If flush is Z_FINISH, then the deflate() state is
|
||||||
is true, then simply write to the output file without compressing, and
|
reset to start a new gzip stream. If gz->direct is true, then simply write
|
||||||
ignore flush. */
|
to the output file without compressing, and ignore flush. */
|
||||||
local int gz_comp(state, flush)
|
local int gz_comp(gz_statep state, int flush) {
|
||||||
gz_statep state;
|
int ret, writ;
|
||||||
int flush;
|
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
|
||||||
{
|
|
||||||
int ret, got;
|
|
||||||
unsigned have;
|
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
|
|
||||||
/* allocate memory if this is the first time through */
|
/* allocate memory if this is the first time through */
|
||||||
@@ -81,15 +73,33 @@ local int gz_comp(state, flush)
|
|||||||
|
|
||||||
/* write directly if requested */
|
/* write directly if requested */
|
||||||
if (state->direct) {
|
if (state->direct) {
|
||||||
got = write(state->fd, strm->next_in, strm->avail_in);
|
while (strm->avail_in) {
|
||||||
if (got < 0 || (unsigned)got != strm->avail_in) {
|
errno = 0;
|
||||||
gz_error(state, Z_ERRNO, zstrerror());
|
state->again = 0;
|
||||||
return -1;
|
put = strm->avail_in > max ? max : strm->avail_in;
|
||||||
|
writ = (int)write(state->fd, strm->next_in, put);
|
||||||
|
if (writ < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
|
state->again = 1;
|
||||||
|
gz_error(state, Z_ERRNO, zstrerror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strm->avail_in -= (unsigned)writ;
|
||||||
|
strm->next_in += writ;
|
||||||
}
|
}
|
||||||
strm->avail_in = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check for a pending reset */
|
||||||
|
if (state->reset) {
|
||||||
|
/* don't start a new gzip member unless there is data to write and
|
||||||
|
we're not flushing */
|
||||||
|
if (strm->avail_in == 0 && flush == Z_NO_FLUSH)
|
||||||
|
return 0;
|
||||||
|
deflateReset(strm);
|
||||||
|
state->reset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* run deflate() on provided input until it produces no more output */
|
/* run deflate() on provided input until it produces no more output */
|
||||||
ret = Z_OK;
|
ret = Z_OK;
|
||||||
do {
|
do {
|
||||||
@@ -97,17 +107,25 @@ local int gz_comp(state, flush)
|
|||||||
doing Z_FINISH then don't write until we get to Z_STREAM_END */
|
doing Z_FINISH then don't write until we get to Z_STREAM_END */
|
||||||
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
||||||
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
||||||
have = (unsigned)(strm->next_out - state->x.next);
|
while (strm->next_out > state->x.next) {
|
||||||
if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
|
errno = 0;
|
||||||
(unsigned)got != have)) {
|
state->again = 0;
|
||||||
gz_error(state, Z_ERRNO, zstrerror());
|
put = strm->next_out - state->x.next > (int)max ? max :
|
||||||
return -1;
|
(unsigned)(strm->next_out - state->x.next);
|
||||||
|
writ = (int)write(state->fd, state->x.next, put);
|
||||||
|
if (writ < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
|
state->again = 1;
|
||||||
|
gz_error(state, Z_ERRNO, zstrerror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
state->x.next += writ;
|
||||||
}
|
}
|
||||||
if (strm->avail_out == 0) {
|
if (strm->avail_out == 0) {
|
||||||
strm->avail_out = state->size;
|
strm->avail_out = state->size;
|
||||||
strm->next_out = state->out;
|
strm->next_out = state->out;
|
||||||
|
state->x.next = state->out;
|
||||||
}
|
}
|
||||||
state->x.next = strm->next_out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compress */
|
/* compress */
|
||||||
@@ -123,18 +141,18 @@ local int gz_comp(state, flush)
|
|||||||
|
|
||||||
/* if that completed a deflate stream, allow another to start */
|
/* if that completed a deflate stream, allow another to start */
|
||||||
if (flush == Z_FINISH)
|
if (flush == Z_FINISH)
|
||||||
deflateReset(strm);
|
state->reset = 1;
|
||||||
|
|
||||||
/* all done, no errors */
|
/* all done, no errors */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compress len zeros to output. Return -1 on error, 0 on success. */
|
/* Compress state->skip (> 0) zeros to output. Return -1 on a write error or
|
||||||
local int gz_zero(state, len)
|
memory allocation failure by gz_comp(), or 0 on success. state->skip is
|
||||||
gz_statep state;
|
updated with the number of successfully written zeros, in case there is a
|
||||||
z_off64_t len;
|
stall on a non-blocking write destination. */
|
||||||
{
|
local int gz_zero(gz_statep state) {
|
||||||
int first;
|
int first, ret;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
z_streamp strm = &(state->strm);
|
z_streamp strm = &(state->strm);
|
||||||
|
|
||||||
@@ -142,51 +160,34 @@ local int gz_zero(state, len)
|
|||||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* compress len zeros (len guaranteed > 0) */
|
/* compress state->skip zeros */
|
||||||
first = 1;
|
first = 1;
|
||||||
while (len) {
|
do {
|
||||||
n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
|
n = GT_OFF(state->size) || (z_off64_t)state->size > state->skip ?
|
||||||
(unsigned)len : state->size;
|
(unsigned)state->skip : state->size;
|
||||||
if (first) {
|
if (first) {
|
||||||
memset(state->in, 0, n);
|
memset(state->in, 0, n);
|
||||||
first = 0;
|
first = 0;
|
||||||
}
|
}
|
||||||
strm->avail_in = n;
|
strm->avail_in = n;
|
||||||
strm->next_in = state->in;
|
strm->next_in = state->in;
|
||||||
|
ret = gz_comp(state, Z_NO_FLUSH);
|
||||||
|
n -= strm->avail_in;
|
||||||
state->x.pos += n;
|
state->x.pos += n;
|
||||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
state->skip -= n;
|
||||||
|
if (ret == -1)
|
||||||
return -1;
|
return -1;
|
||||||
len -= n;
|
} while (state->skip);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* Write len bytes from buf to file. Return the number of bytes written. If
|
||||||
int ZEXPORT gzwrite(file, buf, len)
|
the returned value is less than len, then there was an error. If the error
|
||||||
gzFile file;
|
was a non-blocking stall, then the number of bytes consumed is returned.
|
||||||
voidpc buf;
|
For any other error, 0 is returned. */
|
||||||
unsigned len;
|
local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
|
||||||
{
|
z_size_t put = len;
|
||||||
unsigned put = len;
|
int ret;
|
||||||
gz_statep state;
|
|
||||||
z_streamp strm;
|
|
||||||
|
|
||||||
/* get internal structure */
|
|
||||||
if (file == NULL)
|
|
||||||
return 0;
|
|
||||||
state = (gz_statep)file;
|
|
||||||
strm = &(state->strm);
|
|
||||||
|
|
||||||
/* check that we're writing and that there's no error */
|
|
||||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* since an int is returned, make sure len fits in one, otherwise return
|
|
||||||
with an error (this avoids the flaw in the interface) */
|
|
||||||
if ((int)len < 0) {
|
|
||||||
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if len is zero, avoid unnecessary operations */
|
/* if len is zero, avoid unnecessary operations */
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
@@ -197,55 +198,113 @@ int ZEXPORT gzwrite(file, buf, len)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
return 0;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* for small len, copy to input buffer, otherwise compress directly */
|
/* for small len, copy to input buffer, otherwise compress directly */
|
||||||
if (len < state->size) {
|
if (len < state->size) {
|
||||||
/* copy to input buffer, compress when full */
|
/* copy to input buffer, compress when full */
|
||||||
do {
|
for (;;) {
|
||||||
unsigned have, copy;
|
unsigned have, copy;
|
||||||
|
|
||||||
if (strm->avail_in == 0)
|
if (state->strm.avail_in == 0)
|
||||||
strm->next_in = state->in;
|
state->strm.next_in = state->in;
|
||||||
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
|
||||||
|
state->in);
|
||||||
copy = state->size - have;
|
copy = state->size - have;
|
||||||
if (copy > len)
|
if (copy > len)
|
||||||
copy = len;
|
copy = (unsigned)len;
|
||||||
memcpy(state->in + have, buf, copy);
|
memcpy(state->in + have, buf, copy);
|
||||||
strm->avail_in += copy;
|
state->strm.avail_in += copy;
|
||||||
state->x.pos += copy;
|
state->x.pos += copy;
|
||||||
buf = (const char *)buf + copy;
|
buf = (const char *)buf + copy;
|
||||||
len -= copy;
|
len -= copy;
|
||||||
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
|
if (len == 0)
|
||||||
return 0;
|
break;
|
||||||
} while (len);
|
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||||
|
return state->again ? put - len : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* consume whatever's left in the input buffer */
|
/* consume whatever's left in the input buffer */
|
||||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* directly compress user buffer to file */
|
/* directly compress user buffer to file */
|
||||||
strm->avail_in = len;
|
state->strm.next_in = (z_const Bytef *)buf;
|
||||||
strm->next_in = (z_const Bytef *)buf;
|
do {
|
||||||
state->x.pos += len;
|
unsigned n = (unsigned)-1;
|
||||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
|
||||||
return 0;
|
if (n > len)
|
||||||
|
n = (unsigned)len;
|
||||||
|
state->strm.avail_in = n;
|
||||||
|
ret = gz_comp(state, Z_NO_FLUSH);
|
||||||
|
n -= state->strm.avail_in;
|
||||||
|
state->x.pos += n;
|
||||||
|
len -= n;
|
||||||
|
if (ret == -1)
|
||||||
|
return state->again ? put - len : 0;
|
||||||
|
} while (len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* input was all buffered or compressed (put will fit in int) */
|
/* input was all buffered or compressed */
|
||||||
return (int)put;
|
return put;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzputc(file, c)
|
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
|
||||||
gzFile file;
|
gz_statep state;
|
||||||
int c;
|
|
||||||
{
|
/* get internal structure */
|
||||||
|
if (file == NULL)
|
||||||
|
return 0;
|
||||||
|
state = (gz_statep)file;
|
||||||
|
|
||||||
|
/* check that we're writing and that there's no (serious) error */
|
||||||
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
|
return 0;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
|
/* since an int is returned, make sure len fits in one, otherwise return
|
||||||
|
with an error (this avoids a flaw in the interface) */
|
||||||
|
if ((int)len < 0) {
|
||||||
|
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write len bytes from buf (the return value will fit in an int) */
|
||||||
|
return (int)gz_write(state, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- see zlib.h -- */
|
||||||
|
z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
|
||||||
|
gzFile file) {
|
||||||
|
z_size_t len;
|
||||||
|
gz_statep state;
|
||||||
|
|
||||||
|
/* get internal structure */
|
||||||
|
if (file == NULL)
|
||||||
|
return 0;
|
||||||
|
state = (gz_statep)file;
|
||||||
|
|
||||||
|
/* check that we're writing and that there's no (serious) error */
|
||||||
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
|
return 0;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
|
/* compute bytes to read -- error on overflow */
|
||||||
|
len = nitems * size;
|
||||||
|
if (size && len / size != nitems) {
|
||||||
|
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write len bytes to buf, return the number of full items written */
|
||||||
|
return len ? gz_write(state, buf, len) / size : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- see zlib.h -- */
|
||||||
|
int ZEXPORT gzputc(gzFile file, int c) {
|
||||||
unsigned have;
|
unsigned have;
|
||||||
unsigned char buf[1];
|
unsigned char buf[1];
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
@@ -257,16 +316,14 @@ int ZEXPORT gzputc(file, c)
|
|||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
strm = &(state->strm);
|
strm = &(state->strm);
|
||||||
|
|
||||||
/* check that we're writing and that there's no error */
|
/* check that we're writing and that there's no (serious) error */
|
||||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
return -1;
|
return -1;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
return -1;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try writing to input buffer for speed (state->size == 0 if buffer not
|
/* try writing to input buffer for speed (state->size == 0 if buffer not
|
||||||
initialized) */
|
initialized) */
|
||||||
@@ -275,7 +332,7 @@ int ZEXPORT gzputc(file, c)
|
|||||||
strm->next_in = state->in;
|
strm->next_in = state->in;
|
||||||
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
||||||
if (have < state->size) {
|
if (have < state->size) {
|
||||||
state->in[have] = c;
|
state->in[have] = (unsigned char)c;
|
||||||
strm->avail_in++;
|
strm->avail_in++;
|
||||||
state->x.pos++;
|
state->x.pos++;
|
||||||
return c & 0xff;
|
return c & 0xff;
|
||||||
@@ -283,94 +340,151 @@ int ZEXPORT gzputc(file, c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* no room in buffer or not initialized, use gz_write() */
|
/* no room in buffer or not initialized, use gz_write() */
|
||||||
buf[0] = c;
|
buf[0] = (unsigned char)c;
|
||||||
if (gzwrite(file, buf, 1) != 1)
|
if (gz_write(state, buf, 1) != 1)
|
||||||
return -1;
|
return -1;
|
||||||
return c & 0xff;
|
return c & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzputs(file, str)
|
int ZEXPORT gzputs(gzFile file, const char *s) {
|
||||||
gzFile file;
|
z_size_t len, put;
|
||||||
const char *str;
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
unsigned len;
|
|
||||||
|
|
||||||
/* write string */
|
|
||||||
len = (unsigned)strlen(str);
|
|
||||||
ret = gzwrite(file, str, len);
|
|
||||||
return ret == 0 && len != 0 ? -1 : ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
|
||||||
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
|
||||||
{
|
|
||||||
int size, len;
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
z_streamp strm;
|
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure */
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
|
|
||||||
|
/* check that we're writing and that there's no (serious) error */
|
||||||
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
|
return -1;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
|
/* write string */
|
||||||
|
len = strlen(s);
|
||||||
|
if ((int)len < 0 || (unsigned)len != len) {
|
||||||
|
gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
put = gz_write(state, s, len);
|
||||||
|
return len && put == 0 ? -1 : (int)put;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (((!defined(STDC) && !defined(Z_HAVE_STDARG_H)) || !defined(NO_vsnprintf)) && \
|
||||||
|
(defined(STDC) || defined(Z_HAVE_STDARG_H) || !defined(NO_snprintf))) || \
|
||||||
|
defined(ZLIB_INSECURE)
|
||||||
|
/* If the second half of the input buffer is occupied, write out the contents.
|
||||||
|
If there is any input remaining due to a non-blocking stall on write, move
|
||||||
|
it to the start of the buffer. Return true if this did not open up the
|
||||||
|
second half of the buffer. state->err should be checked after this to
|
||||||
|
handle a gz_comp() error. */
|
||||||
|
local int gz_vacate(gz_statep state) {
|
||||||
|
z_streamp strm;
|
||||||
|
|
||||||
|
strm = &(state->strm);
|
||||||
|
if (strm->next_in + strm->avail_in <= state->in + state->size)
|
||||||
|
return 0;
|
||||||
|
(void)gz_comp(state, Z_NO_FLUSH);
|
||||||
|
if (strm->avail_in == 0) {
|
||||||
|
strm->next_in = state->in;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memmove(state->in, strm->next_in, strm->avail_in);
|
||||||
|
strm->next_in = state->in;
|
||||||
|
return strm->avail_in > state->size;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
/* -- see zlib.h -- */
|
||||||
|
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
|
||||||
|
#if defined(NO_vsnprintf) && !defined(ZLIB_INSECURE)
|
||||||
|
#warning "vsnprintf() not available -- gzprintf() stub returns Z_STREAM_ERROR"
|
||||||
|
#warning "you can recompile with ZLIB_INSECURE defined to use vsprintf()"
|
||||||
|
/* prevent use of insecure vsprintf(), unless purposefully requested */
|
||||||
|
(void)file, (void)format, (void)va;
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
#else
|
||||||
|
int len, ret;
|
||||||
|
char *next;
|
||||||
|
gz_statep state;
|
||||||
|
z_streamp strm;
|
||||||
|
|
||||||
|
/* get internal structure */
|
||||||
|
if (file == NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
state = (gz_statep)file;
|
||||||
strm = &(state->strm);
|
strm = &(state->strm);
|
||||||
|
|
||||||
/* check that we're writing and that there's no error */
|
/* check that we're writing and that there's no (serious) error */
|
||||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
return 0;
|
return Z_STREAM_ERROR;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* make sure we have some buffer space */
|
/* make sure we have some buffer space */
|
||||||
if (state->size == 0 && gz_init(state) == -1)
|
if (state->size == 0 && gz_init(state) == -1)
|
||||||
return 0;
|
return state->err;
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
return state->err;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
return 0;
|
/* do the printf() into the input buffer, put length in len -- the input
|
||||||
|
buffer is double-sized just for this function, so there should be
|
||||||
|
state->size bytes available after the current contents */
|
||||||
|
ret = gz_vacate(state);
|
||||||
|
if (state->err) {
|
||||||
|
if (ret && state->again) {
|
||||||
|
/* There was a non-blocking stall on write, resulting in the part
|
||||||
|
of the second half of the output buffer being occupied. Return
|
||||||
|
a Z_BUF_ERROR to let the application know that this gzprintf()
|
||||||
|
needs to be retried. */
|
||||||
|
gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
|
||||||
|
}
|
||||||
|
if (!state->again)
|
||||||
|
return state->err;
|
||||||
}
|
}
|
||||||
|
if (strm->avail_in == 0)
|
||||||
/* consume whatever's left in the input buffer */
|
strm->next_in = state->in;
|
||||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
|
||||||
return 0;
|
next[state->size - 1] = 0;
|
||||||
|
|
||||||
/* do the printf() into the input buffer, put length in len */
|
|
||||||
size = (int)(state->size);
|
|
||||||
state->in[size - 1] = 0;
|
|
||||||
#ifdef NO_vsnprintf
|
#ifdef NO_vsnprintf
|
||||||
# ifdef HAS_vsprintf_void
|
# ifdef HAS_vsprintf_void
|
||||||
(void)vsprintf((char *)(state->in), format, va);
|
(void)vsprintf(next, format, va);
|
||||||
for (len = 0; len < size; len++)
|
for (len = 0; len < state->size; len++)
|
||||||
if (state->in[len] == 0) break;
|
if (next[len] == 0) break;
|
||||||
# else
|
# else
|
||||||
len = vsprintf((char *)(state->in), format, va);
|
len = vsprintf(next, format, va);
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# ifdef HAS_vsnprintf_void
|
# ifdef HAS_vsnprintf_void
|
||||||
(void)vsnprintf((char *)(state->in), size, format, va);
|
(void)vsnprintf(next, state->size, format, va);
|
||||||
len = strlen((char *)(state->in));
|
len = strlen(next);
|
||||||
# else
|
# else
|
||||||
len = vsnprintf((char *)(state->in), size, format, va);
|
len = vsnprintf(next, state->size, format, va);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check that printf() results fit in buffer */
|
/* check that printf() results fit in buffer */
|
||||||
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
|
if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* update buffer and position, defer compression until needed */
|
/* update buffer and position */
|
||||||
strm->avail_in = (unsigned)len;
|
strm->avail_in += (unsigned)len;
|
||||||
strm->next_in = state->in;
|
|
||||||
state->x.pos += len;
|
state->x.pos += len;
|
||||||
|
|
||||||
|
/* write out buffer if more than half is occupied */
|
||||||
|
ret = gz_vacate(state);
|
||||||
|
if (state->err && !state->again)
|
||||||
|
return state->err;
|
||||||
return len;
|
return len;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
|
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
|
||||||
{
|
|
||||||
va_list va;
|
va_list va;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -383,122 +497,137 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
|
|||||||
#else /* !STDC && !Z_HAVE_STDARG_H */
|
#else /* !STDC && !Z_HAVE_STDARG_H */
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
|
||||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
int a4, int a5, int a6, int a7, int a8, int a9, int a10,
|
||||||
gzFile file;
|
int a11, int a12, int a13, int a14, int a15, int a16,
|
||||||
const char *format;
|
int a17, int a18, int a19, int a20) {
|
||||||
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
#if defined(NO_snprintf) && !defined(ZLIB_INSECURE)
|
||||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
#warning "snprintf() not available -- gzprintf() stub returns Z_STREAM_ERROR"
|
||||||
{
|
#warning "you can recompile with ZLIB_INSECURE defined to use sprintf()"
|
||||||
int size, len;
|
/* prevent use of insecure sprintf(), unless purposefully requested */
|
||||||
|
(void)file, (void)format, (void)a1, (void)a2, (void)a3, (void)a4, (void)a5,
|
||||||
|
(void)a6, (void)a7, (void)a8, (void)a9, (void)a10, (void)a11, (void)a12,
|
||||||
|
(void)a13, (void)a14, (void)a15, (void)a16, (void)a17, (void)a18,
|
||||||
|
(void)a19, (void)a20;
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
#else
|
||||||
|
int ret;
|
||||||
|
unsigned len, left;
|
||||||
|
char *next;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure */
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return -1;
|
return Z_STREAM_ERROR;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
strm = &(state->strm);
|
strm = &(state->strm);
|
||||||
|
|
||||||
/* check that can really pass pointer in ints */
|
/* check that can really pass pointer in ints */
|
||||||
if (sizeof(int) != sizeof(void *))
|
if (sizeof(int) != sizeof(void *))
|
||||||
return 0;
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
/* check that we're writing and that there's no error */
|
/* check that we're writing and that there's no (serious) error */
|
||||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
return 0;
|
return Z_STREAM_ERROR;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* make sure we have some buffer space */
|
/* make sure we have some buffer space */
|
||||||
if (state->size == 0 && gz_init(state) == -1)
|
if (state->size == 0 && gz_init(state) == -1)
|
||||||
return 0;
|
return state->err;
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
return state->err;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
return 0;
|
/* do the printf() into the input buffer, put length in len -- the input
|
||||||
|
buffer is double-sized just for this function, so there is guaranteed to
|
||||||
|
be state->size bytes available after the current contents */
|
||||||
|
ret = gz_vacate(state);
|
||||||
|
if (state->err) {
|
||||||
|
if (ret && state->again) {
|
||||||
|
/* There was a non-blocking stall on write, resulting in the part
|
||||||
|
of the second half of the output buffer being occupied. Return
|
||||||
|
a Z_BUF_ERROR to let the application know that this gzprintf()
|
||||||
|
needs to be retried. */
|
||||||
|
gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
|
||||||
|
}
|
||||||
|
if (!state->again)
|
||||||
|
return state->err;
|
||||||
}
|
}
|
||||||
|
if (strm->avail_in == 0)
|
||||||
/* consume whatever's left in the input buffer */
|
strm->next_in = state->in;
|
||||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
next = (char *)(strm->next_in + strm->avail_in);
|
||||||
return 0;
|
next[state->size - 1] = 0;
|
||||||
|
|
||||||
/* do the printf() into the input buffer, put length in len */
|
|
||||||
size = (int)(state->size);
|
|
||||||
state->in[size - 1] = 0;
|
|
||||||
#ifdef NO_snprintf
|
#ifdef NO_snprintf
|
||||||
# ifdef HAS_sprintf_void
|
# ifdef HAS_sprintf_void
|
||||||
sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
|
||||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
a13, a14, a15, a16, a17, a18, a19, a20);
|
||||||
for (len = 0; len < size; len++)
|
for (len = 0; len < size; len++)
|
||||||
if (state->in[len] == 0) break;
|
if (next[len] == 0)
|
||||||
|
break;
|
||||||
# else
|
# else
|
||||||
len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
|
||||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# ifdef HAS_snprintf_void
|
# ifdef HAS_snprintf_void
|
||||||
snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
|
||||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||||
len = strlen((char *)(state->in));
|
len = strlen(next);
|
||||||
# else
|
# else
|
||||||
len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
|
len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||||
a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
|
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||||
a19, a20);
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check that printf() results fit in buffer */
|
/* check that printf() results fit in buffer */
|
||||||
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
|
if (len == 0 || len >= state->size || next[state->size - 1] != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* update buffer and position, defer compression until needed */
|
/* update buffer and position, compress first half if past that */
|
||||||
strm->avail_in = (unsigned)len;
|
strm->avail_in += len;
|
||||||
strm->next_in = state->in;
|
|
||||||
state->x.pos += len;
|
state->x.pos += len;
|
||||||
return len;
|
|
||||||
|
/* write out buffer if more than half is occupied */
|
||||||
|
ret = gz_vacate(state);
|
||||||
|
if (state->err && !state->again)
|
||||||
|
return state->err;
|
||||||
|
return (int)len;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzflush(file, flush)
|
int ZEXPORT gzflush(gzFile file, int flush) {
|
||||||
gzFile file;
|
|
||||||
int flush;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
/* get internal structure */
|
/* get internal structure */
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return -1;
|
return Z_STREAM_ERROR;
|
||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
|
|
||||||
/* check that we're writing and that there's no error */
|
/* check that we're writing and that there's no (serious) error */
|
||||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* check flush parameter */
|
/* check flush parameter */
|
||||||
if (flush < 0 || flush > Z_FINISH)
|
if (flush < 0 || flush > Z_FINISH)
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
return state->err;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* compress remaining data with requested flush */
|
/* compress remaining data with requested flush */
|
||||||
gz_comp(state, flush);
|
(void)gz_comp(state, flush);
|
||||||
return state->err;
|
return state->err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzsetparams(file, level, strategy)
|
int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||||
gzFile file;
|
|
||||||
int level;
|
|
||||||
int strategy;
|
|
||||||
{
|
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
|
|
||||||
@@ -508,25 +637,24 @@ int ZEXPORT gzsetparams(file, level, strategy)
|
|||||||
state = (gz_statep)file;
|
state = (gz_statep)file;
|
||||||
strm = &(state->strm);
|
strm = &(state->strm);
|
||||||
|
|
||||||
/* check that we're writing and that there's no error */
|
/* check that we're compressing and that there's no (serious) error */
|
||||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again) ||
|
||||||
|
state->direct)
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
gz_error(state, Z_OK, NULL);
|
||||||
|
|
||||||
/* if no change is requested, then do nothing */
|
/* if no change is requested, then do nothing */
|
||||||
if (level == state->level && strategy == state->strategy)
|
if (level == state->level && strategy == state->strategy)
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
return state->err;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* change compression parameters for subsequent input */
|
/* change compression parameters for subsequent input */
|
||||||
if (state->size) {
|
if (state->size) {
|
||||||
/* flush previous input with previous parameters before changing */
|
/* flush previous input with previous parameters before changing */
|
||||||
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
|
if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
|
||||||
return state->err;
|
return state->err;
|
||||||
deflateParams(strm, level, strategy);
|
deflateParams(strm, level, strategy);
|
||||||
}
|
}
|
||||||
@@ -536,9 +664,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
int ZEXPORT gzclose_w(file)
|
int ZEXPORT gzclose_w(gzFile file) {
|
||||||
gzFile file;
|
|
||||||
{
|
|
||||||
int ret = Z_OK;
|
int ret = Z_OK;
|
||||||
gz_statep state;
|
gz_statep state;
|
||||||
|
|
||||||
@@ -552,11 +678,8 @@ int ZEXPORT gzclose_w(file)
|
|||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
/* check for seek request */
|
/* check for seek request */
|
||||||
if (state->seek) {
|
if (state->skip && gz_zero(state) == -1)
|
||||||
state->seek = 0;
|
ret = state->err;
|
||||||
if (gz_zero(state, state->skip) == -1)
|
|
||||||
ret = state->err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* flush, free memory, and close file */
|
/* flush, free memory, and close file */
|
||||||
if (gz_comp(state, Z_FINISH) == -1)
|
if (gz_comp(state, Z_FINISH) == -1)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* infback.c -- inflate using a call-back interface
|
/* infback.c -- inflate using a call-back interface
|
||||||
* Copyright (C) 1995-2011 Mark Adler
|
* Copyright (C) 1995-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -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));
|
|||||||
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] ||
|
||||||
@@ -53,7 +46,7 @@ int stream_size;
|
|||||||
#ifdef Z_SOLO
|
#ifdef Z_SOLO
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
#else
|
#else
|
||||||
strm->zfree = zcfree;
|
strm->zfree = zcfree;
|
||||||
#endif
|
#endif
|
||||||
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
|
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
|
||||||
sizeof(struct inflate_state));
|
sizeof(struct inflate_state));
|
||||||
@@ -61,67 +54,15 @@ int stream_size;
|
|||||||
Tracev((stderr, "inflate: allocated\n"));
|
Tracev((stderr, "inflate: allocated\n"));
|
||||||
strm->state = (struct internal_state FAR *)state;
|
strm->state = (struct internal_state FAR *)state;
|
||||||
state->dmax = 32768U;
|
state->dmax = 32768U;
|
||||||
state->wbits = windowBits;
|
state->wbits = (uInt)windowBits;
|
||||||
state->wsize = 1U << windowBits;
|
state->wsize = 1U << windowBits;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Return state with length and distance decoding tables and index sizes set to
|
|
||||||
fixed code decoding. Normally this returns fixed tables from inffixed.h.
|
|
||||||
If BUILDFIXED is defined, then instead this routine builds the tables the
|
|
||||||
first time it's called, and returns those tables the first time and
|
|
||||||
thereafter. This reduces the size of the code by about 2K bytes, in
|
|
||||||
exchange for a little execution time. However, BUILDFIXED should not be
|
|
||||||
used for threaded applications, since the rewriting of the tables and virgin
|
|
||||||
may not be thread-safe.
|
|
||||||
*/
|
|
||||||
local void fixedtables(state)
|
|
||||||
struct inflate_state FAR *state;
|
|
||||||
{
|
|
||||||
#ifdef BUILDFIXED
|
|
||||||
static int virgin = 1;
|
|
||||||
static code *lenfix, *distfix;
|
|
||||||
static code fixed[544];
|
|
||||||
|
|
||||||
/* build fixed huffman tables if first call (may not be thread safe) */
|
|
||||||
if (virgin) {
|
|
||||||
unsigned sym, bits;
|
|
||||||
static code *next;
|
|
||||||
|
|
||||||
/* literal/length table */
|
|
||||||
sym = 0;
|
|
||||||
while (sym < 144) state->lens[sym++] = 8;
|
|
||||||
while (sym < 256) state->lens[sym++] = 9;
|
|
||||||
while (sym < 280) state->lens[sym++] = 7;
|
|
||||||
while (sym < 288) state->lens[sym++] = 8;
|
|
||||||
next = fixed;
|
|
||||||
lenfix = next;
|
|
||||||
bits = 9;
|
|
||||||
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
|
|
||||||
|
|
||||||
/* distance table */
|
|
||||||
sym = 0;
|
|
||||||
while (sym < 32) state->lens[sym++] = 5;
|
|
||||||
distfix = next;
|
|
||||||
bits = 5;
|
|
||||||
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
|
|
||||||
|
|
||||||
/* do this just once */
|
|
||||||
virgin = 0;
|
|
||||||
}
|
|
||||||
#else /* !BUILDFIXED */
|
|
||||||
# include "inffixed.h"
|
|
||||||
#endif /* BUILDFIXED */
|
|
||||||
state->lencode = lenfix;
|
|
||||||
state->lenbits = 9;
|
|
||||||
state->distcode = distfix;
|
|
||||||
state->distbits = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Macros for inflateBack(): */
|
/* Macros for inflateBack(): */
|
||||||
|
|
||||||
/* Load returned state from inflate_fast() */
|
/* Load returned state from inflate_fast() */
|
||||||
@@ -247,13 +188,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 */
|
||||||
@@ -306,7 +242,7 @@ void FAR *out_desc;
|
|||||||
state->mode = STORED;
|
state->mode = STORED;
|
||||||
break;
|
break;
|
||||||
case 1: /* fixed block */
|
case 1: /* fixed block */
|
||||||
fixedtables(state);
|
inflate_fixed(state);
|
||||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||||
state->last ? " (last)" : ""));
|
state->last ? " (last)" : ""));
|
||||||
state->mode = LEN; /* decode codes */
|
state->mode = LEN; /* decode codes */
|
||||||
@@ -316,8 +252,8 @@ void FAR *out_desc;
|
|||||||
state->last ? " (last)" : ""));
|
state->last ? " (last)" : ""));
|
||||||
state->mode = TABLE;
|
state->mode = TABLE;
|
||||||
break;
|
break;
|
||||||
case 3:
|
default:
|
||||||
strm->msg = (char *)"invalid block type";
|
strm->msg = (z_const char *)"invalid block type";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
}
|
}
|
||||||
DROPBITS(2);
|
DROPBITS(2);
|
||||||
@@ -328,7 +264,7 @@ void FAR *out_desc;
|
|||||||
BYTEBITS(); /* go to byte boundary */
|
BYTEBITS(); /* go to byte boundary */
|
||||||
NEEDBITS(32);
|
NEEDBITS(32);
|
||||||
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
|
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
|
||||||
strm->msg = (char *)"invalid stored block lengths";
|
strm->msg = (z_const char *)"invalid stored block lengths";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -366,7 +302,8 @@ void FAR *out_desc;
|
|||||||
DROPBITS(4);
|
DROPBITS(4);
|
||||||
#ifndef PKZIP_BUG_WORKAROUND
|
#ifndef PKZIP_BUG_WORKAROUND
|
||||||
if (state->nlen > 286 || state->ndist > 30) {
|
if (state->nlen > 286 || state->ndist > 30) {
|
||||||
strm->msg = (char *)"too many length or distance symbols";
|
strm->msg = (z_const char *)
|
||||||
|
"too many length or distance symbols";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -388,7 +325,7 @@ void FAR *out_desc;
|
|||||||
ret = inflate_table(CODES, state->lens, 19, &(state->next),
|
ret = inflate_table(CODES, state->lens, 19, &(state->next),
|
||||||
&(state->lenbits), state->work);
|
&(state->lenbits), state->work);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
strm->msg = (char *)"invalid code lengths set";
|
strm->msg = (z_const char *)"invalid code lengths set";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -411,7 +348,8 @@ void FAR *out_desc;
|
|||||||
NEEDBITS(here.bits + 2);
|
NEEDBITS(here.bits + 2);
|
||||||
DROPBITS(here.bits);
|
DROPBITS(here.bits);
|
||||||
if (state->have == 0) {
|
if (state->have == 0) {
|
||||||
strm->msg = (char *)"invalid bit length repeat";
|
strm->msg = (z_const char *)
|
||||||
|
"invalid bit length repeat";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -434,7 +372,8 @@ void FAR *out_desc;
|
|||||||
DROPBITS(7);
|
DROPBITS(7);
|
||||||
}
|
}
|
||||||
if (state->have + copy > state->nlen + state->ndist) {
|
if (state->have + copy > state->nlen + state->ndist) {
|
||||||
strm->msg = (char *)"invalid bit length repeat";
|
strm->msg = (z_const char *)
|
||||||
|
"invalid bit length repeat";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -448,7 +387,8 @@ void FAR *out_desc;
|
|||||||
|
|
||||||
/* check for end-of-block code (better have one) */
|
/* check for end-of-block code (better have one) */
|
||||||
if (state->lens[256] == 0) {
|
if (state->lens[256] == 0) {
|
||||||
strm->msg = (char *)"invalid code -- missing end-of-block";
|
strm->msg = (z_const char *)
|
||||||
|
"invalid code -- missing end-of-block";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -462,7 +402,7 @@ void FAR *out_desc;
|
|||||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||||
&(state->lenbits), state->work);
|
&(state->lenbits), state->work);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
strm->msg = (char *)"invalid literal/lengths set";
|
strm->msg = (z_const char *)"invalid literal/lengths set";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -471,19 +411,18 @@ void FAR *out_desc;
|
|||||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||||
&(state->next), &(state->distbits), state->work);
|
&(state->next), &(state->distbits), state->work);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
strm->msg = (char *)"invalid distances set";
|
strm->msg = (z_const char *)"invalid distances set";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Tracev((stderr, "inflate: codes ok\n"));
|
Tracev((stderr, "inflate: codes ok\n"));
|
||||||
state->mode = LEN;
|
state->mode = LEN;
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case LEN:
|
case LEN:
|
||||||
/* use inflate_fast() if we have enough input and output */
|
/* use inflate_fast() if we have enough input and output */
|
||||||
if (have >= 6 && left >= 258) {
|
if (have >= 6 && left >= 258) {
|
||||||
RESTORE();
|
RESTORE();
|
||||||
if (state->whave < state->wsize)
|
|
||||||
state->whave = state->wsize - left;
|
|
||||||
inflate_fast(strm, state->wsize);
|
inflate_fast(strm, state->wsize);
|
||||||
LOAD();
|
LOAD();
|
||||||
break;
|
break;
|
||||||
@@ -529,7 +468,7 @@ void FAR *out_desc;
|
|||||||
|
|
||||||
/* invalid code */
|
/* invalid code */
|
||||||
if (here.op & 64) {
|
if (here.op & 64) {
|
||||||
strm->msg = (char *)"invalid literal/length code";
|
strm->msg = (z_const char *)"invalid literal/length code";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -561,7 +500,7 @@ void FAR *out_desc;
|
|||||||
}
|
}
|
||||||
DROPBITS(here.bits);
|
DROPBITS(here.bits);
|
||||||
if (here.op & 64) {
|
if (here.op & 64) {
|
||||||
strm->msg = (char *)"invalid distance code";
|
strm->msg = (z_const char *)"invalid distance code";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -576,7 +515,7 @@ void FAR *out_desc;
|
|||||||
}
|
}
|
||||||
if (state->offset > state->wsize - (state->whave < state->wsize ?
|
if (state->offset > state->wsize - (state->whave < state->wsize ?
|
||||||
left : 0)) {
|
left : 0)) {
|
||||||
strm->msg = (char *)"invalid distance too far back";
|
strm->msg = (z_const char *)"invalid distance too far back";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -604,33 +543,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);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* inffast.c -- fast decoding
|
/* inffast.c -- fast decoding
|
||||||
* Copyright (C) 1995-2008, 2010, 2013 Mark Adler
|
* Copyright (C) 1995-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,26 +8,9 @@
|
|||||||
#include "inflate.h"
|
#include "inflate.h"
|
||||||
#include "inffast.h"
|
#include "inffast.h"
|
||||||
|
|
||||||
#ifndef ASMINF
|
#ifdef ASMINF
|
||||||
|
# pragma message("Assembler code may have bugs -- use at your own risk")
|
||||||
/* Allow machine dependent optimization for post-increment or pre-increment.
|
|
||||||
Based on testing to date,
|
|
||||||
Pre-increment preferred for:
|
|
||||||
- PowerPC G3 (Adler)
|
|
||||||
- MIPS R5000 (Randers-Pehrson)
|
|
||||||
Post-increment preferred for:
|
|
||||||
- none
|
|
||||||
No measurable difference:
|
|
||||||
- Pentium III (Anderson)
|
|
||||||
- M68060 (Nikl)
|
|
||||||
*/
|
|
||||||
#ifdef POSTINC
|
|
||||||
# define OFF 0
|
|
||||||
# define PUP(a) *(a)++
|
|
||||||
#else
|
#else
|
||||||
# define OFF 1
|
|
||||||
# define PUP(a) *++(a)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Decode literal, length, and distance codes and write out the resulting
|
Decode literal, length, and distance codes and write out the resulting
|
||||||
@@ -64,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 */
|
||||||
@@ -87,7 +67,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
code const FAR *dcode; /* local strm->distcode */
|
code const FAR *dcode; /* local strm->distcode */
|
||||||
unsigned lmask; /* mask for first level of length codes */
|
unsigned lmask; /* mask for first level of length codes */
|
||||||
unsigned dmask; /* mask for first level of distance codes */
|
unsigned dmask; /* mask for first level of distance codes */
|
||||||
code here; /* retrieved table entry */
|
code const *here; /* retrieved table entry */
|
||||||
unsigned op; /* code bits, operation, extra bits, or */
|
unsigned op; /* code bits, operation, extra bits, or */
|
||||||
/* window position, window bytes to copy */
|
/* window position, window bytes to copy */
|
||||||
unsigned len; /* match length, unused bytes */
|
unsigned len; /* match length, unused bytes */
|
||||||
@@ -96,9 +76,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
|
|
||||||
/* copy state to local variables */
|
/* copy state to local variables */
|
||||||
state = (struct inflate_state FAR *)strm->state;
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
in = strm->next_in - OFF;
|
in = strm->next_in;
|
||||||
last = in + (strm->avail_in - 5);
|
last = in + (strm->avail_in - 5);
|
||||||
out = strm->next_out - OFF;
|
out = strm->next_out;
|
||||||
beg = out - (start - strm->avail_out);
|
beg = out - (start - strm->avail_out);
|
||||||
end = out + (strm->avail_out - 257);
|
end = out + (strm->avail_out - 257);
|
||||||
#ifdef INFLATE_STRICT
|
#ifdef INFLATE_STRICT
|
||||||
@@ -119,29 +99,29 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
input data or output space */
|
input data or output space */
|
||||||
do {
|
do {
|
||||||
if (bits < 15) {
|
if (bits < 15) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
here = lcode[hold & lmask];
|
here = lcode + (hold & lmask);
|
||||||
dolen:
|
dolen:
|
||||||
op = (unsigned)(here.bits);
|
op = (unsigned)(here->bits);
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
op = (unsigned)(here.op);
|
op = (unsigned)(here->op);
|
||||||
if (op == 0) { /* literal */
|
if (op == 0) { /* literal */
|
||||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
||||||
"inflate: literal '%c'\n" :
|
"inflate: literal '%c'\n" :
|
||||||
"inflate: literal 0x%02x\n", here.val));
|
"inflate: literal 0x%02x\n", here->val));
|
||||||
PUP(out) = (unsigned char)(here.val);
|
*out++ = (unsigned char)(here->val);
|
||||||
}
|
}
|
||||||
else if (op & 16) { /* length base */
|
else if (op & 16) { /* length base */
|
||||||
len = (unsigned)(here.val);
|
len = (unsigned)(here->val);
|
||||||
op &= 15; /* number of extra bits */
|
op &= 15; /* number of extra bits */
|
||||||
if (op) {
|
if (op) {
|
||||||
if (bits < op) {
|
if (bits < op) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
len += (unsigned)hold & ((1U << op) - 1);
|
len += (unsigned)hold & ((1U << op) - 1);
|
||||||
@@ -150,32 +130,33 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
}
|
}
|
||||||
Tracevv((stderr, "inflate: length %u\n", len));
|
Tracevv((stderr, "inflate: length %u\n", len));
|
||||||
if (bits < 15) {
|
if (bits < 15) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
here = dcode[hold & dmask];
|
here = dcode + (hold & dmask);
|
||||||
dodist:
|
dodist:
|
||||||
op = (unsigned)(here.bits);
|
op = (unsigned)(here->bits);
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
op = (unsigned)(here.op);
|
op = (unsigned)(here->op);
|
||||||
if (op & 16) { /* distance base */
|
if (op & 16) { /* distance base */
|
||||||
dist = (unsigned)(here.val);
|
dist = (unsigned)(here->val);
|
||||||
op &= 15; /* number of extra bits */
|
op &= 15; /* number of extra bits */
|
||||||
if (bits < op) {
|
if (bits < op) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
if (bits < op) {
|
if (bits < op) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(*in++) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dist += (unsigned)hold & ((1U << op) - 1);
|
dist += (unsigned)hold & ((1U << op) - 1);
|
||||||
#ifdef INFLATE_STRICT
|
#ifdef INFLATE_STRICT
|
||||||
if (dist > dmax) {
|
if (dist > dmax) {
|
||||||
strm->msg = (char *)"invalid distance too far back";
|
strm->msg = (z_const char *)
|
||||||
|
"invalid distance too far back";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -188,38 +169,38 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
op = dist - op; /* distance back in window */
|
op = dist - op; /* distance back in window */
|
||||||
if (op > whave) {
|
if (op > whave) {
|
||||||
if (state->sane) {
|
if (state->sane) {
|
||||||
strm->msg =
|
strm->msg = (z_const char *)
|
||||||
(char *)"invalid distance too far back";
|
"invalid distance too far back";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||||
if (len <= op - whave) {
|
if (len <= op - whave) {
|
||||||
do {
|
do {
|
||||||
PUP(out) = 0;
|
*out++ = 0;
|
||||||
} while (--len);
|
} while (--len);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
len -= op - whave;
|
len -= op - whave;
|
||||||
do {
|
do {
|
||||||
PUP(out) = 0;
|
*out++ = 0;
|
||||||
} while (--op > whave);
|
} while (--op > whave);
|
||||||
if (op == 0) {
|
if (op == 0) {
|
||||||
from = out - dist;
|
from = out - dist;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
} while (--len);
|
} while (--len);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
from = window - OFF;
|
from = window;
|
||||||
if (wnext == 0) { /* very common case */
|
if (wnext == 0) { /* very common case */
|
||||||
from += wsize - op;
|
from += wsize - op;
|
||||||
if (op < len) { /* some from window */
|
if (op < len) { /* some from window */
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = out - dist; /* rest from output */
|
from = out - dist; /* rest from output */
|
||||||
}
|
}
|
||||||
@@ -230,14 +211,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
if (op < len) { /* some from end of window */
|
if (op < len) { /* some from end of window */
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = window - OFF;
|
from = window;
|
||||||
if (wnext < len) { /* some from start of window */
|
if (wnext < len) { /* some from start of window */
|
||||||
op = wnext;
|
op = wnext;
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = out - dist; /* rest from output */
|
from = out - dist; /* rest from output */
|
||||||
}
|
}
|
||||||
@@ -248,50 +229,50 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
if (op < len) { /* some from window */
|
if (op < len) { /* some from window */
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = out - dist; /* rest from output */
|
from = out - dist; /* rest from output */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (len > 2) {
|
while (len > 2) {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
len -= 3;
|
len -= 3;
|
||||||
}
|
}
|
||||||
if (len) {
|
if (len) {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
from = out - dist; /* copy direct from output */
|
from = out - dist; /* copy direct from output */
|
||||||
do { /* minimum length is three */
|
do { /* minimum length is three */
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
len -= 3;
|
len -= 3;
|
||||||
} while (len > 2);
|
} while (len > 2);
|
||||||
if (len) {
|
if (len) {
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
PUP(out) = PUP(from);
|
*out++ = *from++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((op & 64) == 0) { /* 2nd level distance code */
|
else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||||
here = dcode[here.val + (hold & ((1U << op) - 1))];
|
here = dcode + here->val + (hold & ((1U << op) - 1));
|
||||||
goto dodist;
|
goto dodist;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strm->msg = (char *)"invalid distance code";
|
strm->msg = (z_const char *)"invalid distance code";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((op & 64) == 0) { /* 2nd level length code */
|
else if ((op & 64) == 0) { /* 2nd level length code */
|
||||||
here = lcode[here.val + (hold & ((1U << op) - 1))];
|
here = lcode + here->val + (hold & ((1U << op) - 1));
|
||||||
goto dolen;
|
goto dolen;
|
||||||
}
|
}
|
||||||
else if (op & 32) { /* end-of-block */
|
else if (op & 32) { /* end-of-block */
|
||||||
@@ -300,7 +281,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strm->msg = (char *)"invalid literal/length code";
|
strm->msg = (z_const char *)"invalid literal/length code";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -313,8 +294,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
|||||||
hold &= (1U << bits) - 1;
|
hold &= (1U << bits) - 1;
|
||||||
|
|
||||||
/* update state and return */
|
/* update state and return */
|
||||||
strm->next_in = in + OFF;
|
strm->next_in = in;
|
||||||
strm->next_out = out + OFF;
|
strm->next_out = out;
|
||||||
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
||||||
strm->avail_out = (unsigned)(out < end ?
|
strm->avail_out = (unsigned)(out < end ?
|
||||||
257 + (end - out) : 257 - (out - end));
|
257 + (end - out) : 257 - (out - end));
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,94 +1,94 @@
|
|||||||
/* inffixed.h -- table for decoding fixed codes
|
/* inffixed.h -- table for decoding fixed codes
|
||||||
* Generated automatically by makefixed().
|
* Generated automatically by makefixed().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* WARNING: this file should *not* be used by applications.
|
/* WARNING: this file should *not* be used by applications.
|
||||||
It is part of the implementation of this library and is
|
It is part of the implementation of this library and is
|
||||||
subject to change. Applications should only use zlib.h.
|
subject to change. Applications should only use zlib.h.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const code lenfix[512] = {
|
static const code lenfix[512] = {
|
||||||
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
|
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
|
||||||
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
|
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
|
||||||
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
|
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
|
||||||
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
|
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
|
||||||
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
|
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
|
||||||
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
|
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
|
||||||
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
|
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
|
||||||
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
|
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
|
||||||
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
|
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
|
||||||
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
|
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
|
||||||
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
|
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
|
||||||
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
|
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
|
||||||
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
|
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
|
||||||
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
|
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
|
||||||
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
|
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
|
||||||
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
|
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
|
||||||
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
|
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
|
||||||
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
|
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
|
||||||
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
|
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
|
||||||
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
|
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
|
||||||
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
|
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
|
||||||
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
|
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
|
||||||
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
|
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
|
||||||
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
|
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
|
||||||
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
|
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
|
||||||
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
|
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
|
||||||
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
|
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
|
||||||
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
|
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
|
||||||
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
|
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
|
||||||
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
|
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
|
||||||
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
|
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
|
||||||
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
|
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
|
||||||
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
|
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
|
||||||
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
|
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
|
||||||
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
|
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
|
||||||
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
|
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
|
||||||
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
|
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
|
||||||
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
|
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
|
||||||
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
|
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
|
||||||
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
|
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
|
||||||
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
|
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
|
||||||
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
|
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
|
||||||
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
|
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
|
||||||
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
|
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
|
||||||
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
|
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
|
||||||
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
|
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
|
||||||
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
|
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
|
||||||
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
|
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
|
||||||
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
|
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
|
||||||
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
|
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
|
||||||
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
|
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
|
||||||
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
|
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
|
||||||
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
|
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
|
||||||
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
|
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
|
||||||
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
|
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
|
||||||
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
|
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
|
||||||
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
|
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
|
||||||
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
|
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
|
||||||
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
|
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
|
||||||
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
|
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
|
||||||
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
|
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
|
||||||
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
|
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
|
||||||
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
|
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
|
||||||
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
|
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
|
||||||
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
|
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
|
||||||
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
|
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
|
||||||
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
|
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
|
||||||
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
|
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
|
||||||
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
|
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
|
||||||
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
|
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
|
||||||
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
|
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
|
||||||
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
|
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
|
||||||
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
|
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
|
||||||
{0,9,255}
|
{0,9,255}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const code distfix[32] = {
|
static const code distfix[32] = {
|
||||||
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
|
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
|
||||||
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
|
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
|
||||||
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
|
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
|
||||||
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
|
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
|
||||||
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
|
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
|
||||||
{22,5,193},{64,5,0}
|
{22,5,193},{64,5,0}
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/* inflate.h -- internal inflate state definition
|
/* inflate.h -- internal inflate state definition
|
||||||
* Copyright (C) 1995-2009 Mark Adler
|
* Copyright (C) 1995-2019 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
/* Possible inflate modes between inflate() calls */
|
/* Possible inflate modes between inflate() calls */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HEAD, /* i: waiting for magic header */
|
HEAD = 16180, /* i: waiting for magic header */
|
||||||
FLAGS, /* i: waiting for method and flags (gzip) */
|
FLAGS, /* i: waiting for method and flags (gzip) */
|
||||||
TIME, /* i: waiting for modification time (gzip) */
|
TIME, /* i: waiting for modification time (gzip) */
|
||||||
OS, /* i: waiting for extra flags and operating system (gzip) */
|
OS, /* i: waiting for extra flags and operating system (gzip) */
|
||||||
@@ -77,13 +77,17 @@ typedef enum {
|
|||||||
CHECK -> LENGTH -> DONE
|
CHECK -> LENGTH -> DONE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* state maintained between inflate() calls. Approximately 10K bytes. */
|
/* State maintained between inflate() calls -- approximately 7K bytes, not
|
||||||
|
including the allocated sliding window, which is up to 32K bytes. */
|
||||||
struct inflate_state {
|
struct inflate_state {
|
||||||
|
z_streamp strm; /* pointer back to this zlib stream */
|
||||||
inflate_mode mode; /* current inflate mode */
|
inflate_mode mode; /* current inflate mode */
|
||||||
int last; /* true if processing last block */
|
int last; /* true if processing last block */
|
||||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
|
||||||
|
bit 2 true to validate check value */
|
||||||
int havedict; /* true if dictionary provided */
|
int havedict; /* true if dictionary provided */
|
||||||
int flags; /* gzip header method and flags (0 if zlib) */
|
int flags; /* gzip header method and flags, 0 if zlib, or
|
||||||
|
-1 if raw or no header yet */
|
||||||
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
||||||
unsigned long check; /* protected copy of check value */
|
unsigned long check; /* protected copy of check value */
|
||||||
unsigned long total; /* protected copy of output count */
|
unsigned long total; /* protected copy of output count */
|
||||||
@@ -96,7 +100,7 @@ struct inflate_state {
|
|||||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||||
/* bit accumulator */
|
/* bit accumulator */
|
||||||
unsigned long hold; /* input bit accumulator */
|
unsigned long hold; /* input bit accumulator */
|
||||||
unsigned bits; /* number of bits in "in" */
|
unsigned bits; /* number of bits in hold */
|
||||||
/* for string and stored block copying */
|
/* for string and stored block copying */
|
||||||
unsigned length; /* literal or length of data to copy */
|
unsigned length; /* literal or length of data to copy */
|
||||||
unsigned offset; /* distance back to copy string from */
|
unsigned offset; /* distance back to copy string from */
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||||
* Copyright (C) 1995-2013 Mark Adler
|
* Copyright (C) 1995-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef MAKEFIXED
|
||||||
|
# ifndef BUILDFIXED
|
||||||
|
# define BUILDFIXED
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifdef BUILDFIXED
|
||||||
|
# define Z_ONCE
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "zutil.h"
|
#include "zutil.h"
|
||||||
#include "inftrees.h"
|
#include "inftrees.h"
|
||||||
|
#include "inflate.h"
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
# define NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAXBITS 15
|
#define MAXBITS 15
|
||||||
|
|
||||||
const char inflate_copyright[] =
|
const char inflate_copyright[] =
|
||||||
" inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
|
" inflate 1.3.2.1 Copyright 1995-2026 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 +43,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 */
|
||||||
@@ -52,9 +61,9 @@ unsigned short FAR *work;
|
|||||||
unsigned mask; /* mask for low root bits */
|
unsigned mask; /* mask for low root bits */
|
||||||
code here; /* table entry for duplication */
|
code here; /* table entry for duplication */
|
||||||
code FAR *next; /* next available space in table */
|
code FAR *next; /* next available space in table */
|
||||||
const unsigned short FAR *base; /* base value table to use */
|
const unsigned short FAR *base = NULL; /* base value table to use */
|
||||||
const unsigned short FAR *extra; /* extra bits table to use */
|
const unsigned short FAR *extra = NULL; /* extra bits table to use */
|
||||||
int end; /* use base and extra for symbol > end */
|
unsigned match = 0; /* use base and extra for symbol >= match */
|
||||||
unsigned short count[MAXBITS+1]; /* number of codes of each length */
|
unsigned short count[MAXBITS+1]; /* number of codes of each length */
|
||||||
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
|
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
|
||||||
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
|
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
|
||||||
@@ -62,7 +71,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, 72, 78};
|
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 68, 193};
|
||||||
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
|
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,
|
||||||
@@ -180,20 +189,16 @@ unsigned short FAR *work;
|
|||||||
/* set up for code type */
|
/* set up for code type */
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CODES:
|
case CODES:
|
||||||
base = extra = work; /* dummy value--not used */
|
match = 20;
|
||||||
end = 19;
|
|
||||||
break;
|
break;
|
||||||
case LENS:
|
case LENS:
|
||||||
base = lbase;
|
base = lbase;
|
||||||
base -= 257;
|
|
||||||
extra = lext;
|
extra = lext;
|
||||||
extra -= 257;
|
match = 257;
|
||||||
end = 256;
|
|
||||||
break;
|
break;
|
||||||
default: /* DISTS */
|
case DISTS:
|
||||||
base = dbase;
|
base = dbase;
|
||||||
extra = dext;
|
extra = dext;
|
||||||
end = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize state for loop */
|
/* initialize state for loop */
|
||||||
@@ -216,13 +221,13 @@ unsigned short FAR *work;
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
/* create table entry */
|
/* create table entry */
|
||||||
here.bits = (unsigned char)(len - drop);
|
here.bits = (unsigned char)(len - drop);
|
||||||
if ((int)(work[sym]) < end) {
|
if (work[sym] + 1U < match) {
|
||||||
here.op = (unsigned char)0;
|
here.op = (unsigned char)0;
|
||||||
here.val = work[sym];
|
here.val = work[sym];
|
||||||
}
|
}
|
||||||
else if ((int)(work[sym]) > end) {
|
else if (work[sym] >= match) {
|
||||||
here.op = (unsigned char)(extra[work[sym]]);
|
here.op = (unsigned char)(extra[work[sym] - match]);
|
||||||
here.val = base[work[sym]];
|
here.val = base[work[sym] - match];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
here.op = (unsigned char)(32 + 64); /* end of block */
|
here.op = (unsigned char)(32 + 64); /* end of block */
|
||||||
@@ -304,3 +309,116 @@ unsigned short FAR *work;
|
|||||||
*bits = root;
|
*bits = root;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILDFIXED
|
||||||
|
/*
|
||||||
|
If this is compiled with BUILDFIXED defined, and if inflate will be used in
|
||||||
|
multiple threads, and if atomics are not available, then inflate() must be
|
||||||
|
called with a fixed block (e.g. 0x03 0x00) to initialize the tables and must
|
||||||
|
return before any other threads are allowed to call inflate.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static code *lenfix, *distfix;
|
||||||
|
static code fixed[544];
|
||||||
|
|
||||||
|
/* State for z_once(). */
|
||||||
|
local z_once_t built = Z_ONCE_INIT;
|
||||||
|
|
||||||
|
local void buildtables(void) {
|
||||||
|
unsigned sym, bits;
|
||||||
|
static code *next;
|
||||||
|
unsigned short lens[288], work[288];
|
||||||
|
|
||||||
|
/* literal/length table */
|
||||||
|
sym = 0;
|
||||||
|
while (sym < 144) lens[sym++] = 8;
|
||||||
|
while (sym < 256) lens[sym++] = 9;
|
||||||
|
while (sym < 280) lens[sym++] = 7;
|
||||||
|
while (sym < 288) lens[sym++] = 8;
|
||||||
|
next = fixed;
|
||||||
|
lenfix = next;
|
||||||
|
bits = 9;
|
||||||
|
inflate_table(LENS, lens, 288, &(next), &(bits), work);
|
||||||
|
|
||||||
|
/* distance table */
|
||||||
|
sym = 0;
|
||||||
|
while (sym < 32) lens[sym++] = 5;
|
||||||
|
distfix = next;
|
||||||
|
bits = 5;
|
||||||
|
inflate_table(DISTS, lens, 32, &(next), &(bits), work);
|
||||||
|
}
|
||||||
|
#else /* !BUILDFIXED */
|
||||||
|
# include "inffixed.h"
|
||||||
|
#endif /* BUILDFIXED */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return state with length and distance decoding tables and index sizes set to
|
||||||
|
fixed code decoding. Normally this returns fixed tables from inffixed.h.
|
||||||
|
If BUILDFIXED is defined, then instead this routine builds the tables the
|
||||||
|
first time it's called, and returns those tables the first time and
|
||||||
|
thereafter. This reduces the size of the code by about 2K bytes, in
|
||||||
|
exchange for a little execution time. However, BUILDFIXED should not be
|
||||||
|
used for threaded applications if atomics are not available, as it will
|
||||||
|
not be thread-safe.
|
||||||
|
*/
|
||||||
|
void inflate_fixed(struct inflate_state FAR *state) {
|
||||||
|
#ifdef BUILDFIXED
|
||||||
|
z_once(&built, buildtables);
|
||||||
|
#endif /* BUILDFIXED */
|
||||||
|
state->lencode = lenfix;
|
||||||
|
state->lenbits = 9;
|
||||||
|
state->distcode = distfix;
|
||||||
|
state->distbits = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MAKEFIXED
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
Write out the inffixed.h that will be #include'd above. Defining MAKEFIXED
|
||||||
|
also defines BUILDFIXED, so the tables are built on the fly. main() writes
|
||||||
|
those tables to stdout, which would directed to inffixed.h. Compile this
|
||||||
|
along with zutil.c:
|
||||||
|
|
||||||
|
cc -DMAKEFIXED -o fix inftrees.c zutil.c
|
||||||
|
./fix > inffixed.h
|
||||||
|
*/
|
||||||
|
int main(void) {
|
||||||
|
unsigned low, size;
|
||||||
|
struct inflate_state state;
|
||||||
|
|
||||||
|
inflate_fixed(&state);
|
||||||
|
puts("/* inffixed.h -- table for decoding fixed codes");
|
||||||
|
puts(" * Generated automatically by makefixed().");
|
||||||
|
puts(" */");
|
||||||
|
puts("");
|
||||||
|
puts("/* WARNING: this file should *not* be used by applications.");
|
||||||
|
puts(" It is part of the implementation of this library and is");
|
||||||
|
puts(" subject to change. Applications should only use zlib.h.");
|
||||||
|
puts(" */");
|
||||||
|
puts("");
|
||||||
|
size = 1U << 9;
|
||||||
|
printf("static const code lenfix[%u] = {", size);
|
||||||
|
low = 0;
|
||||||
|
for (;;) {
|
||||||
|
if ((low % 7) == 0) printf("\n ");
|
||||||
|
printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
|
||||||
|
state.lencode[low].bits, state.lencode[low].val);
|
||||||
|
if (++low == size) break;
|
||||||
|
putchar(',');
|
||||||
|
}
|
||||||
|
puts("\n};");
|
||||||
|
size = 1U << 5;
|
||||||
|
printf("\nstatic const code distfix[%u] = {", size);
|
||||||
|
low = 0;
|
||||||
|
for (;;) {
|
||||||
|
if ((low % 6) == 0) printf("\n ");
|
||||||
|
printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
|
||||||
|
state.distcode[low].val);
|
||||||
|
if (++low == size) break;
|
||||||
|
putchar(',');
|
||||||
|
}
|
||||||
|
puts("\n};");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* MAKEFIXED */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* inftrees.h -- header to use inftrees.c
|
/* inftrees.h -- header to use inftrees.c
|
||||||
* Copyright (C) 1995-2005, 2010 Mark Adler
|
* Copyright (C) 1995-2026 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -38,11 +38,11 @@ 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 852, and "enough 30 6 15" for distance codes returns 592. The
|
||||||
The initial root table size (9 or 6) is found in the fifth argument of the
|
initial root table size (9 or 6) is found in the fifth argument of the
|
||||||
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
||||||
changed, then these maximum sizes would be need to be recalculated and
|
changed, then these maximum sizes would be need to be recalculated and
|
||||||
updated. */
|
updated. */
|
||||||
@@ -57,6 +57,8 @@ 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);
|
||||||
|
struct inflate_state;
|
||||||
|
void ZLIB_INTERNAL inflate_fixed(struct inflate_state FAR *state);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/* uncompr.c -- decompress a memory buffer
|
/* uncompr.c -- decompress a memory buffer
|
||||||
* Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
|
* Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,51 +9,93 @@
|
|||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
Decompresses the source buffer into the destination buffer. *sourceLen is
|
||||||
the byte length of the source buffer. Upon entry, destLen is the total
|
the byte length of the source buffer. Upon entry, *destLen is the total size
|
||||||
size of the destination buffer, which must be large enough to hold the
|
of the destination buffer, which must be large enough to hold the entire
|
||||||
entire uncompressed data. (The size of the uncompressed data must have
|
uncompressed data. (The size of the uncompressed data must have been saved
|
||||||
been saved previously by the compressor and transmitted to the decompressor
|
previously by the compressor and transmitted to the decompressor by some
|
||||||
by some mechanism outside the scope of this compression library.)
|
mechanism outside the scope of this compression library.) Upon exit,
|
||||||
Upon exit, destLen is the actual size of the compressed buffer.
|
*destLen is the size of the decompressed data and *sourceLen is the number
|
||||||
|
of source bytes consumed. Upon return, source + *sourceLen points to the
|
||||||
|
first unused input byte.
|
||||||
|
|
||||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
|
||||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
Z_DATA_ERROR if the input data was corrupted, including if the input data is
|
||||||
|
an incomplete zlib stream.
|
||||||
|
|
||||||
|
The _z versions of the functions take size_t length arguments.
|
||||||
*/
|
*/
|
||||||
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
|
int ZEXPORT uncompress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
|
||||||
Bytef *dest;
|
z_size_t *sourceLen) {
|
||||||
uLongf *destLen;
|
|
||||||
const Bytef *source;
|
|
||||||
uLong sourceLen;
|
|
||||||
{
|
|
||||||
z_stream stream;
|
z_stream stream;
|
||||||
int err;
|
int err;
|
||||||
|
const uInt max = (uInt)-1;
|
||||||
|
z_size_t len, left;
|
||||||
|
|
||||||
|
if (sourceLen == NULL || (*sourceLen > 0 && source == NULL) ||
|
||||||
|
destLen == NULL || (*destLen > 0 && dest == NULL))
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
|
len = *sourceLen;
|
||||||
|
left = *destLen;
|
||||||
|
if (left == 0 && dest == Z_NULL)
|
||||||
|
dest = (Bytef *)&stream.reserved; /* next_out cannot be NULL */
|
||||||
|
|
||||||
stream.next_in = (z_const Bytef *)source;
|
stream.next_in = (z_const Bytef *)source;
|
||||||
stream.avail_in = (uInt)sourceLen;
|
stream.avail_in = 0;
|
||||||
/* Check for source > 64K on 16-bit machine: */
|
|
||||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
|
||||||
|
|
||||||
stream.next_out = dest;
|
|
||||||
stream.avail_out = (uInt)*destLen;
|
|
||||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
|
||||||
|
|
||||||
stream.zalloc = (alloc_func)0;
|
stream.zalloc = (alloc_func)0;
|
||||||
stream.zfree = (free_func)0;
|
stream.zfree = (free_func)0;
|
||||||
|
stream.opaque = (voidpf)0;
|
||||||
|
|
||||||
err = inflateInit(&stream);
|
err = inflateInit(&stream);
|
||||||
if (err != Z_OK) return err;
|
if (err != Z_OK) return err;
|
||||||
|
|
||||||
err = inflate(&stream, Z_FINISH);
|
stream.next_out = dest;
|
||||||
if (err != Z_STREAM_END) {
|
stream.avail_out = 0;
|
||||||
inflateEnd(&stream);
|
|
||||||
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
|
|
||||||
return Z_DATA_ERROR;
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
*destLen = stream.total_out;
|
|
||||||
|
|
||||||
err = inflateEnd(&stream);
|
do {
|
||||||
return err;
|
if (stream.avail_out == 0) {
|
||||||
|
stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
|
||||||
|
left -= stream.avail_out;
|
||||||
|
}
|
||||||
|
if (stream.avail_in == 0) {
|
||||||
|
stream.avail_in = len > (z_size_t)max ? max : (uInt)len;
|
||||||
|
len -= stream.avail_in;
|
||||||
|
}
|
||||||
|
err = inflate(&stream, Z_NO_FLUSH);
|
||||||
|
} while (err == Z_OK);
|
||||||
|
|
||||||
|
/* Set len and left to the unused input data and unused output space. Set
|
||||||
|
*sourceLen to the amount of input consumed. Set *destLen to the amount
|
||||||
|
of data produced. */
|
||||||
|
len += stream.avail_in;
|
||||||
|
left += stream.avail_out;
|
||||||
|
*sourceLen -= len;
|
||||||
|
*destLen -= left;
|
||||||
|
|
||||||
|
inflateEnd(&stream);
|
||||||
|
return err == Z_STREAM_END ? Z_OK :
|
||||||
|
err == Z_NEED_DICT ? Z_DATA_ERROR :
|
||||||
|
err == Z_BUF_ERROR && len == 0 ? Z_DATA_ERROR :
|
||||||
|
err;
|
||||||
|
}
|
||||||
|
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||||
|
uLong *sourceLen) {
|
||||||
|
int ret;
|
||||||
|
z_size_t got = *destLen, used = *sourceLen;
|
||||||
|
ret = uncompress2_z(dest, &got, source, &used);
|
||||||
|
*sourceLen = (uLong)used;
|
||||||
|
*destLen = (uLong)got;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int ZEXPORT uncompress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
|
||||||
|
z_size_t sourceLen) {
|
||||||
|
z_size_t used = sourceLen;
|
||||||
|
return uncompress2_z(dest, destLen, source, &used);
|
||||||
|
}
|
||||||
|
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||||
|
uLong sourceLen) {
|
||||||
|
uLong used = sourceLen;
|
||||||
|
return uncompress2(dest, destLen, source, &used);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* zconf.h -- configuration of the zlib compression library
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
* Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||||
# define Z_PREFIX_SET
|
# define Z_PREFIX_SET
|
||||||
|
|
||||||
/* all linked symbols */
|
/* all linked symbols and init macros */
|
||||||
# define _dist_code z__dist_code
|
# define _dist_code z__dist_code
|
||||||
# define _length_code z__length_code
|
# define _length_code z__length_code
|
||||||
# define _tr_align z__tr_align
|
# define _tr_align z__tr_align
|
||||||
@@ -29,18 +29,30 @@
|
|||||||
# define adler32 z_adler32
|
# define adler32 z_adler32
|
||||||
# define adler32_combine z_adler32_combine
|
# define adler32_combine z_adler32_combine
|
||||||
# define adler32_combine64 z_adler32_combine64
|
# define adler32_combine64 z_adler32_combine64
|
||||||
|
# define adler32_z z_adler32_z
|
||||||
# ifndef Z_SOLO
|
# ifndef Z_SOLO
|
||||||
# define compress z_compress
|
# define compress z_compress
|
||||||
# define compress2 z_compress2
|
# define compress2 z_compress2
|
||||||
|
# define compress_z z_compress_z
|
||||||
|
# define compress2_z z_compress2_z
|
||||||
# define compressBound z_compressBound
|
# define compressBound z_compressBound
|
||||||
|
# define compressBound_z z_compressBound_z
|
||||||
# endif
|
# endif
|
||||||
# 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 deflate z_deflate
|
# define deflate z_deflate
|
||||||
# define deflateBound z_deflateBound
|
# define deflateBound z_deflateBound
|
||||||
|
# define deflateBound_z z_deflateBound_z
|
||||||
# define deflateCopy z_deflateCopy
|
# define deflateCopy z_deflateCopy
|
||||||
# define deflateEnd z_deflateEnd
|
# define deflateEnd z_deflateEnd
|
||||||
|
# define deflateGetDictionary z_deflateGetDictionary
|
||||||
|
# define deflateInit z_deflateInit
|
||||||
|
# define deflateInit2 z_deflateInit2
|
||||||
# define deflateInit2_ z_deflateInit2_
|
# define deflateInit2_ z_deflateInit2_
|
||||||
# define deflateInit_ z_deflateInit_
|
# define deflateInit_ z_deflateInit_
|
||||||
# define deflateParams z_deflateParams
|
# define deflateParams z_deflateParams
|
||||||
@@ -51,6 +63,7 @@
|
|||||||
# define deflateSetDictionary z_deflateSetDictionary
|
# define deflateSetDictionary z_deflateSetDictionary
|
||||||
# define deflateSetHeader z_deflateSetHeader
|
# define deflateSetHeader z_deflateSetHeader
|
||||||
# define deflateTune z_deflateTune
|
# define deflateTune z_deflateTune
|
||||||
|
# define deflateUsed z_deflateUsed
|
||||||
# define deflate_copyright z_deflate_copyright
|
# define deflate_copyright z_deflate_copyright
|
||||||
# define get_crc_table z_get_crc_table
|
# define get_crc_table z_get_crc_table
|
||||||
# ifndef Z_SOLO
|
# ifndef Z_SOLO
|
||||||
@@ -67,6 +80,8 @@
|
|||||||
# define gzeof z_gzeof
|
# define gzeof z_gzeof
|
||||||
# define gzerror z_gzerror
|
# define gzerror z_gzerror
|
||||||
# define gzflush z_gzflush
|
# define gzflush z_gzflush
|
||||||
|
# define gzfread z_gzfread
|
||||||
|
# define gzfwrite z_gzfwrite
|
||||||
# define gzgetc z_gzgetc
|
# define gzgetc z_gzgetc
|
||||||
# define gzgetc_ z_gzgetc_
|
# define gzgetc_ z_gzgetc_
|
||||||
# define gzgets z_gzgets
|
# define gzgets z_gzgets
|
||||||
@@ -78,7 +93,6 @@
|
|||||||
# define gzopen_w z_gzopen_w
|
# define gzopen_w z_gzopen_w
|
||||||
# endif
|
# endif
|
||||||
# define gzprintf z_gzprintf
|
# define gzprintf z_gzprintf
|
||||||
# define gzvprintf z_gzvprintf
|
|
||||||
# define gzputc z_gzputc
|
# define gzputc z_gzputc
|
||||||
# define gzputs z_gzputs
|
# define gzputs z_gzputs
|
||||||
# define gzread z_gzread
|
# define gzread z_gzread
|
||||||
@@ -89,32 +103,42 @@
|
|||||||
# define gztell z_gztell
|
# define gztell z_gztell
|
||||||
# define gztell64 z_gztell64
|
# define gztell64 z_gztell64
|
||||||
# define gzungetc z_gzungetc
|
# define gzungetc z_gzungetc
|
||||||
|
# define gzvprintf z_gzvprintf
|
||||||
# define gzwrite z_gzwrite
|
# define gzwrite z_gzwrite
|
||||||
# endif
|
# endif
|
||||||
# define inflate z_inflate
|
# define inflate z_inflate
|
||||||
# define inflateBack z_inflateBack
|
# define inflateBack z_inflateBack
|
||||||
# define inflateBackEnd z_inflateBackEnd
|
# define inflateBackEnd z_inflateBackEnd
|
||||||
|
# define inflateBackInit z_inflateBackInit
|
||||||
# define inflateBackInit_ z_inflateBackInit_
|
# define inflateBackInit_ z_inflateBackInit_
|
||||||
|
# define inflateCodesUsed z_inflateCodesUsed
|
||||||
# define inflateCopy z_inflateCopy
|
# define inflateCopy z_inflateCopy
|
||||||
# define inflateEnd z_inflateEnd
|
# define inflateEnd z_inflateEnd
|
||||||
|
# define inflateGetDictionary z_inflateGetDictionary
|
||||||
# define inflateGetHeader z_inflateGetHeader
|
# define inflateGetHeader z_inflateGetHeader
|
||||||
|
# define inflateInit z_inflateInit
|
||||||
|
# define inflateInit2 z_inflateInit2
|
||||||
# define inflateInit2_ z_inflateInit2_
|
# define inflateInit2_ z_inflateInit2_
|
||||||
# define inflateInit_ z_inflateInit_
|
# define inflateInit_ z_inflateInit_
|
||||||
# define inflateMark z_inflateMark
|
# define inflateMark z_inflateMark
|
||||||
# define inflatePrime z_inflatePrime
|
# define inflatePrime z_inflatePrime
|
||||||
# define inflateReset z_inflateReset
|
# define inflateReset z_inflateReset
|
||||||
# define inflateReset2 z_inflateReset2
|
# define inflateReset2 z_inflateReset2
|
||||||
|
# define inflateResetKeep z_inflateResetKeep
|
||||||
# define inflateSetDictionary z_inflateSetDictionary
|
# define inflateSetDictionary z_inflateSetDictionary
|
||||||
# define inflateGetDictionary z_inflateGetDictionary
|
|
||||||
# define inflateSync z_inflateSync
|
# define inflateSync z_inflateSync
|
||||||
# define inflateSyncPoint z_inflateSyncPoint
|
# define inflateSyncPoint z_inflateSyncPoint
|
||||||
# define inflateUndermine z_inflateUndermine
|
# define inflateUndermine z_inflateUndermine
|
||||||
# define inflateResetKeep z_inflateResetKeep
|
# define inflateValidate z_inflateValidate
|
||||||
# define inflate_copyright z_inflate_copyright
|
# define inflate_copyright z_inflate_copyright
|
||||||
# define inflate_fast z_inflate_fast
|
# define inflate_fast z_inflate_fast
|
||||||
# define inflate_table z_inflate_table
|
# define inflate_table z_inflate_table
|
||||||
|
# define inflate_fixed z_inflate_fixed
|
||||||
# ifndef Z_SOLO
|
# ifndef Z_SOLO
|
||||||
# define uncompress z_uncompress
|
# define uncompress z_uncompress
|
||||||
|
# define uncompress2 z_uncompress2
|
||||||
|
# define uncompress_z z_uncompress_z
|
||||||
|
# define uncompress2_z z_uncompress2_z
|
||||||
# endif
|
# endif
|
||||||
# define zError z_zError
|
# define zError z_zError
|
||||||
# ifndef Z_SOLO
|
# ifndef Z_SOLO
|
||||||
@@ -218,15 +242,31 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
#ifndef z_const
|
||||||
# define z_const const
|
# ifdef ZLIB_CONST
|
||||||
#else
|
# define z_const const
|
||||||
# define z_const
|
# else
|
||||||
|
# define z_const
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Some Mac compilers merge all .h files incorrectly: */
|
#ifdef Z_SOLO
|
||||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
# ifdef _WIN64
|
||||||
# define NO_DUMMY_DECL
|
typedef unsigned long long z_size_t;
|
||||||
|
# else
|
||||||
|
typedef unsigned long z_size_t;
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define z_longlong long long
|
||||||
|
# if defined(NO_SIZE_T)
|
||||||
|
typedef unsigned NO_SIZE_T z_size_t;
|
||||||
|
# elif defined(STDC)
|
||||||
|
# include <stddef.h>
|
||||||
|
typedef size_t z_size_t;
|
||||||
|
# else
|
||||||
|
typedef unsigned long z_size_t;
|
||||||
|
# endif
|
||||||
|
# undef z_longlong
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Maximum value for memLevel in deflateInit2 */
|
/* Maximum value for memLevel in deflateInit2 */
|
||||||
@@ -256,7 +296,7 @@
|
|||||||
Of course this will generally degrade compression (there's no free lunch).
|
Of course this will generally degrade compression (there's no free lunch).
|
||||||
|
|
||||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
|
||||||
for small objects.
|
for small objects.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -270,14 +310,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Z_ARG /* function prototypes for stdarg */
|
|
||||||
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
|
||||||
# define Z_ARG(args) args
|
|
||||||
# else
|
|
||||||
# define Z_ARG(args) ()
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||||
* model programming (small or medium model with some far allocations).
|
* model programming (small or medium model with some far allocations).
|
||||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||||
@@ -326,6 +358,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. */
|
||||||
@@ -408,11 +443,11 @@ typedef uLong FAR uLongf;
|
|||||||
typedef unsigned long z_crc_t;
|
typedef unsigned long z_crc_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
#if HAVE_UNISTD_H-0 /* may be set to #if 1 by ./configure */
|
||||||
# define Z_HAVE_UNISTD_H
|
# define Z_HAVE_UNISTD_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
#if HAVE_STDARG_H-0 /* may be set to #if 1 by ./configure */
|
||||||
# define Z_HAVE_STDARG_H
|
# define Z_HAVE_STDARG_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -444,11 +479,14 @@ 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
|
# if defined(__WATCOMC__) || defined(__GO32__) || \
|
||||||
|
(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 */
|
||||||
@@ -478,17 +516,19 @@ typedef uLong FAR uLongf;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef z_off_t
|
#ifndef z_off_t
|
||||||
# define z_off_t long
|
# define z_off_t long long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||||
# define z_off64_t off64_t
|
# define z_off64_t off64_t
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
# define z_off64_t long long
|
||||||
|
#elif defined(_WIN32) && !defined(__GNUC__)
|
||||||
|
# define z_off64_t __int64
|
||||||
|
#elif defined(__GO32__)
|
||||||
|
# define z_off64_t offset_t
|
||||||
#else
|
#else
|
||||||
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
# define z_off64_t z_off_t
|
||||||
# define z_off64_t long long
|
|
||||||
# else
|
|
||||||
# define z_off64_t z_off_t
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* MVS linker does not support external names larger than 8 bytes */
|
/* MVS linker does not support external names larger than 8 bytes */
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/* zutil.c -- target dependent utility functions for the compression library
|
/* zutil.c -- target dependent utility functions for the compression library
|
||||||
* Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
|
* Copyright (C) 1995-2026 Jean-loup Gailly
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,30 +10,25 @@
|
|||||||
# include "gzguts.h"
|
# include "gzguts.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NO_DUMMY_DECL
|
|
||||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
z_const char * const z_errmsg[10] = {
|
z_const char * const z_errmsg[10] = {
|
||||||
"need dictionary", /* Z_NEED_DICT 2 */
|
(z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
|
||||||
"stream end", /* Z_STREAM_END 1 */
|
(z_const char *)"stream end", /* Z_STREAM_END 1 */
|
||||||
"", /* Z_OK 0 */
|
(z_const char *)"", /* Z_OK 0 */
|
||||||
"file error", /* Z_ERRNO (-1) */
|
(z_const char *)"file error", /* Z_ERRNO (-1) */
|
||||||
"stream error", /* Z_STREAM_ERROR (-2) */
|
(z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
|
||||||
"data error", /* Z_DATA_ERROR (-3) */
|
(z_const char *)"data error", /* Z_DATA_ERROR (-3) */
|
||||||
"insufficient memory", /* Z_MEM_ERROR (-4) */
|
(z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
|
||||||
"buffer error", /* Z_BUF_ERROR (-5) */
|
(z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
|
||||||
"incompatible version",/* Z_VERSION_ERROR (-6) */
|
(z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
|
||||||
""};
|
(z_const char *)""
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const char * ZEXPORT zlibVersion()
|
const char * ZEXPORT zlibVersion(void) {
|
||||||
{
|
|
||||||
return ZLIB_VERSION;
|
return ZLIB_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
uLong ZEXPORT zlibCompileFlags()
|
uLong ZEXPORT zlibCompileFlags(void) {
|
||||||
{
|
|
||||||
uLong flags;
|
uLong flags;
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
@@ -61,12 +56,14 @@ uLong ZEXPORT zlibCompileFlags()
|
|||||||
case 8: flags += 2 << 6; break;
|
case 8: flags += 2 << 6; break;
|
||||||
default: flags += 3 << 6;
|
default: flags += 3 << 6;
|
||||||
}
|
}
|
||||||
#ifdef 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
|
||||||
@@ -89,42 +86,48 @@ uLong ZEXPORT zlibCompileFlags()
|
|||||||
flags += 1L << 21;
|
flags += 1L << 21;
|
||||||
#endif
|
#endif
|
||||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||||
# ifdef NO_vsnprintf
|
# ifdef NO_vsnprintf
|
||||||
flags += 1L << 25;
|
# ifdef ZLIB_INSECURE
|
||||||
# ifdef HAS_vsprintf_void
|
flags += 1L << 25;
|
||||||
flags += 1L << 26;
|
# else
|
||||||
# endif
|
flags += 1L << 27;
|
||||||
# else
|
# endif
|
||||||
# ifdef HAS_vsnprintf_void
|
# ifdef HAS_vsprintf_void
|
||||||
flags += 1L << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# else
|
||||||
|
# ifdef HAS_vsnprintf_void
|
||||||
|
flags += 1L << 26;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
flags += 1L << 24;
|
flags += 1L << 24;
|
||||||
# ifdef NO_snprintf
|
# ifdef NO_snprintf
|
||||||
flags += 1L << 25;
|
# ifdef ZLIB_INSECURE
|
||||||
# ifdef HAS_sprintf_void
|
flags += 1L << 25;
|
||||||
flags += 1L << 26;
|
# else
|
||||||
# endif
|
flags += 1L << 27;
|
||||||
# else
|
# endif
|
||||||
# ifdef HAS_snprintf_void
|
# ifdef HAS_sprintf_void
|
||||||
flags += 1L << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# else
|
||||||
|
# ifdef HAS_snprintf_void
|
||||||
|
flags += 1L << 26;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef ZLIB_DEBUG
|
||||||
|
#include <stdlib.h>
|
||||||
# ifndef verbose
|
# ifndef verbose
|
||||||
# define verbose 0
|
# define verbose 0
|
||||||
# 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);
|
||||||
}
|
}
|
||||||
@@ -133,14 +136,12 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32_WCE)
|
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
|
||||||
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
/* The older Microsoft C Run-Time Library for Windows CE doesn't have
|
||||||
* errno. We define it as a global variable to simplify porting.
|
* errno. We define it as a global variable to simplify porting.
|
||||||
* Its value is always 0 and should not be used.
|
* Its value is always 0 and should not be used.
|
||||||
*/
|
*/
|
||||||
@@ -149,39 +150,33 @@ const char * ZEXPORT zError(err)
|
|||||||
|
|
||||||
#ifndef HAVE_MEMCPY
|
#ifndef HAVE_MEMCPY
|
||||||
|
|
||||||
void ZLIB_INTERNAL zmemcpy(dest, source, len)
|
void ZLIB_INTERNAL zmemcpy(void FAR *dst, const void FAR *src, z_size_t n) {
|
||||||
Bytef* dest;
|
uchf *p = dst;
|
||||||
const Bytef* source;
|
const uchf *q = src;
|
||||||
uInt len;
|
while (n) {
|
||||||
{
|
*p++ = *q++;
|
||||||
if (len == 0) return;
|
n--;
|
||||||
do {
|
}
|
||||||
*dest++ = *source++; /* ??? to be unrolled */
|
|
||||||
} while (--len != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZLIB_INTERNAL zmemcmp(s1, s2, len)
|
int ZLIB_INTERNAL zmemcmp(const void FAR *s1, const void FAR *s2, z_size_t n) {
|
||||||
const Bytef* s1;
|
const uchf *p = s1, *q = s2;
|
||||||
const Bytef* s2;
|
while (n) {
|
||||||
uInt len;
|
if (*p++ != *q++)
|
||||||
{
|
return (int)p[-1] - (int)q[-1];
|
||||||
uInt j;
|
n--;
|
||||||
|
|
||||||
for (j = 0; j < len; j++) {
|
|
||||||
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZLIB_INTERNAL zmemzero(dest, len)
|
void ZLIB_INTERNAL zmemzero(void FAR *b, z_size_t len) {
|
||||||
Bytef* dest;
|
uchf *p = b;
|
||||||
uInt len;
|
while (len) {
|
||||||
{
|
*p++ = 0;
|
||||||
if (len == 0) return;
|
len--;
|
||||||
do {
|
}
|
||||||
*dest++ = 0; /* ??? to be unrolled */
|
|
||||||
} while (--len != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Z_SOLO
|
#ifndef Z_SOLO
|
||||||
@@ -217,11 +212,12 @@ 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 = opaque; /* just to make some compilers happy */
|
|
||||||
ulg bsize = (ulg)items*size;
|
ulg bsize = (ulg)items*size;
|
||||||
|
|
||||||
|
(void)opaque;
|
||||||
|
|
||||||
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||||
* will return a usable pointer which doesn't have to be normalized.
|
* will return a usable pointer which doesn't have to be normalized.
|
||||||
*/
|
*/
|
||||||
@@ -241,9 +237,11 @@ 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;
|
||||||
|
|
||||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||||
farfree(ptr);
|
farfree(ptr);
|
||||||
return;
|
return;
|
||||||
@@ -259,7 +257,6 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
|||||||
next_ptr--;
|
next_ptr--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ptr = opaque; /* just to make some compilers happy */
|
|
||||||
Assert(0, "zcfree: ptr not found");
|
Assert(0, "zcfree: ptr not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,15 +273,13 @@ 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;
|
||||||
if (opaque) opaque = 0; /* to make compiler happy */
|
|
||||||
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;
|
||||||
if (opaque) opaque = 0; /* to make compiler happy */
|
|
||||||
_hfree(ptr);
|
_hfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,27 +291,20 @@ 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;
|
(void)opaque;
|
||||||
unsigned items;
|
|
||||||
unsigned size;
|
|
||||||
{
|
|
||||||
if (opaque) items += size - size; /* make compiler happy */
|
|
||||||
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;
|
(void)opaque;
|
||||||
voidpf ptr;
|
|
||||||
{
|
|
||||||
free(ptr);
|
free(ptr);
|
||||||
if (opaque) return; /* make compiler happy */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MY_ZCALLOC */
|
#endif /* MY_ZCALLOC */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* zutil.h -- internal interface and configuration of the compression library
|
/* zutil.h -- internal interface and configuration of the compression library
|
||||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
* Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -29,14 +29,16 @@
|
|||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Z_SOLO
|
|
||||||
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef local
|
#ifndef local
|
||||||
# define local static
|
# define local static
|
||||||
#endif
|
#endif
|
||||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
/* since "static" is used to mean two completely different things in C, we
|
||||||
|
define "local" for the non-static meaning of "static", for readability
|
||||||
|
(compile with -Dlocal if your debugger can't find static symbols) */
|
||||||
|
|
||||||
|
extern const char deflate_copyright[];
|
||||||
|
extern const char inflate_copyright[];
|
||||||
|
extern const char inflate9_copyright[];
|
||||||
|
|
||||||
typedef unsigned char uch;
|
typedef unsigned char uch;
|
||||||
typedef uch FAR uchf;
|
typedef uch FAR uchf;
|
||||||
@@ -44,17 +46,32 @@ typedef unsigned short ush;
|
|||||||
typedef ush FAR ushf;
|
typedef ush FAR ushf;
|
||||||
typedef unsigned long ulg;
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
|
#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
|
||||||
|
# include <limits.h>
|
||||||
|
# if (ULONG_MAX == 0xffffffffffffffff)
|
||||||
|
# define Z_U8 unsigned long
|
||||||
|
# elif (ULLONG_MAX == 0xffffffffffffffff)
|
||||||
|
# define Z_U8 unsigned long long
|
||||||
|
# elif (ULONG_LONG_MAX == 0xffffffffffffffff)
|
||||||
|
# define Z_U8 unsigned long long
|
||||||
|
# elif (UINT_MAX == 0xffffffffffffffff)
|
||||||
|
# define Z_U8 unsigned
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
/* (size given to avoid silly warnings with Visual C++) */
|
/* (size given to avoid silly warnings with Visual C++) */
|
||||||
|
|
||||||
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
|
||||||
|
|
||||||
#define ERR_RETURN(strm,err) \
|
#define ERR_RETURN(strm,err) \
|
||||||
return (strm->msg = ERR_MSG(err), (err))
|
return (strm->msg = ERR_MSG(err), (err))
|
||||||
/* To be used only when the state is known to be valid */
|
/* To be used only when the state is known to be valid */
|
||||||
|
|
||||||
/* common constants */
|
/* common constants */
|
||||||
|
#if MAX_WBITS < 9 || MAX_WBITS > 15
|
||||||
|
# error MAX_WBITS must be in 9..15
|
||||||
|
#endif
|
||||||
#ifndef DEF_WBITS
|
#ifndef DEF_WBITS
|
||||||
# define DEF_WBITS MAX_WBITS
|
# define DEF_WBITS MAX_WBITS
|
||||||
#endif
|
#endif
|
||||||
@@ -98,67 +115,58 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AMIGA
|
#ifdef AMIGA
|
||||||
# define OS_CODE 0x01
|
# define OS_CODE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(VAXC) || defined(VMS)
|
#if defined(VAXC) || defined(VMS)
|
||||||
# define OS_CODE 0x02
|
# define OS_CODE 2
|
||||||
# define F_OPEN(name, mode) \
|
# define F_OPEN(name, mode) \
|
||||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __370__
|
||||||
|
# if __TARGET_LIB__ < 0x20000000
|
||||||
|
# define OS_CODE 4
|
||||||
|
# elif __TARGET_LIB__ < 0x40000000
|
||||||
|
# define OS_CODE 11
|
||||||
|
# else
|
||||||
|
# define OS_CODE 8
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ATARI) || defined(atarist)
|
#if defined(ATARI) || defined(atarist)
|
||||||
# define OS_CODE 0x05
|
# define OS_CODE 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OS2
|
#ifdef OS2
|
||||||
# define OS_CODE 0x06
|
# define OS_CODE 6
|
||||||
# if defined(M_I86) && !defined(Z_SOLO)
|
# if defined(M_I86) && !defined(Z_SOLO)
|
||||||
# include <malloc.h>
|
# include <malloc.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
#if defined(MACOS)
|
||||||
# define OS_CODE 0x07
|
# define OS_CODE 7
|
||||||
# ifndef Z_SOLO
|
|
||||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
|
||||||
# include <unix.h> /* for fdopen */
|
|
||||||
# else
|
|
||||||
# ifndef fdopen
|
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TOPS20
|
#if defined(__acorn) || defined(__riscos)
|
||||||
# define OS_CODE 0x0a
|
# define OS_CODE 13
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||||
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
|
# define OS_CODE 10
|
||||||
# define OS_CODE 0x0b
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __50SERIES /* Prime/PRIMOS */
|
#ifdef _BEOS_
|
||||||
# define OS_CODE 0x0f
|
# define OS_CODE 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_BEOS_) || defined(RISCOS)
|
#ifdef __TOS_OS400__
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# define OS_CODE 18
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
|
#ifdef __APPLE__
|
||||||
# if defined(_WIN32_WCE)
|
# define OS_CODE 19
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
|
||||||
# ifndef _PTRDIFF_T_DEFINED
|
|
||||||
typedef int ptrdiff_t;
|
|
||||||
# define _PTRDIFF_T_DEFINED
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define fdopen(fd,type) _fdopen(fd,type)
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__BORLANDC__) && !defined(MSDOS)
|
#if defined(__BORLANDC__) && !defined(MSDOS)
|
||||||
@@ -168,16 +176,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* provide prototypes for these when building zlib without LFS */
|
/* provide prototypes for these when building zlib without LFS */
|
||||||
#if !defined(_WIN32) && \
|
#ifndef Z_LARGE64
|
||||||
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
|
||||||
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
|
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
|
||||||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
|
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* common defaults */
|
/* common defaults */
|
||||||
|
|
||||||
#ifndef OS_CODE
|
#ifndef OS_CODE
|
||||||
# define OS_CODE 0x03 /* assume Unix */
|
# define OS_CODE 3 /* assume Unix */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef F_OPEN
|
#ifndef F_OPEN
|
||||||
@@ -210,16 +218,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(void FAR *, const void FAR *, z_size_t);
|
||||||
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
int ZLIB_INTERNAL zmemcmp(const void FAR *, const void FAR *, z_size_t);
|
||||||
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
|
void ZLIB_INTERNAL zmemzero(void FAR *, z_size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Diagnostic functions */
|
/* Diagnostic functions */
|
||||||
#ifdef 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 ;}
|
||||||
@@ -236,9 +244,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) \
|
||||||
@@ -250,4 +258,74 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||||||
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||||
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||||
|
|
||||||
|
#ifdef Z_ONCE
|
||||||
|
/*
|
||||||
|
Create a local z_once() function depending on the availability of atomics.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Check for the availability of atomics. */
|
||||||
|
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
|
||||||
|
!defined(__STDC_NO_ATOMICS__)
|
||||||
|
|
||||||
|
#include <stdatomic.h>
|
||||||
|
typedef struct {
|
||||||
|
atomic_flag begun;
|
||||||
|
atomic_int done;
|
||||||
|
} z_once_t;
|
||||||
|
#define Z_ONCE_INIT {ATOMIC_FLAG_INIT, 0}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Run the provided init() function exactly once, even if multiple threads
|
||||||
|
invoke once() at the same time. The state must be a once_t initialized with
|
||||||
|
Z_ONCE_INIT.
|
||||||
|
*/
|
||||||
|
local void z_once(z_once_t *state, void (*init)(void)) {
|
||||||
|
if (!atomic_load(&state->done)) {
|
||||||
|
if (atomic_flag_test_and_set(&state->begun))
|
||||||
|
while (!atomic_load(&state->done))
|
||||||
|
;
|
||||||
|
else {
|
||||||
|
init();
|
||||||
|
atomic_store(&state->done, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* no atomics */
|
||||||
|
|
||||||
|
#warning zlib not thread-safe
|
||||||
|
|
||||||
|
typedef struct z_once_s {
|
||||||
|
volatile int begun;
|
||||||
|
volatile int done;
|
||||||
|
} z_once_t;
|
||||||
|
#define Z_ONCE_INIT {0, 0}
|
||||||
|
|
||||||
|
/* Test and set. Alas, not atomic, but tries to limit the period of
|
||||||
|
vulnerability. */
|
||||||
|
local int test_and_set(int volatile *flag) {
|
||||||
|
int was;
|
||||||
|
|
||||||
|
was = *flag;
|
||||||
|
*flag = 1;
|
||||||
|
return was;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Run the provided init() function once. This is not thread-safe. */
|
||||||
|
local void z_once(z_once_t *state, void (*init)(void)) {
|
||||||
|
if (!state->done) {
|
||||||
|
if (test_and_set(&state->begun))
|
||||||
|
while (!state->done)
|
||||||
|
;
|
||||||
|
else {
|
||||||
|
init();
|
||||||
|
state->done = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ?atomics */
|
||||||
|
|
||||||
|
#endif /* Z_ONCE */
|
||||||
|
|
||||||
#endif /* ZUTIL_H */
|
#endif /* ZUTIL_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user