xref: /openbsd-src/lib/libz/zlib.h (revision a225ed82339557610307f4ad61f79271a8594b78)
12af503bcStholo /* zlib.h -- interface of the 'zlib' general purpose compression library
2d5e7bdb5Stb   version 1.3.1.1, January xxth, 2024
32af503bcStholo 
4d5e7bdb5Stb   Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
52af503bcStholo 
62af503bcStholo   This software is provided 'as-is', without any express or implied
72af503bcStholo   warranty.  In no event will the authors be held liable for any damages
82af503bcStholo   arising from the use of this software.
92af503bcStholo 
102af503bcStholo   Permission is granted to anyone to use this software for any purpose,
112af503bcStholo   including commercial applications, and to alter it and redistribute it
122af503bcStholo   freely, subject to the following restrictions:
132af503bcStholo 
142af503bcStholo   1. The origin of this software must not be misrepresented; you must not
152af503bcStholo      claim that you wrote the original software. If you use this software
162af503bcStholo      in a product, an acknowledgment in the product documentation would be
172af503bcStholo      appreciated but is not required.
182af503bcStholo   2. Altered source versions must be plainly marked as such, and must not be
192af503bcStholo      misrepresented as being the original software.
202af503bcStholo   3. This notice may not be removed or altered from any source distribution.
212af503bcStholo 
222af503bcStholo   Jean-loup Gailly        Mark Adler
2315ce0796Smillert   jloup@gzip.org          madler@alumni.caltech.edu
242af503bcStholo 
252af503bcStholo 
262af503bcStholo   The data format used by the zlib library is described by RFCs (Request for
2736f395ceStb   Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
2836f395ceStb   (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
292af503bcStholo */
302af503bcStholo 
3185c48e79Shenning #ifndef ZLIB_H
3285c48e79Shenning #define ZLIB_H
332af503bcStholo 
3415ce0796Smillert #include "zconf.h"
3515ce0796Smillert 
362af503bcStholo #ifdef __cplusplus
372af503bcStholo extern "C" {
382af503bcStholo #endif
392af503bcStholo 
40d5e7bdb5Stb #define ZLIB_VERSION "1.3.1.1-motley"
41d5e7bdb5Stb #define ZLIB_VERNUM 0x1311
4236f395ceStb #define ZLIB_VER_MAJOR 1
43f0c5c122Stb #define ZLIB_VER_MINOR 3
44d5e7bdb5Stb #define ZLIB_VER_REVISION 1
4562a6fda7Stb #define ZLIB_VER_SUBREVISION 1
462af503bcStholo 
472af503bcStholo /*
482af503bcStholo     The 'zlib' compression library provides in-memory compression and
4936f395ceStb   decompression functions, including integrity checks of the uncompressed data.
5036f395ceStb   This version of the library supports only one compression method (deflation)
5136f395ceStb   but other algorithms will be added later and will have the same stream
5236f395ceStb   interface.
532af503bcStholo 
5436f395ceStb     Compression can be done in a single step if the buffers are large enough,
5536f395ceStb   or can be done by repeated calls of the compression function.  In the latter
5636f395ceStb   case, the application must provide more input and/or consume the output
572af503bcStholo   (providing more output space) before each call.
582af503bcStholo 
59b967fc35Sdjm     The compressed data format used by default by the in-memory functions is
60b967fc35Sdjm   the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
61b967fc35Sdjm   around a deflate stream, which is itself documented in RFC 1951.
6285c48e79Shenning 
6315ce0796Smillert     The library also supports reading and writing files in gzip (.gz) format
6485c48e79Shenning   with an interface similar to that of stdio using the functions that start
6585c48e79Shenning   with "gz".  The gzip format is different from the zlib format.  gzip is a
6685c48e79Shenning   gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
6785c48e79Shenning 
6836f395ceStb     This library can optionally read and write gzip and raw deflate streams in
6936f395ceStb   memory as well.
70b967fc35Sdjm 
7185c48e79Shenning     The zlib format was designed to be compact and fast for use in memory
7285c48e79Shenning   and on communications channels.  The gzip format was designed for single-
7385c48e79Shenning   file compression on file systems, has a larger header than zlib to maintain
7485c48e79Shenning   directory information, and uses a different, slower check method than zlib.
7585c48e79Shenning 
7615ce0796Smillert     The library does not install any signal handler.  The decoder checks
7736f395ceStb   the consistency of the compressed data, so the library should never crash
7836f395ceStb   even in the case of corrupted input.
792af503bcStholo */
802af503bcStholo 
81a04ea15dStb typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
82a04ea15dStb typedef void   (*free_func)(voidpf opaque, voidpf address);
832af503bcStholo 
842af503bcStholo struct internal_state;
852af503bcStholo 
862af503bcStholo typedef struct z_stream_s {
87f08045d9Sjca     z_const Bytef *next_in;     /* next input byte */
882af503bcStholo     uInt     avail_in;  /* number of bytes available at next_in */
89009e2686Stb     uLong    total_in;  /* total number of input bytes read so far */
902af503bcStholo 
9136f395ceStb     Bytef    *next_out; /* next output byte will go here */
922af503bcStholo     uInt     avail_out; /* remaining free space at next_out */
93009e2686Stb     uLong    total_out; /* total number of bytes output so far */
942af503bcStholo 
95f08045d9Sjca     z_const char *msg;  /* last error message, NULL if no error */
962af503bcStholo     struct internal_state FAR *state; /* not visible by applications */
972af503bcStholo 
982af503bcStholo     alloc_func zalloc;  /* used to allocate the internal state */
992af503bcStholo     free_func  zfree;   /* used to free the internal state */
1002af503bcStholo     voidpf     opaque;  /* private data object passed to zalloc and zfree */
1012af503bcStholo 
10236f395ceStb     int     data_type;  /* best guess about the data type: binary or text
10336f395ceStb                            for deflate, or the decoding state for inflate */
10436f395ceStb     uLong   adler;      /* Adler-32 or CRC-32 value of the uncompressed data */
1052af503bcStholo     uLong   reserved;   /* reserved for future use */
1062af503bcStholo } z_stream;
1072af503bcStholo 
1082af503bcStholo typedef z_stream FAR *z_streamp;
1092af503bcStholo 
1102af503bcStholo /*
111d76b9bfaSmillert      gzip header information passed to and from zlib routines.  See RFC 1952
112d76b9bfaSmillert   for more details on the meanings of these fields.
113d76b9bfaSmillert */
114d76b9bfaSmillert typedef struct gz_header_s {
115d76b9bfaSmillert     int     text;       /* true if compressed data believed to be text */
116d76b9bfaSmillert     uLong   time;       /* modification time */
117d76b9bfaSmillert     int     xflags;     /* extra flags (not used when writing a gzip file) */
118d76b9bfaSmillert     int     os;         /* operating system */
119d76b9bfaSmillert     Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
120d76b9bfaSmillert     uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
121d76b9bfaSmillert     uInt    extra_max;  /* space at extra (only when reading header) */
122d76b9bfaSmillert     Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
123d76b9bfaSmillert     uInt    name_max;   /* space at name (only when reading header) */
124d76b9bfaSmillert     Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
125d76b9bfaSmillert     uInt    comm_max;   /* space at comment (only when reading header) */
126d76b9bfaSmillert     int     hcrc;       /* true if there was or will be a header crc */
127d76b9bfaSmillert     int     done;       /* true when done reading gzip header (not used
128d76b9bfaSmillert                            when writing a gzip file) */
129d76b9bfaSmillert } gz_header;
130d76b9bfaSmillert 
131d76b9bfaSmillert typedef gz_header FAR *gz_headerp;
132d76b9bfaSmillert 
133d76b9bfaSmillert /*
13436f395ceStb      The application must update next_in and avail_in when avail_in has dropped
13536f395ceStb    to zero.  It must update next_out and avail_out when avail_out has dropped
13636f395ceStb    to zero.  The application must initialize zalloc, zfree and opaque before
13736f395ceStb    calling the init function.  All other fields are set by the compression
13836f395ceStb    library and must not be updated by the application.
1392af503bcStholo 
1402af503bcStholo      The opaque value provided by the application will be passed as the first
1412af503bcStholo    parameter for calls of zalloc and zfree.  This can be useful for custom
1422af503bcStholo    memory management.  The compression library attaches no meaning to the
1432af503bcStholo    opaque value.
1442af503bcStholo 
1452af503bcStholo      zalloc must return Z_NULL if there is not enough memory for the object.
14615ce0796Smillert    If zlib is used in a multi-threaded application, zalloc and zfree must be
14736f395ceStb    thread safe.  In that case, zlib is thread-safe.  When zalloc and zfree are
14836f395ceStb    Z_NULL on entry to the initialization function, they are set to internal
14936f395ceStb    routines that use the standard library functions malloc() and free().
15015ce0796Smillert 
1512af503bcStholo      On 16-bit systems, the functions zalloc and zfree must be able to allocate
15236f395ceStb    exactly 65536 bytes, but will not be required to allocate more than this if
15336f395ceStb    the symbol MAXSEG_64K is defined (see zconf.h).  WARNING: On MSDOS, pointers
15436f395ceStb    returned by zalloc for objects of exactly 65536 bytes *must* have their
15536f395ceStb    offset normalized to zero.  The default allocation function provided by this
15636f395ceStb    library ensures this (see zutil.c).  To reduce memory requirements and avoid
15736f395ceStb    any allocation of 64K objects, at the expense of compression ratio, compile
15836f395ceStb    the library with -DMAX_WBITS=14 (see zconf.h).
1592af503bcStholo 
16036f395ceStb      The fields total_in and total_out can be used for statistics or progress
16136f395ceStb    reports.  After compression, total_in holds the total size of the
16236f395ceStb    uncompressed data and may be saved for use by the decompressor (particularly
16336f395ceStb    if the decompressor wants to decompress everything in a single step).
1642af503bcStholo */
1652af503bcStholo 
1662af503bcStholo                         /* constants */
1672af503bcStholo 
1682af503bcStholo #define Z_NO_FLUSH      0
16936f395ceStb #define Z_PARTIAL_FLUSH 1
1702af503bcStholo #define Z_SYNC_FLUSH    2
1712af503bcStholo #define Z_FULL_FLUSH    3
1722af503bcStholo #define Z_FINISH        4
17385c48e79Shenning #define Z_BLOCK         5
17436f395ceStb #define Z_TREES         6
17585c48e79Shenning /* Allowed flush values; see deflate() and inflate() below for details */
1762af503bcStholo 
1772af503bcStholo #define Z_OK            0
1782af503bcStholo #define Z_STREAM_END    1
1792af503bcStholo #define Z_NEED_DICT     2
1802af503bcStholo #define Z_ERRNO        (-1)
1812af503bcStholo #define Z_STREAM_ERROR (-2)
1822af503bcStholo #define Z_DATA_ERROR   (-3)
1832af503bcStholo #define Z_MEM_ERROR    (-4)
1842af503bcStholo #define Z_BUF_ERROR    (-5)
1852af503bcStholo #define Z_VERSION_ERROR (-6)
18636f395ceStb /* Return codes for the compression/decompression functions. Negative values
18736f395ceStb  * are errors, positive values are used for special but normal events.
1882af503bcStholo  */
1892af503bcStholo 
1902af503bcStholo #define Z_NO_COMPRESSION         0
1912af503bcStholo #define Z_BEST_SPEED             1
1922af503bcStholo #define Z_BEST_COMPRESSION       9
1932af503bcStholo #define Z_DEFAULT_COMPRESSION  (-1)
1942af503bcStholo /* compression levels */
1952af503bcStholo 
1962af503bcStholo #define Z_FILTERED            1
1972af503bcStholo #define Z_HUFFMAN_ONLY        2
19885c48e79Shenning #define Z_RLE                 3
199d76b9bfaSmillert #define Z_FIXED               4
2002af503bcStholo #define Z_DEFAULT_STRATEGY    0
2012af503bcStholo /* compression strategy; see deflateInit2() below for details */
2022af503bcStholo 
2032af503bcStholo #define Z_BINARY   0
204d76b9bfaSmillert #define Z_TEXT     1
205d76b9bfaSmillert #define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
2062af503bcStholo #define Z_UNKNOWN  2
20736f395ceStb /* Possible values of the data_type field for deflate() */
2082af503bcStholo 
2092af503bcStholo #define Z_DEFLATED   8
2102af503bcStholo /* The deflate compression method (the only one supported in this version) */
2112af503bcStholo 
2122af503bcStholo #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
2132af503bcStholo 
2142af503bcStholo #define zlib_version zlibVersion()
2152af503bcStholo /* for compatibility with versions < 1.0.2 */
2162af503bcStholo 
21736f395ceStb 
2182af503bcStholo                         /* basic functions */
2192af503bcStholo 
220a04ea15dStb ZEXTERN const char * ZEXPORT zlibVersion(void);
2212af503bcStholo /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
22236f395ceStb    If the first character differs, the library code actually used is not
22336f395ceStb    compatible with the zlib.h header file used by the application.  This check
22436f395ceStb    is automatically made by deflateInit and inflateInit.
2252af503bcStholo  */
2262af503bcStholo 
2272af503bcStholo /*
228a04ea15dStb ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level);
2292af503bcStholo 
2302af503bcStholo      Initializes the internal stream state for compression.  The fields
23136f395ceStb    zalloc, zfree and opaque must be initialized before by the caller.  If
23236f395ceStb    zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
233af63d907Stb    allocation functions.  total_in, total_out, adler, and msg are initialized.
2342af503bcStholo 
2352af503bcStholo      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
23636f395ceStb    1 gives best speed, 9 gives best compression, 0 gives no compression at all
23736f395ceStb    (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
23836f395ceStb    requests a default compromise between speed and compression (currently
23936f395ceStb    equivalent to level 6).
2402af503bcStholo 
24136f395ceStb      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
24236f395ceStb    memory, Z_STREAM_ERROR if level is not a valid compression level, or
2432af503bcStholo    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
24436f395ceStb    with the version assumed by the caller (ZLIB_VERSION).  msg is set to null
24536f395ceStb    if there is no error message.  deflateInit does not perform any compression:
24636f395ceStb    this will be done by deflate().
2472af503bcStholo */
2482af503bcStholo 
2492af503bcStholo 
250a04ea15dStb ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush);
2512af503bcStholo /*
25215ce0796Smillert     deflate compresses as much data as possible, and stops when the input
25336f395ceStb   buffer becomes empty or the output buffer becomes full.  It may introduce
25436f395ceStb   some output latency (reading input without producing any output) except when
25515ce0796Smillert   forced to flush.
25615ce0796Smillert 
25715ce0796Smillert     The detailed semantics are as follows.  deflate performs one or both of the
25815ce0796Smillert   following actions:
2592af503bcStholo 
2602af503bcStholo   - Compress more input starting at next_in and update next_in and avail_in
2612af503bcStholo     accordingly.  If not all input can be processed (because there is not
2622af503bcStholo     enough room in the output buffer), next_in and avail_in are updated and
2632af503bcStholo     processing will resume at this point for the next call of deflate().
2642af503bcStholo 
26536f395ceStb   - Generate more output starting at next_out and update next_out and avail_out
2662af503bcStholo     accordingly.  This action is forced if the parameter flush is non zero.
2672af503bcStholo     Forcing flush frequently degrades the compression ratio, so this parameter
26836f395ceStb     should be set only when necessary.  Some output may be provided even if
26936f395ceStb     flush is zero.
2702af503bcStholo 
2712af503bcStholo     Before the call of deflate(), the application should ensure that at least
27236f395ceStb   one of the actions is possible, by providing more input and/or consuming more
27336f395ceStb   output, and updating avail_in or avail_out accordingly; avail_out should
27436f395ceStb   never be zero before the call.  The application can consume the compressed
27536f395ceStb   output when it wants, for example when the output buffer is full (avail_out
27636f395ceStb   == 0), or after each call of deflate().  If deflate returns Z_OK and with
27736f395ceStb   zero avail_out, it must be called again after making room in the output
27836f395ceStb   buffer because there might be more output pending. See deflatePending(),
2798bda5813Stb   which can be used if desired to determine whether or not there is more output
28036f395ceStb   in that case.
2812af503bcStholo 
282d76b9bfaSmillert     Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
2830742bdbfSsobrado   decide how much data to accumulate before producing output, in order to
284d76b9bfaSmillert   maximize compression.
285d76b9bfaSmillert 
28615ce0796Smillert     If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
28715ce0796Smillert   flushed to the output buffer and the output is aligned on a byte boundary, so
28836f395ceStb   that the decompressor can get all input data available so far.  (In
28936f395ceStb   particular avail_in is zero after the call if enough output space has been
29036f395ceStb   provided before the call.) Flushing may degrade compression for some
29136f395ceStb   compression algorithms and so it should be used only when necessary.  This
29236f395ceStb   completes the current deflate block and follows it with an empty stored block
29336f395ceStb   that is three bits plus filler bits to the next byte, followed by four bytes
29436f395ceStb   (00 00 ff ff).
29536f395ceStb 
29636f395ceStb     If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
29736f395ceStb   output buffer, but the output is not aligned to a byte boundary.  All of the
29836f395ceStb   input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
29936f395ceStb   This completes the current deflate block and follows it with an empty fixed
30036f395ceStb   codes block that is 10 bits long.  This assures that enough bytes are output
30136f395ceStb   in order for the decompressor to finish the block before the empty fixed
30236f395ceStb   codes block.
30336f395ceStb 
30436f395ceStb     If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
30536f395ceStb   for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
30636f395ceStb   seven bits of the current block are held to be written as the next byte after
30736f395ceStb   the next deflate block is completed.  In this case, the decompressor may not
30836f395ceStb   be provided enough bits at this point in order to complete decompression of
30936f395ceStb   the data provided so far to the compressor.  It may need to wait for the next
31036f395ceStb   block to be emitted.  This is for advanced applications that need to control
31136f395ceStb   the emission of deflate blocks.
31215ce0796Smillert 
31315ce0796Smillert     If flush is set to Z_FULL_FLUSH, all output is flushed as with
31415ce0796Smillert   Z_SYNC_FLUSH, and the compression state is reset so that decompression can
31515ce0796Smillert   restart from this point if previous compressed data has been damaged or if
31615ce0796Smillert   random access is desired.  Using Z_FULL_FLUSH too often can seriously degrade
317d76b9bfaSmillert   compression.
31815ce0796Smillert 
31915ce0796Smillert     If deflate returns with avail_out == 0, this function must be called again
32015ce0796Smillert   with the same value of the flush parameter and more output space (updated
32115ce0796Smillert   avail_out), until the flush is complete (deflate returns with non-zero
32285c48e79Shenning   avail_out).  In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
3230f55603fStb   avail_out is greater than six when the flush marker begins, in order to avoid
3240f55603fStb   repeated flush markers upon calling deflate() again when avail_out == 0.
3252af503bcStholo 
326f503157cSmillert     If the parameter flush is set to Z_FINISH, pending input is processed,
32736f395ceStb   pending output is flushed and deflate returns with Z_STREAM_END if there was
32836f395ceStb   enough output space.  If deflate returns with Z_OK or Z_BUF_ERROR, this
32936f395ceStb   function must be called again with Z_FINISH and more output space (updated
33036f395ceStb   avail_out) but no more input data, until it returns with Z_STREAM_END or an
33136f395ceStb   error.  After deflate has returned Z_STREAM_END, the only possible operations
33236f395ceStb   on the stream are deflateReset or deflateEnd.
3332af503bcStholo 
33436f395ceStb     Z_FINISH can be used in the first deflate call after deflateInit if all the
33536f395ceStb   compression is to be done in a single step.  In order to complete in one
33636f395ceStb   call, avail_out must be at least the value returned by deflateBound (see
33736f395ceStb   below).  Then deflate is guaranteed to return Z_STREAM_END.  If not enough
33836f395ceStb   output space is provided, deflate will not return Z_STREAM_END, and it must
33936f395ceStb   be called again as described above.
3402af503bcStholo 
34136f395ceStb     deflate() sets strm->adler to the Adler-32 checksum of all input read
34236f395ceStb   so far (that is, total_in bytes).  If a gzip stream is being generated, then
34336f395ceStb   strm->adler will be the CRC-32 checksum of the input read so far.  (See
34436f395ceStb   deflateInit2 below.)
34515ce0796Smillert 
346d76b9bfaSmillert     deflate() may update strm->data_type if it can make a good guess about
34736f395ceStb   the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
34836f395ceStb   considered binary.  This field is only for information purposes and does not
34936f395ceStb   affect the compression algorithm in any manner.
3502af503bcStholo 
3512af503bcStholo     deflate() returns Z_OK if some progress has been made (more input
3522af503bcStholo   processed or more output produced), Z_STREAM_END if all input has been
3532af503bcStholo   consumed and all output has been produced (only when flush is set to
3542af503bcStholo   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
35536f395ceStb   if next_in or next_out was Z_NULL or the state was inadvertently written over
35636f395ceStb   by the application), or Z_BUF_ERROR if no progress is possible (for example
35736f395ceStb   avail_in or avail_out was zero).  Note that Z_BUF_ERROR is not fatal, and
35836f395ceStb   deflate() can be called again with more input and more output space to
35936f395ceStb   continue compressing.
3602af503bcStholo */
3612af503bcStholo 
3622af503bcStholo 
363a04ea15dStb ZEXTERN int ZEXPORT deflateEnd(z_streamp strm);
3642af503bcStholo /*
3652af503bcStholo      All dynamically allocated data structures for this stream are freed.
36636f395ceStb    This function discards any unprocessed input and does not flush any pending
36736f395ceStb    output.
3682af503bcStholo 
3692af503bcStholo      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
3702af503bcStholo    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
37136f395ceStb    prematurely (some input or output was discarded).  In the error case, msg
37236f395ceStb    may be set but then points to a static string (which must not be
3732af503bcStholo    deallocated).
3742af503bcStholo */
3752af503bcStholo 
3762af503bcStholo 
3772af503bcStholo /*
378a04ea15dStb ZEXTERN int ZEXPORT inflateInit(z_streamp strm);
3792af503bcStholo 
3802af503bcStholo      Initializes the internal stream state for decompression.  The fields
38115ce0796Smillert    next_in, avail_in, zalloc, zfree and opaque must be initialized before by
38236f395ceStb    the caller.  In the current version of inflate, the provided input is not
38336f395ceStb    read or consumed.  The allocation of a sliding window will be deferred to
38436f395ceStb    the first call of inflate (if the decompression does not complete on the
38536f395ceStb    first call).  If zalloc and zfree are set to Z_NULL, inflateInit updates
386af63d907Stb    them to use default allocation functions.  total_in, total_out, adler, and
387af63d907Stb    msg are initialized.
3882af503bcStholo 
38915ce0796Smillert      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
39015ce0796Smillert    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
39136f395ceStb    version assumed by the caller, or Z_STREAM_ERROR if the parameters are
39236f395ceStb    invalid, such as a null pointer to the structure.  msg is set to null if
39336f395ceStb    there is no error message.  inflateInit does not perform any decompression.
39436f395ceStb    Actual decompression will be done by inflate().  So next_in, and avail_in,
39536f395ceStb    next_out, and avail_out are unused and unchanged.  The current
39636f395ceStb    implementation of inflateInit() does not process any header information --
39736f395ceStb    that is deferred until inflate() is called.
3982af503bcStholo */
3992af503bcStholo 
4002af503bcStholo 
401a04ea15dStb ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush);
4022af503bcStholo /*
40315ce0796Smillert     inflate decompresses as much data as possible, and stops when the input
40485c48e79Shenning   buffer becomes empty or the output buffer becomes full.  It may introduce
40585c48e79Shenning   some output latency (reading input without producing any output) except when
40685c48e79Shenning   forced to flush.
40715ce0796Smillert 
40815ce0796Smillert   The detailed semantics are as follows.  inflate performs one or both of the
40915ce0796Smillert   following actions:
4102af503bcStholo 
4112af503bcStholo   - Decompress more input starting at next_in and update next_in and avail_in
4122af503bcStholo     accordingly.  If not all input can be processed (because there is not
41336f395ceStb     enough room in the output buffer), then next_in and avail_in are updated
41436f395ceStb     accordingly, and processing will resume at this point for the next call of
41536f395ceStb     inflate().
4162af503bcStholo 
41736f395ceStb   - Generate more output starting at next_out and update next_out and avail_out
41836f395ceStb     accordingly.  inflate() provides as much output as possible, until there is
41936f395ceStb     no more input data or no more space in the output buffer (see below about
42036f395ceStb     the flush parameter).
4212af503bcStholo 
4222af503bcStholo     Before the call of inflate(), the application should ensure that at least
42336f395ceStb   one of the actions is possible, by providing more input and/or consuming more
42436f395ceStb   output, and updating the next_* and avail_* values accordingly.  If the
42536f395ceStb   caller of inflate() does not provide both available input and available
42636f395ceStb   output space, it is possible that there will be no progress made.  The
42736f395ceStb   application can consume the uncompressed output when it wants, for example
42836f395ceStb   when the output buffer is full (avail_out == 0), or after each call of
42936f395ceStb   inflate().  If inflate returns Z_OK and with zero avail_out, it must be
43036f395ceStb   called again after making room in the output buffer because there might be
43136f395ceStb   more output pending.
4322af503bcStholo 
43336f395ceStb     The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
43436f395ceStb   Z_BLOCK, or Z_TREES.  Z_SYNC_FLUSH requests that inflate() flush as much
43536f395ceStb   output as possible to the output buffer.  Z_BLOCK requests that inflate()
43636f395ceStb   stop if and when it gets to the next deflate block boundary.  When decoding
43736f395ceStb   the zlib or gzip format, this will cause inflate() to return immediately
43836f395ceStb   after the header and before the first block.  When doing a raw inflate,
43936f395ceStb   inflate() will go ahead and process the first block, and will return when it
44036f395ceStb   gets to the end of that block, or when it runs out of data.
44185c48e79Shenning 
44285c48e79Shenning     The Z_BLOCK option assists in appending to or combining deflate streams.
44336f395ceStb   To assist in this, on return inflate() always sets strm->data_type to the
44436f395ceStb   number of unused bits in the last byte taken from strm->next_in, plus 64 if
44536f395ceStb   inflate() is currently decoding the last block in the deflate stream, plus
44636f395ceStb   128 if inflate() returned immediately after decoding an end-of-block code or
44736f395ceStb   decoding the complete header up to just before the first byte of the deflate
44836f395ceStb   stream.  The end-of-block will not be indicated until all of the uncompressed
44936f395ceStb   data from that block has been written to strm->next_out.  The number of
45036f395ceStb   unused bits may in general be greater than seven, except when bit 7 of
45136f395ceStb   data_type is set, in which case the number of unused bits will be less than
45236f395ceStb   eight.  data_type is set as noted here every time inflate() returns for all
45336f395ceStb   flush options, and so can be used to determine the amount of currently
45436f395ceStb   consumed input in bits.
45536f395ceStb 
45636f395ceStb     The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
45736f395ceStb   end of each deflate block header is reached, before any actual data in that
45836f395ceStb   block is decoded.  This allows the caller to determine the length of the
45936f395ceStb   deflate block header for later use in random access within a deflate block.
46036f395ceStb   256 is added to the value of strm->data_type when inflate() returns
46136f395ceStb   immediately after reaching the end of the deflate block header.
4622af503bcStholo 
4632af503bcStholo     inflate() should normally be called until it returns Z_STREAM_END or an
46436f395ceStb   error.  However if all decompression is to be performed in a single step (a
46536f395ceStb   single call of inflate), the parameter flush should be set to Z_FINISH.  In
46636f395ceStb   this case all pending input is processed and all pending output is flushed;
46736f395ceStb   avail_out must be large enough to hold all of the uncompressed data for the
46836f395ceStb   operation to complete.  (The size of the uncompressed data may have been
46936f395ceStb   saved by the compressor for this purpose.)  The use of Z_FINISH is not
47036f395ceStb   required to perform an inflation in one step.  However it may be used to
47136f395ceStb   inform inflate that a faster approach can be used for the single inflate()
47236f395ceStb   call.  Z_FINISH also informs inflate to not maintain a sliding window if the
47336f395ceStb   stream completes, which reduces inflate's memory footprint.  If the stream
47436f395ceStb   does not complete, either because not all of the stream is provided or not
47536f395ceStb   enough output space is provided, then a sliding window will be allocated and
47636f395ceStb   inflate() can be called again to continue the operation as if Z_NO_FLUSH had
47736f395ceStb   been used.
4782af503bcStholo 
47985c48e79Shenning      In this implementation, inflate() always flushes as much output as
48085c48e79Shenning   possible to the output buffer, and always uses the faster approach on the
48136f395ceStb   first call.  So the effects of the flush parameter in this implementation are
48236f395ceStb   on the return value of inflate() as noted below, when inflate() returns early
48336f395ceStb   when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
48436f395ceStb   memory for a sliding window when Z_FINISH is used.
48585c48e79Shenning 
48685c48e79Shenning      If a preset dictionary is needed after this call (see inflateSetDictionary
48736f395ceStb   below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
48885c48e79Shenning   chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
48936f395ceStb   strm->adler to the Adler-32 checksum of all output produced so far (that is,
49085c48e79Shenning   total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
49136f395ceStb   below.  At the end of the stream, inflate() checks that its computed Adler-32
49285c48e79Shenning   checksum is equal to that saved by the compressor and returns Z_STREAM_END
49385c48e79Shenning   only if the checksum is correct.
49485c48e79Shenning 
49536f395ceStb     inflate() can decompress and check either zlib-wrapped or gzip-wrapped
49636f395ceStb   deflate data.  The header type is detected automatically, if requested when
49736f395ceStb   initializing with inflateInit2().  Any information contained in the gzip
49836f395ceStb   header is not retained unless inflateGetHeader() is used.  When processing
49936f395ceStb   gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
50036f395ceStb   produced so far.  The CRC-32 is checked against the gzip trailer, as is the
50136f395ceStb   uncompressed length, modulo 2^32.
50215ce0796Smillert 
50315ce0796Smillert     inflate() returns Z_OK if some progress has been made (more input processed
50415ce0796Smillert   or more output produced), Z_STREAM_END if the end of the compressed data has
50515ce0796Smillert   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
50615ce0796Smillert   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
50785c48e79Shenning   corrupted (input stream not conforming to the zlib format or incorrect check
50836f395ceStb   value, in which case strm->msg points to a string with a more specific
50936f395ceStb   error), Z_STREAM_ERROR if the stream structure was inconsistent (for example
51036f395ceStb   next_in or next_out was Z_NULL, or the state was inadvertently written over
51136f395ceStb   by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR
51236f395ceStb   if no progress was possible or if there was not enough room in the output
51336f395ceStb   buffer when Z_FINISH is used.  Note that Z_BUF_ERROR is not fatal, and
51485c48e79Shenning   inflate() can be called again with more input and more output space to
51536f395ceStb   continue decompressing.  If Z_DATA_ERROR is returned, the application may
51636f395ceStb   then call inflateSync() to look for a good compression block if a partial
51736f395ceStb   recovery of the data is to be attempted.
5182af503bcStholo */
5192af503bcStholo 
5202af503bcStholo 
521a04ea15dStb ZEXTERN int ZEXPORT inflateEnd(z_streamp strm);
5222af503bcStholo /*
5232af503bcStholo      All dynamically allocated data structures for this stream are freed.
52436f395ceStb    This function discards any unprocessed input and does not flush any pending
52536f395ceStb    output.
5262af503bcStholo 
52736f395ceStb      inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state
52836f395ceStb    was inconsistent.
5292af503bcStholo */
5302af503bcStholo 
53136f395ceStb 
5322af503bcStholo                         /* Advanced functions */
5332af503bcStholo 
5342af503bcStholo /*
5352af503bcStholo     The following functions are needed only in some special applications.
5362af503bcStholo */
5372af503bcStholo 
5382af503bcStholo /*
539a04ea15dStb ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
5402af503bcStholo                                  int level,
5412af503bcStholo                                  int method,
5422af503bcStholo                                  int windowBits,
5432af503bcStholo                                  int memLevel,
544a04ea15dStb                                  int strategy);
5452af503bcStholo 
5462af503bcStholo      This is another version of deflateInit with more compression options.  The
547703d4924Stb    fields zalloc, zfree and opaque must be initialized before by the caller.
5482af503bcStholo 
5492af503bcStholo      The method parameter is the compression method.  It must be Z_DEFLATED in
55015ce0796Smillert    this version of the library.
5512af503bcStholo 
5522af503bcStholo      The windowBits parameter is the base two logarithm of the window size
5532af503bcStholo    (the size of the history buffer).  It should be in the range 8..15 for this
55415ce0796Smillert    version of the library.  Larger values of this parameter result in better
55515ce0796Smillert    compression at the expense of memory usage.  The default value is 15 if
55615ce0796Smillert    deflateInit is used instead.
5572af503bcStholo 
55836f395ceStb      For the current implementation of deflate(), a windowBits value of 8 (a
55936f395ceStb    window size of 256 bytes) is not supported.  As a result, a request for 8
56036f395ceStb    will result in 9 (a 512-byte window).  In that case, providing 8 to
56136f395ceStb    inflateInit2() will result in an error when the zlib header with 9 is
56236f395ceStb    checked against the initialization of inflate().  The remedy is to not use 8
56336f395ceStb    with deflateInit2() with this initialization, or at least in that case use 9
56436f395ceStb    with inflateInit2().
56536f395ceStb 
56685c48e79Shenning      windowBits can also be -8..-15 for raw deflate.  In this case, -windowBits
56785c48e79Shenning    determines the window size.  deflate() will then generate raw deflate data
56836f395ceStb    with no zlib header or trailer, and will not compute a check value.
56985c48e79Shenning 
57085c48e79Shenning      windowBits can also be greater than 15 for optional gzip encoding.  Add
57185c48e79Shenning    16 to windowBits to write a simple gzip header and trailer around the
57285c48e79Shenning    compressed data instead of a zlib wrapper.  The gzip header will have no
57336f395ceStb    file name, no extra data, no comment, no modification time (set to zero), no
57436f395ceStb    header crc, and the operating system will be set to the appropriate value,
57536f395ceStb    if the operating system was determined at compile time.  If a gzip stream is
57636f395ceStb    being written, strm->adler is a CRC-32 instead of an Adler-32.
57736f395ceStb 
57836f395ceStb      For raw deflate or gzip encoding, a request for a 256-byte window is
57936f395ceStb    rejected as invalid, since only the zlib header provides a means of
58036f395ceStb    transmitting the window size to the decompressor.
58185c48e79Shenning 
5822af503bcStholo      The memLevel parameter specifies how much memory should be allocated
58336f395ceStb    for the internal compression state.  memLevel=1 uses minimum memory but is
58436f395ceStb    slow and reduces compression ratio; memLevel=9 uses maximum memory for
58536f395ceStb    optimal speed.  The default value is 8.  See zconf.h for total memory usage
58636f395ceStb    as a function of windowBits and memLevel.
5872af503bcStholo 
5882af503bcStholo      The strategy parameter is used to tune the compression algorithm.  Use the
5892af503bcStholo    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
59030bbea86Stb    filter (or predictor), Z_RLE to limit match distances to one (run-length
59130bbea86Stb    encoding), or Z_HUFFMAN_ONLY to force Huffman encoding only (no string
59230bbea86Stb    matching).  Filtered data consists mostly of small values with a somewhat
59330bbea86Stb    random distribution, as produced by the PNG filters.  In this case, the
59430bbea86Stb    compression algorithm is tuned to compress them better.  The effect of
59530bbea86Stb    Z_FILTERED is to force more Huffman coding and less string matching than the
59630bbea86Stb    default; it is intermediate between Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY.
59730bbea86Stb    Z_RLE is almost as fast as Z_HUFFMAN_ONLY, but should give better
59830bbea86Stb    compression for PNG image data than Huffman only.  The degree of string
59930bbea86Stb    matching from most to none is: Z_DEFAULT_STRATEGY, Z_FILTERED, Z_RLE, then
60006968976Stb    Z_HUFFMAN_ONLY. The strategy parameter affects the compression ratio but
60106968976Stb    never the correctness of the compressed output, even if it is not set
60206968976Stb    optimally for the given data.  Z_FIXED uses the default string matching, but
60306968976Stb    prevents the use of dynamic Huffman codes, allowing for a simpler decoder
60406968976Stb    for special applications.
6052af503bcStholo 
60615ce0796Smillert      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
60736f395ceStb    memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
60836f395ceStb    method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
60936f395ceStb    incompatible with the version assumed by the caller (ZLIB_VERSION).  msg is
61036f395ceStb    set to null if there is no error message.  deflateInit2 does not perform any
61136f395ceStb    compression: this will be done by deflate().
6122af503bcStholo */
6132af503bcStholo 
614a04ea15dStb ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
6152af503bcStholo                                          const Bytef *dictionary,
616a04ea15dStb                                          uInt  dictLength);
6172af503bcStholo /*
61815ce0796Smillert      Initializes the compression dictionary from the given byte sequence
61936f395ceStb    without producing any compressed output.  When using the zlib format, this
62036f395ceStb    function must be called immediately after deflateInit, deflateInit2 or
62136f395ceStb    deflateReset, and before any call of deflate.  When doing raw deflate, this
62236f395ceStb    function must be called either before any call of deflate, or immediately
62336f395ceStb    after the completion of a deflate block, i.e. after all input has been
62436f395ceStb    consumed and all output has been delivered when using any of the flush
62536f395ceStb    options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH.  The
62636f395ceStb    compressor and decompressor must use exactly the same dictionary (see
62736f395ceStb    inflateSetDictionary).
62815ce0796Smillert 
6292af503bcStholo      The dictionary should consist of strings (byte sequences) that are likely
6302af503bcStholo    to be encountered later in the data to be compressed, with the most commonly
6312af503bcStholo    used strings preferably put towards the end of the dictionary.  Using a
63215ce0796Smillert    dictionary is most useful when the data to be compressed is short and can be
63315ce0796Smillert    predicted with good accuracy; the data can then be compressed better than
63415ce0796Smillert    with the default empty dictionary.
63515ce0796Smillert 
63615ce0796Smillert      Depending on the size of the compression data structures selected by
63715ce0796Smillert    deflateInit or deflateInit2, a part of the dictionary may in effect be
63836f395ceStb    discarded, for example if the dictionary is larger than the window size
63936f395ceStb    provided in deflateInit or deflateInit2.  Thus the strings most likely to be
64036f395ceStb    useful should be put at the end of the dictionary, not at the front.  In
64136f395ceStb    addition, the current implementation of deflate will use at most the window
64236f395ceStb    size minus 262 bytes of the provided dictionary.
64315ce0796Smillert 
64436f395ceStb      Upon return of this function, strm->adler is set to the Adler-32 value
6452af503bcStholo    of the dictionary; the decompressor may later use this value to determine
64636f395ceStb    which dictionary has been used by the compressor.  (The Adler-32 value
6472af503bcStholo    applies to the whole dictionary even if only a subset of the dictionary is
64885c48e79Shenning    actually used by the compressor.) If a raw deflate was requested, then the
64936f395ceStb    Adler-32 value is not computed and strm->adler is not set.
6502af503bcStholo 
6512af503bcStholo      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
65236f395ceStb    parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
65315ce0796Smillert    inconsistent (for example if deflate has already been called for this stream
65436f395ceStb    or if not at a block boundary for raw deflate).  deflateSetDictionary does
65536f395ceStb    not perform any compression: this will be done by deflate().
65636f395ceStb */
65736f395ceStb 
658a04ea15dStb ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm,
65936f395ceStb                                          Bytef *dictionary,
660a04ea15dStb                                          uInt  *dictLength);
66136f395ceStb /*
66236f395ceStb      Returns the sliding dictionary being maintained by deflate.  dictLength is
66336f395ceStb    set to the number of bytes in the dictionary, and that many bytes are copied
66436f395ceStb    to dictionary.  dictionary must have enough space, where 32768 bytes is
66536f395ceStb    always enough.  If deflateGetDictionary() is called with dictionary equal to
66636f395ceStb    Z_NULL, then only the dictionary length is returned, and nothing is copied.
6678bda5813Stb    Similarly, if dictLength is Z_NULL, then it is not set.
66836f395ceStb 
66936f395ceStb      deflateGetDictionary() may return a length less than the window size, even
67036f395ceStb    when more than the window size in input has been provided. It may return up
67136f395ceStb    to 258 bytes less in that case, due to how zlib's implementation of deflate
67236f395ceStb    manages the sliding window and lookahead for matches, where matches can be
67336f395ceStb    up to 258 bytes long. If the application needs the last window-size bytes of
67436f395ceStb    input, then that would need to be saved by the application outside of zlib.
67536f395ceStb 
67636f395ceStb      deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
67736f395ceStb    stream state is inconsistent.
6782af503bcStholo */
6792af503bcStholo 
680a04ea15dStb ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
681a04ea15dStb                                 z_streamp source);
6822af503bcStholo /*
68315ce0796Smillert      Sets the destination stream as a complete copy of the source stream.
6842af503bcStholo 
6852af503bcStholo      This function can be useful when several compression strategies will be
6862af503bcStholo    tried, for example when there are several ways of pre-processing the input
6872af503bcStholo    data with a filter.  The streams that will be discarded should then be freed
6882af503bcStholo    by calling deflateEnd.  Note that deflateCopy duplicates the internal
68936f395ceStb    compression state which can be quite large, so this strategy is slow and can
69036f395ceStb    consume lots of memory.
6912af503bcStholo 
6922af503bcStholo      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
6932af503bcStholo    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
69436f395ceStb    (such as zalloc being Z_NULL).  msg is left unchanged in both source and
6952af503bcStholo    destination.
6962af503bcStholo */
6972af503bcStholo 
698a04ea15dStb ZEXTERN int ZEXPORT deflateReset(z_streamp strm);
6992af503bcStholo /*
70036f395ceStb      This function is equivalent to deflateEnd followed by deflateInit, but
70136f395ceStb    does not free and reallocate the internal compression state.  The stream
70236f395ceStb    will leave the compression level and any other attributes that may have been
703af63d907Stb    set unchanged.  total_in, total_out, adler, and msg are initialized.
7042af503bcStholo 
7052af503bcStholo      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
70636f395ceStb    stream state was inconsistent (such as zalloc or state being Z_NULL).
7072af503bcStholo */
7082af503bcStholo 
709a04ea15dStb ZEXTERN int ZEXPORT deflateParams(z_streamp strm,
71015ce0796Smillert                                   int level,
711a04ea15dStb                                   int strategy);
7122af503bcStholo /*
71315ce0796Smillert      Dynamically update the compression level and compression strategy.  The
71436f395ceStb    interpretation of level and strategy is as in deflateInit2().  This can be
71515ce0796Smillert    used to switch between compression and straight copy of the input data, or
71636f395ceStb    to switch to a different kind of input data requiring a different strategy.
71736f395ceStb    If the compression approach (which is a function of the level) or the
718703d4924Stb    strategy is changed, and if there have been any deflate() calls since the
719703d4924Stb    state was initialized or reset, then the input available so far is
720703d4924Stb    compressed with the old level and strategy using deflate(strm, Z_BLOCK).
721703d4924Stb    There are three approaches for the compression levels 0, 1..3, and 4..9
722703d4924Stb    respectively.  The new level and strategy will take effect at the next call
723703d4924Stb    of deflate().
7242af503bcStholo 
72536f395ceStb      If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
72636f395ceStb    not have enough output space to complete, then the parameter change will not
72736f395ceStb    take effect.  In this case, deflateParams() can be called again with the
72836f395ceStb    same parameters and more output space to try again.
7292af503bcStholo 
73036f395ceStb      In order to assure a change in the parameters on the first try, the
73136f395ceStb    deflate stream should be flushed using deflate() with Z_BLOCK or other flush
73236f395ceStb    request until strm.avail_out is not zero, before calling deflateParams().
73336f395ceStb    Then no more input data should be provided before the deflateParams() call.
73436f395ceStb    If this is done, the old level and strategy will be applied to the data
73536f395ceStb    compressed before deflateParams(), and the new level and strategy will be
73628d10565Stb    applied to the data compressed after deflateParams().
73736f395ceStb 
73836f395ceStb      deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
73936f395ceStb    state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
74036f395ceStb    there was not enough output space to complete the compression of the
74136f395ceStb    available input data before a change in the strategy or approach.  Note that
74236f395ceStb    in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
74336f395ceStb    value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
74436f395ceStb    retried with more output space.
7452af503bcStholo */
7462af503bcStholo 
747a04ea15dStb ZEXTERN int ZEXPORT deflateTune(z_streamp strm,
748d76b9bfaSmillert                                 int good_length,
749d76b9bfaSmillert                                 int max_lazy,
750d76b9bfaSmillert                                 int nice_length,
751a04ea15dStb                                 int max_chain);
752d76b9bfaSmillert /*
753d76b9bfaSmillert      Fine tune deflate's internal compression parameters.  This should only be
754d76b9bfaSmillert    used by someone who understands the algorithm used by zlib's deflate for
755d76b9bfaSmillert    searching for the best matching string, and even then only by the most
756d76b9bfaSmillert    fanatic optimizer trying to squeeze out the last compressed bit for their
757d76b9bfaSmillert    specific input data.  Read the deflate.c source code for the meaning of the
758d76b9bfaSmillert    max_lazy, good_length, nice_length, and max_chain parameters.
759d76b9bfaSmillert 
760d76b9bfaSmillert      deflateTune() can be called after deflateInit() or deflateInit2(), and
761d76b9bfaSmillert    returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
762d76b9bfaSmillert  */
763d76b9bfaSmillert 
764a04ea15dStb ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm,
765a04ea15dStb                                    uLong sourceLen);
76685c48e79Shenning /*
76785c48e79Shenning      deflateBound() returns an upper bound on the compressed size after
76836f395ceStb    deflation of sourceLen bytes.  It must be called after deflateInit() or
76936f395ceStb    deflateInit2(), and after deflateSetHeader(), if used.  This would be used
77036f395ceStb    to allocate an output buffer for deflation in a single pass, and so would be
77136f395ceStb    called before deflate().  If that first deflate() call is provided the
77236f395ceStb    sourceLen input bytes, an output buffer allocated to the size returned by
77336f395ceStb    deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
77436f395ceStb    to return Z_STREAM_END.  Note that it is possible for the compressed size to
77536f395ceStb    be larger than the value returned by deflateBound() if flush options other
77636f395ceStb    than Z_FINISH or Z_NO_FLUSH are used.
77736f395ceStb */
77836f395ceStb 
779a04ea15dStb ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
78036f395ceStb                                    unsigned *pending,
781a04ea15dStb                                    int *bits);
78236f395ceStb /*
78336f395ceStb      deflatePending() returns the number of bytes and bits of output that have
78436f395ceStb    been generated, but not yet provided in the available output.  The bytes not
78536f395ceStb    provided would be due to the available output space having being consumed.
78636f395ceStb    The number of bits of output not provided are between 0 and 7, where they
78736f395ceStb    await more bits to join them in order to fill out a full byte.  If pending
78836f395ceStb    or bits are Z_NULL, then those values are not set.
78936f395ceStb 
79036f395ceStb      deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
79136f395ceStb    stream state was inconsistent.
79285c48e79Shenning  */
79385c48e79Shenning 
794*a225ed82Stb ZEXTERN int ZEXPORT deflateUsed(z_streamp strm,
795*a225ed82Stb                                 int *bits);
796*a225ed82Stb /*
797*a225ed82Stb      deflateUsed() returns in *bits the most recent number of deflate bits used
798*a225ed82Stb    in the last byte when flushing to a byte boundary. The result is in 1..8, or
799*a225ed82Stb    0 if there has not yet been a flush. This helps determine the location of
800*a225ed82Stb    the last bit of a deflate stream.
801*a225ed82Stb 
802*a225ed82Stb      deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source
803*a225ed82Stb    stream state was inconsistent.
804*a225ed82Stb  */
805*a225ed82Stb 
806a04ea15dStb ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
80785c48e79Shenning                                  int bits,
808a04ea15dStb                                  int value);
80985c48e79Shenning /*
81085c48e79Shenning      deflatePrime() inserts bits in the deflate output stream.  The intent
81136f395ceStb    is that this function is used to start off the deflate output with the bits
81236f395ceStb    leftover from a previous deflate stream when appending to it.  As such, this
81336f395ceStb    function can only be used for raw deflate, and must be used before the first
81436f395ceStb    deflate() call after a deflateInit2() or deflateReset().  bits must be less
81536f395ceStb    than or equal to 16, and that many of the least significant bits of value
81636f395ceStb    will be inserted in the output.
81785c48e79Shenning 
81836f395ceStb      deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
81936f395ceStb    room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
82036f395ceStb    source stream state was inconsistent.
82185c48e79Shenning */
82285c48e79Shenning 
823a04ea15dStb ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm,
824a04ea15dStb                                      gz_headerp head);
825d76b9bfaSmillert /*
826d76b9bfaSmillert      deflateSetHeader() provides gzip header information for when a gzip
827d76b9bfaSmillert    stream is requested by deflateInit2().  deflateSetHeader() may be called
828d76b9bfaSmillert    after deflateInit2() or deflateReset() and before the first call of
829d76b9bfaSmillert    deflate().  The text, time, os, extra field, name, and comment information
830d76b9bfaSmillert    in the provided gz_header structure are written to the gzip header (xflag is
831d76b9bfaSmillert    ignored -- the extra flags are set according to the compression level).  The
832d76b9bfaSmillert    caller must assure that, if not Z_NULL, name and comment are terminated with
833d76b9bfaSmillert    a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
834d76b9bfaSmillert    available there.  If hcrc is true, a gzip header crc is included.  Note that
835d76b9bfaSmillert    the current versions of the command-line version of gzip (up through version
836d76b9bfaSmillert    1.3.x) do not support header crc's, and will report that it is a "multi-part
837d76b9bfaSmillert    gzip file" and give up.
838d76b9bfaSmillert 
839d76b9bfaSmillert      If deflateSetHeader is not used, the default gzip header has text false,
840af63d907Stb    the time set to zero, and os set to the current operating system, with no
841af63d907Stb    extra, name, or comment fields.  The gzip header is returned to the default
842af63d907Stb    state by deflateReset().
843d76b9bfaSmillert 
844d76b9bfaSmillert      deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
845d76b9bfaSmillert    stream state was inconsistent.
846d76b9bfaSmillert */
847d76b9bfaSmillert 
8482af503bcStholo /*
849a04ea15dStb ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
850a04ea15dStb                                  int windowBits);
8512af503bcStholo 
85215ce0796Smillert      This is another version of inflateInit with an extra parameter.  The
85315ce0796Smillert    fields next_in, avail_in, zalloc, zfree and opaque must be initialized
85415ce0796Smillert    before by the caller.
8552af503bcStholo 
8562af503bcStholo      The windowBits parameter is the base two logarithm of the maximum window
8572af503bcStholo    size (the size of the history buffer).  It should be in the range 8..15 for
85815ce0796Smillert    this version of the library.  The default value is 15 if inflateInit is used
85985c48e79Shenning    instead.  windowBits must be greater than or equal to the windowBits value
86085c48e79Shenning    provided to deflateInit2() while compressing, or it must be equal to 15 if
86185c48e79Shenning    deflateInit2() was not used.  If a compressed stream with a larger window
86285c48e79Shenning    size is given as input, inflate() will return with the error code
86385c48e79Shenning    Z_DATA_ERROR instead of trying to allocate a larger window.
86485c48e79Shenning 
86536f395ceStb      windowBits can also be zero to request that inflate use the window size in
86636f395ceStb    the zlib header of the compressed stream.
86736f395ceStb 
86885c48e79Shenning      windowBits can also be -8..-15 for raw inflate.  In this case, -windowBits
86985c48e79Shenning    determines the window size.  inflate() will then process raw deflate data,
87085c48e79Shenning    not looking for a zlib or gzip header, not generating a check value, and not
87185c48e79Shenning    looking for any check values for comparison at the end of the stream.  This
87285c48e79Shenning    is for use with other formats that use the deflate compressed data format
87385c48e79Shenning    such as zip.  Those formats provide their own check values.  If a custom
87485c48e79Shenning    format is developed using the raw deflate format for compressed data, it is
87536f395ceStb    recommended that a check value such as an Adler-32 or a CRC-32 be applied to
87685c48e79Shenning    the uncompressed data as is done in the zlib, gzip, and zip formats.  For
87785c48e79Shenning    most applications, the zlib format should be used as is.  Note that comments
87885c48e79Shenning    above on the use in deflateInit2() applies to the magnitude of windowBits.
87985c48e79Shenning 
88085c48e79Shenning      windowBits can also be greater than 15 for optional gzip decoding.  Add
88185c48e79Shenning    32 to windowBits to enable zlib and gzip decoding with automatic header
88285c48e79Shenning    detection, or add 16 to decode only the gzip format (the zlib format will
88336f395ceStb    return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is a
88436f395ceStb    CRC-32 instead of an Adler-32.  Unlike the gunzip utility and gzread() (see
885703d4924Stb    below), inflate() will *not* automatically decode concatenated gzip members.
886703d4924Stb    inflate() will return Z_STREAM_END at the end of the gzip member.  The state
887703d4924Stb    would need to be reset to continue decoding a subsequent gzip member.  This
888703d4924Stb    *must* be done if there is more data after a gzip member, in order for the
889703d4924Stb    decompression to be compliant with the gzip standard (RFC 1952).
8902af503bcStholo 
89115ce0796Smillert      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
89236f395ceStb    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
89336f395ceStb    version assumed by the caller, or Z_STREAM_ERROR if the parameters are
89436f395ceStb    invalid, such as a null pointer to the structure.  msg is set to null if
89536f395ceStb    there is no error message.  inflateInit2 does not perform any decompression
89636f395ceStb    apart from possibly reading the zlib header if present: actual decompression
89736f395ceStb    will be done by inflate().  (So next_in and avail_in may be modified, but
89836f395ceStb    next_out and avail_out are unused and unchanged.) The current implementation
89936f395ceStb    of inflateInit2() does not process any header information -- that is
90036f395ceStb    deferred until inflate() is called.
9012af503bcStholo */
9022af503bcStholo 
903a04ea15dStb ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
9042af503bcStholo                                          const Bytef *dictionary,
905a04ea15dStb                                          uInt  dictLength);
9062af503bcStholo /*
90715ce0796Smillert      Initializes the decompression dictionary from the given uncompressed byte
908d76b9bfaSmillert    sequence.  This function must be called immediately after a call of inflate,
909d76b9bfaSmillert    if that call returned Z_NEED_DICT.  The dictionary chosen by the compressor
91036f395ceStb    can be determined from the Adler-32 value returned by that call of inflate.
911d76b9bfaSmillert    The compressor and decompressor must use exactly the same dictionary (see
91236f395ceStb    deflateSetDictionary).  For raw inflate, this function can be called at any
91336f395ceStb    time to set the dictionary.  If the provided dictionary is smaller than the
91436f395ceStb    window and there is already data in the window, then the provided dictionary
91536f395ceStb    will amend what's there.  The application must insure that the dictionary
91636f395ceStb    that was used for compression is provided.
9172af503bcStholo 
9182af503bcStholo      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
91936f395ceStb    parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
9202af503bcStholo    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
92136f395ceStb    expected one (incorrect Adler-32 value).  inflateSetDictionary does not
9222af503bcStholo    perform any decompression: this will be done by subsequent calls of
9232af503bcStholo    inflate().
9242af503bcStholo */
9252af503bcStholo 
926a04ea15dStb ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm,
92736f395ceStb                                          Bytef *dictionary,
928a04ea15dStb                                          uInt  *dictLength);
92936f395ceStb /*
93036f395ceStb      Returns the sliding dictionary being maintained by inflate.  dictLength is
93136f395ceStb    set to the number of bytes in the dictionary, and that many bytes are copied
93236f395ceStb    to dictionary.  dictionary must have enough space, where 32768 bytes is
93336f395ceStb    always enough.  If inflateGetDictionary() is called with dictionary equal to
93436f395ceStb    Z_NULL, then only the dictionary length is returned, and nothing is copied.
9358bda5813Stb    Similarly, if dictLength is Z_NULL, then it is not set.
93636f395ceStb 
93736f395ceStb      inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
93836f395ceStb    stream state is inconsistent.
93936f395ceStb */
94036f395ceStb 
941a04ea15dStb ZEXTERN int ZEXPORT inflateSync(z_streamp strm);
9422af503bcStholo /*
94336f395ceStb      Skips invalid compressed data until a possible full flush point (see above
94436f395ceStb    for the description of deflate with Z_FULL_FLUSH) can be found, or until all
94515ce0796Smillert    available input is skipped.  No output is provided.
9462af503bcStholo 
94736f395ceStb      inflateSync searches for a 00 00 FF FF pattern in the compressed data.
94836f395ceStb    All full flush points have this pattern, but not all occurrences of this
94936f395ceStb    pattern are full flush points.
95036f395ceStb 
95136f395ceStb      inflateSync returns Z_OK if a possible full flush point has been found,
95236f395ceStb    Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
95336f395ceStb    has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
95462a6fda7Stb    In the success case, the application may save the current value of total_in
95562a6fda7Stb    which indicates where valid compressed data was found.  In the error case,
95662a6fda7Stb    the application may repeatedly call inflateSync, providing more input each
95762a6fda7Stb    time, until success or end of the input data.
9582af503bcStholo */
9592af503bcStholo 
960a04ea15dStb ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
961a04ea15dStb                                 z_streamp source);
96285c48e79Shenning /*
96385c48e79Shenning      Sets the destination stream as a complete copy of the source stream.
96485c48e79Shenning 
96585c48e79Shenning      This function can be useful when randomly accessing a large stream.  The
96685c48e79Shenning    first pass through the stream can periodically record the inflate state,
96785c48e79Shenning    allowing restarting inflate at those points when randomly accessing the
96885c48e79Shenning    stream.
96985c48e79Shenning 
97085c48e79Shenning      inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
97185c48e79Shenning    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
97236f395ceStb    (such as zalloc being Z_NULL).  msg is left unchanged in both source and
97385c48e79Shenning    destination.
97485c48e79Shenning */
97585c48e79Shenning 
976a04ea15dStb ZEXTERN int ZEXPORT inflateReset(z_streamp strm);
9772af503bcStholo /*
9782af503bcStholo      This function is equivalent to inflateEnd followed by inflateInit,
97936f395ceStb    but does not free and reallocate the internal decompression state.  The
98036f395ceStb    stream will keep attributes that may have been set by inflateInit2.
981af63d907Stb    total_in, total_out, adler, and msg are initialized.
9822af503bcStholo 
9832af503bcStholo      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
98436f395ceStb    stream state was inconsistent (such as zalloc or state being Z_NULL).
98536f395ceStb */
98636f395ceStb 
987a04ea15dStb ZEXTERN int ZEXPORT inflateReset2(z_streamp strm,
988a04ea15dStb                                   int windowBits);
98936f395ceStb /*
99036f395ceStb      This function is the same as inflateReset, but it also permits changing
99136f395ceStb    the wrap and window size requests.  The windowBits parameter is interpreted
99236f395ceStb    the same as it is for inflateInit2.  If the window size is changed, then the
99336f395ceStb    memory allocated for the window is freed, and the window will be reallocated
99436f395ceStb    by inflate() if needed.
99536f395ceStb 
99636f395ceStb      inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
99736f395ceStb    stream state was inconsistent (such as zalloc or state being Z_NULL), or if
99836f395ceStb    the windowBits parameter is invalid.
9992af503bcStholo */
10002af503bcStholo 
1001a04ea15dStb ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
1002d76b9bfaSmillert                                  int bits,
1003a04ea15dStb                                  int value);
100485c48e79Shenning /*
1005d76b9bfaSmillert      This function inserts bits in the inflate input stream.  The intent is
1006d76b9bfaSmillert    that this function is used to start inflating at a bit position in the
1007d76b9bfaSmillert    middle of a byte.  The provided bits will be used before any bytes are used
1008d76b9bfaSmillert    from next_in.  This function should only be used with raw inflate, and
1009d76b9bfaSmillert    should be used before the first inflate() call after inflateInit2() or
1010d76b9bfaSmillert    inflateReset().  bits must be less than or equal to 16, and that many of the
1011d76b9bfaSmillert    least significant bits of value will be inserted in the input.
1012d76b9bfaSmillert 
101336f395ceStb      If bits is negative, then the input stream bit buffer is emptied.  Then
101436f395ceStb    inflatePrime() can be called again to put bits in the buffer.  This is used
101536f395ceStb    to clear out bits leftover after feeding inflate a block description prior
101636f395ceStb    to feeding inflate codes.
101736f395ceStb 
1018d76b9bfaSmillert      inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
1019d76b9bfaSmillert    stream state was inconsistent.
1020d76b9bfaSmillert */
1021d76b9bfaSmillert 
1022a04ea15dStb ZEXTERN long ZEXPORT inflateMark(z_streamp strm);
102336f395ceStb /*
102436f395ceStb      This function returns two values, one in the lower 16 bits of the return
102536f395ceStb    value, and the other in the remaining upper bits, obtained by shifting the
102636f395ceStb    return value down 16 bits.  If the upper value is -1 and the lower value is
102736f395ceStb    zero, then inflate() is currently decoding information outside of a block.
102836f395ceStb    If the upper value is -1 and the lower value is non-zero, then inflate is in
102936f395ceStb    the middle of a stored block, with the lower value equaling the number of
103036f395ceStb    bytes from the input remaining to copy.  If the upper value is not -1, then
103136f395ceStb    it is the number of bits back from the current bit position in the input of
103236f395ceStb    the code (literal or length/distance pair) currently being processed.  In
103336f395ceStb    that case the lower value is the number of bytes already emitted for that
103436f395ceStb    code.
103536f395ceStb 
103636f395ceStb      A code is being processed if inflate is waiting for more input to complete
103736f395ceStb    decoding of the code, or if it has completed decoding but is waiting for
103836f395ceStb    more output space to write the literal or match data.
103936f395ceStb 
104036f395ceStb      inflateMark() is used to mark locations in the input data for random
104136f395ceStb    access, which may be at bit positions, and to note those cases where the
104236f395ceStb    output of a code may span boundaries of random access blocks.  The current
104336f395ceStb    location in the input stream can be determined from avail_in and data_type
104436f395ceStb    as noted in the description for the Z_BLOCK flush parameter for inflate.
104536f395ceStb 
104636f395ceStb      inflateMark returns the value noted above, or -65536 if the provided
104736f395ceStb    source stream state was inconsistent.
104836f395ceStb */
104936f395ceStb 
1050a04ea15dStb ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
1051a04ea15dStb                                      gz_headerp head);
1052d76b9bfaSmillert /*
1053d76b9bfaSmillert      inflateGetHeader() requests that gzip header information be stored in the
1054d76b9bfaSmillert    provided gz_header structure.  inflateGetHeader() may be called after
1055d76b9bfaSmillert    inflateInit2() or inflateReset(), and before the first call of inflate().
1056d76b9bfaSmillert    As inflate() processes the gzip stream, head->done is zero until the header
1057d76b9bfaSmillert    is completed, at which time head->done is set to one.  If a zlib stream is
1058d76b9bfaSmillert    being decoded, then head->done is set to -1 to indicate that there will be
105936f395ceStb    no gzip header information forthcoming.  Note that Z_BLOCK or Z_TREES can be
106036f395ceStb    used to force inflate() to return immediately after header processing is
106136f395ceStb    complete and before any actual data is decompressed.
1062d76b9bfaSmillert 
1063d76b9bfaSmillert      The text, time, xflags, and os fields are filled in with the gzip header
1064d76b9bfaSmillert    contents.  hcrc is set to true if there is a header CRC.  (The header CRC
1065d76b9bfaSmillert    was valid if done is set to one.) If extra is not Z_NULL, then extra_max
1066d76b9bfaSmillert    contains the maximum number of bytes to write to extra.  Once done is true,
1067d76b9bfaSmillert    extra_len contains the actual extra field length, and extra contains the
1068d76b9bfaSmillert    extra field, or that field truncated if extra_max is less than extra_len.
1069d76b9bfaSmillert    If name is not Z_NULL, then up to name_max characters are written there,
1070d76b9bfaSmillert    terminated with a zero unless the length is greater than name_max.  If
1071d76b9bfaSmillert    comment is not Z_NULL, then up to comm_max characters are written there,
107236f395ceStb    terminated with a zero unless the length is greater than comm_max.  When any
107336f395ceStb    of extra, name, or comment are not Z_NULL and the respective field is not
107436f395ceStb    present in the header, then that field is set to Z_NULL to signal its
1075d76b9bfaSmillert    absence.  This allows the use of deflateSetHeader() with the returned
1076d76b9bfaSmillert    structure to duplicate the header.  However if those fields are set to
1077d76b9bfaSmillert    allocated memory, then the application will need to save those pointers
1078d76b9bfaSmillert    elsewhere so that they can be eventually freed.
1079d76b9bfaSmillert 
1080d76b9bfaSmillert      If inflateGetHeader is not used, then the header information is simply
1081d76b9bfaSmillert    discarded.  The header is always checked for validity, including the header
1082d76b9bfaSmillert    CRC if present.  inflateReset() will reset the process to discard the header
1083d76b9bfaSmillert    information.  The application would need to call inflateGetHeader() again to
1084d76b9bfaSmillert    retrieve the header from the next gzip stream.
1085d76b9bfaSmillert 
1086d76b9bfaSmillert      inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
1087d76b9bfaSmillert    stream state was inconsistent.
1088d76b9bfaSmillert */
1089d76b9bfaSmillert 
1090d76b9bfaSmillert /*
1091a04ea15dStb ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits,
1092a04ea15dStb                                     unsigned char FAR *window);
109385c48e79Shenning 
109485c48e79Shenning      Initialize the internal stream state for decompression using inflateBack()
109585c48e79Shenning    calls.  The fields zalloc, zfree and opaque in strm must be initialized
109685c48e79Shenning    before the call.  If zalloc and zfree are Z_NULL, then the default library-
109785c48e79Shenning    derived memory allocation routines are used.  windowBits is the base two
109885c48e79Shenning    logarithm of the window size, in the range 8..15.  window is a caller
109985c48e79Shenning    supplied buffer of that size.  Except for special applications where it is
110085c48e79Shenning    assured that deflate was used with small window sizes, windowBits must be 15
110185c48e79Shenning    and a 32K byte window must be supplied to be able to decompress general
110285c48e79Shenning    deflate streams.
110385c48e79Shenning 
110485c48e79Shenning      See inflateBack() for the usage of these routines.
110585c48e79Shenning 
110685c48e79Shenning      inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
110736f395ceStb    the parameters are invalid, Z_MEM_ERROR if the internal state could not be
110836f395ceStb    allocated, or Z_VERSION_ERROR if the version of the library does not match
110936f395ceStb    the version of the header file.
111085c48e79Shenning */
111185c48e79Shenning 
1112a04ea15dStb typedef unsigned (*in_func)(void FAR *,
1113a04ea15dStb                             z_const unsigned char FAR * FAR *);
1114a04ea15dStb typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned);
111585c48e79Shenning 
1116a04ea15dStb ZEXTERN int ZEXPORT inflateBack(z_streamp strm,
111785c48e79Shenning                                 in_func in, void FAR *in_desc,
1118a04ea15dStb                                 out_func out, void FAR *out_desc);
111985c48e79Shenning /*
112085c48e79Shenning      inflateBack() does a raw inflate with a single call using a call-back
112136f395ceStb    interface for input and output.  This is potentially more efficient than
112236f395ceStb    inflate() for file i/o applications, in that it avoids copying between the
112336f395ceStb    output and the sliding window by simply making the window itself the output
112436f395ceStb    buffer.  inflate() can be faster on modern CPUs when used with large
112536f395ceStb    buffers.  inflateBack() trusts the application to not change the output
112636f395ceStb    buffer passed by the output function, at least until inflateBack() returns.
112785c48e79Shenning 
112885c48e79Shenning      inflateBackInit() must be called first to allocate the internal state
112985c48e79Shenning    and to initialize the state with the user-provided window buffer.
113085c48e79Shenning    inflateBack() may then be used multiple times to inflate a complete, raw
113136f395ceStb    deflate stream with each call.  inflateBackEnd() is then called to free the
113236f395ceStb    allocated state.
113385c48e79Shenning 
113485c48e79Shenning      A raw deflate stream is one with no zlib or gzip header or trailer.
113585c48e79Shenning    This routine would normally be used in a utility that reads zip or gzip
113685c48e79Shenning    files and writes out uncompressed files.  The utility would decode the
113736f395ceStb    header and process the trailer on its own, hence this routine expects only
113836f395ceStb    the raw deflate stream to decompress.  This is different from the default
113936f395ceStb    behavior of inflate(), which expects a zlib header and trailer around the
114036f395ceStb    deflate stream.
114185c48e79Shenning 
114285c48e79Shenning      inflateBack() uses two subroutines supplied by the caller that are then
114385c48e79Shenning    called by inflateBack() for input and output.  inflateBack() calls those
114485c48e79Shenning    routines until it reads a complete deflate stream and writes out all of the
114585c48e79Shenning    uncompressed data, or until it encounters an error.  The function's
114685c48e79Shenning    parameters and return types are defined above in the in_func and out_func
114785c48e79Shenning    typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
114885c48e79Shenning    number of bytes of provided input, and a pointer to that input in buf.  If
114985c48e79Shenning    there is no input available, in() must return zero -- buf is ignored in that
115036f395ceStb    case -- and inflateBack() will return a buffer error.  inflateBack() will
115136f395ceStb    call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
115236f395ceStb    out() should return zero on success, or non-zero on failure.  If out()
115336f395ceStb    returns non-zero, inflateBack() will return with an error.  Neither in() nor
115436f395ceStb    out() are permitted to change the contents of the window provided to
115585c48e79Shenning    inflateBackInit(), which is also the buffer that out() uses to write from.
115685c48e79Shenning    The length written by out() will be at most the window size.  Any non-zero
115785c48e79Shenning    amount of input may be provided by in().
115885c48e79Shenning 
115985c48e79Shenning      For convenience, inflateBack() can be provided input on the first call by
116085c48e79Shenning    setting strm->next_in and strm->avail_in.  If that input is exhausted, then
116185c48e79Shenning    in() will be called.  Therefore strm->next_in must be initialized before
116285c48e79Shenning    calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called
116385c48e79Shenning    immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
116485c48e79Shenning    must also be initialized, and then if strm->avail_in is not zero, input will
116585c48e79Shenning    initially be taken from strm->next_in[0 ..  strm->avail_in - 1].
116685c48e79Shenning 
116785c48e79Shenning      The in_desc and out_desc parameters of inflateBack() is passed as the
116885c48e79Shenning    first parameter of in() and out() respectively when they are called.  These
116985c48e79Shenning    descriptors can be optionally used to pass any information that the caller-
117085c48e79Shenning    supplied in() and out() functions need to do their job.
117185c48e79Shenning 
117285c48e79Shenning      On return, inflateBack() will set strm->next_in and strm->avail_in to
117385c48e79Shenning    pass back any unused input that was provided by the last in() call.  The
117485c48e79Shenning    return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
117536f395ceStb    if in() or out() returned an error, Z_DATA_ERROR if there was a format error
117636f395ceStb    in the deflate stream (in which case strm->msg is set to indicate the nature
117736f395ceStb    of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
117836f395ceStb    In the case of Z_BUF_ERROR, an input or output error can be distinguished
117936f395ceStb    using strm->next_in which will be Z_NULL only if in() returned an error.  If
118036f395ceStb    strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
118136f395ceStb    non-zero.  (in() will always be called before out(), so strm->next_in is
118236f395ceStb    assured to be defined if out() returns non-zero.)  Note that inflateBack()
118336f395ceStb    cannot return Z_OK.
118485c48e79Shenning */
118585c48e79Shenning 
1186a04ea15dStb ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm);
118785c48e79Shenning /*
118885c48e79Shenning      All memory allocated by inflateBackInit() is freed.
118985c48e79Shenning 
119085c48e79Shenning      inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
119185c48e79Shenning    state was inconsistent.
119285c48e79Shenning */
119385c48e79Shenning 
1194a04ea15dStb ZEXTERN uLong ZEXPORT zlibCompileFlags(void);
119585c48e79Shenning /* Return flags indicating compile-time options.
119685c48e79Shenning 
119785c48e79Shenning     Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
119885c48e79Shenning      1.0: size of uInt
119985c48e79Shenning      3.2: size of uLong
120085c48e79Shenning      5.4: size of voidpf (pointer)
120185c48e79Shenning      7.6: size of z_off_t
120285c48e79Shenning 
120385c48e79Shenning     Compiler, assembler, and debug options:
120436f395ceStb      8: ZLIB_DEBUG
120585c48e79Shenning      9: ASMV or ASMINF -- use ASM code
120685c48e79Shenning      10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
120785c48e79Shenning      11: 0 (reserved)
120885c48e79Shenning 
120985c48e79Shenning     One-time table building (smaller code, but not thread-safe if true):
121085c48e79Shenning      12: BUILDFIXED -- build static block decoding tables when needed
121185c48e79Shenning      13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
121285c48e79Shenning      14,15: 0 (reserved)
121385c48e79Shenning 
121485c48e79Shenning     Library content (indicates missing functionality):
121585c48e79Shenning      16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
121685c48e79Shenning                           deflate code when not needed)
121785c48e79Shenning      17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
121885c48e79Shenning                     and decode gzip streams (to avoid linking crc code)
121985c48e79Shenning      18-19: 0 (reserved)
122085c48e79Shenning 
122185c48e79Shenning     Operation variations (changes in library functionality):
122285c48e79Shenning      20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
122385c48e79Shenning      21: FASTEST -- deflate algorithm with only one, lowest compression level
122485c48e79Shenning      22,23: 0 (reserved)
122585c48e79Shenning 
122685c48e79Shenning     The sprintf variant used by gzprintf (zero is best):
122785c48e79Shenning      24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
122885c48e79Shenning      25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
122985c48e79Shenning      26: 0 = returns value, 1 = void -- 1 means inferred string length returned
123085c48e79Shenning 
123185c48e79Shenning     Remainder:
123285c48e79Shenning      27-31: 0 (reserved)
123385c48e79Shenning  */
123485c48e79Shenning 
123536f395ceStb #ifndef Z_SOLO
12362af503bcStholo 
12372af503bcStholo                         /* utility functions */
12382af503bcStholo 
12392af503bcStholo /*
124036f395ceStb      The following utility functions are implemented on top of the basic
124136f395ceStb    stream-oriented functions.  To simplify the interface, some default options
124236f395ceStb    are assumed (compression level and memory usage, standard memory allocation
124336f395ceStb    functions).  The source code of these utility functions can be modified if
124436f395ceStb    you need special options.
12452af503bcStholo */
12462af503bcStholo 
1247a04ea15dStb ZEXTERN int ZEXPORT compress(Bytef *dest,   uLongf *destLen,
1248a04ea15dStb                              const Bytef *source, uLong sourceLen);
12492af503bcStholo /*
12502af503bcStholo      Compresses the source buffer into the destination buffer.  sourceLen is
125136f395ceStb    the byte length of the source buffer.  Upon entry, destLen is the total size
125236f395ceStb    of the destination buffer, which must be at least the value returned by
125336f395ceStb    compressBound(sourceLen).  Upon exit, destLen is the actual size of the
125436f395ceStb    compressed data.  compress() is equivalent to compress2() with a level
125536f395ceStb    parameter of Z_DEFAULT_COMPRESSION.
125636f395ceStb 
12572af503bcStholo      compress returns Z_OK if success, Z_MEM_ERROR if there was not
12582af503bcStholo    enough memory, Z_BUF_ERROR if there was not enough room in the output
12592af503bcStholo    buffer.
12602af503bcStholo */
12612af503bcStholo 
1262a04ea15dStb ZEXTERN int ZEXPORT compress2(Bytef *dest,   uLongf *destLen,
126315ce0796Smillert                               const Bytef *source, uLong sourceLen,
1264a04ea15dStb                               int level);
126515ce0796Smillert /*
126615ce0796Smillert      Compresses the source buffer into the destination buffer.  The level
126715ce0796Smillert    parameter has the same meaning as in deflateInit.  sourceLen is the byte
126815ce0796Smillert    length of the source buffer.  Upon entry, destLen is the total size of the
126985c48e79Shenning    destination buffer, which must be at least the value returned by
127085c48e79Shenning    compressBound(sourceLen).  Upon exit, destLen is the actual size of the
127136f395ceStb    compressed data.
127215ce0796Smillert 
127315ce0796Smillert      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
127415ce0796Smillert    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
127515ce0796Smillert    Z_STREAM_ERROR if the level parameter is invalid.
127615ce0796Smillert */
127715ce0796Smillert 
1278a04ea15dStb ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen);
127985c48e79Shenning /*
128085c48e79Shenning      compressBound() returns an upper bound on the compressed size after
128136f395ceStb    compress() or compress2() on sourceLen bytes.  It would be used before a
128236f395ceStb    compress() or compress2() call to allocate the destination buffer.
128385c48e79Shenning */
128485c48e79Shenning 
1285a04ea15dStb ZEXTERN int ZEXPORT uncompress(Bytef *dest,   uLongf *destLen,
1286a04ea15dStb                                const Bytef *source, uLong sourceLen);
12872af503bcStholo /*
12882af503bcStholo      Decompresses the source buffer into the destination buffer.  sourceLen is
128936f395ceStb    the byte length of the source buffer.  Upon entry, destLen is the total size
129036f395ceStb    of the destination buffer, which must be large enough to hold the entire
129136f395ceStb    uncompressed data.  (The size of the uncompressed data must have been saved
129236f395ceStb    previously by the compressor and transmitted to the decompressor by some
129336f395ceStb    mechanism outside the scope of this compression library.) Upon exit, destLen
129436f395ceStb    is the actual size of the uncompressed data.
12952af503bcStholo 
12962af503bcStholo      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
12972af503bcStholo    enough memory, Z_BUF_ERROR if there was not enough room in the output
129836f395ceStb    buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.  In
129936f395ceStb    the case where there is not enough room, uncompress() will fill the output
130036f395ceStb    buffer with the uncompressed data up to that point.
13012af503bcStholo */
13022af503bcStholo 
1303a04ea15dStb ZEXTERN int ZEXPORT uncompress2(Bytef *dest,   uLongf *destLen,
1304a04ea15dStb                                 const Bytef *source, uLong *sourceLen);
13052af503bcStholo /*
130636f395ceStb      Same as uncompress, except that sourceLen is a pointer, where the
130736f395ceStb    length of the source is *sourceLen.  On return, *sourceLen is the number of
130836f395ceStb    source bytes consumed.
130936f395ceStb */
131036f395ceStb 
131136f395ceStb                         /* gzip file access functions */
131236f395ceStb 
131336f395ceStb /*
131436f395ceStb      This library supports reading and writing files in gzip (.gz) format with
131536f395ceStb    an interface similar to that of stdio, using the functions that start with
131636f395ceStb    "gz".  The gzip format is different from the zlib format.  gzip is a gzip
131736f395ceStb    wrapper, documented in RFC 1952, wrapped around a deflate stream.
131836f395ceStb */
131936f395ceStb 
132036f395ceStb typedef struct gzFile_s *gzFile;    /* semi-opaque gzip file descriptor */
132136f395ceStb 
132236f395ceStb /*
1323a04ea15dStb ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
132436f395ceStb 
1325703d4924Stb      Open the gzip (.gz) file at path for reading and decompressing, or
1326703d4924Stb    compressing and writing.  The mode parameter is as in fopen ("rb" or "wb")
1327703d4924Stb    but can also include a compression level ("wb9") or a strategy: 'f' for
1328703d4924Stb    filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
1329703d4924Stb    'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
1330703d4924Stb    as in "wb9F".  (See the description of deflateInit2 for more information
1331703d4924Stb    about the strategy parameter.)  'T' will request transparent writing or
1332703d4924Stb    appending with no compression and not using the gzip format.
133336f395ceStb 
133436f395ceStb      "a" can be used instead of "w" to request that the gzip stream that will
133536f395ceStb    be written be appended to the file.  "+" will result in an error, since
133636f395ceStb    reading and writing to the same gzip file is not supported.  The addition of
133736f395ceStb    "x" when writing will create the file exclusively, which fails if the file
133836f395ceStb    already exists.  On systems that support it, the addition of "e" when
133936f395ceStb    reading or writing will set the flag to close the file on an execve() call.
134036f395ceStb 
134136f395ceStb      These functions, as well as gzip, will read and decode a sequence of gzip
134236f395ceStb    streams in a file.  The append function of gzopen() can be used to create
134336f395ceStb    such a file.  (Also see gzflush() for another way to do this.)  When
134436f395ceStb    appending, gzopen does not test whether the file begins with a gzip stream,
134536f395ceStb    nor does it look for the end of the gzip streams to begin appending.  gzopen
134636f395ceStb    will simply append a gzip stream to the existing file.
134715ce0796Smillert 
134815ce0796Smillert      gzopen can be used to read a file which is not in gzip format; in this
134936f395ceStb    case gzread will directly read from the file without decompression.  When
135036f395ceStb    reading, this will be detected automatically by looking for the magic two-
135136f395ceStb    byte gzip header.
135215ce0796Smillert 
135336f395ceStb      gzopen returns NULL if the file could not be opened, if there was
135436f395ceStb    insufficient memory to allocate the gzFile state, or if an invalid mode was
135536f395ceStb    specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
135636f395ceStb    errno can be checked to determine if the reason gzopen failed was that the
135736f395ceStb    file could not be opened.
135836f395ceStb */
13592af503bcStholo 
1360a04ea15dStb ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode);
13612af503bcStholo /*
1362703d4924Stb      Associate a gzFile with the file descriptor fd.  File descriptors are
1363703d4924Stb    obtained from calls like open, dup, creat, pipe or fileno (if the file has
1364703d4924Stb    been previously opened with fopen).  The mode parameter is as in gzopen.
136536f395ceStb 
136636f395ceStb      The next call of gzclose on the returned gzFile will also close the file
136736f395ceStb    descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
136836f395ceStb    fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
136936f395ceStb    mode);.  The duplicated descriptor should be saved to avoid a leak, since
137036f395ceStb    gzdopen does not close fd if it fails.  If you are using fileno() to get the
137136f395ceStb    file descriptor from a FILE *, then you will have to use dup() to avoid
137236f395ceStb    double-close()ing the file descriptor.  Both gzclose() and fclose() will
137336f395ceStb    close the associated file descriptor, so they need to have different file
137436f395ceStb    descriptors.
137536f395ceStb 
137636f395ceStb      gzdopen returns NULL if there was insufficient memory to allocate the
137736f395ceStb    gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
137836f395ceStb    provided, or '+' was provided), or if fd is -1.  The file descriptor is not
137936f395ceStb    used until the next gz* read, write, seek, or close operation, so gzdopen
138036f395ceStb    will not detect if fd is invalid (unless fd is -1).
138136f395ceStb */
138236f395ceStb 
1383a04ea15dStb ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size);
138436f395ceStb /*
1385703d4924Stb      Set the internal buffer size used by this library's functions for file to
1386703d4924Stb    size.  The default buffer size is 8192 bytes.  This function must be called
1387703d4924Stb    after gzopen() or gzdopen(), and before any other calls that read or write
1388703d4924Stb    the file.  The buffer memory allocation is always deferred to the first read
1389703d4924Stb    or write.  Three times that size in buffer space is allocated.  A larger
1390703d4924Stb    buffer size of, for example, 64K or 128K bytes will noticeably increase the
1391703d4924Stb    speed of decompression (reading).
139236f395ceStb 
139336f395ceStb      The new buffer size also affects the maximum length for gzprintf().
139436f395ceStb 
139536f395ceStb      gzbuffer() returns 0 on success, or -1 on failure, such as being called
139636f395ceStb    too late.
13972af503bcStholo */
13982af503bcStholo 
1399a04ea15dStb ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy);
140015ce0796Smillert /*
1401703d4924Stb      Dynamically update the compression level and strategy for file.  See the
1402703d4924Stb    description of deflateInit2 for the meaning of these parameters. Previously
1403703d4924Stb    provided data is flushed before applying the parameter changes.
140436f395ceStb 
140536f395ceStb      gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
140636f395ceStb    opened for writing, Z_ERRNO if there is an error writing the flushed data,
140736f395ceStb    or Z_MEM_ERROR if there is a memory allocation error.
140815ce0796Smillert */
140915ce0796Smillert 
1410a04ea15dStb ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len);
14112af503bcStholo /*
1412703d4924Stb      Read and decompress up to len uncompressed bytes from file into buf.  If
141336f395ceStb    the input file is not in gzip format, gzread copies the given number of
141436f395ceStb    bytes into the buffer directly from the file.
141536f395ceStb 
141636f395ceStb      After reaching the end of a gzip stream in the input, gzread will continue
141736f395ceStb    to read, looking for another gzip stream.  Any number of gzip streams may be
141836f395ceStb    concatenated in the input file, and will all be decompressed by gzread().
141936f395ceStb    If something other than a gzip stream is encountered after a gzip stream,
142036f395ceStb    that remaining trailing garbage is ignored (and no error is returned).
142136f395ceStb 
142236f395ceStb      gzread can be used to read a gzip file that is being concurrently written.
142336f395ceStb    Upon reaching the end of the input, gzread will return with the available
142436f395ceStb    data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
142536f395ceStb    gzclearerr can be used to clear the end of file indicator in order to permit
142636f395ceStb    gzread to be tried again.  Z_OK indicates that a gzip stream was completed
142736f395ceStb    on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
142836f395ceStb    middle of a gzip stream.  Note that gzread does not return -1 in the event
142936f395ceStb    of an incomplete gzip stream.  This error is deferred until gzclose(), which
143036f395ceStb    will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
143136f395ceStb    stream.  Alternatively, gzerror can be used before gzclose to detect this
143236f395ceStb    case.
143336f395ceStb 
143436f395ceStb      gzread returns the number of uncompressed bytes actually read, less than
143536f395ceStb    len for end of file, or -1 for error.  If len is too large to fit in an int,
143636f395ceStb    then nothing is read, -1 is returned, and the error state is set to
143736f395ceStb    Z_STREAM_ERROR.
143836f395ceStb */
143936f395ceStb 
1440a04ea15dStb ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
1441a04ea15dStb                                  gzFile file);
144236f395ceStb /*
1443703d4924Stb      Read and decompress up to nitems items of size size from file into buf,
1444703d4924Stb    otherwise operating as gzread() does.  This duplicates the interface of
1445703d4924Stb    stdio's fread(), with size_t request and return types.  If the library
1446703d4924Stb    defines size_t, then z_size_t is identical to size_t.  If not, then z_size_t
1447703d4924Stb    is an unsigned integer type that can contain a pointer.
144836f395ceStb 
144936f395ceStb      gzfread() returns the number of full items read of size size, or zero if
145036f395ceStb    the end of the file was reached and a full item could not be read, or if
145136f395ceStb    there was an error.  gzerror() must be consulted if zero is returned in
145236f395ceStb    order to determine if there was an error.  If the multiplication of size and
145336f395ceStb    nitems overflows, i.e. the product does not fit in a z_size_t, then nothing
145436f395ceStb    is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
145536f395ceStb 
145636f395ceStb      In the event that the end of file is reached and only a partial item is
145736f395ceStb    available at the end, i.e. the remaining uncompressed data length is not a
14588bda5813Stb    multiple of size, then the final partial item is nevertheless read into buf
145936f395ceStb    and the end-of-file flag is set.  The length of the partial item read is not
146036f395ceStb    provided, but could be inferred from the result of gztell().  This behavior
146136f395ceStb    is the same as the behavior of fread() implementations in common libraries,
146236f395ceStb    but it prevents the direct use of gzfread() to read a concurrently written
14638bda5813Stb    file, resetting and retrying on end-of-file, when size is not 1.
146436f395ceStb */
14652af503bcStholo 
1466a04ea15dStb ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len);
14672af503bcStholo /*
1468703d4924Stb      Compress and write the len uncompressed bytes at buf to file. gzwrite
1469703d4924Stb    returns the number of uncompressed bytes written or 0 in case of error.
14702af503bcStholo */
14712af503bcStholo 
1472a04ea15dStb ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
1473a04ea15dStb                                   z_size_t nitems, gzFile file);
147415ce0796Smillert /*
1475703d4924Stb      Compress and write nitems items of size size from buf to file, duplicating
147636f395ceStb    the interface of stdio's fwrite(), with size_t request and return types.  If
147736f395ceStb    the library defines size_t, then z_size_t is identical to size_t.  If not,
147836f395ceStb    then z_size_t is an unsigned integer type that can contain a pointer.
147936f395ceStb 
148036f395ceStb      gzfwrite() returns the number of full items written of size size, or zero
148136f395ceStb    if there was an error.  If the multiplication of size and nitems overflows,
148236f395ceStb    i.e. the product does not fit in a z_size_t, then nothing is written, zero
148336f395ceStb    is returned, and the error state is set to Z_STREAM_ERROR.
148436f395ceStb */
148536f395ceStb 
1486a04ea15dStb ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
148736f395ceStb /*
1488703d4924Stb      Convert, format, compress, and write the arguments (...) to file under
1489703d4924Stb    control of the string format, as in fprintf.  gzprintf returns the number of
149036f395ceStb    uncompressed bytes actually written, or a negative zlib error code in case
149136f395ceStb    of error.  The number of uncompressed bytes written is limited to 8191, or
149236f395ceStb    one less than the buffer size given to gzbuffer().  The caller should assure
149336f395ceStb    that this limit is not exceeded.  If it is exceeded, then gzprintf() will
149485c48e79Shenning    return an error (0) with nothing written.  In this case, there may also be a
149585c48e79Shenning    buffer overflow with unpredictable consequences, which is possible only if
1496703d4924Stb    zlib was compiled with the insecure functions sprintf() or vsprintf(),
149785c48e79Shenning    because the secure snprintf() or vsnprintf() functions were not available.
149836f395ceStb    This can be determined using zlibCompileFlags().
149915ce0796Smillert */
150015ce0796Smillert 
1501a04ea15dStb ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
150215ce0796Smillert /*
1503703d4924Stb      Compress and write the given null-terminated string s to file, excluding
150415ce0796Smillert    the terminating null character.
150536f395ceStb 
150615ce0796Smillert      gzputs returns the number of characters written, or -1 in case of error.
150715ce0796Smillert */
150815ce0796Smillert 
1509a04ea15dStb ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
151015ce0796Smillert /*
1511703d4924Stb      Read and decompress bytes from file into buf, until len-1 characters are
1512703d4924Stb    read, or until a newline character is read and transferred to buf, or an
1513703d4924Stb    end-of-file condition is encountered.  If any characters are read or if len
1514703d4924Stb    is one, the string is terminated with a null character.  If no characters
1515703d4924Stb    are read due to an end-of-file or len is less than one, then the buffer is
1516703d4924Stb    left untouched.
151736f395ceStb 
151836f395ceStb      gzgets returns buf which is a null-terminated string, or it returns NULL
151936f395ceStb    for end-of-file or in case of error.  If there was an error, the contents at
152036f395ceStb    buf are indeterminate.
152115ce0796Smillert */
152215ce0796Smillert 
1523a04ea15dStb ZEXTERN int ZEXPORT gzputc(gzFile file, int c);
152415ce0796Smillert /*
1525703d4924Stb      Compress and write c, converted to an unsigned char, into file.  gzputc
152636f395ceStb    returns the value that was written, or -1 in case of error.
152715ce0796Smillert */
152815ce0796Smillert 
1529a04ea15dStb ZEXTERN int ZEXPORT gzgetc(gzFile file);
153015ce0796Smillert /*
1531703d4924Stb      Read and decompress one byte from file.  gzgetc returns this byte or -1
153236f395ceStb    in case of end of file or error.  This is implemented as a macro for speed.
153336f395ceStb    As such, it does not do all of the checking the other functions do.  I.e.
153436f395ceStb    it does not check to see if file is NULL, nor whether the structure file
153536f395ceStb    points to has been clobbered or not.
153615ce0796Smillert */
153715ce0796Smillert 
1538a04ea15dStb ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
153985c48e79Shenning /*
1540703d4924Stb      Push c back onto the stream for file to be read as the first character on
1541703d4924Stb    the next read.  At least one character of push-back is always allowed.
154236f395ceStb    gzungetc() returns the character pushed, or -1 on failure.  gzungetc() will
154336f395ceStb    fail if c is -1, and may fail if a character has been pushed but not read
154436f395ceStb    yet.  If gzungetc is used immediately after gzopen or gzdopen, at least the
154536f395ceStb    output buffer size of pushed characters is allowed.  (See gzbuffer above.)
154636f395ceStb    The pushed character will be discarded if the stream is repositioned with
154736f395ceStb    gzseek() or gzrewind().
154885c48e79Shenning */
154985c48e79Shenning 
1550a04ea15dStb ZEXTERN int ZEXPORT gzflush(gzFile file, int flush);
15512af503bcStholo /*
1552703d4924Stb      Flush all pending output to file.  The parameter flush is as in the
1553703d4924Stb    deflate() function.  The return value is the zlib error number (see function
1554703d4924Stb    gzerror below).  gzflush is only permitted when writing.
155536f395ceStb 
155636f395ceStb      If the flush parameter is Z_FINISH, the remaining data is written and the
155736f395ceStb    gzip stream is completed in the output.  If gzwrite() is called again, a new
155836f395ceStb    gzip stream will be started in the output.  gzread() is able to read such
155936f395ceStb    concatenated gzip streams.
156036f395ceStb 
156136f395ceStb      gzflush should be called only when strictly necessary because it will
156236f395ceStb    degrade compression if called too often.
15632af503bcStholo */
15642af503bcStholo 
156536f395ceStb /*
1566a04ea15dStb ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
1567a04ea15dStb                                z_off_t offset, int whence);
156836f395ceStb 
1569703d4924Stb      Set the starting position to offset relative to whence for the next gzread
1570703d4924Stb    or gzwrite on file.  The offset represents a number of bytes in the
157115ce0796Smillert    uncompressed data stream.  The whence parameter is defined as in lseek(2);
157215ce0796Smillert    the value SEEK_END is not supported.
157336f395ceStb 
157415ce0796Smillert      If the file is opened for reading, this function is emulated but can be
157515ce0796Smillert    extremely slow.  If the file is opened for writing, only forward seeks are
157615ce0796Smillert    supported; gzseek then compresses a sequence of zeroes up to the new
157715ce0796Smillert    starting position.
157815ce0796Smillert 
157915ce0796Smillert      gzseek returns the resulting offset location as measured in bytes from
158015ce0796Smillert    the beginning of the uncompressed stream, or -1 in case of error, in
158115ce0796Smillert    particular if the file is opened for writing and the new starting position
158215ce0796Smillert    would be before the current position.
158315ce0796Smillert */
158415ce0796Smillert 
1585a04ea15dStb ZEXTERN int ZEXPORT    gzrewind(gzFile file);
158615ce0796Smillert /*
1587703d4924Stb      Rewind file. This function is supported only for reading.
158815ce0796Smillert 
1589703d4924Stb      gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
159015ce0796Smillert */
159115ce0796Smillert 
159215ce0796Smillert /*
1593a04ea15dStb ZEXTERN z_off_t ZEXPORT    gztell(gzFile file);
159436f395ceStb 
1595703d4924Stb      Return the starting position for the next gzread or gzwrite on file.
1596703d4924Stb    This position represents a number of bytes in the uncompressed data stream,
1597703d4924Stb    and is zero when starting, even if appending or reading a gzip stream from
1598703d4924Stb    the middle of a file using gzdopen().
159915ce0796Smillert 
160015ce0796Smillert      gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
160115ce0796Smillert */
160215ce0796Smillert 
160336f395ceStb /*
1604a04ea15dStb ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file);
160536f395ceStb 
1606703d4924Stb      Return the current compressed (actual) read or write offset of file.  This
1607703d4924Stb    offset includes the count of bytes that precede the gzip stream, for example
1608703d4924Stb    when appending or when using gzdopen() for reading.  When reading, the
1609703d4924Stb    offset does not include as yet unused buffered input.  This information can
1610703d4924Stb    be used for a progress indicator.  On error, gzoffset() returns -1.
161136f395ceStb */
161236f395ceStb 
1613a04ea15dStb ZEXTERN int ZEXPORT gzeof(gzFile file);
161415ce0796Smillert /*
1615703d4924Stb      Return true (1) if the end-of-file indicator for file has been set while
1616703d4924Stb    reading, false (0) otherwise.  Note that the end-of-file indicator is set
1617703d4924Stb    only if the read tried to go past the end of the input, but came up short.
1618703d4924Stb    Therefore, just like feof(), gzeof() may return false even if there is no
1619703d4924Stb    more data to read, in the event that the last read request was for the exact
1620703d4924Stb    number of bytes remaining in the input file.  This will happen if the input
1621703d4924Stb    file size is an exact multiple of the buffer size.
162236f395ceStb 
162336f395ceStb      If gzeof() returns true, then the read functions will return no more data,
162436f395ceStb    unless the end-of-file indicator is reset by gzclearerr() and the input file
162536f395ceStb    has grown since the previous end of file was detected.
162615ce0796Smillert */
162715ce0796Smillert 
1628a04ea15dStb ZEXTERN int ZEXPORT gzdirect(gzFile file);
1629d76b9bfaSmillert /*
1630703d4924Stb      Return true (1) if file is being copied directly while reading, or false
163136f395ceStb    (0) if file is a gzip stream being decompressed.
163236f395ceStb 
163336f395ceStb      If the input file is empty, gzdirect() will return true, since the input
163436f395ceStb    does not contain a gzip stream.
163536f395ceStb 
163636f395ceStb      If gzdirect() is used immediately after gzopen() or gzdopen() it will
163736f395ceStb    cause buffers to be allocated to allow reading the file to determine if it
163836f395ceStb    is a gzip file.  Therefore if gzbuffer() is used, it should be called before
163936f395ceStb    gzdirect().
164036f395ceStb 
164136f395ceStb      When writing, gzdirect() returns true (1) if transparent writing was
164236f395ceStb    requested ("wT" for the gzopen() mode), or false (0) otherwise.  (Note:
164336f395ceStb    gzdirect() is not needed when writing.  Transparent writing must be
164436f395ceStb    explicitly requested, so the application already knows the answer.  When
164536f395ceStb    linking statically, using gzdirect() will include all of the zlib code for
164636f395ceStb    gzip file reading and decompression, which may not be desired.)
1647d76b9bfaSmillert */
1648d76b9bfaSmillert 
1649a04ea15dStb ZEXTERN int ZEXPORT    gzclose(gzFile file);
16502af503bcStholo /*
1651703d4924Stb      Flush all pending output for file, if necessary, close file and
1652703d4924Stb    deallocate the (de)compression state.  Note that once file is closed, you
165336f395ceStb    cannot call gzerror with file, since its structures have been deallocated.
165436f395ceStb    gzclose must not be called more than once on the same file, just as free
165536f395ceStb    must not be called more than once on the same allocation.
165636f395ceStb 
165736f395ceStb      gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
165836f395ceStb    file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
165936f395ceStb    last read ended in the middle of a gzip stream, or Z_OK on success.
166036f395ceStb */
166136f395ceStb 
1662a04ea15dStb ZEXTERN int ZEXPORT gzclose_r(gzFile file);
1663a04ea15dStb ZEXTERN int ZEXPORT gzclose_w(gzFile file);
166436f395ceStb /*
166536f395ceStb      Same as gzclose(), but gzclose_r() is only for use when reading, and
166636f395ceStb    gzclose_w() is only for use when writing or appending.  The advantage to
166736f395ceStb    using these instead of gzclose() is that they avoid linking in zlib
166836f395ceStb    compression or decompression code that is not used when only reading or only
166936f395ceStb    writing respectively.  If gzclose() is used, then both compression and
167036f395ceStb    decompression code will be included the application when linking to a static
167136f395ceStb    zlib library.
16722af503bcStholo */
16732af503bcStholo 
1674a04ea15dStb ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
16752af503bcStholo /*
1676703d4924Stb      Return the error message for the last error which occurred on file.
1677703d4924Stb    errnum is set to zlib error number.  If an error occurred in the file system
1678703d4924Stb    and not in the compression library, errnum is set to Z_ERRNO and the
1679703d4924Stb    application may consult errno to get the exact error code.
168036f395ceStb 
168136f395ceStb      The application must not modify the returned string.  Future calls to
168236f395ceStb    this function may invalidate the previously returned string.  If file is
168336f395ceStb    closed, then the string previously returned by gzerror will no longer be
168436f395ceStb    available.
168536f395ceStb 
168636f395ceStb      gzerror() should be used to distinguish errors from end-of-file for those
168736f395ceStb    functions above that do not distinguish those cases in their return values.
16882af503bcStholo */
16892af503bcStholo 
1690a04ea15dStb ZEXTERN void ZEXPORT gzclearerr(gzFile file);
169185c48e79Shenning /*
1692703d4924Stb      Clear the error and end-of-file flags for file.  This is analogous to the
169385c48e79Shenning    clearerr() function in stdio.  This is useful for continuing to read a gzip
169485c48e79Shenning    file that is being written concurrently.
169585c48e79Shenning */
169685c48e79Shenning 
169736f395ceStb #endif /* !Z_SOLO */
169836f395ceStb 
16992af503bcStholo                         /* checksum functions */
17002af503bcStholo 
17012af503bcStholo /*
17022af503bcStholo      These functions are not related to compression but are exported
170336f395ceStb    anyway because they might be useful in applications using the compression
170436f395ceStb    library.
17052af503bcStholo */
17062af503bcStholo 
1707a04ea15dStb ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len);
17082af503bcStholo /*
17092af503bcStholo      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1710703d4924Stb    return the updated checksum. An Adler-32 value is in the range of a 32-bit
1711703d4924Stb    unsigned integer. If buf is Z_NULL, this function returns the required
1712703d4924Stb    initial value for the checksum.
171336f395ceStb 
171436f395ceStb      An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
171536f395ceStb    much faster.
171636f395ceStb 
171736f395ceStb    Usage example:
17182af503bcStholo 
17192af503bcStholo      uLong adler = adler32(0L, Z_NULL, 0);
17202af503bcStholo 
17212af503bcStholo      while (read_buffer(buffer, length) != EOF) {
17222af503bcStholo        adler = adler32(adler, buffer, length);
17232af503bcStholo      }
17242af503bcStholo      if (adler != original_adler) error();
17252af503bcStholo */
17262af503bcStholo 
1727a04ea15dStb ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf,
1728a04ea15dStb                                 z_size_t len);
172936f395ceStb /*
173036f395ceStb      Same as adler32(), but with a size_t length.
173136f395ceStb */
173236f395ceStb 
173336f395ceStb /*
1734a04ea15dStb ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2,
1735a04ea15dStb                                       z_off_t len2);
173636f395ceStb 
1737d76b9bfaSmillert      Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
1738d76b9bfaSmillert    and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1739d76b9bfaSmillert    each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
174036f395ceStb    seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.  Note
174136f395ceStb    that the z_off_t type (like off_t) is a signed integer.  If len2 is
174236f395ceStb    negative, the result has no meaning or utility.
1743d76b9bfaSmillert */
1744d76b9bfaSmillert 
1745a04ea15dStb ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len);
17462af503bcStholo /*
1747d76b9bfaSmillert      Update a running CRC-32 with the bytes buf[0..len-1] and return the
1748703d4924Stb    updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
1749703d4924Stb    If buf is Z_NULL, this function returns the required initial value for the
1750703d4924Stb    crc. Pre- and post-conditioning (one's complement) is performed within this
1751703d4924Stb    function so it shouldn't be done by the application.
175236f395ceStb 
17532af503bcStholo    Usage example:
17542af503bcStholo 
17552af503bcStholo      uLong crc = crc32(0L, Z_NULL, 0);
17562af503bcStholo 
17572af503bcStholo      while (read_buffer(buffer, length) != EOF) {
17582af503bcStholo        crc = crc32(crc, buffer, length);
17592af503bcStholo      }
17602af503bcStholo      if (crc != original_crc) error();
17612af503bcStholo */
17622af503bcStholo 
1763a04ea15dStb ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf,
1764a04ea15dStb                               z_size_t len);
176536f395ceStb /*
176636f395ceStb      Same as crc32(), but with a size_t length.
176736f395ceStb */
1768d76b9bfaSmillert 
1769d76b9bfaSmillert /*
1770a04ea15dStb ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
177136f395ceStb 
1772d76b9bfaSmillert      Combine two CRC-32 check values into one.  For two sequences of bytes,
1773d76b9bfaSmillert    seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1774d76b9bfaSmillert    calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32
1775d76b9bfaSmillert    check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1776f5252e2dStb    len2. len2 must be non-negative.
1777d76b9bfaSmillert */
1778d76b9bfaSmillert 
1779703d4924Stb /*
1780a04ea15dStb ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2);
1781703d4924Stb 
1782703d4924Stb      Return the operator corresponding to length len2, to be used with
1783f5252e2dStb    crc32_combine_op(). len2 must be non-negative.
1784703d4924Stb */
1785703d4924Stb 
1786a04ea15dStb ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
1787703d4924Stb /*
1788703d4924Stb      Give the same result as crc32_combine(), using op in place of len2. op is
1789703d4924Stb    is generated from len2 by crc32_combine_gen(). This will be faster than
1790703d4924Stb    crc32_combine() if the generated op is used more than once.
1791703d4924Stb */
1792703d4924Stb 
17932af503bcStholo 
17942af503bcStholo                         /* various hacks, don't look :) */
17952af503bcStholo 
17962af503bcStholo /* deflateInit and inflateInit are macros to allow checking the zlib version
17972af503bcStholo  * and the compiler's view of z_stream:
17982af503bcStholo  */
1799a04ea15dStb ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level,
1800a04ea15dStb                                  const char *version, int stream_size);
1801a04ea15dStb ZEXTERN int ZEXPORT inflateInit_(z_streamp strm,
1802a04ea15dStb                                  const char *version, int stream_size);
1803a04ea15dStb ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int  level, int  method,
180415ce0796Smillert                                   int windowBits, int memLevel,
180515ce0796Smillert                                   int strategy, const char *version,
1806a04ea15dStb                                   int stream_size);
1807a04ea15dStb ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int  windowBits,
1808a04ea15dStb                                   const char *version, int stream_size);
1809a04ea15dStb ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
181085c48e79Shenning                                      unsigned char FAR *window,
181185c48e79Shenning                                      const char *version,
1812a04ea15dStb                                      int stream_size);
181336f395ceStb #ifdef Z_PREFIX_SET
181436f395ceStb #  define z_deflateInit(strm, level) \
181536f395ceStb           deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
181636f395ceStb #  define z_inflateInit(strm) \
181736f395ceStb           inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
181836f395ceStb #  define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
181936f395ceStb           deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
182036f395ceStb                         (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
182136f395ceStb #  define z_inflateInit2(strm, windowBits) \
182236f395ceStb           inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
182336f395ceStb                         (int)sizeof(z_stream))
182436f395ceStb #  define z_inflateBackInit(strm, windowBits, window) \
182536f395ceStb           inflateBackInit_((strm), (windowBits), (window), \
182636f395ceStb                            ZLIB_VERSION, (int)sizeof(z_stream))
182736f395ceStb #else
18282af503bcStholo #  define deflateInit(strm, level) \
182936f395ceStb           deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
18302af503bcStholo #  define inflateInit(strm) \
183136f395ceStb           inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
18322af503bcStholo #  define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
18332af503bcStholo           deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
183436f395ceStb                         (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
18352af503bcStholo #  define inflateInit2(strm, windowBits) \
183636f395ceStb           inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
183736f395ceStb                         (int)sizeof(z_stream))
183885c48e79Shenning #  define inflateBackInit(strm, windowBits, window) \
183985c48e79Shenning           inflateBackInit_((strm), (windowBits), (window), \
184036f395ceStb                            ZLIB_VERSION, (int)sizeof(z_stream))
18412af503bcStholo #endif
18422af503bcStholo 
184336f395ceStb #ifndef Z_SOLO
184436f395ceStb 
184536f395ceStb /* gzgetc() macro and its supporting function and exposed data structure.  Note
184636f395ceStb  * that the real internal state is much larger than the exposed structure.
184736f395ceStb  * This abbreviated structure exposes just enough for the gzgetc() macro.  The
184836f395ceStb  * user should not mess with these exposed elements, since their names or
184936f395ceStb  * behavior could change in the future, perhaps even capriciously.  They can
185036f395ceStb  * only be used by the gzgetc() macro.  You have been warned.
185136f395ceStb  */
185236f395ceStb struct gzFile_s {
185336f395ceStb     unsigned have;
185436f395ceStb     unsigned char *next;
185536f395ceStb     z_off64_t pos;
185636f395ceStb };
1857a04ea15dStb ZEXTERN int ZEXPORT gzgetc_(gzFile file);       /* backward compatibility */
185836f395ceStb #ifdef Z_PREFIX_SET
185936f395ceStb #  undef z_gzgetc
186036f395ceStb #  define z_gzgetc(g) \
186136f395ceStb           ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
186236f395ceStb #else
186336f395ceStb #  define gzgetc(g) \
186436f395ceStb           ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
186536f395ceStb #endif
186636f395ceStb 
186736f395ceStb /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
186836f395ceStb  * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
186936f395ceStb  * both are true, the application gets the *64 functions, and the regular
187036f395ceStb  * functions are changed to 64 bits) -- in case these are set on systems
187136f395ceStb  * without large file support, _LFS64_LARGEFILE must also be true
187236f395ceStb  */
187336f395ceStb #ifdef Z_LARGE64
1874a04ea15dStb    ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
1875a04ea15dStb    ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
1876a04ea15dStb    ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
1877a04ea15dStb    ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
1878a04ea15dStb    ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
1879a04ea15dStb    ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
1880a04ea15dStb    ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
188136f395ceStb #endif
188236f395ceStb 
188336f395ceStb #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
188436f395ceStb #  ifdef Z_PREFIX_SET
188536f395ceStb #    define z_gzopen z_gzopen64
188636f395ceStb #    define z_gzseek z_gzseek64
188736f395ceStb #    define z_gztell z_gztell64
188836f395ceStb #    define z_gzoffset z_gzoffset64
188936f395ceStb #    define z_adler32_combine z_adler32_combine64
189036f395ceStb #    define z_crc32_combine z_crc32_combine64
1891703d4924Stb #    define z_crc32_combine_gen z_crc32_combine_gen64
189236f395ceStb #  else
189336f395ceStb #    define gzopen gzopen64
189436f395ceStb #    define gzseek gzseek64
189536f395ceStb #    define gztell gztell64
189636f395ceStb #    define gzoffset gzoffset64
189736f395ceStb #    define adler32_combine adler32_combine64
189836f395ceStb #    define crc32_combine crc32_combine64
1899703d4924Stb #    define crc32_combine_gen crc32_combine_gen64
190036f395ceStb #  endif
190136f395ceStb #  ifndef Z_LARGE64
1902a04ea15dStb      ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
1903a04ea15dStb      ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int);
1904a04ea15dStb      ZEXTERN z_off_t ZEXPORT gztell64(gzFile);
1905a04ea15dStb      ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile);
19068ffe7b2aStb      ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
19078ffe7b2aStb      ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
19088ffe7b2aStb      ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
190936f395ceStb #  endif
191036f395ceStb #else
1911a04ea15dStb    ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *);
1912a04ea15dStb    ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int);
1913a04ea15dStb    ZEXTERN z_off_t ZEXPORT gztell(gzFile);
1914a04ea15dStb    ZEXTERN z_off_t ZEXPORT gzoffset(gzFile);
1915a04ea15dStb    ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
1916a04ea15dStb    ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
1917a04ea15dStb    ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
191836f395ceStb #endif
191936f395ceStb 
192036f395ceStb #else /* Z_SOLO */
192136f395ceStb 
1922a04ea15dStb    ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
1923a04ea15dStb    ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
1924a04ea15dStb    ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
192536f395ceStb 
192636f395ceStb #endif /* !Z_SOLO */
192736f395ceStb 
192836f395ceStb /* undocumented functions */
1929a04ea15dStb ZEXTERN const char   * ZEXPORT zError(int);
1930a04ea15dStb ZEXTERN int            ZEXPORT inflateSyncPoint(z_streamp);
1931a04ea15dStb ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void);
1932a04ea15dStb ZEXTERN int            ZEXPORT inflateUndermine(z_streamp, int);
1933a04ea15dStb ZEXTERN int            ZEXPORT inflateValidate(z_streamp, int);
1934a04ea15dStb ZEXTERN unsigned long  ZEXPORT inflateCodesUsed(z_streamp);
1935a04ea15dStb ZEXTERN int            ZEXPORT inflateResetKeep(z_streamp);
1936a04ea15dStb ZEXTERN int            ZEXPORT deflateResetKeep(z_streamp);
1937703d4924Stb #if defined(_WIN32) && !defined(Z_SOLO)
1938a04ea15dStb ZEXTERN gzFile         ZEXPORT gzopen_w(const wchar_t *path,
1939a04ea15dStb                                         const char *mode);
194036f395ceStb #endif
194136f395ceStb #if defined(STDC) || defined(Z_HAVE_STDARG_H)
194236f395ceStb #  ifndef Z_SOLO
1943a04ea15dStb ZEXTERN int            ZEXPORTVA gzvprintf(gzFile file,
194436f395ceStb                                            const char *format,
1945a04ea15dStb                                            va_list va);
194636f395ceStb #  endif
194736f395ceStb #endif
19482af503bcStholo 
19492af503bcStholo #ifdef __cplusplus
19502af503bcStholo }
19512af503bcStholo #endif
19522af503bcStholo 
195385c48e79Shenning #endif /* ZLIB_H */
1954