xref: /onnv-gate/usr/src/uts/common/zmod/zlib.h (revision 3886:3291401d66a6)
1*3886Sahl /* zlib.h -- interface of the 'zlib' general purpose compression library
2*3886Sahl   version 1.2.3, July 18th, 2005
3*3886Sahl 
4*3886Sahl   Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
5*3886Sahl 
6*3886Sahl   This software is provided 'as-is', without any express or implied
7*3886Sahl   warranty.  In no event will the authors be held liable for any damages
8*3886Sahl   arising from the use of this software.
9*3886Sahl 
10*3886Sahl   Permission is granted to anyone to use this software for any purpose,
11*3886Sahl   including commercial applications, and to alter it and redistribute it
12*3886Sahl   freely, subject to the following restrictions:
130Sstevel@tonic-gate 
14*3886Sahl   1. The origin of this software must not be misrepresented; you must not
15*3886Sahl      claim that you wrote the original software. If you use this software
16*3886Sahl      in a product, an acknowledgment in the product documentation would be
17*3886Sahl      appreciated but is not required.
18*3886Sahl   2. Altered source versions must be plainly marked as such, and must not be
19*3886Sahl      misrepresented as being the original software.
20*3886Sahl   3. This notice may not be removed or altered from any source distribution.
210Sstevel@tonic-gate 
22*3886Sahl   Jean-loup Gailly        Mark Adler
23*3886Sahl   jloup@gzip.org          madler@alumni.caltech.edu
24*3886Sahl 
25*3886Sahl 
26*3886Sahl   The data format used by the zlib library is described by RFCs (Request for
27*3886Sahl   Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
28*3886Sahl   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29*3886Sahl */
30*3886Sahl 
31*3886Sahl #ifndef _ZLIB_H
32*3886Sahl #define _ZLIB_H
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
350Sstevel@tonic-gate 
36*3886Sahl #include "zconf.h"
37*3886Sahl 
38*3886Sahl #ifdef __cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
42*3886Sahl #define ZLIB_VERSION "1.2.3"
43*3886Sahl #define ZLIB_VERNUM 0x1230
440Sstevel@tonic-gate 
45*3886Sahl /*
460Sstevel@tonic-gate      The 'zlib' compression library provides in-memory compression and
470Sstevel@tonic-gate   decompression functions, including integrity checks of the uncompressed
480Sstevel@tonic-gate   data.  This version of the library supports only one compression method
490Sstevel@tonic-gate   (deflation) but other algorithms will be added later and will have the same
500Sstevel@tonic-gate   stream interface.
510Sstevel@tonic-gate 
520Sstevel@tonic-gate      Compression can be done in a single step if the buffers are large
530Sstevel@tonic-gate   enough (for example if an input file is mmap'ed), or can be done by
540Sstevel@tonic-gate   repeated calls of the compression function.  In the latter case, the
550Sstevel@tonic-gate   application must provide more input and/or consume the output
560Sstevel@tonic-gate   (providing more output space) before each call.
570Sstevel@tonic-gate 
58*3886Sahl      The compressed data format used by default by the in-memory functions is
59*3886Sahl   the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
60*3886Sahl   around a deflate stream, which is itself documented in RFC 1951.
61*3886Sahl 
620Sstevel@tonic-gate      The library also supports reading and writing files in gzip (.gz) format
63*3886Sahl   with an interface similar to that of stdio using the functions that start
64*3886Sahl   with "gz".  The gzip format is different from the zlib format.  gzip is a
65*3886Sahl   gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
66*3886Sahl 
67*3886Sahl      This library can optionally read and write gzip streams in memory as well.
68*3886Sahl 
69*3886Sahl      The zlib format was designed to be compact and fast for use in memory
70*3886Sahl   and on communications channels.  The gzip format was designed for single-
71*3886Sahl   file compression on file systems, has a larger header than zlib to maintain
72*3886Sahl   directory information, and uses a different, slower check method than zlib.
730Sstevel@tonic-gate 
740Sstevel@tonic-gate      The library does not install any signal handler. The decoder checks
750Sstevel@tonic-gate   the consistency of the compressed data, so the library should never
760Sstevel@tonic-gate   crash even in case of corrupted input.
770Sstevel@tonic-gate */
780Sstevel@tonic-gate 
790Sstevel@tonic-gate typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
800Sstevel@tonic-gate typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
810Sstevel@tonic-gate 
820Sstevel@tonic-gate struct internal_state;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate typedef struct z_stream_s {
850Sstevel@tonic-gate     Bytef    *next_in;  /* next input byte */
860Sstevel@tonic-gate     uInt     avail_in;  /* number of bytes available at next_in */
870Sstevel@tonic-gate     uLong    total_in;  /* total nb of input bytes read so far */
880Sstevel@tonic-gate 
890Sstevel@tonic-gate     Bytef    *next_out; /* next output byte should be put there */
900Sstevel@tonic-gate     uInt     avail_out; /* remaining free space at next_out */
910Sstevel@tonic-gate     uLong    total_out; /* total nb of bytes output so far */
920Sstevel@tonic-gate 
930Sstevel@tonic-gate     char     *msg;      /* last error message, NULL if no error */
940Sstevel@tonic-gate     struct internal_state FAR *state; /* not visible by applications */
950Sstevel@tonic-gate 
960Sstevel@tonic-gate     alloc_func zalloc;  /* used to allocate the internal state */
970Sstevel@tonic-gate     free_func  zfree;   /* used to free the internal state */
980Sstevel@tonic-gate     voidpf     opaque;  /* private data object passed to zalloc and zfree */
990Sstevel@tonic-gate 
100*3886Sahl     int     data_type;  /* best guess about the data type: binary or text */
1010Sstevel@tonic-gate     uLong   adler;      /* adler32 value of the uncompressed data */
1020Sstevel@tonic-gate     uLong   reserved;   /* reserved for future use */
1030Sstevel@tonic-gate } z_stream;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate typedef z_stream FAR *z_streamp;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate /*
108*3886Sahl      gzip header information passed to and from zlib routines.  See RFC 1952
109*3886Sahl   for more details on the meanings of these fields.
110*3886Sahl */
111*3886Sahl typedef struct gz_header_s {
112*3886Sahl     int     text;       /* true if compressed data believed to be text */
113*3886Sahl     uLong   time;       /* modification time */
114*3886Sahl     int     xflags;     /* extra flags (not used when writing a gzip file) */
115*3886Sahl     int     os;         /* operating system */
116*3886Sahl     Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
117*3886Sahl     uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
118*3886Sahl     uInt    extra_max;  /* space at extra (only when reading header) */
119*3886Sahl     Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
120*3886Sahl     uInt    name_max;   /* space at name (only when reading header) */
121*3886Sahl     Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
122*3886Sahl     uInt    comm_max;   /* space at comment (only when reading header) */
123*3886Sahl     int     hcrc;       /* true if there was or will be a header crc */
124*3886Sahl     int     done;       /* true when done reading gzip header (not used
125*3886Sahl                            when writing a gzip file) */
126*3886Sahl } gz_header;
127*3886Sahl 
128*3886Sahl typedef gz_header FAR *gz_headerp;
129*3886Sahl 
130*3886Sahl /*
1310Sstevel@tonic-gate    The application must update next_in and avail_in when avail_in has
1320Sstevel@tonic-gate    dropped to zero. It must update next_out and avail_out when avail_out
1330Sstevel@tonic-gate    has dropped to zero. The application must initialize zalloc, zfree and
1340Sstevel@tonic-gate    opaque before calling the init function. All other fields are set by the
1350Sstevel@tonic-gate    compression library and must not be updated by the application.
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate    The opaque value provided by the application will be passed as the first
1380Sstevel@tonic-gate    parameter for calls of zalloc and zfree. This can be useful for custom
1390Sstevel@tonic-gate    memory management. The compression library attaches no meaning to the
1400Sstevel@tonic-gate    opaque value.
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate    zalloc must return Z_NULL if there is not enough memory for the object.
1430Sstevel@tonic-gate    If zlib is used in a multi-threaded application, zalloc and zfree must be
1440Sstevel@tonic-gate    thread safe.
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate    On 16-bit systems, the functions zalloc and zfree must be able to allocate
1470Sstevel@tonic-gate    exactly 65536 bytes, but will not be required to allocate more than this
1480Sstevel@tonic-gate    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
1490Sstevel@tonic-gate    pointers returned by zalloc for objects of exactly 65536 bytes *must*
1500Sstevel@tonic-gate    have their offset normalized to zero. The default allocation function
1510Sstevel@tonic-gate    provided by this library ensures this (see zutil.c). To reduce memory
1520Sstevel@tonic-gate    requirements and avoid any allocation of 64K objects, at the expense of
1530Sstevel@tonic-gate    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate    The fields total_in and total_out can be used for statistics or
1560Sstevel@tonic-gate    progress reports. After compression, total_in holds the total size of
1570Sstevel@tonic-gate    the uncompressed data and may be saved for use in the decompressor
1580Sstevel@tonic-gate    (particularly if the decompressor wants to decompress everything in
1590Sstevel@tonic-gate    a single step).
1600Sstevel@tonic-gate */
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate                         /* constants */
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate #define Z_NO_FLUSH      0
1650Sstevel@tonic-gate #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
1660Sstevel@tonic-gate #define Z_SYNC_FLUSH    2
1670Sstevel@tonic-gate #define Z_FULL_FLUSH    3
1680Sstevel@tonic-gate #define Z_FINISH        4
169*3886Sahl #define Z_BLOCK         5
170*3886Sahl /* Allowed flush values; see deflate() and inflate() below for details */
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate #define Z_OK            0
1730Sstevel@tonic-gate #define Z_STREAM_END    1
1740Sstevel@tonic-gate #define Z_NEED_DICT     2
1750Sstevel@tonic-gate #define Z_ERRNO        (-1)
1760Sstevel@tonic-gate #define Z_STREAM_ERROR (-2)
1770Sstevel@tonic-gate #define Z_DATA_ERROR   (-3)
1780Sstevel@tonic-gate #define Z_MEM_ERROR    (-4)
1790Sstevel@tonic-gate #define Z_BUF_ERROR    (-5)
1800Sstevel@tonic-gate #define Z_VERSION_ERROR (-6)
1810Sstevel@tonic-gate /* Return codes for the compression/decompression functions. Negative
1820Sstevel@tonic-gate  * values are errors, positive values are used for special but normal events.
1830Sstevel@tonic-gate  */
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate #define Z_NO_COMPRESSION         0
1860Sstevel@tonic-gate #define Z_BEST_SPEED             1
1870Sstevel@tonic-gate #define Z_BEST_COMPRESSION       9
1880Sstevel@tonic-gate #define Z_DEFAULT_COMPRESSION  (-1)
1890Sstevel@tonic-gate /* compression levels */
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate #define Z_FILTERED            1
1920Sstevel@tonic-gate #define Z_HUFFMAN_ONLY        2
193*3886Sahl #define Z_RLE                 3
194*3886Sahl #define Z_FIXED               4
1950Sstevel@tonic-gate #define Z_DEFAULT_STRATEGY    0
1960Sstevel@tonic-gate /* compression strategy; see deflateInit2() below for details */
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate #define Z_BINARY   0
199*3886Sahl #define Z_TEXT     1
200*3886Sahl #define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
2010Sstevel@tonic-gate #define Z_UNKNOWN  2
202*3886Sahl /* Possible values of the data_type field (though see inflate()) */
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate #define Z_DEFLATED   8
2050Sstevel@tonic-gate /* The deflate compression method (the only one supported in this version) */
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate #define zlib_version zlibVersion()
2100Sstevel@tonic-gate /* for compatibility with versions < 1.0.2 */
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate                         /* basic functions */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate ZEXTERN const char * ZEXPORT zlibVersion OF((void));
2150Sstevel@tonic-gate /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
2160Sstevel@tonic-gate    If the first character differs, the library code actually used is
2170Sstevel@tonic-gate    not compatible with the zlib.h header file used by the application.
2180Sstevel@tonic-gate    This check is automatically made by deflateInit and inflateInit.
2190Sstevel@tonic-gate  */
2200Sstevel@tonic-gate 
221*3886Sahl /*
2220Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate      Initializes the internal stream state for compression. The fields
2250Sstevel@tonic-gate    zalloc, zfree and opaque must be initialized before by the caller.
2260Sstevel@tonic-gate    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
2270Sstevel@tonic-gate    use default allocation functions.
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
2300Sstevel@tonic-gate    1 gives best speed, 9 gives best compression, 0 gives no compression at
2310Sstevel@tonic-gate    all (the input data is simply copied a block at a time).
2320Sstevel@tonic-gate    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
2330Sstevel@tonic-gate    compression (currently equivalent to level 6).
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
2360Sstevel@tonic-gate    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
2370Sstevel@tonic-gate    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
2380Sstevel@tonic-gate    with the version assumed by the caller (ZLIB_VERSION).
2390Sstevel@tonic-gate    msg is set to null if there is no error message.  deflateInit does not
2400Sstevel@tonic-gate    perform any compression: this will be done by deflate().
2410Sstevel@tonic-gate */
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
2450Sstevel@tonic-gate /*
2460Sstevel@tonic-gate     deflate compresses as much data as possible, and stops when the input
2470Sstevel@tonic-gate   buffer becomes empty or the output buffer becomes full. It may introduce some
2480Sstevel@tonic-gate   output latency (reading input without producing any output) except when
2490Sstevel@tonic-gate   forced to flush.
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate     The detailed semantics are as follows. deflate performs one or both of the
2520Sstevel@tonic-gate   following actions:
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate   - Compress more input starting at next_in and update next_in and avail_in
2550Sstevel@tonic-gate     accordingly. If not all input can be processed (because there is not
2560Sstevel@tonic-gate     enough room in the output buffer), next_in and avail_in are updated and
2570Sstevel@tonic-gate     processing will resume at this point for the next call of deflate().
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate   - Provide more output starting at next_out and update next_out and avail_out
2600Sstevel@tonic-gate     accordingly. This action is forced if the parameter flush is non zero.
2610Sstevel@tonic-gate     Forcing flush frequently degrades the compression ratio, so this parameter
2620Sstevel@tonic-gate     should be set only when necessary (in interactive applications).
2630Sstevel@tonic-gate     Some output may be provided even if flush is not set.
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate   Before the call of deflate(), the application should ensure that at least
2660Sstevel@tonic-gate   one of the actions is possible, by providing more input and/or consuming
2670Sstevel@tonic-gate   more output, and updating avail_in or avail_out accordingly; avail_out
2680Sstevel@tonic-gate   should never be zero before the call. The application can consume the
2690Sstevel@tonic-gate   compressed output when it wants, for example when the output buffer is full
2700Sstevel@tonic-gate   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
2710Sstevel@tonic-gate   and with zero avail_out, it must be called again after making room in the
2720Sstevel@tonic-gate   output buffer because there might be more output pending.
2730Sstevel@tonic-gate 
274*3886Sahl     Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
275*3886Sahl   decide how much data to accumualte before producing output, in order to
276*3886Sahl   maximize compression.
277*3886Sahl 
2780Sstevel@tonic-gate     If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
2790Sstevel@tonic-gate   flushed to the output buffer and the output is aligned on a byte boundary, so
2800Sstevel@tonic-gate   that the decompressor can get all input data available so far. (In particular
2810Sstevel@tonic-gate   avail_in is zero after the call if enough output space has been provided
2820Sstevel@tonic-gate   before the call.)  Flushing may degrade compression for some compression
2830Sstevel@tonic-gate   algorithms and so it should be used only when necessary.
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate     If flush is set to Z_FULL_FLUSH, all output is flushed as with
2860Sstevel@tonic-gate   Z_SYNC_FLUSH, and the compression state is reset so that decompression can
2870Sstevel@tonic-gate   restart from this point if previous compressed data has been damaged or if
2880Sstevel@tonic-gate   random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
289*3886Sahl   compression.
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate     If deflate returns with avail_out == 0, this function must be called again
2920Sstevel@tonic-gate   with the same value of the flush parameter and more output space (updated
2930Sstevel@tonic-gate   avail_out), until the flush is complete (deflate returns with non-zero
294*3886Sahl   avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
295*3886Sahl   avail_out is greater than six to avoid repeated flush markers due to
296*3886Sahl   avail_out == 0 on return.
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate     If the parameter flush is set to Z_FINISH, pending input is processed,
2990Sstevel@tonic-gate   pending output is flushed and deflate returns with Z_STREAM_END if there
3000Sstevel@tonic-gate   was enough output space; if deflate returns with Z_OK, this function must be
3010Sstevel@tonic-gate   called again with Z_FINISH and more output space (updated avail_out) but no
3020Sstevel@tonic-gate   more input data, until it returns with Z_STREAM_END or an error. After
3030Sstevel@tonic-gate   deflate has returned Z_STREAM_END, the only possible operations on the
3040Sstevel@tonic-gate   stream are deflateReset or deflateEnd.
305*3886Sahl 
3060Sstevel@tonic-gate     Z_FINISH can be used immediately after deflateInit if all the compression
3070Sstevel@tonic-gate   is to be done in a single step. In this case, avail_out must be at least
308*3886Sahl   the value returned by deflateBound (see below). If deflate does not return
3090Sstevel@tonic-gate   Z_STREAM_END, then it must be called again as described above.
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate     deflate() sets strm->adler to the adler32 checksum of all input read
3120Sstevel@tonic-gate   so far (that is, total_in bytes).
3130Sstevel@tonic-gate 
314*3886Sahl     deflate() may update strm->data_type if it can make a good guess about
315*3886Sahl   the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
3160Sstevel@tonic-gate   binary. This field is only for information purposes and does not affect
3170Sstevel@tonic-gate   the compression algorithm in any manner.
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate     deflate() returns Z_OK if some progress has been made (more input
3200Sstevel@tonic-gate   processed or more output produced), Z_STREAM_END if all input has been
3210Sstevel@tonic-gate   consumed and all output has been produced (only when flush is set to
3220Sstevel@tonic-gate   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
3230Sstevel@tonic-gate   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
324*3886Sahl   (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
325*3886Sahl   fatal, and deflate() can be called again with more input and more output
326*3886Sahl   space to continue compressing.
3270Sstevel@tonic-gate */
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
3310Sstevel@tonic-gate /*
3320Sstevel@tonic-gate      All dynamically allocated data structures for this stream are freed.
3330Sstevel@tonic-gate    This function discards any unprocessed input and does not flush any
3340Sstevel@tonic-gate    pending output.
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
3370Sstevel@tonic-gate    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
3380Sstevel@tonic-gate    prematurely (some input or output was discarded). In the error case,
3390Sstevel@tonic-gate    msg may be set but then points to a static string (which must not be
3400Sstevel@tonic-gate    deallocated).
3410Sstevel@tonic-gate */
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 
344*3886Sahl /*
3450Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate      Initializes the internal stream state for decompression. The fields
3480Sstevel@tonic-gate    next_in, avail_in, zalloc, zfree and opaque must be initialized before by
3490Sstevel@tonic-gate    the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
3500Sstevel@tonic-gate    value depends on the compression method), inflateInit determines the
3510Sstevel@tonic-gate    compression method from the zlib header and allocates all data structures
3520Sstevel@tonic-gate    accordingly; otherwise the allocation will be deferred to the first call of
3530Sstevel@tonic-gate    inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
3540Sstevel@tonic-gate    use default allocation functions.
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
3570Sstevel@tonic-gate    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
3580Sstevel@tonic-gate    version assumed by the caller.  msg is set to null if there is no error
3590Sstevel@tonic-gate    message. inflateInit does not perform any decompression apart from reading
3600Sstevel@tonic-gate    the zlib header if present: this will be done by inflate().  (So next_in and
3610Sstevel@tonic-gate    avail_in may be modified, but next_out and avail_out are unchanged.)
3620Sstevel@tonic-gate */
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
3660Sstevel@tonic-gate /*
3670Sstevel@tonic-gate     inflate decompresses as much data as possible, and stops when the input
368*3886Sahl   buffer becomes empty or the output buffer becomes full. It may introduce
369*3886Sahl   some output latency (reading input without producing any output) except when
370*3886Sahl   forced to flush.
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate   The detailed semantics are as follows. inflate performs one or both of the
3730Sstevel@tonic-gate   following actions:
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate   - Decompress more input starting at next_in and update next_in and avail_in
3760Sstevel@tonic-gate     accordingly. If not all input can be processed (because there is not
3770Sstevel@tonic-gate     enough room in the output buffer), next_in is updated and processing
3780Sstevel@tonic-gate     will resume at this point for the next call of inflate().
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate   - Provide more output starting at next_out and update next_out and avail_out
3810Sstevel@tonic-gate     accordingly.  inflate() provides as much output as possible, until there
3820Sstevel@tonic-gate     is no more input data or no more space in the output buffer (see below
3830Sstevel@tonic-gate     about the flush parameter).
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate   Before the call of inflate(), the application should ensure that at least
3860Sstevel@tonic-gate   one of the actions is possible, by providing more input and/or consuming
3870Sstevel@tonic-gate   more output, and updating the next_* and avail_* values accordingly.
3880Sstevel@tonic-gate   The application can consume the uncompressed output when it wants, for
3890Sstevel@tonic-gate   example when the output buffer is full (avail_out == 0), or after each
3900Sstevel@tonic-gate   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
3910Sstevel@tonic-gate   must be called again after making room in the output buffer because there
3920Sstevel@tonic-gate   might be more output pending.
3930Sstevel@tonic-gate 
394*3886Sahl     The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
395*3886Sahl   Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
396*3886Sahl   output as possible to the output buffer. Z_BLOCK requests that inflate() stop
397*3886Sahl   if and when it gets to the next deflate block boundary. When decoding the
398*3886Sahl   zlib or gzip format, this will cause inflate() to return immediately after
399*3886Sahl   the header and before the first block. When doing a raw inflate, inflate()
400*3886Sahl   will go ahead and process the first block, and will return when it gets to
401*3886Sahl   the end of that block, or when it runs out of data.
402*3886Sahl 
403*3886Sahl     The Z_BLOCK option assists in appending to or combining deflate streams.
404*3886Sahl   Also to assist in this, on return inflate() will set strm->data_type to the
405*3886Sahl   number of unused bits in the last byte taken from strm->next_in, plus 64
406*3886Sahl   if inflate() is currently decoding the last block in the deflate stream,
407*3886Sahl   plus 128 if inflate() returned immediately after decoding an end-of-block
408*3886Sahl   code or decoding the complete header up to just before the first byte of the
409*3886Sahl   deflate stream. The end-of-block will not be indicated until all of the
410*3886Sahl   uncompressed data from that block has been written to strm->next_out.  The
411*3886Sahl   number of unused bits may in general be greater than seven, except when
412*3886Sahl   bit 7 of data_type is set, in which case the number of unused bits will be
413*3886Sahl   less than eight.
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate     inflate() should normally be called until it returns Z_STREAM_END or an
4160Sstevel@tonic-gate   error. However if all decompression is to be performed in a single step
4170Sstevel@tonic-gate   (a single call of inflate), the parameter flush should be set to
4180Sstevel@tonic-gate   Z_FINISH. In this case all pending input is processed and all pending
4190Sstevel@tonic-gate   output is flushed; avail_out must be large enough to hold all the
4200Sstevel@tonic-gate   uncompressed data. (The size of the uncompressed data may have been saved
4210Sstevel@tonic-gate   by the compressor for this purpose.) The next operation on this stream must
4220Sstevel@tonic-gate   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
423*3886Sahl   is never required, but can be used to inform inflate that a faster approach
4240Sstevel@tonic-gate   may be used for the single inflate() call.
4250Sstevel@tonic-gate 
426*3886Sahl      In this implementation, inflate() always flushes as much output as
427*3886Sahl   possible to the output buffer, and always uses the faster approach on the
428*3886Sahl   first call. So the only effect of the flush parameter in this implementation
429*3886Sahl   is on the return value of inflate(), as noted below, or when it returns early
430*3886Sahl   because Z_BLOCK is used.
431*3886Sahl 
432*3886Sahl      If a preset dictionary is needed after this call (see inflateSetDictionary
433*3886Sahl   below), inflate sets strm->adler to the adler32 checksum of the dictionary
434*3886Sahl   chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
435*3886Sahl   strm->adler to the adler32 checksum of all output produced so far (that is,
436*3886Sahl   total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
437*3886Sahl   below. At the end of the stream, inflate() checks that its computed adler32
438*3886Sahl   checksum is equal to that saved by the compressor and returns Z_STREAM_END
439*3886Sahl   only if the checksum is correct.
440*3886Sahl 
441*3886Sahl     inflate() will decompress and check either zlib-wrapped or gzip-wrapped
442*3886Sahl   deflate data.  The header type is detected automatically.  Any information
443*3886Sahl   contained in the gzip header is not retained, so applications that need that
444*3886Sahl   information should instead use raw inflate, see inflateInit2() below, or
445*3886Sahl   inflateBack() and perform their own processing of the gzip header and
446*3886Sahl   trailer.
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate     inflate() returns Z_OK if some progress has been made (more input processed
4490Sstevel@tonic-gate   or more output produced), Z_STREAM_END if the end of the compressed data has
4500Sstevel@tonic-gate   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
4510Sstevel@tonic-gate   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
452*3886Sahl   corrupted (input stream not conforming to the zlib format or incorrect check
453*3886Sahl   value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
454*3886Sahl   if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
455*3886Sahl   Z_BUF_ERROR if no progress is possible or if there was not enough room in the
456*3886Sahl   output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
457*3886Sahl   inflate() can be called again with more input and more output space to
458*3886Sahl   continue decompressing. If Z_DATA_ERROR is returned, the application may then
459*3886Sahl   call inflateSync() to look for a good compression block if a partial recovery
460*3886Sahl   of the data is desired.
4610Sstevel@tonic-gate */
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
4650Sstevel@tonic-gate /*
4660Sstevel@tonic-gate      All dynamically allocated data structures for this stream are freed.
4670Sstevel@tonic-gate    This function discards any unprocessed input and does not flush any
4680Sstevel@tonic-gate    pending output.
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
4710Sstevel@tonic-gate    was inconsistent. In the error case, msg may be set but then points to a
4720Sstevel@tonic-gate    static string (which must not be deallocated).
4730Sstevel@tonic-gate */
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate                         /* Advanced functions */
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate /*
4780Sstevel@tonic-gate     The following functions are needed only in some special applications.
4790Sstevel@tonic-gate */
4800Sstevel@tonic-gate 
481*3886Sahl /*
4820Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
4830Sstevel@tonic-gate                                      int  level,
4840Sstevel@tonic-gate                                      int  method,
4850Sstevel@tonic-gate                                      int  windowBits,
4860Sstevel@tonic-gate                                      int  memLevel,
4870Sstevel@tonic-gate                                      int  strategy));
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate      This is another version of deflateInit with more compression options. The
4900Sstevel@tonic-gate    fields next_in, zalloc, zfree and opaque must be initialized before by
4910Sstevel@tonic-gate    the caller.
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate      The method parameter is the compression method. It must be Z_DEFLATED in
4940Sstevel@tonic-gate    this version of the library.
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate      The windowBits parameter is the base two logarithm of the window size
497*3886Sahl    (the size of the history buffer). It should be in the range 8..15 for this
4980Sstevel@tonic-gate    version of the library. Larger values of this parameter result in better
4990Sstevel@tonic-gate    compression at the expense of memory usage. The default value is 15 if
5000Sstevel@tonic-gate    deflateInit is used instead.
5010Sstevel@tonic-gate 
502*3886Sahl      windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
503*3886Sahl    determines the window size. deflate() will then generate raw deflate data
504*3886Sahl    with no zlib header or trailer, and will not compute an adler32 check value.
505*3886Sahl 
506*3886Sahl      windowBits can also be greater than 15 for optional gzip encoding. Add
507*3886Sahl    16 to windowBits to write a simple gzip header and trailer around the
508*3886Sahl    compressed data instead of a zlib wrapper. The gzip header will have no
509*3886Sahl    file name, no extra data, no comment, no modification time (set to zero),
510*3886Sahl    no header crc, and the operating system will be set to 255 (unknown).  If a
511*3886Sahl    gzip stream is being written, strm->adler is a crc32 instead of an adler32.
512*3886Sahl 
5130Sstevel@tonic-gate      The memLevel parameter specifies how much memory should be allocated
5140Sstevel@tonic-gate    for the internal compression state. memLevel=1 uses minimum memory but
5150Sstevel@tonic-gate    is slow and reduces compression ratio; memLevel=9 uses maximum memory
5160Sstevel@tonic-gate    for optimal speed. The default value is 8. See zconf.h for total memory
5170Sstevel@tonic-gate    usage as a function of windowBits and memLevel.
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate      The strategy parameter is used to tune the compression algorithm. Use the
5200Sstevel@tonic-gate    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
521*3886Sahl    filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
522*3886Sahl    string match), or Z_RLE to limit match distances to one (run-length
523*3886Sahl    encoding). Filtered data consists mostly of small values with a somewhat
524*3886Sahl    random distribution. In this case, the compression algorithm is tuned to
525*3886Sahl    compress them better. The effect of Z_FILTERED is to force more Huffman
526*3886Sahl    coding and less string matching; it is somewhat intermediate between
527*3886Sahl    Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
528*3886Sahl    Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
529*3886Sahl    parameter only affects the compression ratio but not the correctness of the
530*3886Sahl    compressed output even if it is not set appropriately.  Z_FIXED prevents the
531*3886Sahl    use of dynamic Huffman codes, allowing for a simpler decoder for special
532*3886Sahl    applications.
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
5350Sstevel@tonic-gate    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
5360Sstevel@tonic-gate    method). msg is set to null if there is no error message.  deflateInit2 does
5370Sstevel@tonic-gate    not perform any compression: this will be done by deflate().
5380Sstevel@tonic-gate */
539*3886Sahl 
5400Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
5410Sstevel@tonic-gate                                              const Bytef *dictionary,
5420Sstevel@tonic-gate                                              uInt  dictLength));
5430Sstevel@tonic-gate /*
5440Sstevel@tonic-gate      Initializes the compression dictionary from the given byte sequence
5450Sstevel@tonic-gate    without producing any compressed output. This function must be called
5460Sstevel@tonic-gate    immediately after deflateInit, deflateInit2 or deflateReset, before any
5470Sstevel@tonic-gate    call of deflate. The compressor and decompressor must use exactly the same
5480Sstevel@tonic-gate    dictionary (see inflateSetDictionary).
5490Sstevel@tonic-gate 
5500Sstevel@tonic-gate      The dictionary should consist of strings (byte sequences) that are likely
5510Sstevel@tonic-gate    to be encountered later in the data to be compressed, with the most commonly
5520Sstevel@tonic-gate    used strings preferably put towards the end of the dictionary. Using a
5530Sstevel@tonic-gate    dictionary is most useful when the data to be compressed is short and can be
5540Sstevel@tonic-gate    predicted with good accuracy; the data can then be compressed better than
5550Sstevel@tonic-gate    with the default empty dictionary.
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate      Depending on the size of the compression data structures selected by
5580Sstevel@tonic-gate    deflateInit or deflateInit2, a part of the dictionary may in effect be
5590Sstevel@tonic-gate    discarded, for example if the dictionary is larger than the window size in
5600Sstevel@tonic-gate    deflate or deflate2. Thus the strings most likely to be useful should be
561*3886Sahl    put at the end of the dictionary, not at the front. In addition, the
562*3886Sahl    current implementation of deflate will use at most the window size minus
563*3886Sahl    262 bytes of the provided dictionary.
5640Sstevel@tonic-gate 
565*3886Sahl      Upon return of this function, strm->adler is set to the adler32 value
5660Sstevel@tonic-gate    of the dictionary; the decompressor may later use this value to determine
567*3886Sahl    which dictionary has been used by the compressor. (The adler32 value
5680Sstevel@tonic-gate    applies to the whole dictionary even if only a subset of the dictionary is
569*3886Sahl    actually used by the compressor.) If a raw deflate was requested, then the
570*3886Sahl    adler32 value is not computed and strm->adler is not set.
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
5730Sstevel@tonic-gate    parameter is invalid (such as NULL dictionary) or the stream state is
5740Sstevel@tonic-gate    inconsistent (for example if deflate has already been called for this stream
5750Sstevel@tonic-gate    or if the compression method is bsort). deflateSetDictionary does not
5760Sstevel@tonic-gate    perform any compression: this will be done by deflate().
5770Sstevel@tonic-gate */
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
5800Sstevel@tonic-gate                                     z_streamp source));
5810Sstevel@tonic-gate /*
5820Sstevel@tonic-gate      Sets the destination stream as a complete copy of the source stream.
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate      This function can be useful when several compression strategies will be
5850Sstevel@tonic-gate    tried, for example when there are several ways of pre-processing the input
5860Sstevel@tonic-gate    data with a filter. The streams that will be discarded should then be freed
5870Sstevel@tonic-gate    by calling deflateEnd.  Note that deflateCopy duplicates the internal
5880Sstevel@tonic-gate    compression state which can be quite large, so this strategy is slow and
5890Sstevel@tonic-gate    can consume lots of memory.
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
5920Sstevel@tonic-gate    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
5930Sstevel@tonic-gate    (such as zalloc being NULL). msg is left unchanged in both source and
5940Sstevel@tonic-gate    destination.
5950Sstevel@tonic-gate */
5960Sstevel@tonic-gate 
5970Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
5980Sstevel@tonic-gate /*
5990Sstevel@tonic-gate      This function is equivalent to deflateEnd followed by deflateInit,
6000Sstevel@tonic-gate    but does not free and reallocate all the internal compression state.
6010Sstevel@tonic-gate    The stream will keep the same compression level and any other attributes
6020Sstevel@tonic-gate    that may have been set by deflateInit2.
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
6050Sstevel@tonic-gate    stream state was inconsistent (such as zalloc or state being NULL).
6060Sstevel@tonic-gate */
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
609*3886Sahl                                       int level,
610*3886Sahl                                       int strategy));
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate      Dynamically update the compression level and compression strategy.  The
6130Sstevel@tonic-gate    interpretation of level and strategy is as in deflateInit2.  This can be
6140Sstevel@tonic-gate    used to switch between compression and straight copy of the input data, or
6150Sstevel@tonic-gate    to switch to a different kind of input data requiring a different
6160Sstevel@tonic-gate    strategy. If the compression level is changed, the input available so far
6170Sstevel@tonic-gate    is compressed with the old level (and may be flushed); the new level will
6180Sstevel@tonic-gate    take effect only at the next call of deflate().
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate      Before the call of deflateParams, the stream state must be set as for
6210Sstevel@tonic-gate    a call of deflate(), since the currently available input may have to
6220Sstevel@tonic-gate    be compressed and flushed. In particular, strm->avail_out must be non-zero.
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
6250Sstevel@tonic-gate    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
6260Sstevel@tonic-gate    if strm->avail_out was zero.
6270Sstevel@tonic-gate */
6280Sstevel@tonic-gate 
629*3886Sahl ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
630*3886Sahl                                     int good_length,
631*3886Sahl                                     int max_lazy,
632*3886Sahl                                     int nice_length,
633*3886Sahl                                     int max_chain));
634*3886Sahl /*
635*3886Sahl      Fine tune deflate's internal compression parameters.  This should only be
636*3886Sahl    used by someone who understands the algorithm used by zlib's deflate for
637*3886Sahl    searching for the best matching string, and even then only by the most
638*3886Sahl    fanatic optimizer trying to squeeze out the last compressed bit for their
639*3886Sahl    specific input data.  Read the deflate.c source code for the meaning of the
640*3886Sahl    max_lazy, good_length, nice_length, and max_chain parameters.
641*3886Sahl 
642*3886Sahl      deflateTune() can be called after deflateInit() or deflateInit2(), and
643*3886Sahl    returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
644*3886Sahl  */
645*3886Sahl 
646*3886Sahl ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
647*3886Sahl                                        uLong sourceLen));
648*3886Sahl /*
649*3886Sahl      deflateBound() returns an upper bound on the compressed size after
650*3886Sahl    deflation of sourceLen bytes.  It must be called after deflateInit()
651*3886Sahl    or deflateInit2().  This would be used to allocate an output buffer
652*3886Sahl    for deflation in a single pass, and so would be called before deflate().
653*3886Sahl */
654*3886Sahl 
655*3886Sahl ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
656*3886Sahl                                      int bits,
657*3886Sahl                                      int value));
658*3886Sahl /*
659*3886Sahl      deflatePrime() inserts bits in the deflate output stream.  The intent
660*3886Sahl   is that this function is used to start off the deflate output with the
661*3886Sahl   bits leftover from a previous deflate stream when appending to it.  As such,
662*3886Sahl   this function can only be used for raw deflate, and must be used before the
663*3886Sahl   first deflate() call after a deflateInit2() or deflateReset().  bits must be
664*3886Sahl   less than or equal to 16, and that many of the least significant bits of
665*3886Sahl   value will be inserted in the output.
666*3886Sahl 
667*3886Sahl       deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
668*3886Sahl    stream state was inconsistent.
669*3886Sahl */
670*3886Sahl 
671*3886Sahl ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
672*3886Sahl                                          gz_headerp head));
673*3886Sahl /*
674*3886Sahl       deflateSetHeader() provides gzip header information for when a gzip
675*3886Sahl    stream is requested by deflateInit2().  deflateSetHeader() may be called
676*3886Sahl    after deflateInit2() or deflateReset() and before the first call of
677*3886Sahl    deflate().  The text, time, os, extra field, name, and comment information
678*3886Sahl    in the provided gz_header structure are written to the gzip header (xflag is
679*3886Sahl    ignored -- the extra flags are set according to the compression level).  The
680*3886Sahl    caller must assure that, if not Z_NULL, name and comment are terminated with
681*3886Sahl    a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
682*3886Sahl    available there.  If hcrc is true, a gzip header crc is included.  Note that
683*3886Sahl    the current versions of the command-line version of gzip (up through version
684*3886Sahl    1.3.x) do not support header crc's, and will report that it is a "multi-part
685*3886Sahl    gzip file" and give up.
686*3886Sahl 
687*3886Sahl       If deflateSetHeader is not used, the default gzip header has text false,
688*3886Sahl    the time set to zero, and os set to 255, with no extra, name, or comment
689*3886Sahl    fields.  The gzip header is returned to the default state by deflateReset().
690*3886Sahl 
691*3886Sahl       deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
692*3886Sahl    stream state was inconsistent.
693*3886Sahl */
694*3886Sahl 
695*3886Sahl /*
6960Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
6970Sstevel@tonic-gate                                      int  windowBits));
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate      This is another version of inflateInit with an extra parameter. The
7000Sstevel@tonic-gate    fields next_in, avail_in, zalloc, zfree and opaque must be initialized
7010Sstevel@tonic-gate    before by the caller.
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate      The windowBits parameter is the base two logarithm of the maximum window
7040Sstevel@tonic-gate    size (the size of the history buffer).  It should be in the range 8..15 for
7050Sstevel@tonic-gate    this version of the library. The default value is 15 if inflateInit is used
706*3886Sahl    instead. windowBits must be greater than or equal to the windowBits value
707*3886Sahl    provided to deflateInit2() while compressing, or it must be equal to 15 if
708*3886Sahl    deflateInit2() was not used. If a compressed stream with a larger window
709*3886Sahl    size is given as input, inflate() will return with the error code
710*3886Sahl    Z_DATA_ERROR instead of trying to allocate a larger window.
7110Sstevel@tonic-gate 
712*3886Sahl      windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
713*3886Sahl    determines the window size. inflate() will then process raw deflate data,
714*3886Sahl    not looking for a zlib or gzip header, not generating a check value, and not
715*3886Sahl    looking for any check values for comparison at the end of the stream. This
716*3886Sahl    is for use with other formats that use the deflate compressed data format
717*3886Sahl    such as zip.  Those formats provide their own check values. If a custom
718*3886Sahl    format is developed using the raw deflate format for compressed data, it is
719*3886Sahl    recommended that a check value such as an adler32 or a crc32 be applied to
720*3886Sahl    the uncompressed data as is done in the zlib, gzip, and zip formats.  For
721*3886Sahl    most applications, the zlib format should be used as is. Note that comments
722*3886Sahl    above on the use in deflateInit2() applies to the magnitude of windowBits.
723*3886Sahl 
724*3886Sahl      windowBits can also be greater than 15 for optional gzip decoding. Add
725*3886Sahl    32 to windowBits to enable zlib and gzip decoding with automatic header
726*3886Sahl    detection, or add 16 to decode only the gzip format (the zlib format will
727*3886Sahl    return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is
728*3886Sahl    a crc32 instead of an adler32.
729*3886Sahl 
730*3886Sahl      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
731*3886Sahl    memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
732*3886Sahl    is set to null if there is no error message.  inflateInit2 does not perform
733*3886Sahl    any decompression apart from reading the zlib header if present: this will
734*3886Sahl    be done by inflate(). (So next_in and avail_in may be modified, but next_out
735*3886Sahl    and avail_out are unchanged.)
7360Sstevel@tonic-gate */
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
7390Sstevel@tonic-gate                                              const Bytef *dictionary,
7400Sstevel@tonic-gate                                              uInt  dictLength));
7410Sstevel@tonic-gate /*
7420Sstevel@tonic-gate      Initializes the decompression dictionary from the given uncompressed byte
743*3886Sahl    sequence. This function must be called immediately after a call of inflate,
744*3886Sahl    if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
745*3886Sahl    can be determined from the adler32 value returned by that call of inflate.
746*3886Sahl    The compressor and decompressor must use exactly the same dictionary (see
747*3886Sahl    deflateSetDictionary).  For raw inflate, this function can be called
748*3886Sahl    immediately after inflateInit2() or inflateReset() and before any call of
749*3886Sahl    inflate() to set the dictionary.  The application must insure that the
750*3886Sahl    dictionary that was used for compression is provided.
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
7530Sstevel@tonic-gate    parameter is invalid (such as NULL dictionary) or the stream state is
7540Sstevel@tonic-gate    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
755*3886Sahl    expected one (incorrect adler32 value). inflateSetDictionary does not
7560Sstevel@tonic-gate    perform any decompression: this will be done by subsequent calls of
7570Sstevel@tonic-gate    inflate().
7580Sstevel@tonic-gate */
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
761*3886Sahl /*
7620Sstevel@tonic-gate     Skips invalid compressed data until a full flush point (see above the
7630Sstevel@tonic-gate   description of deflate with Z_FULL_FLUSH) can be found, or until all
7640Sstevel@tonic-gate   available input is skipped. No output is provided.
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
7670Sstevel@tonic-gate   if no more input was provided, Z_DATA_ERROR if no flush point has been found,
7680Sstevel@tonic-gate   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
7690Sstevel@tonic-gate   case, the application may save the current current value of total_in which
7700Sstevel@tonic-gate   indicates where valid compressed data was found. In the error case, the
7710Sstevel@tonic-gate   application may repeatedly call inflateSync, providing more input each time,
7720Sstevel@tonic-gate   until success or end of the input data.
7730Sstevel@tonic-gate */
7740Sstevel@tonic-gate 
775*3886Sahl ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
776*3886Sahl                                     z_streamp source));
777*3886Sahl /*
778*3886Sahl      Sets the destination stream as a complete copy of the source stream.
779*3886Sahl 
780*3886Sahl      This function can be useful when randomly accessing a large stream.  The
781*3886Sahl    first pass through the stream can periodically record the inflate state,
782*3886Sahl    allowing restarting inflate at those points when randomly accessing the
783*3886Sahl    stream.
784*3886Sahl 
785*3886Sahl      inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
786*3886Sahl    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
787*3886Sahl    (such as zalloc being NULL). msg is left unchanged in both source and
788*3886Sahl    destination.
789*3886Sahl */
790*3886Sahl 
7910Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
7920Sstevel@tonic-gate /*
7930Sstevel@tonic-gate      This function is equivalent to inflateEnd followed by inflateInit,
7940Sstevel@tonic-gate    but does not free and reallocate all the internal decompression state.
7950Sstevel@tonic-gate    The stream will keep attributes that may have been set by inflateInit2.
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
7980Sstevel@tonic-gate    stream state was inconsistent (such as zalloc or state being NULL).
7990Sstevel@tonic-gate */
8000Sstevel@tonic-gate 
801*3886Sahl ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
802*3886Sahl                                      int bits,
803*3886Sahl                                      int value));
804*3886Sahl /*
805*3886Sahl      This function inserts bits in the inflate input stream.  The intent is
806*3886Sahl   that this function is used to start inflating at a bit position in the
807*3886Sahl   middle of a byte.  The provided bits will be used before any bytes are used
808*3886Sahl   from next_in.  This function should only be used with raw inflate, and
809*3886Sahl   should be used before the first inflate() call after inflateInit2() or
810*3886Sahl   inflateReset().  bits must be less than or equal to 16, and that many of the
811*3886Sahl   least significant bits of value will be inserted in the input.
812*3886Sahl 
813*3886Sahl       inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
814*3886Sahl    stream state was inconsistent.
815*3886Sahl */
816*3886Sahl 
817*3886Sahl ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
818*3886Sahl                                          gz_headerp head));
819*3886Sahl /*
820*3886Sahl       inflateGetHeader() requests that gzip header information be stored in the
821*3886Sahl    provided gz_header structure.  inflateGetHeader() may be called after
822*3886Sahl    inflateInit2() or inflateReset(), and before the first call of inflate().
823*3886Sahl    As inflate() processes the gzip stream, head->done is zero until the header
824*3886Sahl    is completed, at which time head->done is set to one.  If a zlib stream is
825*3886Sahl    being decoded, then head->done is set to -1 to indicate that there will be
826*3886Sahl    no gzip header information forthcoming.  Note that Z_BLOCK can be used to
827*3886Sahl    force inflate() to return immediately after header processing is complete
828*3886Sahl    and before any actual data is decompressed.
829*3886Sahl 
830*3886Sahl       The text, time, xflags, and os fields are filled in with the gzip header
831*3886Sahl    contents.  hcrc is set to true if there is a header CRC.  (The header CRC
832*3886Sahl    was valid if done is set to one.)  If extra is not Z_NULL, then extra_max
833*3886Sahl    contains the maximum number of bytes to write to extra.  Once done is true,
834*3886Sahl    extra_len contains the actual extra field length, and extra contains the
835*3886Sahl    extra field, or that field truncated if extra_max is less than extra_len.
836*3886Sahl    If name is not Z_NULL, then up to name_max characters are written there,
837*3886Sahl    terminated with a zero unless the length is greater than name_max.  If
838*3886Sahl    comment is not Z_NULL, then up to comm_max characters are written there,
839*3886Sahl    terminated with a zero unless the length is greater than comm_max.  When
840*3886Sahl    any of extra, name, or comment are not Z_NULL and the respective field is
841*3886Sahl    not present in the header, then that field is set to Z_NULL to signal its
842*3886Sahl    absence.  This allows the use of deflateSetHeader() with the returned
843*3886Sahl    structure to duplicate the header.  However if those fields are set to
844*3886Sahl    allocated memory, then the application will need to save those pointers
845*3886Sahl    elsewhere so that they can be eventually freed.
846*3886Sahl 
847*3886Sahl       If inflateGetHeader is not used, then the header information is simply
848*3886Sahl    discarded.  The header is always checked for validity, including the header
849*3886Sahl    CRC if present.  inflateReset() will reset the process to discard the header
850*3886Sahl    information.  The application would need to call inflateGetHeader() again to
851*3886Sahl    retrieve the header from the next gzip stream.
852*3886Sahl 
853*3886Sahl       inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
854*3886Sahl    stream state was inconsistent.
855*3886Sahl */
856*3886Sahl 
857*3886Sahl /*
858*3886Sahl ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
859*3886Sahl                                         unsigned char FAR *window));
860*3886Sahl 
861*3886Sahl      Initialize the internal stream state for decompression using inflateBack()
862*3886Sahl    calls.  The fields zalloc, zfree and opaque in strm must be initialized
863*3886Sahl    before the call.  If zalloc and zfree are Z_NULL, then the default library-
864*3886Sahl    derived memory allocation routines are used.  windowBits is the base two
865*3886Sahl    logarithm of the window size, in the range 8..15.  window is a caller
866*3886Sahl    supplied buffer of that size.  Except for special applications where it is
867*3886Sahl    assured that deflate was used with small window sizes, windowBits must be 15
868*3886Sahl    and a 32K byte window must be supplied to be able to decompress general
869*3886Sahl    deflate streams.
870*3886Sahl 
871*3886Sahl      See inflateBack() for the usage of these routines.
872*3886Sahl 
873*3886Sahl      inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
874*3886Sahl    the paramaters are invalid, Z_MEM_ERROR if the internal state could not
875*3886Sahl    be allocated, or Z_VERSION_ERROR if the version of the library does not
876*3886Sahl    match the version of the header file.
877*3886Sahl */
878*3886Sahl 
879*3886Sahl typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
880*3886Sahl typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
881*3886Sahl 
882*3886Sahl ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
883*3886Sahl                                     in_func in, void FAR *in_desc,
884*3886Sahl                                     out_func out, void FAR *out_desc));
885*3886Sahl /*
886*3886Sahl      inflateBack() does a raw inflate with a single call using a call-back
887*3886Sahl    interface for input and output.  This is more efficient than inflate() for
888*3886Sahl    file i/o applications in that it avoids copying between the output and the
889*3886Sahl    sliding window by simply making the window itself the output buffer.  This
890*3886Sahl    function trusts the application to not change the output buffer passed by
891*3886Sahl    the output function, at least until inflateBack() returns.
892*3886Sahl 
893*3886Sahl      inflateBackInit() must be called first to allocate the internal state
894*3886Sahl    and to initialize the state with the user-provided window buffer.
895*3886Sahl    inflateBack() may then be used multiple times to inflate a complete, raw
896*3886Sahl    deflate stream with each call.  inflateBackEnd() is then called to free
897*3886Sahl    the allocated state.
898*3886Sahl 
899*3886Sahl      A raw deflate stream is one with no zlib or gzip header or trailer.
900*3886Sahl    This routine would normally be used in a utility that reads zip or gzip
901*3886Sahl    files and writes out uncompressed files.  The utility would decode the
902*3886Sahl    header and process the trailer on its own, hence this routine expects
903*3886Sahl    only the raw deflate stream to decompress.  This is different from the
904*3886Sahl    normal behavior of inflate(), which expects either a zlib or gzip header and
905*3886Sahl    trailer around the deflate stream.
906*3886Sahl 
907*3886Sahl      inflateBack() uses two subroutines supplied by the caller that are then
908*3886Sahl    called by inflateBack() for input and output.  inflateBack() calls those
909*3886Sahl    routines until it reads a complete deflate stream and writes out all of the
910*3886Sahl    uncompressed data, or until it encounters an error.  The function's
911*3886Sahl    parameters and return types are defined above in the in_func and out_func
912*3886Sahl    typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
913*3886Sahl    number of bytes of provided input, and a pointer to that input in buf.  If
914*3886Sahl    there is no input available, in() must return zero--buf is ignored in that
915*3886Sahl    case--and inflateBack() will return a buffer error.  inflateBack() will call
916*3886Sahl    out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()
917*3886Sahl    should return zero on success, or non-zero on failure.  If out() returns
918*3886Sahl    non-zero, inflateBack() will return with an error.  Neither in() nor out()
919*3886Sahl    are permitted to change the contents of the window provided to
920*3886Sahl    inflateBackInit(), which is also the buffer that out() uses to write from.
921*3886Sahl    The length written by out() will be at most the window size.  Any non-zero
922*3886Sahl    amount of input may be provided by in().
923*3886Sahl 
924*3886Sahl      For convenience, inflateBack() can be provided input on the first call by
925*3886Sahl    setting strm->next_in and strm->avail_in.  If that input is exhausted, then
926*3886Sahl    in() will be called.  Therefore strm->next_in must be initialized before
927*3886Sahl    calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called
928*3886Sahl    immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
929*3886Sahl    must also be initialized, and then if strm->avail_in is not zero, input will
930*3886Sahl    initially be taken from strm->next_in[0 .. strm->avail_in - 1].
931*3886Sahl 
932*3886Sahl      The in_desc and out_desc parameters of inflateBack() is passed as the
933*3886Sahl    first parameter of in() and out() respectively when they are called.  These
934*3886Sahl    descriptors can be optionally used to pass any information that the caller-
935*3886Sahl    supplied in() and out() functions need to do their job.
936*3886Sahl 
937*3886Sahl      On return, inflateBack() will set strm->next_in and strm->avail_in to
938*3886Sahl    pass back any unused input that was provided by the last in() call.  The
939*3886Sahl    return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
940*3886Sahl    if in() or out() returned an error, Z_DATA_ERROR if there was a format
941*3886Sahl    error in the deflate stream (in which case strm->msg is set to indicate the
942*3886Sahl    nature of the error), or Z_STREAM_ERROR if the stream was not properly
943*3886Sahl    initialized.  In the case of Z_BUF_ERROR, an input or output error can be
944*3886Sahl    distinguished using strm->next_in which will be Z_NULL only if in() returned
945*3886Sahl    an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
946*3886Sahl    out() returning non-zero.  (in() will always be called before out(), so
947*3886Sahl    strm->next_in is assured to be defined if out() returns non-zero.)  Note
948*3886Sahl    that inflateBack() cannot return Z_OK.
949*3886Sahl */
950*3886Sahl 
951*3886Sahl ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
952*3886Sahl /*
953*3886Sahl      All memory allocated by inflateBackInit() is freed.
954*3886Sahl 
955*3886Sahl      inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
956*3886Sahl    state was inconsistent.
957*3886Sahl */
958*3886Sahl 
959*3886Sahl ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
960*3886Sahl /* Return flags indicating compile-time options.
961*3886Sahl 
962*3886Sahl     Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
963*3886Sahl      1.0: size of uInt
964*3886Sahl      3.2: size of uLong
965*3886Sahl      5.4: size of voidpf (pointer)
966*3886Sahl      7.6: size of z_off_t
967*3886Sahl 
968*3886Sahl     Compiler, assembler, and debug options:
969*3886Sahl      8: DEBUG
970*3886Sahl      9: ASMV or ASMINF -- use ASM code
971*3886Sahl      10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
972*3886Sahl      11: 0 (reserved)
973*3886Sahl 
974*3886Sahl     One-time table building (smaller code, but not thread-safe if true):
975*3886Sahl      12: BUILDFIXED -- build static block decoding tables when needed
976*3886Sahl      13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
977*3886Sahl      14,15: 0 (reserved)
978*3886Sahl 
979*3886Sahl     Library content (indicates missing functionality):
980*3886Sahl      16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
981*3886Sahl                           deflate code when not needed)
982*3886Sahl      17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
983*3886Sahl                     and decode gzip streams (to avoid linking crc code)
984*3886Sahl      18-19: 0 (reserved)
985*3886Sahl 
986*3886Sahl     Operation variations (changes in library functionality):
987*3886Sahl      20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
988*3886Sahl      21: FASTEST -- deflate algorithm with only one, lowest compression level
989*3886Sahl      22,23: 0 (reserved)
990*3886Sahl 
991*3886Sahl     The sprintf variant used by gzprintf (zero is best):
992*3886Sahl      24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
993*3886Sahl      25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
994*3886Sahl      26: 0 = returns value, 1 = void -- 1 means inferred string length returned
995*3886Sahl 
996*3886Sahl     Remainder:
997*3886Sahl      27-31: 0 (reserved)
998*3886Sahl  */
999*3886Sahl 
1000*3886Sahl 
1001*3886Sahl                         /* utility functions */
1002*3886Sahl 
1003*3886Sahl /*
1004*3886Sahl      The following utility functions are implemented on top of the
1005*3886Sahl    basic stream-oriented functions. To simplify the interface, some
1006*3886Sahl    default options are assumed (compression level and memory usage,
1007*3886Sahl    standard memory allocation functions). The source code of these
1008*3886Sahl    utility functions can easily be modified if you need special options.
1009*3886Sahl */
1010*3886Sahl 
1011*3886Sahl ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
1012*3886Sahl                                  const Bytef *source, uLong sourceLen));
1013*3886Sahl /*
1014*3886Sahl      Compresses the source buffer into the destination buffer.  sourceLen is
1015*3886Sahl    the byte length of the source buffer. Upon entry, destLen is the total
1016*3886Sahl    size of the destination buffer, which must be at least the value returned
1017*3886Sahl    by compressBound(sourceLen). Upon exit, destLen is the actual size of the
1018*3886Sahl    compressed buffer.
1019*3886Sahl      This function can be used to compress a whole file at once if the
1020*3886Sahl    input file is mmap'ed.
1021*3886Sahl      compress returns Z_OK if success, Z_MEM_ERROR if there was not
1022*3886Sahl    enough memory, Z_BUF_ERROR if there was not enough room in the output
1023*3886Sahl    buffer.
1024*3886Sahl */
1025*3886Sahl 
1026*3886Sahl ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
1027*3886Sahl                                   const Bytef *source, uLong sourceLen,
1028*3886Sahl                                   int level));
1029*3886Sahl /*
1030*3886Sahl      Compresses the source buffer into the destination buffer. The level
1031*3886Sahl    parameter has the same meaning as in deflateInit.  sourceLen is the byte
1032*3886Sahl    length of the source buffer. Upon entry, destLen is the total size of the
1033*3886Sahl    destination buffer, which must be at least the value returned by
1034*3886Sahl    compressBound(sourceLen). Upon exit, destLen is the actual size of the
1035*3886Sahl    compressed buffer.
1036*3886Sahl 
1037*3886Sahl      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1038*3886Sahl    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1039*3886Sahl    Z_STREAM_ERROR if the level parameter is invalid.
1040*3886Sahl */
1041*3886Sahl 
1042*3886Sahl ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1043*3886Sahl /*
1044*3886Sahl      compressBound() returns an upper bound on the compressed size after
1045*3886Sahl    compress() or compress2() on sourceLen bytes.  It would be used before
1046*3886Sahl    a compress() or compress2() call to allocate the destination buffer.
1047*3886Sahl */
1048*3886Sahl 
1049*3886Sahl ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
1050*3886Sahl                                    const Bytef *source, uLong sourceLen));
1051*3886Sahl /*
1052*3886Sahl      Decompresses the source buffer into the destination buffer.  sourceLen is
1053*3886Sahl    the byte length of the source buffer. Upon entry, destLen is the total
1054*3886Sahl    size of the destination buffer, which must be large enough to hold the
1055*3886Sahl    entire uncompressed data. (The size of the uncompressed data must have
1056*3886Sahl    been saved previously by the compressor and transmitted to the decompressor
1057*3886Sahl    by some mechanism outside the scope of this compression library.)
1058*3886Sahl    Upon exit, destLen is the actual size of the compressed buffer.
1059*3886Sahl      This function can be used to decompress a whole file at once if the
1060*3886Sahl    input file is mmap'ed.
1061*3886Sahl 
1062*3886Sahl      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1063*3886Sahl    enough memory, Z_BUF_ERROR if there was not enough room in the output
1064*3886Sahl    buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
1065*3886Sahl */
1066*3886Sahl 
1067*3886Sahl 
1068*3886Sahl typedef voidp gzFile;
1069*3886Sahl 
1070*3886Sahl ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
1071*3886Sahl /*
1072*3886Sahl      Opens a gzip (.gz) file for reading or writing. The mode parameter
1073*3886Sahl    is as in fopen ("rb" or "wb") but can also include a compression level
1074*3886Sahl    ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
1075*3886Sahl    Huffman only compression as in "wb1h", or 'R' for run-length encoding
1076*3886Sahl    as in "wb1R". (See the description of deflateInit2 for more information
1077*3886Sahl    about the strategy parameter.)
1078*3886Sahl 
1079*3886Sahl      gzopen can be used to read a file which is not in gzip format; in this
1080*3886Sahl    case gzread will directly read from the file without decompression.
1081*3886Sahl 
1082*3886Sahl      gzopen returns NULL if the file could not be opened or if there was
1083*3886Sahl    insufficient memory to allocate the (de)compression state; errno
1084*3886Sahl    can be checked to distinguish the two cases (if errno is zero, the
1085*3886Sahl    zlib error is Z_MEM_ERROR).  */
1086*3886Sahl 
1087*3886Sahl ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
1088*3886Sahl /*
1089*3886Sahl      gzdopen() associates a gzFile with the file descriptor fd.  File
1090*3886Sahl    descriptors are obtained from calls like open, dup, creat, pipe or
1091*3886Sahl    fileno (in the file has been previously opened with fopen).
1092*3886Sahl    The mode parameter is as in gzopen.
1093*3886Sahl      The next call of gzclose on the returned gzFile will also close the
1094*3886Sahl    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
1095*3886Sahl    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
1096*3886Sahl      gzdopen returns NULL if there was insufficient memory to allocate
1097*3886Sahl    the (de)compression state.
1098*3886Sahl */
1099*3886Sahl 
1100*3886Sahl ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1101*3886Sahl /*
1102*3886Sahl      Dynamically update the compression level or strategy. See the description
1103*3886Sahl    of deflateInit2 for the meaning of these parameters.
1104*3886Sahl      gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1105*3886Sahl    opened for writing.
1106*3886Sahl */
1107*3886Sahl 
1108*3886Sahl ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
1109*3886Sahl /*
1110*3886Sahl      Reads the given number of uncompressed bytes from the compressed file.
1111*3886Sahl    If the input file was not in gzip format, gzread copies the given number
1112*3886Sahl    of bytes into the buffer.
1113*3886Sahl      gzread returns the number of uncompressed bytes actually read (0 for
1114*3886Sahl    end of file, -1 for error). */
1115*3886Sahl 
1116*3886Sahl ZEXTERN int ZEXPORT    gzwrite OF((gzFile file,
1117*3886Sahl                                    voidpc buf, unsigned len));
1118*3886Sahl /*
1119*3886Sahl      Writes the given number of uncompressed bytes into the compressed file.
1120*3886Sahl    gzwrite returns the number of uncompressed bytes actually written
1121*3886Sahl    (0 in case of error).
1122*3886Sahl */
1123*3886Sahl 
1124*3886Sahl ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
1125*3886Sahl /*
1126*3886Sahl      Converts, formats, and writes the args to the compressed file under
1127*3886Sahl    control of the format string, as in fprintf. gzprintf returns the number of
1128*3886Sahl    uncompressed bytes actually written (0 in case of error).  The number of
1129*3886Sahl    uncompressed bytes written is limited to 4095. The caller should assure that
1130*3886Sahl    this limit is not exceeded. If it is exceeded, then gzprintf() will return
1131*3886Sahl    return an error (0) with nothing written. In this case, there may also be a
1132*3886Sahl    buffer overflow with unpredictable consequences, which is possible only if
1133*3886Sahl    zlib was compiled with the insecure functions sprintf() or vsprintf()
1134*3886Sahl    because the secure snprintf() or vsnprintf() functions were not available.
1135*3886Sahl */
1136*3886Sahl 
1137*3886Sahl ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1138*3886Sahl /*
1139*3886Sahl       Writes the given null-terminated string to the compressed file, excluding
1140*3886Sahl    the terminating null character.
1141*3886Sahl       gzputs returns the number of characters written, or -1 in case of error.
1142*3886Sahl */
1143*3886Sahl 
1144*3886Sahl ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1145*3886Sahl /*
1146*3886Sahl       Reads bytes from the compressed file until len-1 characters are read, or
1147*3886Sahl    a newline character is read and transferred to buf, or an end-of-file
1148*3886Sahl    condition is encountered.  The string is then terminated with a null
1149*3886Sahl    character.
1150*3886Sahl       gzgets returns buf, or Z_NULL in case of error.
1151*3886Sahl */
1152*3886Sahl 
1153*3886Sahl ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
1154*3886Sahl /*
1155*3886Sahl       Writes c, converted to an unsigned char, into the compressed file.
1156*3886Sahl    gzputc returns the value that was written, or -1 in case of error.
1157*3886Sahl */
1158*3886Sahl 
1159*3886Sahl ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
1160*3886Sahl /*
1161*3886Sahl       Reads one byte from the compressed file. gzgetc returns this byte
1162*3886Sahl    or -1 in case of end of file or error.
1163*3886Sahl */
1164*3886Sahl 
1165*3886Sahl ZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));
1166*3886Sahl /*
1167*3886Sahl       Push one character back onto the stream to be read again later.
1168*3886Sahl    Only one character of push-back is allowed.  gzungetc() returns the
1169*3886Sahl    character pushed, or -1 on failure.  gzungetc() will fail if a
1170*3886Sahl    character has been pushed but not read yet, or if c is -1. The pushed
1171*3886Sahl    character will be discarded if the stream is repositioned with gzseek()
1172*3886Sahl    or gzrewind().
1173*3886Sahl */
1174*3886Sahl 
1175*3886Sahl ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
1176*3886Sahl /*
1177*3886Sahl      Flushes all pending output into the compressed file. The parameter
1178*3886Sahl    flush is as in the deflate() function. The return value is the zlib
1179*3886Sahl    error number (see function gzerror below). gzflush returns Z_OK if
1180*3886Sahl    the flush parameter is Z_FINISH and all output could be flushed.
1181*3886Sahl      gzflush should be called only when strictly necessary because it can
1182*3886Sahl    degrade compression.
1183*3886Sahl */
1184*3886Sahl 
1185*3886Sahl ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
1186*3886Sahl                                       z_off_t offset, int whence));
1187*3886Sahl /*
1188*3886Sahl       Sets the starting position for the next gzread or gzwrite on the
1189*3886Sahl    given compressed file. The offset represents a number of bytes in the
1190*3886Sahl    uncompressed data stream. The whence parameter is defined as in lseek(2);
1191*3886Sahl    the value SEEK_END is not supported.
1192*3886Sahl      If the file is opened for reading, this function is emulated but can be
1193*3886Sahl    extremely slow. If the file is opened for writing, only forward seeks are
1194*3886Sahl    supported; gzseek then compresses a sequence of zeroes up to the new
1195*3886Sahl    starting position.
1196*3886Sahl 
1197*3886Sahl       gzseek returns the resulting offset location as measured in bytes from
1198*3886Sahl    the beginning of the uncompressed stream, or -1 in case of error, in
1199*3886Sahl    particular if the file is opened for writing and the new starting position
1200*3886Sahl    would be before the current position.
1201*3886Sahl */
1202*3886Sahl 
1203*3886Sahl ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
1204*3886Sahl /*
1205*3886Sahl      Rewinds the given file. This function is supported only for reading.
1206*3886Sahl 
1207*3886Sahl    gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1208*3886Sahl */
1209*3886Sahl 
1210*3886Sahl ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
1211*3886Sahl /*
1212*3886Sahl      Returns the starting position for the next gzread or gzwrite on the
1213*3886Sahl    given compressed file. This position represents a number of bytes in the
1214*3886Sahl    uncompressed data stream.
1215*3886Sahl 
1216*3886Sahl    gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1217*3886Sahl */
1218*3886Sahl 
1219*3886Sahl ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1220*3886Sahl /*
1221*3886Sahl      Returns 1 when EOF has previously been detected reading the given
1222*3886Sahl    input stream, otherwise zero.
1223*3886Sahl */
1224*3886Sahl 
1225*3886Sahl ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1226*3886Sahl /*
1227*3886Sahl      Returns 1 if file is being read directly without decompression, otherwise
1228*3886Sahl    zero.
1229*3886Sahl */
1230*3886Sahl 
1231*3886Sahl ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
1232*3886Sahl /*
1233*3886Sahl      Flushes all pending output if necessary, closes the compressed file
1234*3886Sahl    and deallocates all the (de)compression state. The return value is the zlib
1235*3886Sahl    error number (see function gzerror below).
1236*3886Sahl */
1237*3886Sahl 
1238*3886Sahl ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1239*3886Sahl /*
1240*3886Sahl      Returns the error message for the last error which occurred on the
1241*3886Sahl    given compressed file. errnum is set to zlib error number. If an
1242*3886Sahl    error occurred in the file system and not in the compression library,
1243*3886Sahl    errnum is set to Z_ERRNO and the application may consult errno
1244*3886Sahl    to get the exact error code.
1245*3886Sahl */
1246*3886Sahl 
1247*3886Sahl ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1248*3886Sahl /*
1249*3886Sahl      Clears the error and end-of-file flags for file. This is analogous to the
1250*3886Sahl    clearerr() function in stdio. This is useful for continuing to read a gzip
1251*3886Sahl    file that is being written concurrently.
1252*3886Sahl */
1253*3886Sahl 
12540Sstevel@tonic-gate                         /* checksum functions */
12550Sstevel@tonic-gate 
12560Sstevel@tonic-gate /*
12570Sstevel@tonic-gate      These functions are not related to compression but are exported
12580Sstevel@tonic-gate    anyway because they might be useful in applications using the
12590Sstevel@tonic-gate    compression library.
12600Sstevel@tonic-gate */
12610Sstevel@tonic-gate 
12620Sstevel@tonic-gate ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
12630Sstevel@tonic-gate /*
12640Sstevel@tonic-gate      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
12650Sstevel@tonic-gate    return the updated checksum. If buf is NULL, this function returns
12660Sstevel@tonic-gate    the required initial value for the checksum.
12670Sstevel@tonic-gate    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
12680Sstevel@tonic-gate    much faster. Usage example:
12690Sstevel@tonic-gate 
12700Sstevel@tonic-gate      uLong adler = adler32(0L, Z_NULL, 0);
12710Sstevel@tonic-gate 
12720Sstevel@tonic-gate      while (read_buffer(buffer, length) != EOF) {
12730Sstevel@tonic-gate        adler = adler32(adler, buffer, length);
12740Sstevel@tonic-gate      }
12750Sstevel@tonic-gate      if (adler != original_adler) error();
12760Sstevel@tonic-gate */
12770Sstevel@tonic-gate 
1278*3886Sahl ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1279*3886Sahl                                           z_off_t len2));
1280*3886Sahl /*
1281*3886Sahl      Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
1282*3886Sahl    and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1283*3886Sahl    each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
1284*3886Sahl    seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
1285*3886Sahl */
1286*3886Sahl 
12870Sstevel@tonic-gate ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
12880Sstevel@tonic-gate /*
1289*3886Sahl      Update a running CRC-32 with the bytes buf[0..len-1] and return the
1290*3886Sahl    updated CRC-32. If buf is NULL, this function returns the required initial
1291*3886Sahl    value for the for the crc. Pre- and post-conditioning (one's complement) is
1292*3886Sahl    performed within this function so it shouldn't be done by the application.
12930Sstevel@tonic-gate    Usage example:
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate      uLong crc = crc32(0L, Z_NULL, 0);
12960Sstevel@tonic-gate 
12970Sstevel@tonic-gate      while (read_buffer(buffer, length) != EOF) {
12980Sstevel@tonic-gate        crc = crc32(crc, buffer, length);
12990Sstevel@tonic-gate      }
13000Sstevel@tonic-gate      if (crc != original_crc) error();
13010Sstevel@tonic-gate */
13020Sstevel@tonic-gate 
1303*3886Sahl ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1304*3886Sahl 
1305*3886Sahl /*
1306*3886Sahl      Combine two CRC-32 check values into one.  For two sequences of bytes,
1307*3886Sahl    seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1308*3886Sahl    calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32
1309*3886Sahl    check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1310*3886Sahl    len2.
1311*3886Sahl */
1312*3886Sahl 
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate                         /* various hacks, don't look :) */
13150Sstevel@tonic-gate 
13160Sstevel@tonic-gate /* deflateInit and inflateInit are macros to allow checking the zlib version
13170Sstevel@tonic-gate  * and the compiler's view of z_stream:
13180Sstevel@tonic-gate  */
13190Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
13200Sstevel@tonic-gate                                      const char *version, int stream_size));
13210Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
13220Sstevel@tonic-gate                                      const char *version, int stream_size));
13230Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
13240Sstevel@tonic-gate                                       int windowBits, int memLevel,
13250Sstevel@tonic-gate                                       int strategy, const char *version,
13260Sstevel@tonic-gate                                       int stream_size));
13270Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
13280Sstevel@tonic-gate                                       const char *version, int stream_size));
1329*3886Sahl ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1330*3886Sahl                                          unsigned char FAR *window,
1331*3886Sahl                                          const char *version,
1332*3886Sahl                                          int stream_size));
13330Sstevel@tonic-gate #define deflateInit(strm, level) \
13340Sstevel@tonic-gate         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
13350Sstevel@tonic-gate #define inflateInit(strm) \
13360Sstevel@tonic-gate         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
13370Sstevel@tonic-gate #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
13380Sstevel@tonic-gate         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
13390Sstevel@tonic-gate                       (strategy),           ZLIB_VERSION, sizeof(z_stream))
13400Sstevel@tonic-gate #define inflateInit2(strm, windowBits) \
13410Sstevel@tonic-gate         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1342*3886Sahl #define inflateBackInit(strm, windowBits, window) \
1343*3886Sahl         inflateBackInit_((strm), (windowBits), (window), \
1344*3886Sahl         ZLIB_VERSION, sizeof(z_stream))
13450Sstevel@tonic-gate 
13460Sstevel@tonic-gate 
1347*3886Sahl #if !defined(_ZUTIL_H) && !defined(NO_DUMMY_DECL)
1348*3886Sahl     struct internal_state {int dummy;}; /* hack for buggy compilers */
1349*3886Sahl #endif
1350*3886Sahl 
1351*3886Sahl ZEXTERN const char   * ZEXPORT zError           OF((int));
13520Sstevel@tonic-gate ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
13530Sstevel@tonic-gate ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
13540Sstevel@tonic-gate 
1355*3886Sahl #ifdef __cplusplus
13560Sstevel@tonic-gate }
13570Sstevel@tonic-gate #endif
13580Sstevel@tonic-gate 
1359*3886Sahl #endif /* _ZLIB_H */
1360