100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* zlib.h -- interface of the 'zlib' general purpose compression library
209eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  version 1.2.7, May 2nd, 2012
300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  This software is provided 'as-is', without any express or implied
700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  warranty.  In no event will the authors be held liable for any damages
800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  arising from the use of this software.
900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
1000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Permission is granted to anyone to use this software for any purpose,
1100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  including commercial applications, and to alter it and redistribute it
1200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  freely, subject to the following restrictions:
1300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
1400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  1. The origin of this software must not be misrepresented; you must not
1500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     claim that you wrote the original software. If you use this software
1600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     in a product, an acknowledgment in the product documentation would be
1700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     appreciated but is not required.
1800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  2. Altered source versions must be plainly marked as such, and must not be
1900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     misrepresented as being the original software.
2000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  3. This notice may not be removed or altered from any source distribution.
2100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
2200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Jean-loup Gailly        Mark Adler
2300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  jloup@gzip.org          madler@alumni.caltech.edu
2400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
2500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
2600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  The data format used by the zlib library is described by RFCs (Request for
2700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
2800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
2900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
3000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
3100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#ifndef ZLIB_H
3200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define ZLIB_H
3300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
3400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#include "zconf.h"
3500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
3600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#ifdef __cplusplus
3700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughesextern "C" {
3800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif
3900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
4009eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#define ZLIB_VERSION "1.2.7"
4109eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#define ZLIB_VERNUM 0x1270
4200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define ZLIB_VER_MAJOR 1
4300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define ZLIB_VER_MINOR 2
4409eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#define ZLIB_VER_REVISION 7
4500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define ZLIB_VER_SUBREVISION 0
4600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
4700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
4800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The 'zlib' compression library provides in-memory compression and
4900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  decompression functions, including integrity checks of the uncompressed data.
5000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  This version of the library supports only one compression method (deflation)
5100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  but other algorithms will be added later and will have the same stream
5200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  interface.
5300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
5400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Compression can be done in a single step if the buffers are large enough,
5500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  or can be done by repeated calls of the compression function.  In the latter
5600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  case, the application must provide more input and/or consume the output
5700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  (providing more output space) before each call.
5800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
5900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The compressed data format used by default by the in-memory functions is
6000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
6100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  around a deflate stream, which is itself documented in RFC 1951.
6200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
6300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The library also supports reading and writing files in gzip (.gz) format
6400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  with an interface similar to that of stdio using the functions that start
6500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  with "gz".  The gzip format is different from the zlib format.  gzip is a
6600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
6700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
6800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    This library can optionally read and write gzip streams in memory as well.
6900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
7000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The zlib format was designed to be compact and fast for use in memory
7100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  and on communications channels.  The gzip format was designed for single-
7200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  file compression on file systems, has a larger header than zlib to maintain
7300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  directory information, and uses a different, slower check method than zlib.
7400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
7500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The library does not install any signal handler.  The decoder checks
7600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the consistency of the compressed data, so the library should never crash
7700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  even in case of corrupted input.
7800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
7900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
8000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
8100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef void   (*free_func)  OF((voidpf opaque, voidpf address));
8200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
8300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughesstruct internal_state;
8400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
8500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef struct z_stream_s {
8600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    z_const Bytef *next_in;     /* next input byte */
8700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uInt     avail_in;  /* number of bytes available at next_in */
8800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uLong    total_in;  /* total number of input bytes read so far */
8900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
9000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Bytef    *next_out; /* next output byte should be put there */
9100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uInt     avail_out; /* remaining free space at next_out */
9200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uLong    total_out; /* total number of bytes output so far */
9300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
9400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    z_const char *msg;  /* last error message, NULL if no error */
9500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    struct internal_state FAR *state; /* not visible by applications */
9600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
9700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    alloc_func zalloc;  /* used to allocate the internal state */
9800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    free_func  zfree;   /* used to free the internal state */
9900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    voidpf     opaque;  /* private data object passed to zalloc and zfree */
10000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
10100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    int     data_type;  /* best guess about the data type: binary or text */
10200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uLong   adler;      /* adler32 value of the uncompressed data */
10300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uLong   reserved;   /* reserved for future use */
10400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes} z_stream;
10500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
10600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef z_stream FAR *z_streamp;
10700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
10800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
10900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzip header information passed to and from zlib routines.  See RFC 1952
11000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  for more details on the meanings of these fields.
11100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
11200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef struct gz_header_s {
11300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    int     text;       /* true if compressed data believed to be text */
11400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uLong   time;       /* modification time */
11500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    int     xflags;     /* extra flags (not used when writing a gzip file) */
11600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    int     os;         /* operating system */
11700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
11800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
11900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uInt    extra_max;  /* space at extra (only when reading header) */
12000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
12100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uInt    name_max;   /* space at name (only when reading header) */
12200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
12300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    uInt    comm_max;   /* space at comment (only when reading header) */
12400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    int     hcrc;       /* true if there was or will be a header crc */
12500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    int     done;       /* true when done reading gzip header (not used
12600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                           when writing a gzip file) */
12700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes} gz_header;
12800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
12900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef gz_header FAR *gz_headerp;
13000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
13100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
13200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The application must update next_in and avail_in when avail_in has dropped
13300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to zero.  It must update next_out and avail_out when avail_out has dropped
13400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to zero.  The application must initialize zalloc, zfree and opaque before
13500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   calling the init function.  All other fields are set by the compression
13600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   library and must not be updated by the application.
13700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
13800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The opaque value provided by the application will be passed as the first
13900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   parameter for calls of zalloc and zfree.  This can be useful for custom
14000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   memory management.  The compression library attaches no meaning to the
14100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   opaque value.
14200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
14300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     zalloc must return Z_NULL if there is not enough memory for the object.
14400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   If zlib is used in a multi-threaded application, zalloc and zfree must be
14500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   thread safe.
14600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
14700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     On 16-bit systems, the functions zalloc and zfree must be able to allocate
14800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   exactly 65536 bytes, but will not be required to allocate more than this if
14900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the symbol MAXSEG_64K is defined (see zconf.h).  WARNING: On MSDOS, pointers
15000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   returned by zalloc for objects of exactly 65536 bytes *must* have their
15100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   offset normalized to zero.  The default allocation function provided by this
15200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   library ensures this (see zutil.c).  To reduce memory requirements and avoid
15300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   any allocation of 64K objects, at the expense of compression ratio, compile
15400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the library with -DMAX_WBITS=14 (see zconf.h).
15500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
15600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The fields total_in and total_out can be used for statistics or progress
15700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   reports.  After compression, total_in holds the total size of the
15800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed data and may be saved for use in the decompressor (particularly
15900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   if the decompressor wants to decompress everything in a single step).
16000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
16100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
16200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* constants */
16300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
16400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_NO_FLUSH      0
16500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_PARTIAL_FLUSH 1
16600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_SYNC_FLUSH    2
16700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_FULL_FLUSH    3
16800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_FINISH        4
16900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_BLOCK         5
17000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_TREES         6
17100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* Allowed flush values; see deflate() and inflate() below for details */
17200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
17300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_OK            0
17400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_STREAM_END    1
17500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_NEED_DICT     2
17600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_ERRNO        (-1)
17700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_STREAM_ERROR (-2)
17800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_DATA_ERROR   (-3)
17900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_MEM_ERROR    (-4)
18000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_BUF_ERROR    (-5)
18100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_VERSION_ERROR (-6)
18200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* Return codes for the compression/decompression functions. Negative values
18300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * are errors, positive values are used for special but normal events.
18400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
18500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
18600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_NO_COMPRESSION         0
18700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_BEST_SPEED             1
18800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_BEST_COMPRESSION       9
18900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_DEFAULT_COMPRESSION  (-1)
19000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* compression levels */
19100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
19200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_FILTERED            1
19300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_HUFFMAN_ONLY        2
19400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_RLE                 3
19500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_FIXED               4
19600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_DEFAULT_STRATEGY    0
19700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* compression strategy; see deflateInit2() below for details */
19800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
19900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_BINARY   0
20000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_TEXT     1
20100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
20200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_UNKNOWN  2
20300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* Possible values of the data_type field (though see inflate()) */
20400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
20500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_DEFLATED   8
20600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* The deflate compression method (the only one supported in this version) */
20700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
20800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
20900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
21000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define zlib_version zlibVersion()
21100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* for compatibility with versions < 1.0.2 */
21200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
21300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
21400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* basic functions */
21500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
21600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN const char * ZEXPORT zlibVersion OF((void));
21700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
21800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   If the first character differs, the library code actually used is not
21900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compatible with the zlib.h header file used by the application.  This check
22000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is automatically made by deflateInit and inflateInit.
22100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
22200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
22300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
22400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
22500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
22600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Initializes the internal stream state for compression.  The fields
22700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   zalloc, zfree and opaque must be initialized before by the caller.  If
22800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
22900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   allocation functions.
23000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
23100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
23200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   1 gives best speed, 9 gives best compression, 0 gives no compression at all
23300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
23400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   requests a default compromise between speed and compression (currently
23500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   equivalent to level 6).
23600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
23700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
23800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   memory, Z_STREAM_ERROR if level is not a valid compression level, or
23900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
24000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   with the version assumed by the caller (ZLIB_VERSION).  msg is set to null
24100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   if there is no error message.  deflateInit does not perform any compression:
24200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   this will be done by deflate().
24300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
24400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
24500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
24600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
24700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
24800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    deflate compresses as much data as possible, and stops when the input
24900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  buffer becomes empty or the output buffer becomes full.  It may introduce
25000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  some output latency (reading input without producing any output) except when
25100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  forced to flush.
25200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
25300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The detailed semantics are as follows.  deflate performs one or both of the
25400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  following actions:
25500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
25600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  - Compress more input starting at next_in and update next_in and avail_in
25700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    accordingly.  If not all input can be processed (because there is not
25800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    enough room in the output buffer), next_in and avail_in are updated and
25900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    processing will resume at this point for the next call of deflate().
26000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
26100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  - Provide more output starting at next_out and update next_out and avail_out
26200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    accordingly.  This action is forced if the parameter flush is non zero.
26300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Forcing flush frequently degrades the compression ratio, so this parameter
26400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    should be set only when necessary (in interactive applications).  Some
26500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    output may be provided even if flush is not set.
26600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
26700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Before the call of deflate(), the application should ensure that at least
26800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  one of the actions is possible, by providing more input and/or consuming more
26900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  output, and updating avail_in or avail_out accordingly; avail_out should
27000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  never be zero before the call.  The application can consume the compressed
27100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  output when it wants, for example when the output buffer is full (avail_out
27200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  == 0), or after each call of deflate().  If deflate returns Z_OK and with
27300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  zero avail_out, it must be called again after making room in the output
27400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  buffer because there might be more output pending.
27500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
27600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
27700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  decide how much data to accumulate before producing output, in order to
27800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  maximize compression.
27900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
28000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
28100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  flushed to the output buffer and the output is aligned on a byte boundary, so
28200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  that the decompressor can get all input data available so far.  (In
28300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  particular avail_in is zero after the call if enough output space has been
28400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  provided before the call.) Flushing may degrade compression for some
28500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  compression algorithms and so it should be used only when necessary.  This
28600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  completes the current deflate block and follows it with an empty stored block
28700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  that is three bits plus filler bits to the next byte, followed by four bytes
28800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  (00 00 ff ff).
28900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
29000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
29100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  output buffer, but the output is not aligned to a byte boundary.  All of the
29200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
29300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  This completes the current deflate block and follows it with an empty fixed
29400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  codes block that is 10 bits long.  This assures that enough bytes are output
29500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  in order for the decompressor to finish the block before the empty fixed code
29600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  block.
29700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
29800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
29900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
30000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  seven bits of the current block are held to be written as the next byte after
30100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the next deflate block is completed.  In this case, the decompressor may not
30200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  be provided enough bits at this point in order to complete decompression of
30300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the data provided so far to the compressor.  It may need to wait for the next
30400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  block to be emitted.  This is for advanced applications that need to control
30500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the emission of deflate blocks.
30600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
30700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    If flush is set to Z_FULL_FLUSH, all output is flushed as with
30800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Z_SYNC_FLUSH, and the compression state is reset so that decompression can
30900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  restart from this point if previous compressed data has been damaged or if
31000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  random access is desired.  Using Z_FULL_FLUSH too often can seriously degrade
31100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  compression.
31200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
31300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    If deflate returns with avail_out == 0, this function must be called again
31400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  with the same value of the flush parameter and more output space (updated
31500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  avail_out), until the flush is complete (deflate returns with non-zero
31600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  avail_out).  In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
31700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  avail_out is greater than six to avoid repeated flush markers due to
31800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  avail_out == 0 on return.
31900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
32000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    If the parameter flush is set to Z_FINISH, pending input is processed,
32100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  pending output is flushed and deflate returns with Z_STREAM_END if there was
32200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  enough output space; if deflate returns with Z_OK, this function must be
32300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  called again with Z_FINISH and more output space (updated avail_out) but no
32400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  more input data, until it returns with Z_STREAM_END or an error.  After
32500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  deflate has returned Z_STREAM_END, the only possible operations on the stream
32600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  are deflateReset or deflateEnd.
32700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
32800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Z_FINISH can be used immediately after deflateInit if all the compression
32900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  is to be done in a single step.  In this case, avail_out must be at least the
33000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  value returned by deflateBound (see below).  Then deflate is guaranteed to
33100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  return Z_STREAM_END.  If not enough output space is provided, deflate will
33200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  not return Z_STREAM_END, and it must be called again as described above.
33300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
33400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    deflate() sets strm->adler to the adler32 checksum of all input read
33500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  so far (that is, total_in bytes).
33600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
33700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    deflate() may update strm->data_type if it can make a good guess about
33800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the input data type (Z_BINARY or Z_TEXT).  In doubt, the data is considered
33900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  binary.  This field is only for information purposes and does not affect the
34000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  compression algorithm in any manner.
34100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
34200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    deflate() returns Z_OK if some progress has been made (more input
34300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  processed or more output produced), Z_STREAM_END if all input has been
34400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  consumed and all output has been produced (only when flush is set to
34500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
34600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
34700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  (for example avail_in or avail_out was zero).  Note that Z_BUF_ERROR is not
34800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  fatal, and deflate() can be called again with more input and more output
34900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  space to continue compressing.
35000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
35100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
35200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
35300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
35400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
35500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     All dynamically allocated data structures for this stream are freed.
35600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   This function discards any unprocessed input and does not flush any pending
35700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   output.
35800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
35900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
36000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
36100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   prematurely (some input or output was discarded).  In the error case, msg
36200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   may be set but then points to a static string (which must not be
36300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deallocated).
36400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
36500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
36600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
36700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
36800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
36900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
37000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Initializes the internal stream state for decompression.  The fields
37100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   next_in, avail_in, zalloc, zfree and opaque must be initialized before by
37200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the caller.  If next_in is not Z_NULL and avail_in is large enough (the
37300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   exact value depends on the compression method), inflateInit determines the
37400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compression method from the zlib header and allocates all data structures
37500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   accordingly; otherwise the allocation will be deferred to the first call of
37600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
37700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   use default allocation functions.
37800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
37900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
38000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
38100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   version assumed by the caller, or Z_STREAM_ERROR if the parameters are
38200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   invalid, such as a null pointer to the structure.  msg is set to null if
38300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   there is no error message.  inflateInit does not perform any decompression
38400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   apart from possibly reading the zlib header if present: actual decompression
38500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will be done by inflate().  (So next_in and avail_in may be modified, but
38600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   next_out and avail_out are unused and unchanged.) The current implementation
38700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of inflateInit() does not process any header information -- that is deferred
38800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   until inflate() is called.
38900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
39000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
39100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
39200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
39300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
39400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    inflate decompresses as much data as possible, and stops when the input
39500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  buffer becomes empty or the output buffer becomes full.  It may introduce
39600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  some output latency (reading input without producing any output) except when
39700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  forced to flush.
39800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
39900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  The detailed semantics are as follows.  inflate performs one or both of the
40000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  following actions:
40100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
40200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  - Decompress more input starting at next_in and update next_in and avail_in
40300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    accordingly.  If not all input can be processed (because there is not
40400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    enough room in the output buffer), next_in is updated and processing will
40500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    resume at this point for the next call of inflate().
40600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
40700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  - Provide more output starting at next_out and update next_out and avail_out
40800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    accordingly.  inflate() provides as much output as possible, until there is
40900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    no more input data or no more space in the output buffer (see below about
41000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    the flush parameter).
41100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
41200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Before the call of inflate(), the application should ensure that at least
41300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  one of the actions is possible, by providing more input and/or consuming more
41400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  output, and updating the next_* and avail_* values accordingly.  The
41500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  application can consume the uncompressed output when it wants, for example
41600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  when the output buffer is full (avail_out == 0), or after each call of
41700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  inflate().  If inflate returns Z_OK and with zero avail_out, it must be
41800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  called again after making room in the output buffer because there might be
41900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  more output pending.
42000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
42100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
42200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Z_BLOCK, or Z_TREES.  Z_SYNC_FLUSH requests that inflate() flush as much
42300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  output as possible to the output buffer.  Z_BLOCK requests that inflate()
42400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  stop if and when it gets to the next deflate block boundary.  When decoding
42500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  the zlib or gzip format, this will cause inflate() to return immediately
42600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  after the header and before the first block.  When doing a raw inflate,
42700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  inflate() will go ahead and process the first block, and will return when it
42800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  gets to the end of that block, or when it runs out of data.
42900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
43000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The Z_BLOCK option assists in appending to or combining deflate streams.
43100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Also to assist in this, on return inflate() will set strm->data_type to the
43200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  number of unused bits in the last byte taken from strm->next_in, plus 64 if
43300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  inflate() is currently decoding the last block in the deflate stream, plus
43400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  128 if inflate() returned immediately after decoding an end-of-block code or
43500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  decoding the complete header up to just before the first byte of the deflate
43600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  stream.  The end-of-block will not be indicated until all of the uncompressed
43700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  data from that block has been written to strm->next_out.  The number of
43800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  unused bits may in general be greater than seven, except when bit 7 of
43900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  data_type is set, in which case the number of unused bits will be less than
44000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  eight.  data_type is set as noted here every time inflate() returns for all
44100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  flush options, and so can be used to determine the amount of currently
44200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  consumed input in bits.
44300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
44400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
44500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  end of each deflate block header is reached, before any actual data in that
44600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  block is decoded.  This allows the caller to determine the length of the
44700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  deflate block header for later use in random access within a deflate block.
44800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  256 is added to the value of strm->data_type when inflate() returns
44900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  immediately after reaching the end of the deflate block header.
45000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
45100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    inflate() should normally be called until it returns Z_STREAM_END or an
45200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  error.  However if all decompression is to be performed in a single step (a
45300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  single call of inflate), the parameter flush should be set to Z_FINISH.  In
45400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  this case all pending input is processed and all pending output is flushed;
45509eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  avail_out must be large enough to hold all of the uncompressed data for the
45609eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  operation to complete.  (The size of the uncompressed data may have been
45709eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  saved by the compressor for this purpose.) The use of Z_FINISH is not
45809eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  required to perform an inflation in one step.  However it may be used to
45909eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  inform inflate that a faster approach can be used for the single inflate()
46009eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  call.  Z_FINISH also informs inflate to not maintain a sliding window if the
46109eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  stream completes, which reduces inflate's memory footprint.  If the stream
46209eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  does not complete, either because not all of the stream is provided or not
46309eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  enough output space is provided, then a sliding window will be allocated and
46409eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  inflate() can be called again to continue the operation as if Z_NO_FLUSH had
46509eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes  been used.
46600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
46700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     In this implementation, inflate() always flushes as much output as
46800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  possible to the output buffer, and always uses the faster approach on the
46900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  first call.  So the effects of the flush parameter in this implementation are
47000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  on the return value of inflate() as noted below, when inflate() returns early
47100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
47200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  memory for a sliding window when Z_FINISH is used.
47300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
47400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If a preset dictionary is needed after this call (see inflateSetDictionary
47500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
47600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
47700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  strm->adler to the Adler-32 checksum of all output produced so far (that is,
47800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
47900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  below.  At the end of the stream, inflate() checks that its computed adler32
48000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  checksum is equal to that saved by the compressor and returns Z_STREAM_END
48100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  only if the checksum is correct.
48200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
48300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    inflate() can decompress and check either zlib-wrapped or gzip-wrapped
48400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  deflate data.  The header type is detected automatically, if requested when
48500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  initializing with inflateInit2().  Any information contained in the gzip
48600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  header is not retained, so applications that need that information should
48700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  instead use raw inflate, see inflateInit2() below, or inflateBack() and
48800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  perform their own processing of the gzip header and trailer.  When processing
48900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
49000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  producted so far.  The CRC-32 is checked against the gzip trailer.
49100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
49200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    inflate() returns Z_OK if some progress has been made (more input processed
49300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  or more output produced), Z_STREAM_END if the end of the compressed data has
49400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  been reached and all uncompressed output has been produced, Z_NEED_DICT if a
49500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
49600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  corrupted (input stream not conforming to the zlib format or incorrect check
49700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
49800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
49900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
50000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  output buffer when Z_FINISH is used.  Note that Z_BUF_ERROR is not fatal, and
50100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  inflate() can be called again with more input and more output space to
50200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  continue decompressing.  If Z_DATA_ERROR is returned, the application may
50300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  then call inflateSync() to look for a good compression block if a partial
50400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes  recovery of the data is desired.
50500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
50600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
50700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
50800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
50900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
51000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     All dynamically allocated data structures for this stream are freed.
51100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   This function discards any unprocessed input and does not flush any pending
51200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   output.
51300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
51400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
51500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   was inconsistent.  In the error case, msg may be set but then points to a
51600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   static string (which must not be deallocated).
51700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
51800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
51900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
52000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* Advanced functions */
52100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
52200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
52300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The following functions are needed only in some special applications.
52400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
52500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
52600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
52700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
52800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int  level,
52900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int  method,
53000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int  windowBits,
53100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int  memLevel,
53200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int  strategy));
53300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
53400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This is another version of deflateInit with more compression options.  The
53500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fields next_in, zalloc, zfree and opaque must be initialized before by the
53600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   caller.
53700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
53800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The method parameter is the compression method.  It must be Z_DEFLATED in
53900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   this version of the library.
54000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
54100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The windowBits parameter is the base two logarithm of the window size
54200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   (the size of the history buffer).  It should be in the range 8..15 for this
54300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   version of the library.  Larger values of this parameter result in better
54400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compression at the expense of memory usage.  The default value is 15 if
54500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateInit is used instead.
54600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
54700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     windowBits can also be -8..-15 for raw deflate.  In this case, -windowBits
54800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   determines the window size.  deflate() will then generate raw deflate data
54900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   with no zlib header or trailer, and will not compute an adler32 check value.
55000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
55100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     windowBits can also be greater than 15 for optional gzip encoding.  Add
55200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   16 to windowBits to write a simple gzip header and trailer around the
55300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed data instead of a zlib wrapper.  The gzip header will have no
55400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file name, no extra data, no comment, no modification time (set to zero), no
55500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   header crc, and the operating system will be set to 255 (unknown).  If a
55600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzip stream is being written, strm->adler is a crc32 instead of an adler32.
55700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
55800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The memLevel parameter specifies how much memory should be allocated
55900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   for the internal compression state.  memLevel=1 uses minimum memory but is
56000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   slow and reduces compression ratio; memLevel=9 uses maximum memory for
56100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   optimal speed.  The default value is 8.  See zconf.h for total memory usage
56200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   as a function of windowBits and memLevel.
56300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
56400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The strategy parameter is used to tune the compression algorithm.  Use the
56500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
56600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
56700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   string match), or Z_RLE to limit match distances to one (run-length
56800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   encoding).  Filtered data consists mostly of small values with a somewhat
56900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   random distribution.  In this case, the compression algorithm is tuned to
57000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compress them better.  The effect of Z_FILTERED is to force more Huffman
57100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   coding and less string matching; it is somewhat intermediate between
57200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY.  Z_RLE is designed to be almost as
57300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data.  The
57400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   strategy parameter only affects the compression ratio but not the
57500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   correctness of the compressed output even if it is not set appropriately.
57600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
57700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   decoder for special applications.
57800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
57900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
58000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
58100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
58200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   incompatible with the version assumed by the caller (ZLIB_VERSION).  msg is
58300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   set to null if there is no error message.  deflateInit2 does not perform any
58400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compression: this will be done by deflate().
58500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
58600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
58700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
58800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                             const Bytef *dictionary,
58900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                             uInt  dictLength));
59000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
59100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Initializes the compression dictionary from the given byte sequence
59200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   without producing any compressed output.  When using the zlib format, this
59300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   function must be called immediately after deflateInit, deflateInit2 or
59400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateReset, and before any call of deflate.  When doing raw deflate, this
59500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   function must be called either before any call of deflate, or immediately
59600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   after the completion of a deflate block, i.e. after all input has been
59700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   consumed and all output has been delivered when using any of the flush
59800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH.  The
59900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressor and decompressor must use exactly the same dictionary (see
60000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflateSetDictionary).
60100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
60200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The dictionary should consist of strings (byte sequences) that are likely
60300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to be encountered later in the data to be compressed, with the most commonly
60400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   used strings preferably put towards the end of the dictionary.  Using a
60500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   dictionary is most useful when the data to be compressed is short and can be
60600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   predicted with good accuracy; the data can then be compressed better than
60700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   with the default empty dictionary.
60800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
60900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Depending on the size of the compression data structures selected by
61000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateInit or deflateInit2, a part of the dictionary may in effect be
61100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   discarded, for example if the dictionary is larger than the window size
61200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   provided in deflateInit or deflateInit2.  Thus the strings most likely to be
61300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   useful should be put at the end of the dictionary, not at the front.  In
61400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   addition, the current implementation of deflate will use at most the window
61500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   size minus 262 bytes of the provided dictionary.
61600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
61700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Upon return of this function, strm->adler is set to the adler32 value
61800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of the dictionary; the decompressor may later use this value to determine
61900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   which dictionary has been used by the compressor.  (The adler32 value
62000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   applies to the whole dictionary even if only a subset of the dictionary is
62100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   actually used by the compressor.) If a raw deflate was requested, then the
62200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   adler32 value is not computed and strm->adler is not set.
62300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
62400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
62500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
62600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inconsistent (for example if deflate has already been called for this stream
62700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   or if not at a block boundary for raw deflate).  deflateSetDictionary does
62800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   not perform any compression: this will be done by deflate().
62900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
63000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
63100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
63200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    z_streamp source));
63300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
63400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Sets the destination stream as a complete copy of the source stream.
63500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
63600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function can be useful when several compression strategies will be
63700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   tried, for example when there are several ways of pre-processing the input
63800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   data with a filter.  The streams that will be discarded should then be freed
63900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   by calling deflateEnd.  Note that deflateCopy duplicates the internal
64000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compression state which can be quite large, so this strategy is slow and can
64100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   consume lots of memory.
64200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
64300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
64400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
64500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   (such as zalloc being Z_NULL).  msg is left unchanged in both source and
64600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   destination.
64700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
64800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
64900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
65000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
65100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function is equivalent to deflateEnd followed by deflateInit,
65200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   but does not free and reallocate all the internal compression state.  The
65300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream will keep the same compression level and any other attributes that
65400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   may have been set by deflateInit2.
65500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
65600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
65700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent (such as zalloc or state being Z_NULL).
65800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
65900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
66000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
66100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      int level,
66200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      int strategy));
66300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
66400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Dynamically update the compression level and compression strategy.  The
66500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   interpretation of level and strategy is as in deflateInit2.  This can be
66600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   used to switch between compression and straight copy of the input data, or
66700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to switch to a different kind of input data requiring a different strategy.
66800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   If the compression level is changed, the input available so far is
66900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed with the old level (and may be flushed); the new level will take
67000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   effect only at the next call of deflate().
67100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
67200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Before the call of deflateParams, the stream state must be set as for
67300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   a call of deflate(), since the currently available input may have to be
67400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed and flushed.  In particular, strm->avail_out must be non-zero.
67500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
67600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
67700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
67800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   strm->avail_out was zero.
67900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
68000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
68100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
68200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    int good_length,
68300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    int max_lazy,
68400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    int nice_length,
68500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    int max_chain));
68600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
68700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Fine tune deflate's internal compression parameters.  This should only be
68800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   used by someone who understands the algorithm used by zlib's deflate for
68900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   searching for the best matching string, and even then only by the most
69000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fanatic optimizer trying to squeeze out the last compressed bit for their
69100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   specific input data.  Read the deflate.c source code for the meaning of the
69200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   max_lazy, good_length, nice_length, and max_chain parameters.
69300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
69400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateTune() can be called after deflateInit() or deflateInit2(), and
69500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
69600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
69700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
69800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
69900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                       uLong sourceLen));
70000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
70100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateBound() returns an upper bound on the compressed size after
70200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflation of sourceLen bytes.  It must be called after deflateInit() or
70300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateInit2(), and after deflateSetHeader(), if used.  This would be used
70400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to allocate an output buffer for deflation in a single pass, and so would be
70500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   called before deflate().  If that first deflate() call is provided the
70600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   sourceLen input bytes, an output buffer allocated to the size returned by
70700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
70800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to return Z_STREAM_END.  Note that it is possible for the compressed size to
70900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   be larger than the value returned by deflateBound() if flush options other
71000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   than Z_FINISH or Z_NO_FLUSH are used.
71100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
71200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
71300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
71400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                       unsigned *pending,
71500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                       int *bits));
71600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
71700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflatePending() returns the number of bytes and bits of output that have
71800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   been generated, but not yet provided in the available output.  The bytes not
71900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   provided would be due to the available output space having being consumed.
72000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   The number of bits of output not provided are between 0 and 7, where they
72100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   await more bits to join them in order to fill out a full byte.  If pending
72200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   or bits are Z_NULL, then those values are not set.
72300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
72400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
72500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent.
72600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
72700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
72800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
72900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int bits,
73000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int value));
73100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
73200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflatePrime() inserts bits in the deflate output stream.  The intent
73300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is that this function is used to start off the deflate output with the bits
73400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   leftover from a previous deflate stream when appending to it.  As such, this
73500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   function can only be used for raw deflate, and must be used before the first
73600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflate() call after a deflateInit2() or deflateReset().  bits must be less
73700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   than or equal to 16, and that many of the least significant bits of value
73800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will be inserted in the output.
73900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
74000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
74100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
74200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   source stream state was inconsistent.
74300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
74400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
74500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
74600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                         gz_headerp head));
74700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
74800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateSetHeader() provides gzip header information for when a gzip
74900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream is requested by deflateInit2().  deflateSetHeader() may be called
75000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   after deflateInit2() or deflateReset() and before the first call of
75100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflate().  The text, time, os, extra field, name, and comment information
75200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   in the provided gz_header structure are written to the gzip header (xflag is
75300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ignored -- the extra flags are set according to the compression level).  The
75400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   caller must assure that, if not Z_NULL, name and comment are terminated with
75500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
75600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   available there.  If hcrc is true, a gzip header crc is included.  Note that
75700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the current versions of the command-line version of gzip (up through version
75800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   1.3.x) do not support header crc's, and will report that it is a "multi-part
75900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzip file" and give up.
76000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
76100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If deflateSetHeader is not used, the default gzip header has text false,
76200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the time set to zero, and os set to 255, with no extra, name, or comment
76300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fields.  The gzip header is returned to the default state by deflateReset().
76400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
76500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
76600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent.
76700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
76800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
76900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
77000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
77100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int  windowBits));
77200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
77300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This is another version of inflateInit with an extra parameter.  The
77400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
77500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   before by the caller.
77600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
77700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The windowBits parameter is the base two logarithm of the maximum window
77800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   size (the size of the history buffer).  It should be in the range 8..15 for
77900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   this version of the library.  The default value is 15 if inflateInit is used
78000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   instead.  windowBits must be greater than or equal to the windowBits value
78100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   provided to deflateInit2() while compressing, or it must be equal to 15 if
78200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateInit2() was not used.  If a compressed stream with a larger window
78300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   size is given as input, inflate() will return with the error code
78400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_DATA_ERROR instead of trying to allocate a larger window.
78500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
78600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     windowBits can also be zero to request that inflate use the window size in
78700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the zlib header of the compressed stream.
78800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
78900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     windowBits can also be -8..-15 for raw inflate.  In this case, -windowBits
79000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   determines the window size.  inflate() will then process raw deflate data,
79100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   not looking for a zlib or gzip header, not generating a check value, and not
79200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   looking for any check values for comparison at the end of the stream.  This
79300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is for use with other formats that use the deflate compressed data format
79400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   such as zip.  Those formats provide their own check values.  If a custom
79500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   format is developed using the raw deflate format for compressed data, it is
79600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   recommended that a check value such as an adler32 or a crc32 be applied to
79700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the uncompressed data as is done in the zlib, gzip, and zip formats.  For
79800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   most applications, the zlib format should be used as is.  Note that comments
79900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   above on the use in deflateInit2() applies to the magnitude of windowBits.
80000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
80100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     windowBits can also be greater than 15 for optional gzip decoding.  Add
80200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   32 to windowBits to enable zlib and gzip decoding with automatic header
80300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   detection, or add 16 to decode only the gzip format (the zlib format will
80400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is a
80500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   crc32 instead of an adler32.
80600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
80700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
80800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
80900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   version assumed by the caller, or Z_STREAM_ERROR if the parameters are
81000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   invalid, such as a null pointer to the structure.  msg is set to null if
81100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   there is no error message.  inflateInit2 does not perform any decompression
81200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   apart from possibly reading the zlib header if present: actual decompression
81300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will be done by inflate().  (So next_in and avail_in may be modified, but
81400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   next_out and avail_out are unused and unchanged.) The current implementation
81500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of inflateInit2() does not process any header information -- that is
81600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deferred until inflate() is called.
81700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
81800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
81900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
82000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                             const Bytef *dictionary,
82100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                             uInt  dictLength));
82200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
82300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Initializes the decompression dictionary from the given uncompressed byte
82400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   sequence.  This function must be called immediately after a call of inflate,
82500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   if that call returned Z_NEED_DICT.  The dictionary chosen by the compressor
82600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   can be determined from the adler32 value returned by that call of inflate.
82700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   The compressor and decompressor must use exactly the same dictionary (see
82800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateSetDictionary).  For raw inflate, this function can be called at any
82900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   time to set the dictionary.  If the provided dictionary is smaller than the
83000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   window and there is already data in the window, then the provided dictionary
83100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will amend what's there.  The application must insure that the dictionary
83200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   that was used for compression is provided.
83300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
83400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
83500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is
83600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
83700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   expected one (incorrect adler32 value).  inflateSetDictionary does not
83800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   perform any decompression: this will be done by subsequent calls of
83900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflate().
84000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
84100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
84200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
84300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
84400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Skips invalid compressed data until a possible full flush point (see above
84500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   for the description of deflate with Z_FULL_FLUSH) can be found, or until all
84600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   available input is skipped.  No output is provided.
84700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
84800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateSync searches for a 00 00 FF FF pattern in the compressed data.
84900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   All full flush points have this pattern, but not all occurences of this
85000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   pattern are full flush points.
85100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
85200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateSync returns Z_OK if a possible full flush point has been found,
85300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
85400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
85500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   In the success case, the application may save the current current value of
85600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   total_in which indicates where valid compressed data was found.  In the
85700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   error case, the application may repeatedly call inflateSync, providing more
85800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   input each time, until success or end of the input data.
85900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
86000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
86100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
86200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    z_streamp source));
86300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
86400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Sets the destination stream as a complete copy of the source stream.
86500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
86600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function can be useful when randomly accessing a large stream.  The
86700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   first pass through the stream can periodically record the inflate state,
86800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   allowing restarting inflate at those points when randomly accessing the
86900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream.
87000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
87100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
87200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
87300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   (such as zalloc being Z_NULL).  msg is left unchanged in both source and
87400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   destination.
87500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
87600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
87700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
87800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
87900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function is equivalent to inflateEnd followed by inflateInit,
88000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   but does not free and reallocate all the internal decompression state.  The
88100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream will keep attributes that may have been set by inflateInit2.
88200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
88300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
88400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent (such as zalloc or state being Z_NULL).
88500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
88600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
88700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
88800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      int windowBits));
88900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
89000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function is the same as inflateReset, but it also permits changing
89100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the wrap and window size requests.  The windowBits parameter is interpreted
89200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the same as it is for inflateInit2.
89300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
89400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
89500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent (such as zalloc or state being Z_NULL), or if
89600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the windowBits parameter is invalid.
89700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
89800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
89900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
90000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int bits,
90100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     int value));
90200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
90300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function inserts bits in the inflate input stream.  The intent is
90400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   that this function is used to start inflating at a bit position in the
90500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   middle of a byte.  The provided bits will be used before any bytes are used
90600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   from next_in.  This function should only be used with raw inflate, and
90700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   should be used before the first inflate() call after inflateInit2() or
90800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflateReset().  bits must be less than or equal to 16, and that many of the
90900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   least significant bits of value will be inserted in the input.
91000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
91100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If bits is negative, then the input stream bit buffer is emptied.  Then
91200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflatePrime() can be called again to put bits in the buffer.  This is used
91300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to clear out bits leftover after feeding inflate a block description prior
91400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to feeding inflate codes.
91500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
91600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
91700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent.
91800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
91900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
92000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
92100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
92200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This function returns two values, one in the lower 16 bits of the return
92300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   value, and the other in the remaining upper bits, obtained by shifting the
92400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   return value down 16 bits.  If the upper value is -1 and the lower value is
92500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   zero, then inflate() is currently decoding information outside of a block.
92600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   If the upper value is -1 and the lower value is non-zero, then inflate is in
92700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the middle of a stored block, with the lower value equaling the number of
92800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   bytes from the input remaining to copy.  If the upper value is not -1, then
92900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   it is the number of bits back from the current bit position in the input of
93000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the code (literal or length/distance pair) currently being processed.  In
93100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   that case the lower value is the number of bytes already emitted for that
93200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   code.
93300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
93400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     A code is being processed if inflate is waiting for more input to complete
93500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   decoding of the code, or if it has completed decoding but is waiting for
93600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   more output space to write the literal or match data.
93700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
93800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateMark() is used to mark locations in the input data for random
93900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   access, which may be at bit positions, and to note those cases where the
94000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   output of a code may span boundaries of random access blocks.  The current
94100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   location in the input stream can be determined from avail_in and data_type
94200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   as noted in the description for the Z_BLOCK flush parameter for inflate.
94300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
94400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateMark returns the value noted above or -1 << 16 if the provided
94500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   source stream state was inconsistent.
94600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
94700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
94800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
94900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                         gz_headerp head));
95000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
95100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateGetHeader() requests that gzip header information be stored in the
95200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   provided gz_header structure.  inflateGetHeader() may be called after
95300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflateInit2() or inflateReset(), and before the first call of inflate().
95400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   As inflate() processes the gzip stream, head->done is zero until the header
95500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is completed, at which time head->done is set to one.  If a zlib stream is
95600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   being decoded, then head->done is set to -1 to indicate that there will be
95700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   no gzip header information forthcoming.  Note that Z_BLOCK or Z_TREES can be
95800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   used to force inflate() to return immediately after header processing is
95900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   complete and before any actual data is decompressed.
96000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
96100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The text, time, xflags, and os fields are filled in with the gzip header
96200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   contents.  hcrc is set to true if there is a header CRC.  (The header CRC
96300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   was valid if done is set to one.) If extra is not Z_NULL, then extra_max
96400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   contains the maximum number of bytes to write to extra.  Once done is true,
96500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   extra_len contains the actual extra field length, and extra contains the
96600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   extra field, or that field truncated if extra_max is less than extra_len.
96700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   If name is not Z_NULL, then up to name_max characters are written there,
96800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   terminated with a zero unless the length is greater than name_max.  If
96900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   comment is not Z_NULL, then up to comm_max characters are written there,
97000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   terminated with a zero unless the length is greater than comm_max.  When any
97100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of extra, name, or comment are not Z_NULL and the respective field is not
97200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   present in the header, then that field is set to Z_NULL to signal its
97300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   absence.  This allows the use of deflateSetHeader() with the returned
97400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   structure to duplicate the header.  However if those fields are set to
97500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   allocated memory, then the application will need to save those pointers
97600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   elsewhere so that they can be eventually freed.
97700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
97800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If inflateGetHeader is not used, then the header information is simply
97900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   discarded.  The header is always checked for validity, including the header
98000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   CRC if present.  inflateReset() will reset the process to discard the header
98100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   information.  The application would need to call inflateGetHeader() again to
98200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   retrieve the header from the next gzip stream.
98300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
98400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
98500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream state was inconsistent.
98600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
98700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
98800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
98900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
99000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                        unsigned char FAR *window));
99100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
99200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Initialize the internal stream state for decompression using inflateBack()
99300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   calls.  The fields zalloc, zfree and opaque in strm must be initialized
99400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   before the call.  If zalloc and zfree are Z_NULL, then the default library-
99500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   derived memory allocation routines are used.  windowBits is the base two
99600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   logarithm of the window size, in the range 8..15.  window is a caller
99700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   supplied buffer of that size.  Except for special applications where it is
99800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   assured that deflate was used with small window sizes, windowBits must be 15
99900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   and a 32K byte window must be supplied to be able to decompress general
100000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflate streams.
100100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
100200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     See inflateBack() for the usage of these routines.
100300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
100400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
100500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the parameters are invalid, Z_MEM_ERROR if the internal state could not be
100600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   allocated, or Z_VERSION_ERROR if the version of the library does not match
100700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the version of the header file.
100800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
100900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
101000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
101100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
101200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
101300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
101400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    in_func in, void FAR *in_desc,
101500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                    out_func out, void FAR *out_desc));
101600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
101700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateBack() does a raw inflate with a single call using a call-back
101800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   interface for input and output.  This is more efficient than inflate() for
101900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file i/o applications in that it avoids copying between the output and the
102000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   sliding window by simply making the window itself the output buffer.  This
102100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   function trusts the application to not change the output buffer passed by
102200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the output function, at least until inflateBack() returns.
102300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
102400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateBackInit() must be called first to allocate the internal state
102500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   and to initialize the state with the user-provided window buffer.
102600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflateBack() may then be used multiple times to inflate a complete, raw
102700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflate stream with each call.  inflateBackEnd() is then called to free the
102800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   allocated state.
102900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
103000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     A raw deflate stream is one with no zlib or gzip header or trailer.
103100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   This routine would normally be used in a utility that reads zip or gzip
103200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   files and writes out uncompressed files.  The utility would decode the
103300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   header and process the trailer on its own, hence this routine expects only
103400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the raw deflate stream to decompress.  This is different from the normal
103500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   behavior of inflate(), which expects either a zlib or gzip header and
103600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   trailer around the deflate stream.
103700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
103800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateBack() uses two subroutines supplied by the caller that are then
103900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   called by inflateBack() for input and output.  inflateBack() calls those
104000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   routines until it reads a complete deflate stream and writes out all of the
104100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed data, or until it encounters an error.  The function's
104200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   parameters and return types are defined above in the in_func and out_func
104300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
104400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   number of bytes of provided input, and a pointer to that input in buf.  If
104500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   there is no input available, in() must return zero--buf is ignored in that
104600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   case--and inflateBack() will return a buffer error.  inflateBack() will call
104700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()
104800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   should return zero on success, or non-zero on failure.  If out() returns
104900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   non-zero, inflateBack() will return with an error.  Neither in() nor out()
105000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   are permitted to change the contents of the window provided to
105100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   inflateBackInit(), which is also the buffer that out() uses to write from.
105200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   The length written by out() will be at most the window size.  Any non-zero
105300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   amount of input may be provided by in().
105400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
105500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     For convenience, inflateBack() can be provided input on the first call by
105600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   setting strm->next_in and strm->avail_in.  If that input is exhausted, then
105700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   in() will be called.  Therefore strm->next_in must be initialized before
105800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called
105900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
106000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   must also be initialized, and then if strm->avail_in is not zero, input will
106100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   initially be taken from strm->next_in[0 ..  strm->avail_in - 1].
106200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
106300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The in_desc and out_desc parameters of inflateBack() is passed as the
106400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   first parameter of in() and out() respectively when they are called.  These
106500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   descriptors can be optionally used to pass any information that the caller-
106600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   supplied in() and out() functions need to do their job.
106700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
106800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     On return, inflateBack() will set strm->next_in and strm->avail_in to
106900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   pass back any unused input that was provided by the last in() call.  The
107000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
107100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   if in() or out() returned an error, Z_DATA_ERROR if there was a format error
107200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   in the deflate stream (in which case strm->msg is set to indicate the nature
107300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
107400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   In the case of Z_BUF_ERROR, an input or output error can be distinguished
107500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   using strm->next_in which will be Z_NULL only if in() returned an error.  If
107600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
107700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   non-zero.  (in() will always be called before out(), so strm->next_in is
107800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   assured to be defined if out() returns non-zero.) Note that inflateBack()
107900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   cannot return Z_OK.
108000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
108100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
108200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
108300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
108400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     All memory allocated by inflateBackInit() is freed.
108500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
108600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
108700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   state was inconsistent.
108800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
108900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
109000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
109100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* Return flags indicating compile-time options.
109200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
109300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
109400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     1.0: size of uInt
109500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     3.2: size of uLong
109600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     5.4: size of voidpf (pointer)
109700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     7.6: size of z_off_t
109800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
109900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Compiler, assembler, and debug options:
110000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     8: DEBUG
110100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     9: ASMV or ASMINF -- use ASM code
110200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
110300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     11: 0 (reserved)
110400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
110500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    One-time table building (smaller code, but not thread-safe if true):
110600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     12: BUILDFIXED -- build static block decoding tables when needed
110700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
110800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     14,15: 0 (reserved)
110900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
111000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Library content (indicates missing functionality):
111100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
111200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                          deflate code when not needed)
111300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
111400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                    and decode gzip streams (to avoid linking crc code)
111500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     18-19: 0 (reserved)
111600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
111700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Operation variations (changes in library functionality):
111800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
111900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     21: FASTEST -- deflate algorithm with only one, lowest compression level
112000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     22,23: 0 (reserved)
112100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
112200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    The sprintf variant used by gzprintf (zero is best):
112300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
112400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
112500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     26: 0 = returns value, 1 = void -- 1 means inferred string length returned
112600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
112700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    Remainder:
112800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     27-31: 0 (reserved)
112900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
113000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
113100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#ifndef Z_SOLO
113200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
113300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* utility functions */
113400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
113500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
113600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The following utility functions are implemented on top of the basic
113700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream-oriented functions.  To simplify the interface, some default options
113800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   are assumed (compression level and memory usage, standard memory allocation
113900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   functions).  The source code of these utility functions can be modified if
114000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   you need special options.
114100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
114200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
114300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
114400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                 const Bytef *source, uLong sourceLen));
114500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
114600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Compresses the source buffer into the destination buffer.  sourceLen is
114700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the byte length of the source buffer.  Upon entry, destLen is the total size
114800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of the destination buffer, which must be at least the value returned by
114900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressBound(sourceLen).  Upon exit, destLen is the actual size of the
115000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed buffer.
115100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
115200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     compress returns Z_OK if success, Z_MEM_ERROR if there was not
115300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   enough memory, Z_BUF_ERROR if there was not enough room in the output
115400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   buffer.
115500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
115600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
115700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
115800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                  const Bytef *source, uLong sourceLen,
115900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                  int level));
116000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
116100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Compresses the source buffer into the destination buffer.  The level
116200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   parameter has the same meaning as in deflateInit.  sourceLen is the byte
116300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   length of the source buffer.  Upon entry, destLen is the total size of the
116400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   destination buffer, which must be at least the value returned by
116500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressBound(sourceLen).  Upon exit, destLen is the actual size of the
116600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed buffer.
116700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
116800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
116900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
117000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_STREAM_ERROR if the level parameter is invalid.
117100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
117200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
117300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
117400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
117500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     compressBound() returns an upper bound on the compressed size after
117600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compress() or compress2() on sourceLen bytes.  It would be used before a
117700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compress() or compress2() call to allocate the destination buffer.
117800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
117900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
118000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
118100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                   const Bytef *source, uLong sourceLen));
118200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
118300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Decompresses the source buffer into the destination buffer.  sourceLen is
118400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the byte length of the source buffer.  Upon entry, destLen is the total size
118500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of the destination buffer, which must be large enough to hold the entire
118600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed data.  (The size of the uncompressed data must have been saved
118700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   previously by the compressor and transmitted to the decompressor by some
118800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   mechanism outside the scope of this compression library.) Upon exit, destLen
118900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is the actual size of the uncompressed buffer.
119000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
119100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
119200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   enough memory, Z_BUF_ERROR if there was not enough room in the output
119300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.  In
119400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the case where there is not enough room, uncompress() will fill the output
119500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   buffer with the uncompressed data up to that point.
119600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
119700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
119800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* gzip file access functions */
119900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
120000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
120100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     This library supports reading and writing files in gzip (.gz) format with
120200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   an interface similar to that of stdio, using the functions that start with
120300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   "gz".  The gzip format is different from the zlib format.  gzip is a gzip
120400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   wrapper, documented in RFC 1952, wrapped around a deflate stream.
120500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
120600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
120700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughestypedef struct gzFile_s *gzFile;    /* semi-opaque gzip file descriptor */
120800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
120900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
121000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
121100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
121200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Opens a gzip (.gz) file for reading or writing.  The mode parameter is as
121300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
121400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
121500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
121600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   for fixed code compression as in "wb9F".  (See the description of
121700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deflateInit2 for more information about the strategy parameter.)  'T' will
121800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   request transparent writing or appending with no compression and not using
121900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the gzip format.
122000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
122100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     "a" can be used instead of "w" to request that the gzip stream that will
122200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   be written be appended to the file.  "+" will result in an error, since
122309eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes   reading and writing to the same gzip file is not supported.  The addition of
122409eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes   "x" when writing will create the file exclusively, which fails if the file
122509eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes   already exists.  On systems that support it, the addition of "e" when
122609eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes   reading or writing will set the flag to close the file on an execve() call.
122700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
122800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     These functions, as well as gzip, will read and decode a sequence of gzip
122900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   streams in a file.  The append function of gzopen() can be used to create
123000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   such a file.  (Also see gzflush() for another way to do this.)  When
123100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   appending, gzopen does not test whether the file begins with a gzip stream,
123200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   nor does it look for the end of the gzip streams to begin appending.  gzopen
123300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will simply append a gzip stream to the existing file.
123400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
123500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzopen can be used to read a file which is not in gzip format; in this
123600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   case gzread will directly read from the file without decompression.  When
123700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   reading, this will be detected automatically by looking for the magic two-
123800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   byte gzip header.
123900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
124000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzopen returns NULL if the file could not be opened, if there was
124100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   insufficient memory to allocate the gzFile state, or if an invalid mode was
124200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
124300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   errno can be checked to determine if the reason gzopen failed was that the
124400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file could not be opened.
124500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
124600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
124700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
124800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
124900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzdopen associates a gzFile with the file descriptor fd.  File descriptors
125000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   are obtained from calls like open, dup, creat, pipe or fileno (if the file
125100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   has been previously opened with fopen).  The mode parameter is as in gzopen.
125200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
125300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The next call of gzclose on the returned gzFile will also close the file
125400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
125500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
125600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   mode);.  The duplicated descriptor should be saved to avoid a leak, since
125700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzdopen does not close fd if it fails.  If you are using fileno() to get the
125800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file descriptor from a FILE *, then you will have to use dup() to avoid
125900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   double-close()ing the file descriptor.  Both gzclose() and fclose() will
126000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   close the associated file descriptor, so they need to have different file
126100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   descriptors.
126200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
126300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzdopen returns NULL if there was insufficient memory to allocate the
126400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
126500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   provided, or '+' was provided), or if fd is -1.  The file descriptor is not
126600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   used until the next gz* read, write, seek, or close operation, so gzdopen
126700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will not detect if fd is invalid (unless fd is -1).
126800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
126900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
127000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
127100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
127200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Set the internal buffer size used by this library's functions.  The
127300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   default buffer size is 8192 bytes.  This function must be called after
127400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzopen() or gzdopen(), and before any other calls that read or write the
127500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file.  The buffer memory allocation is always deferred to the first read or
127600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   write.  Two buffers are allocated, either both of the specified size when
127700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   writing, or one of the specified size and the other twice that size when
127800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   reading.  A larger buffer size of, for example, 64K or 128K bytes will
127900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   noticeably increase the speed of decompression (reading).
128000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
128100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The new buffer size also affects the maximum length for gzprintf().
128200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
128300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzbuffer() returns 0 on success, or -1 on failure, such as being called
128400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   too late.
128500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
128600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
128700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
128800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
128900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Dynamically update the compression level or strategy.  See the description
129000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of deflateInit2 for the meaning of these parameters.
129100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
129200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
129300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   opened for writing.
129400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
129500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
129600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
129700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
129800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Reads the given number of uncompressed bytes from the compressed file.  If
129900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the input file is not in gzip format, gzread copies the given number of
130000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   bytes into the buffer directly from the file.
130100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
130200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     After reaching the end of a gzip stream in the input, gzread will continue
130300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to read, looking for another gzip stream.  Any number of gzip streams may be
130400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   concatenated in the input file, and will all be decompressed by gzread().
130500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   If something other than a gzip stream is encountered after a gzip stream,
130600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   that remaining trailing garbage is ignored (and no error is returned).
130700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
130800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzread can be used to read a gzip file that is being concurrently written.
130900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Upon reaching the end of the input, gzread will return with the available
131000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
131100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzclearerr can be used to clear the end of file indicator in order to permit
131200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzread to be tried again.  Z_OK indicates that a gzip stream was completed
131300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
131400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   middle of a gzip stream.  Note that gzread does not return -1 in the event
131500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   of an incomplete gzip stream.  This error is deferred until gzclose(), which
131600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
131700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   stream.  Alternatively, gzerror can be used before gzclose to detect this
131800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   case.
131900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
132000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzread returns the number of uncompressed bytes actually read, less than
132100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   len for end of file, or -1 for error.
132200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
132300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
132400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzwrite OF((gzFile file,
132500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                voidpc buf, unsigned len));
132600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
132700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Writes the given number of uncompressed bytes into the compressed file.
132800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzwrite returns the number of uncompressed bytes written or 0 in case of
132900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   error.
133000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
133100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
133200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
133300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
133400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Converts, formats, and writes the arguments to the compressed file under
133500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   control of the format string, as in fprintf.  gzprintf returns the number of
133600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed bytes actually written, or 0 in case of error.  The number of
133700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed bytes written is limited to 8191, or one less than the buffer
133800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   size given to gzbuffer().  The caller should assure that this limit is not
133900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   exceeded.  If it is exceeded, then gzprintf() will return an error (0) with
134000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   nothing written.  In this case, there may also be a buffer overflow with
134100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   unpredictable consequences, which is possible only if zlib was compiled with
134200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the insecure functions sprintf() or vsprintf() because the secure snprintf()
134300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   or vsnprintf() functions were not available.  This can be determined using
134400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   zlibCompileFlags().
134500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
134600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
134700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
134800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
134900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Writes the given null-terminated string to the compressed file, excluding
135000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the terminating null character.
135100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
135200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzputs returns the number of characters written, or -1 in case of error.
135300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
135400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
135500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
135600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
135700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Reads bytes from the compressed file until len-1 characters are read, or a
135800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   newline character is read and transferred to buf, or an end-of-file
135900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   condition is encountered.  If any characters are read or if len == 1, the
136000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   string is terminated with a null character.  If no characters are read due
136100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   to an end-of-file or len < 1, then the buffer is left untouched.
136200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
136300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzgets returns buf which is a null-terminated string, or it returns NULL
136400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   for end-of-file or in case of error.  If there was an error, the contents at
136500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   buf are indeterminate.
136600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
136700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
136800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
136900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
137000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Writes c, converted to an unsigned char, into the compressed file.  gzputc
137100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   returns the value that was written, or -1 in case of error.
137200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
137300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
137400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzgetc OF((gzFile file));
137500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
137600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Reads one byte from the compressed file.  gzgetc returns this byte or -1
137700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   in case of end of file or error.  This is implemented as a macro for speed.
137800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   As such, it does not do all of the checking the other functions do.  I.e.
137900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   it does not check to see if file is NULL, nor whether the structure file
138000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   points to has been clobbered or not.
138100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
138200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
138300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
138400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
138500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Push one character back onto the stream to be read as the first character
138600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   on the next read.  At least one character of push-back is allowed.
138700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzungetc() returns the character pushed, or -1 on failure.  gzungetc() will
138800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   fail if c is -1, and may fail if a character has been pushed but not read
138900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   yet.  If gzungetc is used immediately after gzopen or gzdopen, at least the
139000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   output buffer size of pushed characters is allowed.  (See gzbuffer above.)
139100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   The pushed character will be discarded if the stream is repositioned with
139200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzseek() or gzrewind().
139300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
139400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
139500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
139600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
139700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Flushes all pending output into the compressed file.  The parameter flush
139800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is as in the deflate() function.  The return value is the zlib error number
139900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   (see function gzerror below).  gzflush is only permitted when writing.
140000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
140100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If the flush parameter is Z_FINISH, the remaining data is written and the
140200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzip stream is completed in the output.  If gzwrite() is called again, a new
140300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzip stream will be started in the output.  gzread() is able to read such
140400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   concatented gzip streams.
140500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
140600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzflush should be called only when strictly necessary because it will
140700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   degrade compression if called too often.
140800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
140900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
141000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
141100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
141200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                   z_off_t offset, int whence));
141300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
141400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Sets the starting position for the next gzread or gzwrite on the given
141500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed file.  The offset represents a number of bytes in the
141600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed data stream.  The whence parameter is defined as in lseek(2);
141700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the value SEEK_END is not supported.
141800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
141900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If the file is opened for reading, this function is emulated but can be
142000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   extremely slow.  If the file is opened for writing, only forward seeks are
142100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   supported; gzseek then compresses a sequence of zeroes up to the new
142200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   starting position.
142300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
142400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzseek returns the resulting offset location as measured in bytes from
142500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   the beginning of the uncompressed stream, or -1 in case of error, in
142600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   particular if the file is opened for writing and the new starting position
142700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   would be before the current position.
142800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
142900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
143000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
143100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
143200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Rewinds the given file. This function is supported only for reading.
143300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
143400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
143500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
143600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
143700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
143800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
143900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
144000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Returns the starting position for the next gzread or gzwrite on the given
144100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed file.  This position represents a number of bytes in the
144200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   uncompressed data stream, and is zero when starting, even if appending or
144300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   reading a gzip stream from the middle of a file using gzdopen().
144400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
144500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
144600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
144700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
144800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
144900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
145000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
145100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Returns the current offset in the file being read or written.  This offset
145200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   includes the count of bytes that precede the gzip stream, for example when
145300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   appending or when using gzdopen() for reading.  When reading, the offset
145400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   does not include as yet unused buffered input.  This information can be used
145500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   for a progress indicator.  On error, gzoffset() returns -1.
145600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
145700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
145800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzeof OF((gzFile file));
145900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
146000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Returns true (1) if the end-of-file indicator has been set while reading,
146100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   false (0) otherwise.  Note that the end-of-file indicator is set only if the
146200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   read tried to go past the end of the input, but came up short.  Therefore,
146300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   just like feof(), gzeof() may return false even if there is no more data to
146400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   read, in the event that the last read request was for the exact number of
146500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   bytes remaining in the input file.  This will happen if the input file size
146600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is an exact multiple of the buffer size.
146700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
146800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If gzeof() returns true, then the read functions will return no more data,
146900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   unless the end-of-file indicator is reset by gzclearerr() and the input file
147000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   has grown since the previous end of file was detected.
147100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
147200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
147300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzdirect OF((gzFile file));
147400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
147500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Returns true (1) if file is being copied directly while reading, or false
147600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   (0) if file is a gzip stream being decompressed.
147700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
147800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If the input file is empty, gzdirect() will return true, since the input
147900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   does not contain a gzip stream.
148000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
148100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     If gzdirect() is used immediately after gzopen() or gzdopen() it will
148200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   cause buffers to be allocated to allow reading the file to determine if it
148300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   is a gzip file.  Therefore if gzbuffer() is used, it should be called before
148400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzdirect().
148500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
148600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     When writing, gzdirect() returns true (1) if transparent writing was
148700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   requested ("wT" for the gzopen() mode), or false (0) otherwise.  (Note:
148800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzdirect() is not needed when writing.  Transparent writing must be
148900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   explicitly requested, so the application already knows the answer.  When
149000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   linking statically, using gzdirect() will include all of the zlib code for
149100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzip file reading and decompression, which may not be desired.)
149200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
149300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
149400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT    gzclose OF((gzFile file));
149500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
149600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Flushes all pending output if necessary, closes the compressed file and
149700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   deallocates the (de)compression state.  Note that once file is closed, you
149800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   cannot call gzerror with file, since its structures have been deallocated.
149900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzclose must not be called more than once on the same file, just as free
150000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   must not be called more than once on the same allocation.
150100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
150200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
150300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
150400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   last read ended in the middle of a gzip stream, or Z_OK on success.
150500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
150600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
150700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
150800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
150900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
151000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Same as gzclose(), but gzclose_r() is only for use when reading, and
151100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   gzclose_w() is only for use when writing or appending.  The advantage to
151200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   using these instead of gzclose() is that they avoid linking in zlib
151300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compression or decompression code that is not used when only reading or only
151400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   writing respectively.  If gzclose() is used, then both compression and
151500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   decompression code will be included the application when linking to a static
151600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   zlib library.
151700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
151800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
151900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
152000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
152100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Returns the error message for the last error which occurred on the given
152200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   compressed file.  errnum is set to zlib error number.  If an error occurred
152300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   in the file system and not in the compression library, errnum is set to
152400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Z_ERRNO and the application may consult errno to get the exact error code.
152500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
152600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     The application must not modify the returned string.  Future calls to
152700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   this function may invalidate the previously returned string.  If file is
152800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   closed, then the string previously returned by gzerror will no longer be
152900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   available.
153000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
153100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     gzerror() should be used to distinguish errors from end-of-file for those
153200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   functions above that do not distinguish those cases in their return values.
153300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
153400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
153500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
153600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
153700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Clears the error and end-of-file flags for file.  This is analogous to the
153800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   clearerr() function in stdio.  This is useful for continuing to read a gzip
153900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   file that is being written concurrently.
154000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
154100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
154200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif /* !Z_SOLO */
154300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
154400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* checksum functions */
154500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
154600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
154700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     These functions are not related to compression but are exported
154800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   anyway because they might be useful in applications using the compression
154900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   library.
155000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
155100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
155200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
155300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
155400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
155500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   return the updated checksum.  If buf is Z_NULL, this function returns the
155600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   required initial value for the checksum.
155700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
155800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
155900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   much faster.
156000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
156100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Usage example:
156200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
156300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     uLong adler = adler32(0L, Z_NULL, 0);
156400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
156500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     while (read_buffer(buffer, length) != EOF) {
156600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes       adler = adler32(adler, buffer, length);
156700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     }
156800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     if (adler != original_adler) error();
156900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
157000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
157100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
157200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
157300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                          z_off_t len2));
157400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
157500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
157600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
157700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
157800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.  Note
157900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   that the z_off_t type (like off_t) is a signed integer.  If len2 is
158000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   negative, the result has no meaning or utility.
158100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
158200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
158300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
158400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
158500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Update a running CRC-32 with the bytes buf[0..len-1] and return the
158600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   updated CRC-32.  If buf is Z_NULL, this function returns the required
158709eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes   initial value for the crc.  Pre- and post-conditioning (one's complement) is
158809eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes   performed within this function so it shouldn't be done by the application.
158900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
159000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   Usage example:
159100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
159200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     uLong crc = crc32(0L, Z_NULL, 0);
159300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
159400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     while (read_buffer(buffer, length) != EOF) {
159500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes       crc = crc32(crc, buffer, length);
159600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     }
159700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     if (crc != original_crc) error();
159800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
159900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
160000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/*
160100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
160200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
160300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     Combine two CRC-32 check values into one.  For two sequences of bytes,
160400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
160500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32
160600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
160700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   len2.
160800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes*/
160900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
161000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
161100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                        /* various hacks, don't look :) */
161200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
161300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* deflateInit and inflateInit are macros to allow checking the zlib version
161400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * and the compiler's view of z_stream:
161500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
161600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
161700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     const char *version, int stream_size));
161800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
161900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                     const char *version, int stream_size));
162000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
162100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      int windowBits, int memLevel,
162200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      int strategy, const char *version,
162300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      int stream_size));
162400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
162500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                      const char *version, int stream_size));
162600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
162700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                         unsigned char FAR *window,
162800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                         const char *version,
162900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                                         int stream_size));
163000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define deflateInit(strm, level) \
163100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes        deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
163200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define inflateInit(strm) \
163300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes        inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
163400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
163500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
163600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                      (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
163700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define inflateInit2(strm, windowBits) \
163800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes        inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
163900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                      (int)sizeof(z_stream))
164000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#define inflateBackInit(strm, windowBits, window) \
164100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes        inflateBackInit_((strm), (windowBits), (window), \
164200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes                      ZLIB_VERSION, (int)sizeof(z_stream))
164300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
164400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#ifndef Z_SOLO
164500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
164600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* gzgetc() macro and its supporting function and exposed data structure.  Note
164700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * that the real internal state is much larger than the exposed structure.
164800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * This abbreviated structure exposes just enough for the gzgetc() macro.  The
164900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * user should not mess with these exposed elements, since their names or
165000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * behavior could change in the future, perhaps even capriciously.  They can
165100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * only be used by the gzgetc() macro.  You have been warned.
165200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
165300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughesstruct gzFile_s {
165400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    unsigned have;
165500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    unsigned char *next;
165600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    z_off64_t pos;
165700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes};
165809eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott HughesZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));  /* backward compatibility */
165909eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#ifdef Z_PREFIX_SET
166009eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#  undef z_gzgetc
166109eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#  define z_gzgetc(g) \
166209eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
166309eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#else
166409eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#  define gzgetc(g) \
166509eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
166609eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#endif
166700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
166800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
166900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
167000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * both are true, the application gets the *64 functions, and the regular
167100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * functions are changed to 64 bits) -- in case these are set on systems
167200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes * without large file support, _LFS64_LARGEFILE must also be true
167300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes */
167409eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#ifdef Z_LARGE64
167500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
167600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
167700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
167800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
167900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
168000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
168100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif
168200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
168309eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
168400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#  ifdef Z_PREFIX_SET
168500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define z_gzopen z_gzopen64
168600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define z_gzseek z_gzseek64
168700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define z_gztell z_gztell64
168800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define z_gzoffset z_gzoffset64
168900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define z_adler32_combine z_adler32_combine64
169000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define z_crc32_combine z_crc32_combine64
169100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#  else
169200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define gzopen gzopen64
169300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define gzseek gzseek64
169400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define gztell gztell64
169500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define gzoffset gzoffset64
169600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define adler32_combine adler32_combine64
169700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#    define crc32_combine crc32_combine64
169800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#  endif
169909eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#  ifndef Z_LARGE64
170000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
170100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
170200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
170300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
170400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
170500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
170600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#  endif
170700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#else
170800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
170900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
171000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
171100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
171200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
171300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
171400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif
171500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
171600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#else /* Z_SOLO */
171700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
171800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
171900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes   ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
172000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
172100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif /* !Z_SOLO */
172200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
172300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* hack for buggy compilers */
172400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
172500fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes    struct internal_state {int dummy;};
172600fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif
172700fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
172800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes/* undocumented functions */
172900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN const char   * ZEXPORT zError           OF((int));
173000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp));
173109eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott HughesZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table    OF((void));
173200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int            ZEXPORT inflateUndermine OF((z_streamp, int));
173300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int            ZEXPORT inflateResetKeep OF((z_streamp));
173400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott HughesZEXTERN int            ZEXPORT deflateResetKeep OF((z_streamp));
173509eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes#if defined(_WIN32) && !defined(Z_SOLO)
173609eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott HughesZEXTERN gzFile         ZEXPORT gzopen_w OF((const wchar_t *path,
173709eb358bbbb9aad3fe48dd3368c8a7a481cbda1cElliott Hughes                                            const char *mode));
173800fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif
173900fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
174000fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#ifdef __cplusplus
174100fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes}
174200fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif
174300fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes
174400fb66d0b1488e4ca655906f82b27eb2ccc3e309Elliott Hughes#endif /* ZLIB_H */
1745