1168404Spjd/* zlib.h -- interface of the 'zlib' general purpose compression library
2168404Spjd  version 1.2.3, July 18th, 2005
3168404Spjd
4168404Spjd  Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
5168404Spjd
6168404Spjd  This software is provided 'as-is', without any express or implied
7168404Spjd  warranty.  In no event will the authors be held liable for any damages
8168404Spjd  arising from the use of this software.
9168404Spjd
10168404Spjd  Permission is granted to anyone to use this software for any purpose,
11168404Spjd  including commercial applications, and to alter it and redistribute it
12168404Spjd  freely, subject to the following restrictions:
13168404Spjd
14168404Spjd  1. The origin of this software must not be misrepresented; you must not
15168404Spjd     claim that you wrote the original software. If you use this software
16168404Spjd     in a product, an acknowledgment in the product documentation would be
17168404Spjd     appreciated but is not required.
18168404Spjd  2. Altered source versions must be plainly marked as such, and must not be
19168404Spjd     misrepresented as being the original software.
20168404Spjd  3. This notice may not be removed or altered from any source distribution.
21168404Spjd
22168404Spjd  Jean-loup Gailly        Mark Adler
23168404Spjd  jloup@gzip.org          madler@alumni.caltech.edu
24168404Spjd
25168404Spjd
26168404Spjd  The data format used by the zlib library is described by RFCs (Request for
27168404Spjd  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
28168404Spjd  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29168404Spjd*/
30168404Spjd
31168404Spjd#ifndef _ZLIB_H
32168404Spjd#define _ZLIB_H
33168404Spjd
34168404Spjd#pragma ident	"%Z%%M%	%I%	%E% SMI"
35168404Spjd
36168404Spjd#include "zconf.h"
37168404Spjd
38168404Spjd#ifdef __cplusplus
39168404Spjdextern "C" {
40168404Spjd#endif
41168404Spjd
42168404Spjd#define ZLIB_VERSION "1.2.3"
43168404Spjd#define ZLIB_VERNUM 0x1230
44168404Spjd
45168404Spjd/*
46168404Spjd     The 'zlib' compression library provides in-memory compression and
47168404Spjd  decompression functions, including integrity checks of the uncompressed
48168404Spjd  data.  This version of the library supports only one compression method
49168404Spjd  (deflation) but other algorithms will be added later and will have the same
50168404Spjd  stream interface.
51168404Spjd
52168404Spjd     Compression can be done in a single step if the buffers are large
53168404Spjd  enough (for example if an input file is mmap'ed), or can be done by
54168404Spjd  repeated calls of the compression function.  In the latter case, the
55168404Spjd  application must provide more input and/or consume the output
56168404Spjd  (providing more output space) before each call.
57168404Spjd
58168404Spjd     The compressed data format used by default by the in-memory functions is
59168404Spjd  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
60168404Spjd  around a deflate stream, which is itself documented in RFC 1951.
61168404Spjd
62168404Spjd     The library also supports reading and writing files in gzip (.gz) format
63168404Spjd  with an interface similar to that of stdio using the functions that start
64168404Spjd  with "gz".  The gzip format is different from the zlib format.  gzip is a
65168404Spjd  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
66168404Spjd
67168404Spjd     This library can optionally read and write gzip streams in memory as well.
68168404Spjd
69168404Spjd     The zlib format was designed to be compact and fast for use in memory
70168404Spjd  and on communications channels.  The gzip format was designed for single-
71168404Spjd  file compression on file systems, has a larger header than zlib to maintain
72168404Spjd  directory information, and uses a different, slower check method than zlib.
73168404Spjd
74168404Spjd     The library does not install any signal handler. The decoder checks
75168404Spjd  the consistency of the compressed data, so the library should never
76168404Spjd  crash even in case of corrupted input.
77168404Spjd*/
78168404Spjd
79168404Spjdtypedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
80168404Spjdtypedef void   (*free_func)  OF((voidpf opaque, voidpf address));
81168404Spjd
82168404Spjdstruct internal_state;
83168404Spjd
84168404Spjdtypedef struct z_stream_s {
85168404Spjd    Bytef    *next_in;  /* next input byte */
86168404Spjd    uInt     avail_in;  /* number of bytes available at next_in */
87168404Spjd    uLong    total_in;  /* total nb of input bytes read so far */
88168404Spjd
89168404Spjd    Bytef    *next_out; /* next output byte should be put there */
90168404Spjd    uInt     avail_out; /* remaining free space at next_out */
91168404Spjd    uLong    total_out; /* total nb of bytes output so far */
92168404Spjd
93168404Spjd    char     *msg;      /* last error message, NULL if no error */
94168404Spjd    struct internal_state FAR *state; /* not visible by applications */
95168404Spjd
96168404Spjd    alloc_func zalloc;  /* used to allocate the internal state */
97168404Spjd    free_func  zfree;   /* used to free the internal state */
98168404Spjd    voidpf     opaque;  /* private data object passed to zalloc and zfree */
99168404Spjd
100168404Spjd    int     data_type;  /* best guess about the data type: binary or text */
101168404Spjd    uLong   adler;      /* adler32 value of the uncompressed data */
102168404Spjd    uLong   reserved;   /* reserved for future use */
103168404Spjd} z_stream;
104168404Spjd
105168404Spjdtypedef z_stream FAR *z_streamp;
106168404Spjd
107168404Spjd/*
108168404Spjd     gzip header information passed to and from zlib routines.  See RFC 1952
109168404Spjd  for more details on the meanings of these fields.
110168404Spjd*/
111168404Spjdtypedef struct gz_header_s {
112168404Spjd    int     text;       /* true if compressed data believed to be text */
113168404Spjd    uLong   time;       /* modification time */
114168404Spjd    int     xflags;     /* extra flags (not used when writing a gzip file) */
115168404Spjd    int     os;         /* operating system */
116168404Spjd    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
117168404Spjd    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
118168404Spjd    uInt    extra_max;  /* space at extra (only when reading header) */
119168404Spjd    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
120168404Spjd    uInt    name_max;   /* space at name (only when reading header) */
121168404Spjd    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
122168404Spjd    uInt    comm_max;   /* space at comment (only when reading header) */
123168404Spjd    int     hcrc;       /* true if there was or will be a header crc */
124168404Spjd    int     done;       /* true when done reading gzip header (not used
125168404Spjd                           when writing a gzip file) */
126168404Spjd} gz_header;
127168404Spjd
128168404Spjdtypedef gz_header FAR *gz_headerp;
129168404Spjd
130168404Spjd/*
131168404Spjd   The application must update next_in and avail_in when avail_in has
132168404Spjd   dropped to zero. It must update next_out and avail_out when avail_out
133168404Spjd   has dropped to zero. The application must initialize zalloc, zfree and
134168404Spjd   opaque before calling the init function. All other fields are set by the
135168404Spjd   compression library and must not be updated by the application.
136168404Spjd
137168404Spjd   The opaque value provided by the application will be passed as the first
138168404Spjd   parameter for calls of zalloc and zfree. This can be useful for custom
139168404Spjd   memory management. The compression library attaches no meaning to the
140168404Spjd   opaque value.
141168404Spjd
142168404Spjd   zalloc must return Z_NULL if there is not enough memory for the object.
143168404Spjd   If zlib is used in a multi-threaded application, zalloc and zfree must be
144168404Spjd   thread safe.
145168404Spjd
146168404Spjd   On 16-bit systems, the functions zalloc and zfree must be able to allocate
147168404Spjd   exactly 65536 bytes, but will not be required to allocate more than this
148168404Spjd   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
149168404Spjd   pointers returned by zalloc for objects of exactly 65536 bytes *must*
150168404Spjd   have their offset normalized to zero. The default allocation function
151168404Spjd   provided by this library ensures this (see zutil.c). To reduce memory
152168404Spjd   requirements and avoid any allocation of 64K objects, at the expense of
153168404Spjd   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
154168404Spjd
155168404Spjd   The fields total_in and total_out can be used for statistics or
156168404Spjd   progress reports. After compression, total_in holds the total size of
157168404Spjd   the uncompressed data and may be saved for use in the decompressor
158168404Spjd   (particularly if the decompressor wants to decompress everything in
159168404Spjd   a single step).
160168404Spjd*/
161168404Spjd
162168404Spjd                        /* constants */
163168404Spjd
164168404Spjd#define Z_NO_FLUSH      0
165168404Spjd#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
166168404Spjd#define Z_SYNC_FLUSH    2
167168404Spjd#define Z_FULL_FLUSH    3
168168404Spjd#define Z_FINISH        4
169168404Spjd#define Z_BLOCK         5
170168404Spjd/* Allowed flush values; see deflate() and inflate() below for details */
171168404Spjd
172168404Spjd#define Z_OK            0
173168404Spjd#define Z_STREAM_END    1
174168404Spjd#define Z_NEED_DICT     2
175168404Spjd#define Z_ERRNO        (-1)
176168404Spjd#define Z_STREAM_ERROR (-2)
177168404Spjd#define Z_DATA_ERROR   (-3)
178168404Spjd#define Z_MEM_ERROR    (-4)
179168404Spjd#define Z_BUF_ERROR    (-5)
180168404Spjd#define Z_VERSION_ERROR (-6)
181168404Spjd/* Return codes for the compression/decompression functions. Negative
182168404Spjd * values are errors, positive values are used for special but normal events.
183168404Spjd */
184168404Spjd
185168404Spjd#define Z_NO_COMPRESSION         0
186168404Spjd#define Z_BEST_SPEED             1
187168404Spjd#define Z_BEST_COMPRESSION       9
188168404Spjd#define Z_DEFAULT_COMPRESSION  (-1)
189168404Spjd/* compression levels */
190168404Spjd
191168404Spjd#define Z_FILTERED            1
192168404Spjd#define Z_HUFFMAN_ONLY        2
193168404Spjd#define Z_RLE                 3
194168404Spjd#define Z_FIXED               4
195168404Spjd#define Z_DEFAULT_STRATEGY    0
196168404Spjd/* compression strategy; see deflateInit2() below for details */
197168404Spjd
198168404Spjd#define Z_BINARY   0
199168404Spjd#define Z_TEXT     1
200168404Spjd#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
201168404Spjd#define Z_UNKNOWN  2
202168404Spjd/* Possible values of the data_type field (though see inflate()) */
203168404Spjd
204168404Spjd#define Z_DEFLATED   8
205168404Spjd/* The deflate compression method (the only one supported in this version) */
206168404Spjd
207168404Spjd#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
208168404Spjd
209168404Spjd#define zlib_version zlibVersion()
210168404Spjd/* for compatibility with versions < 1.0.2 */
211168404Spjd
212168404Spjd                        /* basic functions */
213168404Spjd
214168404SpjdZEXTERN const char * ZEXPORT zlibVersion OF((void));
215168404Spjd/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
216168404Spjd   If the first character differs, the library code actually used is
217168404Spjd   not compatible with the zlib.h header file used by the application.
218168404Spjd   This check is automatically made by deflateInit and inflateInit.
219168404Spjd */
220168404Spjd
221168404Spjd/*
222168404SpjdZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
223168404Spjd
224168404Spjd     Initializes the internal stream state for compression. The fields
225168404Spjd   zalloc, zfree and opaque must be initialized before by the caller.
226168404Spjd   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
227168404Spjd   use default allocation functions.
228168404Spjd
229168404Spjd     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
230168404Spjd   1 gives best speed, 9 gives best compression, 0 gives no compression at
231168404Spjd   all (the input data is simply copied a block at a time).
232168404Spjd   Z_DEFAULT_COMPRESSION requests a default compromise between speed and
233168404Spjd   compression (currently equivalent to level 6).
234168404Spjd
235168404Spjd     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
236168404Spjd   enough memory, Z_STREAM_ERROR if level is not a valid compression level,
237168404Spjd   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
238168404Spjd   with the version assumed by the caller (ZLIB_VERSION).
239168404Spjd   msg is set to null if there is no error message.  deflateInit does not
240168404Spjd   perform any compression: this will be done by deflate().
241168404Spjd*/
242168404Spjd
243168404Spjd
244168404SpjdZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
245168404Spjd/*
246168404Spjd    deflate compresses as much data as possible, and stops when the input
247168404Spjd  buffer becomes empty or the output buffer becomes full. It may introduce some
248168404Spjd  output latency (reading input without producing any output) except when
249168404Spjd  forced to flush.
250168404Spjd
251168404Spjd    The detailed semantics are as follows. deflate performs one or both of the
252168404Spjd  following actions:
253168404Spjd
254168404Spjd  - Compress more input starting at next_in and update next_in and avail_in
255168404Spjd    accordingly. If not all input can be processed (because there is not
256168404Spjd    enough room in the output buffer), next_in and avail_in are updated and
257168404Spjd    processing will resume at this point for the next call of deflate().
258168404Spjd
259168404Spjd  - Provide more output starting at next_out and update next_out and avail_out
260168404Spjd    accordingly. This action is forced if the parameter flush is non zero.
261168404Spjd    Forcing flush frequently degrades the compression ratio, so this parameter
262168404Spjd    should be set only when necessary (in interactive applications).
263168404Spjd    Some output may be provided even if flush is not set.
264168404Spjd
265168404Spjd  Before the call of deflate(), the application should ensure that at least
266168404Spjd  one of the actions is possible, by providing more input and/or consuming
267168404Spjd  more output, and updating avail_in or avail_out accordingly; avail_out
268168404Spjd  should never be zero before the call. The application can consume the
269168404Spjd  compressed output when it wants, for example when the output buffer is full
270168404Spjd  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
271168404Spjd  and with zero avail_out, it must be called again after making room in the
272168404Spjd  output buffer because there might be more output pending.
273168404Spjd
274168404Spjd    Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
275168404Spjd  decide how much data to accumualte before producing output, in order to
276168404Spjd  maximize compression.
277168404Spjd
278168404Spjd    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
279168404Spjd  flushed to the output buffer and the output is aligned on a byte boundary, so
280168404Spjd  that the decompressor can get all input data available so far. (In particular
281168404Spjd  avail_in is zero after the call if enough output space has been provided
282168404Spjd  before the call.)  Flushing may degrade compression for some compression
283168404Spjd  algorithms and so it should be used only when necessary.
284168404Spjd
285168404Spjd    If flush is set to Z_FULL_FLUSH, all output is flushed as with
286168404Spjd  Z_SYNC_FLUSH, and the compression state is reset so that decompression can
287168404Spjd  restart from this point if previous compressed data has been damaged or if
288168404Spjd  random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
289168404Spjd  compression.
290168404Spjd
291168404Spjd    If deflate returns with avail_out == 0, this function must be called again
292168404Spjd  with the same value of the flush parameter and more output space (updated
293168404Spjd  avail_out), until the flush is complete (deflate returns with non-zero
294168404Spjd  avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
295168404Spjd  avail_out is greater than six to avoid repeated flush markers due to
296168404Spjd  avail_out == 0 on return.
297168404Spjd
298168404Spjd    If the parameter flush is set to Z_FINISH, pending input is processed,
299168404Spjd  pending output is flushed and deflate returns with Z_STREAM_END if there
300168404Spjd  was enough output space; if deflate returns with Z_OK, this function must be
301168404Spjd  called again with Z_FINISH and more output space (updated avail_out) but no
302168404Spjd  more input data, until it returns with Z_STREAM_END or an error. After
303168404Spjd  deflate has returned Z_STREAM_END, the only possible operations on the
304168404Spjd  stream are deflateReset or deflateEnd.
305168404Spjd
306168404Spjd    Z_FINISH can be used immediately after deflateInit if all the compression
307168404Spjd  is to be done in a single step. In this case, avail_out must be at least
308168404Spjd  the value returned by deflateBound (see below). If deflate does not return
309168404Spjd  Z_STREAM_END, then it must be called again as described above.
310168404Spjd
311168404Spjd    deflate() sets strm->adler to the adler32 checksum of all input read
312168404Spjd  so far (that is, total_in bytes).
313168404Spjd
314168404Spjd    deflate() may update strm->data_type if it can make a good guess about
315168404Spjd  the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
316168404Spjd  binary. This field is only for information purposes and does not affect
317168404Spjd  the compression algorithm in any manner.
318168404Spjd
319168404Spjd    deflate() returns Z_OK if some progress has been made (more input
320168404Spjd  processed or more output produced), Z_STREAM_END if all input has been
321168404Spjd  consumed and all output has been produced (only when flush is set to
322168404Spjd  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
323168404Spjd  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
324168404Spjd  (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
325168404Spjd  fatal, and deflate() can be called again with more input and more output
326168404Spjd  space to continue compressing.
327168404Spjd*/
328168404Spjd
329168404Spjd
330168404SpjdZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
331168404Spjd/*
332168404Spjd     All dynamically allocated data structures for this stream are freed.
333168404Spjd   This function discards any unprocessed input and does not flush any
334168404Spjd   pending output.
335168404Spjd
336168404Spjd     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
337168404Spjd   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
338168404Spjd   prematurely (some input or output was discarded). In the error case,
339168404Spjd   msg may be set but then points to a static string (which must not be
340168404Spjd   deallocated).
341168404Spjd*/
342168404Spjd
343168404Spjd
344168404Spjd/*
345168404SpjdZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
346168404Spjd
347168404Spjd     Initializes the internal stream state for decompression. The fields
348168404Spjd   next_in, avail_in, zalloc, zfree and opaque must be initialized before by
349168404Spjd   the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
350168404Spjd   value depends on the compression method), inflateInit determines the
351168404Spjd   compression method from the zlib header and allocates all data structures
352168404Spjd   accordingly; otherwise the allocation will be deferred to the first call of
353168404Spjd   inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
354168404Spjd   use default allocation functions.
355168404Spjd
356168404Spjd     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
357168404Spjd   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
358168404Spjd   version assumed by the caller.  msg is set to null if there is no error
359168404Spjd   message. inflateInit does not perform any decompression apart from reading
360168404Spjd   the zlib header if present: this will be done by inflate().  (So next_in and
361168404Spjd   avail_in may be modified, but next_out and avail_out are unchanged.)
362168404Spjd*/
363168404Spjd
364168404Spjd
365168404SpjdZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
366168404Spjd/*
367168404Spjd    inflate decompresses as much data as possible, and stops when the input
368168404Spjd  buffer becomes empty or the output buffer becomes full. It may introduce
369168404Spjd  some output latency (reading input without producing any output) except when
370168404Spjd  forced to flush.
371168404Spjd
372168404Spjd  The detailed semantics are as follows. inflate performs one or both of the
373168404Spjd  following actions:
374168404Spjd
375168404Spjd  - Decompress more input starting at next_in and update next_in and avail_in
376168404Spjd    accordingly. If not all input can be processed (because there is not
377168404Spjd    enough room in the output buffer), next_in is updated and processing
378168404Spjd    will resume at this point for the next call of inflate().
379168404Spjd
380168404Spjd  - Provide more output starting at next_out and update next_out and avail_out
381168404Spjd    accordingly.  inflate() provides as much output as possible, until there
382168404Spjd    is no more input data or no more space in the output buffer (see below
383168404Spjd    about the flush parameter).
384168404Spjd
385168404Spjd  Before the call of inflate(), the application should ensure that at least
386168404Spjd  one of the actions is possible, by providing more input and/or consuming
387168404Spjd  more output, and updating the next_* and avail_* values accordingly.
388168404Spjd  The application can consume the uncompressed output when it wants, for
389168404Spjd  example when the output buffer is full (avail_out == 0), or after each
390168404Spjd  call of inflate(). If inflate returns Z_OK and with zero avail_out, it
391168404Spjd  must be called again after making room in the output buffer because there
392168404Spjd  might be more output pending.
393168404Spjd
394168404Spjd    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
395168404Spjd  Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
396168404Spjd  output as possible to the output buffer. Z_BLOCK requests that inflate() stop
397168404Spjd  if and when it gets to the next deflate block boundary. When decoding the
398168404Spjd  zlib or gzip format, this will cause inflate() to return immediately after
399168404Spjd  the header and before the first block. When doing a raw inflate, inflate()
400168404Spjd  will go ahead and process the first block, and will return when it gets to
401168404Spjd  the end of that block, or when it runs out of data.
402168404Spjd
403168404Spjd    The Z_BLOCK option assists in appending to or combining deflate streams.
404168404Spjd  Also to assist in this, on return inflate() will set strm->data_type to the
405168404Spjd  number of unused bits in the last byte taken from strm->next_in, plus 64
406168404Spjd  if inflate() is currently decoding the last block in the deflate stream,
407168404Spjd  plus 128 if inflate() returned immediately after decoding an end-of-block
408168404Spjd  code or decoding the complete header up to just before the first byte of the
409168404Spjd  deflate stream. The end-of-block will not be indicated until all of the
410168404Spjd  uncompressed data from that block has been written to strm->next_out.  The
411168404Spjd  number of unused bits may in general be greater than seven, except when
412168404Spjd  bit 7 of data_type is set, in which case the number of unused bits will be
413168404Spjd  less than eight.
414168404Spjd
415168404Spjd    inflate() should normally be called until it returns Z_STREAM_END or an
416168404Spjd  error. However if all decompression is to be performed in a single step
417168404Spjd  (a single call of inflate), the parameter flush should be set to
418168404Spjd  Z_FINISH. In this case all pending input is processed and all pending
419168404Spjd  output is flushed; avail_out must be large enough to hold all the
420168404Spjd  uncompressed data. (The size of the uncompressed data may have been saved
421168404Spjd  by the compressor for this purpose.) The next operation on this stream must
422168404Spjd  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
423168404Spjd  is never required, but can be used to inform inflate that a faster approach
424168404Spjd  may be used for the single inflate() call.
425168404Spjd
426168404Spjd     In this implementation, inflate() always flushes as much output as
427168404Spjd  possible to the output buffer, and always uses the faster approach on the
428168404Spjd  first call. So the only effect of the flush parameter in this implementation
429168404Spjd  is on the return value of inflate(), as noted below, or when it returns early
430168404Spjd  because Z_BLOCK is used.
431168404Spjd
432168404Spjd     If a preset dictionary is needed after this call (see inflateSetDictionary
433168404Spjd  below), inflate sets strm->adler to the adler32 checksum of the dictionary
434168404Spjd  chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
435168404Spjd  strm->adler to the adler32 checksum of all output produced so far (that is,
436168404Spjd  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
437168404Spjd  below. At the end of the stream, inflate() checks that its computed adler32
438168404Spjd  checksum is equal to that saved by the compressor and returns Z_STREAM_END
439168404Spjd  only if the checksum is correct.
440168404Spjd
441168404Spjd    inflate() will decompress and check either zlib-wrapped or gzip-wrapped
442168404Spjd  deflate data.  The header type is detected automatically.  Any information
443168404Spjd  contained in the gzip header is not retained, so applications that need that
444168404Spjd  information should instead use raw inflate, see inflateInit2() below, or
445168404Spjd  inflateBack() and perform their own processing of the gzip header and
446168404Spjd  trailer.
447168404Spjd
448168404Spjd    inflate() returns Z_OK if some progress has been made (more input processed
449168404Spjd  or more output produced), Z_STREAM_END if the end of the compressed data has
450168404Spjd  been reached and all uncompressed output has been produced, Z_NEED_DICT if a
451168404Spjd  preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
452168404Spjd  corrupted (input stream not conforming to the zlib format or incorrect check
453168404Spjd  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
454168404Spjd  if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
455168404Spjd  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
456168404Spjd  output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
457168404Spjd  inflate() can be called again with more input and more output space to
458168404Spjd  continue decompressing. If Z_DATA_ERROR is returned, the application may then
459168404Spjd  call inflateSync() to look for a good compression block if a partial recovery
460168404Spjd  of the data is desired.
461168404Spjd*/
462168404Spjd
463168404Spjd
464168404SpjdZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
465168404Spjd/*
466168404Spjd     All dynamically allocated data structures for this stream are freed.
467168404Spjd   This function discards any unprocessed input and does not flush any
468168404Spjd   pending output.
469168404Spjd
470168404Spjd     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
471168404Spjd   was inconsistent. In the error case, msg may be set but then points to a
472168404Spjd   static string (which must not be deallocated).
473168404Spjd*/
474168404Spjd
475168404Spjd                        /* Advanced functions */
476168404Spjd
477168404Spjd/*
478168404Spjd    The following functions are needed only in some special applications.
479168404Spjd*/
480168404Spjd
481168404Spjd/*
482168404SpjdZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
483168404Spjd                                     int  level,
484168404Spjd                                     int  method,
485168404Spjd                                     int  windowBits,
486168404Spjd                                     int  memLevel,
487168404Spjd                                     int  strategy));
488168404Spjd
489168404Spjd     This is another version of deflateInit with more compression options. The
490168404Spjd   fields next_in, zalloc, zfree and opaque must be initialized before by
491168404Spjd   the caller.
492168404Spjd
493168404Spjd     The method parameter is the compression method. It must be Z_DEFLATED in
494168404Spjd   this version of the library.
495168404Spjd
496168404Spjd     The windowBits parameter is the base two logarithm of the window size
497168404Spjd   (the size of the history buffer). It should be in the range 8..15 for this
498168404Spjd   version of the library. Larger values of this parameter result in better
499168404Spjd   compression at the expense of memory usage. The default value is 15 if
500168404Spjd   deflateInit is used instead.
501168404Spjd
502168404Spjd     windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
503168404Spjd   determines the window size. deflate() will then generate raw deflate data
504168404Spjd   with no zlib header or trailer, and will not compute an adler32 check value.
505168404Spjd
506168404Spjd     windowBits can also be greater than 15 for optional gzip encoding. Add
507168404Spjd   16 to windowBits to write a simple gzip header and trailer around the
508168404Spjd   compressed data instead of a zlib wrapper. The gzip header will have no
509168404Spjd   file name, no extra data, no comment, no modification time (set to zero),
510168404Spjd   no header crc, and the operating system will be set to 255 (unknown).  If a
511168404Spjd   gzip stream is being written, strm->adler is a crc32 instead of an adler32.
512168404Spjd
513168404Spjd     The memLevel parameter specifies how much memory should be allocated
514168404Spjd   for the internal compression state. memLevel=1 uses minimum memory but
515168404Spjd   is slow and reduces compression ratio; memLevel=9 uses maximum memory
516168404Spjd   for optimal speed. The default value is 8. See zconf.h for total memory
517168404Spjd   usage as a function of windowBits and memLevel.
518168404Spjd
519168404Spjd     The strategy parameter is used to tune the compression algorithm. Use the
520168404Spjd   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
521168404Spjd   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
522168404Spjd   string match), or Z_RLE to limit match distances to one (run-length
523168404Spjd   encoding). Filtered data consists mostly of small values with a somewhat
524168404Spjd   random distribution. In this case, the compression algorithm is tuned to
525168404Spjd   compress them better. The effect of Z_FILTERED is to force more Huffman
526168404Spjd   coding and less string matching; it is somewhat intermediate between
527168404Spjd   Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
528168404Spjd   Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
529168404Spjd   parameter only affects the compression ratio but not the correctness of the
530168404Spjd   compressed output even if it is not set appropriately.  Z_FIXED prevents the
531168404Spjd   use of dynamic Huffman codes, allowing for a simpler decoder for special
532168404Spjd   applications.
533168404Spjd
534168404Spjd      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
535168404Spjd   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
536168404Spjd   method). msg is set to null if there is no error message.  deflateInit2 does
537168404Spjd   not perform any compression: this will be done by deflate().
538168404Spjd*/
539168404Spjd
540168404SpjdZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
541168404Spjd                                             const Bytef *dictionary,
542168404Spjd                                             uInt  dictLength));
543168404Spjd/*
544168404Spjd     Initializes the compression dictionary from the given byte sequence
545168404Spjd   without producing any compressed output. This function must be called
546168404Spjd   immediately after deflateInit, deflateInit2 or deflateReset, before any
547168404Spjd   call of deflate. The compressor and decompressor must use exactly the same
548168404Spjd   dictionary (see inflateSetDictionary).
549168404Spjd
550168404Spjd     The dictionary should consist of strings (byte sequences) that are likely
551168404Spjd   to be encountered later in the data to be compressed, with the most commonly
552168404Spjd   used strings preferably put towards the end of the dictionary. Using a
553168404Spjd   dictionary is most useful when the data to be compressed is short and can be
554168404Spjd   predicted with good accuracy; the data can then be compressed better than
555168404Spjd   with the default empty dictionary.
556168404Spjd
557168404Spjd     Depending on the size of the compression data structures selected by
558168404Spjd   deflateInit or deflateInit2, a part of the dictionary may in effect be
559168404Spjd   discarded, for example if the dictionary is larger than the window size in
560168404Spjd   deflate or deflate2. Thus the strings most likely to be useful should be
561168404Spjd   put at the end of the dictionary, not at the front. In addition, the
562168404Spjd   current implementation of deflate will use at most the window size minus
563168404Spjd   262 bytes of the provided dictionary.
564168404Spjd
565168404Spjd     Upon return of this function, strm->adler is set to the adler32 value
566168404Spjd   of the dictionary; the decompressor may later use this value to determine
567168404Spjd   which dictionary has been used by the compressor. (The adler32 value
568168404Spjd   applies to the whole dictionary even if only a subset of the dictionary is
569168404Spjd   actually used by the compressor.) If a raw deflate was requested, then the
570168404Spjd   adler32 value is not computed and strm->adler is not set.
571168404Spjd
572168404Spjd     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
573168404Spjd   parameter is invalid (such as NULL dictionary) or the stream state is
574168404Spjd   inconsistent (for example if deflate has already been called for this stream
575168404Spjd   or if the compression method is bsort). deflateSetDictionary does not
576168404Spjd   perform any compression: this will be done by deflate().
577168404Spjd*/
578168404Spjd
579168404SpjdZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
580168404Spjd                                    z_streamp source));
581168404Spjd/*
582168404Spjd     Sets the destination stream as a complete copy of the source stream.
583168404Spjd
584168404Spjd     This function can be useful when several compression strategies will be
585168404Spjd   tried, for example when there are several ways of pre-processing the input
586168404Spjd   data with a filter. The streams that will be discarded should then be freed
587168404Spjd   by calling deflateEnd.  Note that deflateCopy duplicates the internal
588168404Spjd   compression state which can be quite large, so this strategy is slow and
589168404Spjd   can consume lots of memory.
590168404Spjd
591168404Spjd     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
592168404Spjd   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
593168404Spjd   (such as zalloc being NULL). msg is left unchanged in both source and
594168404Spjd   destination.
595168404Spjd*/
596168404Spjd
597168404SpjdZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
598168404Spjd/*
599168404Spjd     This function is equivalent to deflateEnd followed by deflateInit,
600168404Spjd   but does not free and reallocate all the internal compression state.
601168404Spjd   The stream will keep the same compression level and any other attributes
602168404Spjd   that may have been set by deflateInit2.
603168404Spjd
604168404Spjd      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
605168404Spjd   stream state was inconsistent (such as zalloc or state being NULL).
606168404Spjd*/
607168404Spjd
608168404SpjdZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
609168404Spjd                                      int level,
610168404Spjd                                      int strategy));
611168404Spjd/*
612168404Spjd     Dynamically update the compression level and compression strategy.  The
613168404Spjd   interpretation of level and strategy is as in deflateInit2.  This can be
614168404Spjd   used to switch between compression and straight copy of the input data, or
615168404Spjd   to switch to a different kind of input data requiring a different
616168404Spjd   strategy. If the compression level is changed, the input available so far
617168404Spjd   is compressed with the old level (and may be flushed); the new level will
618168404Spjd   take effect only at the next call of deflate().
619168404Spjd
620168404Spjd     Before the call of deflateParams, the stream state must be set as for
621168404Spjd   a call of deflate(), since the currently available input may have to
622168404Spjd   be compressed and flushed. In particular, strm->avail_out must be non-zero.
623168404Spjd
624168404Spjd     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
625168404Spjd   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
626168404Spjd   if strm->avail_out was zero.
627168404Spjd*/
628168404Spjd
629168404SpjdZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
630168404Spjd                                    int good_length,
631168404Spjd                                    int max_lazy,
632168404Spjd                                    int nice_length,
633168404Spjd                                    int max_chain));
634168404Spjd/*
635168404Spjd     Fine tune deflate's internal compression parameters.  This should only be
636168404Spjd   used by someone who understands the algorithm used by zlib's deflate for
637168404Spjd   searching for the best matching string, and even then only by the most
638168404Spjd   fanatic optimizer trying to squeeze out the last compressed bit for their
639168404Spjd   specific input data.  Read the deflate.c source code for the meaning of the
640168404Spjd   max_lazy, good_length, nice_length, and max_chain parameters.
641168404Spjd
642168404Spjd     deflateTune() can be called after deflateInit() or deflateInit2(), and
643168404Spjd   returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
644168404Spjd */
645168404Spjd
646168404SpjdZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
647168404Spjd                                       uLong sourceLen));
648168404Spjd/*
649168404Spjd     deflateBound() returns an upper bound on the compressed size after
650168404Spjd   deflation of sourceLen bytes.  It must be called after deflateInit()
651168404Spjd   or deflateInit2().  This would be used to allocate an output buffer
652168404Spjd   for deflation in a single pass, and so would be called before deflate().
653168404Spjd*/
654168404Spjd
655168404SpjdZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
656168404Spjd                                     int bits,
657168404Spjd                                     int value));
658168404Spjd/*
659168404Spjd     deflatePrime() inserts bits in the deflate output stream.  The intent
660168404Spjd  is that this function is used to start off the deflate output with the
661168404Spjd  bits leftover from a previous deflate stream when appending to it.  As such,
662168404Spjd  this function can only be used for raw deflate, and must be used before the
663168404Spjd  first deflate() call after a deflateInit2() or deflateReset().  bits must be
664168404Spjd  less than or equal to 16, and that many of the least significant bits of
665168404Spjd  value will be inserted in the output.
666168404Spjd
667168404Spjd      deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
668168404Spjd   stream state was inconsistent.
669168404Spjd*/
670168404Spjd
671168404SpjdZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
672168404Spjd                                         gz_headerp head));
673168404Spjd/*
674168404Spjd      deflateSetHeader() provides gzip header information for when a gzip
675168404Spjd   stream is requested by deflateInit2().  deflateSetHeader() may be called
676168404Spjd   after deflateInit2() or deflateReset() and before the first call of
677168404Spjd   deflate().  The text, time, os, extra field, name, and comment information
678168404Spjd   in the provided gz_header structure are written to the gzip header (xflag is
679168404Spjd   ignored -- the extra flags are set according to the compression level).  The
680168404Spjd   caller must assure that, if not Z_NULL, name and comment are terminated with
681168404Spjd   a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
682168404Spjd   available there.  If hcrc is true, a gzip header crc is included.  Note that
683168404Spjd   the current versions of the command-line version of gzip (up through version
684168404Spjd   1.3.x) do not support header crc's, and will report that it is a "multi-part
685168404Spjd   gzip file" and give up.
686168404Spjd
687168404Spjd      If deflateSetHeader is not used, the default gzip header has text false,
688168404Spjd   the time set to zero, and os set to 255, with no extra, name, or comment
689168404Spjd   fields.  The gzip header is returned to the default state by deflateReset().
690168404Spjd
691168404Spjd      deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
692168404Spjd   stream state was inconsistent.
693168404Spjd*/
694168404Spjd
695168404Spjd/*
696168404SpjdZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
697168404Spjd                                     int  windowBits));
698168404Spjd
699168404Spjd     This is another version of inflateInit with an extra parameter. The
700168404Spjd   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
701168404Spjd   before by the caller.
702168404Spjd
703168404Spjd     The windowBits parameter is the base two logarithm of the maximum window
704168404Spjd   size (the size of the history buffer).  It should be in the range 8..15 for
705168404Spjd   this version of the library. The default value is 15 if inflateInit is used
706168404Spjd   instead. windowBits must be greater than or equal to the windowBits value
707168404Spjd   provided to deflateInit2() while compressing, or it must be equal to 15 if
708168404Spjd   deflateInit2() was not used. If a compressed stream with a larger window
709168404Spjd   size is given as input, inflate() will return with the error code
710168404Spjd   Z_DATA_ERROR instead of trying to allocate a larger window.
711168404Spjd
712168404Spjd     windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
713168404Spjd   determines the window size. inflate() will then process raw deflate data,
714168404Spjd   not looking for a zlib or gzip header, not generating a check value, and not
715168404Spjd   looking for any check values for comparison at the end of the stream. This
716168404Spjd   is for use with other formats that use the deflate compressed data format
717168404Spjd   such as zip.  Those formats provide their own check values. If a custom
718168404Spjd   format is developed using the raw deflate format for compressed data, it is
719168404Spjd   recommended that a check value such as an adler32 or a crc32 be applied to
720168404Spjd   the uncompressed data as is done in the zlib, gzip, and zip formats.  For
721168404Spjd   most applications, the zlib format should be used as is. Note that comments
722168404Spjd   above on the use in deflateInit2() applies to the magnitude of windowBits.
723168404Spjd
724168404Spjd     windowBits can also be greater than 15 for optional gzip decoding. Add
725168404Spjd   32 to windowBits to enable zlib and gzip decoding with automatic header
726168404Spjd   detection, or add 16 to decode only the gzip format (the zlib format will
727168404Spjd   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is
728168404Spjd   a crc32 instead of an adler32.
729168404Spjd
730168404Spjd     inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
731168404Spjd   memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
732168404Spjd   is set to null if there is no error message.  inflateInit2 does not perform
733168404Spjd   any decompression apart from reading the zlib header if present: this will
734168404Spjd   be done by inflate(). (So next_in and avail_in may be modified, but next_out
735168404Spjd   and avail_out are unchanged.)
736168404Spjd*/
737168404Spjd
738168404SpjdZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
739168404Spjd                                             const Bytef *dictionary,
740168404Spjd                                             uInt  dictLength));
741168404Spjd/*
742168404Spjd     Initializes the decompression dictionary from the given uncompressed byte
743168404Spjd   sequence. This function must be called immediately after a call of inflate,
744168404Spjd   if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
745168404Spjd   can be determined from the adler32 value returned by that call of inflate.
746168404Spjd   The compressor and decompressor must use exactly the same dictionary (see
747168404Spjd   deflateSetDictionary).  For raw inflate, this function can be called
748168404Spjd   immediately after inflateInit2() or inflateReset() and before any call of
749168404Spjd   inflate() to set the dictionary.  The application must insure that the
750168404Spjd   dictionary that was used for compression is provided.
751168404Spjd
752168404Spjd     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
753168404Spjd   parameter is invalid (such as NULL dictionary) or the stream state is
754168404Spjd   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
755168404Spjd   expected one (incorrect adler32 value). inflateSetDictionary does not
756168404Spjd   perform any decompression: this will be done by subsequent calls of
757168404Spjd   inflate().
758168404Spjd*/
759168404Spjd
760168404SpjdZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
761168404Spjd/*
762168404Spjd    Skips invalid compressed data until a full flush point (see above the
763168404Spjd  description of deflate with Z_FULL_FLUSH) can be found, or until all
764168404Spjd  available input is skipped. No output is provided.
765168404Spjd
766168404Spjd    inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
767168404Spjd  if no more input was provided, Z_DATA_ERROR if no flush point has been found,
768168404Spjd  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
769168404Spjd  case, the application may save the current current value of total_in which
770168404Spjd  indicates where valid compressed data was found. In the error case, the
771168404Spjd  application may repeatedly call inflateSync, providing more input each time,
772168404Spjd  until success or end of the input data.
773168404Spjd*/
774168404Spjd
775168404SpjdZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
776168404Spjd                                    z_streamp source));
777168404Spjd/*
778168404Spjd     Sets the destination stream as a complete copy of the source stream.
779168404Spjd
780168404Spjd     This function can be useful when randomly accessing a large stream.  The
781168404Spjd   first pass through the stream can periodically record the inflate state,
782168404Spjd   allowing restarting inflate at those points when randomly accessing the
783168404Spjd   stream.
784168404Spjd
785168404Spjd     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
786168404Spjd   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
787168404Spjd   (such as zalloc being NULL). msg is left unchanged in both source and
788168404Spjd   destination.
789168404Spjd*/
790168404Spjd
791168404SpjdZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
792168404Spjd/*
793168404Spjd     This function is equivalent to inflateEnd followed by inflateInit,
794168404Spjd   but does not free and reallocate all the internal decompression state.
795168404Spjd   The stream will keep attributes that may have been set by inflateInit2.
796168404Spjd
797168404Spjd      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
798168404Spjd   stream state was inconsistent (such as zalloc or state being NULL).
799168404Spjd*/
800168404Spjd
801168404SpjdZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
802168404Spjd                                     int bits,
803168404Spjd                                     int value));
804168404Spjd/*
805168404Spjd     This function inserts bits in the inflate input stream.  The intent is
806168404Spjd  that this function is used to start inflating at a bit position in the
807168404Spjd  middle of a byte.  The provided bits will be used before any bytes are used
808168404Spjd  from next_in.  This function should only be used with raw inflate, and
809168404Spjd  should be used before the first inflate() call after inflateInit2() or
810168404Spjd  inflateReset().  bits must be less than or equal to 16, and that many of the
811168404Spjd  least significant bits of value will be inserted in the input.
812168404Spjd
813168404Spjd      inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
814168404Spjd   stream state was inconsistent.
815168404Spjd*/
816168404Spjd
817168404SpjdZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
818168404Spjd                                         gz_headerp head));
819168404Spjd/*
820168404Spjd      inflateGetHeader() requests that gzip header information be stored in the
821168404Spjd   provided gz_header structure.  inflateGetHeader() may be called after
822168404Spjd   inflateInit2() or inflateReset(), and before the first call of inflate().
823168404Spjd   As inflate() processes the gzip stream, head->done is zero until the header
824168404Spjd   is completed, at which time head->done is set to one.  If a zlib stream is
825168404Spjd   being decoded, then head->done is set to -1 to indicate that there will be
826168404Spjd   no gzip header information forthcoming.  Note that Z_BLOCK can be used to
827168404Spjd   force inflate() to return immediately after header processing is complete
828168404Spjd   and before any actual data is decompressed.
829168404Spjd
830168404Spjd      The text, time, xflags, and os fields are filled in with the gzip header
831168404Spjd   contents.  hcrc is set to true if there is a header CRC.  (The header CRC
832168404Spjd   was valid if done is set to one.)  If extra is not Z_NULL, then extra_max
833168404Spjd   contains the maximum number of bytes to write to extra.  Once done is true,
834168404Spjd   extra_len contains the actual extra field length, and extra contains the
835168404Spjd   extra field, or that field truncated if extra_max is less than extra_len.
836168404Spjd   If name is not Z_NULL, then up to name_max characters are written there,
837168404Spjd   terminated with a zero unless the length is greater than name_max.  If
838168404Spjd   comment is not Z_NULL, then up to comm_max characters are written there,
839168404Spjd   terminated with a zero unless the length is greater than comm_max.  When
840168404Spjd   any of extra, name, or comment are not Z_NULL and the respective field is
841168404Spjd   not present in the header, then that field is set to Z_NULL to signal its
842168404Spjd   absence.  This allows the use of deflateSetHeader() with the returned
843168404Spjd   structure to duplicate the header.  However if those fields are set to
844168404Spjd   allocated memory, then the application will need to save those pointers
845168404Spjd   elsewhere so that they can be eventually freed.
846168404Spjd
847168404Spjd      If inflateGetHeader is not used, then the header information is simply
848168404Spjd   discarded.  The header is always checked for validity, including the header
849168404Spjd   CRC if present.  inflateReset() will reset the process to discard the header
850168404Spjd   information.  The application would need to call inflateGetHeader() again to
851168404Spjd   retrieve the header from the next gzip stream.
852168404Spjd
853168404Spjd      inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
854168404Spjd   stream state was inconsistent.
855168404Spjd*/
856168404Spjd
857168404Spjd/*
858168404SpjdZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
859168404Spjd                                        unsigned char FAR *window));
860168404Spjd
861168404Spjd     Initialize the internal stream state for decompression using inflateBack()
862168404Spjd   calls.  The fields zalloc, zfree and opaque in strm must be initialized
863168404Spjd   before the call.  If zalloc and zfree are Z_NULL, then the default library-
864168404Spjd   derived memory allocation routines are used.  windowBits is the base two
865168404Spjd   logarithm of the window size, in the range 8..15.  window is a caller
866168404Spjd   supplied buffer of that size.  Except for special applications where it is
867168404Spjd   assured that deflate was used with small window sizes, windowBits must be 15
868168404Spjd   and a 32K byte window must be supplied to be able to decompress general
869168404Spjd   deflate streams.
870168404Spjd
871168404Spjd     See inflateBack() for the usage of these routines.
872168404Spjd
873168404Spjd     inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
874168404Spjd   the paramaters are invalid, Z_MEM_ERROR if the internal state could not
875168404Spjd   be allocated, or Z_VERSION_ERROR if the version of the library does not
876168404Spjd   match the version of the header file.
877168404Spjd*/
878168404Spjd
879168404Spjdtypedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
880168404Spjdtypedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
881168404Spjd
882168404SpjdZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
883168404Spjd                                    in_func in, void FAR *in_desc,
884168404Spjd                                    out_func out, void FAR *out_desc));
885168404Spjd/*
886168404Spjd     inflateBack() does a raw inflate with a single call using a call-back
887168404Spjd   interface for input and output.  This is more efficient than inflate() for
888168404Spjd   file i/o applications in that it avoids copying between the output and the
889168404Spjd   sliding window by simply making the window itself the output buffer.  This
890168404Spjd   function trusts the application to not change the output buffer passed by
891168404Spjd   the output function, at least until inflateBack() returns.
892168404Spjd
893168404Spjd     inflateBackInit() must be called first to allocate the internal state
894168404Spjd   and to initialize the state with the user-provided window buffer.
895168404Spjd   inflateBack() may then be used multiple times to inflate a complete, raw
896168404Spjd   deflate stream with each call.  inflateBackEnd() is then called to free
897168404Spjd   the allocated state.
898168404Spjd
899168404Spjd     A raw deflate stream is one with no zlib or gzip header or trailer.
900168404Spjd   This routine would normally be used in a utility that reads zip or gzip
901168404Spjd   files and writes out uncompressed files.  The utility would decode the
902168404Spjd   header and process the trailer on its own, hence this routine expects
903168404Spjd   only the raw deflate stream to decompress.  This is different from the
904168404Spjd   normal behavior of inflate(), which expects either a zlib or gzip header and
905168404Spjd   trailer around the deflate stream.
906168404Spjd
907168404Spjd     inflateBack() uses two subroutines supplied by the caller that are then
908168404Spjd   called by inflateBack() for input and output.  inflateBack() calls those
909168404Spjd   routines until it reads a complete deflate stream and writes out all of the
910168404Spjd   uncompressed data, or until it encounters an error.  The function's
911168404Spjd   parameters and return types are defined above in the in_func and out_func
912168404Spjd   typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
913168404Spjd   number of bytes of provided input, and a pointer to that input in buf.  If
914168404Spjd   there is no input available, in() must return zero--buf is ignored in that
915168404Spjd   case--and inflateBack() will return a buffer error.  inflateBack() will call
916168404Spjd   out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()
917168404Spjd   should return zero on success, or non-zero on failure.  If out() returns
918168404Spjd   non-zero, inflateBack() will return with an error.  Neither in() nor out()
919168404Spjd   are permitted to change the contents of the window provided to
920168404Spjd   inflateBackInit(), which is also the buffer that out() uses to write from.
921168404Spjd   The length written by out() will be at most the window size.  Any non-zero
922168404Spjd   amount of input may be provided by in().
923168404Spjd
924168404Spjd     For convenience, inflateBack() can be provided input on the first call by
925168404Spjd   setting strm->next_in and strm->avail_in.  If that input is exhausted, then
926168404Spjd   in() will be called.  Therefore strm->next_in must be initialized before
927168404Spjd   calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called
928168404Spjd   immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
929168404Spjd   must also be initialized, and then if strm->avail_in is not zero, input will
930168404Spjd   initially be taken from strm->next_in[0 .. strm->avail_in - 1].
931168404Spjd
932168404Spjd     The in_desc and out_desc parameters of inflateBack() is passed as the
933168404Spjd   first parameter of in() and out() respectively when they are called.  These
934168404Spjd   descriptors can be optionally used to pass any information that the caller-
935168404Spjd   supplied in() and out() functions need to do their job.
936168404Spjd
937168404Spjd     On return, inflateBack() will set strm->next_in and strm->avail_in to
938168404Spjd   pass back any unused input that was provided by the last in() call.  The
939168404Spjd   return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
940168404Spjd   if in() or out() returned an error, Z_DATA_ERROR if there was a format
941168404Spjd   error in the deflate stream (in which case strm->msg is set to indicate the
942168404Spjd   nature of the error), or Z_STREAM_ERROR if the stream was not properly
943168404Spjd   initialized.  In the case of Z_BUF_ERROR, an input or output error can be
944168404Spjd   distinguished using strm->next_in which will be Z_NULL only if in() returned
945168404Spjd   an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
946168404Spjd   out() returning non-zero.  (in() will always be called before out(), so
947168404Spjd   strm->next_in is assured to be defined if out() returns non-zero.)  Note
948168404Spjd   that inflateBack() cannot return Z_OK.
949168404Spjd*/
950168404Spjd
951168404SpjdZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
952168404Spjd/*
953168404Spjd     All memory allocated by inflateBackInit() is freed.
954168404Spjd
955168404Spjd     inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
956168404Spjd   state was inconsistent.
957168404Spjd*/
958168404Spjd
959168404SpjdZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
960168404Spjd/* Return flags indicating compile-time options.
961168404Spjd
962168404Spjd    Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
963168404Spjd     1.0: size of uInt
964168404Spjd     3.2: size of uLong
965168404Spjd     5.4: size of voidpf (pointer)
966168404Spjd     7.6: size of z_off_t
967168404Spjd
968168404Spjd    Compiler, assembler, and debug options:
969168404Spjd     8: DEBUG
970168404Spjd     9: ASMV or ASMINF -- use ASM code
971168404Spjd     10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
972168404Spjd     11: 0 (reserved)
973168404Spjd
974168404Spjd    One-time table building (smaller code, but not thread-safe if true):
975168404Spjd     12: BUILDFIXED -- build static block decoding tables when needed
976168404Spjd     13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
977168404Spjd     14,15: 0 (reserved)
978168404Spjd
979168404Spjd    Library content (indicates missing functionality):
980168404Spjd     16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
981168404Spjd                          deflate code when not needed)
982168404Spjd     17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
983168404Spjd                    and decode gzip streams (to avoid linking crc code)
984168404Spjd     18-19: 0 (reserved)
985168404Spjd
986168404Spjd    Operation variations (changes in library functionality):
987168404Spjd     20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
988168404Spjd     21: FASTEST -- deflate algorithm with only one, lowest compression level
989168404Spjd     22,23: 0 (reserved)
990168404Spjd
991168404Spjd    The sprintf variant used by gzprintf (zero is best):
992168404Spjd     24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
993168404Spjd     25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
994168404Spjd     26: 0 = returns value, 1 = void -- 1 means inferred string length returned
995168404Spjd
996168404Spjd    Remainder:
997168404Spjd     27-31: 0 (reserved)
998168404Spjd */
999168404Spjd
1000168404Spjd
1001168404Spjd                        /* utility functions */
1002168404Spjd
1003168404Spjd/*
1004168404Spjd     The following utility functions are implemented on top of the
1005168404Spjd   basic stream-oriented functions. To simplify the interface, some
1006168404Spjd   default options are assumed (compression level and memory usage,
1007168404Spjd   standard memory allocation functions). The source code of these
1008168404Spjd   utility functions can easily be modified if you need special options.
1009168404Spjd*/
1010168404Spjd
1011168404SpjdZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
1012168404Spjd                                 const Bytef *source, uLong sourceLen));
1013168404Spjd/*
1014168404Spjd     Compresses the source buffer into the destination buffer.  sourceLen is
1015168404Spjd   the byte length of the source buffer. Upon entry, destLen is the total
1016168404Spjd   size of the destination buffer, which must be at least the value returned
1017168404Spjd   by compressBound(sourceLen). Upon exit, destLen is the actual size of the
1018168404Spjd   compressed buffer.
1019168404Spjd     This function can be used to compress a whole file at once if the
1020168404Spjd   input file is mmap'ed.
1021168404Spjd     compress returns Z_OK if success, Z_MEM_ERROR if there was not
1022168404Spjd   enough memory, Z_BUF_ERROR if there was not enough room in the output
1023168404Spjd   buffer.
1024168404Spjd*/
1025168404Spjd
1026168404SpjdZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
1027168404Spjd                                  const Bytef *source, uLong sourceLen,
1028168404Spjd                                  int level));
1029168404Spjd/*
1030168404Spjd     Compresses the source buffer into the destination buffer. The level
1031168404Spjd   parameter has the same meaning as in deflateInit.  sourceLen is the byte
1032168404Spjd   length of the source buffer. Upon entry, destLen is the total size of the
1033168404Spjd   destination buffer, which must be at least the value returned by
1034168404Spjd   compressBound(sourceLen). Upon exit, destLen is the actual size of the
1035168404Spjd   compressed buffer.
1036168404Spjd
1037168404Spjd     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1038168404Spjd   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1039168404Spjd   Z_STREAM_ERROR if the level parameter is invalid.
1040168404Spjd*/
1041168404Spjd
1042168404SpjdZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1043168404Spjd/*
1044168404Spjd     compressBound() returns an upper bound on the compressed size after
1045168404Spjd   compress() or compress2() on sourceLen bytes.  It would be used before
1046168404Spjd   a compress() or compress2() call to allocate the destination buffer.
1047168404Spjd*/
1048168404Spjd
1049168404SpjdZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
1050168404Spjd                                   const Bytef *source, uLong sourceLen));
1051168404Spjd/*
1052168404Spjd     Decompresses the source buffer into the destination buffer.  sourceLen is
1053168404Spjd   the byte length of the source buffer. Upon entry, destLen is the total
1054168404Spjd   size of the destination buffer, which must be large enough to hold the
1055168404Spjd   entire uncompressed data. (The size of the uncompressed data must have
1056168404Spjd   been saved previously by the compressor and transmitted to the decompressor
1057168404Spjd   by some mechanism outside the scope of this compression library.)
1058168404Spjd   Upon exit, destLen is the actual size of the compressed buffer.
1059168404Spjd     This function can be used to decompress a whole file at once if the
1060168404Spjd   input file is mmap'ed.
1061168404Spjd
1062168404Spjd     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1063168404Spjd   enough memory, Z_BUF_ERROR if there was not enough room in the output
1064168404Spjd   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
1065168404Spjd*/
1066168404Spjd
1067168404Spjd
1068168404Spjdtypedef voidp gzFile;
1069168404Spjd
1070168404SpjdZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
1071168404Spjd/*
1072168404Spjd     Opens a gzip (.gz) file for reading or writing. The mode parameter
1073168404Spjd   is as in fopen ("rb" or "wb") but can also include a compression level
1074168404Spjd   ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
1075168404Spjd   Huffman only compression as in "wb1h", or 'R' for run-length encoding
1076168404Spjd   as in "wb1R". (See the description of deflateInit2 for more information
1077168404Spjd   about the strategy parameter.)
1078168404Spjd
1079168404Spjd     gzopen can be used to read a file which is not in gzip format; in this
1080168404Spjd   case gzread will directly read from the file without decompression.
1081168404Spjd
1082168404Spjd     gzopen returns NULL if the file could not be opened or if there was
1083168404Spjd   insufficient memory to allocate the (de)compression state; errno
1084168404Spjd   can be checked to distinguish the two cases (if errno is zero, the
1085168404Spjd   zlib error is Z_MEM_ERROR).  */
1086168404Spjd
1087168404SpjdZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
1088168404Spjd/*
1089168404Spjd     gzdopen() associates a gzFile with the file descriptor fd.  File
1090168404Spjd   descriptors are obtained from calls like open, dup, creat, pipe or
1091168404Spjd   fileno (in the file has been previously opened with fopen).
1092168404Spjd   The mode parameter is as in gzopen.
1093168404Spjd     The next call of gzclose on the returned gzFile will also close the
1094168404Spjd   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
1095168404Spjd   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
1096168404Spjd     gzdopen returns NULL if there was insufficient memory to allocate
1097168404Spjd   the (de)compression state.
1098168404Spjd*/
1099168404Spjd
1100168404SpjdZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1101168404Spjd/*
1102168404Spjd     Dynamically update the compression level or strategy. See the description
1103168404Spjd   of deflateInit2 for the meaning of these parameters.
1104168404Spjd     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1105168404Spjd   opened for writing.
1106168404Spjd*/
1107168404Spjd
1108168404SpjdZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
1109168404Spjd/*
1110168404Spjd     Reads the given number of uncompressed bytes from the compressed file.
1111168404Spjd   If the input file was not in gzip format, gzread copies the given number
1112168404Spjd   of bytes into the buffer.
1113168404Spjd     gzread returns the number of uncompressed bytes actually read (0 for
1114168404Spjd   end of file, -1 for error). */
1115168404Spjd
1116168404SpjdZEXTERN int ZEXPORT    gzwrite OF((gzFile file,
1117168404Spjd                                   voidpc buf, unsigned len));
1118168404Spjd/*
1119168404Spjd     Writes the given number of uncompressed bytes into the compressed file.
1120168404Spjd   gzwrite returns the number of uncompressed bytes actually written
1121168404Spjd   (0 in case of error).
1122168404Spjd*/
1123168404Spjd
1124168404SpjdZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
1125168404Spjd/*
1126168404Spjd     Converts, formats, and writes the args to the compressed file under
1127168404Spjd   control of the format string, as in fprintf. gzprintf returns the number of
1128168404Spjd   uncompressed bytes actually written (0 in case of error).  The number of
1129168404Spjd   uncompressed bytes written is limited to 4095. The caller should assure that
1130168404Spjd   this limit is not exceeded. If it is exceeded, then gzprintf() will return
1131168404Spjd   return an error (0) with nothing written. In this case, there may also be a
1132168404Spjd   buffer overflow with unpredictable consequences, which is possible only if
1133168404Spjd   zlib was compiled with the insecure functions sprintf() or vsprintf()
1134168404Spjd   because the secure snprintf() or vsnprintf() functions were not available.
1135168404Spjd*/
1136168404Spjd
1137168404SpjdZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1138168404Spjd/*
1139168404Spjd      Writes the given null-terminated string to the compressed file, excluding
1140168404Spjd   the terminating null character.
1141168404Spjd      gzputs returns the number of characters written, or -1 in case of error.
1142168404Spjd*/
1143168404Spjd
1144168404SpjdZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1145168404Spjd/*
1146168404Spjd      Reads bytes from the compressed file until len-1 characters are read, or
1147168404Spjd   a newline character is read and transferred to buf, or an end-of-file
1148168404Spjd   condition is encountered.  The string is then terminated with a null
1149168404Spjd   character.
1150168404Spjd      gzgets returns buf, or Z_NULL in case of error.
1151168404Spjd*/
1152168404Spjd
1153168404SpjdZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
1154168404Spjd/*
1155168404Spjd      Writes c, converted to an unsigned char, into the compressed file.
1156168404Spjd   gzputc returns the value that was written, or -1 in case of error.
1157168404Spjd*/
1158168404Spjd
1159168404SpjdZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
1160168404Spjd/*
1161168404Spjd      Reads one byte from the compressed file. gzgetc returns this byte
1162168404Spjd   or -1 in case of end of file or error.
1163168404Spjd*/
1164168404Spjd
1165168404SpjdZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));
1166168404Spjd/*
1167168404Spjd      Push one character back onto the stream to be read again later.
1168168404Spjd   Only one character of push-back is allowed.  gzungetc() returns the
1169168404Spjd   character pushed, or -1 on failure.  gzungetc() will fail if a
1170168404Spjd   character has been pushed but not read yet, or if c is -1. The pushed
1171168404Spjd   character will be discarded if the stream is repositioned with gzseek()
1172168404Spjd   or gzrewind().
1173168404Spjd*/
1174168404Spjd
1175168404SpjdZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
1176168404Spjd/*
1177168404Spjd     Flushes all pending output into the compressed file. The parameter
1178168404Spjd   flush is as in the deflate() function. The return value is the zlib
1179168404Spjd   error number (see function gzerror below). gzflush returns Z_OK if
1180168404Spjd   the flush parameter is Z_FINISH and all output could be flushed.
1181168404Spjd     gzflush should be called only when strictly necessary because it can
1182168404Spjd   degrade compression.
1183168404Spjd*/
1184168404Spjd
1185168404SpjdZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
1186168404Spjd                                      z_off_t offset, int whence));
1187168404Spjd/*
1188168404Spjd      Sets the starting position for the next gzread or gzwrite on the
1189168404Spjd   given compressed file. The offset represents a number of bytes in the
1190168404Spjd   uncompressed data stream. The whence parameter is defined as in lseek(2);
1191168404Spjd   the value SEEK_END is not supported.
1192168404Spjd     If the file is opened for reading, this function is emulated but can be
1193168404Spjd   extremely slow. If the file is opened for writing, only forward seeks are
1194168404Spjd   supported; gzseek then compresses a sequence of zeroes up to the new
1195168404Spjd   starting position.
1196168404Spjd
1197168404Spjd      gzseek returns the resulting offset location as measured in bytes from
1198168404Spjd   the beginning of the uncompressed stream, or -1 in case of error, in
1199168404Spjd   particular if the file is opened for writing and the new starting position
1200168404Spjd   would be before the current position.
1201168404Spjd*/
1202168404Spjd
1203168404SpjdZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
1204168404Spjd/*
1205168404Spjd     Rewinds the given file. This function is supported only for reading.
1206168404Spjd
1207168404Spjd   gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1208168404Spjd*/
1209168404Spjd
1210168404SpjdZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
1211168404Spjd/*
1212168404Spjd     Returns the starting position for the next gzread or gzwrite on the
1213168404Spjd   given compressed file. This position represents a number of bytes in the
1214168404Spjd   uncompressed data stream.
1215168404Spjd
1216168404Spjd   gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1217168404Spjd*/
1218168404Spjd
1219168404SpjdZEXTERN int ZEXPORT gzeof OF((gzFile file));
1220168404Spjd/*
1221168404Spjd     Returns 1 when EOF has previously been detected reading the given
1222168404Spjd   input stream, otherwise zero.
1223168404Spjd*/
1224168404Spjd
1225168404SpjdZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1226168404Spjd/*
1227168404Spjd     Returns 1 if file is being read directly without decompression, otherwise
1228168404Spjd   zero.
1229168404Spjd*/
1230168404Spjd
1231168404SpjdZEXTERN int ZEXPORT    gzclose OF((gzFile file));
1232168404Spjd/*
1233168404Spjd     Flushes all pending output if necessary, closes the compressed file
1234168404Spjd   and deallocates all the (de)compression state. The return value is the zlib
1235168404Spjd   error number (see function gzerror below).
1236168404Spjd*/
1237168404Spjd
1238168404SpjdZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1239168404Spjd/*
1240168404Spjd     Returns the error message for the last error which occurred on the
1241168404Spjd   given compressed file. errnum is set to zlib error number. If an
1242168404Spjd   error occurred in the file system and not in the compression library,
1243168404Spjd   errnum is set to Z_ERRNO and the application may consult errno
1244168404Spjd   to get the exact error code.
1245168404Spjd*/
1246168404Spjd
1247168404SpjdZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1248168404Spjd/*
1249168404Spjd     Clears the error and end-of-file flags for file. This is analogous to the
1250168404Spjd   clearerr() function in stdio. This is useful for continuing to read a gzip
1251168404Spjd   file that is being written concurrently.
1252168404Spjd*/
1253168404Spjd
1254168404Spjd                        /* checksum functions */
1255168404Spjd
1256168404Spjd/*
1257168404Spjd     These functions are not related to compression but are exported
1258168404Spjd   anyway because they might be useful in applications using the
1259168404Spjd   compression library.
1260168404Spjd*/
1261168404Spjd
1262168404SpjdZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1263168404Spjd/*
1264168404Spjd     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1265168404Spjd   return the updated checksum. If buf is NULL, this function returns
1266168404Spjd   the required initial value for the checksum.
1267168404Spjd   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1268168404Spjd   much faster. Usage example:
1269168404Spjd
1270168404Spjd     uLong adler = adler32(0L, Z_NULL, 0);
1271168404Spjd
1272168404Spjd     while (read_buffer(buffer, length) != EOF) {
1273168404Spjd       adler = adler32(adler, buffer, length);
1274168404Spjd     }
1275168404Spjd     if (adler != original_adler) error();
1276168404Spjd*/
1277168404Spjd
1278168404SpjdZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1279168404Spjd                                          z_off_t len2));
1280168404Spjd/*
1281168404Spjd     Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
1282168404Spjd   and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1283168404Spjd   each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
1284168404Spjd   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
1285168404Spjd*/
1286168404Spjd
1287168404SpjdZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
1288168404Spjd/*
1289168404Spjd     Update a running CRC-32 with the bytes buf[0..len-1] and return the
1290168404Spjd   updated CRC-32. If buf is NULL, this function returns the required initial
1291168404Spjd   value for the for the crc. Pre- and post-conditioning (one's complement) is
1292168404Spjd   performed within this function so it shouldn't be done by the application.
1293168404Spjd   Usage example:
1294168404Spjd
1295168404Spjd     uLong crc = crc32(0L, Z_NULL, 0);
1296168404Spjd
1297168404Spjd     while (read_buffer(buffer, length) != EOF) {
1298168404Spjd       crc = crc32(crc, buffer, length);
1299168404Spjd     }
1300168404Spjd     if (crc != original_crc) error();
1301168404Spjd*/
1302168404Spjd
1303168404SpjdZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1304168404Spjd
1305168404Spjd/*
1306168404Spjd     Combine two CRC-32 check values into one.  For two sequences of bytes,
1307168404Spjd   seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1308168404Spjd   calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32
1309168404Spjd   check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1310168404Spjd   len2.
1311168404Spjd*/
1312168404Spjd
1313168404Spjd
1314168404Spjd                        /* various hacks, don't look :) */
1315168404Spjd
1316168404Spjd/* deflateInit and inflateInit are macros to allow checking the zlib version
1317168404Spjd * and the compiler's view of z_stream:
1318168404Spjd */
1319168404SpjdZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1320168404Spjd                                     const char *version, int stream_size));
1321168404SpjdZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1322168404Spjd                                     const char *version, int stream_size));
1323168404SpjdZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
1324168404Spjd                                      int windowBits, int memLevel,
1325168404Spjd                                      int strategy, const char *version,
1326168404Spjd                                      int stream_size));
1327168404SpjdZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
1328168404Spjd                                      const char *version, int stream_size));
1329168404SpjdZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1330168404Spjd                                         unsigned char FAR *window,
1331168404Spjd                                         const char *version,
1332168404Spjd                                         int stream_size));
1333168404Spjd#define deflateInit(strm, level) \
1334168404Spjd        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
1335168404Spjd#define inflateInit(strm) \
1336168404Spjd        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
1337168404Spjd#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1338168404Spjd        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1339168404Spjd                      (strategy),           ZLIB_VERSION, sizeof(z_stream))
1340168404Spjd#define inflateInit2(strm, windowBits) \
1341168404Spjd        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1342168404Spjd#define inflateBackInit(strm, windowBits, window) \
1343168404Spjd        inflateBackInit_((strm), (windowBits), (window), \
1344168404Spjd        ZLIB_VERSION, sizeof(z_stream))
1345168404Spjd
1346168404Spjd
1347168404Spjd#if !defined(_ZUTIL_H) && !defined(NO_DUMMY_DECL)
1348168404Spjd    struct internal_state {int dummy;}; /* hack for buggy compilers */
1349168404Spjd#endif
1350168404Spjd
1351168404SpjdZEXTERN const char   * ZEXPORT zError           OF((int));
1352168404SpjdZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
1353168404SpjdZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
1354168404Spjd
1355168404Spjd#ifdef __cplusplus
1356168404Spjd}
1357168404Spjd#endif
1358168404Spjd
1359168404Spjd#endif /* _ZLIB_H */
1360