mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
phobos 0.166
This commit is contained in:
parent
dbc7ec7b92
commit
7b6d43bcb5
41 changed files with 1428 additions and 2543 deletions
237
etc/c/zlib.d
237
etc/c/zlib.d
|
@ -1,11 +1,12 @@
|
||||||
/* zlib.d: modified from zlib.h by Walter Bright */
|
/* zlib.d: modified from zlib.h by Walter Bright */
|
||||||
|
/* updated from 1.2.1 to 1.2.3 by Thomas Kuehne */
|
||||||
|
|
||||||
module etc.c.zlib;
|
module etc.c.zlib;
|
||||||
|
|
||||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||||
version 1.2.1, November 17th, 2003
|
version 1.2.3, July 18th, 2005
|
||||||
|
|
||||||
Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
|
Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
@ -34,7 +35,8 @@ module etc.c.zlib;
|
||||||
|
|
||||||
extern (C):
|
extern (C):
|
||||||
|
|
||||||
char[] ZLIB_VERSION = "1.2.1";
|
char[] ZLIB_VERSION = "1.2.3";
|
||||||
|
const ZLIB_VERNUM = 0x1230;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The 'zlib' compression library provides in-memory compression and
|
The 'zlib' compression library provides in-memory compression and
|
||||||
|
@ -49,24 +51,22 @@ char[] ZLIB_VERSION = "1.2.1";
|
||||||
application must provide more input and/or consume the output
|
application must provide more input and/or consume the output
|
||||||
(providing more output space) before each call.
|
(providing more output space) before each call.
|
||||||
|
|
||||||
The compressed data format used by the in-memory functions is the zlib
|
The compressed data format used by default by the in-memory functions is
|
||||||
format, which is a zlib wrapper documented in RFC 1950, wrapped around a
|
the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
|
||||||
deflate stream, which is itself documented in RFC 1951.
|
around a deflate stream, which is itself documented in RFC 1951.
|
||||||
|
|
||||||
The library also supports reading and writing files in gzip (.gz) format
|
The library also supports reading and writing files in gzip (.gz) format
|
||||||
with an interface similar to that of stdio using the functions that start
|
with an interface similar to that of stdio using the functions that start
|
||||||
with "gz". The gzip format is different from the zlib format. gzip is a
|
with "gz". The gzip format is different from the zlib format. gzip is a
|
||||||
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
||||||
|
|
||||||
|
This library can optionally read and write gzip streams in memory as well.
|
||||||
|
|
||||||
The zlib format was designed to be compact and fast for use in memory
|
The zlib format was designed to be compact and fast for use in memory
|
||||||
and on communications channels. The gzip format was designed for single-
|
and on communications channels. The gzip format was designed for single-
|
||||||
file compression on file systems, has a larger header than zlib to maintain
|
file compression on file systems, has a larger header than zlib to maintain
|
||||||
directory information, and uses a different, slower check method than zlib.
|
directory information, and uses a different, slower check method than zlib.
|
||||||
|
|
||||||
This library does not provide any functions to write gzip files in memory.
|
|
||||||
However such functions could be easily written using zlib's deflate function,
|
|
||||||
the documentation in the gzip RFC, and the examples in gzio.c.
|
|
||||||
|
|
||||||
The library does not install any signal handler. The decoder checks
|
The library does not install any signal handler. The decoder checks
|
||||||
the consistency of the compressed data, so the library should never
|
the consistency of the compressed data, so the library should never
|
||||||
crash even in case of corrupted input.
|
crash even in case of corrupted input.
|
||||||
|
@ -92,7 +92,7 @@ struct z_stream
|
||||||
free_func zfree; /* used to free the internal state */
|
free_func zfree; /* used to free the internal state */
|
||||||
void* opaque; /* private data object passed to zalloc and zfree */
|
void* opaque; /* private data object passed to zalloc and zfree */
|
||||||
|
|
||||||
int data_type; /* best guess about the data type: ascii or binary */
|
int data_type; /* best guess about the data type: binary or text */
|
||||||
uint adler; /* adler32 value of the uncompressed data */
|
uint adler; /* adler32 value of the uncompressed data */
|
||||||
uint reserved; /* reserved for future use */
|
uint reserved; /* reserved for future use */
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,30 @@ struct z_stream
|
||||||
alias z_stream* z_streamp;
|
alias z_stream* z_streamp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The application must update next_in and avail_in when avail_in has
|
gzip header information passed to and from zlib routines. See RFC 1952
|
||||||
|
for more details on the meanings of these fields.
|
||||||
|
*/
|
||||||
|
struct gz_header {
|
||||||
|
int text; /* true if compressed data believed to be text */
|
||||||
|
ulong time; /* modification time */
|
||||||
|
int xflags; /* extra flags (not used when writing a gzip file) */
|
||||||
|
int os; /* operating system */
|
||||||
|
byte *extra; /* pointer to extra field or Z_NULL if none */
|
||||||
|
uint extra_len; /* extra field length (valid if extra != Z_NULL) */
|
||||||
|
uint extra_max; /* space at extra (only when reading header) */
|
||||||
|
byte *name; /* pointer to zero-terminated file name or Z_NULL */
|
||||||
|
uint name_max; /* space at name (only when reading header) */
|
||||||
|
byte *comment; /* pointer to zero-terminated comment or Z_NULL */
|
||||||
|
uint comm_max; /* space at comment (only when reading header) */
|
||||||
|
int hcrc; /* true if there was or will be a header crc */
|
||||||
|
int done; /* true when done reading gzip header (not used
|
||||||
|
when writing a gzip file) */
|
||||||
|
}
|
||||||
|
|
||||||
|
alias gz_header* gz_headerp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
The application must update next_in and avail_in when avail_in has
|
||||||
dropped to zero. It must update next_out and avail_out when avail_out
|
dropped to zero. It must update next_out and avail_out when avail_out
|
||||||
has dropped to zero. The application must initialize zalloc, zfree and
|
has dropped to zero. The application must initialize zalloc, zfree and
|
||||||
opaque before calling the init function. All other fields are set by the
|
opaque before calling the init function. All other fields are set by the
|
||||||
|
@ -174,6 +197,7 @@ enum
|
||||||
Z_FILTERED = 1,
|
Z_FILTERED = 1,
|
||||||
Z_HUFFMAN_ONLY = 2,
|
Z_HUFFMAN_ONLY = 2,
|
||||||
Z_RLE = 3,
|
Z_RLE = 3,
|
||||||
|
Z_FIXED = 4,
|
||||||
Z_DEFAULT_STRATEGY = 0,
|
Z_DEFAULT_STRATEGY = 0,
|
||||||
}
|
}
|
||||||
/* compression strategy; see deflateInit2() below for details */
|
/* compression strategy; see deflateInit2() below for details */
|
||||||
|
@ -181,8 +205,10 @@ enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
Z_BINARY = 0,
|
Z_BINARY = 0,
|
||||||
Z_ASCII = 1,
|
Z_TEXT = 1,
|
||||||
Z_UNKNOWN = 2,
|
Z_UNKNOWN = 2,
|
||||||
|
|
||||||
|
Z_ASCII = Z_TEXT
|
||||||
}
|
}
|
||||||
/* Possible values of the data_type field (though see inflate()) */
|
/* Possible values of the data_type field (though see inflate()) */
|
||||||
|
|
||||||
|
@ -258,6 +284,10 @@ int deflate(z_streamp strm, int flush);
|
||||||
and with zero avail_out, it must be called again after making room in the
|
and with zero avail_out, it must be called again after making room in the
|
||||||
output buffer because there might be more output pending.
|
output buffer because there might be more output pending.
|
||||||
|
|
||||||
|
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
|
||||||
|
decide how much data to accumualte before producing output, in order to
|
||||||
|
maximize compression.
|
||||||
|
|
||||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||||
that the decompressor can get all input data available so far. (In particular
|
that the decompressor can get all input data available so far. (In particular
|
||||||
|
@ -269,7 +299,7 @@ int deflate(z_streamp strm, int flush);
|
||||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||||
restart from this point if previous compressed data has been damaged or if
|
restart from this point if previous compressed data has been damaged or if
|
||||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||||
the compression.
|
compression.
|
||||||
|
|
||||||
If deflate returns with avail_out == 0, this function must be called again
|
If deflate returns with avail_out == 0, this function must be called again
|
||||||
with the same value of the flush parameter and more output space (updated
|
with the same value of the flush parameter and more output space (updated
|
||||||
|
@ -294,8 +324,8 @@ int deflate(z_streamp strm, int flush);
|
||||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||||
so far (that is, total_in bytes).
|
so far (that is, total_in bytes).
|
||||||
|
|
||||||
deflate() may update data_type if it can make a good guess about
|
deflate() may update strm->data_type if it can make a good guess about
|
||||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
|
||||||
binary. This field is only for information purposes and does not affect
|
binary. This field is only for information purposes and does not affect
|
||||||
the compression algorithm in any manner.
|
the compression algorithm in any manner.
|
||||||
|
|
||||||
|
@ -379,11 +409,11 @@ int inflate(z_streamp strm, int flush);
|
||||||
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
|
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
|
||||||
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
|
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
|
||||||
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
|
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
|
||||||
if and when it get to the next deflate block boundary. When decoding the zlib
|
if and when it gets to the next deflate block boundary. When decoding the
|
||||||
or gzip format, this will cause inflate() to return immediately after the
|
zlib or gzip format, this will cause inflate() to return immediately after
|
||||||
header and before the first block. When doing a raw inflate, inflate() will
|
the header and before the first block. When doing a raw inflate, inflate()
|
||||||
go ahead and process the first block, and will return when it gets to the end
|
will go ahead and process the first block, and will return when it gets to
|
||||||
of that block, or when it runs out of data.
|
the end of that block, or when it runs out of data.
|
||||||
|
|
||||||
The Z_BLOCK option assists in appending to or combining deflate streams.
|
The Z_BLOCK option assists in appending to or combining deflate streams.
|
||||||
Also to assist in this, on return inflate() will set strm->data_type to the
|
Also to assist in this, on return inflate() will set strm->data_type to the
|
||||||
|
@ -415,7 +445,7 @@ int inflate(z_streamp strm, int flush);
|
||||||
because Z_BLOCK is used.
|
because Z_BLOCK is used.
|
||||||
|
|
||||||
If a preset dictionary is needed after this call (see inflateSetDictionary
|
If a preset dictionary is needed after this call (see inflateSetDictionary
|
||||||
below), inflate sets strm-adler to the adler32 checksum of the dictionary
|
below), inflate sets strm->adler to the adler32 checksum of the dictionary
|
||||||
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
||||||
strm->adler to the adler32 checksum of all output produced so far (that is,
|
strm->adler to the adler32 checksum of all output produced so far (that is,
|
||||||
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
|
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
|
||||||
|
@ -495,7 +525,8 @@ int deflateInit2(z_streamp strm,
|
||||||
16 to windowBits to write a simple gzip header and trailer around the
|
16 to windowBits to write a simple gzip header and trailer around the
|
||||||
compressed data instead of a zlib wrapper. The gzip header will have no
|
compressed data instead of a zlib wrapper. The gzip header will have no
|
||||||
file name, no extra data, no comment, no modification time (set to zero),
|
file name, no extra data, no comment, no modification time (set to zero),
|
||||||
no header crc, and the operating system will be set to 255 (unknown).
|
no header crc, and the operating system will be set to 255 (unknown). If a
|
||||||
|
gzip stream is being written, strm->adler is a crc32 instead of an adler32.
|
||||||
|
|
||||||
The memLevel parameter specifies how much memory should be allocated
|
The memLevel parameter specifies how much memory should be allocated
|
||||||
for the internal compression state. memLevel=1 uses minimum memory but
|
for the internal compression state. memLevel=1 uses minimum memory but
|
||||||
|
@ -514,7 +545,9 @@ int deflateInit2(z_streamp strm,
|
||||||
Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
|
Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
|
||||||
Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
|
Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
|
||||||
parameter only affects the compression ratio but not the correctness of the
|
parameter only affects the compression ratio but not the correctness of the
|
||||||
compressed output even if it is not set appropriately.
|
compressed output even if it is not set appropriately. Z_FIXED prevents the
|
||||||
|
use of dynamic Huffman codes, allowing for a simpler decoder for special
|
||||||
|
applications.
|
||||||
|
|
||||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||||
|
@ -541,7 +574,9 @@ int deflateSetDictionary(z_streamp strm, ubyte* dictionary, uint dictLength);
|
||||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||||
discarded, for example if the dictionary is larger than the window size in
|
discarded, for example if the dictionary is larger than the window size in
|
||||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||||
put at the end of the dictionary, not at the front.
|
put at the end of the dictionary, not at the front. In addition, the
|
||||||
|
current implementation of deflate will use at most the window size minus
|
||||||
|
262 bytes of the provided dictionary.
|
||||||
|
|
||||||
Upon return of this function, strm->adler is set to the adler32 value
|
Upon return of this function, strm->adler is set to the adler32 value
|
||||||
of the dictionary; the decompressor may later use this value to determine
|
of the dictionary; the decompressor may later use this value to determine
|
||||||
|
@ -585,6 +620,59 @@ int deflateReset(z_streamp strm);
|
||||||
stream state was inconsistent (such as zalloc or state being NULL).
|
stream state was inconsistent (such as zalloc or state being NULL).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int inflatePrime(z_streamp strm, int bits, int value);
|
||||||
|
/*
|
||||||
|
This function inserts bits in the inflate input stream. The intent is
|
||||||
|
that this function is used to start inflating at a bit position in the
|
||||||
|
middle of a byte. The provided bits will be used before any bytes are used
|
||||||
|
from next_in. This function should only be used with raw inflate, and
|
||||||
|
should be used before the first inflate() call after inflateInit2() or
|
||||||
|
inflateReset(). bits must be less than or equal to 16, and that many of the
|
||||||
|
least significant bits of value will be inserted in the input.
|
||||||
|
|
||||||
|
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int inflateGetHeader(z_streamp strm, gz_headerp head);
|
||||||
|
/*
|
||||||
|
inflateGetHeader() requests that gzip header information be stored in the
|
||||||
|
provided gz_header structure. inflateGetHeader() may be called after
|
||||||
|
inflateInit2() or inflateReset(), and before the first call of inflate().
|
||||||
|
As inflate() processes the gzip stream, head->done is zero until the header
|
||||||
|
is completed, at which time head->done is set to one. If a zlib stream is
|
||||||
|
being decoded, then head->done is set to -1 to indicate that there will be
|
||||||
|
no gzip header information forthcoming. Note that Z_BLOCK can be used to
|
||||||
|
force inflate() to return immediately after header processing is complete
|
||||||
|
and before any actual data is decompressed.
|
||||||
|
|
||||||
|
The text, time, xflags, and os fields are filled in with the gzip header
|
||||||
|
contents. hcrc is set to true if there is a header CRC. (The header CRC
|
||||||
|
was valid if done is set to one.) If extra is not Z_NULL, then extra_max
|
||||||
|
contains the maximum number of bytes to write to extra. Once done is true,
|
||||||
|
extra_len contains the actual extra field length, and extra contains the
|
||||||
|
extra field, or that field truncated if extra_max is less than extra_len.
|
||||||
|
If name is not Z_NULL, then up to name_max characters are written there,
|
||||||
|
terminated with a zero unless the length is greater than name_max. If
|
||||||
|
comment is not Z_NULL, then up to comm_max characters are written there,
|
||||||
|
terminated with a zero unless the length is greater than comm_max. When
|
||||||
|
any of extra, name, or comment are not Z_NULL and the respective field is
|
||||||
|
not present in the header, then that field is set to Z_NULL to signal its
|
||||||
|
absence. This allows the use of deflateSetHeader() with the returned
|
||||||
|
structure to duplicate the header. However if those fields are set to
|
||||||
|
allocated memory, then the application will need to save those pointers
|
||||||
|
elsewhere so that they can be eventually freed.
|
||||||
|
|
||||||
|
If inflateGetHeader is not used, then the header information is simply
|
||||||
|
discarded. The header is always checked for validity, including the header
|
||||||
|
CRC if present. inflateReset() will reset the process to discard the header
|
||||||
|
information. The application would need to call inflateGetHeader() again to
|
||||||
|
retrieve the header from the next gzip stream.
|
||||||
|
|
||||||
|
inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent.
|
||||||
|
*/
|
||||||
|
|
||||||
int deflateParams(z_streamp strm, int level, int strategy);
|
int deflateParams(z_streamp strm, int level, int strategy);
|
||||||
/*
|
/*
|
||||||
Dynamically update the compression level and compression strategy. The
|
Dynamically update the compression level and compression strategy. The
|
||||||
|
@ -604,7 +692,21 @@ int deflateParams(z_streamp strm, int level, int strategy);
|
||||||
if strm->avail_out was zero.
|
if strm->avail_out was zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint deflateBound(z_streamp strm, uint sourceLen);
|
int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
|
||||||
|
int max_chain);
|
||||||
|
/*
|
||||||
|
Fine tune deflate's internal compression parameters. This should only be
|
||||||
|
used by someone who understands the algorithm used by zlib's deflate for
|
||||||
|
searching for the best matching string, and even then only by the most
|
||||||
|
fanatic optimizer trying to squeeze out the last compressed bit for their
|
||||||
|
specific input data. Read the deflate.c source code for the meaning of the
|
||||||
|
max_lazy, good_length, nice_length, and max_chain parameters.
|
||||||
|
|
||||||
|
deflateTune() can be called after deflateInit() or deflateInit2(), and
|
||||||
|
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int deflateBound(z_streamp strm, uint sourceLen);
|
||||||
/*
|
/*
|
||||||
deflateBound() returns an upper bound on the compressed size after
|
deflateBound() returns an upper bound on the compressed size after
|
||||||
deflation of sourceLen bytes. It must be called after deflateInit()
|
deflation of sourceLen bytes. It must be called after deflateInit()
|
||||||
|
@ -626,6 +728,29 @@ int deflatePrime(z_streamp strm, int bits, int value);
|
||||||
stream state was inconsistent.
|
stream state was inconsistent.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int deflateSetHeader(z_streamp strm, gz_headerp head);
|
||||||
|
/*
|
||||||
|
deflateSetHeader() provides gzip header information for when a gzip
|
||||||
|
stream is requested by deflateInit2(). deflateSetHeader() may be called
|
||||||
|
after deflateInit2() or deflateReset() and before the first call of
|
||||||
|
deflate(). The text, time, os, extra field, name, and comment information
|
||||||
|
in the provided gz_header structure are written to the gzip header (xflag is
|
||||||
|
ignored -- the extra flags are set according to the compression level). The
|
||||||
|
caller must assure that, if not Z_NULL, name and comment are terminated with
|
||||||
|
a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
|
||||||
|
available there. If hcrc is true, a gzip header crc is included. Note that
|
||||||
|
the current versions of the command-line version of gzip (up through version
|
||||||
|
1.3.x) do not support header crc's, and will report that it is a "multi-part
|
||||||
|
gzip file" and give up.
|
||||||
|
|
||||||
|
If deflateSetHeader is not used, the default gzip header has text false,
|
||||||
|
the time set to zero, and os set to 255, with no extra, name, or comment
|
||||||
|
fields. The gzip header is returned to the default state by deflateReset().
|
||||||
|
|
||||||
|
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent.
|
||||||
|
*/
|
||||||
|
|
||||||
int inflateInit2(z_streamp strm, int windowBits)
|
int inflateInit2(z_streamp strm, int windowBits)
|
||||||
{
|
{
|
||||||
return inflateInit2_(strm, windowBits, ZLIB_VERSION, z_stream.sizeof);
|
return inflateInit2_(strm, windowBits, ZLIB_VERSION, z_stream.sizeof);
|
||||||
|
@ -659,24 +784,28 @@ int inflateInit2(z_streamp strm, int windowBits)
|
||||||
windowBits can also be greater than 15 for optional gzip decoding. Add
|
windowBits can also be greater than 15 for optional gzip decoding. Add
|
||||||
32 to windowBits to enable zlib and gzip decoding with automatic header
|
32 to windowBits to enable zlib and gzip decoding with automatic header
|
||||||
detection, or add 16 to decode only the gzip format (the zlib format will
|
detection, or add 16 to decode only the gzip format (the zlib format will
|
||||||
return a Z_DATA_ERROR).
|
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
|
||||||
|
a crc32 instead of an adler32.
|
||||||
|
|
||||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
|
||||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
is set to null if there is no error message. inflateInit2 does not perform
|
||||||
does not perform any decompression apart from reading the zlib header if
|
any decompression apart from reading the zlib header if present: this will
|
||||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
be done by inflate(). (So next_in and avail_in may be modified, but next_out
|
||||||
modified, but next_out and avail_out are unchanged.)
|
and avail_out are unchanged.)
|
||||||
*/
|
/
|
||||||
|
|
||||||
int inflateSetDictionary(z_streamp strm, ubyte* dictionary, uint dictLength);
|
int inflateSetDictionary(z_streamp strm, ubyte* dictionary, uint dictLength);
|
||||||
/*
|
/*
|
||||||
Initializes the decompression dictionary from the given uncompressed byte
|
Initializes the decompression dictionary from the given uncompressed byte
|
||||||
sequence. This function must be called immediately after a call of inflate
|
sequence. This function must be called immediately after a call of inflate,
|
||||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||||
can be determined from the adler32 value returned by this call of
|
can be determined from the adler32 value returned by that call of inflate.
|
||||||
inflate. The compressor and decompressor must use exactly the same
|
The compressor and decompressor must use exactly the same dictionary (see
|
||||||
dictionary (see deflateSetDictionary).
|
deflateSetDictionary). For raw inflate, this function can be called
|
||||||
|
immediately after inflateInit2() or inflateReset() and before any call of
|
||||||
|
inflate() to set the dictionary. The application must insure that the
|
||||||
|
dictionary that was used for compression is provided.
|
||||||
|
|
||||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||||
|
@ -1102,6 +1231,12 @@ int gzeof(gzFile file);
|
||||||
input stream, otherwise zero.
|
input stream, otherwise zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int gzdirect(gzFile file);
|
||||||
|
/*
|
||||||
|
Returns 1 if file is being read directly without decompression, otherwise
|
||||||
|
zero.
|
||||||
|
*/
|
||||||
|
|
||||||
int gzclose(gzFile file);
|
int gzclose(gzFile file);
|
||||||
/*
|
/*
|
||||||
Flushes all pending output if necessary, closes the compressed file
|
Flushes all pending output if necessary, closes the compressed file
|
||||||
|
@ -1150,12 +1285,20 @@ void gzclearerr (gzFile file);
|
||||||
if (adler != original_adler) error();
|
if (adler != original_adler) error();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
uint adler32_combine(uint adler1, uint adler2, z_off_t len2);
|
||||||
|
/*
|
||||||
|
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
|
||||||
|
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
|
||||||
|
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
|
||||||
|
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
|
||||||
|
*/
|
||||||
|
|
||||||
uint crc32(uint crc, ubyte *buf, uint len);
|
uint crc32(uint crc, ubyte *buf, uint len);
|
||||||
/*
|
/*
|
||||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
Update a running CRC-32 with the bytes buf[0..len-1] and return the
|
||||||
crc. If buf is NULL, this function returns the required initial value
|
updated CRC-32. If buf is NULL, this function returns the required initial
|
||||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
value for the for the crc. Pre- and post-conditioning (one's complement) is
|
||||||
within this function so it shouldn't be done by the application.
|
performed within this function so it shouldn't be done by the application.
|
||||||
Usage example:
|
Usage example:
|
||||||
|
|
||||||
uint crc = crc32(0L, Z_NULL, 0);
|
uint crc = crc32(0L, Z_NULL, 0);
|
||||||
|
@ -1166,6 +1309,16 @@ uint crc32(uint crc, ubyte *buf, uint len);
|
||||||
if (crc != original_crc) error();
|
if (crc != original_crc) error();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
uint crc32_combine (uint crc1, uint crc2, z_off_t len2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Combine two CRC-32 check values into one. For two sequences of bytes,
|
||||||
|
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
|
||||||
|
calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
|
||||||
|
check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
|
||||||
|
len2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* various hacks, don't look :) */
|
/* various hacks, don't look :) */
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,139 @@
|
||||||
|
|
||||||
ChangeLog file for zlib
|
ChangeLog file for zlib
|
||||||
|
|
||||||
|
Changes in 1.2.3 (18 July 2005)
|
||||||
|
- Apply security vulnerability fixes to contrib/infback9 as well
|
||||||
|
- Clean up some text files (carriage returns, trailing space)
|
||||||
|
- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
|
||||||
|
|
||||||
|
Changes in 1.2.2.4 (11 July 2005)
|
||||||
|
- Add inflatePrime() function for starting inflation at bit boundary
|
||||||
|
- Avoid some Visual C warnings in deflate.c
|
||||||
|
- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
|
||||||
|
compile
|
||||||
|
- Fix some spelling errors in comments [Betts]
|
||||||
|
- Correct inflateInit2() error return documentation in zlib.h
|
||||||
|
- Added zran.c example of compressed data random access to examples
|
||||||
|
directory, shows use of inflatePrime()
|
||||||
|
- Fix cast for assignments to strm->state in inflate.c and infback.c
|
||||||
|
- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
|
||||||
|
- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
|
||||||
|
- Add cast in trees.c t avoid a warning [Oberhumer]
|
||||||
|
- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
|
||||||
|
- Update make_vms.com [Zinser]
|
||||||
|
- Initialize state->write in inflateReset() since copied in inflate_fast()
|
||||||
|
- Be more strict on incomplete code sets in inflate_table() and increase
|
||||||
|
ENOUGH and MAXD -- this repairs a possible security vulnerability for
|
||||||
|
invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
|
||||||
|
discovering the vulnerability and providing test cases.
|
||||||
|
- Add ia64 support to configure for HP-UX [Smith]
|
||||||
|
- Add error return to gzread() for format or i/o error [Levin]
|
||||||
|
- Use malloc.h for OS/2 [Necasek]
|
||||||
|
|
||||||
|
Changes in 1.2.2.3 (27 May 2005)
|
||||||
|
- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
|
||||||
|
- Typecast fread() return values in gzio.c [Vollant]
|
||||||
|
- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
|
||||||
|
- Fix crc check bug in gzread() after gzungetc() [Heiner]
|
||||||
|
- Add the deflateTune() function to adjust internal compression parameters
|
||||||
|
- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
|
||||||
|
- Remove an incorrect assertion in examples/zpipe.c
|
||||||
|
- Add C++ wrapper in infback9.h [Donais]
|
||||||
|
- Fix bug in inflateCopy() when decoding fixed codes
|
||||||
|
- Note in zlib.h how much deflateSetDictionary() actually uses
|
||||||
|
- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
|
||||||
|
- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
|
||||||
|
- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
|
||||||
|
- Add gzdirect() function to indicate transparent reads
|
||||||
|
- Update contrib/minizip [Vollant]
|
||||||
|
- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
|
||||||
|
- Add casts in crc32.c to avoid warnings [Oberhumer]
|
||||||
|
- Add contrib/masmx64 [Vollant]
|
||||||
|
- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
|
||||||
|
|
||||||
|
Changes in 1.2.2.2 (30 December 2004)
|
||||||
|
- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
|
||||||
|
avoid implicit memcpy calls (portability for no-library compilation)
|
||||||
|
- Increase sprintf() buffer size in gzdopen() to allow for large numbers
|
||||||
|
- Add INFLATE_STRICT to check distances against zlib header
|
||||||
|
- Improve WinCE errno handling and comments [Chang]
|
||||||
|
- Remove comment about no gzip header processing in FAQ
|
||||||
|
- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
|
||||||
|
- Add updated make_vms.com [Coghlan], update README
|
||||||
|
- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
|
||||||
|
fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
|
||||||
|
- Add FAQ entry and comments in deflate.c on uninitialized memory access
|
||||||
|
- Add Solaris 9 make options in configure [Gilbert]
|
||||||
|
- Allow strerror() usage in gzio.c for STDC
|
||||||
|
- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
|
||||||
|
- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
|
||||||
|
- Use z_off_t for adler32_combine() and crc32_combine() lengths
|
||||||
|
- Make adler32() much faster for small len
|
||||||
|
- Use OS_CODE in deflate() default gzip header
|
||||||
|
|
||||||
|
Changes in 1.2.2.1 (31 October 2004)
|
||||||
|
- Allow inflateSetDictionary() call for raw inflate
|
||||||
|
- Fix inflate header crc check bug for file names and comments
|
||||||
|
- Add deflateSetHeader() and gz_header structure for custom gzip headers
|
||||||
|
- Add inflateGetheader() to retrieve gzip headers
|
||||||
|
- Add crc32_combine() and adler32_combine() functions
|
||||||
|
- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
|
||||||
|
- Use zstreamp consistently in zlib.h (inflate_back functions)
|
||||||
|
- Remove GUNZIP condition from definition of inflate_mode in inflate.h
|
||||||
|
and in contrib/inflate86/inffast.S [Truta, Anderson]
|
||||||
|
- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
|
||||||
|
- Update projects/README.projects and projects/visualc6 [Truta]
|
||||||
|
- Update win32/DLL_FAQ.txt [Truta]
|
||||||
|
- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
|
||||||
|
- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
|
||||||
|
- Use a new algorithm for setting strm->data_type in trees.c [Truta]
|
||||||
|
- Do not define an exit() prototype in zutil.c unless DEBUG defined
|
||||||
|
- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
|
||||||
|
- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
|
||||||
|
- Fix Darwin build version identification [Peterson]
|
||||||
|
|
||||||
|
Changes in 1.2.2 (3 October 2004)
|
||||||
|
- Update zlib.h comments on gzip in-memory processing
|
||||||
|
- Set adler to 1 in inflateReset() to support Java test suite [Walles]
|
||||||
|
- Add contrib/dotzlib [Ravn]
|
||||||
|
- Update win32/DLL_FAQ.txt [Truta]
|
||||||
|
- Update contrib/minizip [Vollant]
|
||||||
|
- Move contrib/visual-basic.txt to old/ [Truta]
|
||||||
|
- Fix assembler builds in projects/visualc6/ [Truta]
|
||||||
|
|
||||||
|
Changes in 1.2.1.2 (9 September 2004)
|
||||||
|
- Update INDEX file
|
||||||
|
- Fix trees.c to update strm->data_type (no one ever noticed!)
|
||||||
|
- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
|
||||||
|
- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
|
||||||
|
- Add limited multitasking protection to DYNAMIC_CRC_TABLE
|
||||||
|
- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
|
||||||
|
- Don't declare strerror() under VMS [Mozilla]
|
||||||
|
- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
|
||||||
|
- Update contrib/ada [Anisimkov]
|
||||||
|
- Update contrib/minizip [Vollant]
|
||||||
|
- Fix configure to not hardcode directories for Darwin [Peterson]
|
||||||
|
- Fix gzio.c to not return error on empty files [Brown]
|
||||||
|
- Fix indentation; update version in contrib/delphi/ZLib.pas and
|
||||||
|
contrib/pascal/zlibpas.pas [Truta]
|
||||||
|
- Update mkasm.bat in contrib/masmx86 [Truta]
|
||||||
|
- Update contrib/untgz [Truta]
|
||||||
|
- Add projects/README.projects [Truta]
|
||||||
|
- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
|
||||||
|
- Update win32/DLL_FAQ.txt [Truta]
|
||||||
|
- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
|
||||||
|
- Remove an unnecessary assignment to curr in inftrees.c [Truta]
|
||||||
|
- Add OS/2 to exe builds in configure [Poltorak]
|
||||||
|
- Remove err dummy parameter in zlib.h [Kientzle]
|
||||||
|
|
||||||
|
Changes in 1.2.1.1 (9 January 2004)
|
||||||
|
- Update email address in README
|
||||||
|
- Several FAQ updates
|
||||||
|
- Fix a big fat bug in inftrees.c that prevented decoding valid
|
||||||
|
dynamic blocks with only literals and no distance codes --
|
||||||
|
Thanks to "Hot Emu" for the bug report and sample file
|
||||||
|
- Add a note to puff.c on no distance codes case.
|
||||||
|
|
||||||
Changes in 1.2.1 (17 November 2003)
|
Changes in 1.2.1 (17 November 2003)
|
||||||
- Remove a tab in contrib/gzappend/gzappend.c
|
- Remove a tab in contrib/gzappend/gzappend.c
|
||||||
- Update some interfaces in contrib for new zlib functions
|
- Update some interfaces in contrib for new zlib functions
|
||||||
|
@ -407,7 +540,7 @@ Changes in 1.0.7 (20 Jan 1998)
|
||||||
Changes in 1.0.6 (19 Jan 1998)
|
Changes in 1.0.6 (19 Jan 1998)
|
||||||
- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
|
- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
|
||||||
gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
|
gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
|
||||||
- Fix a deflate bug occuring only with compression level 0 (thanks to
|
- Fix a deflate bug occurring only with compression level 0 (thanks to
|
||||||
Andy Buckler for finding this one).
|
Andy Buckler for finding this one).
|
||||||
- In minigzip, pass transparently also the first byte for .Z files.
|
- In minigzip, pass transparently also the first byte for .Z files.
|
||||||
- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
|
- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
|
||||||
|
|
100
etc/c/zlib/FAQ
100
etc/c/zlib/FAQ
|
@ -1,100 +0,0 @@
|
||||||
|
|
||||||
Frequently Asked Questions about zlib
|
|
||||||
|
|
||||||
|
|
||||||
If your question is not there, please check the zlib home page
|
|
||||||
http://www.zlib.org which may have more recent information.
|
|
||||||
The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
|
|
||||||
|
|
||||||
|
|
||||||
1. Is zlib Y2K-compliant?
|
|
||||||
|
|
||||||
Yes. zlib doesn't handle dates.
|
|
||||||
|
|
||||||
2. Where can I get a Windows DLL version?
|
|
||||||
|
|
||||||
The zlib sources can be compiled without change to produce a DLL. If you
|
|
||||||
want a precompiled DLL, see http://www.winimage.com/zLibDll/ . Questions
|
|
||||||
about the zlib DLL should be sent to Gilles Vollant (info@winimage.com).
|
|
||||||
|
|
||||||
3. Where can I get a Visual Basic interface to zlib?
|
|
||||||
|
|
||||||
See
|
|
||||||
* http://www.winimage.com/zLibDll/cmp-z-it.zip
|
|
||||||
* http://www.dogma.net/markn/articles/zlibtool/zlibtool.htm
|
|
||||||
* contrib/visual-basic.txt in the zlib distribution
|
|
||||||
|
|
||||||
4. compress() returns Z_BUF_ERROR
|
|
||||||
|
|
||||||
Make sure that before the call of compress, the length of the compressed
|
|
||||||
buffer is equal to the total size of the compressed buffer and not
|
|
||||||
zero. For Visual Basic, check that this parameter is passed by reference
|
|
||||||
("as any"), not by value ("as long").
|
|
||||||
|
|
||||||
5. deflate() or inflate() returns Z_BUF_ERROR
|
|
||||||
|
|
||||||
Before making the call, make sure that avail_in and avail_out are not
|
|
||||||
zero. When setting the parameter flush equal to Z_FINISH, also make sure
|
|
||||||
that avail_out is big enough to allow processing all pending input.
|
|
||||||
|
|
||||||
6. Where's the zlib documentation (man pages, etc.)?
|
|
||||||
|
|
||||||
It's in zlib.h for the moment, and Francis S. Lin has converted it to a
|
|
||||||
web page zlib.html. Volunteers to transform this to Unix-style man pages,
|
|
||||||
please contact Jean-loup Gailly (jloup@gzip.org). Examples of zlib usage
|
|
||||||
are in the files example.c and minigzip.c.
|
|
||||||
|
|
||||||
7. Why don't you use GNU autoconf or libtool or ...?
|
|
||||||
|
|
||||||
Because we would like to keep zlib as a very small and simple
|
|
||||||
package. zlib is rather portable and doesn't need much configuration.
|
|
||||||
|
|
||||||
8. I found a bug in zlib.
|
|
||||||
|
|
||||||
Most of the time, such problems are due to an incorrect usage of
|
|
||||||
zlib. Please try to reproduce the problem with a small program and send
|
|
||||||
the corresponding source to us at zlib@gzip.org . Do not send
|
|
||||||
multi-megabyte data files without prior agreement.
|
|
||||||
|
|
||||||
9. Why do I get "undefined reference to gzputc"?
|
|
||||||
|
|
||||||
If "make test" produces something like
|
|
||||||
|
|
||||||
example.o(.text+0x154): undefined reference to `gzputc'
|
|
||||||
|
|
||||||
check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
|
|
||||||
/usr/X11R6/lib. Remove any old versions, then do "make install".
|
|
||||||
|
|
||||||
10. I need a Delphi interface to zlib.
|
|
||||||
|
|
||||||
See the directories contrib/delphi and contrib/delphi2 in the zlib
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
11. Can zlib handle .zip archives?
|
|
||||||
|
|
||||||
See the directory contrib/minizip in the zlib distribution.
|
|
||||||
|
|
||||||
12. Can zlib handle .Z files?
|
|
||||||
|
|
||||||
No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
|
|
||||||
the code of uncompress on your own.
|
|
||||||
|
|
||||||
13. How can I make a Unix shared library?
|
|
||||||
|
|
||||||
make clean
|
|
||||||
./configure -s
|
|
||||||
make
|
|
||||||
|
|
||||||
14. Why does "make test" fail on Mac OS X?
|
|
||||||
|
|
||||||
Mac OS X already includes zlib as a shared library, and so -lz links the
|
|
||||||
shared library instead of the one that the "make" compiled. For zlib
|
|
||||||
1.1.3, the two are incompatible due to different compile-time
|
|
||||||
options. Simply change the -lz in the Makefile to libz.a, and it will use
|
|
||||||
the compiled library instead of the shared one and the "make test" will
|
|
||||||
succeed.
|
|
||||||
|
|
||||||
15. I have a question about OttoPDF
|
|
||||||
|
|
||||||
We are not the authors of OttoPDF. The real author is on the OttoPDF web
|
|
||||||
site Joel Hainley jhainley@myndkryme.com.
|
|
|
@ -1,86 +0,0 @@
|
||||||
ChangeLog history of changes
|
|
||||||
INDEX this file
|
|
||||||
FAQ Frequently Asked Questions about zlib
|
|
||||||
Make_vms.com script for Vax/VMS
|
|
||||||
Makefile makefile for Unix (generated by configure)
|
|
||||||
Makefile.in makefile for Unix (template for configure)
|
|
||||||
Makefile.riscos makefile for RISCOS
|
|
||||||
README guess what
|
|
||||||
algorithm.txt description of the (de)compression algorithm
|
|
||||||
configure configure script for Unix
|
|
||||||
descrip.mms makefile for Vax/VMS
|
|
||||||
zlib.3 mini man page for zlib (volunteers to write full
|
|
||||||
man pages from zlib.h welcome. write to jloup@gzip.org)
|
|
||||||
|
|
||||||
amiga/Makefile.sas makefile for Amiga SAS/C
|
|
||||||
amiga/Makefile.pup makefile for Amiga powerUP SAS/C PPC
|
|
||||||
|
|
||||||
msdos/Makefile.w32 makefile for Microsoft Visual C++ 32-bit
|
|
||||||
msdos/Makefile.b32 makefile for Borland C++ 32-bit
|
|
||||||
msdos/Makefile.bor makefile for Borland C/C++ 16-bit
|
|
||||||
msdos/Makefile.dj2 makefile for DJGPP 2.x
|
|
||||||
msdos/Makefile.emx makefile for EMX 0.9c (32-bit DOS/OS2)
|
|
||||||
msdos/Makefile.msc makefile for Microsoft C 16-bit
|
|
||||||
msdos/Makefile.tc makefile for Turbo C
|
|
||||||
msdos/Makefile.wat makefile for Watcom C
|
|
||||||
msdos/zlib.def definition file for Windows DLL
|
|
||||||
msdos/zlib.rc definition file for Windows DLL
|
|
||||||
|
|
||||||
nt/Makefile.nt makefile for Windows NT
|
|
||||||
nt/zlib.dnt definition file for Windows NT DLL
|
|
||||||
nt/Makefile.emx makefile for EMX 0.9c/RSXNT 1.41 (Win32 Intel)
|
|
||||||
nt/Makefile.gcc makefile for Windows NT using GCC (mingw32)
|
|
||||||
|
|
||||||
|
|
||||||
zlib public header files (must be kept):
|
|
||||||
zconf.h
|
|
||||||
zlib.h
|
|
||||||
|
|
||||||
private source files used to build the zlib library:
|
|
||||||
adler32.c
|
|
||||||
compress.c
|
|
||||||
crc32.c
|
|
||||||
deflate.c
|
|
||||||
deflate.h
|
|
||||||
gzio.c
|
|
||||||
infblock.c
|
|
||||||
infblock.h
|
|
||||||
infcodes.c
|
|
||||||
infcodes.h
|
|
||||||
inffast.c
|
|
||||||
inffast.h
|
|
||||||
inflate.c
|
|
||||||
inftrees.c
|
|
||||||
inftrees.h
|
|
||||||
infutil.c
|
|
||||||
infutil.h
|
|
||||||
maketree.c
|
|
||||||
trees.c
|
|
||||||
uncompr.c
|
|
||||||
zutil.c
|
|
||||||
zutil.h
|
|
||||||
|
|
||||||
source files for sample programs:
|
|
||||||
example.c
|
|
||||||
minigzip.c
|
|
||||||
|
|
||||||
unsupported contribution by third parties
|
|
||||||
|
|
||||||
contrib/asm386/ by Gilles Vollant <info@winimage.com>
|
|
||||||
386 asm code replacing longest_match().
|
|
||||||
|
|
||||||
contrib/minizip/ by Gilles Vollant <info@winimage.com>
|
|
||||||
Mini zip and unzip based on zlib
|
|
||||||
See http://www.winimage.com/zLibDll/unzip.html
|
|
||||||
|
|
||||||
contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
|
|
||||||
A C++ I/O streams interface to the zlib gz* functions
|
|
||||||
|
|
||||||
contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
|
|
||||||
Another C++ I/O streams interface
|
|
||||||
|
|
||||||
contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
|
|
||||||
A very simple tar.gz extractor using zlib
|
|
||||||
|
|
||||||
contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
|
|
||||||
How to use compress(), uncompress() and the gz* functions from VB.
|
|
|
@ -1,11 +1,6 @@
|
||||||
==================================================
|
|
||||||
To build with Digital Mars C:
|
|
||||||
make -f win32.mak
|
|
||||||
==================================================
|
|
||||||
|
|
||||||
ZLIB DATA COMPRESSION LIBRARY
|
ZLIB DATA COMPRESSION LIBRARY
|
||||||
|
|
||||||
zlib 1.2.1 is a general purpose data compression library. All the code is
|
zlib 1.2.3 is a general purpose data compression library. All the code is
|
||||||
thread safe. The data format used by the zlib library is described by RFCs
|
thread safe. The data format used by the zlib library is described by RFCs
|
||||||
(Request for Comments) 1950 to 1952 in the files
|
(Request for Comments) 1950 to 1952 in the files
|
||||||
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
|
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
|
||||||
|
@ -21,9 +16,8 @@ minigzip.c.
|
||||||
|
|
||||||
To compile all files and run the test program, follow the instructions given at
|
To compile all files and run the test program, follow the instructions given at
|
||||||
the top of Makefile. In short "make test; make install" should work for most
|
the top of Makefile. In short "make test; make install" should work for most
|
||||||
machines. For Unix: "./configure; make test; make install" For MSDOS, use one
|
machines. For Unix: "./configure; make test; make install". For MSDOS, use one
|
||||||
of the special makefiles such as Makefile.msc. For VMS, use Make_vms.com or
|
of the special makefiles such as Makefile.msc. For VMS, use make_vms.com.
|
||||||
descrip.mms.
|
|
||||||
|
|
||||||
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
|
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
|
||||||
<info@winimage.com> for the Windows DLL version. The zlib home page is
|
<info@winimage.com> for the Windows DLL version. The zlib home page is
|
||||||
|
@ -39,7 +33,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
|
||||||
issue of Dr. Dobb's Journal; a copy of the article is available in
|
issue of Dr. Dobb's Journal; a copy of the article is available in
|
||||||
http://dogma.net/markn/articles/zlibtool/zlibtool.htm
|
http://dogma.net/markn/articles/zlibtool/zlibtool.htm
|
||||||
|
|
||||||
The changes made in version 1.2.1 are documented in the file ChangeLog.
|
The changes made in version 1.2.3 are documented in the file ChangeLog.
|
||||||
|
|
||||||
Unsupported third party contributions are provided in directory "contrib".
|
Unsupported third party contributions are provided in directory "contrib".
|
||||||
|
|
||||||
|
@ -51,7 +45,7 @@ A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
|
||||||
CPAN (Comprehensive Perl Archive Network) sites
|
CPAN (Comprehensive Perl Archive Network) sites
|
||||||
http://www.cpan.org/modules/by-module/Compress/
|
http://www.cpan.org/modules/by-module/Compress/
|
||||||
|
|
||||||
A Python interface to zlib written by A.M. Kuchling <amk@magnet.com> is
|
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
|
||||||
available in Python 1.5 and later versions, see
|
available in Python 1.5 and later versions, see
|
||||||
http://www.python.org/doc/lib/module-zlib.html
|
http://www.python.org/doc/lib/module-zlib.html
|
||||||
|
|
||||||
|
@ -98,7 +92,7 @@ Acknowledgments:
|
||||||
|
|
||||||
Copyright notice:
|
Copyright notice:
|
||||||
|
|
||||||
(C) 1995-2003 Jean-loup Gailly and Mark Adler
|
(C) 1995-2004 Jean-loup Gailly and Mark Adler
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* 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-2003 Mark Adler
|
* Copyright (C) 1995-2004 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -12,12 +12,13 @@
|
||||||
#define NMAX 5552
|
#define NMAX 5552
|
||||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||||
|
|
||||||
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
|
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
||||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||||
|
|
||||||
|
/* use NO_DIVIDE if your processor does not do division in hardware */
|
||||||
#ifdef NO_DIVIDE
|
#ifdef NO_DIVIDE
|
||||||
# define MOD(a) \
|
# define MOD(a) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -39,8 +40,17 @@
|
||||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
||||||
if (a >= BASE) a -= BASE; \
|
if (a >= BASE) a -= BASE; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
# define MOD4(a) \
|
||||||
|
do { \
|
||||||
|
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
||||||
|
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
||||||
|
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
||||||
|
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
||||||
|
if (a >= BASE) a -= BASE; \
|
||||||
|
} while (0)
|
||||||
#else
|
#else
|
||||||
# define MOD(a) a %= BASE
|
# define MOD(a) a %= BASE
|
||||||
|
# define MOD4(a) a %= BASE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
@ -49,26 +59,91 @@ uLong ZEXPORT adler32(adler, buf, len)
|
||||||
const Bytef *buf;
|
const Bytef *buf;
|
||||||
uInt len;
|
uInt len;
|
||||||
{
|
{
|
||||||
unsigned long s1 = adler & 0xffff;
|
unsigned long sum2;
|
||||||
unsigned long s2 = (adler >> 16) & 0xffff;
|
unsigned n;
|
||||||
int k;
|
|
||||||
|
|
||||||
if (buf == Z_NULL) return 1L;
|
/* split Adler-32 into component sums */
|
||||||
|
sum2 = (adler >> 16) & 0xffff;
|
||||||
|
adler &= 0xffff;
|
||||||
|
|
||||||
while (len > 0) {
|
/* in case user likes doing a byte at a time, keep it fast */
|
||||||
k = len < NMAX ? (int)len : NMAX;
|
if (len == 1) {
|
||||||
len -= k;
|
adler += buf[0];
|
||||||
while (k >= 16) {
|
if (adler >= BASE)
|
||||||
|
adler -= BASE;
|
||||||
|
sum2 += adler;
|
||||||
|
if (sum2 >= BASE)
|
||||||
|
sum2 -= BASE;
|
||||||
|
return adler | (sum2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initial Adler-32 value (deferred check for len == 1 speed) */
|
||||||
|
if (buf == Z_NULL)
|
||||||
|
return 1L;
|
||||||
|
|
||||||
|
/* in case short lengths are provided, keep it somewhat fast */
|
||||||
|
if (len < 16) {
|
||||||
|
while (len--) {
|
||||||
|
adler += *buf++;
|
||||||
|
sum2 += adler;
|
||||||
|
}
|
||||||
|
if (adler >= BASE)
|
||||||
|
adler -= BASE;
|
||||||
|
MOD4(sum2); /* only added so many BASE's */
|
||||||
|
return adler | (sum2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do length NMAX blocks -- requires just one modulo operation */
|
||||||
|
while (len >= NMAX) {
|
||||||
|
len -= NMAX;
|
||||||
|
n = NMAX / 16; /* NMAX is divisible by 16 */
|
||||||
|
do {
|
||||||
|
DO16(buf); /* 16 sums unrolled */
|
||||||
|
buf += 16;
|
||||||
|
} while (--n);
|
||||||
|
MOD(adler);
|
||||||
|
MOD(sum2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do remaining bytes (less than NMAX, still just one modulo) */
|
||||||
|
if (len) { /* avoid modulos if none remaining */
|
||||||
|
while (len >= 16) {
|
||||||
|
len -= 16;
|
||||||
DO16(buf);
|
DO16(buf);
|
||||||
buf += 16;
|
buf += 16;
|
||||||
k -= 16;
|
|
||||||
}
|
}
|
||||||
if (k != 0) do {
|
while (len--) {
|
||||||
s1 += *buf++;
|
adler += *buf++;
|
||||||
s2 += s1;
|
sum2 += adler;
|
||||||
} while (--k);
|
}
|
||||||
MOD(s1);
|
MOD(adler);
|
||||||
MOD(s2);
|
MOD(sum2);
|
||||||
}
|
}
|
||||||
return (s2 << 16) | s1;
|
|
||||||
|
/* return recombined sums */
|
||||||
|
return adler | (sum2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||||
|
uLong adler1;
|
||||||
|
uLong adler2;
|
||||||
|
z_off_t len2;
|
||||||
|
{
|
||||||
|
unsigned long sum1;
|
||||||
|
unsigned long sum2;
|
||||||
|
unsigned rem;
|
||||||
|
|
||||||
|
/* the derivation of this formula is left as an exercise for the reader */
|
||||||
|
rem = (unsigned)(len2 % BASE);
|
||||||
|
sum1 = adler1 & 0xffff;
|
||||||
|
sum2 = rem * sum1;
|
||||||
|
MOD(sum2);
|
||||||
|
sum1 += (adler2 & 0xffff) + BASE - 1;
|
||||||
|
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||||
|
if (sum1 > BASE) sum1 -= BASE;
|
||||||
|
if (sum1 > BASE) sum1 -= BASE;
|
||||||
|
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
|
||||||
|
if (sum2 > BASE) sum2 -= BASE;
|
||||||
|
return sum1 | (sum2 << 16);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* compress.c -- compress a memory buffer
|
/* compress.c -- compress a memory buffer
|
||||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
* Copyright (C) 1995-2003 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
/* crc32.c -- compute the CRC-32 of a data stream
|
/* crc32.c -- compute the CRC-32 of a data stream
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2005 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
|
||||||
*
|
*
|
||||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||||
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
||||||
* tables for updating the shift register in one step with three exclusive-ors
|
* tables for updating the shift register in one step with three exclusive-ors
|
||||||
* instead of four steps with four exclusive-ors. This results about a factor
|
* instead of four steps with four exclusive-ors. This results in about a
|
||||||
* of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
|
||||||
|
protection on the static variables used to control the first-use generation
|
||||||
|
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
||||||
|
first call get_crc_table() to initialize the tables before allowing more than
|
||||||
|
one thread to use crc32().
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef MAKECRCH
|
#ifdef MAKECRCH
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# ifndef DYNAMIC_CRC_TABLE
|
# ifndef DYNAMIC_CRC_TABLE
|
||||||
|
@ -56,15 +64,19 @@
|
||||||
# define TBLS 1
|
# define TBLS 1
|
||||||
#endif /* BYFOUR */
|
#endif /* BYFOUR */
|
||||||
|
|
||||||
|
/* Local functions for crc concatenation */
|
||||||
|
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||||
|
unsigned long vec));
|
||||||
|
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||||
|
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
|
|
||||||
local int crc_table_empty = 1;
|
local volatile int crc_table_empty = 1;
|
||||||
local unsigned long FAR crc_table[TBLS][256];
|
local unsigned long FAR crc_table[TBLS][256];
|
||||||
local void make_crc_table OF((void));
|
local void make_crc_table OF((void));
|
||||||
#ifdef MAKECRCH
|
#ifdef MAKECRCH
|
||||||
local void write_table OF((FILE *, const unsigned long FAR *));
|
local void write_table OF((FILE *, const unsigned long FAR *));
|
||||||
#endif /* MAKECRCH */
|
#endif /* MAKECRCH */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||||
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||||
|
@ -95,38 +107,51 @@ local void make_crc_table()
|
||||||
{
|
{
|
||||||
unsigned long c;
|
unsigned long c;
|
||||||
int n, k;
|
int n, k;
|
||||||
unsigned long poly; /* polynomial exclusive-or pattern */
|
unsigned long poly; /* polynomial exclusive-or pattern */
|
||||||
/* terms of polynomial defining this crc (except x^32): */
|
/* terms of polynomial defining this crc (except x^32): */
|
||||||
|
static volatile int first = 1; /* flag to limit concurrent making */
|
||||||
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||||
|
|
||||||
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
/* See if another task is already doing this (not thread-safe, but better
|
||||||
poly = 0UL;
|
than nothing -- significantly reduces duration of vulnerability in
|
||||||
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
case the advice about DYNAMIC_CRC_TABLE is ignored) */
|
||||||
poly |= 1UL << (31 - p[n]);
|
if (first) {
|
||||||
|
first = 0;
|
||||||
|
|
||||||
/* generate a crc for every 8-bit value */
|
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
||||||
for (n = 0; n < 256; n++) {
|
poly = 0UL;
|
||||||
c = (unsigned long)n;
|
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
||||||
for (k = 0; k < 8; k++)
|
poly |= 1UL << (31 - p[n]);
|
||||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
|
||||||
crc_table[0][n] = c;
|
/* generate a crc for every 8-bit value */
|
||||||
}
|
for (n = 0; n < 256; n++) {
|
||||||
|
c = (unsigned long)n;
|
||||||
|
for (k = 0; k < 8; k++)
|
||||||
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||||
|
crc_table[0][n] = c;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef BYFOUR
|
#ifdef BYFOUR
|
||||||
/* generate crc for each value followed by one, two, and three zeros, and
|
/* generate crc for each value followed by one, two, and three zeros,
|
||||||
then the byte reversal of those as well as the first table */
|
and then the byte reversal of those as well as the first table */
|
||||||
for (n = 0; n < 256; n++) {
|
for (n = 0; n < 256; n++) {
|
||||||
c = crc_table[0][n];
|
c = crc_table[0][n];
|
||||||
crc_table[4][n] = REV(c);
|
crc_table[4][n] = REV(c);
|
||||||
for (k = 1; k < 4; k++) {
|
for (k = 1; k < 4; k++) {
|
||||||
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
||||||
crc_table[k][n] = c;
|
crc_table[k][n] = c;
|
||||||
crc_table[k + 4][n] = REV(c);
|
crc_table[k + 4][n] = REV(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif /* BYFOUR */
|
#endif /* BYFOUR */
|
||||||
|
|
||||||
crc_table_empty = 0;
|
crc_table_empty = 0;
|
||||||
|
}
|
||||||
|
else { /* not first */
|
||||||
|
/* wait for the other guy to finish (not efficient, but rare) */
|
||||||
|
while (crc_table_empty)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MAKECRCH
|
#ifdef MAKECRCH
|
||||||
/* write out CRC tables to crc32.h */
|
/* write out CRC tables to crc32.h */
|
||||||
|
@ -180,9 +205,10 @@ local void write_table(out, table)
|
||||||
const unsigned long FAR * ZEXPORT get_crc_table()
|
const unsigned long FAR * ZEXPORT get_crc_table()
|
||||||
{
|
{
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
if (crc_table_empty) make_crc_table();
|
if (crc_table_empty)
|
||||||
|
make_crc_table();
|
||||||
#endif /* DYNAMIC_CRC_TABLE */
|
#endif /* DYNAMIC_CRC_TABLE */
|
||||||
return (const unsigned long FAR *)crc_table;
|
return (const unsigned long FAR *)crc_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
@ -248,7 +274,7 @@ local unsigned long crc32_little(crc, buf, len)
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf4 = (const u4 FAR *)buf;
|
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
||||||
while (len >= 32) {
|
while (len >= 32) {
|
||||||
DOLIT32;
|
DOLIT32;
|
||||||
len -= 32;
|
len -= 32;
|
||||||
|
@ -288,7 +314,7 @@ local unsigned long crc32_big(crc, buf, len)
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf4 = (const u4 FAR *)buf;
|
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
||||||
buf4--;
|
buf4--;
|
||||||
while (len >= 32) {
|
while (len >= 32) {
|
||||||
DOBIG32;
|
DOBIG32;
|
||||||
|
@ -309,3 +335,89 @@ local unsigned long crc32_big(crc, buf, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* BYFOUR */
|
#endif /* BYFOUR */
|
||||||
|
|
||||||
|
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
local unsigned long gf2_matrix_times(mat, vec)
|
||||||
|
unsigned long *mat;
|
||||||
|
unsigned long vec;
|
||||||
|
{
|
||||||
|
unsigned long sum;
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
while (vec) {
|
||||||
|
if (vec & 1)
|
||||||
|
sum ^= *mat;
|
||||||
|
vec >>= 1;
|
||||||
|
mat++;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
local void gf2_matrix_square(square, mat)
|
||||||
|
unsigned long *square;
|
||||||
|
unsigned long *mat;
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
for (n = 0; n < GF2_DIM; n++)
|
||||||
|
square[n] = gf2_matrix_times(mat, mat[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||||
|
uLong crc1;
|
||||||
|
uLong crc2;
|
||||||
|
z_off_t len2;
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
unsigned long row;
|
||||||
|
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||||
|
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||||
|
|
||||||
|
/* degenerate case */
|
||||||
|
if (len2 == 0)
|
||||||
|
return crc1;
|
||||||
|
|
||||||
|
/* put operator for one zero bit in odd */
|
||||||
|
odd[0] = 0xedb88320L; /* CRC-32 polynomial */
|
||||||
|
row = 1;
|
||||||
|
for (n = 1; n < GF2_DIM; n++) {
|
||||||
|
odd[n] = row;
|
||||||
|
row <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* put operator for two zero bits in even */
|
||||||
|
gf2_matrix_square(even, odd);
|
||||||
|
|
||||||
|
/* put operator for four zero bits in odd */
|
||||||
|
gf2_matrix_square(odd, even);
|
||||||
|
|
||||||
|
/* apply len2 zeros to crc1 (first square will put the operator for one
|
||||||
|
zero byte, eight zero bits, in even) */
|
||||||
|
do {
|
||||||
|
/* apply zeros operator for this bit of len2 */
|
||||||
|
gf2_matrix_square(even, odd);
|
||||||
|
if (len2 & 1)
|
||||||
|
crc1 = gf2_matrix_times(even, crc1);
|
||||||
|
len2 >>= 1;
|
||||||
|
|
||||||
|
/* if no more bits set, then done */
|
||||||
|
if (len2 == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* another iteration of the loop with odd and even swapped */
|
||||||
|
gf2_matrix_square(odd, even);
|
||||||
|
if (len2 & 1)
|
||||||
|
crc1 = gf2_matrix_times(odd, crc1);
|
||||||
|
len2 >>= 1;
|
||||||
|
|
||||||
|
/* if no more bits set, then done */
|
||||||
|
} while (len2 != 0);
|
||||||
|
|
||||||
|
/* return combined crc */
|
||||||
|
crc1 ^= crc2;
|
||||||
|
return crc1;
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* deflate.c -- compress data using the deflation algorithm
|
/* deflate.c -- compress data using the deflation algorithm
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
#include "deflate.h"
|
#include "deflate.h"
|
||||||
|
|
||||||
const char deflate_copyright[] =
|
const char deflate_copyright[] =
|
||||||
" deflate 1.2.1 Copyright 1995-2003 Jean-loup Gailly ";
|
" deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
|
||||||
/*
|
/*
|
||||||
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
|
||||||
|
@ -264,7 +264,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||||
#endif
|
#endif
|
||||||
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
|
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
|
||||||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
|
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
|
||||||
strategy < 0 || strategy > Z_RLE) {
|
strategy < 0 || strategy > Z_FIXED) {
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
|
if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
|
||||||
|
@ -274,6 +274,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||||
s->strm = strm;
|
s->strm = strm;
|
||||||
|
|
||||||
s->wrap = wrap;
|
s->wrap = wrap;
|
||||||
|
s->gzhead = Z_NULL;
|
||||||
s->w_bits = windowBits;
|
s->w_bits = windowBits;
|
||||||
s->w_size = 1 << s->w_bits;
|
s->w_size = 1 << s->w_bits;
|
||||||
s->w_mask = s->w_size - 1;
|
s->w_mask = s->w_size - 1;
|
||||||
|
@ -333,9 +334,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
||||||
if (length < MIN_MATCH) return Z_OK;
|
if (length < MIN_MATCH) return Z_OK;
|
||||||
if (length > MAX_DIST(s)) {
|
if (length > MAX_DIST(s)) {
|
||||||
length = MAX_DIST(s);
|
length = MAX_DIST(s);
|
||||||
#ifndef USE_DICT_HEAD
|
|
||||||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
dictionary += dictLength - length; /* use the tail of the dictionary */
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
zmemcpy(s->window, dictionary, length);
|
zmemcpy(s->window, dictionary, length);
|
||||||
s->strstart = length;
|
s->strstart = length;
|
||||||
|
@ -390,6 +389,17 @@ int ZEXPORT deflateReset (strm)
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
int ZEXPORT deflateSetHeader (strm, head)
|
||||||
|
z_streamp strm;
|
||||||
|
gz_headerp head;
|
||||||
|
{
|
||||||
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
|
if (strm->state->wrap != 2) return Z_STREAM_ERROR;
|
||||||
|
strm->state->gzhead = head;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
int ZEXPORT deflatePrime (strm, bits, value)
|
int ZEXPORT deflatePrime (strm, bits, value)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
|
@ -420,7 +430,7 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
||||||
#else
|
#else
|
||||||
if (level == Z_DEFAULT_COMPRESSION) level = 6;
|
if (level == Z_DEFAULT_COMPRESSION) level = 6;
|
||||||
#endif
|
#endif
|
||||||
if (level < 0 || level > 9 || strategy < 0 || strategy > Z_RLE) {
|
if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
func = configuration_table[s->level].func;
|
func = configuration_table[s->level].func;
|
||||||
|
@ -440,6 +450,25 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
|
||||||
|
z_streamp strm;
|
||||||
|
int good_length;
|
||||||
|
int max_lazy;
|
||||||
|
int nice_length;
|
||||||
|
int max_chain;
|
||||||
|
{
|
||||||
|
deflate_state *s;
|
||||||
|
|
||||||
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
|
s = strm->state;
|
||||||
|
s->good_match = good_length;
|
||||||
|
s->max_lazy_match = max_lazy;
|
||||||
|
s->nice_match = nice_length;
|
||||||
|
s->max_chain_length = max_chain;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
* For the default windowBits of 15 and memLevel of 8, this function returns
|
* For the default windowBits of 15 and memLevel of 8, this function returns
|
||||||
* a close to exact, as well as small, upper bound on the compressed size.
|
* a close to exact, as well as small, upper bound on the compressed size.
|
||||||
|
@ -548,20 +577,47 @@ int ZEXPORT deflate (strm, flush)
|
||||||
if (s->status == INIT_STATE) {
|
if (s->status == INIT_STATE) {
|
||||||
#ifdef GZIP
|
#ifdef GZIP
|
||||||
if (s->wrap == 2) {
|
if (s->wrap == 2) {
|
||||||
|
strm->adler = crc32(0L, Z_NULL, 0);
|
||||||
put_byte(s, 31);
|
put_byte(s, 31);
|
||||||
put_byte(s, 139);
|
put_byte(s, 139);
|
||||||
put_byte(s, 8);
|
put_byte(s, 8);
|
||||||
put_byte(s, 0);
|
if (s->gzhead == NULL) {
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
put_byte(s, s->level == 9 ? 2 :
|
put_byte(s, 0);
|
||||||
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
|
put_byte(s, s->level == 9 ? 2 :
|
||||||
4 : 0));
|
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
|
||||||
put_byte(s, 255);
|
4 : 0));
|
||||||
s->status = BUSY_STATE;
|
put_byte(s, OS_CODE);
|
||||||
strm->adler = crc32(0L, Z_NULL, 0);
|
s->status = BUSY_STATE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
put_byte(s, (s->gzhead->text ? 1 : 0) +
|
||||||
|
(s->gzhead->hcrc ? 2 : 0) +
|
||||||
|
(s->gzhead->extra == Z_NULL ? 0 : 4) +
|
||||||
|
(s->gzhead->name == Z_NULL ? 0 : 8) +
|
||||||
|
(s->gzhead->comment == Z_NULL ? 0 : 16)
|
||||||
|
);
|
||||||
|
put_byte(s, (Byte)(s->gzhead->time & 0xff));
|
||||||
|
put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
|
||||||
|
put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
|
||||||
|
put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
|
||||||
|
put_byte(s, s->level == 9 ? 2 :
|
||||||
|
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
|
||||||
|
4 : 0));
|
||||||
|
put_byte(s, s->gzhead->os & 0xff);
|
||||||
|
if (s->gzhead->extra != NULL) {
|
||||||
|
put_byte(s, s->gzhead->extra_len & 0xff);
|
||||||
|
put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
|
||||||
|
}
|
||||||
|
if (s->gzhead->hcrc)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf,
|
||||||
|
s->pending);
|
||||||
|
s->gzindex = 0;
|
||||||
|
s->status = EXTRA_STATE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -592,6 +648,110 @@ int ZEXPORT deflate (strm, flush)
|
||||||
strm->adler = adler32(0L, Z_NULL, 0);
|
strm->adler = adler32(0L, Z_NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef GZIP
|
||||||
|
if (s->status == EXTRA_STATE) {
|
||||||
|
if (s->gzhead->extra != NULL) {
|
||||||
|
uInt beg = s->pending; /* start of bytes to update crc */
|
||||||
|
|
||||||
|
while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
|
||||||
|
if (s->pending == s->pending_buf_size) {
|
||||||
|
if (s->gzhead->hcrc && s->pending > beg)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf + beg,
|
||||||
|
s->pending - beg);
|
||||||
|
flush_pending(strm);
|
||||||
|
beg = s->pending;
|
||||||
|
if (s->pending == s->pending_buf_size)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
put_byte(s, s->gzhead->extra[s->gzindex]);
|
||||||
|
s->gzindex++;
|
||||||
|
}
|
||||||
|
if (s->gzhead->hcrc && s->pending > beg)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf + beg,
|
||||||
|
s->pending - beg);
|
||||||
|
if (s->gzindex == s->gzhead->extra_len) {
|
||||||
|
s->gzindex = 0;
|
||||||
|
s->status = NAME_STATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s->status = NAME_STATE;
|
||||||
|
}
|
||||||
|
if (s->status == NAME_STATE) {
|
||||||
|
if (s->gzhead->name != NULL) {
|
||||||
|
uInt beg = s->pending; /* start of bytes to update crc */
|
||||||
|
int val;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (s->pending == s->pending_buf_size) {
|
||||||
|
if (s->gzhead->hcrc && s->pending > beg)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf + beg,
|
||||||
|
s->pending - beg);
|
||||||
|
flush_pending(strm);
|
||||||
|
beg = s->pending;
|
||||||
|
if (s->pending == s->pending_buf_size) {
|
||||||
|
val = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val = s->gzhead->name[s->gzindex++];
|
||||||
|
put_byte(s, val);
|
||||||
|
} while (val != 0);
|
||||||
|
if (s->gzhead->hcrc && s->pending > beg)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf + beg,
|
||||||
|
s->pending - beg);
|
||||||
|
if (val == 0) {
|
||||||
|
s->gzindex = 0;
|
||||||
|
s->status = COMMENT_STATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s->status = COMMENT_STATE;
|
||||||
|
}
|
||||||
|
if (s->status == COMMENT_STATE) {
|
||||||
|
if (s->gzhead->comment != NULL) {
|
||||||
|
uInt beg = s->pending; /* start of bytes to update crc */
|
||||||
|
int val;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (s->pending == s->pending_buf_size) {
|
||||||
|
if (s->gzhead->hcrc && s->pending > beg)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf + beg,
|
||||||
|
s->pending - beg);
|
||||||
|
flush_pending(strm);
|
||||||
|
beg = s->pending;
|
||||||
|
if (s->pending == s->pending_buf_size) {
|
||||||
|
val = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val = s->gzhead->comment[s->gzindex++];
|
||||||
|
put_byte(s, val);
|
||||||
|
} while (val != 0);
|
||||||
|
if (s->gzhead->hcrc && s->pending > beg)
|
||||||
|
strm->adler = crc32(strm->adler, s->pending_buf + beg,
|
||||||
|
s->pending - beg);
|
||||||
|
if (val == 0)
|
||||||
|
s->status = HCRC_STATE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s->status = HCRC_STATE;
|
||||||
|
}
|
||||||
|
if (s->status == HCRC_STATE) {
|
||||||
|
if (s->gzhead->hcrc) {
|
||||||
|
if (s->pending + 2 > s->pending_buf_size)
|
||||||
|
flush_pending(strm);
|
||||||
|
if (s->pending + 2 <= s->pending_buf_size) {
|
||||||
|
put_byte(s, (Byte)(strm->adler & 0xff));
|
||||||
|
put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
|
||||||
|
strm->adler = crc32(0L, Z_NULL, 0);
|
||||||
|
s->status = BUSY_STATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s->status = BUSY_STATE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Flush as much pending output as possible */
|
/* Flush as much pending output as possible */
|
||||||
if (s->pending != 0) {
|
if (s->pending != 0) {
|
||||||
|
@ -704,7 +864,12 @@ int ZEXPORT deflateEnd (strm)
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
|
|
||||||
status = strm->state->status;
|
status = strm->state->status;
|
||||||
if (status != INIT_STATE && status != BUSY_STATE &&
|
if (status != INIT_STATE &&
|
||||||
|
status != EXTRA_STATE &&
|
||||||
|
status != NAME_STATE &&
|
||||||
|
status != COMMENT_STATE &&
|
||||||
|
status != HCRC_STATE &&
|
||||||
|
status != BUSY_STATE &&
|
||||||
status != FINISH_STATE) {
|
status != FINISH_STATE) {
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -744,12 +909,12 @@ int ZEXPORT deflateCopy (dest, source)
|
||||||
|
|
||||||
ss = source->state;
|
ss = source->state;
|
||||||
|
|
||||||
*dest = *source;
|
zmemcpy(dest, source, sizeof(z_stream));
|
||||||
|
|
||||||
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
||||||
if (ds == Z_NULL) return Z_MEM_ERROR;
|
if (ds == Z_NULL) return Z_MEM_ERROR;
|
||||||
dest->state = (struct internal_state FAR *) ds;
|
dest->state = (struct internal_state FAR *) ds;
|
||||||
*ds = *ss;
|
zmemcpy(ds, ss, sizeof(deflate_state));
|
||||||
ds->strm = dest;
|
ds->strm = dest;
|
||||||
|
|
||||||
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
||||||
|
@ -838,9 +1003,11 @@ local void lm_init (s)
|
||||||
s->match_length = s->prev_length = MIN_MATCH-1;
|
s->match_length = s->prev_length = MIN_MATCH-1;
|
||||||
s->match_available = 0;
|
s->match_available = 0;
|
||||||
s->ins_h = 0;
|
s->ins_h = 0;
|
||||||
|
#ifndef FASTEST
|
||||||
#ifdef ASMV
|
#ifdef ASMV
|
||||||
match_init(); /* initialize the asm code */
|
match_init(); /* initialize the asm code */
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FASTEST
|
#ifndef FASTEST
|
||||||
|
@ -909,7 +1076,12 @@ local uInt longest_match(s, cur_match)
|
||||||
match = s->window + cur_match;
|
match = s->window + cur_match;
|
||||||
|
|
||||||
/* Skip to next match if the match length cannot increase
|
/* Skip to next match if the match length cannot increase
|
||||||
* or if the match length is less than 2:
|
* or if the match length is less than 2. Note that the checks below
|
||||||
|
* for insufficient lookahead only occur occasionally for performance
|
||||||
|
* reasons. Therefore uninitialized memory will be accessed, and
|
||||||
|
* conditional jumps will be made that depend on those values.
|
||||||
|
* However the length of the match is limited to the lookahead, so
|
||||||
|
* the output of deflate is not affected by the uninitialized values.
|
||||||
*/
|
*/
|
||||||
#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
|
#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
|
||||||
/* This code assumes sizeof(unsigned short) == 2. Do not use
|
/* This code assumes sizeof(unsigned short) == 2. Do not use
|
||||||
|
@ -1131,6 +1303,7 @@ local void fill_window(s)
|
||||||
later. (Using level 0 permanently is not an optimal usage of
|
later. (Using level 0 permanently is not an optimal usage of
|
||||||
zlib, so we don't care about this pathological case.)
|
zlib, so we don't care about this pathological case.)
|
||||||
*/
|
*/
|
||||||
|
/* %%% avoid this when Z_RLE */
|
||||||
n = s->hash_size;
|
n = s->hash_size;
|
||||||
p = &s->head[n];
|
p = &s->head[n];
|
||||||
do {
|
do {
|
||||||
|
@ -1309,12 +1482,12 @@ local block_state deflate_fast(s, flush)
|
||||||
* of the string with itself at the start of the input file).
|
* of the string with itself at the start of the input file).
|
||||||
*/
|
*/
|
||||||
#ifdef FASTEST
|
#ifdef FASTEST
|
||||||
if ((s->strategy < Z_HUFFMAN_ONLY) ||
|
if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
|
||||||
(s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
|
(s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
|
||||||
s->match_length = longest_match_fast (s, hash_head);
|
s->match_length = longest_match_fast (s, hash_head);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (s->strategy < Z_HUFFMAN_ONLY) {
|
if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
|
||||||
s->match_length = longest_match (s, hash_head);
|
s->match_length = longest_match (s, hash_head);
|
||||||
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
||||||
s->match_length = longest_match_fast (s, hash_head);
|
s->match_length = longest_match_fast (s, hash_head);
|
||||||
|
@ -1418,7 +1591,7 @@ local block_state deflate_slow(s, flush)
|
||||||
* of window index 0 (in particular we have to avoid a match
|
* of window index 0 (in particular we have to avoid a match
|
||||||
* of the string with itself at the start of the input file).
|
* of the string with itself at the start of the input file).
|
||||||
*/
|
*/
|
||||||
if (s->strategy < Z_HUFFMAN_ONLY) {
|
if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
|
||||||
s->match_length = longest_match (s, hash_head);
|
s->match_length = longest_match (s, hash_head);
|
||||||
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
||||||
s->match_length = longest_match_fast (s, hash_head);
|
s->match_length = longest_match_fast (s, hash_head);
|
||||||
|
@ -1500,3 +1673,64 @@ local block_state deflate_slow(s, flush)
|
||||||
return flush == Z_FINISH ? finish_done : block_done;
|
return flush == Z_FINISH ? finish_done : block_done;
|
||||||
}
|
}
|
||||||
#endif /* FASTEST */
|
#endif /* FASTEST */
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* ===========================================================================
|
||||||
|
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
|
||||||
|
* one. Do not maintain a hash table. (It will be regenerated if this run of
|
||||||
|
* deflate switches away from Z_RLE.)
|
||||||
|
*/
|
||||||
|
local block_state deflate_rle(s, flush)
|
||||||
|
deflate_state *s;
|
||||||
|
int flush;
|
||||||
|
{
|
||||||
|
int bflush; /* set if current block must be flushed */
|
||||||
|
uInt run; /* length of run */
|
||||||
|
uInt max; /* maximum length of run */
|
||||||
|
uInt prev; /* byte at distance one to match */
|
||||||
|
Bytef *scan; /* scan for end of run */
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
/* Make sure that we always have enough lookahead, except
|
||||||
|
* at the end of the input file. We need MAX_MATCH bytes
|
||||||
|
* for the longest encodable run.
|
||||||
|
*/
|
||||||
|
if (s->lookahead < MAX_MATCH) {
|
||||||
|
fill_window(s);
|
||||||
|
if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
|
||||||
|
return need_more;
|
||||||
|
}
|
||||||
|
if (s->lookahead == 0) break; /* flush the current block */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See how many times the previous byte repeats */
|
||||||
|
run = 0;
|
||||||
|
if (s->strstart > 0) { /* if there is a previous byte, that is */
|
||||||
|
max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
|
||||||
|
scan = s->window + s->strstart - 1;
|
||||||
|
prev = *scan++;
|
||||||
|
do {
|
||||||
|
if (*scan++ != prev)
|
||||||
|
break;
|
||||||
|
} while (++run < max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
|
||||||
|
if (run >= MIN_MATCH) {
|
||||||
|
check_match(s, s->strstart, s->strstart - 1, run);
|
||||||
|
_tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
|
||||||
|
s->lookahead -= run;
|
||||||
|
s->strstart += run;
|
||||||
|
} else {
|
||||||
|
/* No match, output a literal byte */
|
||||||
|
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||||
|
_tr_tally_lit (s, s->window[s->strstart], bflush);
|
||||||
|
s->lookahead--;
|
||||||
|
s->strstart++;
|
||||||
|
}
|
||||||
|
if (bflush) FLUSH_BLOCK(s, 0);
|
||||||
|
}
|
||||||
|
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||||
|
return flush == Z_FINISH ? finish_done : block_done;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* deflate.h -- internal compression state
|
/* deflate.h -- internal compression state
|
||||||
* Copyright (C) 1995-2002 Jean-loup Gailly
|
* Copyright (C) 1995-2004 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -49,6 +49,10 @@
|
||||||
/* All codes must not exceed MAX_BITS bits */
|
/* All codes must not exceed MAX_BITS bits */
|
||||||
|
|
||||||
#define INIT_STATE 42
|
#define INIT_STATE 42
|
||||||
|
#define EXTRA_STATE 69
|
||||||
|
#define NAME_STATE 73
|
||||||
|
#define COMMENT_STATE 91
|
||||||
|
#define HCRC_STATE 103
|
||||||
#define BUSY_STATE 113
|
#define BUSY_STATE 113
|
||||||
#define FINISH_STATE 666
|
#define FINISH_STATE 666
|
||||||
/* Stream status */
|
/* Stream status */
|
||||||
|
@ -93,9 +97,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 */
|
||||||
int pending; /* nb of bytes in the pending buffer */
|
uInt 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 */
|
||||||
Byte data_type; /* UNKNOWN, BINARY or ASCII */
|
gz_headerp gzhead; /* gzip header information to write */
|
||||||
|
uInt gzindex; /* where in extra, name, or comment */
|
||||||
Byte method; /* STORED (for zip only) or DEFLATED */
|
Byte method; /* STORED (for zip only) or DEFLATED */
|
||||||
int last_flush; /* value of flush param for previous deflate call */
|
int last_flush; /* value of flush param for previous deflate call */
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* example.c -- usage example of the zlib compression library
|
/* example.c -- usage example of the zlib compression library
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2004 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
#ifdef STDC
|
#ifdef STDC
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#else
|
|
||||||
extern void exit OF((int));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(VMS) || defined(RISCOS)
|
#if defined(VMS) || defined(RISCOS)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* gzio.c -- IO on .gz files
|
/* gzio.c -- IO on .gz files
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*
|
*
|
||||||
* Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
|
* Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "zutil.h"
|
#include "zutil.h"
|
||||||
|
|
||||||
#ifdef NO_DEFLATE /* for compatiblity with old definition */
|
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
||||||
# define NO_GZCOMPRESS
|
# define NO_GZCOMPRESS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ gzFile ZEXPORT gzdopen (fd, mode)
|
||||||
int fd;
|
int fd;
|
||||||
const char *mode;
|
const char *mode;
|
||||||
{
|
{
|
||||||
char name[20];
|
char name[46]; /* allow for up to 128-bit integers */
|
||||||
|
|
||||||
if (fd < 0) return (gzFile)Z_NULL;
|
if (fd < 0) return (gzFile)Z_NULL;
|
||||||
sprintf(name, "<fd:%d>", fd); /* for debugging */
|
sprintf(name, "<fd:%d>", fd); /* for debugging */
|
||||||
|
@ -264,7 +264,7 @@ local int get_byte(s)
|
||||||
if (s->z_eof) return EOF;
|
if (s->z_eof) return EOF;
|
||||||
if (s->stream.avail_in == 0) {
|
if (s->stream.avail_in == 0) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||||
if (s->stream.avail_in == 0) {
|
if (s->stream.avail_in == 0) {
|
||||||
s->z_eof = 1;
|
s->z_eof = 1;
|
||||||
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
||||||
|
@ -300,7 +300,7 @@ local void check_header(s)
|
||||||
if (len < 2) {
|
if (len < 2) {
|
||||||
if (len) s->inbuf[0] = s->stream.next_in[0];
|
if (len) s->inbuf[0] = s->stream.next_in[0];
|
||||||
errno = 0;
|
errno = 0;
|
||||||
len = fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
|
len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
|
||||||
if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
|
if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
|
||||||
s->stream.avail_in += len;
|
s->stream.avail_in += len;
|
||||||
s->stream.next_in = s->inbuf;
|
s->stream.next_in = s->inbuf;
|
||||||
|
@ -415,6 +415,7 @@ int ZEXPORT gzread (file, buf, len)
|
||||||
s->stream.avail_out--;
|
s->stream.avail_out--;
|
||||||
s->back = EOF;
|
s->back = EOF;
|
||||||
s->out++;
|
s->out++;
|
||||||
|
start++;
|
||||||
if (s->last) {
|
if (s->last) {
|
||||||
s->z_err = Z_STREAM_END;
|
s->z_err = Z_STREAM_END;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -436,8 +437,8 @@ int ZEXPORT gzread (file, buf, len)
|
||||||
s->stream.avail_in -= n;
|
s->stream.avail_in -= n;
|
||||||
}
|
}
|
||||||
if (s->stream.avail_out > 0) {
|
if (s->stream.avail_out > 0) {
|
||||||
s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
|
s->stream.avail_out -=
|
||||||
s->file);
|
(uInt)fread(next_out, 1, s->stream.avail_out, s->file);
|
||||||
}
|
}
|
||||||
len -= s->stream.avail_out;
|
len -= s->stream.avail_out;
|
||||||
s->in += len;
|
s->in += len;
|
||||||
|
@ -448,7 +449,7 @@ int ZEXPORT gzread (file, buf, len)
|
||||||
if (s->stream.avail_in == 0 && !s->z_eof) {
|
if (s->stream.avail_in == 0 && !s->z_eof) {
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||||
if (s->stream.avail_in == 0) {
|
if (s->stream.avail_in == 0) {
|
||||||
s->z_eof = 1;
|
s->z_eof = 1;
|
||||||
if (ferror(s->file)) {
|
if (ferror(s->file)) {
|
||||||
|
@ -488,6 +489,9 @@ int ZEXPORT gzread (file, buf, len)
|
||||||
}
|
}
|
||||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||||
|
|
||||||
|
if (len == s->stream.avail_out &&
|
||||||
|
(s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO))
|
||||||
|
return -1;
|
||||||
return (int)(len - s->stream.avail_out);
|
return (int)(len - s->stream.avail_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,6 +902,18 @@ int ZEXPORT gzeof (file)
|
||||||
return s->z_err == Z_STREAM_END;
|
return s->z_err == Z_STREAM_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===========================================================================
|
||||||
|
Returns 1 if reading and doing so transparently, otherwise zero.
|
||||||
|
*/
|
||||||
|
int ZEXPORT gzdirect (file)
|
||||||
|
gzFile file;
|
||||||
|
{
|
||||||
|
gz_stream *s = (gz_stream*)file;
|
||||||
|
|
||||||
|
if (s == NULL || s->mode != 'r') return 0;
|
||||||
|
return s->transparent;
|
||||||
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
Outputs a long in LSB order to the given file
|
Outputs a long in LSB order to the given file
|
||||||
*/
|
*/
|
||||||
|
@ -937,7 +953,6 @@ local uLong getLong (s)
|
||||||
int ZEXPORT gzclose (file)
|
int ZEXPORT gzclose (file)
|
||||||
gzFile file;
|
gzFile file;
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
gz_stream *s = (gz_stream*)file;
|
gz_stream *s = (gz_stream*)file;
|
||||||
|
|
||||||
if (s == NULL) return Z_STREAM_ERROR;
|
if (s == NULL) return Z_STREAM_ERROR;
|
||||||
|
@ -946,8 +961,8 @@ int ZEXPORT gzclose (file)
|
||||||
#ifdef NO_GZCOMPRESS
|
#ifdef NO_GZCOMPRESS
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
#else
|
#else
|
||||||
err = do_flush (file, Z_FINISH);
|
if (do_flush (file, Z_FINISH) != Z_OK)
|
||||||
if (err != Z_OK) return destroy((gz_stream*)file);
|
return destroy((gz_stream*)file);
|
||||||
|
|
||||||
putLong (s->file, s->crc);
|
putLong (s->file, s->crc);
|
||||||
putLong (s->file, (uLong)(s->in & 0xffffffff));
|
putLong (s->file, (uLong)(s->in & 0xffffffff));
|
||||||
|
@ -956,10 +971,16 @@ int ZEXPORT gzclose (file)
|
||||||
return destroy((gz_stream*)file);
|
return destroy((gz_stream*)file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef STDC
|
||||||
|
# define zstrerror(errnum) strerror(errnum)
|
||||||
|
#else
|
||||||
|
# define zstrerror(errnum) ""
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
Returns the error message for the last error which occured on the
|
Returns the error message for the last error which occurred on the
|
||||||
given compressed file. errnum is set to zlib error number. If an
|
given compressed file. errnum is set to zlib error number. If an
|
||||||
error occured in the file system and not in the compression library,
|
error occurred in the file system and not in the compression library,
|
||||||
errnum is set to Z_ERRNO and the application may consult errno
|
errnum is set to Z_ERRNO and the application may consult errno
|
||||||
to get the exact error code.
|
to get the exact error code.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* infback.c -- inflate using a call-back interface
|
/* infback.c -- inflate using a call-back interface
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ local void fixedtables OF((struct inflate_state FAR *state));
|
||||||
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_(strm, windowBits, window, version, stream_size)
|
||||||
z_stream FAR *strm;
|
z_streamp strm;
|
||||||
int windowBits;
|
int windowBits;
|
||||||
unsigned char FAR *window;
|
unsigned char FAR *window;
|
||||||
const char *version;
|
const char *version;
|
||||||
|
@ -50,7 +50,8 @@ int stream_size;
|
||||||
sizeof(struct inflate_state));
|
sizeof(struct inflate_state));
|
||||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||||
Tracev((stderr, "inflate: allocated\n"));
|
Tracev((stderr, "inflate: allocated\n"));
|
||||||
strm->state = (voidpf)state;
|
strm->state = (struct internal_state FAR *)state;
|
||||||
|
state->dmax = 32768U;
|
||||||
state->wbits = windowBits;
|
state->wbits = windowBits;
|
||||||
state->wsize = 1U << windowBits;
|
state->wsize = 1U << windowBits;
|
||||||
state->window = window;
|
state->window = window;
|
||||||
|
@ -238,7 +239,7 @@ struct inflate_state FAR *state;
|
||||||
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(strm, in, in_desc, out, out_desc)
|
||||||
z_stream FAR *strm;
|
z_streamp strm;
|
||||||
in_func in;
|
in_func in;
|
||||||
void FAR *in_desc;
|
void FAR *in_desc;
|
||||||
out_func out;
|
out_func out;
|
||||||
|
@ -434,6 +435,9 @@ void FAR *out_desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* handle error breaks in while */
|
||||||
|
if (state->mode == BAD) break;
|
||||||
|
|
||||||
/* build code tables */
|
/* build code tables */
|
||||||
state->next = state->codes;
|
state->next = state->codes;
|
||||||
state->lencode = (code const FAR *)(state->next);
|
state->lencode = (code const FAR *)(state->next);
|
||||||
|
@ -608,7 +612,7 @@ void FAR *out_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZEXPORT inflateBackEnd(strm)
|
int ZEXPORT inflateBackEnd(strm)
|
||||||
z_stream FAR *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;
|
||||||
|
|
|
@ -1,403 +0,0 @@
|
||||||
/* infblock.c -- interpret and process block types to last block
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "zutil.h"
|
|
||||||
#include "infblock.h"
|
|
||||||
#include "inftrees.h"
|
|
||||||
#include "infcodes.h"
|
|
||||||
#include "infutil.h"
|
|
||||||
|
|
||||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
|
||||||
|
|
||||||
/* simplify the use of the inflate_huft type with some defines */
|
|
||||||
#define exop word.what.Exop
|
|
||||||
#define bits word.what.Bits
|
|
||||||
|
|
||||||
/* Table for deflate from PKZIP's appnote.txt. */
|
|
||||||
local const uInt border[] = { /* Order of the bit length code lengths */
|
|
||||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Notes beyond the 1.93a appnote.txt:
|
|
||||||
|
|
||||||
1. Distance pointers never point before the beginning of the output
|
|
||||||
stream.
|
|
||||||
2. Distance pointers can point back across blocks, up to 32k away.
|
|
||||||
3. There is an implied maximum of 7 bits for the bit length table and
|
|
||||||
15 bits for the actual data.
|
|
||||||
4. If only one code exists, then it is encoded using one bit. (Zero
|
|
||||||
would be more efficient, but perhaps a little confusing.) If two
|
|
||||||
codes exist, they are coded using one bit each (0 and 1).
|
|
||||||
5. There is no way of sending zero distance codes--a dummy must be
|
|
||||||
sent if there are none. (History: a pre 2.0 version of PKZIP would
|
|
||||||
store blocks with no distance codes, but this was discovered to be
|
|
||||||
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
|
|
||||||
zero distance codes, which is sent as one code of zero bits in
|
|
||||||
length.
|
|
||||||
6. There are up to 286 literal/length codes. Code 256 represents the
|
|
||||||
end-of-block. Note however that the static length tree defines
|
|
||||||
288 codes just to fill out the Huffman codes. Codes 286 and 287
|
|
||||||
cannot be used though, since there is no length base or extra bits
|
|
||||||
defined for them. Similarily, there are up to 30 distance codes.
|
|
||||||
However, static trees define 32 codes (all 5 bits) to fill out the
|
|
||||||
Huffman codes, but the last two had better not show up in the data.
|
|
||||||
7. Unzip can check dynamic Huffman blocks for complete code sets.
|
|
||||||
The exception is that a single code would not be complete (see #4).
|
|
||||||
8. The five bits following the block type is really the number of
|
|
||||||
literal codes sent minus 257.
|
|
||||||
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
|
|
||||||
(1+6+6). Therefore, to output three times the length, you output
|
|
||||||
three codes (1+1+1), whereas to output four times the same length,
|
|
||||||
you only need two codes (1+3). Hmm.
|
|
||||||
10. In the tree reconstruction algorithm, Code = Code + Increment
|
|
||||||
only if BitLength(i) is not zero. (Pretty obvious.)
|
|
||||||
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
|
|
||||||
12. Note: length code 284 can represent 227-258, but length code 285
|
|
||||||
really is 258. The last length deserves its own, short code
|
|
||||||
since it gets used a lot in very redundant files. The length
|
|
||||||
258 is special since 258 - 3 (the min match length) is 255.
|
|
||||||
13. The literal/length and distance code bit lengths are read as a
|
|
||||||
single stream of lengths. It is possible (and advantageous) for
|
|
||||||
a repeat code (16, 17, or 18) to go across the boundary between
|
|
||||||
the two sets of lengths.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void inflate_blocks_reset(s, z, c)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
z_streamp z;
|
|
||||||
uLongf *c;
|
|
||||||
{
|
|
||||||
if (c != Z_NULL)
|
|
||||||
*c = s->check;
|
|
||||||
if (s->mode == BTREE || s->mode == DTREE)
|
|
||||||
ZFREE(z, s->sub.trees.blens);
|
|
||||||
if (s->mode == CODES)
|
|
||||||
inflate_codes_free(s->sub.decode.codes, z);
|
|
||||||
s->mode = TYPE;
|
|
||||||
s->bitk = 0;
|
|
||||||
s->bitb = 0;
|
|
||||||
s->read = s->write = s->window;
|
|
||||||
if (s->checkfn != Z_NULL)
|
|
||||||
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
|
|
||||||
Tracev((stderr, "inflate: blocks reset\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inflate_blocks_statef *inflate_blocks_new(z, c, w)
|
|
||||||
z_streamp z;
|
|
||||||
check_func c;
|
|
||||||
uInt w;
|
|
||||||
{
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
|
|
||||||
if ((s = (inflate_blocks_statef *)ZALLOC
|
|
||||||
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
|
|
||||||
return s;
|
|
||||||
if ((s->hufts =
|
|
||||||
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
|
|
||||||
{
|
|
||||||
ZFREE(z, s);
|
|
||||||
return Z_NULL;
|
|
||||||
}
|
|
||||||
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
|
|
||||||
{
|
|
||||||
ZFREE(z, s->hufts);
|
|
||||||
ZFREE(z, s);
|
|
||||||
return Z_NULL;
|
|
||||||
}
|
|
||||||
s->end = s->window + w;
|
|
||||||
s->checkfn = c;
|
|
||||||
s->mode = TYPE;
|
|
||||||
Tracev((stderr, "inflate: blocks allocated\n"));
|
|
||||||
inflate_blocks_reset(s, z, Z_NULL);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int inflate_blocks(s, z, r)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
z_streamp z;
|
|
||||||
int r;
|
|
||||||
{
|
|
||||||
uInt t; /* temporary storage */
|
|
||||||
uLong b; /* bit buffer */
|
|
||||||
uInt k; /* bits in bit buffer */
|
|
||||||
Bytef *p; /* input data pointer */
|
|
||||||
uInt n; /* bytes available there */
|
|
||||||
Bytef *q; /* output window write pointer */
|
|
||||||
uInt m; /* bytes to end of window or read pointer */
|
|
||||||
|
|
||||||
/* copy input/output information to locals (UPDATE macro restores) */
|
|
||||||
LOAD
|
|
||||||
|
|
||||||
/* process input based on current state */
|
|
||||||
while (1) switch (s->mode)
|
|
||||||
{
|
|
||||||
case TYPE:
|
|
||||||
NEEDBITS(3)
|
|
||||||
t = (uInt)b & 7;
|
|
||||||
s->last = t & 1;
|
|
||||||
switch (t >> 1)
|
|
||||||
{
|
|
||||||
case 0: /* stored */
|
|
||||||
Tracev((stderr, "inflate: stored block%s\n",
|
|
||||||
s->last ? " (last)" : ""));
|
|
||||||
DUMPBITS(3)
|
|
||||||
t = k & 7; /* go to byte boundary */
|
|
||||||
DUMPBITS(t)
|
|
||||||
s->mode = LENS; /* get length of stored block */
|
|
||||||
break;
|
|
||||||
case 1: /* fixed */
|
|
||||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
|
||||||
s->last ? " (last)" : ""));
|
|
||||||
{
|
|
||||||
uInt bl, bd;
|
|
||||||
inflate_huft *tl, *td;
|
|
||||||
|
|
||||||
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
|
|
||||||
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
|
||||||
if (s->sub.decode.codes == Z_NULL)
|
|
||||||
{
|
|
||||||
r = Z_MEM_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DUMPBITS(3)
|
|
||||||
s->mode = CODES;
|
|
||||||
break;
|
|
||||||
case 2: /* dynamic */
|
|
||||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
|
||||||
s->last ? " (last)" : ""));
|
|
||||||
DUMPBITS(3)
|
|
||||||
s->mode = TABLE;
|
|
||||||
break;
|
|
||||||
case 3: /* illegal */
|
|
||||||
DUMPBITS(3)
|
|
||||||
s->mode = BAD;
|
|
||||||
z->msg = (char*)"invalid block type";
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LENS:
|
|
||||||
NEEDBITS(32)
|
|
||||||
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
|
|
||||||
{
|
|
||||||
s->mode = BAD;
|
|
||||||
z->msg = (char*)"invalid stored block lengths";
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
s->sub.left = (uInt)b & 0xffff;
|
|
||||||
b = k = 0; /* dump bits */
|
|
||||||
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
|
|
||||||
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
|
|
||||||
break;
|
|
||||||
case STORED:
|
|
||||||
if (n == 0)
|
|
||||||
LEAVE
|
|
||||||
NEEDOUT
|
|
||||||
t = s->sub.left;
|
|
||||||
if (t > n) t = n;
|
|
||||||
if (t > m) t = m;
|
|
||||||
zmemcpy(q, p, t);
|
|
||||||
p += t; n -= t;
|
|
||||||
q += t; m -= t;
|
|
||||||
if ((s->sub.left -= t) != 0)
|
|
||||||
break;
|
|
||||||
Tracev((stderr, "inflate: stored end, %lu total out\n",
|
|
||||||
z->total_out + (q >= s->read ? q - s->read :
|
|
||||||
(s->end - s->read) + (q - s->window))));
|
|
||||||
s->mode = s->last ? DRY : TYPE;
|
|
||||||
break;
|
|
||||||
case TABLE:
|
|
||||||
NEEDBITS(14)
|
|
||||||
s->sub.trees.table = t = (uInt)b & 0x3fff;
|
|
||||||
#ifndef PKZIP_BUG_WORKAROUND
|
|
||||||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
|
|
||||||
{
|
|
||||||
s->mode = BAD;
|
|
||||||
z->msg = (char*)"too many length or distance symbols";
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
|
||||||
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
|
||||||
{
|
|
||||||
r = Z_MEM_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
DUMPBITS(14)
|
|
||||||
s->sub.trees.index = 0;
|
|
||||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
|
||||||
s->mode = BTREE;
|
|
||||||
case BTREE:
|
|
||||||
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
|
|
||||||
{
|
|
||||||
NEEDBITS(3)
|
|
||||||
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
|
|
||||||
DUMPBITS(3)
|
|
||||||
}
|
|
||||||
while (s->sub.trees.index < 19)
|
|
||||||
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
|
|
||||||
s->sub.trees.bb = 7;
|
|
||||||
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
|
|
||||||
&s->sub.trees.tb, s->hufts, z);
|
|
||||||
if (t != Z_OK)
|
|
||||||
{
|
|
||||||
r = t;
|
|
||||||
if (r == Z_DATA_ERROR)
|
|
||||||
{
|
|
||||||
ZFREE(z, s->sub.trees.blens);
|
|
||||||
s->mode = BAD;
|
|
||||||
}
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
s->sub.trees.index = 0;
|
|
||||||
Tracev((stderr, "inflate: bits tree ok\n"));
|
|
||||||
s->mode = DTREE;
|
|
||||||
case DTREE:
|
|
||||||
while (t = s->sub.trees.table,
|
|
||||||
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
|
|
||||||
{
|
|
||||||
inflate_huft *h;
|
|
||||||
uInt i, j, c;
|
|
||||||
|
|
||||||
t = s->sub.trees.bb;
|
|
||||||
NEEDBITS(t)
|
|
||||||
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
|
|
||||||
t = h->bits;
|
|
||||||
c = h->base;
|
|
||||||
if (c < 16)
|
|
||||||
{
|
|
||||||
DUMPBITS(t)
|
|
||||||
s->sub.trees.blens[s->sub.trees.index++] = c;
|
|
||||||
}
|
|
||||||
else /* c == 16..18 */
|
|
||||||
{
|
|
||||||
i = c == 18 ? 7 : c - 14;
|
|
||||||
j = c == 18 ? 11 : 3;
|
|
||||||
NEEDBITS(t + i)
|
|
||||||
DUMPBITS(t)
|
|
||||||
j += (uInt)b & inflate_mask[i];
|
|
||||||
DUMPBITS(i)
|
|
||||||
i = s->sub.trees.index;
|
|
||||||
t = s->sub.trees.table;
|
|
||||||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
|
||||||
(c == 16 && i < 1))
|
|
||||||
{
|
|
||||||
ZFREE(z, s->sub.trees.blens);
|
|
||||||
s->mode = BAD;
|
|
||||||
z->msg = (char*)"invalid bit length repeat";
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
|
|
||||||
do {
|
|
||||||
s->sub.trees.blens[i++] = c;
|
|
||||||
} while (--j);
|
|
||||||
s->sub.trees.index = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s->sub.trees.tb = Z_NULL;
|
|
||||||
{
|
|
||||||
uInt bl, bd;
|
|
||||||
inflate_huft *tl, *td;
|
|
||||||
inflate_codes_statef *c;
|
|
||||||
|
|
||||||
bl = 9; /* must be <= 9 for lookahead assumptions */
|
|
||||||
bd = 6; /* must be <= 9 for lookahead assumptions */
|
|
||||||
t = s->sub.trees.table;
|
|
||||||
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
|
|
||||||
s->sub.trees.blens, &bl, &bd, &tl, &td,
|
|
||||||
s->hufts, z);
|
|
||||||
if (t != Z_OK)
|
|
||||||
{
|
|
||||||
if (t == (uInt)Z_DATA_ERROR)
|
|
||||||
{
|
|
||||||
ZFREE(z, s->sub.trees.blens);
|
|
||||||
s->mode = BAD;
|
|
||||||
}
|
|
||||||
r = t;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
Tracev((stderr, "inflate: trees ok\n"));
|
|
||||||
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
|
||||||
{
|
|
||||||
r = Z_MEM_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
s->sub.decode.codes = c;
|
|
||||||
}
|
|
||||||
ZFREE(z, s->sub.trees.blens);
|
|
||||||
s->mode = CODES;
|
|
||||||
case CODES:
|
|
||||||
UPDATE
|
|
||||||
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
|
|
||||||
return inflate_flush(s, z, r);
|
|
||||||
r = Z_OK;
|
|
||||||
inflate_codes_free(s->sub.decode.codes, z);
|
|
||||||
LOAD
|
|
||||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
|
||||||
z->total_out + (q >= s->read ? q - s->read :
|
|
||||||
(s->end - s->read) + (q - s->window))));
|
|
||||||
if (!s->last)
|
|
||||||
{
|
|
||||||
s->mode = TYPE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s->mode = DRY;
|
|
||||||
case DRY:
|
|
||||||
FLUSH
|
|
||||||
if (s->read != s->write)
|
|
||||||
LEAVE
|
|
||||||
s->mode = DONE;
|
|
||||||
case DONE:
|
|
||||||
r = Z_STREAM_END;
|
|
||||||
LEAVE
|
|
||||||
case BAD:
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
default:
|
|
||||||
r = Z_STREAM_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int inflate_blocks_free(s, z)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
z_streamp z;
|
|
||||||
{
|
|
||||||
inflate_blocks_reset(s, z, Z_NULL);
|
|
||||||
ZFREE(z, s->window);
|
|
||||||
ZFREE(z, s->hufts);
|
|
||||||
ZFREE(z, s);
|
|
||||||
Tracev((stderr, "inflate: blocks freed\n"));
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void inflate_set_dictionary(s, d, n)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
const Bytef *d;
|
|
||||||
uInt n;
|
|
||||||
{
|
|
||||||
zmemcpy(s->window, d, n);
|
|
||||||
s->read = s->write = s->window + n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns true if inflate is currently at the end of a block generated
|
|
||||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
|
||||||
* IN assertion: s != Z_NULL
|
|
||||||
*/
|
|
||||||
int inflate_blocks_sync_point(s)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
{
|
|
||||||
return s->mode == LENS;
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/* infblock.h -- header to use infblock.c
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: this file should *not* be used by applications. It is
|
|
||||||
part of the implementation of the compression library and is
|
|
||||||
subject to change. Applications should only use zlib.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct inflate_blocks_state;
|
|
||||||
typedef struct inflate_blocks_state FAR inflate_blocks_statef;
|
|
||||||
|
|
||||||
extern inflate_blocks_statef * inflate_blocks_new OF((
|
|
||||||
z_streamp z,
|
|
||||||
check_func c, /* check function */
|
|
||||||
uInt w)); /* window size */
|
|
||||||
|
|
||||||
extern int inflate_blocks OF((
|
|
||||||
inflate_blocks_statef *,
|
|
||||||
z_streamp ,
|
|
||||||
int)); /* initial return code */
|
|
||||||
|
|
||||||
extern void inflate_blocks_reset OF((
|
|
||||||
inflate_blocks_statef *,
|
|
||||||
z_streamp ,
|
|
||||||
uLongf *)); /* check value on output */
|
|
||||||
|
|
||||||
extern int inflate_blocks_free OF((
|
|
||||||
inflate_blocks_statef *,
|
|
||||||
z_streamp));
|
|
||||||
|
|
||||||
extern void inflate_set_dictionary OF((
|
|
||||||
inflate_blocks_statef *s,
|
|
||||||
const Bytef *d, /* dictionary */
|
|
||||||
uInt n)); /* dictionary length */
|
|
||||||
|
|
||||||
extern int inflate_blocks_sync_point OF((
|
|
||||||
inflate_blocks_statef *s));
|
|
|
@ -1,251 +0,0 @@
|
||||||
/* infcodes.c -- process literals and length/distance pairs
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "zutil.h"
|
|
||||||
#include "inftrees.h"
|
|
||||||
#include "infblock.h"
|
|
||||||
#include "infcodes.h"
|
|
||||||
#include "infutil.h"
|
|
||||||
#include "inffast.h"
|
|
||||||
|
|
||||||
/* simplify the use of the inflate_huft type with some defines */
|
|
||||||
#define exop word.what.Exop
|
|
||||||
#define bits word.what.Bits
|
|
||||||
|
|
||||||
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
|
||||||
START, /* x: set up for LEN */
|
|
||||||
LEN, /* i: get length/literal/eob next */
|
|
||||||
LENEXT, /* i: getting length extra (have base) */
|
|
||||||
DIST, /* i: get distance next */
|
|
||||||
DISTEXT, /* i: getting distance extra */
|
|
||||||
COPY, /* o: copying bytes in window, waiting for space */
|
|
||||||
LIT, /* o: got literal, waiting for output space */
|
|
||||||
WASH, /* o: got eob, possibly still output waiting */
|
|
||||||
END, /* x: got eob and all data flushed */
|
|
||||||
BADCODE} /* x: got error */
|
|
||||||
inflate_codes_mode;
|
|
||||||
|
|
||||||
/* inflate codes private state */
|
|
||||||
struct inflate_codes_state {
|
|
||||||
|
|
||||||
/* mode */
|
|
||||||
inflate_codes_mode mode; /* current inflate_codes mode */
|
|
||||||
|
|
||||||
/* mode dependent information */
|
|
||||||
uInt len;
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
inflate_huft *tree; /* pointer into tree */
|
|
||||||
uInt need; /* bits needed */
|
|
||||||
} code; /* if LEN or DIST, where in tree */
|
|
||||||
uInt lit; /* if LIT, literal */
|
|
||||||
struct {
|
|
||||||
uInt get; /* bits to get for extra */
|
|
||||||
uInt dist; /* distance back to copy from */
|
|
||||||
} copy; /* if EXT or COPY, where and how much */
|
|
||||||
} sub; /* submode */
|
|
||||||
|
|
||||||
/* mode independent information */
|
|
||||||
Byte lbits; /* ltree bits decoded per branch */
|
|
||||||
Byte dbits; /* dtree bits decoder per branch */
|
|
||||||
inflate_huft *ltree; /* literal/length/eob tree */
|
|
||||||
inflate_huft *dtree; /* distance tree */
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
|
|
||||||
uInt bl, bd;
|
|
||||||
inflate_huft *tl;
|
|
||||||
inflate_huft *td; /* need separate declaration for Borland C++ */
|
|
||||||
z_streamp z;
|
|
||||||
{
|
|
||||||
inflate_codes_statef *c;
|
|
||||||
|
|
||||||
if ((c = (inflate_codes_statef *)
|
|
||||||
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
|
|
||||||
{
|
|
||||||
c->mode = START;
|
|
||||||
c->lbits = (Byte)bl;
|
|
||||||
c->dbits = (Byte)bd;
|
|
||||||
c->ltree = tl;
|
|
||||||
c->dtree = td;
|
|
||||||
Tracev((stderr, "inflate: codes new\n"));
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int inflate_codes(s, z, r)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
z_streamp z;
|
|
||||||
int r;
|
|
||||||
{
|
|
||||||
uInt j; /* temporary storage */
|
|
||||||
inflate_huft *t; /* temporary pointer */
|
|
||||||
uInt e; /* extra bits or operation */
|
|
||||||
uLong b; /* bit buffer */
|
|
||||||
uInt k; /* bits in bit buffer */
|
|
||||||
Bytef *p; /* input data pointer */
|
|
||||||
uInt n; /* bytes available there */
|
|
||||||
Bytef *q; /* output window write pointer */
|
|
||||||
uInt m; /* bytes to end of window or read pointer */
|
|
||||||
Bytef *f; /* pointer to copy strings from */
|
|
||||||
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
|
|
||||||
|
|
||||||
/* copy input/output information to locals (UPDATE macro restores) */
|
|
||||||
LOAD
|
|
||||||
|
|
||||||
/* process input and output based on current state */
|
|
||||||
while (1) switch (c->mode)
|
|
||||||
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
|
||||||
case START: /* x: set up for LEN */
|
|
||||||
#ifndef SLOW
|
|
||||||
if (m >= 258 && n >= 10)
|
|
||||||
{
|
|
||||||
UPDATE
|
|
||||||
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
|
|
||||||
LOAD
|
|
||||||
if (r != Z_OK)
|
|
||||||
{
|
|
||||||
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !SLOW */
|
|
||||||
c->sub.code.need = c->lbits;
|
|
||||||
c->sub.code.tree = c->ltree;
|
|
||||||
c->mode = LEN;
|
|
||||||
case LEN: /* i: get length/literal/eob next */
|
|
||||||
j = c->sub.code.need;
|
|
||||||
NEEDBITS(j)
|
|
||||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
|
||||||
DUMPBITS(t->bits)
|
|
||||||
e = (uInt)(t->exop);
|
|
||||||
if (e == 0) /* literal */
|
|
||||||
{
|
|
||||||
c->sub.lit = t->base;
|
|
||||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
|
||||||
"inflate: literal '%c'\n" :
|
|
||||||
"inflate: literal 0x%02x\n", t->base));
|
|
||||||
c->mode = LIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (e & 16) /* length */
|
|
||||||
{
|
|
||||||
c->sub.copy.get = e & 15;
|
|
||||||
c->len = t->base;
|
|
||||||
c->mode = LENEXT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((e & 64) == 0) /* next table */
|
|
||||||
{
|
|
||||||
c->sub.code.need = e;
|
|
||||||
c->sub.code.tree = t + t->base;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (e & 32) /* end of block */
|
|
||||||
{
|
|
||||||
Tracevv((stderr, "inflate: end of block\n"));
|
|
||||||
c->mode = WASH;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
c->mode = BADCODE; /* invalid code */
|
|
||||||
z->msg = (char*)"invalid literal/length code";
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
case LENEXT: /* i: getting length extra (have base) */
|
|
||||||
j = c->sub.copy.get;
|
|
||||||
NEEDBITS(j)
|
|
||||||
c->len += (uInt)b & inflate_mask[j];
|
|
||||||
DUMPBITS(j)
|
|
||||||
c->sub.code.need = c->dbits;
|
|
||||||
c->sub.code.tree = c->dtree;
|
|
||||||
Tracevv((stderr, "inflate: length %u\n", c->len));
|
|
||||||
c->mode = DIST;
|
|
||||||
case DIST: /* i: get distance next */
|
|
||||||
j = c->sub.code.need;
|
|
||||||
NEEDBITS(j)
|
|
||||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
|
||||||
DUMPBITS(t->bits)
|
|
||||||
e = (uInt)(t->exop);
|
|
||||||
if (e & 16) /* distance */
|
|
||||||
{
|
|
||||||
c->sub.copy.get = e & 15;
|
|
||||||
c->sub.copy.dist = t->base;
|
|
||||||
c->mode = DISTEXT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((e & 64) == 0) /* next table */
|
|
||||||
{
|
|
||||||
c->sub.code.need = e;
|
|
||||||
c->sub.code.tree = t + t->base;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
c->mode = BADCODE; /* invalid code */
|
|
||||||
z->msg = (char*)"invalid distance code";
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
case DISTEXT: /* i: getting distance extra */
|
|
||||||
j = c->sub.copy.get;
|
|
||||||
NEEDBITS(j)
|
|
||||||
c->sub.copy.dist += (uInt)b & inflate_mask[j];
|
|
||||||
DUMPBITS(j)
|
|
||||||
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
|
|
||||||
c->mode = COPY;
|
|
||||||
case COPY: /* o: copying bytes in window, waiting for space */
|
|
||||||
f = q - c->sub.copy.dist;
|
|
||||||
while (f < s->window) /* modulo window size-"while" instead */
|
|
||||||
f += s->end - s->window; /* of "if" handles invalid distances */
|
|
||||||
while (c->len)
|
|
||||||
{
|
|
||||||
NEEDOUT
|
|
||||||
OUTBYTE(*f++)
|
|
||||||
if (f == s->end)
|
|
||||||
f = s->window;
|
|
||||||
c->len--;
|
|
||||||
}
|
|
||||||
c->mode = START;
|
|
||||||
break;
|
|
||||||
case LIT: /* o: got literal, waiting for output space */
|
|
||||||
NEEDOUT
|
|
||||||
OUTBYTE(c->sub.lit)
|
|
||||||
c->mode = START;
|
|
||||||
break;
|
|
||||||
case WASH: /* o: got eob, possibly more output */
|
|
||||||
if (k > 7) /* return unused byte, if any */
|
|
||||||
{
|
|
||||||
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
|
||||||
k -= 8;
|
|
||||||
n++;
|
|
||||||
p--; /* can always return one */
|
|
||||||
}
|
|
||||||
FLUSH
|
|
||||||
if (s->read != s->write)
|
|
||||||
LEAVE
|
|
||||||
c->mode = END;
|
|
||||||
case END:
|
|
||||||
r = Z_STREAM_END;
|
|
||||||
LEAVE
|
|
||||||
case BADCODE: /* x: got error */
|
|
||||||
r = Z_DATA_ERROR;
|
|
||||||
LEAVE
|
|
||||||
default:
|
|
||||||
r = Z_STREAM_ERROR;
|
|
||||||
LEAVE
|
|
||||||
}
|
|
||||||
#ifdef NEED_DUMMY_RETURN
|
|
||||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void inflate_codes_free(c, z)
|
|
||||||
inflate_codes_statef *c;
|
|
||||||
z_streamp z;
|
|
||||||
{
|
|
||||||
ZFREE(z, c);
|
|
||||||
Tracev((stderr, "inflate: codes free\n"));
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* infcodes.h -- header to use infcodes.c
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: this file should *not* be used by applications. It is
|
|
||||||
part of the implementation of the compression library and is
|
|
||||||
subject to change. Applications should only use zlib.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct inflate_codes_state;
|
|
||||||
typedef struct inflate_codes_state FAR inflate_codes_statef;
|
|
||||||
|
|
||||||
extern inflate_codes_statef *inflate_codes_new OF((
|
|
||||||
uInt, uInt,
|
|
||||||
inflate_huft *, inflate_huft *,
|
|
||||||
z_streamp ));
|
|
||||||
|
|
||||||
extern int inflate_codes OF((
|
|
||||||
inflate_blocks_statef *,
|
|
||||||
z_streamp ,
|
|
||||||
int));
|
|
||||||
|
|
||||||
extern void inflate_codes_free OF((
|
|
||||||
inflate_codes_statef *,
|
|
||||||
z_streamp ));
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* inffast.c -- fast decoding
|
/* inffast.c -- fast decoding
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2004 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
- none
|
- none
|
||||||
No measurable difference:
|
No measurable difference:
|
||||||
- Pentium III (Anderson)
|
- Pentium III (Anderson)
|
||||||
- 68060 (Nikl)
|
- M68060 (Nikl)
|
||||||
*/
|
*/
|
||||||
#ifdef POSTINC
|
#ifdef POSTINC
|
||||||
# define OFF 0
|
# define OFF 0
|
||||||
|
@ -74,6 +74,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||||
unsigned char FAR *out; /* local strm->next_out */
|
unsigned char FAR *out; /* local strm->next_out */
|
||||||
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
||||||
unsigned char FAR *end; /* while out < end, enough space available */
|
unsigned char FAR *end; /* while out < end, enough space available */
|
||||||
|
#ifdef INFLATE_STRICT
|
||||||
|
unsigned dmax; /* maximum distance from zlib header */
|
||||||
|
#endif
|
||||||
unsigned wsize; /* window size or zero if not using window */
|
unsigned wsize; /* window size or zero if not using window */
|
||||||
unsigned whave; /* valid bytes in the window */
|
unsigned whave; /* valid bytes in the window */
|
||||||
unsigned write; /* window write index */
|
unsigned write; /* window write index */
|
||||||
|
@ -98,6 +101,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||||
out = strm->next_out - OFF;
|
out = strm->next_out - OFF;
|
||||||
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
|
||||||
|
dmax = state->dmax;
|
||||||
|
#endif
|
||||||
wsize = state->wsize;
|
wsize = state->wsize;
|
||||||
whave = state->whave;
|
whave = state->whave;
|
||||||
write = state->write;
|
write = state->write;
|
||||||
|
@ -167,6 +173,13 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dist += (unsigned)hold & ((1U << op) - 1);
|
dist += (unsigned)hold & ((1U << op) - 1);
|
||||||
|
#ifdef INFLATE_STRICT
|
||||||
|
if (dist > dmax) {
|
||||||
|
strm->msg = (char *)"invalid distance too far back";
|
||||||
|
state->mode = BAD;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
Tracevv((stderr, "inflate: distance %u\n", dist));
|
Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* inflate.c -- zlib decompression
|
/* inflate.c -- zlib decompression
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -109,11 +109,15 @@ z_streamp strm;
|
||||||
state = (struct inflate_state FAR *)strm->state;
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
strm->total_in = strm->total_out = state->total = 0;
|
strm->total_in = strm->total_out = state->total = 0;
|
||||||
strm->msg = Z_NULL;
|
strm->msg = Z_NULL;
|
||||||
|
strm->adler = 1; /* to support ill-conceived Java test suite */
|
||||||
state->mode = HEAD;
|
state->mode = HEAD;
|
||||||
state->last = 0;
|
state->last = 0;
|
||||||
state->havedict = 0;
|
state->havedict = 0;
|
||||||
|
state->dmax = 32768U;
|
||||||
|
state->head = Z_NULL;
|
||||||
state->wsize = 0;
|
state->wsize = 0;
|
||||||
state->whave = 0;
|
state->whave = 0;
|
||||||
|
state->write = 0;
|
||||||
state->hold = 0;
|
state->hold = 0;
|
||||||
state->bits = 0;
|
state->bits = 0;
|
||||||
state->lencode = state->distcode = state->next = state->codes;
|
state->lencode = state->distcode = state->next = state->codes;
|
||||||
|
@ -121,6 +125,22 @@ z_streamp strm;
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ZEXPORT inflatePrime(strm, bits, value)
|
||||||
|
z_streamp strm;
|
||||||
|
int bits;
|
||||||
|
int value;
|
||||||
|
{
|
||||||
|
struct inflate_state FAR *state;
|
||||||
|
|
||||||
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
|
if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
|
||||||
|
value &= (1L << bits) - 1;
|
||||||
|
state->hold += value << state->bits;
|
||||||
|
state->bits += bits;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
|
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
int windowBits;
|
int windowBits;
|
||||||
|
@ -143,7 +163,7 @@ int stream_size;
|
||||||
ZALLOC(strm, 1, sizeof(struct inflate_state));
|
ZALLOC(strm, 1, sizeof(struct inflate_state));
|
||||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||||
Tracev((stderr, "inflate: allocated\n"));
|
Tracev((stderr, "inflate: allocated\n"));
|
||||||
strm->state = (voidpf)state;
|
strm->state = (struct internal_state FAR *)state;
|
||||||
if (windowBits < 0) {
|
if (windowBits < 0) {
|
||||||
state->wrap = 0;
|
state->wrap = 0;
|
||||||
windowBits = -windowBits;
|
windowBits = -windowBits;
|
||||||
|
@ -581,6 +601,8 @@ int flush;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state->flags = 0; /* expect zlib header */
|
state->flags = 0; /* expect zlib header */
|
||||||
|
if (state->head != Z_NULL)
|
||||||
|
state->head->done = -1;
|
||||||
if (!(state->wrap & 1) || /* check if zlib header allowed */
|
if (!(state->wrap & 1) || /* check if zlib header allowed */
|
||||||
#else
|
#else
|
||||||
if (
|
if (
|
||||||
|
@ -596,11 +618,13 @@ int flush;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DROPBITS(4);
|
DROPBITS(4);
|
||||||
if (BITS(4) + 8 > state->wbits) {
|
len = BITS(4) + 8;
|
||||||
|
if (len > state->wbits) {
|
||||||
strm->msg = (char *)"invalid window size";
|
strm->msg = (char *)"invalid window size";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
state->dmax = 1U << len;
|
||||||
Tracev((stderr, "inflate: zlib header ok\n"));
|
Tracev((stderr, "inflate: zlib header ok\n"));
|
||||||
strm->adler = state->check = adler32(0L, Z_NULL, 0);
|
strm->adler = state->check = adler32(0L, Z_NULL, 0);
|
||||||
state->mode = hold & 0x200 ? DICTID : TYPE;
|
state->mode = hold & 0x200 ? DICTID : TYPE;
|
||||||
|
@ -620,16 +644,24 @@ int flush;
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (state->head != Z_NULL)
|
||||||
|
state->head->text = (int)((hold >> 8) & 1);
|
||||||
if (state->flags & 0x0200) CRC2(state->check, hold);
|
if (state->flags & 0x0200) CRC2(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
state->mode = TIME;
|
state->mode = TIME;
|
||||||
case TIME:
|
case TIME:
|
||||||
NEEDBITS(32);
|
NEEDBITS(32);
|
||||||
|
if (state->head != Z_NULL)
|
||||||
|
state->head->time = hold;
|
||||||
if (state->flags & 0x0200) CRC4(state->check, hold);
|
if (state->flags & 0x0200) CRC4(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
state->mode = OS;
|
state->mode = OS;
|
||||||
case OS:
|
case OS:
|
||||||
NEEDBITS(16);
|
NEEDBITS(16);
|
||||||
|
if (state->head != Z_NULL) {
|
||||||
|
state->head->xflags = (int)(hold & 0xff);
|
||||||
|
state->head->os = (int)(hold >> 8);
|
||||||
|
}
|
||||||
if (state->flags & 0x0200) CRC2(state->check, hold);
|
if (state->flags & 0x0200) CRC2(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
state->mode = EXLEN;
|
state->mode = EXLEN;
|
||||||
|
@ -637,15 +669,26 @@ int flush;
|
||||||
if (state->flags & 0x0400) {
|
if (state->flags & 0x0400) {
|
||||||
NEEDBITS(16);
|
NEEDBITS(16);
|
||||||
state->length = (unsigned)(hold);
|
state->length = (unsigned)(hold);
|
||||||
|
if (state->head != Z_NULL)
|
||||||
|
state->head->extra_len = (unsigned)hold;
|
||||||
if (state->flags & 0x0200) CRC2(state->check, hold);
|
if (state->flags & 0x0200) CRC2(state->check, hold);
|
||||||
INITBITS();
|
INITBITS();
|
||||||
}
|
}
|
||||||
|
else if (state->head != Z_NULL)
|
||||||
|
state->head->extra = Z_NULL;
|
||||||
state->mode = EXTRA;
|
state->mode = EXTRA;
|
||||||
case EXTRA:
|
case EXTRA:
|
||||||
if (state->flags & 0x0400) {
|
if (state->flags & 0x0400) {
|
||||||
copy = state->length;
|
copy = state->length;
|
||||||
if (copy > have) copy = have;
|
if (copy > have) copy = have;
|
||||||
if (copy) {
|
if (copy) {
|
||||||
|
if (state->head != Z_NULL &&
|
||||||
|
state->head->extra != Z_NULL) {
|
||||||
|
len = state->head->extra_len - state->length;
|
||||||
|
zmemcpy(state->head->extra + len, next,
|
||||||
|
len + copy > state->head->extra_max ?
|
||||||
|
state->head->extra_max - len : copy);
|
||||||
|
}
|
||||||
if (state->flags & 0x0200)
|
if (state->flags & 0x0200)
|
||||||
state->check = crc32(state->check, next, copy);
|
state->check = crc32(state->check, next, copy);
|
||||||
have -= copy;
|
have -= copy;
|
||||||
|
@ -654,6 +697,7 @@ int flush;
|
||||||
}
|
}
|
||||||
if (state->length) goto inf_leave;
|
if (state->length) goto inf_leave;
|
||||||
}
|
}
|
||||||
|
state->length = 0;
|
||||||
state->mode = NAME;
|
state->mode = NAME;
|
||||||
case NAME:
|
case NAME:
|
||||||
if (state->flags & 0x0800) {
|
if (state->flags & 0x0800) {
|
||||||
|
@ -661,13 +705,20 @@ int flush;
|
||||||
copy = 0;
|
copy = 0;
|
||||||
do {
|
do {
|
||||||
len = (unsigned)(next[copy++]);
|
len = (unsigned)(next[copy++]);
|
||||||
|
if (state->head != Z_NULL &&
|
||||||
|
state->head->name != Z_NULL &&
|
||||||
|
state->length < state->head->name_max)
|
||||||
|
state->head->name[state->length++] = len;
|
||||||
} while (len && copy < have);
|
} while (len && copy < have);
|
||||||
if (state->flags & 0x02000)
|
if (state->flags & 0x0200)
|
||||||
state->check = crc32(state->check, next, copy);
|
state->check = crc32(state->check, next, copy);
|
||||||
have -= copy;
|
have -= copy;
|
||||||
next += copy;
|
next += copy;
|
||||||
if (len) goto inf_leave;
|
if (len) goto inf_leave;
|
||||||
}
|
}
|
||||||
|
else if (state->head != Z_NULL)
|
||||||
|
state->head->name = Z_NULL;
|
||||||
|
state->length = 0;
|
||||||
state->mode = COMMENT;
|
state->mode = COMMENT;
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
if (state->flags & 0x1000) {
|
if (state->flags & 0x1000) {
|
||||||
|
@ -675,13 +726,19 @@ int flush;
|
||||||
copy = 0;
|
copy = 0;
|
||||||
do {
|
do {
|
||||||
len = (unsigned)(next[copy++]);
|
len = (unsigned)(next[copy++]);
|
||||||
|
if (state->head != Z_NULL &&
|
||||||
|
state->head->comment != Z_NULL &&
|
||||||
|
state->length < state->head->comm_max)
|
||||||
|
state->head->comment[state->length++] = len;
|
||||||
} while (len && copy < have);
|
} while (len && copy < have);
|
||||||
if (state->flags & 0x02000)
|
if (state->flags & 0x0200)
|
||||||
state->check = crc32(state->check, next, copy);
|
state->check = crc32(state->check, next, copy);
|
||||||
have -= copy;
|
have -= copy;
|
||||||
next += copy;
|
next += copy;
|
||||||
if (len) goto inf_leave;
|
if (len) goto inf_leave;
|
||||||
}
|
}
|
||||||
|
else if (state->head != Z_NULL)
|
||||||
|
state->head->comment = Z_NULL;
|
||||||
state->mode = HCRC;
|
state->mode = HCRC;
|
||||||
case HCRC:
|
case HCRC:
|
||||||
if (state->flags & 0x0200) {
|
if (state->flags & 0x0200) {
|
||||||
|
@ -693,6 +750,10 @@ int flush;
|
||||||
}
|
}
|
||||||
INITBITS();
|
INITBITS();
|
||||||
}
|
}
|
||||||
|
if (state->head != Z_NULL) {
|
||||||
|
state->head->hcrc = (int)((state->flags >> 9) & 1);
|
||||||
|
state->head->done = 1;
|
||||||
|
}
|
||||||
strm->adler = state->check = crc32(0L, Z_NULL, 0);
|
strm->adler = state->check = crc32(0L, Z_NULL, 0);
|
||||||
state->mode = TYPE;
|
state->mode = TYPE;
|
||||||
break;
|
break;
|
||||||
|
@ -861,6 +922,9 @@ int flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* handle error breaks in while */
|
||||||
|
if (state->mode == BAD) break;
|
||||||
|
|
||||||
/* build code tables */
|
/* build code tables */
|
||||||
state->next = state->codes;
|
state->next = state->codes;
|
||||||
state->lencode = (code const FAR *)(state->next);
|
state->lencode = (code const FAR *)(state->next);
|
||||||
|
@ -965,6 +1029,13 @@ int flush;
|
||||||
state->offset += BITS(state->extra);
|
state->offset += BITS(state->extra);
|
||||||
DROPBITS(state->extra);
|
DROPBITS(state->extra);
|
||||||
}
|
}
|
||||||
|
#ifdef INFLATE_STRICT
|
||||||
|
if (state->offset > state->dmax) {
|
||||||
|
strm->msg = (char *)"invalid distance too far back";
|
||||||
|
state->mode = BAD;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (state->offset > state->whave + out - left) {
|
if (state->offset > state->whave + out - left) {
|
||||||
strm->msg = (char *)"invalid distance too far back";
|
strm->msg = (char *)"invalid distance too far back";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
|
@ -1106,12 +1177,16 @@ uInt dictLength;
|
||||||
/* check state */
|
/* check state */
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
state = (struct inflate_state FAR *)strm->state;
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
if (state->mode != DICT) return Z_STREAM_ERROR;
|
if (state->wrap != 0 && state->mode != DICT)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
/* check for correct dictionary id */
|
/* check for correct dictionary id */
|
||||||
id = adler32(0L, Z_NULL, 0);
|
if (state->mode == DICT) {
|
||||||
id = adler32(id, dictionary, dictLength);
|
id = adler32(0L, Z_NULL, 0);
|
||||||
if (id != state->check) return Z_DATA_ERROR;
|
id = adler32(id, dictionary, dictLength);
|
||||||
|
if (id != state->check)
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* copy dictionary to window */
|
/* copy dictionary to window */
|
||||||
if (updatewindow(strm, strm->avail_out)) {
|
if (updatewindow(strm, strm->avail_out)) {
|
||||||
|
@ -1133,6 +1208,23 @@ uInt dictLength;
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ZEXPORT inflateGetHeader(strm, head)
|
||||||
|
z_streamp strm;
|
||||||
|
gz_headerp head;
|
||||||
|
{
|
||||||
|
struct inflate_state FAR *state;
|
||||||
|
|
||||||
|
/* check state */
|
||||||
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
|
if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
|
||||||
|
|
||||||
|
/* save header structure */
|
||||||
|
state->head = head;
|
||||||
|
head->done = 0;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
|
Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
|
||||||
or when out of input. When called, *have is the number of pattern bytes
|
or when out of input. When called, *have is the number of pattern bytes
|
||||||
|
@ -1235,6 +1327,7 @@ z_streamp source;
|
||||||
struct inflate_state FAR *state;
|
struct inflate_state FAR *state;
|
||||||
struct inflate_state FAR *copy;
|
struct inflate_state FAR *copy;
|
||||||
unsigned char FAR *window;
|
unsigned char FAR *window;
|
||||||
|
unsigned wsize;
|
||||||
|
|
||||||
/* check input */
|
/* check input */
|
||||||
if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
|
if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
|
||||||
|
@ -1257,14 +1350,19 @@ z_streamp source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy state */
|
/* copy state */
|
||||||
*dest = *source;
|
zmemcpy(dest, source, sizeof(z_stream));
|
||||||
*copy = *state;
|
zmemcpy(copy, state, sizeof(struct inflate_state));
|
||||||
copy->lencode = copy->codes + (state->lencode - state->codes);
|
if (state->lencode >= state->codes &&
|
||||||
copy->distcode = copy->codes + (state->distcode - state->codes);
|
state->lencode <= state->codes + ENOUGH - 1) {
|
||||||
|
copy->lencode = copy->codes + (state->lencode - state->codes);
|
||||||
|
copy->distcode = copy->codes + (state->distcode - state->codes);
|
||||||
|
}
|
||||||
copy->next = copy->codes + (state->next - state->codes);
|
copy->next = copy->codes + (state->next - state->codes);
|
||||||
if (window != Z_NULL)
|
if (window != Z_NULL) {
|
||||||
zmemcpy(window, state->window, 1U << state->wbits);
|
wsize = 1U << state->wbits;
|
||||||
|
zmemcpy(window, state->window, wsize);
|
||||||
|
}
|
||||||
copy->window = window;
|
copy->window = window;
|
||||||
dest->state = (voidpf)copy;
|
dest->state = (struct internal_state FAR *)copy;
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* inflate.h -- internal inflate state definition
|
/* inflate.h -- internal inflate state definition
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2004 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
||||||
/* Possible inflate modes between inflate() calls */
|
/* Possible inflate modes between inflate() calls */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HEAD, /* i: waiting for magic header */
|
HEAD, /* i: waiting for magic header */
|
||||||
#ifdef GUNZIP
|
|
||||||
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) */
|
||||||
|
@ -28,7 +27,6 @@ typedef enum {
|
||||||
NAME, /* i: waiting for end of file name (gzip) */
|
NAME, /* i: waiting for end of file name (gzip) */
|
||||||
COMMENT, /* i: waiting for end of comment (gzip) */
|
COMMENT, /* i: waiting for end of comment (gzip) */
|
||||||
HCRC, /* i: waiting for header crc (gzip) */
|
HCRC, /* i: waiting for header crc (gzip) */
|
||||||
#endif
|
|
||||||
DICTID, /* i: waiting for dictionary check value */
|
DICTID, /* i: waiting for dictionary check value */
|
||||||
DICT, /* waiting for inflateSetDictionary() call */
|
DICT, /* waiting for inflateSetDictionary() call */
|
||||||
TYPE, /* i: waiting for type bits, including last-flag bit */
|
TYPE, /* i: waiting for type bits, including last-flag bit */
|
||||||
|
@ -45,9 +43,7 @@ typedef enum {
|
||||||
MATCH, /* o: waiting for output space to copy string */
|
MATCH, /* o: waiting for output space to copy string */
|
||||||
LIT, /* o: waiting for output space to write literal */
|
LIT, /* o: waiting for output space to write literal */
|
||||||
CHECK, /* i: waiting for 32-bit check value */
|
CHECK, /* i: waiting for 32-bit check value */
|
||||||
#ifdef GUNZIP
|
|
||||||
LENGTH, /* i: waiting for 32-bit length (gzip) */
|
LENGTH, /* i: waiting for 32-bit length (gzip) */
|
||||||
#endif
|
|
||||||
DONE, /* finished check, done -- remain here until reset */
|
DONE, /* finished check, done -- remain here until reset */
|
||||||
BAD, /* got a data error -- remain here until reset */
|
BAD, /* got a data error -- remain here until reset */
|
||||||
MEM, /* got an inflate() memory error -- remain here until reset */
|
MEM, /* got an inflate() memory error -- remain here until reset */
|
||||||
|
@ -84,8 +80,10 @@ struct inflate_state {
|
||||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||||
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) */
|
||||||
|
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 */
|
||||||
|
gz_headerp head; /* where to save gzip header information */
|
||||||
/* sliding window */
|
/* sliding window */
|
||||||
unsigned wbits; /* log base 2 of requested window size */
|
unsigned wbits; /* log base 2 of requested window size */
|
||||||
unsigned wsize; /* window size or zero if not using window */
|
unsigned wsize; /* window size or zero if not using window */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2005 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define MAXBITS 15
|
#define MAXBITS 15
|
||||||
|
|
||||||
const char inflate_copyright[] =
|
const char inflate_copyright[] =
|
||||||
" inflate 1.2.1 Copyright 1995-2003 Mark Adler ";
|
" inflate 1.2.3 Copyright 1995-2005 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
|
||||||
|
@ -62,7 +62,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, 76, 66};
|
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
|
||||||
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,
|
||||||
|
@ -114,7 +114,15 @@ unsigned short FAR *work;
|
||||||
for (max = MAXBITS; max >= 1; max--)
|
for (max = MAXBITS; max >= 1; max--)
|
||||||
if (count[max] != 0) break;
|
if (count[max] != 0) break;
|
||||||
if (root > max) root = max;
|
if (root > max) root = max;
|
||||||
if (max == 0) return -1; /* no codes! */
|
if (max == 0) { /* no symbols to code at all */
|
||||||
|
this.op = (unsigned char)64; /* invalid code marker */
|
||||||
|
this.bits = (unsigned char)1;
|
||||||
|
this.val = (unsigned short)0;
|
||||||
|
*(*table)++ = this; /* make a table to force an error */
|
||||||
|
*(*table)++ = this;
|
||||||
|
*bits = 1;
|
||||||
|
return 0; /* no symbols, but wait for decoding to report error */
|
||||||
|
}
|
||||||
for (min = 1; min <= MAXBITS; min++)
|
for (min = 1; min <= MAXBITS; min++)
|
||||||
if (count[min] != 0) break;
|
if (count[min] != 0) break;
|
||||||
if (root < min) root = min;
|
if (root < min) root = min;
|
||||||
|
@ -127,7 +135,6 @@ unsigned short FAR *work;
|
||||||
if (left < 0) return -1; /* over-subscribed */
|
if (left < 0) return -1; /* over-subscribed */
|
||||||
}
|
}
|
||||||
if (left > 0 && (type == CODES || max != 1))
|
if (left > 0 && (type == CODES || max != 1))
|
||||||
//if (left > 0 && (type == CODES || (codes - count[0] != 1)))
|
|
||||||
return -1; /* incomplete set */
|
return -1; /* incomplete set */
|
||||||
|
|
||||||
/* generate offsets into symbol table for each length for sorting */
|
/* generate offsets into symbol table for each length for sorting */
|
||||||
|
@ -225,6 +232,7 @@ unsigned short FAR *work;
|
||||||
/* replicate for those indices with low len bits equal to huff */
|
/* replicate for those indices with low len bits equal to huff */
|
||||||
incr = 1U << (len - drop);
|
incr = 1U << (len - drop);
|
||||||
fill = 1U << curr;
|
fill = 1U << curr;
|
||||||
|
min = fill; /* save offset to next table */
|
||||||
do {
|
do {
|
||||||
fill -= incr;
|
fill -= incr;
|
||||||
next[(huff >> drop) + fill] = this;
|
next[(huff >> drop) + fill] = this;
|
||||||
|
@ -255,7 +263,7 @@ unsigned short FAR *work;
|
||||||
drop = root;
|
drop = root;
|
||||||
|
|
||||||
/* increment past last table */
|
/* increment past last table */
|
||||||
next += 1U << curr;
|
next += min; /* here min is 1 << curr */
|
||||||
|
|
||||||
/* determine length of next table */
|
/* determine length of next table */
|
||||||
curr = len - drop;
|
curr = len - drop;
|
||||||
|
@ -296,7 +304,6 @@ unsigned short FAR *work;
|
||||||
drop = 0;
|
drop = 0;
|
||||||
len = root;
|
len = root;
|
||||||
next = *table;
|
next = *table;
|
||||||
curr = root;
|
|
||||||
this.bits = (unsigned char)len;
|
this.bits = (unsigned char)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* inftrees.h -- header to use inftrees.c
|
/* inftrees.h -- header to use inftrees.c
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -36,12 +36,12 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||||
exhaustive search was 1004 code structures (850 for length/literals
|
exhaustive search was 1444 code structures (852 for length/literals
|
||||||
and 154 for distances, the latter actually the result of an
|
and 592 for distances, the latter actually the result of an
|
||||||
exhaustive search). The true maximum is not known, but the value
|
exhaustive search). The true maximum is not known, but the value
|
||||||
below is more than safe. */
|
below is more than safe. */
|
||||||
#define ENOUGH 1440
|
#define ENOUGH 2048
|
||||||
#define MAXD 154
|
#define MAXD 592
|
||||||
|
|
||||||
/* Type of code to build for inftable() */
|
/* Type of code to build for inftable() */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
/* inflate_util.c -- data and routines common to blocks and codes
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "zutil.h"
|
|
||||||
#include "infblock.h"
|
|
||||||
#include "inftrees.h"
|
|
||||||
#include "infcodes.h"
|
|
||||||
#include "infutil.h"
|
|
||||||
|
|
||||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
|
||||||
|
|
||||||
/* And'ing with mask[n] masks the lower n bits */
|
|
||||||
uInt inflate_mask[17] = {
|
|
||||||
0x0000,
|
|
||||||
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
|
||||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* copy as much as possible from the sliding window to the output area */
|
|
||||||
int inflate_flush(s, z, r)
|
|
||||||
inflate_blocks_statef *s;
|
|
||||||
z_streamp z;
|
|
||||||
int r;
|
|
||||||
{
|
|
||||||
uInt n;
|
|
||||||
Bytef *p;
|
|
||||||
Bytef *q;
|
|
||||||
|
|
||||||
/* local copies of source and destination pointers */
|
|
||||||
p = z->next_out;
|
|
||||||
q = s->read;
|
|
||||||
|
|
||||||
/* compute number of bytes to copy as far as end of window */
|
|
||||||
n = (uInt)((q <= s->write ? s->write : s->end) - q);
|
|
||||||
if (n > z->avail_out) n = z->avail_out;
|
|
||||||
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
|
||||||
|
|
||||||
/* update counters */
|
|
||||||
z->avail_out -= n;
|
|
||||||
z->total_out += n;
|
|
||||||
|
|
||||||
/* update check information */
|
|
||||||
if (s->checkfn != Z_NULL)
|
|
||||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
|
||||||
|
|
||||||
/* copy as far as end of window */
|
|
||||||
zmemcpy(p, q, n);
|
|
||||||
p += n;
|
|
||||||
q += n;
|
|
||||||
|
|
||||||
/* see if more to copy at beginning of window */
|
|
||||||
if (q == s->end)
|
|
||||||
{
|
|
||||||
/* wrap pointers */
|
|
||||||
q = s->window;
|
|
||||||
if (s->write == s->end)
|
|
||||||
s->write = s->window;
|
|
||||||
|
|
||||||
/* compute bytes to copy */
|
|
||||||
n = (uInt)(s->write - q);
|
|
||||||
if (n > z->avail_out) n = z->avail_out;
|
|
||||||
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
|
||||||
|
|
||||||
/* update counters */
|
|
||||||
z->avail_out -= n;
|
|
||||||
z->total_out += n;
|
|
||||||
|
|
||||||
/* update check information */
|
|
||||||
if (s->checkfn != Z_NULL)
|
|
||||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
|
||||||
|
|
||||||
/* copy */
|
|
||||||
zmemcpy(p, q, n);
|
|
||||||
p += n;
|
|
||||||
q += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update pointers */
|
|
||||||
z->next_out = p;
|
|
||||||
s->read = q;
|
|
||||||
|
|
||||||
/* done */
|
|
||||||
return r;
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
/* infutil.h -- types and macros common to blocks and codes
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: this file should *not* be used by applications. It is
|
|
||||||
part of the implementation of the compression library and is
|
|
||||||
subject to change. Applications should only use zlib.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _INFUTIL_H
|
|
||||||
#define _INFUTIL_H
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TYPE, /* get type bits (3, including end bit) */
|
|
||||||
LENS, /* get lengths for stored */
|
|
||||||
STORED, /* processing stored block */
|
|
||||||
TABLE, /* get table lengths */
|
|
||||||
BTREE, /* get bit lengths tree for a dynamic block */
|
|
||||||
DTREE, /* get length, distance trees for a dynamic block */
|
|
||||||
CODES, /* processing fixed or dynamic block */
|
|
||||||
DRY, /* output remaining window bytes */
|
|
||||||
DONE, /* finished last block, done */
|
|
||||||
BAD} /* got a data error--stuck here */
|
|
||||||
inflate_block_mode;
|
|
||||||
|
|
||||||
/* inflate blocks semi-private state */
|
|
||||||
struct inflate_blocks_state {
|
|
||||||
|
|
||||||
/* mode */
|
|
||||||
inflate_block_mode mode; /* current inflate_block mode */
|
|
||||||
|
|
||||||
/* mode dependent information */
|
|
||||||
union {
|
|
||||||
uInt left; /* if STORED, bytes left to copy */
|
|
||||||
struct {
|
|
||||||
uInt table; /* table lengths (14 bits) */
|
|
||||||
uInt index; /* index into blens (or border) */
|
|
||||||
uIntf *blens; /* bit lengths of codes */
|
|
||||||
uInt bb; /* bit length tree depth */
|
|
||||||
inflate_huft *tb; /* bit length decoding tree */
|
|
||||||
} trees; /* if DTREE, decoding info for trees */
|
|
||||||
struct {
|
|
||||||
inflate_codes_statef
|
|
||||||
*codes;
|
|
||||||
} decode; /* if CODES, current state */
|
|
||||||
} sub; /* submode */
|
|
||||||
uInt last; /* true if this block is the last block */
|
|
||||||
|
|
||||||
/* mode independent information */
|
|
||||||
uInt bitk; /* bits in bit buffer */
|
|
||||||
uLong bitb; /* bit buffer */
|
|
||||||
inflate_huft *hufts; /* single malloc for tree space */
|
|
||||||
Bytef *window; /* sliding window */
|
|
||||||
Bytef *end; /* one byte after sliding window */
|
|
||||||
Bytef *read; /* window read pointer */
|
|
||||||
Bytef *write; /* window write pointer */
|
|
||||||
check_func checkfn; /* check function */
|
|
||||||
uLong check; /* check on output */
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* defines for inflate input/output */
|
|
||||||
/* update pointers and return */
|
|
||||||
#define UPDBITS {s->bitb=b;s->bitk=k;}
|
|
||||||
#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
|
|
||||||
#define UPDOUT {s->write=q;}
|
|
||||||
#define UPDATE {UPDBITS UPDIN UPDOUT}
|
|
||||||
#define LEAVE {UPDATE return inflate_flush(s,z,r);}
|
|
||||||
/* get bytes and bits */
|
|
||||||
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
|
|
||||||
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
|
|
||||||
#define NEXTBYTE (n--,*p++)
|
|
||||||
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
|
||||||
#define DUMPBITS(j) {b>>=(j);k-=(j);}
|
|
||||||
/* output bytes */
|
|
||||||
#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
|
|
||||||
#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
|
|
||||||
#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
|
|
||||||
#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
|
|
||||||
#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
|
|
||||||
#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
|
|
||||||
/* load local pointers */
|
|
||||||
#define LOAD {LOADIN LOADOUT}
|
|
||||||
|
|
||||||
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
|
|
||||||
extern uInt inflate_mask[17];
|
|
||||||
|
|
||||||
/* copy as much as possible from the sliding window to the output area */
|
|
||||||
extern int inflate_flush OF((
|
|
||||||
inflate_blocks_statef *,
|
|
||||||
z_streamp ,
|
|
||||||
int));
|
|
||||||
|
|
||||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
LD=link
|
LD=link
|
||||||
CFLAGS=-O
|
CFLAGS=-O -m32
|
||||||
LDFLAGS=
|
LDFLAGS=
|
||||||
O=.o
|
O=.o
|
||||||
|
|
||||||
|
@ -74,4 +74,4 @@ test: example minigzip
|
||||||
echo hello world | minigzip | minigzip -d
|
echo hello world | minigzip | minigzip -d
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJS) zlib.a example minigzip test foo.gz
|
$(RM) $(OBJS) zlib.a example minigzip minigzip.o test foo.gz
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
/* maketree.c -- make inffixed.h table for decoding fixed codes
|
|
||||||
* Copyright (C) 1995-2002 Mark Adler
|
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: this file should *not* be used by applications. It is
|
|
||||||
part of the implementation of the compression library and is
|
|
||||||
subject to change. Applications should only use zlib.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This program is included in the distribution for completeness.
|
|
||||||
You do not need to compile or run this program since inffixed.h
|
|
||||||
is already included in the distribution. To use this program
|
|
||||||
you need to compile zlib with BUILDFIXED defined and then compile
|
|
||||||
and link this program with the zlib library. Then the output of
|
|
||||||
this program can be piped to inffixed.h. */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "zutil.h"
|
|
||||||
#include "inftrees.h"
|
|
||||||
|
|
||||||
/* simplify the use of the inflate_huft type with some defines */
|
|
||||||
#define exop word.what.Exop
|
|
||||||
#define bits word.what.Bits
|
|
||||||
|
|
||||||
/* generate initialization table for an inflate_huft structure array */
|
|
||||||
void maketree(uInt b, inflate_huft *t)
|
|
||||||
{
|
|
||||||
int i, e;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
e = t[i].exop;
|
|
||||||
if (e && (e & (16+64)) == 0) /* table pointer */
|
|
||||||
{
|
|
||||||
fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (i % 4 == 0)
|
|
||||||
printf("\n ");
|
|
||||||
printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
|
|
||||||
if (++i == (1<<b))
|
|
||||||
break;
|
|
||||||
putchar(',');
|
|
||||||
}
|
|
||||||
puts("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create the fixed tables in C initialization syntax */
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
uInt bl, bd;
|
|
||||||
inflate_huft *tl, *td;
|
|
||||||
z_stream z;
|
|
||||||
|
|
||||||
z.zalloc = zcalloc;
|
|
||||||
z.opaque = (voidpf)0;
|
|
||||||
z.zfree = zcfree;
|
|
||||||
r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
|
|
||||||
if (r)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "inflate_trees_fixed error %d\n", r);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
puts("/* inffixed.h -- table for decoding fixed codes");
|
|
||||||
puts(" * Generated automatically by the maketree.c program");
|
|
||||||
puts(" */");
|
|
||||||
puts("");
|
|
||||||
puts("/* WARNING: this file should *not* be used by applications. It is");
|
|
||||||
puts(" part of the implementation of the compression library and is");
|
|
||||||
puts(" subject to change. Applications should only use zlib.h.");
|
|
||||||
puts(" */");
|
|
||||||
puts("");
|
|
||||||
printf("local uInt fixed_bl = %d;\n", bl);
|
|
||||||
printf("local uInt fixed_bd = %d;\n", bd);
|
|
||||||
printf("local inflate_huft fixed_tl[] = {");
|
|
||||||
maketree(bl, tl);
|
|
||||||
puts(" };");
|
|
||||||
printf("local inflate_huft fixed_td[] = {");
|
|
||||||
maketree(bd, td);
|
|
||||||
puts(" };");
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* minigzip.c -- simulate gzip using the zlib compression library
|
/* minigzip.c -- simulate gzip using the zlib compression library
|
||||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@
|
||||||
#ifdef STDC
|
#ifdef STDC
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#else
|
|
||||||
extern void exit OF((int));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_MMAP
|
#ifdef USE_MMAP
|
||||||
|
@ -297,6 +295,8 @@ int main(argc, argv)
|
||||||
break;
|
break;
|
||||||
argc--, argv++;
|
argc--, argv++;
|
||||||
}
|
}
|
||||||
|
if (outmode[3] == ' ')
|
||||||
|
outmode[3] = 0;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
SET_BINARY_MODE(stdin);
|
SET_BINARY_MODE(stdin);
|
||||||
SET_BINARY_MODE(stdout);
|
SET_BINARY_MODE(stdout);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* trees.c -- output deflated data using Huffman coding
|
/* trees.c -- output deflated data using Huffman coding
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ local void gen_bitlen(s, desc)
|
||||||
while (n != 0) {
|
while (n != 0) {
|
||||||
m = s->heap[--h];
|
m = s->heap[--h];
|
||||||
if (m > max_code) continue;
|
if (m > max_code) continue;
|
||||||
if (tree[m].Len != (unsigned) bits) {
|
if ((unsigned) tree[m].Len != (unsigned) bits) {
|
||||||
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
|
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
|
||||||
s->opt_len += ((long)bits - (long)tree[m].Len)
|
s->opt_len += ((long)bits - (long)tree[m].Len)
|
||||||
*(long)tree[m].Freq;
|
*(long)tree[m].Freq;
|
||||||
|
@ -930,8 +930,9 @@ void _tr_flush_block(s, buf, stored_len, eof)
|
||||||
/* Build the Huffman trees unless a stored block is forced */
|
/* Build the Huffman trees unless a stored block is forced */
|
||||||
if (s->level > 0) {
|
if (s->level > 0) {
|
||||||
|
|
||||||
/* Check if the file is ascii or binary */
|
/* Check if the file is binary or text */
|
||||||
if (s->data_type == Z_UNKNOWN) set_data_type(s);
|
if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
|
||||||
|
set_data_type(s);
|
||||||
|
|
||||||
/* Construct the literal and distance trees */
|
/* Construct the literal and distance trees */
|
||||||
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
||||||
|
@ -982,7 +983,7 @@ void _tr_flush_block(s, buf, stored_len, eof)
|
||||||
#ifdef FORCE_STATIC
|
#ifdef FORCE_STATIC
|
||||||
} else if (static_lenb >= 0) { /* force static trees */
|
} else if (static_lenb >= 0) { /* force static trees */
|
||||||
#else
|
#else
|
||||||
} else if (static_lenb == opt_lenb) {
|
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
|
||||||
#endif
|
#endif
|
||||||
send_bits(s, (STATIC_TREES<<1)+eof, 3);
|
send_bits(s, (STATIC_TREES<<1)+eof, 3);
|
||||||
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
|
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
|
||||||
|
@ -1117,21 +1118,24 @@ local void compress_block(s, ltree, dtree)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Set the data type to ASCII or BINARY, using a crude approximation:
|
* Set the data type to BINARY or TEXT, using a crude approximation:
|
||||||
* binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
|
* set it to Z_TEXT if all symbols are either printable characters (33 to 255)
|
||||||
* IN assertion: the fields freq of dyn_ltree are set and the total of all
|
* or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise.
|
||||||
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
|
* IN assertion: the fields Freq of dyn_ltree are set.
|
||||||
*/
|
*/
|
||||||
local void set_data_type(s)
|
local void set_data_type(s)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n;
|
||||||
unsigned ascii_freq = 0;
|
|
||||||
unsigned bin_freq = 0;
|
for (n = 0; n < 9; n++)
|
||||||
while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
|
if (s->dyn_ltree[n].Freq != 0)
|
||||||
while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
|
break;
|
||||||
while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
|
if (n == 9)
|
||||||
s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
|
for (n = 14; n < 32; n++)
|
||||||
|
if (s->dyn_ltree[n].Freq != 0)
|
||||||
|
break;
|
||||||
|
s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* zconf.h -- configuration of the zlib compression library
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -13,43 +13,50 @@
|
||||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||||
*/
|
*/
|
||||||
#ifdef Z_PREFIX
|
#ifdef Z_PREFIX
|
||||||
# define deflateInit_ z_deflateInit_
|
# define deflateInit_ z_deflateInit_
|
||||||
# define deflate z_deflate
|
# define deflate z_deflate
|
||||||
# define deflateEnd z_deflateEnd
|
# define deflateEnd z_deflateEnd
|
||||||
# define inflateInit_ z_inflateInit_
|
# define inflateInit_ z_inflateInit_
|
||||||
# define inflate z_inflate
|
# define inflate z_inflate
|
||||||
# define inflateEnd z_inflateEnd
|
# define inflateEnd z_inflateEnd
|
||||||
# define deflateInit2_ z_deflateInit2_
|
# define deflateInit2_ z_deflateInit2_
|
||||||
# define deflateSetDictionary z_deflateSetDictionary
|
# define deflateSetDictionary z_deflateSetDictionary
|
||||||
# define deflateCopy z_deflateCopy
|
# define deflateCopy z_deflateCopy
|
||||||
# define deflateReset z_deflateReset
|
# define deflateReset z_deflateReset
|
||||||
# define deflatePrime z_deflatePrime
|
# define deflateParams z_deflateParams
|
||||||
# define deflateParams z_deflateParams
|
# define deflateBound z_deflateBound
|
||||||
# define deflateBound z_deflateBound
|
# define deflatePrime z_deflatePrime
|
||||||
# define inflateInit2_ z_inflateInit2_
|
# define inflateInit2_ z_inflateInit2_
|
||||||
# define inflateSetDictionary z_inflateSetDictionary
|
# define inflateSetDictionary z_inflateSetDictionary
|
||||||
# define inflateSync z_inflateSync
|
# define inflateSync z_inflateSync
|
||||||
# define inflateSyncPoint z_inflateSyncPoint
|
# define inflateSyncPoint z_inflateSyncPoint
|
||||||
# define inflateCopy z_inflateCopy
|
# define inflateCopy z_inflateCopy
|
||||||
# define inflateReset z_inflateReset
|
# define inflateReset z_inflateReset
|
||||||
# define compress z_compress
|
# define inflateBack z_inflateBack
|
||||||
# define compress2 z_compress2
|
# define inflateBackEnd z_inflateBackEnd
|
||||||
# define compressBound z_compressBound
|
# define compress z_compress
|
||||||
# define uncompress z_uncompress
|
# define compress2 z_compress2
|
||||||
# define adler32 z_adler32
|
# define compressBound z_compressBound
|
||||||
# define crc32 z_crc32
|
# define uncompress z_uncompress
|
||||||
# define get_crc_table z_get_crc_table
|
# define adler32 z_adler32
|
||||||
|
# define crc32 z_crc32
|
||||||
|
# define get_crc_table z_get_crc_table
|
||||||
|
# define zError z_zError
|
||||||
|
|
||||||
# define Byte z_Byte
|
# define alloc_func z_alloc_func
|
||||||
# define uInt z_uInt
|
# define free_func z_free_func
|
||||||
# define uLong z_uLong
|
# define in_func z_in_func
|
||||||
# define Bytef z_Bytef
|
# define out_func z_out_func
|
||||||
# define charf z_charf
|
# define Byte z_Byte
|
||||||
# define intf z_intf
|
# define uInt z_uInt
|
||||||
# define uIntf z_uIntf
|
# define uLong z_uLong
|
||||||
# define uLongf z_uLongf
|
# define Bytef z_Bytef
|
||||||
# define voidpf z_voidpf
|
# define charf z_charf
|
||||||
# define voidp z_voidp
|
# define intf z_intf
|
||||||
|
# define uIntf z_uIntf
|
||||||
|
# define uLongf z_uLongf
|
||||||
|
# define voidpf z_voidpf
|
||||||
|
# define voidp z_voidp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||||
|
@ -61,8 +68,10 @@
|
||||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||||
# define WINDOWS
|
# define WINDOWS
|
||||||
#endif
|
#endif
|
||||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||||
# define WIN32
|
# ifndef WIN32
|
||||||
|
# define WIN32
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||||
|
@ -281,7 +290,7 @@ typedef uLong FAR uLongf;
|
||||||
# ifdef VMS
|
# ifdef VMS
|
||||||
# include <unixio.h> /* for off_t */
|
# include <unixio.h> /* for off_t */
|
||||||
# endif
|
# endif
|
||||||
# define z_off_t off_t
|
# define z_off_t off_t
|
||||||
#endif
|
#endif
|
||||||
#ifndef SEEK_SET
|
#ifndef SEEK_SET
|
||||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||||
|
@ -289,11 +298,11 @@ typedef uLong FAR uLongf;
|
||||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||||
#endif
|
#endif
|
||||||
#ifndef z_off_t
|
#ifndef z_off_t
|
||||||
# define z_off_t long
|
# define z_off_t long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__OS400__)
|
#if defined(__OS400__)
|
||||||
#define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__MVS__)
|
#if defined(__MVS__)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* zconf.h -- configuration of the zlib compression library
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -13,43 +13,50 @@
|
||||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||||
*/
|
*/
|
||||||
#ifdef Z_PREFIX
|
#ifdef Z_PREFIX
|
||||||
# define deflateInit_ z_deflateInit_
|
# define deflateInit_ z_deflateInit_
|
||||||
# define deflate z_deflate
|
# define deflate z_deflate
|
||||||
# define deflateEnd z_deflateEnd
|
# define deflateEnd z_deflateEnd
|
||||||
# define inflateInit_ z_inflateInit_
|
# define inflateInit_ z_inflateInit_
|
||||||
# define inflate z_inflate
|
# define inflate z_inflate
|
||||||
# define inflateEnd z_inflateEnd
|
# define inflateEnd z_inflateEnd
|
||||||
# define deflateInit2_ z_deflateInit2_
|
# define deflateInit2_ z_deflateInit2_
|
||||||
# define deflateSetDictionary z_deflateSetDictionary
|
# define deflateSetDictionary z_deflateSetDictionary
|
||||||
# define deflateCopy z_deflateCopy
|
# define deflateCopy z_deflateCopy
|
||||||
# define deflateReset z_deflateReset
|
# define deflateReset z_deflateReset
|
||||||
# define deflatePrime z_deflatePrime
|
# define deflateParams z_deflateParams
|
||||||
# define deflateParams z_deflateParams
|
# define deflateBound z_deflateBound
|
||||||
# define deflateBound z_deflateBound
|
# define deflatePrime z_deflatePrime
|
||||||
# define inflateInit2_ z_inflateInit2_
|
# define inflateInit2_ z_inflateInit2_
|
||||||
# define inflateSetDictionary z_inflateSetDictionary
|
# define inflateSetDictionary z_inflateSetDictionary
|
||||||
# define inflateSync z_inflateSync
|
# define inflateSync z_inflateSync
|
||||||
# define inflateSyncPoint z_inflateSyncPoint
|
# define inflateSyncPoint z_inflateSyncPoint
|
||||||
# define inflateCopy z_inflateCopy
|
# define inflateCopy z_inflateCopy
|
||||||
# define inflateReset z_inflateReset
|
# define inflateReset z_inflateReset
|
||||||
# define compress z_compress
|
# define inflateBack z_inflateBack
|
||||||
# define compress2 z_compress2
|
# define inflateBackEnd z_inflateBackEnd
|
||||||
# define compressBound z_compressBound
|
# define compress z_compress
|
||||||
# define uncompress z_uncompress
|
# define compress2 z_compress2
|
||||||
# define adler32 z_adler32
|
# define compressBound z_compressBound
|
||||||
# define crc32 z_crc32
|
# define uncompress z_uncompress
|
||||||
# define get_crc_table z_get_crc_table
|
# define adler32 z_adler32
|
||||||
|
# define crc32 z_crc32
|
||||||
|
# define get_crc_table z_get_crc_table
|
||||||
|
# define zError z_zError
|
||||||
|
|
||||||
# define Byte z_Byte
|
# define alloc_func z_alloc_func
|
||||||
# define uInt z_uInt
|
# define free_func z_free_func
|
||||||
# define uLong z_uLong
|
# define in_func z_in_func
|
||||||
# define Bytef z_Bytef
|
# define out_func z_out_func
|
||||||
# define charf z_charf
|
# define Byte z_Byte
|
||||||
# define intf z_intf
|
# define uInt z_uInt
|
||||||
# define uIntf z_uIntf
|
# define uLong z_uLong
|
||||||
# define uLongf z_uLongf
|
# define Bytef z_Bytef
|
||||||
# define voidpf z_voidpf
|
# define charf z_charf
|
||||||
# define voidp z_voidp
|
# define intf z_intf
|
||||||
|
# define uIntf z_uIntf
|
||||||
|
# define uLongf z_uLongf
|
||||||
|
# define voidpf z_voidpf
|
||||||
|
# define voidp z_voidp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||||
|
@ -61,8 +68,10 @@
|
||||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||||
# define WINDOWS
|
# define WINDOWS
|
||||||
#endif
|
#endif
|
||||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||||
# define WIN32
|
# ifndef WIN32
|
||||||
|
# define WIN32
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||||
|
@ -281,7 +290,7 @@ typedef uLong FAR uLongf;
|
||||||
# ifdef VMS
|
# ifdef VMS
|
||||||
# include <unixio.h> /* for off_t */
|
# include <unixio.h> /* for off_t */
|
||||||
# endif
|
# endif
|
||||||
# define z_off_t off_t
|
# define z_off_t off_t
|
||||||
#endif
|
#endif
|
||||||
#ifndef SEEK_SET
|
#ifndef SEEK_SET
|
||||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||||
|
@ -289,11 +298,11 @@ typedef uLong FAR uLongf;
|
||||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||||
#endif
|
#endif
|
||||||
#ifndef z_off_t
|
#ifndef z_off_t
|
||||||
# define z_off_t long
|
# define z_off_t long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__OS400__)
|
#if defined(__OS400__)
|
||||||
#define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__MVS__)
|
#if defined(__MVS__)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.TH ZLIB 3 "17 November 2003"
|
.TH ZLIB 3 "18 July 2005"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
zlib \- compression/decompression library
|
zlib \- compression/decompression library
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
@ -133,8 +133,8 @@ before asking for help.
|
||||||
Send questions and/or comments to zlib@gzip.org,
|
Send questions and/or comments to zlib@gzip.org,
|
||||||
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
|
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Version 1.2.1
|
Version 1.2.3
|
||||||
Copyright (C) 1995-2003 Jean-loup Gailly (jloup@gzip.org)
|
Copyright (C) 1995-2005 Jean-loup Gailly (jloup@gzip.org)
|
||||||
and Mark Adler (madler@alumni.caltech.edu).
|
and Mark Adler (madler@alumni.caltech.edu).
|
||||||
.LP
|
.LP
|
||||||
This software is provided "as-is,"
|
This software is provided "as-is,"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||||
version 1.2.1, November 17th, 2003
|
version 1.2.3, July 18th, 2005
|
||||||
|
|
||||||
Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
|
Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
@ -37,8 +37,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ZLIB_VERSION "1.2.1"
|
#define ZLIB_VERSION "1.2.3"
|
||||||
#define ZLIB_VERNUM 0x1210
|
#define ZLIB_VERNUM 0x1230
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The 'zlib' compression library provides in-memory compression and
|
The 'zlib' compression library provides in-memory compression and
|
||||||
|
@ -53,24 +53,22 @@ extern "C" {
|
||||||
application must provide more input and/or consume the output
|
application must provide more input and/or consume the output
|
||||||
(providing more output space) before each call.
|
(providing more output space) before each call.
|
||||||
|
|
||||||
The compressed data format used by the in-memory functions is the zlib
|
The compressed data format used by default by the in-memory functions is
|
||||||
format, which is a zlib wrapper documented in RFC 1950, wrapped around a
|
the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
|
||||||
deflate stream, which is itself documented in RFC 1951.
|
around a deflate stream, which is itself documented in RFC 1951.
|
||||||
|
|
||||||
The library also supports reading and writing files in gzip (.gz) format
|
The library also supports reading and writing files in gzip (.gz) format
|
||||||
with an interface similar to that of stdio using the functions that start
|
with an interface similar to that of stdio using the functions that start
|
||||||
with "gz". The gzip format is different from the zlib format. gzip is a
|
with "gz". The gzip format is different from the zlib format. gzip is a
|
||||||
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
||||||
|
|
||||||
|
This library can optionally read and write gzip streams in memory as well.
|
||||||
|
|
||||||
The zlib format was designed to be compact and fast for use in memory
|
The zlib format was designed to be compact and fast for use in memory
|
||||||
and on communications channels. The gzip format was designed for single-
|
and on communications channels. The gzip format was designed for single-
|
||||||
file compression on file systems, has a larger header than zlib to maintain
|
file compression on file systems, has a larger header than zlib to maintain
|
||||||
directory information, and uses a different, slower check method than zlib.
|
directory information, and uses a different, slower check method than zlib.
|
||||||
|
|
||||||
This library does not provide any functions to write gzip files in memory.
|
|
||||||
However such functions could be easily written using zlib's deflate function,
|
|
||||||
the documentation in the gzip RFC, and the examples in gzio.c.
|
|
||||||
|
|
||||||
The library does not install any signal handler. The decoder checks
|
The library does not install any signal handler. The decoder checks
|
||||||
the consistency of the compressed data, so the library should never
|
the consistency of the compressed data, so the library should never
|
||||||
crash even in case of corrupted input.
|
crash even in case of corrupted input.
|
||||||
|
@ -97,13 +95,36 @@ typedef struct z_stream_s {
|
||||||
free_func zfree; /* used to free the internal state */
|
free_func zfree; /* used to free the internal state */
|
||||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||||
|
|
||||||
int data_type; /* best guess about the data type: ascii or binary */
|
int data_type; /* best guess about the data type: binary or text */
|
||||||
uLong adler; /* adler32 value of the uncompressed data */
|
uLong adler; /* adler32 value of the uncompressed data */
|
||||||
uLong reserved; /* reserved for future use */
|
uLong reserved; /* reserved for future use */
|
||||||
} z_stream;
|
} z_stream;
|
||||||
|
|
||||||
typedef z_stream FAR *z_streamp;
|
typedef z_stream FAR *z_streamp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
gzip header information passed to and from zlib routines. See RFC 1952
|
||||||
|
for more details on the meanings of these fields.
|
||||||
|
*/
|
||||||
|
typedef struct gz_header_s {
|
||||||
|
int text; /* true if compressed data believed to be text */
|
||||||
|
uLong time; /* modification time */
|
||||||
|
int xflags; /* extra flags (not used when writing a gzip file) */
|
||||||
|
int os; /* operating system */
|
||||||
|
Bytef *extra; /* pointer to extra field or Z_NULL if none */
|
||||||
|
uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
|
||||||
|
uInt extra_max; /* space at extra (only when reading header) */
|
||||||
|
Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
|
||||||
|
uInt name_max; /* space at name (only when reading header) */
|
||||||
|
Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
|
||||||
|
uInt comm_max; /* space at comment (only when reading header) */
|
||||||
|
int hcrc; /* true if there was or will be a header crc */
|
||||||
|
int done; /* true when done reading gzip header (not used
|
||||||
|
when writing a gzip file) */
|
||||||
|
} gz_header;
|
||||||
|
|
||||||
|
typedef gz_header FAR *gz_headerp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The application must update next_in and avail_in when avail_in has
|
The application must update next_in and avail_in when avail_in has
|
||||||
dropped to zero. It must update next_out and avail_out when avail_out
|
dropped to zero. It must update next_out and avail_out when avail_out
|
||||||
|
@ -168,11 +189,13 @@ typedef z_stream FAR *z_streamp;
|
||||||
#define Z_FILTERED 1
|
#define Z_FILTERED 1
|
||||||
#define Z_HUFFMAN_ONLY 2
|
#define Z_HUFFMAN_ONLY 2
|
||||||
#define Z_RLE 3
|
#define Z_RLE 3
|
||||||
|
#define Z_FIXED 4
|
||||||
#define Z_DEFAULT_STRATEGY 0
|
#define Z_DEFAULT_STRATEGY 0
|
||||||
/* compression strategy; see deflateInit2() below for details */
|
/* compression strategy; see deflateInit2() below for details */
|
||||||
|
|
||||||
#define Z_BINARY 0
|
#define Z_BINARY 0
|
||||||
#define Z_ASCII 1
|
#define Z_TEXT 1
|
||||||
|
#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
|
||||||
#define Z_UNKNOWN 2
|
#define Z_UNKNOWN 2
|
||||||
/* Possible values of the data_type field (though see inflate()) */
|
/* Possible values of the data_type field (though see inflate()) */
|
||||||
|
|
||||||
|
@ -246,6 +269,10 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||||
and with zero avail_out, it must be called again after making room in the
|
and with zero avail_out, it must be called again after making room in the
|
||||||
output buffer because there might be more output pending.
|
output buffer because there might be more output pending.
|
||||||
|
|
||||||
|
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
|
||||||
|
decide how much data to accumualte before producing output, in order to
|
||||||
|
maximize compression.
|
||||||
|
|
||||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||||
that the decompressor can get all input data available so far. (In particular
|
that the decompressor can get all input data available so far. (In particular
|
||||||
|
@ -257,7 +284,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||||
restart from this point if previous compressed data has been damaged or if
|
restart from this point if previous compressed data has been damaged or if
|
||||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||||
the compression.
|
compression.
|
||||||
|
|
||||||
If deflate returns with avail_out == 0, this function must be called again
|
If deflate returns with avail_out == 0, this function must be called again
|
||||||
with the same value of the flush parameter and more output space (updated
|
with the same value of the flush parameter and more output space (updated
|
||||||
|
@ -282,8 +309,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||||
so far (that is, total_in bytes).
|
so far (that is, total_in bytes).
|
||||||
|
|
||||||
deflate() may update data_type if it can make a good guess about
|
deflate() may update strm->data_type if it can make a good guess about
|
||||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
|
||||||
binary. This field is only for information purposes and does not affect
|
binary. This field is only for information purposes and does not affect
|
||||||
the compression algorithm in any manner.
|
the compression algorithm in any manner.
|
||||||
|
|
||||||
|
@ -365,11 +392,11 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||||
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
|
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
|
||||||
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
|
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
|
||||||
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
|
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
|
||||||
if and when it get to the next deflate block boundary. When decoding the zlib
|
if and when it gets to the next deflate block boundary. When decoding the
|
||||||
or gzip format, this will cause inflate() to return immediately after the
|
zlib or gzip format, this will cause inflate() to return immediately after
|
||||||
header and before the first block. When doing a raw inflate, inflate() will
|
the header and before the first block. When doing a raw inflate, inflate()
|
||||||
go ahead and process the first block, and will return when it gets to the end
|
will go ahead and process the first block, and will return when it gets to
|
||||||
of that block, or when it runs out of data.
|
the end of that block, or when it runs out of data.
|
||||||
|
|
||||||
The Z_BLOCK option assists in appending to or combining deflate streams.
|
The Z_BLOCK option assists in appending to or combining deflate streams.
|
||||||
Also to assist in this, on return inflate() will set strm->data_type to the
|
Also to assist in this, on return inflate() will set strm->data_type to the
|
||||||
|
@ -401,7 +428,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||||
because Z_BLOCK is used.
|
because Z_BLOCK is used.
|
||||||
|
|
||||||
If a preset dictionary is needed after this call (see inflateSetDictionary
|
If a preset dictionary is needed after this call (see inflateSetDictionary
|
||||||
below), inflate sets strm-adler to the adler32 checksum of the dictionary
|
below), inflate sets strm->adler to the adler32 checksum of the dictionary
|
||||||
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
||||||
strm->adler to the adler32 checksum of all output produced so far (that is,
|
strm->adler to the adler32 checksum of all output produced so far (that is,
|
||||||
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
|
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
|
||||||
|
@ -478,7 +505,8 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||||
16 to windowBits to write a simple gzip header and trailer around the
|
16 to windowBits to write a simple gzip header and trailer around the
|
||||||
compressed data instead of a zlib wrapper. The gzip header will have no
|
compressed data instead of a zlib wrapper. The gzip header will have no
|
||||||
file name, no extra data, no comment, no modification time (set to zero),
|
file name, no extra data, no comment, no modification time (set to zero),
|
||||||
no header crc, and the operating system will be set to 255 (unknown).
|
no header crc, and the operating system will be set to 255 (unknown). If a
|
||||||
|
gzip stream is being written, strm->adler is a crc32 instead of an adler32.
|
||||||
|
|
||||||
The memLevel parameter specifies how much memory should be allocated
|
The memLevel parameter specifies how much memory should be allocated
|
||||||
for the internal compression state. memLevel=1 uses minimum memory but
|
for the internal compression state. memLevel=1 uses minimum memory but
|
||||||
|
@ -497,7 +525,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||||
Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
|
Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
|
||||||
Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
|
Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
|
||||||
parameter only affects the compression ratio but not the correctness of the
|
parameter only affects the compression ratio but not the correctness of the
|
||||||
compressed output even if it is not set appropriately.
|
compressed output even if it is not set appropriately. Z_FIXED prevents the
|
||||||
|
use of dynamic Huffman codes, allowing for a simpler decoder for special
|
||||||
|
applications.
|
||||||
|
|
||||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||||
|
@ -526,7 +556,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||||
discarded, for example if the dictionary is larger than the window size in
|
discarded, for example if the dictionary is larger than the window size in
|
||||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||||
put at the end of the dictionary, not at the front.
|
put at the end of the dictionary, not at the front. In addition, the
|
||||||
|
current implementation of deflate will use at most the window size minus
|
||||||
|
262 bytes of the provided dictionary.
|
||||||
|
|
||||||
Upon return of this function, strm->adler is set to the adler32 value
|
Upon return of this function, strm->adler is set to the adler32 value
|
||||||
of the dictionary; the decompressor may later use this value to determine
|
of the dictionary; the decompressor may later use this value to determine
|
||||||
|
@ -592,6 +624,23 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||||
if strm->avail_out was zero.
|
if strm->avail_out was zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
|
||||||
|
int good_length,
|
||||||
|
int max_lazy,
|
||||||
|
int nice_length,
|
||||||
|
int max_chain));
|
||||||
|
/*
|
||||||
|
Fine tune deflate's internal compression parameters. This should only be
|
||||||
|
used by someone who understands the algorithm used by zlib's deflate for
|
||||||
|
searching for the best matching string, and even then only by the most
|
||||||
|
fanatic optimizer trying to squeeze out the last compressed bit for their
|
||||||
|
specific input data. Read the deflate.c source code for the meaning of the
|
||||||
|
max_lazy, good_length, nice_length, and max_chain parameters.
|
||||||
|
|
||||||
|
deflateTune() can be called after deflateInit() or deflateInit2(), and
|
||||||
|
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
|
||||||
|
*/
|
||||||
|
|
||||||
ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
|
ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
|
||||||
uLong sourceLen));
|
uLong sourceLen));
|
||||||
/*
|
/*
|
||||||
|
@ -617,6 +666,30 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
|
||||||
stream state was inconsistent.
|
stream state was inconsistent.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
|
||||||
|
gz_headerp head));
|
||||||
|
/*
|
||||||
|
deflateSetHeader() provides gzip header information for when a gzip
|
||||||
|
stream is requested by deflateInit2(). deflateSetHeader() may be called
|
||||||
|
after deflateInit2() or deflateReset() and before the first call of
|
||||||
|
deflate(). The text, time, os, extra field, name, and comment information
|
||||||
|
in the provided gz_header structure are written to the gzip header (xflag is
|
||||||
|
ignored -- the extra flags are set according to the compression level). The
|
||||||
|
caller must assure that, if not Z_NULL, name and comment are terminated with
|
||||||
|
a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
|
||||||
|
available there. If hcrc is true, a gzip header crc is included. Note that
|
||||||
|
the current versions of the command-line version of gzip (up through version
|
||||||
|
1.3.x) do not support header crc's, and will report that it is a "multi-part
|
||||||
|
gzip file" and give up.
|
||||||
|
|
||||||
|
If deflateSetHeader is not used, the default gzip header has text false,
|
||||||
|
the time set to zero, and os set to 255, with no extra, name, or comment
|
||||||
|
fields. The gzip header is returned to the default state by deflateReset().
|
||||||
|
|
||||||
|
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||||
int windowBits));
|
int windowBits));
|
||||||
|
@ -649,14 +722,15 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||||
windowBits can also be greater than 15 for optional gzip decoding. Add
|
windowBits can also be greater than 15 for optional gzip decoding. Add
|
||||||
32 to windowBits to enable zlib and gzip decoding with automatic header
|
32 to windowBits to enable zlib and gzip decoding with automatic header
|
||||||
detection, or add 16 to decode only the gzip format (the zlib format will
|
detection, or add 16 to decode only the gzip format (the zlib format will
|
||||||
return a Z_DATA_ERROR).
|
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
|
||||||
|
a crc32 instead of an adler32.
|
||||||
|
|
||||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
|
||||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
is set to null if there is no error message. inflateInit2 does not perform
|
||||||
does not perform any decompression apart from reading the zlib header if
|
any decompression apart from reading the zlib header if present: this will
|
||||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
be done by inflate(). (So next_in and avail_in may be modified, but next_out
|
||||||
modified, but next_out and avail_out are unchanged.)
|
and avail_out are unchanged.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||||
|
@ -664,11 +738,14 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||||
uInt dictLength));
|
uInt dictLength));
|
||||||
/*
|
/*
|
||||||
Initializes the decompression dictionary from the given uncompressed byte
|
Initializes the decompression dictionary from the given uncompressed byte
|
||||||
sequence. This function must be called immediately after a call of inflate
|
sequence. This function must be called immediately after a call of inflate,
|
||||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||||
can be determined from the adler32 value returned by this call of
|
can be determined from the adler32 value returned by that call of inflate.
|
||||||
inflate. The compressor and decompressor must use exactly the same
|
The compressor and decompressor must use exactly the same dictionary (see
|
||||||
dictionary (see deflateSetDictionary).
|
deflateSetDictionary). For raw inflate, this function can be called
|
||||||
|
immediately after inflateInit2() or inflateReset() and before any call of
|
||||||
|
inflate() to set the dictionary. The application must insure that the
|
||||||
|
dictionary that was used for compression is provided.
|
||||||
|
|
||||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||||
|
@ -719,8 +796,64 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||||
stream state was inconsistent (such as zalloc or state being NULL).
|
stream state was inconsistent (such as zalloc or state being NULL).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
|
||||||
|
int bits,
|
||||||
|
int value));
|
||||||
/*
|
/*
|
||||||
ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
|
This function inserts bits in the inflate input stream. The intent is
|
||||||
|
that this function is used to start inflating at a bit position in the
|
||||||
|
middle of a byte. The provided bits will be used before any bytes are used
|
||||||
|
from next_in. This function should only be used with raw inflate, and
|
||||||
|
should be used before the first inflate() call after inflateInit2() or
|
||||||
|
inflateReset(). bits must be less than or equal to 16, and that many of the
|
||||||
|
least significant bits of value will be inserted in the input.
|
||||||
|
|
||||||
|
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
|
||||||
|
gz_headerp head));
|
||||||
|
/*
|
||||||
|
inflateGetHeader() requests that gzip header information be stored in the
|
||||||
|
provided gz_header structure. inflateGetHeader() may be called after
|
||||||
|
inflateInit2() or inflateReset(), and before the first call of inflate().
|
||||||
|
As inflate() processes the gzip stream, head->done is zero until the header
|
||||||
|
is completed, at which time head->done is set to one. If a zlib stream is
|
||||||
|
being decoded, then head->done is set to -1 to indicate that there will be
|
||||||
|
no gzip header information forthcoming. Note that Z_BLOCK can be used to
|
||||||
|
force inflate() to return immediately after header processing is complete
|
||||||
|
and before any actual data is decompressed.
|
||||||
|
|
||||||
|
The text, time, xflags, and os fields are filled in with the gzip header
|
||||||
|
contents. hcrc is set to true if there is a header CRC. (The header CRC
|
||||||
|
was valid if done is set to one.) If extra is not Z_NULL, then extra_max
|
||||||
|
contains the maximum number of bytes to write to extra. Once done is true,
|
||||||
|
extra_len contains the actual extra field length, and extra contains the
|
||||||
|
extra field, or that field truncated if extra_max is less than extra_len.
|
||||||
|
If name is not Z_NULL, then up to name_max characters are written there,
|
||||||
|
terminated with a zero unless the length is greater than name_max. If
|
||||||
|
comment is not Z_NULL, then up to comm_max characters are written there,
|
||||||
|
terminated with a zero unless the length is greater than comm_max. When
|
||||||
|
any of extra, name, or comment are not Z_NULL and the respective field is
|
||||||
|
not present in the header, then that field is set to Z_NULL to signal its
|
||||||
|
absence. This allows the use of deflateSetHeader() with the returned
|
||||||
|
structure to duplicate the header. However if those fields are set to
|
||||||
|
allocated memory, then the application will need to save those pointers
|
||||||
|
elsewhere so that they can be eventually freed.
|
||||||
|
|
||||||
|
If inflateGetHeader is not used, then the header information is simply
|
||||||
|
discarded. The header is always checked for validity, including the header
|
||||||
|
CRC if present. inflateReset() will reset the process to discard the header
|
||||||
|
information. The application would need to call inflateGetHeader() again to
|
||||||
|
retrieve the header from the next gzip stream.
|
||||||
|
|
||||||
|
inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
|
||||||
unsigned char FAR *window));
|
unsigned char FAR *window));
|
||||||
|
|
||||||
Initialize the internal stream state for decompression using inflateBack()
|
Initialize the internal stream state for decompression using inflateBack()
|
||||||
|
@ -744,7 +877,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
|
||||||
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
|
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
|
||||||
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
|
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
|
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
||||||
in_func in, void FAR *in_desc,
|
in_func in, void FAR *in_desc,
|
||||||
out_func out, void FAR *out_desc));
|
out_func out, void FAR *out_desc));
|
||||||
/*
|
/*
|
||||||
|
@ -813,7 +946,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
|
||||||
that inflateBack() cannot return Z_OK.
|
that inflateBack() cannot return Z_OK.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm));
|
ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
|
||||||
/*
|
/*
|
||||||
All memory allocated by inflateBackInit() is freed.
|
All memory allocated by inflateBackInit() is freed.
|
||||||
|
|
||||||
|
@ -1087,6 +1220,12 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
||||||
input stream, otherwise zero.
|
input stream, otherwise zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
|
||||||
|
/*
|
||||||
|
Returns 1 if file is being read directly without decompression, otherwise
|
||||||
|
zero.
|
||||||
|
*/
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||||
/*
|
/*
|
||||||
Flushes all pending output if necessary, closes the compressed file
|
Flushes all pending output if necessary, closes the compressed file
|
||||||
|
@ -1119,7 +1258,6 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||||
return the updated checksum. If buf is NULL, this function returns
|
return the updated checksum. If buf is NULL, this function returns
|
||||||
|
@ -1135,12 +1273,21 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||||
if (adler != original_adler) error();
|
if (adler != original_adler) error();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
|
||||||
|
z_off_t len2));
|
||||||
|
/*
|
||||||
|
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
|
||||||
|
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
|
||||||
|
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
|
||||||
|
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
|
||||||
|
*/
|
||||||
|
|
||||||
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||||
/*
|
/*
|
||||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
Update a running CRC-32 with the bytes buf[0..len-1] and return the
|
||||||
crc. If buf is NULL, this function returns the required initial value
|
updated CRC-32. If buf is NULL, this function returns the required initial
|
||||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
value for the for the crc. Pre- and post-conditioning (one's complement) is
|
||||||
within this function so it shouldn't be done by the application.
|
performed within this function so it shouldn't be done by the application.
|
||||||
Usage example:
|
Usage example:
|
||||||
|
|
||||||
uLong crc = crc32(0L, Z_NULL, 0);
|
uLong crc = crc32(0L, Z_NULL, 0);
|
||||||
|
@ -1151,6 +1298,16 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||||
if (crc != original_crc) error();
|
if (crc != original_crc) error();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Combine two CRC-32 check values into one. For two sequences of bytes,
|
||||||
|
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
|
||||||
|
calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
|
||||||
|
check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
|
||||||
|
len2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* various hacks, don't look :) */
|
/* various hacks, don't look :) */
|
||||||
|
|
||||||
|
@ -1167,7 +1324,7 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||||
int stream_size));
|
int stream_size));
|
||||||
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||||
const char *version, int stream_size));
|
const char *version, int stream_size));
|
||||||
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
|
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
||||||
unsigned char FAR *window,
|
unsigned char FAR *window,
|
||||||
const char *version,
|
const char *version,
|
||||||
int stream_size));
|
int stream_size));
|
||||||
|
@ -1189,7 +1346,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
|
||||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZEXTERN const char * ZEXPORT zError OF((int err));
|
ZEXTERN const char * ZEXPORT zError OF((int));
|
||||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||||
|
|
||||||
|
|
|
@ -1,971 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>
|
|
||||||
zlib general purpose compression library version 1.1.4
|
|
||||||
</title>
|
|
||||||
</head>
|
|
||||||
<body bgcolor="White" text="Black" vlink="Red" alink="Navy" link="Red">
|
|
||||||
<!-- background="zlibbg.gif" -->
|
|
||||||
|
|
||||||
<h1> zlib 1.1.4 Manual </h1>
|
|
||||||
<hr>
|
|
||||||
<a name="Contents"><h2>Contents</h2>
|
|
||||||
<ol type="I">
|
|
||||||
<li> <a href="#Prologue">Prologue</a>
|
|
||||||
<li> <a href="#Introduction">Introduction</a>
|
|
||||||
<li> <a href="#Utility functions">Utility functions</a>
|
|
||||||
<li> <a href="#Basic functions">Basic functions</a>
|
|
||||||
<li> <a href="#Advanced functions">Advanced functions</a>
|
|
||||||
<li> <a href="#Constants">Constants</a>
|
|
||||||
<li> <a href="#struct z_stream_s">struct z_stream_s</a>
|
|
||||||
<li> <a href="#Checksum functions">Checksum functions</a>
|
|
||||||
<li> <a href="#Misc">Misc</a>
|
|
||||||
</ol>
|
|
||||||
<hr>
|
|
||||||
<a name="Prologue"><h2> Prologue </h2>
|
|
||||||
'zlib' general purpose compression library version 1.1.4, March 11th, 2002
|
|
||||||
<p>
|
|
||||||
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
|
|
||||||
<p>
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
<p>
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
<ol>
|
|
||||||
<li> The origin of this software must not be misrepresented ; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
<li> Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
<li> This notice may not be removed or altered from any source distribution.
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
<dt>Jean-loup Gailly
|
|
||||||
<dd><a href="mailto:jloup@gzip.org">jloup@gzip.org</a>
|
|
||||||
<dt>Mark Adler
|
|
||||||
<dd><a href="mailto:madler@alumni.caltech.edu">madler@alumni.caltech.edu</a>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
The data format used by the zlib library is described by RFCs (Request for
|
|
||||||
Comments) 1950 to 1952 in the files
|
|
||||||
<a href="ftp://ds.internic.net/rfc/rfc1950.txt">
|
|
||||||
ftp://ds.internic.net/rfc/rfc1950.txt </a>
|
|
||||||
(zlib format),
|
|
||||||
<a href="ftp://ds.internic.net/rfc/rfc1951.txt">
|
|
||||||
rfc1951.txt </a>
|
|
||||||
(<a href="#deflate">deflate</a> format) and
|
|
||||||
<a href="ftp://ds.internic.net/rfc/rfc1952.txt">
|
|
||||||
rfc1952.txt </a>
|
|
||||||
(gzip format).
|
|
||||||
<p>
|
|
||||||
This manual is converted from zlib.h by
|
|
||||||
<a href="mailto:piaip@csie.ntu.edu.tw"> piaip </a>
|
|
||||||
<p>
|
|
||||||
Visit <a href="http://ftp.cdrom.com/pub/infozip/zlib/">
|
|
||||||
http://ftp.cdrom.com/pub/infozip/zlib/</a>
|
|
||||||
for the official zlib web page.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<a name="Introduction"><h2> Introduction </h2>
|
|
||||||
The 'zlib' compression library provides in-memory compression and
|
|
||||||
decompression functions, including integrity checks of the uncompressed
|
|
||||||
data. This version of the library supports only one compression method
|
|
||||||
(deflation) but other algorithms will be added later and will have the same
|
|
||||||
stream interface.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
Compression can be done in a single step if the buffers are large
|
|
||||||
enough (for example if an input file is mmap'ed), or can be done by
|
|
||||||
repeated calls of the compression function. In the latter case, the
|
|
||||||
application must provide more input and/or consume the output
|
|
||||||
(providing more output space) before each call.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
The library also supports reading and writing files in gzip (.gz) format
|
|
||||||
with an interface similar to that of stdio.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
The library does not install any signal handler. The decoder checks
|
|
||||||
the consistency of the compressed data, so the library should never
|
|
||||||
crash even in case of corrupted input.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<a name="Utility functions"><h2> Utility functions </h2>
|
|
||||||
The following utility functions are implemented on top of the
|
|
||||||
<a href="#Basic functions">basic stream-oriented functions</a>.
|
|
||||||
To simplify the interface, some
|
|
||||||
default options are assumed (compression level and memory usage,
|
|
||||||
standard memory allocation functions). The source code of these
|
|
||||||
utility functions can easily be modified if you need special options.
|
|
||||||
<h3> Function list </h3>
|
|
||||||
<ul>
|
|
||||||
<li> int <a href="#compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
|
|
||||||
<li> int <a href="#compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);
|
|
||||||
<li> int <a href="#uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
|
|
||||||
<li> typedef voidp gzFile;
|
|
||||||
<li> gzFile <a href="#gzopen">gzopen</a> (const char *path, const char *mode);
|
|
||||||
<li> gzFile <a href="#gzdopen">gzdopen</a> (int fd, const char *mode);
|
|
||||||
<li> int <a href="#gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);
|
|
||||||
<li> int <a href="#gzread">gzread</a> (gzFile file, voidp buf, unsigned len);
|
|
||||||
<li> int <a href="#gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);
|
|
||||||
<li> int VA <a href="#gzprintf">gzprintf</a> (gzFile file, const char *format, ...);
|
|
||||||
<li> int <a href="#gzputs">gzputs</a> (gzFile file, const char *s);
|
|
||||||
<li> char * <a href="#gzgets">gzgets</a> (gzFile file, char *buf, int len);
|
|
||||||
<li> int <a href="#gzputc">gzputc</a> (gzFile file, int c);
|
|
||||||
<li> int <a href="#gzgetc">gzgetc</a> (gzFile file);
|
|
||||||
<li> int <a href="#gzflush">gzflush</a> (gzFile file, int flush);
|
|
||||||
<li> z_off_t <a href="#gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);
|
|
||||||
<li> z_off_t <a href="#gztell">gztell</a> (gzFile file);
|
|
||||||
<li> int <a href="#gzrewind">gzrewind</a> (gzFile file);
|
|
||||||
<li> int <a href="#gzeof">gzeof</a> (gzFile file);
|
|
||||||
<li> int <a href="#gzclose">gzclose</a> (gzFile file);
|
|
||||||
<li> const char * <a href="#gzerror">gzerror</a> (gzFile file, int *errnum);
|
|
||||||
</ul>
|
|
||||||
<h3> Function description </h3>
|
|
||||||
<dl>
|
|
||||||
<font color="Blue"><dt> int <a name="compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
|
|
||||||
<dd>
|
|
||||||
Compresses the source buffer into the destination buffer. sourceLen is
|
|
||||||
the byte length of the source buffer. Upon entry, destLen is the total
|
|
||||||
size of the destination buffer, which must be at least 0.1% larger than
|
|
||||||
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
|
||||||
compressed buffer.<p>
|
|
||||||
This function can be used to <a href="#compress">compress</a> a whole file at once if the
|
|
||||||
input file is mmap'ed.<p>
|
|
||||||
<a href="#compress">compress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
|
|
||||||
enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
|
|
||||||
buffer.<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);</font>
|
|
||||||
<dd>
|
|
||||||
Compresses the source buffer into the destination buffer. The level
|
|
||||||
parameter has the same meaning as in <a href="#deflateInit">deflateInit</a>. sourceLen is the byte
|
|
||||||
length of the source buffer. Upon entry, destLen is the total size of the
|
|
||||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
|
||||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#compress2">compress2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
|
|
||||||
memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer,
|
|
||||||
<a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the level parameter is invalid.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
|
|
||||||
<dd>
|
|
||||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
|
||||||
the byte length of the source buffer. Upon entry, destLen is the total
|
|
||||||
size of the destination buffer, which must be large enough to hold the
|
|
||||||
entire uncompressed data. (The size of the uncompressed data must have
|
|
||||||
been saved previously by the compressor and transmitted to the decompressor
|
|
||||||
by some mechanism outside the scope of this compression library.)
|
|
||||||
Upon exit, destLen is the actual size of the compressed buffer. <p>
|
|
||||||
This function can be used to decompress a whole file at once if the
|
|
||||||
input file is mmap'ed.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#uncompress">uncompress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
|
|
||||||
enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
|
|
||||||
buffer, or <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was corrupted.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<dt> typedef voidp gzFile;
|
|
||||||
<dd> <p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> gzFile <a name="gzopen">gzopen</a> (const char *path, const char *mode);</font>
|
|
||||||
<dd>
|
|
||||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
|
||||||
is as in fopen ("rb" or "wb") but can also include a compression level
|
|
||||||
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
|
|
||||||
Huffman only compression as in "wb1h". (See the description
|
|
||||||
of <a href="#deflateInit2">deflateInit2</a> for more information about the strategy parameter.)
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#gzopen">gzopen</a> can be used to read a file which is not in gzip format ; in this
|
|
||||||
case <a href="#gzread">gzread</a> will directly read from the file without decompression.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#gzopen">gzopen</a> returns NULL if the file could not be opened or if there was
|
|
||||||
insufficient memory to allocate the (de)compression <a href="#state">state</a> ; errno
|
|
||||||
can be checked to distinguish the two cases (if errno is zero, the
|
|
||||||
zlib error is <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a>).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> gzFile <a name="gzdopen">gzdopen</a> (int fd, const char *mode);</font>
|
|
||||||
<dd>
|
|
||||||
<a href="#gzdopen">gzdopen</a>() associates a gzFile with the file descriptor fd. File
|
|
||||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
|
||||||
fileno (in the file has been previously opened with fopen).
|
|
||||||
The mode parameter is as in <a href="#gzopen">gzopen</a>.
|
|
||||||
<p>
|
|
||||||
The next call of <a href="#gzclose">gzclose</a> on the returned gzFile will also close the
|
|
||||||
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
|
|
||||||
descriptor fd. If you want to keep fd open, use <a href="#gzdopen">gzdopen</a>(dup(fd), mode).
|
|
||||||
<p>
|
|
||||||
<a href="#gzdopen">gzdopen</a> returns NULL if there was insufficient memory to allocate
|
|
||||||
the (de)compression <a href="#state">state</a>.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);</font>
|
|
||||||
<dd>
|
|
||||||
Dynamically update the compression level or strategy. See the description
|
|
||||||
of <a href="#deflateInit2">deflateInit2</a> for the meaning of these parameters.
|
|
||||||
<p>
|
|
||||||
<a href="#gzsetparams">gzsetparams</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the file was not
|
|
||||||
opened for writing.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzread">gzread</a> (gzFile file, voidp buf, unsigned len);</font>
|
|
||||||
<dd>
|
|
||||||
Reads the given number of uncompressed bytes from the compressed file.
|
|
||||||
If the input file was not in gzip format, <a href="#gzread">gzread</a> copies the given number
|
|
||||||
of bytes into the buffer.
|
|
||||||
<p>
|
|
||||||
<a href="#gzread">gzread</a> returns the number of uncompressed bytes actually read (0 for
|
|
||||||
end of file, -1 for error).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);</font>
|
|
||||||
<dd>
|
|
||||||
Writes the given number of uncompressed bytes into the compressed file.
|
|
||||||
<a href="#gzwrite">gzwrite</a> returns the number of uncompressed bytes actually written
|
|
||||||
(0 in case of error).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int VA <a name="gzprintf">gzprintf</a> (gzFile file, const char *format, ...);</font>
|
|
||||||
<dd>
|
|
||||||
Converts, formats, and writes the args to the compressed file under
|
|
||||||
control of the format string, as in fprintf. <a href="#gzprintf">gzprintf</a> returns the number of
|
|
||||||
uncompressed bytes actually written (0 in case of error).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzputs">gzputs</a> (gzFile file, const char *s);</font>
|
|
||||||
<dd>
|
|
||||||
Writes the given null-terminated string to the compressed file, excluding
|
|
||||||
the terminating null character.
|
|
||||||
<p>
|
|
||||||
<a href="#gzputs">gzputs</a> returns the number of characters written, or -1 in case of error.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> char * <a name="gzgets">gzgets</a> (gzFile file, char *buf, int len);</font>
|
|
||||||
<dd>
|
|
||||||
Reads bytes from the compressed file until len-1 characters are read, or
|
|
||||||
a newline character is read and transferred to buf, or an end-of-file
|
|
||||||
condition is encountered. The string is then terminated with a null
|
|
||||||
character.
|
|
||||||
<p>
|
|
||||||
<a href="#gzgets">gzgets</a> returns buf, or <a href="#Z_NULL">Z_NULL</a> in case of error.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzputc">gzputc</a> (gzFile file, int c);</font>
|
|
||||||
<dd>
|
|
||||||
Writes c, converted to an unsigned char, into the compressed file.
|
|
||||||
<a href="#gzputc">gzputc</a> returns the value that was written, or -1 in case of error.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzgetc">gzgetc</a> (gzFile file);</font>
|
|
||||||
<dd>
|
|
||||||
Reads one byte from the compressed file. <a href="#gzgetc">gzgetc</a> returns this byte
|
|
||||||
or -1 in case of end of file or error.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzflush">gzflush</a> (gzFile file, int flush);</font>
|
|
||||||
<dd>
|
|
||||||
Flushes all pending output into the compressed file. The parameter
|
|
||||||
flush is as in the <a href="#deflate">deflate</a>() function. The return value is the zlib
|
|
||||||
error number (see function <a href="#gzerror">gzerror</a> below). <a href="#gzflush">gzflush</a> returns <a href="#Z_OK">Z_OK</a> if
|
|
||||||
the flush parameter is <a href="#Z_FINISH">Z_FINISH</a> and all output could be flushed.
|
|
||||||
<p>
|
|
||||||
<a href="#gzflush">gzflush</a> should be called only when strictly necessary because it can
|
|
||||||
degrade compression.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> z_off_t <a name="gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);</font>
|
|
||||||
<dd>
|
|
||||||
Sets the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
|
|
||||||
given compressed file. The offset represents a number of bytes in the
|
|
||||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
|
||||||
the value SEEK_END is not supported.
|
|
||||||
<p>
|
|
||||||
If the file is opened for reading, this function is emulated but can be
|
|
||||||
extremely slow. If the file is opened for writing, only forward seeks are
|
|
||||||
supported ; <a href="#gzseek">gzseek</a> then compresses a sequence of zeroes up to the new
|
|
||||||
starting position.
|
|
||||||
<p>
|
|
||||||
<a href="#gzseek">gzseek</a> returns the resulting offset location as measured in bytes from
|
|
||||||
the beginning of the uncompressed stream, or -1 in case of error, in
|
|
||||||
particular if the file is opened for writing and the new starting position
|
|
||||||
would be before the current position.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzrewind">gzrewind</a> (gzFile file);</font>
|
|
||||||
<dd>
|
|
||||||
Rewinds the given file. This function is supported only for reading.
|
|
||||||
<p>
|
|
||||||
<a href="#gzrewind">gzrewind</a>(file) is equivalent to (int)<a href="#gzseek">gzseek</a>(file, 0L, SEEK_SET)
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> z_off_t <a name="gztell">gztell</a> (gzFile file);</font>
|
|
||||||
<dd>
|
|
||||||
Returns the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
|
|
||||||
given compressed file. This position represents a number of bytes in the
|
|
||||||
uncompressed data stream.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#gztell">gztell</a>(file) is equivalent to <a href="#gzseek">gzseek</a>(file, 0L, SEEK_CUR)
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzeof">gzeof</a> (gzFile file);</font>
|
|
||||||
<dd>
|
|
||||||
Returns 1 when EOF has previously been detected reading the given
|
|
||||||
input stream, otherwise zero.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="gzclose">gzclose</a> (gzFile file);</font>
|
|
||||||
<dd>
|
|
||||||
Flushes all pending output if necessary, closes the compressed file
|
|
||||||
and deallocates all the (de)compression <a href="#state">state</a>. The return value is the zlib
|
|
||||||
error number (see function <a href="#gzerror">gzerror</a> below).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> const char * <a name="gzerror">gzerror</a> (gzFile file, int *errnum);</font>
|
|
||||||
<dd>
|
|
||||||
Returns the error message for the last error which occurred on the
|
|
||||||
given compressed file. errnum is set to zlib error number. If an
|
|
||||||
error occurred in the file system and not in the compression library,
|
|
||||||
errnum is set to <a href="#Z_ERRNO">Z_ERRNO</a> and the application may consult errno
|
|
||||||
to get the exact error code.
|
|
||||||
<p>
|
|
||||||
</dl>
|
|
||||||
<hr>
|
|
||||||
<a name="Basic functions"><h2> Basic functions </h2>
|
|
||||||
<h3> Function list </h3>
|
|
||||||
<ul>
|
|
||||||
<li> const char * <a href="#zlibVersion">zlibVersion</a> (void);
|
|
||||||
<li> int <a href="#deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);
|
|
||||||
<li> int <a href="#deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
|
|
||||||
<li> int <a href="#deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
|
|
||||||
<li> int <a href="#inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);
|
|
||||||
<li> int <a href="#inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
|
|
||||||
<li> int <a href="#inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3> Function description </h3>
|
|
||||||
<dl>
|
|
||||||
<font color="Blue"><dt> const char * <a name="zlibVersion">zlibVersion</a> (void);</font>
|
|
||||||
<dd> The application can compare <a href="#zlibVersion">zlibVersion</a> and ZLIB_VERSION for consistency.
|
|
||||||
If the first character differs, the library code actually used is
|
|
||||||
not compatible with the zlib.h header file used by the application.
|
|
||||||
This check is automatically made by <a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a>.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);</font>
|
|
||||||
<dd>
|
|
||||||
Initializes the internal stream <a href="#state">state</a> for compression. The fields
|
|
||||||
<a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by the caller.
|
|
||||||
If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#deflateInit">deflateInit</a> updates them to
|
|
||||||
use default allocation functions.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
The compression level must be <a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a>, or between 0 and 9:
|
|
||||||
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
|
||||||
all (the input data is simply copied a block at a time).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> requests a default compromise between speed and
|
|
||||||
compression (currently equivalent to level 6).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#deflateInit">deflateInit</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
|
|
||||||
enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if level is not a valid compression level,
|
|
||||||
<a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version (<a href="#zlib_version">zlib_version</a>) is incompatible
|
|
||||||
with the version assumed by the caller (ZLIB_VERSION).
|
|
||||||
<a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit">deflateInit</a> does not
|
|
||||||
perform any compression: this will be done by <a href="#deflate">deflate</a>().
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
|
|
||||||
<dd>
|
|
||||||
<a href="#deflate">deflate</a> compresses as much data as possible, and stops when the input
|
|
||||||
buffer becomes empty or the output buffer becomes full. It may introduce some
|
|
||||||
output latency (reading input without producing any output) except when
|
|
||||||
forced to flush.<p>
|
|
||||||
|
|
||||||
The detailed semantics are as follows. <a href="#deflate">deflate</a> performs one or both of the
|
|
||||||
following actions:
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li> Compress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a>
|
|
||||||
accordingly. If not all input can be processed (because there is not
|
|
||||||
enough room in the output buffer), <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> are updated and
|
|
||||||
processing will resume at this point for the next call of <a href="#deflate">deflate</a>().
|
|
||||||
|
|
||||||
<li>
|
|
||||||
Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a>
|
|
||||||
accordingly. This action is forced if the parameter flush is non zero.
|
|
||||||
Forcing flush frequently degrades the compression ratio, so this parameter
|
|
||||||
should be set only when necessary (in interactive applications).
|
|
||||||
Some output may be provided even if flush is not set.
|
|
||||||
</ul> <p>
|
|
||||||
|
|
||||||
Before the call of <a href="#deflate">deflate</a>(), the application should ensure that at least
|
|
||||||
one of the actions is possible, by providing more input and/or consuming
|
|
||||||
more output, and updating <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> accordingly ; <a href="#avail_out">avail_out</a>
|
|
||||||
should never be zero before the call. The application can consume the
|
|
||||||
compressed output when it wants, for example when the output buffer is full
|
|
||||||
(<a href="#avail_out">avail_out</a> == 0), or after each call of <a href="#deflate">deflate</a>(). If <a href="#deflate">deflate</a> returns <a href="#Z_OK">Z_OK</a>
|
|
||||||
and with zero <a href="#avail_out">avail_out</a>, it must be called again after making room in the
|
|
||||||
output buffer because there might be more output pending.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, all pending output is
|
|
||||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
|
||||||
that the decompressor can get all input data available so far. (In particular
|
|
||||||
<a href="#avail_in">avail_in</a> is zero after the call if enough output space has been provided
|
|
||||||
before the call.) Flushing may degrade compression for some compression
|
|
||||||
algorithms and so it should be used only when necessary.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
If flush is set to <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>, all output is flushed as with
|
|
||||||
<a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, and the compression <a href="#state">state</a> is reset so that decompression can
|
|
||||||
restart from this point if previous compressed data has been damaged or if
|
|
||||||
random access is desired. Using <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a> too often can seriously degrade
|
|
||||||
the compression.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
If <a href="#deflate">deflate</a> returns with <a href="#avail_out">avail_out</a> == 0, this function must be called again
|
|
||||||
with the same value of the flush parameter and more output space (updated
|
|
||||||
<a href="#avail_out">avail_out</a>), until the flush is complete (<a href="#deflate">deflate</a> returns with non-zero
|
|
||||||
<a href="#avail_out">avail_out</a>).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
If the parameter flush is set to <a href="#Z_FINISH">Z_FINISH</a>, pending input is processed,
|
|
||||||
pending output is flushed and <a href="#deflate">deflate</a> returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> if there
|
|
||||||
was enough output space ; if <a href="#deflate">deflate</a> returns with <a href="#Z_OK">Z_OK</a>, this function must be
|
|
||||||
called again with <a href="#Z_FINISH">Z_FINISH</a> and more output space (updated <a href="#avail_out">avail_out</a>) but no
|
|
||||||
more input data, until it returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error. After
|
|
||||||
<a href="#deflate">deflate</a> has returned <a href="#Z_STREAM_END">Z_STREAM_END</a>, the only possible operations on the
|
|
||||||
stream are <a href="#deflateReset">deflateReset</a> or <a href="#deflateEnd">deflateEnd</a>.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#Z_FINISH">Z_FINISH</a> can be used immediately after <a href="#deflateInit">deflateInit</a> if all the compression
|
|
||||||
is to be done in a single step. In this case, <a href="#avail_out">avail_out</a> must be at least
|
|
||||||
0.1% larger than <a href="#avail_in">avail_in</a> plus 12 bytes. If <a href="#deflate">deflate</a> does not return
|
|
||||||
<a href="#Z_STREAM_END">Z_STREAM_END</a>, then it must be called again as described above.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#deflate">deflate</a>() sets strm-> <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all input read
|
|
||||||
so far (that is, <a href="#total_in">total_in</a> bytes).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#deflate">deflate</a>() may update <a href="#data_type">data_type</a> if it can make a good guess about
|
|
||||||
the input data type (<a href="#Z_ASCII">Z_ASCII</a> or <a href="#Z_BINARY">Z_BINARY</a>). In doubt, the data is considered
|
|
||||||
binary. This field is only for information purposes and does not affect
|
|
||||||
the compression algorithm in any manner.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#deflate">deflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input
|
|
||||||
processed or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if all input has been
|
|
||||||
consumed and all output has been produced (only when flush is set to
|
|
||||||
<a href="#Z_FINISH">Z_FINISH</a>), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a> was inconsistent (for example
|
|
||||||
if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible
|
|
||||||
(for example <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> was zero).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
|
|
||||||
<dd>
|
|
||||||
All dynamically allocated data structures for this stream are freed.
|
|
||||||
This function discards any unprocessed input and does not flush any
|
|
||||||
pending output.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#deflateEnd">deflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the
|
|
||||||
stream <a href="#state">state</a> was inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the stream was freed
|
|
||||||
prematurely (some input or output was discarded). In the error case,
|
|
||||||
<a href="#msg">msg</a> may be set but then points to a static string (which must not be
|
|
||||||
deallocated).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
|
|
||||||
<dd>
|
|
||||||
Initializes the internal stream <a href="#state">state</a> for decompression. The fields
|
|
||||||
<a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by
|
|
||||||
the caller. If <a href="#next_in">next_in</a> is not <a href="#Z_NULL">Z_NULL</a> and <a href="#avail_in">avail_in</a> is large enough (the exact
|
|
||||||
value depends on the compression method), <a href="#inflateInit">inflateInit</a> determines the
|
|
||||||
compression method from the zlib header and allocates all data structures
|
|
||||||
accordingly ; otherwise the allocation will be deferred to the first call of
|
|
||||||
<a href="#inflate">inflate</a>. If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#inflateInit">inflateInit</a> updates them to
|
|
||||||
use default allocation functions.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#inflateInit">inflateInit</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
|
|
||||||
memory, <a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version is incompatible with the
|
|
||||||
version assumed by the caller. <a href="#msg">msg</a> is set to null if there is no error
|
|
||||||
message. <a href="#inflateInit">inflateInit</a> does not perform any decompression apart from reading
|
|
||||||
the zlib header if present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and
|
|
||||||
<a href="#avail_in">avail_in</a> may be modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
|
|
||||||
<dd>
|
|
||||||
<a href="#inflate">inflate</a> decompresses as much data as possible, and stops when the input
|
|
||||||
buffer becomes empty or the output buffer becomes full. It may some
|
|
||||||
introduce some output latency (reading input without producing any output)
|
|
||||||
except when forced to flush.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
The detailed semantics are as follows. <a href="#inflate">inflate</a> performs one or both of the
|
|
||||||
following actions:
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li> Decompress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a>
|
|
||||||
accordingly. If not all input can be processed (because there is not
|
|
||||||
enough room in the output buffer), <a href="#next_in">next_in</a> is updated and processing
|
|
||||||
will resume at this point for the next call of <a href="#inflate">inflate</a>().
|
|
||||||
|
|
||||||
<li> Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and
|
|
||||||
<a href="#avail_out">avail_out</a> accordingly. <a href="#inflate">inflate</a>() provides as much output as possible,
|
|
||||||
until there is no more input data or no more space in the output buffer
|
|
||||||
(see below about the flush parameter).
|
|
||||||
</ul> <p>
|
|
||||||
|
|
||||||
Before the call of <a href="#inflate">inflate</a>(), the application should ensure that at least
|
|
||||||
one of the actions is possible, by providing more input and/or consuming
|
|
||||||
more output, and updating the next_* and avail_* values accordingly.
|
|
||||||
The application can consume the uncompressed output when it wants, for
|
|
||||||
example when the output buffer is full (<a href="#avail_out">avail_out</a> == 0), or after each
|
|
||||||
call of <a href="#inflate">inflate</a>(). If <a href="#inflate">inflate</a> returns <a href="#Z_OK">Z_OK</a> and with zero <a href="#avail_out">avail_out</a>, it
|
|
||||||
must be called again after making room in the output buffer because there
|
|
||||||
might be more output pending.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, <a href="#inflate">inflate</a> flushes as much
|
|
||||||
output as possible to the output buffer. The flushing behavior of <a href="#inflate">inflate</a> is
|
|
||||||
not specified for values of the flush parameter other than <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>
|
|
||||||
and <a href="#Z_FINISH">Z_FINISH</a>, but the current implementation actually flushes as much output
|
|
||||||
as possible anyway.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#inflate">inflate</a>() should normally be called until it returns <a href="#Z_STREAM_END">Z_STREAM_END</a> or an
|
|
||||||
error. However if all decompression is to be performed in a single step
|
|
||||||
(a single call of <a href="#inflate">inflate</a>), the parameter flush should be set to
|
|
||||||
<a href="#Z_FINISH">Z_FINISH</a>. In this case all pending input is processed and all pending
|
|
||||||
output is flushed ; <a href="#avail_out">avail_out</a> must be large enough to hold all the
|
|
||||||
uncompressed data. (The size of the uncompressed data may have been saved
|
|
||||||
by the compressor for this purpose.) The next operation on this stream must
|
|
||||||
be <a href="#inflateEnd">inflateEnd</a> to deallocate the decompression <a href="#state">state</a>. The use of <a href="#Z_FINISH">Z_FINISH</a>
|
|
||||||
is never required, but can be used to inform <a href="#inflate">inflate</a> that a faster routine
|
|
||||||
may be used for the single <a href="#inflate">inflate</a>() call.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
If a preset dictionary is needed at this point (see <a href="#inflateSetDictionary">inflateSetDictionary</a>
|
|
||||||
below), <a href="#inflate">inflate</a> sets strm-<a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of the
|
|
||||||
dictionary chosen by the compressor and returns <a href="#Z_NEED_DICT">Z_NEED_DICT</a> ; otherwise
|
|
||||||
it sets strm-> <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all output produced
|
|
||||||
so far (that is, <a href="#total_out">total_out</a> bytes) and returns <a href="#Z_OK">Z_OK</a>, <a href="#Z_STREAM_END">Z_STREAM_END</a> or
|
|
||||||
an error code as described below. At the end of the stream, <a href="#inflate">inflate</a>()
|
|
||||||
checks that its computed <a href="#adler32">adler32</a> checksum is equal to that saved by the
|
|
||||||
compressor and returns <a href="#Z_STREAM_END">Z_STREAM_END</a> only if the checksum is correct.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#inflate">inflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input processed
|
|
||||||
or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if the end of the compressed data has
|
|
||||||
been reached and all uncompressed output has been produced, <a href="#Z_NEED_DICT">Z_NEED_DICT</a> if a
|
|
||||||
preset dictionary is needed at this point, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was
|
|
||||||
corrupted (input stream not conforming to the zlib format or incorrect
|
|
||||||
<a href="#adler32">adler32</a> checksum), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent
|
|
||||||
(for example if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
|
|
||||||
enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible or if there was not
|
|
||||||
enough room in the output buffer when <a href="#Z_FINISH">Z_FINISH</a> is used. In the <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a>
|
|
||||||
case, the application may then call <a href="#inflateSync">inflateSync</a> to look for a good
|
|
||||||
compression block.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
|
|
||||||
<dd>
|
|
||||||
All dynamically allocated data structures for this stream are freed.
|
|
||||||
This function discards any unprocessed input and does not flush any
|
|
||||||
pending output.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#inflateEnd">inflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a>
|
|
||||||
was inconsistent. In the error case, <a href="#msg">msg</a> may be set but then points to a
|
|
||||||
static string (which must not be deallocated).
|
|
||||||
</dl>
|
|
||||||
<hr>
|
|
||||||
<a name="Advanced functions"><h2> Advanced functions </h2>
|
|
||||||
The following functions are needed only in some special applications.
|
|
||||||
<h3> Function list </h3>
|
|
||||||
<ul>
|
|
||||||
<li> int <a href="#deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm,
|
|
||||||
<li> int <a href="#deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
|
|
||||||
<li> int <a href="#deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);
|
|
||||||
<li> int <a href="#deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
|
|
||||||
<li> int <a href="#deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);
|
|
||||||
<li> int <a href="#inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);
|
|
||||||
<li> int <a href="#inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
|
|
||||||
<li> int <a href="#inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);
|
|
||||||
<li> int <a href="#inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
<h3> Function description </h3>
|
|
||||||
<dl>
|
|
||||||
<font color="Blue"><dt> int <a name="deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int method, int windowBits, int memLevel, int strategy);</font>
|
|
||||||
|
|
||||||
<dd> This is another version of <a href="#deflateInit">deflateInit</a> with more compression options. The
|
|
||||||
fields <a href="#next_in">next_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by
|
|
||||||
the caller.<p>
|
|
||||||
|
|
||||||
The method parameter is the compression method. It must be <a href="#Z_DEFLATED">Z_DEFLATED</a> in
|
|
||||||
this version of the library.<p>
|
|
||||||
|
|
||||||
The windowBits parameter is the base two logarithm of the window size
|
|
||||||
(the size of the history buffer). It should be in the range 8..15 for this
|
|
||||||
version of the library. Larger values of this parameter result in better
|
|
||||||
compression at the expense of memory usage. The default value is 15 if
|
|
||||||
<a href="#deflateInit">deflateInit</a> is used instead.<p>
|
|
||||||
|
|
||||||
The memLevel parameter specifies how much memory should be allocated
|
|
||||||
for the internal compression <a href="#state">state</a>. memLevel=1 uses minimum memory but
|
|
||||||
is slow and reduces compression ratio ; memLevel=9 uses maximum memory
|
|
||||||
for optimal speed. The default value is 8. See zconf.h for total memory
|
|
||||||
usage as a function of windowBits and memLevel.<p>
|
|
||||||
|
|
||||||
The strategy parameter is used to tune the compression algorithm. Use the
|
|
||||||
value <a href="#Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> for normal data, <a href="#Z_FILTERED">Z_FILTERED</a> for data produced by a
|
|
||||||
filter (or predictor), or <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> to force Huffman encoding only (no
|
|
||||||
string match). Filtered data consists mostly of small values with a
|
|
||||||
somewhat random distribution. In this case, the compression algorithm is
|
|
||||||
tuned to <a href="#compress">compress</a> them better. The effect of <a href="#Z_FILTERED">Z_FILTERED</a> is to force more
|
|
||||||
Huffman coding and less string matching ; it is somewhat intermediate
|
|
||||||
between Z_DEFAULT and <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a>. The strategy parameter only affects
|
|
||||||
the compression ratio but not the correctness of the compressed output even
|
|
||||||
if it is not set appropriately.<p>
|
|
||||||
|
|
||||||
<a href="#deflateInit2">deflateInit2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
|
|
||||||
memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as an invalid
|
|
||||||
method). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit2">deflateInit2</a> does
|
|
||||||
not perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
|
|
||||||
<dd>
|
|
||||||
Initializes the compression dictionary from the given byte sequence
|
|
||||||
without producing any compressed output. This function must be called
|
|
||||||
immediately after <a href="#deflateInit">deflateInit</a>, <a href="#deflateInit2">deflateInit2</a> or <a href="#deflateReset">deflateReset</a>, before any
|
|
||||||
call of <a href="#deflate">deflate</a>. The compressor and decompressor must use exactly the same
|
|
||||||
dictionary (see <a href="#inflateSetDictionary">inflateSetDictionary</a>).<p>
|
|
||||||
|
|
||||||
The dictionary should consist of strings (byte sequences) that are likely
|
|
||||||
to be encountered later in the data to be compressed, with the most commonly
|
|
||||||
used strings preferably put towards the end of the dictionary. Using a
|
|
||||||
dictionary is most useful when the data to be compressed is short and can be
|
|
||||||
predicted with good accuracy ; the data can then be compressed better than
|
|
||||||
with the default empty dictionary.<p>
|
|
||||||
|
|
||||||
Depending on the size of the compression data structures selected by
|
|
||||||
<a href="#deflateInit">deflateInit</a> or <a href="#deflateInit2">deflateInit2</a>, a part of the dictionary may in effect be
|
|
||||||
discarded, for example if the dictionary is larger than the window size in
|
|
||||||
<a href="#deflate">deflate</a> or deflate2. Thus the strings most likely to be useful should be
|
|
||||||
put at the end of the dictionary, not at the front.<p>
|
|
||||||
|
|
||||||
Upon return of this function, strm-> <a href="#adler">adler</a> is set to the Adler32 value
|
|
||||||
of the dictionary ; the decompressor may later use this value to determine
|
|
||||||
which dictionary has been used by the compressor. (The Adler32 value
|
|
||||||
applies to the whole dictionary even if only a subset of the dictionary is
|
|
||||||
actually used by the compressor.)<p>
|
|
||||||
|
|
||||||
<a href="#deflateSetDictionary">deflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a
|
|
||||||
parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
|
|
||||||
inconsistent (for example if <a href="#deflate">deflate</a> has already been called for this stream
|
|
||||||
or if the compression method is bsort). <a href="#deflateSetDictionary">deflateSetDictionary</a> does not
|
|
||||||
perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);</font>
|
|
||||||
<dd>
|
|
||||||
Sets the destination stream as a complete copy of the source stream.<p>
|
|
||||||
|
|
||||||
This function can be useful when several compression strategies will be
|
|
||||||
tried, for example when there are several ways of pre-processing the input
|
|
||||||
data with a filter. The streams that will be discarded should then be freed
|
|
||||||
by calling <a href="#deflateEnd">deflateEnd</a>. Note that <a href="#deflateCopy">deflateCopy</a> duplicates the internal
|
|
||||||
compression <a href="#state">state</a> which can be quite large, so this strategy is slow and
|
|
||||||
can consume lots of memory.<p>
|
|
||||||
|
|
||||||
<a href="#deflateCopy">deflateCopy</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
|
|
||||||
enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent
|
|
||||||
(such as <a href="#zalloc">zalloc</a> being NULL). <a href="#msg">msg</a> is left unchanged in both source and
|
|
||||||
destination.<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
|
|
||||||
<dd> This function is equivalent to <a href="#deflateEnd">deflateEnd</a> followed by <a href="#deflateInit">deflateInit</a>,
|
|
||||||
but does not free and reallocate all the internal compression <a href="#state">state</a>.
|
|
||||||
The stream will keep the same compression level and any other attributes
|
|
||||||
that may have been set by <a href="#deflateInit2">deflateInit2</a>.<p>
|
|
||||||
|
|
||||||
<a href="#deflateReset">deflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
|
|
||||||
stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);</font>
|
|
||||||
<dd>
|
|
||||||
Dynamically update the compression level and compression strategy. The
|
|
||||||
interpretation of level and strategy is as in <a href="#deflateInit2">deflateInit2</a>. This can be
|
|
||||||
used to switch between compression and straight copy of the input data, or
|
|
||||||
to switch to a different kind of input data requiring a different
|
|
||||||
strategy. If the compression level is changed, the input available so far
|
|
||||||
is compressed with the old level (and may be flushed); the new level will
|
|
||||||
take effect only at the next call of <a href="#deflate">deflate</a>().<p>
|
|
||||||
|
|
||||||
Before the call of <a href="#deflateParams">deflateParams</a>, the stream <a href="#state">state</a> must be set as for
|
|
||||||
a call of <a href="#deflate">deflate</a>(), since the currently available input may have to
|
|
||||||
be compressed and flushed. In particular, strm-> <a href="#avail_out">avail_out</a> must be
|
|
||||||
non-zero.<p>
|
|
||||||
|
|
||||||
<a href="#deflateParams">deflateParams</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
|
|
||||||
stream <a href="#state">state</a> was inconsistent or if a parameter was invalid, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
|
|
||||||
if strm->avail_out was zero.<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);</font>
|
|
||||||
|
|
||||||
<dd> This is another version of <a href="#inflateInit">inflateInit</a> with an extra parameter. The
|
|
||||||
fields <a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized
|
|
||||||
before by the caller.<p>
|
|
||||||
|
|
||||||
The windowBits parameter is the base two logarithm of the maximum window
|
|
||||||
size (the size of the history buffer). It should be in the range 8..15 for
|
|
||||||
this version of the library. The default value is 15 if <a href="#inflateInit">inflateInit</a> is used
|
|
||||||
instead. If a compressed stream with a larger window size is given as
|
|
||||||
input, <a href="#inflate">inflate</a>() will return with the error code <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> instead of
|
|
||||||
trying to allocate a larger window.<p>
|
|
||||||
|
|
||||||
<a href="#inflateInit2">inflateInit2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
|
|
||||||
memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as a negative
|
|
||||||
memLevel). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#inflateInit2">inflateInit2</a>
|
|
||||||
does not perform any decompression apart from reading the zlib header if
|
|
||||||
present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> may be
|
|
||||||
modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
|
|
||||||
<dd>
|
|
||||||
Initializes the decompression dictionary from the given uncompressed byte
|
|
||||||
sequence. This function must be called immediately after a call of <a href="#inflate">inflate</a>
|
|
||||||
if this call returned <a href="#Z_NEED_DICT">Z_NEED_DICT</a>. The dictionary chosen by the compressor
|
|
||||||
can be determined from the Adler32 value returned by this call of
|
|
||||||
<a href="#inflate">inflate</a>. The compressor and decompressor must use exactly the same
|
|
||||||
dictionary (see <a href="#deflateSetDictionary">deflateSetDictionary</a>).<p>
|
|
||||||
|
|
||||||
<a href="#inflateSetDictionary">inflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a
|
|
||||||
parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
|
|
||||||
inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the given dictionary doesn't match the
|
|
||||||
expected one (incorrect Adler32 value). <a href="#inflateSetDictionary">inflateSetDictionary</a> does not
|
|
||||||
perform any decompression: this will be done by subsequent calls of
|
|
||||||
<a href="#inflate">inflate</a>().<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
|
|
||||||
|
|
||||||
<dd> Skips invalid compressed data until a full flush point (see above the
|
|
||||||
description of <a href="#deflate">deflate</a> with <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>) can be found, or until all
|
|
||||||
available input is skipped. No output is provided.<p>
|
|
||||||
|
|
||||||
<a href="#inflateSync">inflateSync</a> returns <a href="#Z_OK">Z_OK</a> if a full flush point has been found, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
|
|
||||||
if no more input was provided, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if no flush point has been found,
|
|
||||||
or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent. In the success
|
|
||||||
case, the application may save the current current value of <a href="#total_in">total_in</a> which
|
|
||||||
indicates where valid compressed data was found. In the error case, the
|
|
||||||
application may repeatedly call <a href="#inflateSync">inflateSync</a>, providing more input each time,
|
|
||||||
until success or end of the input data.<p>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> int <a name="inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
|
|
||||||
<dd>
|
|
||||||
This function is equivalent to <a href="#inflateEnd">inflateEnd</a> followed by <a href="#inflateInit">inflateInit</a>,
|
|
||||||
but does not free and reallocate all the internal decompression <a href="#state">state</a>.
|
|
||||||
The stream will keep attributes that may have been set by <a href="#inflateInit2">inflateInit2</a>.
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<a href="#inflateReset">inflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
|
|
||||||
stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).
|
|
||||||
<p>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<a name="Checksum functions"><h2> Checksum functions </h2>
|
|
||||||
These functions are not related to compression but are exported
|
|
||||||
anyway because they might be useful in applications using the
|
|
||||||
compression library.
|
|
||||||
<h3> Function list </h3>
|
|
||||||
<ul>
|
|
||||||
<li> uLong <a href="#adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);
|
|
||||||
<li> uLong <a href="#crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);
|
|
||||||
</ul>
|
|
||||||
<h3> Function description </h3>
|
|
||||||
<dl>
|
|
||||||
<font color="Blue"><dt> uLong <a name="adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);</font>
|
|
||||||
<dd>
|
|
||||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
|
||||||
return the updated checksum. If buf is NULL, this function returns
|
|
||||||
the required initial value for the checksum.
|
|
||||||
<p>
|
|
||||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
|
||||||
much faster. Usage example:
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
uLong <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
|
|
||||||
|
|
||||||
while (read_buffer(buffer, length) != EOF) {
|
|
||||||
<a href="#adler">adler</a> = <a href="#adler32">adler32</a>(<a href="#adler">adler</a>, buffer, length);
|
|
||||||
}
|
|
||||||
if (<a href="#adler">adler</a> != original_adler) error();
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<font color="Blue"><dt> uLong <a name="crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);</font>
|
|
||||||
<dd>
|
|
||||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
|
||||||
crc. If buf is NULL, this function returns the required initial value
|
|
||||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
|
||||||
within this function so it shouldn't be done by the application.
|
|
||||||
Usage example:
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
uLong crc = <a href="#crc32">crc32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
|
|
||||||
|
|
||||||
while (read_buffer(buffer, length) != EOF) {
|
|
||||||
crc = <a href="#crc32">crc32</a>(crc, buffer, length);
|
|
||||||
}
|
|
||||||
if (crc != original_crc) error();
|
|
||||||
</pre>
|
|
||||||
</dl>
|
|
||||||
<hr>
|
|
||||||
<a name="struct z_stream_s"><h2> struct z_stream_s </h2>
|
|
||||||
<font color="Blue">
|
|
||||||
<a name="z_stream_s">
|
|
||||||
<pre>
|
|
||||||
typedef struct z_stream_s {
|
|
||||||
Bytef *<a name="next_in">next_in</a>; /* next input byte */
|
|
||||||
uInt <a name="avail_in">avail_in</a>; /* number of bytes available at <a href="#next_in">next_in</a> */
|
|
||||||
uLong <a name="total_in">total_in</a>; /* total nb of input bytes read so far */
|
|
||||||
|
|
||||||
Bytef *<a name="next_out">next_out</a>; /* next output byte should be put there */
|
|
||||||
uInt <a name="avail_out">avail_out</a>; /* remaining free space at <a href="#next_out">next_out</a> */
|
|
||||||
uLong <a name="total_out">total_out</a>; /* total nb of bytes output so far */
|
|
||||||
|
|
||||||
char *<a name="msg">msg</a>; /* last error message, NULL if no error */
|
|
||||||
struct internal_state FAR *<a name="state">state</a>; /* not visible by applications */
|
|
||||||
|
|
||||||
alloc_func <a name="zalloc">zalloc</a>; /* used to allocate the internal <a href="#state">state</a> */
|
|
||||||
free_func <a name="zfree">zfree</a>; /* used to free the internal <a href="#state">state</a> */
|
|
||||||
voidpf <a name="opaque">opaque</a>; /* private data object passed to <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> */
|
|
||||||
|
|
||||||
int <a name="data_type">data_type</a>; /* best guess about the data type: ascii or binary */
|
|
||||||
uLong <a name="adler">adler</a>; /* <a href="#adler32">adler32</a> value of the uncompressed data */
|
|
||||||
uLong <a name="reserved">reserved</a>; /* <a href="#reserved">reserved</a> for future use */
|
|
||||||
} <a href="#z_stream_s">z_stream</a> ;
|
|
||||||
|
|
||||||
typedef <a href="#z_stream_s">z_stream</a> FAR * <a name="z_streamp">z_streamp</a>; ÿ
|
|
||||||
</pre>
|
|
||||||
</font>
|
|
||||||
The application must update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> when <a href="#avail_in">avail_in</a> has
|
|
||||||
dropped to zero. It must update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> when <a href="#avail_out">avail_out</a>
|
|
||||||
has dropped to zero. The application must initialize <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and
|
|
||||||
<a href="#opaque">opaque</a> before calling the init function. All other fields are set by the
|
|
||||||
compression library and must not be updated by the application. <p>
|
|
||||||
|
|
||||||
The <a href="#opaque">opaque</a> value provided by the application will be passed as the first
|
|
||||||
parameter for calls of <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a>. This can be useful for custom
|
|
||||||
memory management. The compression library attaches no meaning to the
|
|
||||||
<a href="#opaque">opaque</a> value. <p>
|
|
||||||
|
|
||||||
<a href="#zalloc">zalloc</a> must return <a href="#Z_NULL">Z_NULL</a> if there is not enough memory for the object.
|
|
||||||
If zlib is used in a multi-threaded application, <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be
|
|
||||||
thread safe. <p>
|
|
||||||
|
|
||||||
On 16-bit systems, the functions <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be able to allocate
|
|
||||||
exactly 65536 bytes, but will not be required to allocate more than this
|
|
||||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
|
||||||
pointers returned by <a href="#zalloc">zalloc</a> for objects of exactly 65536 bytes *must*
|
|
||||||
have their offset normalized to zero. The default allocation function
|
|
||||||
provided by this library ensures this (see zutil.c). To reduce memory
|
|
||||||
requirements and avoid any allocation of 64K objects, at the expense of
|
|
||||||
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
|
||||||
<p>
|
|
||||||
|
|
||||||
The fields <a href="#total_in">total_in</a> and <a href="#total_out">total_out</a> can be used for statistics or
|
|
||||||
progress reports. After compression, <a href="#total_in">total_in</a> holds the total size of
|
|
||||||
the uncompressed data and may be saved for use in the decompressor
|
|
||||||
(particularly if the decompressor wants to decompress everything in
|
|
||||||
a single step). <p>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<a name="Constants"><h2> Constants </h2>
|
|
||||||
<font color="Blue">
|
|
||||||
<pre>
|
|
||||||
#define <a name="Z_NO_FLUSH">Z_NO_FLUSH</a> 0
|
|
||||||
#define <a name="Z_PARTIAL_FLUSH">Z_PARTIAL_FLUSH</a> 1
|
|
||||||
/* will be removed, use <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> instead */
|
|
||||||
#define <a name="Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> 2
|
|
||||||
#define <a name="Z_FULL_FLUSH">Z_FULL_FLUSH</a> 3
|
|
||||||
#define <a name="Z_FINISH">Z_FINISH</a> 4
|
|
||||||
/* Allowed flush values ; see <a href="#deflate">deflate</a>() below for details */
|
|
||||||
|
|
||||||
#define <a name="Z_OK">Z_OK</a> 0
|
|
||||||
#define <a name="Z_STREAM_END">Z_STREAM_END</a> 1
|
|
||||||
#define <a name="Z_NEED_DICT">Z_NEED_DICT</a> 2
|
|
||||||
#define <a name="Z_ERRNO">Z_ERRNO</a> (-1)
|
|
||||||
#define <a name="Z_STREAM_ERROR">Z_STREAM_ERROR</a> (-2)
|
|
||||||
#define <a name="Z_DATA_ERROR">Z_DATA_ERROR</a> (-3)
|
|
||||||
#define <a name="Z_MEM_ERROR">Z_MEM_ERROR</a> (-4)
|
|
||||||
#define <a name="Z_BUF_ERROR">Z_BUF_ERROR</a> (-5)
|
|
||||||
#define <a name="Z_VERSION_ERROR">Z_VERSION_ERROR</a> (-6)
|
|
||||||
/* Return codes for the compression/decompression functions. Negative
|
|
||||||
* values are errors, positive values are used for special but normal events.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define <a name="Z_NO_COMPRESSION">Z_NO_COMPRESSION</a> 0
|
|
||||||
#define <a name="Z_BEST_SPEED">Z_BEST_SPEED</a> 1
|
|
||||||
#define <a name="Z_BEST_COMPRESSION">Z_BEST_COMPRESSION</a> 9
|
|
||||||
#define <a name="Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> (-1)
|
|
||||||
/* compression levels */
|
|
||||||
|
|
||||||
#define <a name="Z_FILTERED">Z_FILTERED</a> 1
|
|
||||||
#define <a name="Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> 2
|
|
||||||
#define <a name="Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> 0
|
|
||||||
/* compression strategy ; see <a href="#deflateInit2">deflateInit2</a>() below for details */
|
|
||||||
|
|
||||||
#define <a name="Z_BINARY">Z_BINARY</a> 0
|
|
||||||
#define <a name="Z_ASCII">Z_ASCII</a> 1
|
|
||||||
#define <a name="Z_UNKNOWN">Z_UNKNOWN</a> 2
|
|
||||||
/* Possible values of the <a href="#data_type">data_type</a> field */
|
|
||||||
|
|
||||||
#define <a name="Z_DEFLATED">Z_DEFLATED</a> 8
|
|
||||||
/* The <a href="#deflate">deflate</a> compression method (the only one supported in this version) */
|
|
||||||
|
|
||||||
#define <a name="Z_NULL">Z_NULL</a> 0 /* for initializing <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a>, <a href="#opaque">opaque</a> */
|
|
||||||
|
|
||||||
#define <a name="zlib_version">zlib_version</a> <a href="#zlibVersion">zlibVersion</a>()
|
|
||||||
/* for compatibility with versions less than 1.0.2 */
|
|
||||||
</pre>
|
|
||||||
</font>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<a name="Misc"><h2> Misc </h2>
|
|
||||||
<a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a> are macros to allow checking the zlib version
|
|
||||||
and the compiler's view of <a href="#z_stream_s">z_stream</a>.
|
|
||||||
<p>
|
|
||||||
Other functions:
|
|
||||||
<dl>
|
|
||||||
<font color="Blue"><dt> const char * <a name="zError">zError</a> (int err);</font>
|
|
||||||
<font color="Blue"><dt> int <a name="inflateSyncPoint">inflateSyncPoint</a> (<a href="#z_streamp">z_streamp</a> z);</font>
|
|
||||||
<font color="Blue"><dt> const uLongf * <a name="get_crc_table">get_crc_table</a> (void);</font>
|
|
||||||
</dl>
|
|
||||||
<hr>
|
|
||||||
<font size="-1">
|
|
||||||
Last update: Wed Oct 13 20:42:34 1999<br>
|
|
||||||
piapi@csie.ntu.edu.tw
|
|
||||||
</font>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -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-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -11,10 +11,6 @@
|
||||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STDC
|
|
||||||
extern void exit OF((int));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char * const z_errmsg[10] = {
|
const char * const z_errmsg[10] = {
|
||||||
"need dictionary", /* Z_NEED_DICT 2 */
|
"need dictionary", /* Z_NEED_DICT 2 */
|
||||||
"stream end", /* Z_STREAM_END 1 */
|
"stream end", /* Z_STREAM_END 1 */
|
||||||
|
@ -78,38 +74,38 @@ uLong ZEXPORT zlibCompileFlags()
|
||||||
flags += 1 << 13;
|
flags += 1 << 13;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NO_GZCOMPRESS
|
#ifdef NO_GZCOMPRESS
|
||||||
flags += 1 << 16;
|
flags += 1L << 16;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NO_GZIP
|
#ifdef NO_GZIP
|
||||||
flags += 1 << 17;
|
flags += 1L << 17;
|
||||||
#endif
|
#endif
|
||||||
#ifdef PKZIP_BUG_WORKAROUND
|
#ifdef PKZIP_BUG_WORKAROUND
|
||||||
flags += 1 << 20;
|
flags += 1L << 20;
|
||||||
#endif
|
#endif
|
||||||
#ifdef FASTEST
|
#ifdef FASTEST
|
||||||
flags += 1 << 21;
|
flags += 1L << 21;
|
||||||
#endif
|
#endif
|
||||||
#ifdef STDC
|
#ifdef STDC
|
||||||
# ifdef NO_vsnprintf
|
# ifdef NO_vsnprintf
|
||||||
flags += 1 << 25;
|
flags += 1L << 25;
|
||||||
# ifdef HAS_vsprintf_void
|
# ifdef HAS_vsprintf_void
|
||||||
flags += 1 << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
# ifdef HAS_vsnprintf_void
|
# ifdef HAS_vsnprintf_void
|
||||||
flags += 1 << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
flags += 1 << 24;
|
flags += 1L << 24;
|
||||||
# ifdef NO_snprintf
|
# ifdef NO_snprintf
|
||||||
flags += 1 << 25;
|
flags += 1L << 25;
|
||||||
# ifdef HAS_sprintf_void
|
# ifdef HAS_sprintf_void
|
||||||
flags += 1 << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
# ifdef HAS_snprintf_void
|
# ifdef HAS_snprintf_void
|
||||||
flags += 1 << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -141,7 +137,10 @@ const char * ZEXPORT zError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32_WCE)
|
#if defined(_WIN32_WCE)
|
||||||
/* does not exist on WCE */
|
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
||||||
|
* errno. We define it as a global variable to simplify porting.
|
||||||
|
* Its value is always 0 and should not be used.
|
||||||
|
*/
|
||||||
int errno = 0;
|
int errno = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -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-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -17,14 +17,26 @@
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
|
|
||||||
#ifdef STDC
|
#ifdef STDC
|
||||||
# include <stddef.h>
|
# ifndef _WIN32_WCE
|
||||||
|
# include <stddef.h>
|
||||||
|
# endif
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef NO_ERRNO_H
|
#ifdef NO_ERRNO_H
|
||||||
|
# ifdef _WIN32_WCE
|
||||||
|
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
||||||
|
* errno. We define it as a global variable to simplify porting.
|
||||||
|
* Its value is always 0 and should not be used. We rename it to
|
||||||
|
* avoid conflict with other libraries that use the same workaround.
|
||||||
|
*/
|
||||||
|
# define errno z_errno
|
||||||
|
# endif
|
||||||
extern int errno;
|
extern int errno;
|
||||||
#else
|
#else
|
||||||
# include <errno.h>
|
# ifndef _WIN32_WCE
|
||||||
|
# include <errno.h>
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef local
|
#ifndef local
|
||||||
|
@ -105,6 +117,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
|
||||||
#ifdef OS2
|
#ifdef OS2
|
||||||
# define OS_CODE 0x06
|
# define OS_CODE 0x06
|
||||||
|
# ifdef M_I86
|
||||||
|
#include <malloc.h>
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||||
|
@ -189,12 +204,8 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
# define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef VMS
|
||||||
#ifdef HAVE_STRERROR
|
# define NO_vsnprintf
|
||||||
extern char *strerror OF((int));
|
|
||||||
# define zstrerror(errnum) strerror(errnum)
|
|
||||||
#else
|
|
||||||
# define zstrerror(errnum) ""
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(pyr)
|
#if defined(pyr)
|
||||||
|
|
|
@ -112,9 +112,9 @@ extern (C) int _aApplywc1(wchar[] aa, dg_t dg)
|
||||||
|
|
||||||
d = std.utf.decode(aa, i);
|
d = std.utf.decode(aa, i);
|
||||||
b = std.utf.toUTF8(buf, d);
|
b = std.utf.toUTF8(buf, d);
|
||||||
foreach (char c; b)
|
foreach (char c2; b)
|
||||||
{
|
{
|
||||||
result = dg(cast(void *)&c);
|
result = dg(cast(void *)&c2);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -145,9 +145,9 @@ extern (C) int _aApplydc1(dchar[] aa, dg_t dg)
|
||||||
char[] b;
|
char[] b;
|
||||||
|
|
||||||
b = std.utf.toUTF8(buf, d);
|
b = std.utf.toUTF8(buf, d);
|
||||||
foreach (char c; b)
|
foreach (char c2; b)
|
||||||
{
|
{
|
||||||
result = dg(cast(void *)&c);
|
result = dg(cast(void *)&c2);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -305,9 +305,9 @@ extern (C) int _aApplywc2(wchar[] aa, dg2_t dg)
|
||||||
d = std.utf.decode(aa, n);
|
d = std.utf.decode(aa, n);
|
||||||
n -= i;
|
n -= i;
|
||||||
b = std.utf.toUTF8(buf, d);
|
b = std.utf.toUTF8(buf, d);
|
||||||
foreach (char c; b)
|
foreach (char c2; b)
|
||||||
{
|
{
|
||||||
result = dg(&i, cast(void *)&c);
|
result = dg(&i, cast(void *)&c2);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -341,9 +341,9 @@ extern (C) int _aApplydc2(dchar[] aa, dg2_t dg)
|
||||||
char[] b;
|
char[] b;
|
||||||
|
|
||||||
b = std.utf.toUTF8(buf, d);
|
b = std.utf.toUTF8(buf, d);
|
||||||
foreach (char c; b)
|
foreach (char c2; b)
|
||||||
{
|
{
|
||||||
result = dg(&i, cast(void *)&c);
|
result = dg(&i, cast(void *)&c2);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#DMD=../../../dmd
|
#DMD=../../../dmd
|
||||||
DMD=dmd
|
DMD=dmd
|
||||||
CFLAGS=-g
|
CFLAGS=-g -m32
|
||||||
#DFLAGS=-unittest -g -release
|
#DFLAGS=-unittest -g -release
|
||||||
DFLAGS=-release -O -inline -I../..
|
DFLAGS=-release -O -inline -I../..
|
||||||
#DFLAGS=-release -inline -O
|
#DFLAGS=-release -inline -O
|
||||||
|
@ -43,8 +43,8 @@ gclinux.o : gclinux.d
|
||||||
$(DMD) -c $(DFLAGS) gclinux.d
|
$(DMD) -c $(DFLAGS) gclinux.d
|
||||||
|
|
||||||
zip : $(SRC)
|
zip : $(SRC)
|
||||||
rm dmgc.zip
|
$(RM) dmgc.zip
|
||||||
zip dmgc $(SRC)
|
zip dmgc $(SRC)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJS) dmgc.a testgc testgc.o
|
$(RM) $(OBJS) dmgc.a testgc testgc.o
|
||||||
|
|
19
linux.mak
19
linux.mak
|
@ -9,8 +9,8 @@
|
||||||
# make unittest
|
# make unittest
|
||||||
# Build libphobos.a, build and run unit tests
|
# Build libphobos.a, build and run unit tests
|
||||||
|
|
||||||
CFLAGS=-O
|
CFLAGS=-O -m32
|
||||||
#CFLAGS=-g
|
#CFLAGS=-g -m32
|
||||||
|
|
||||||
DFLAGS=-O -release -w
|
DFLAGS=-O -release -w
|
||||||
#DFLAGS=-unittest -w
|
#DFLAGS=-unittest -w
|
||||||
|
@ -45,7 +45,7 @@ unittest : unittest.o libphobos.a
|
||||||
unittest.o : unittest.d
|
unittest.o : unittest.d
|
||||||
$(DMD) -c unittest
|
$(DMD) -c unittest
|
||||||
|
|
||||||
OBJS= asserterror.o deh2.o switch.o complex.o gcstats.o \
|
OBJS = asserterror.o deh2.o switch.o complex.o gcstats.o \
|
||||||
critical.o object.o monitor.o arraycat.o invariant.o \
|
critical.o object.o monitor.o arraycat.o invariant.o \
|
||||||
dmain2.o outofmemory.o aaA.o adi.o aApply.o file.o \
|
dmain2.o outofmemory.o aaA.o adi.o aApply.o file.o \
|
||||||
compiler.o system.o moduleinit.o md5.o base64.o \
|
compiler.o system.o moduleinit.o md5.o base64.o \
|
||||||
|
@ -53,7 +53,7 @@ OBJS= asserterror.o deh2.o switch.o complex.o gcstats.o \
|
||||||
outbuffer.o ctype.o regexp.o random.o linux.o linuxsocket.o \
|
outbuffer.o ctype.o regexp.o random.o linux.o linuxsocket.o \
|
||||||
stream.o cstream.o switcherr.o array.o gc.o \
|
stream.o cstream.o switcherr.o array.o gc.o \
|
||||||
qsort.o thread.o obj.o utf.o uri.o \
|
qsort.o thread.o obj.o utf.o uri.o \
|
||||||
crc32.o conv.o arraycast.o errno.o alloca.o cmath2.o \
|
Dcrc32.o conv.o arraycast.o errno.o alloca.o cmath2.o \
|
||||||
process.o syserror.o \
|
process.o syserror.o \
|
||||||
socket.o socketstream.o stdarg.o stdio.o format.o \
|
socket.o socketstream.o stdarg.o stdio.o format.o \
|
||||||
perf.o openrj.o uni.o trace.o boxer.o \
|
perf.o openrj.o uni.o trace.o boxer.o \
|
||||||
|
@ -71,7 +71,7 @@ OBJS= asserterror.o deh2.o switch.o complex.o gcstats.o \
|
||||||
ti_void.o \
|
ti_void.o \
|
||||||
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o
|
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o
|
||||||
|
|
||||||
ZLIB_OBJS= etc/c/zlib/adler32.o etc/c/zlib/compress.o \
|
ZLIB_OBJS = etc/c/zlib/adler32.o etc/c/zlib/compress.o \
|
||||||
etc/c/zlib/crc32.o etc/c/zlib/gzio.o \
|
etc/c/zlib/crc32.o etc/c/zlib/gzio.o \
|
||||||
etc/c/zlib/uncompr.o etc/c/zlib/deflate.o \
|
etc/c/zlib/uncompr.o etc/c/zlib/deflate.o \
|
||||||
etc/c/zlib/trees.o etc/c/zlib/zutil.o \
|
etc/c/zlib/trees.o etc/c/zlib/zutil.o \
|
||||||
|
@ -172,7 +172,6 @@ SRC_ZLIB= etc/c/zlib\trees.h \
|
||||||
etc/c/zlib\zlib.h \
|
etc/c/zlib\zlib.h \
|
||||||
etc/c/zlib\adler32.c \
|
etc/c/zlib\adler32.c \
|
||||||
etc/c/zlib\ChangeLog \
|
etc/c/zlib\ChangeLog \
|
||||||
etc/c/zlib\zlib.html \
|
|
||||||
etc/c/zlib\README \
|
etc/c/zlib\README \
|
||||||
etc/c/zlib\win32.mak \
|
etc/c/zlib\win32.mak \
|
||||||
etc/c/zlib\linux.mak
|
etc/c/zlib\linux.mak
|
||||||
|
@ -212,8 +211,8 @@ $(ZLIB_OBJS):
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
crc32.o : crc32.d
|
Dcrc32.o : crc32.d
|
||||||
$(DMD) -c $(DFLAGS) crc32.d
|
$(DMD) -c $(DFLAGS) crc32.d -ofDcrc32.o
|
||||||
|
|
||||||
errno.o : errno.c
|
errno.o : errno.c
|
||||||
|
|
||||||
|
@ -580,8 +579,8 @@ ti_bit.o : std/typeinfo/ti_bit.d
|
||||||
##########################################################333
|
##########################################################333
|
||||||
|
|
||||||
zip : $(ALLSRCS) linux.mak win32.mak phoboslicense.txt
|
zip : $(ALLSRCS) linux.mak win32.mak phoboslicense.txt
|
||||||
rm phobos.zip
|
$(RM) phobos.zip
|
||||||
zip phobos $(ALLSRCS) linux.mak win32.mak phoboslicense.txt
|
zip phobos $(ALLSRCS) linux.mak win32.mak phoboslicense.txt
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJS) unittest unittest.o
|
$(RM) $(OBJS) unittest unittest.o
|
||||||
|
|
|
@ -124,14 +124,14 @@ static ~this()
|
||||||
if (i >= c.data.length)
|
if (i >= c.data.length)
|
||||||
break;
|
break;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (char c; lstlines[i])
|
foreach (char c2; lstlines[i])
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c2)
|
||||||
{ case ' ':
|
{ case ' ':
|
||||||
continue;
|
continue;
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
count = count * 10 + c - '0';
|
count = count * 10 + c2 - '0';
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -730,9 +730,9 @@ char[] toUTF8(dchar[] s)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r.length = i;
|
r.length = i;
|
||||||
foreach (dchar c; s[i .. slen])
|
foreach (dchar d; s[i .. slen])
|
||||||
{
|
{
|
||||||
encode(r, c);
|
encode(r, d);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,6 @@ SRC_ZLIB= etc\c\zlib\trees.h \
|
||||||
etc\c\zlib\zlib.h \
|
etc\c\zlib\zlib.h \
|
||||||
etc\c\zlib\adler32.c \
|
etc\c\zlib\adler32.c \
|
||||||
etc\c\zlib\ChangeLog \
|
etc\c\zlib\ChangeLog \
|
||||||
etc\c\zlib\zlib.html \
|
|
||||||
etc\c\zlib\README \
|
etc\c\zlib\README \
|
||||||
etc\c\zlib\win32.mak \
|
etc\c\zlib\win32.mak \
|
||||||
etc\c\zlib\linux.mak
|
etc\c\zlib\linux.mak
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue