Changeset View
Changeset View
Standalone View
Standalone View
sys/netgraph/ng_zlib.h
- This file was moved from sys/sys/zlib.h.
Show All 40 Lines | /*- | ||||
3. This notice may not be removed or altered from any source distribution. | 3. This notice may not be removed or altered from any source distribution. | ||||
Jean-loup Gailly Mark Adler | Jean-loup Gailly Mark Adler | ||||
gzip@prep.ai.mit.edu madler@alumni.caltech.edu | gzip@prep.ai.mit.edu madler@alumni.caltech.edu | ||||
*/ | */ | ||||
/* | /* | ||||
The data format used by the zlib library is described by RFCs (Request for | The data format used by the zlib library is described by RFCs (Request for | ||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt | Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt | ||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). | ||||
delphij: (see comment on sys/conf/kern.pre.mk: I think we could eliminate this need). | |||||
*/ | */ | ||||
#ifndef _ZLIB_H | #ifndef _ZLIB_H | ||||
#define _ZLIB_H | #define _ZLIB_H | ||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
extern "C" { | extern "C" { | ||||
#endif | #endif | ||||
Show All 33 Lines | |||||
# define compress z_compress | # define compress z_compress | ||||
# define uncompress z_uncompress | # define uncompress z_uncompress | ||||
# define adler32 z_adler32 | # define adler32 z_adler32 | ||||
#if 0 | #if 0 | ||||
# define crc32 z_crc32 | # define crc32 z_crc32 | ||||
# define get_crc_table z_get_crc_table | # define get_crc_table z_get_crc_table | ||||
#endif | #endif | ||||
# define Byte z_Byte | # define Byte z_Byte | ||||
Done Inline Actions[OPTIONAL] I wonder if we can make deflate_copyright and inflate_copyright in sys/libkern/zlib.c static instead? delphij: [OPTIONAL] I wonder if we can make deflate_copyright and inflate_copyright in sys/libkern/zlib. | |||||
Done Inline ActionsIt appeared that these 2 variables are not used at all. Converting to static variable resulted in error. ota_j.email.ne.jp: It appeared that these 2 variables are not used at all. Converting to static variable resulted… | |||||
# define uInt z_uInt | # define uInt z_uInt | ||||
# define uLong z_uLong | # define uLong z_uLong | ||||
# define Bytef z_Bytef | # define Bytef z_Bytef | ||||
# define charf z_charf | # define charf z_charf | ||||
# define intf z_intf | # define intf z_intf | ||||
# define uIntf z_uIntf | # define uIntf z_uIntf | ||||
# define uLongf z_uLongf | # define uLongf z_uLongf | ||||
# define voidpf z_voidpf | # define voidpf z_voidpf | ||||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | |||||
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ | ||||
#define zlib_version zlibVersion() | #define zlib_version zlibVersion() | ||||
/* for compatibility with versions < 1.0.2 */ | /* for compatibility with versions < 1.0.2 */ | ||||
/* basic functions */ | /* basic functions */ | ||||
extern const char * EXPORT zlibVersion OF((void)); | static const char * EXPORT zlibVersion OF((void)); | ||||
/* The application can compare zlibVersion and ZLIB_VERSION for consistency. | /* The application can compare zlibVersion and ZLIB_VERSION for consistency. | ||||
If the first character differs, the library code actually used is | If the first character differs, the library code actually used is | ||||
not compatible with the zlib.h header file used by the application. | not compatible with the zlib.h header file used by the application. | ||||
This check is automatically made by deflateInit and inflateInit. | This check is automatically made by deflateInit and inflateInit. | ||||
*/ | */ | ||||
static int EXPORT deflateInit OF((z_streamp strm, int level)); | |||||
/* | /* | ||||
extern int EXPORT deflateInit OF((z_streamp strm, int level)); | |||||
Done Inline ActionsMissed this one. ota_j.email.ne.jp: Missed this one. | |||||
Initializes the internal stream state for compression. The fields | Initializes the internal stream state for compression. The fields | ||||
zalloc, zfree and opaque must be initialized before by the caller. | zalloc, zfree and opaque must be initialized before by the caller. | ||||
If zalloc and zfree are set to Z_NULL, deflateInit updates them to | If zalloc and zfree are set to Z_NULL, deflateInit updates them to | ||||
use default allocation functions. | use default allocation functions. | ||||
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: | The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: | ||||
1 gives best speed, 9 gives best compression, 0 gives no compression at | 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). | all (the input data is simply copied a block at a time). | ||||
Z_DEFAULT_COMPRESSION requests a default compromise between speed and | Z_DEFAULT_COMPRESSION requests a default compromise between speed and | ||||
compression (currently equivalent to level 6). | compression (currently equivalent to level 6). | ||||
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | ||||
enough memory, Z_STREAM_ERROR if level is not a valid compression level, | enough memory, Z_STREAM_ERROR if level is not a valid compression level, | ||||
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible | ||||
with the version assumed by the caller (ZLIB_VERSION). | with the version assumed by the caller (ZLIB_VERSION). | ||||
msg is set to null if there is no error message. deflateInit does not | msg is set to null if there is no error message. deflateInit does not | ||||
perform any compression: this will be done by deflate(). | perform any compression: this will be done by deflate(). | ||||
*/ | */ | ||||
extern int EXPORT deflate OF((z_streamp strm, int flush)); | static int EXPORT ng_deflate OF((z_streamp strm, int flush)); | ||||
/* | /* | ||||
Performs one or both of the following actions: | Performs one or both of the following actions: | ||||
- Compress more input starting at next_in and update next_in and avail_in | - Compress more input starting at next_in and update next_in and avail_in | ||||
accordingly. If not all input can be processed (because there is not | accordingly. If not all input can be processed (because there is not | ||||
enough room in the output buffer), next_in and avail_in are updated and | enough room in the output buffer), next_in and avail_in are updated and | ||||
processing will resume at this point for the next call of deflate(). | processing will resume at this point for the next call of deflate(). | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | the compression algorithm in any manner. | ||||
deflate() returns Z_OK if some progress has been made (more input | deflate() returns Z_OK if some progress has been made (more input | ||||
processed or more output produced), Z_STREAM_END if all input has been | processed or more output produced), Z_STREAM_END if all input has been | ||||
consumed and all output has been produced (only when flush is set to | consumed and all output has been produced (only when flush is set to | ||||
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example | ||||
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible. | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible. | ||||
*/ | */ | ||||
extern int EXPORT deflateEnd OF((z_streamp strm)); | static int EXPORT deflateEnd OF((z_streamp strm)); | ||||
/* | /* | ||||
All dynamically allocated data structures for this stream are freed. | All dynamically allocated data structures for this stream are freed. | ||||
This function discards any unprocessed input and does not flush any | This function discards any unprocessed input and does not flush any | ||||
pending output. | pending output. | ||||
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the | ||||
stream state was inconsistent, Z_DATA_ERROR if the stream was freed | stream state was inconsistent, Z_DATA_ERROR if the stream was freed | ||||
prematurely (some input or output was discarded). In the error case, | prematurely (some input or output was discarded). In the error case, | ||||
msg may be set but then points to a static string (which must not be | msg may be set but then points to a static string (which must not be | ||||
deallocated). | deallocated). | ||||
*/ | */ | ||||
/* | |||||
extern int EXPORT inflateInit OF((z_streamp strm)); | |||||
static int EXPORT inflateInit OF((z_streamp strm)); | |||||
/* | |||||
Initializes the internal stream state for decompression. The fields | Initializes the internal stream state for decompression. The fields | ||||
zalloc, zfree and opaque must be initialized before by the caller. If | zalloc, zfree and opaque must be initialized before by the caller. If | ||||
zalloc and zfree are set to Z_NULL, inflateInit updates them to use default | zalloc and zfree are set to Z_NULL, inflateInit updates them to use default | ||||
allocation functions. | allocation functions. | ||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | ||||
enough memory, Z_VERSION_ERROR if the zlib library version is incompatible | enough memory, Z_VERSION_ERROR if the zlib library version is incompatible | ||||
with the version assumed by the caller. msg is set to null if there is no | with the version assumed by the caller. msg is set to null if there is no | ||||
error message. inflateInit does not perform any decompression: this will be | error message. inflateInit does not perform any decompression: this will be | ||||
done by inflate(). | done by inflate(). | ||||
*/ | */ | ||||
#if defined(__FreeBSD__) && defined(_KERNEL) | static int EXPORT ng_inflate OF((z_streamp strm, int flush)); | ||||
#define inflate _zlib104_inflate /* FreeBSD already has an inflate :-( */ | |||||
#endif | |||||
extern int EXPORT inflate OF((z_streamp strm, int flush)); | |||||
/* | /* | ||||
Performs one or both of the following actions: | Performs one or both of the following actions: | ||||
- Decompress more input starting at next_in and update next_in and avail_in | - Decompress more input starting at next_in and update next_in and avail_in | ||||
accordingly. If not all input can be processed (because there is not | accordingly. If not all input can be processed (because there is not | ||||
enough room in the output buffer), next_in is updated and processing | enough room in the output buffer), next_in is updated and processing | ||||
will resume at this point for the next call of inflate(). | will resume at this point for the next call of inflate(). | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | /* | ||||
Z_BUF_ERROR if no progress is possible or if there was not enough room in | Z_BUF_ERROR if no progress is possible or if there was not enough room in | ||||
the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the | the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the | ||||
application may then call inflateSync to look for a good compression block. | application may then call inflateSync to look for a good compression block. | ||||
In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the | In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the | ||||
dictionary chosen by the compressor. | dictionary chosen by the compressor. | ||||
*/ | */ | ||||
extern int EXPORT inflateEnd OF((z_streamp strm)); | static int EXPORT inflateEnd OF((z_streamp strm)); | ||||
/* | /* | ||||
All dynamically allocated data structures for this stream are freed. | All dynamically allocated data structures for this stream are freed. | ||||
This function discards any unprocessed input and does not flush any | This function discards any unprocessed input and does not flush any | ||||
pending output. | pending output. | ||||
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state | inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state | ||||
was inconsistent. In the error case, msg may be set but then points to a | was inconsistent. In the error case, msg may be set but then points to a | ||||
static string (which must not be deallocated). | static string (which must not be deallocated). | ||||
*/ | */ | ||||
/* Advanced functions */ | /* Advanced functions */ | ||||
/* | /* | ||||
The following functions are needed only in some special applications. | The following functions are needed only in some special applications. | ||||
*/ | */ | ||||
/* | static int EXPORT deflateInit2 OF((z_streamp strm, | ||||
extern int EXPORT deflateInit2 OF((z_streamp strm, | |||||
int level, | int level, | ||||
int method, | int method, | ||||
int windowBits, | int windowBits, | ||||
int memLevel, | int memLevel, | ||||
int strategy)); | int strategy)); | ||||
/* | |||||
This is another version of deflateInit with more compression options. The | This is another version of deflateInit with more compression options. The | ||||
fields next_in, zalloc, zfree and opaque must be initialized before by | fields next_in, zalloc, zfree and opaque must be initialized before by | ||||
the caller. | the caller. | ||||
The method parameter is the compression method. It must be Z_DEFLATED in | The method parameter is the compression method. It must be Z_DEFLATED in | ||||
this version of the library. (Method 9 will allow a 64K history buffer and | this version of the library. (Method 9 will allow a 64K history buffer and | ||||
partial block flushes.) | partial block flushes.) | ||||
Show All 35 Lines | reset by the library in this case. | ||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was | 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 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as | ||||
an invalid method). msg is set to null if there is no error message. | an invalid method). msg is set to null if there is no error message. | ||||
deflateInit2 does not perform any compression: this will be done by | deflateInit2 does not perform any compression: this will be done by | ||||
deflate(). | deflate(). | ||||
*/ | */ | ||||
extern int EXPORT deflateSetDictionary OF((z_streamp strm, | static int EXPORT deflateSetDictionary OF((z_streamp strm, | ||||
const Bytef *dictionary, | const Bytef *dictionary, | ||||
uInt dictLength)); | uInt dictLength)); | ||||
/* | /* | ||||
Initializes the compression dictionary (history buffer) from the given | Initializes the compression dictionary (history buffer) from the given | ||||
byte sequence without producing any compressed output. This function must | byte sequence without producing any compressed output. This function must | ||||
be called immediately after deflateInit or deflateInit2, before any call | be called immediately after deflateInit or deflateInit2, before any call | ||||
of deflate. The compressor and decompressor must use exactly the same | of deflate. The compressor and decompressor must use exactly the same | ||||
dictionary (see inflateSetDictionary). | dictionary (see inflateSetDictionary). | ||||
Show All 12 Lines | actually used by the compressor.) | ||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a | ||||
parameter is invalid (such as NULL dictionary) or the stream state | parameter is invalid (such as NULL dictionary) or the stream state | ||||
is inconsistent (for example if deflate has already been called for this | is inconsistent (for example if deflate has already been called for this | ||||
stream). deflateSetDictionary does not perform any compression: this will | stream). deflateSetDictionary does not perform any compression: this will | ||||
be done by deflate(). | be done by deflate(). | ||||
*/ | */ | ||||
extern int EXPORT deflateCopy OF((z_streamp dest, | static int EXPORT deflateCopy OF((z_streamp dest, | ||||
z_streamp source)); | z_streamp source)); | ||||
/* | /* | ||||
Sets the destination stream as a complete copy of the source stream. If | Sets the destination stream as a complete copy of the source stream. If | ||||
the source stream is using an application-supplied history buffer, a new | the source stream is using an application-supplied history buffer, a new | ||||
buffer is allocated for the destination stream. The compressed output | buffer is allocated for the destination stream. The compressed output | ||||
buffer is always application-supplied. It's the responsibility of the | buffer is always application-supplied. It's the responsibility of the | ||||
application to provide the correct values of next_out and avail_out for the | application to provide the correct values of next_out and avail_out for the | ||||
next call of deflate. | next call of deflate. | ||||
This function can be useful when several compression strategies will be | This function can be useful when several compression strategies will be | ||||
tried, for example when there are several ways of pre-processing the input | 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 | data with a filter. The streams that will be discarded should then be freed | ||||
by calling deflateEnd. Note that deflateCopy duplicates the internal | by calling deflateEnd. Note that deflateCopy duplicates the internal | ||||
compression state which can be quite large, so this strategy is slow and | compression state which can be quite large, so this strategy is slow and | ||||
can consume lots of memory. | can consume lots of memory. | ||||
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not | ||||
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent | ||||
(such as zalloc being NULL). msg is left unchanged in both source and | (such as zalloc being NULL). msg is left unchanged in both source and | ||||
destination. | destination. | ||||
*/ | */ | ||||
extern int EXPORT deflateReset OF((z_streamp strm)); | static int EXPORT deflateReset OF((z_streamp strm)); | ||||
/* | /* | ||||
This function is equivalent to deflateEnd followed by deflateInit, | This function is equivalent to deflateEnd followed by deflateInit, | ||||
but does not free and reallocate all the internal compression state. | but does not free and reallocate all the internal compression state. | ||||
The stream will keep the same compression level and any other attributes | The stream will keep the same compression level and any other attributes | ||||
that may have been set by deflateInit2. | that may have been set by deflateInit2. | ||||
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source | deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source | ||||
stream state was inconsistent (such as zalloc or state being NULL). | stream state was inconsistent (such as zalloc or state being NULL). | ||||
*/ | */ | ||||
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); | static int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); | ||||
/* | /* | ||||
Dynamically update the compression level and compression strategy. | Dynamically update the compression level and compression strategy. | ||||
This can be used to switch between compression and straight copy of | 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 | 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 | a different strategy. If the compression level is changed, the input | ||||
available so far is compressed with the old level (and may be flushed); | 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 deflate(). | the new level will take effect only at the next call of deflate(). | ||||
Before the call of deflateParams, the stream state must be set as for | Before the call of deflateParams, the stream state must be set as for | ||||
a call of deflate(), since the currently available input may have to | a call of deflate(), since the currently available input may have to | ||||
be compressed and flushed. In particular, strm->avail_out must be non-zero. | be compressed and flushed. In particular, strm->avail_out must be non-zero. | ||||
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source | ||||
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR | stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR | ||||
if strm->avail_out was zero. | if strm->avail_out was zero. | ||||
*/ | */ | ||||
extern int EXPORT deflateOutputPending OF((z_streamp strm)); | static int EXPORT deflateOutputPending OF((z_streamp strm)); | ||||
/* | /* | ||||
Returns the number of bytes of output which are immediately | Returns the number of bytes of output which are immediately | ||||
available from the compressor (i.e. without any further input | available from the compressor (i.e. without any further input | ||||
or flush). | or flush). | ||||
*/ | */ | ||||
/* | static int EXPORT inflateInit2 OF((z_streamp strm, | ||||
extern int EXPORT inflateInit2 OF((z_streamp strm, | |||||
int windowBits)); | int windowBits)); | ||||
/* | |||||
This is another version of inflateInit with more compression options. The | This is another version of inflateInit with more compression options. The | ||||
fields next_out, zalloc, zfree and opaque must be initialized before by | fields next_out, zalloc, zfree and opaque must be initialized before by | ||||
the caller. | the caller. | ||||
The windowBits parameter is the base two logarithm of the maximum window | 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 | size (the size of the history buffer). It should be in the range 8..15 for | ||||
this version of the library (the value 16 will be allowed soon). The | this version of the library (the value 16 will be allowed soon). The | ||||
default value is 15 if inflateInit is used instead. If a compressed stream | default value is 15 if inflateInit is used instead. If a compressed stream | ||||
Show All 15 Lines | avail_out is zero and all output has been consumed. | ||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was | 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 | not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as | ||||
windowBits < 8). msg is set to null if there is no error message. | windowBits < 8). msg is set to null if there is no error message. | ||||
inflateInit2 does not perform any decompression: this will be done by | inflateInit2 does not perform any decompression: this will be done by | ||||
inflate(). | inflate(). | ||||
*/ | */ | ||||
extern int EXPORT inflateSetDictionary OF((z_streamp strm, | static int EXPORT inflateSetDictionary OF((z_streamp strm, | ||||
const Bytef *dictionary, | const Bytef *dictionary, | ||||
uInt dictLength)); | uInt dictLength)); | ||||
/* | /* | ||||
Initializes the decompression dictionary (history buffer) from the given | Initializes the decompression dictionary (history buffer) from the given | ||||
uncompressed byte sequence. This function must be called immediately after | uncompressed byte sequence. This function must be called immediately after | ||||
a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen | a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen | ||||
by the compressor can be determined from the Adler32 value returned by this | by the compressor can be determined from the Adler32 value returned by this | ||||
call of inflate. The compressor and decompressor must use exactly the same | call of inflate. The compressor and decompressor must use exactly the same | ||||
dictionary (see deflateSetDictionary). | dictionary (see deflateSetDictionary). | ||||
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 | ||||
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the | ||||
expected one (incorrect Adler32 value). inflateSetDictionary does not | expected one (incorrect Adler32 value). inflateSetDictionary does not | ||||
perform any decompression: this will be done by subsequent calls of | perform any decompression: this will be done by subsequent calls of | ||||
inflate(). | inflate(). | ||||
*/ | */ | ||||
extern int EXPORT inflateSync OF((z_streamp strm)); | static int EXPORT inflateSync OF((z_streamp strm)); | ||||
/* | /* | ||||
Skips invalid compressed data until the special marker (see deflate() | Skips invalid compressed data until the special marker (see deflate() | ||||
above) can be found, or until all available input is skipped. No output | above) can be found, or until all available input is skipped. No output | ||||
is provided. | is provided. | ||||
inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR | inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR | ||||
if no more input was provided, Z_DATA_ERROR if no marker has been found, | if no more input was provided, Z_DATA_ERROR if no marker has been found, | ||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success | ||||
case, the application may save the current current value of total_in which | case, the application may save the current current value of total_in which | ||||
indicates where valid compressed data was found. In the error case, the | indicates where valid compressed data was found. In the error case, the | ||||
application may repeatedly call inflateSync, providing more input each time, | application may repeatedly call inflateSync, providing more input each time, | ||||
until success or end of the input data. | until success or end of the input data. | ||||
*/ | */ | ||||
extern int EXPORT inflateReset OF((z_streamp strm)); | static int EXPORT inflateReset OF((z_streamp strm)); | ||||
/* | /* | ||||
This function is equivalent to inflateEnd followed by inflateInit, | This function is equivalent to inflateEnd followed by inflateInit, | ||||
but does not free and reallocate all the internal decompression state. | but does not free and reallocate all the internal decompression state. | ||||
The stream will keep attributes that may have been set by inflateInit2. | The stream will keep attributes that may have been set by inflateInit2. | ||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source | inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source | ||||
stream state was inconsistent (such as zalloc or state being NULL). | stream state was inconsistent (such as zalloc or state being NULL). | ||||
*/ | */ | ||||
extern int inflateIncomp OF((z_stream *strm)); | static int inflateIncomp OF((z_stream *strm)); | ||||
/* | /* | ||||
This function adds the data at next_in (avail_in bytes) to the output | This function adds the data at next_in (avail_in bytes) to the output | ||||
history without performing any output. There must be no pending output, | history without performing any output. There must be no pending output, | ||||
and the decompressor must be expecting to see the start of a block. | and the decompressor must be expecting to see the start of a block. | ||||
Calling this function is equivalent to decompressing a stored block | Calling this function is equivalent to decompressing a stored block | ||||
containing the data at next_in (except that the data is not output). | containing the data at next_in (except that the data is not output). | ||||
*/ | */ | ||||
/* utility functions */ | /* utility functions */ | ||||
/* | /* | ||||
The following utility functions are implemented on top of the | The following utility functions are implemented on top of the | ||||
basic stream-oriented functions. To simplify the interface, some | basic stream-oriented functions. To simplify the interface, some | ||||
default options are assumed (compression level, window size, | default options are assumed (compression level, window size, | ||||
standard memory allocation functions). The source code of these | standard memory allocation functions). The source code of these | ||||
utility functions can easily be modified if you need special options. | utility functions can easily be modified if you need special options. | ||||
*/ | */ | ||||
extern int EXPORT compress OF((Bytef *dest, uLongf *destLen, | static int EXPORT compress OF((Bytef *dest, uLongf *destLen, | ||||
const Bytef *source, uLong sourceLen)); | const Bytef *source, uLong sourceLen)); | ||||
/* | /* | ||||
Compresses the source buffer into the destination buffer. sourceLen is | Compresses the source buffer into the destination buffer. sourceLen is | ||||
the byte length of the source buffer. Upon entry, destLen is the total | 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 | 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 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the | ||||
compressed buffer. | compressed buffer. | ||||
This function can be used to compress a whole file at once if the | This function can be used to compress a whole file at once if the | ||||
input file is mmap'ed. | input file is mmap'ed. | ||||
compress returns Z_OK if success, Z_MEM_ERROR if there was not | compress returns Z_OK if success, Z_MEM_ERROR if there was not | ||||
enough memory, Z_BUF_ERROR if there was not enough room in the output | enough memory, Z_BUF_ERROR if there was not enough room in the output | ||||
buffer. | buffer. | ||||
*/ | */ | ||||
extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen, | static int EXPORT uncompress OF((Bytef *dest, uLongf *destLen, | ||||
const Bytef *source, uLong sourceLen)); | const Bytef *source, uLong sourceLen)); | ||||
/* | /* | ||||
Decompresses the source buffer into the destination buffer. sourceLen is | Decompresses the source buffer into the destination buffer. sourceLen is | ||||
the byte length of the source buffer. Upon entry, destLen is the total | 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 | size of the destination buffer, which must be large enough to hold the | ||||
entire uncompressed data. (The size of the uncompressed data must have | entire uncompressed data. (The size of the uncompressed data must have | ||||
been saved previously by the compressor and transmitted to the decompressor | been saved previously by the compressor and transmitted to the decompressor | ||||
by some mechanism outside the scope of this compression library.) | by some mechanism outside the scope of this compression library.) | ||||
Upon exit, destLen is the actual size of the compressed buffer. | Upon exit, destLen is the actual size of the compressed buffer. | ||||
This function can be used to decompress a whole file at once if the | This function can be used to decompress a whole file at once if the | ||||
input file is mmap'ed. | input file is mmap'ed. | ||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not | ||||
enough memory, Z_BUF_ERROR if there was not enough room in the output | enough memory, Z_BUF_ERROR if there was not enough room in the output | ||||
buffer, or Z_DATA_ERROR if the input data was corrupted. | buffer, or Z_DATA_ERROR if the input data was corrupted. | ||||
*/ | */ | ||||
typedef voidp gzFile; | typedef voidp gzFile; | ||||
extern gzFile EXPORT gzopen OF((const char *path, const char *mode)); | static gzFile EXPORT gzopen OF((const char *path, const char *mode)); | ||||
/* | /* | ||||
Opens a gzip (.gz) file for reading or writing. The mode parameter | 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 | is as in fopen ("rb" or "wb") but can also include a compression level | ||||
("wb9"). gzopen can be used to read a file which is not in gzip format; | ("wb9"). gzopen can be used to read a file which is not in gzip format; | ||||
in this case gzread will directly read from the file without decompression. | in this case gzread will directly read from the file without decompression. | ||||
gzopen returns NULL if the file could not be opened or if there was | gzopen returns NULL if the file could not be opened or if there was | ||||
insufficient memory to allocate the (de)compression state; errno | insufficient memory to allocate the (de)compression state; errno | ||||
can be checked to distinguish the two cases (if errno is zero, the | can be checked to distinguish the two cases (if errno is zero, the | ||||
zlib error is Z_MEM_ERROR). | zlib error is Z_MEM_ERROR). | ||||
*/ | */ | ||||
extern gzFile EXPORT gzdopen OF((int fd, const char *mode)); | static gzFile EXPORT gzdopen OF((int fd, const char *mode)); | ||||
/* | /* | ||||
gzdopen() associates a gzFile with the file descriptor fd. File | gzdopen() associates a gzFile with the file descriptor fd. File | ||||
descriptors are obtained from calls like open, dup, creat, pipe or | descriptors are obtained from calls like open, dup, creat, pipe or | ||||
fileno (in the file has been previously opened with fopen). | fileno (in the file has been previously opened with fopen). | ||||
The mode parameter is as in gzopen. | The mode parameter is as in gzopen. | ||||
The next call of gzclose on the returned gzFile will also close the | The next call of gzclose on the returned gzFile will also close the | ||||
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file | file descriptor fd, just like fclose(fdopen(fd), mode) closes the file | ||||
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). | descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). | ||||
gzdopen returns NULL if there was insufficient memory to allocate | gzdopen returns NULL if there was insufficient memory to allocate | ||||
the (de)compression state. | the (de)compression state. | ||||
*/ | */ | ||||
extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | static int EXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | ||||
/* | /* | ||||
Reads the given number of uncompressed bytes from the compressed file. | Reads the given number of uncompressed bytes from the compressed file. | ||||
If the input file was not in gzip format, gzread copies the given number | If the input file was not in gzip format, gzread copies the given number | ||||
of bytes into the buffer. | of bytes into the buffer. | ||||
gzread returns the number of uncompressed bytes actually read (0 for | gzread returns the number of uncompressed bytes actually read (0 for | ||||
end of file, -1 for error). */ | end of file, -1 for error). */ | ||||
extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len)); | static int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len)); | ||||
/* | /* | ||||
Writes the given number of uncompressed bytes into the compressed file. | Writes the given number of uncompressed bytes into the compressed file. | ||||
gzwrite returns the number of uncompressed bytes actually written | gzwrite returns the number of uncompressed bytes actually written | ||||
(0 in case of error). | (0 in case of error). | ||||
*/ | */ | ||||
extern int EXPORT gzflush OF((gzFile file, int flush)); | static int EXPORT gzflush OF((gzFile file, int flush)); | ||||
/* | /* | ||||
Flushes all pending output into the compressed file. The parameter | Flushes all pending output into the compressed file. The parameter | ||||
flush is as in the deflate() function. The return value is the zlib | flush is as in the deflate() function. The return value is the zlib | ||||
error number (see function gzerror below). gzflush returns Z_OK if | error number (see function gzerror below). gzflush returns Z_OK if | ||||
the flush parameter is Z_FINISH and all output could be flushed. | the flush parameter is Z_FINISH and all output could be flushed. | ||||
gzflush should be called only when strictly necessary because it can | gzflush should be called only when strictly necessary because it can | ||||
degrade compression. | degrade compression. | ||||
*/ | */ | ||||
extern int EXPORT gzclose OF((gzFile file)); | static int EXPORT gzclose OF((gzFile file)); | ||||
/* | /* | ||||
Flushes all pending output if necessary, closes the compressed file | Flushes all pending output if necessary, closes the compressed file | ||||
and deallocates all the (de)compression state. The return value is the zlib | and deallocates all the (de)compression state. The return value is the zlib | ||||
error number (see function gzerror below). | error number (see function gzerror below). | ||||
*/ | */ | ||||
extern const char * EXPORT gzerror OF((gzFile file, int *errnum)); | static const char * EXPORT gzerror OF((gzFile file, int *errnum)); | ||||
/* | /* | ||||
Returns the error message for the last error which occurred 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 occurred in the filesystem and not in the compression library, | error occurred in the filesystem 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. | ||||
*/ | */ | ||||
/* checksum functions */ | /* checksum functions */ | ||||
/* | /* | ||||
These functions are not related to compression but are exported | These functions are not related to compression but are exported | ||||
anyway because they might be useful in applications using the | anyway because they might be useful in applications using the | ||||
compression library. | compression library. | ||||
*/ | */ | ||||
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); | static uLong EXPORT 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 | ||||
the required initial value for the checksum. | the required initial value for the checksum. | ||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed | ||||
much faster. Usage example: | much faster. Usage example: | ||||
uLong adler = adler32(0L, Z_NULL, 0); | uLong adler = adler32(0L, Z_NULL, 0); | ||||
while (read_buffer(buffer, length) != EOF) { | while (read_buffer(buffer, length) != EOF) { | ||||
adler = adler32(adler, buffer, length); | adler = adler32(adler, buffer, length); | ||||
} | } | ||||
if (adler != original_adler) error(); | if (adler != original_adler) error(); | ||||
*/ | */ | ||||
#if 0 | #if 0 | ||||
extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); | static uLong EXPORT 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 with the bytes buf[0..len-1] and return the updated | ||||
crc. If buf is NULL, this function returns the required initial value | crc. If buf is NULL, this function returns the required initial value | ||||
for the crc. Pre- and post-conditioning (one's complement) is performed | for the crc. Pre- and post-conditioning (one's complement) is performed | ||||
within this function so it shouldn't be done by the application. | 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); | ||||
while (read_buffer(buffer, length) != EOF) { | while (read_buffer(buffer, length) != EOF) { | ||||
crc = crc32(crc, buffer, length); | crc = crc32(crc, buffer, length); | ||||
} | } | ||||
if (crc != original_crc) error(); | if (crc != original_crc) error(); | ||||
*/ | */ | ||||
#endif | #endif | ||||
/* various hacks, don't look :) */ | /* various hacks, don't look :) */ | ||||
/* deflateInit and inflateInit are macros to allow checking the zlib version | /* deflateInit and inflateInit are macros to allow checking the zlib version | ||||
* and the compiler's view of z_stream: | * and the compiler's view of z_stream: | ||||
*/ | */ | ||||
extern int EXPORT deflateInit_ OF((z_streamp strm, int level, | static int EXPORT deflateInit_ OF((z_streamp strm, int level, | ||||
const char *version, int stream_size)); | const char *version, int stream_size)); | ||||
extern int EXPORT inflateInit_ OF((z_streamp strm, | static int EXPORT inflateInit_ OF((z_streamp strm, | ||||
const char *version, int stream_size)); | const char *version, int stream_size)); | ||||
extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method, | static int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method, | ||||
int windowBits, int memLevel, int strategy, | int windowBits, int memLevel, int strategy, | ||||
const char *version, int stream_size)); | const char *version, int stream_size)); | ||||
extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | static int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | ||||
const char *version, int stream_size)); | const char *version, int stream_size)); | ||||
#define deflateInit(strm, level) \ | #define deflateInit(strm, level) \ | ||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) | ||||
#define inflateInit(strm) \ | #define inflateInit(strm) \ | ||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) | inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) | ||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | ||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | ||||
(strategy), ZLIB_VERSION, sizeof(z_stream)) | (strategy), ZLIB_VERSION, sizeof(z_stream)) | ||||
Show All 15 Lines |
(see comment on sys/conf/kern.pre.mk: I think we could eliminate this need).