xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.bin/pppdump/zlib.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*	$Id: zlib.h,v 1.1 1999/03/23 03:21:58 paulus Exp $	*/
2*0Sstevel@tonic-gate 
3*0Sstevel@tonic-gate /*
4*0Sstevel@tonic-gate  * This file is derived from zlib.h and zconf.h from the zlib-0.95
5*0Sstevel@tonic-gate  * distribution by Jean-loup Gailly and Mark Adler, with some additions
6*0Sstevel@tonic-gate  * by Paul Mackerras to aid in implementing Deflate compression and
7*0Sstevel@tonic-gate  * decompression for PPP packets.
8*0Sstevel@tonic-gate  */
9*0Sstevel@tonic-gate 
10*0Sstevel@tonic-gate /* zlib.h -- interface of the 'zlib' general purpose compression library
11*0Sstevel@tonic-gate   version 0.95, Aug 16th, 1995.
12*0Sstevel@tonic-gate 
13*0Sstevel@tonic-gate   Copyright (C) 1995 Jean-loup Gailly and Mark Adler
14*0Sstevel@tonic-gate 
15*0Sstevel@tonic-gate   This software is provided 'as-is', without any express or implied
16*0Sstevel@tonic-gate   warranty.  In no event will the authors be held liable for any damages
17*0Sstevel@tonic-gate   arising from the use of this software.
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate   Permission is granted to anyone to use this software for any purpose,
20*0Sstevel@tonic-gate   including commercial applications, and to alter it and redistribute it
21*0Sstevel@tonic-gate   freely, subject to the following restrictions:
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate   1. The origin of this software must not be misrepresented; you must not
24*0Sstevel@tonic-gate      claim that you wrote the original software. If you use this software
25*0Sstevel@tonic-gate      in a product, an acknowledgment in the product documentation would be
26*0Sstevel@tonic-gate      appreciated but is not required.
27*0Sstevel@tonic-gate   2. Altered source versions must be plainly marked as such, and must not be
28*0Sstevel@tonic-gate      misrepresented as being the original software.
29*0Sstevel@tonic-gate   3. This notice may not be removed or altered from any source distribution.
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate   Jean-loup Gailly        Mark Adler
32*0Sstevel@tonic-gate   gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
33*0Sstevel@tonic-gate  */
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #ifndef _ZLIB_H
36*0Sstevel@tonic-gate #define _ZLIB_H
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /* #include "zconf.h" */	/* included directly here */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate /* zconf.h -- configuration of the zlib compression library
41*0Sstevel@tonic-gate  * Copyright (C) 1995 Jean-loup Gailly.
42*0Sstevel@tonic-gate  * For conditions of distribution and use, see copyright notice in zlib.h
43*0Sstevel@tonic-gate  */
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate /* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /*
48*0Sstevel@tonic-gate      The library does not install any signal handler. It is recommended to
49*0Sstevel@tonic-gate   add at least a handler for SIGSEGV when decompressing; the library checks
50*0Sstevel@tonic-gate   the consistency of the input data whenever possible but may go nuts
51*0Sstevel@tonic-gate   for some forms of corrupted input.
52*0Sstevel@tonic-gate  */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate  * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
56*0Sstevel@tonic-gate  * than 64k bytes at a time (needed on systems with 16-bit int).
57*0Sstevel@tonic-gate  * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
58*0Sstevel@tonic-gate  * at addresses which are not a multiple of their size.
59*0Sstevel@tonic-gate  * Under DOS, -DFAR=far or -DFAR=__far may be needed.
60*0Sstevel@tonic-gate  */
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate #ifndef STDC
63*0Sstevel@tonic-gate #  if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
64*0Sstevel@tonic-gate #    define STDC
65*0Sstevel@tonic-gate #  endif
66*0Sstevel@tonic-gate #endif
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate #ifdef	__MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
69*0Sstevel@tonic-gate #  include <unix.h>
70*0Sstevel@tonic-gate #endif
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate /* Maximum value for memLevel in deflateInit2 */
73*0Sstevel@tonic-gate #ifndef MAX_MEM_LEVEL
74*0Sstevel@tonic-gate #  ifdef MAXSEG_64K
75*0Sstevel@tonic-gate #    define MAX_MEM_LEVEL 8
76*0Sstevel@tonic-gate #  else
77*0Sstevel@tonic-gate #    define MAX_MEM_LEVEL 9
78*0Sstevel@tonic-gate #  endif
79*0Sstevel@tonic-gate #endif
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate #ifndef FAR
82*0Sstevel@tonic-gate #  define FAR
83*0Sstevel@tonic-gate #endif
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /* Maximum value for windowBits in deflateInit2 and inflateInit2 */
86*0Sstevel@tonic-gate #ifndef MAX_WBITS
87*0Sstevel@tonic-gate #  define MAX_WBITS   15 /* 32K LZ77 window */
88*0Sstevel@tonic-gate #endif
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate /* The memory requirements for deflate are (in bytes):
91*0Sstevel@tonic-gate             1 << (windowBits+2)   +  1 << (memLevel+9)
92*0Sstevel@tonic-gate  that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
93*0Sstevel@tonic-gate  plus a few kilobytes for small objects. For example, if you want to reduce
94*0Sstevel@tonic-gate  the default memory requirements from 256K to 128K, compile with
95*0Sstevel@tonic-gate      make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
96*0Sstevel@tonic-gate  Of course this will generally degrade compression (there's no free lunch).
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate    The memory requirements for inflate are (in bytes) 1 << windowBits
99*0Sstevel@tonic-gate  that is, 32K for windowBits=15 (default value) plus a few kilobytes
100*0Sstevel@tonic-gate  for small objects.
101*0Sstevel@tonic-gate */
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate                         /* Type declarations */
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate #ifndef OF /* function prototypes */
106*0Sstevel@tonic-gate #  ifdef STDC
107*0Sstevel@tonic-gate #    define OF(args)  args
108*0Sstevel@tonic-gate #  else
109*0Sstevel@tonic-gate #    define OF(args)  ()
110*0Sstevel@tonic-gate #  endif
111*0Sstevel@tonic-gate #endif
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate typedef unsigned char  Byte;  /* 8 bits */
114*0Sstevel@tonic-gate typedef unsigned int   uInt;  /* 16 bits or more */
115*0Sstevel@tonic-gate typedef unsigned long  uLong; /* 32 bits or more */
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate typedef Byte FAR Bytef;
118*0Sstevel@tonic-gate typedef char FAR charf;
119*0Sstevel@tonic-gate typedef int FAR intf;
120*0Sstevel@tonic-gate typedef uInt FAR uIntf;
121*0Sstevel@tonic-gate typedef uLong FAR uLongf;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #ifdef STDC
124*0Sstevel@tonic-gate    typedef void FAR *voidpf;
125*0Sstevel@tonic-gate    typedef void     *voidp;
126*0Sstevel@tonic-gate #else
127*0Sstevel@tonic-gate    typedef Byte FAR *voidpf;
128*0Sstevel@tonic-gate    typedef Byte     *voidp;
129*0Sstevel@tonic-gate #endif
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate /* end of original zconf.h */
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate #define ZLIB_VERSION "0.95P"
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate /*
136*0Sstevel@tonic-gate      The 'zlib' compression library provides in-memory compression and
137*0Sstevel@tonic-gate   decompression functions, including integrity checks of the uncompressed
138*0Sstevel@tonic-gate   data.  This version of the library supports only one compression method
139*0Sstevel@tonic-gate   (deflation) but other algorithms may be added later and will have the same
140*0Sstevel@tonic-gate   stream interface.
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate      For compression the application must provide the output buffer and
143*0Sstevel@tonic-gate   may optionally provide the input buffer for optimization. For decompression,
144*0Sstevel@tonic-gate   the application must provide the input buffer and may optionally provide
145*0Sstevel@tonic-gate   the output buffer for optimization.
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate      Compression can be done in a single step if the buffers are large
148*0Sstevel@tonic-gate   enough (for example if an input file is mmap'ed), or can be done by
149*0Sstevel@tonic-gate   repeated calls of the compression function.  In the latter case, the
150*0Sstevel@tonic-gate   application must provide more input and/or consume the output
151*0Sstevel@tonic-gate   (providing more output space) before each call.
152*0Sstevel@tonic-gate */
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
155*0Sstevel@tonic-gate typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt nbytes));
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate struct internal_state;
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate typedef struct z_stream_s {
160*0Sstevel@tonic-gate     Bytef    *next_in;  /* next input byte */
161*0Sstevel@tonic-gate     uInt     avail_in;  /* number of bytes available at next_in */
162*0Sstevel@tonic-gate     uLong    total_in;  /* total nb of input bytes read so far */
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate     Bytef    *next_out; /* next output byte should be put there */
165*0Sstevel@tonic-gate     uInt     avail_out; /* remaining free space at next_out */
166*0Sstevel@tonic-gate     uLong    total_out; /* total nb of bytes output so far */
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate     char     *msg;      /* last error message, NULL if no error */
169*0Sstevel@tonic-gate     struct internal_state FAR *state; /* not visible by applications */
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate     alloc_func zalloc;  /* used to allocate the internal state */
172*0Sstevel@tonic-gate     free_func  zfree;   /* used to free the internal state */
173*0Sstevel@tonic-gate     voidp      opaque;  /* private data object passed to zalloc and zfree */
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate     Byte     data_type; /* best guess about the data type: ascii or binary */
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate } z_stream;
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate /*
180*0Sstevel@tonic-gate    The application must update next_in and avail_in when avail_in has
181*0Sstevel@tonic-gate    dropped to zero. It must update next_out and avail_out when avail_out
182*0Sstevel@tonic-gate    has dropped to zero. The application must initialize zalloc, zfree and
183*0Sstevel@tonic-gate    opaque before calling the init function. All other fields are set by the
184*0Sstevel@tonic-gate    compression library and must not be updated by the application.
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate    The opaque value provided by the application will be passed as the first
187*0Sstevel@tonic-gate    parameter for calls of zalloc and zfree. This can be useful for custom
188*0Sstevel@tonic-gate    memory management. The compression library attaches no meaning to the
189*0Sstevel@tonic-gate    opaque value.
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate    zalloc must return Z_NULL if there is not enough memory for the object.
192*0Sstevel@tonic-gate    On 16-bit systems, the functions zalloc and zfree must be able to allocate
193*0Sstevel@tonic-gate    exactly 65536 bytes, but will not be required to allocate more than this
194*0Sstevel@tonic-gate    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
195*0Sstevel@tonic-gate    pointers returned by zalloc for objects of exactly 65536 bytes *must*
196*0Sstevel@tonic-gate    have their offset normalized to zero. The default allocation function
197*0Sstevel@tonic-gate    provided by this library ensures this (see zutil.c). To reduce memory
198*0Sstevel@tonic-gate    requirements and avoid any allocation of 64K objects, at the expense of
199*0Sstevel@tonic-gate    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate    The fields total_in and total_out can be used for statistics or
202*0Sstevel@tonic-gate    progress reports. After compression, total_in holds the total size of
203*0Sstevel@tonic-gate    the uncompressed data and may be saved for use in the decompressor
204*0Sstevel@tonic-gate    (particularly if the decompressor wants to decompress everything in
205*0Sstevel@tonic-gate    a single step).
206*0Sstevel@tonic-gate */
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate                         /* constants */
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate #define Z_NO_FLUSH      0
211*0Sstevel@tonic-gate #define Z_PARTIAL_FLUSH 1
212*0Sstevel@tonic-gate #define Z_FULL_FLUSH    2
213*0Sstevel@tonic-gate #define Z_SYNC_FLUSH    3 /* experimental: partial_flush + byte align */
214*0Sstevel@tonic-gate #define Z_FINISH        4
215*0Sstevel@tonic-gate #define Z_PACKET_FLUSH	5
216*0Sstevel@tonic-gate /* See deflate() below for the usage of these constants */
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate #define Z_OK            0
219*0Sstevel@tonic-gate #define Z_STREAM_END    1
220*0Sstevel@tonic-gate #define Z_ERRNO        (-1)
221*0Sstevel@tonic-gate #define Z_STREAM_ERROR (-2)
222*0Sstevel@tonic-gate #define Z_DATA_ERROR   (-3)
223*0Sstevel@tonic-gate #define Z_MEM_ERROR    (-4)
224*0Sstevel@tonic-gate #define Z_BUF_ERROR    (-5)
225*0Sstevel@tonic-gate /* error codes for the compression/decompression functions */
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate #define Z_BEST_SPEED             1
228*0Sstevel@tonic-gate #define Z_BEST_COMPRESSION       9
229*0Sstevel@tonic-gate #define Z_DEFAULT_COMPRESSION  (-1)
230*0Sstevel@tonic-gate /* compression levels */
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate #define Z_FILTERED            1
233*0Sstevel@tonic-gate #define Z_HUFFMAN_ONLY        2
234*0Sstevel@tonic-gate #define Z_DEFAULT_STRATEGY    0
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate #define Z_BINARY   0
237*0Sstevel@tonic-gate #define Z_ASCII    1
238*0Sstevel@tonic-gate #define Z_UNKNOWN  2
239*0Sstevel@tonic-gate /* Used to set the data_type field */
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate extern char *zlib_version;
244*0Sstevel@tonic-gate /* The application can compare zlib_version and ZLIB_VERSION for consistency.
245*0Sstevel@tonic-gate    If the first character differs, the library code actually used is
246*0Sstevel@tonic-gate    not compatible with the zlib.h header file used by the application.
247*0Sstevel@tonic-gate  */
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate                         /* basic functions */
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate extern int deflateInit OF((z_stream *strm, int level));
252*0Sstevel@tonic-gate /*
253*0Sstevel@tonic-gate      Initializes the internal stream state for compression. The fields
254*0Sstevel@tonic-gate    zalloc, zfree and opaque must be initialized before by the caller.
255*0Sstevel@tonic-gate    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
256*0Sstevel@tonic-gate    use default allocation functions.
257*0Sstevel@tonic-gate 
258*0Sstevel@tonic-gate      The compression level must be Z_DEFAULT_COMPRESSION, or between 1 and 9:
259*0Sstevel@tonic-gate    1 gives best speed, 9 gives best compression. Z_DEFAULT_COMPRESSION requests
260*0Sstevel@tonic-gate    a default compromise between speed and compression (currently equivalent
261*0Sstevel@tonic-gate    to level 6).
262*0Sstevel@tonic-gate 
263*0Sstevel@tonic-gate      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
264*0Sstevel@tonic-gate    enough memory, Z_STREAM_ERROR if level is not a valid compression level.
265*0Sstevel@tonic-gate    msg is set to null if there is no error message.  deflateInit does not
266*0Sstevel@tonic-gate    perform any compression: this will be done by deflate().
267*0Sstevel@tonic-gate */
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 
270*0Sstevel@tonic-gate extern int deflate OF((z_stream *strm, int flush));
271*0Sstevel@tonic-gate /*
272*0Sstevel@tonic-gate   Performs one or both of the following actions:
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate   - Compress more input starting at next_in and update next_in and avail_in
275*0Sstevel@tonic-gate     accordingly. If not all input can be processed (because there is not
276*0Sstevel@tonic-gate     enough room in the output buffer), next_in and avail_in are updated and
277*0Sstevel@tonic-gate     processing will resume at this point for the next call of deflate().
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate   - Provide more output starting at next_out and update next_out and avail_out
280*0Sstevel@tonic-gate     accordingly. This action is forced if the parameter flush is non zero.
281*0Sstevel@tonic-gate     Forcing flush frequently degrades the compression ratio, so this parameter
282*0Sstevel@tonic-gate     should be set only when necessary (in interactive applications).
283*0Sstevel@tonic-gate     Some output may be provided even if flush is not set.
284*0Sstevel@tonic-gate 
285*0Sstevel@tonic-gate   Before the call of deflate(), the application should ensure that at least
286*0Sstevel@tonic-gate   one of the actions is possible, by providing more input and/or consuming
287*0Sstevel@tonic-gate   more output, and updating avail_in or avail_out accordingly; avail_out
288*0Sstevel@tonic-gate   should never be zero before the call. The application can consume the
289*0Sstevel@tonic-gate   compressed output when it wants, for example when the output buffer is full
290*0Sstevel@tonic-gate   (avail_out == 0), or after each call of deflate().
291*0Sstevel@tonic-gate 
292*0Sstevel@tonic-gate     If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
293*0Sstevel@tonic-gate   block is terminated and flushed to the output buffer so that the
294*0Sstevel@tonic-gate   decompressor can get all input data available so far. For method 9, a future
295*0Sstevel@tonic-gate   variant on method 8, the current block will be flushed but not terminated.
296*0Sstevel@tonic-gate   If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
297*0Sstevel@tonic-gate   special marker is output and the compression dictionary is discarded; this
298*0Sstevel@tonic-gate   is useful to allow the decompressor to synchronize if one compressed block
299*0Sstevel@tonic-gate   has been damaged (see inflateSync below).  Flushing degrades compression and
300*0Sstevel@tonic-gate   so should be used only when necessary.  Using Z_FULL_FLUSH too often can
301*0Sstevel@tonic-gate   seriously degrade the compression. If deflate returns with avail_out == 0,
302*0Sstevel@tonic-gate   this function must be called again with the same value of the flush
303*0Sstevel@tonic-gate   parameter and more output space (updated avail_out), until the flush is
304*0Sstevel@tonic-gate   complete (deflate returns with non-zero avail_out).
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate     If the parameter flush is set to Z_PACKET_FLUSH, the compression
307*0Sstevel@tonic-gate   block is terminated, and a zero-length stored block is output,
308*0Sstevel@tonic-gate   omitting the length bytes (the effect of this is that the 3-bit type
309*0Sstevel@tonic-gate   code 000 for a stored block is output, and the output is then
310*0Sstevel@tonic-gate   byte-aligned).  This is designed for use at the end of a PPP packet.
311*0Sstevel@tonic-gate   In addition, if the current compression block contains all the data
312*0Sstevel@tonic-gate   since the last Z_PACKET_FLUSH, it is never output as a stored block.
313*0Sstevel@tonic-gate   If the current compression block output as a static or dynamic block
314*0Sstevel@tonic-gate   would not be at least `minCompression' bytes smaller than the
315*0Sstevel@tonic-gate   original data, then nothing is output for that block.  (The type
316*0Sstevel@tonic-gate   code for the zero-length stored block is still output, resulting in
317*0Sstevel@tonic-gate   a single zero byte being output for the whole packet.)
318*0Sstevel@tonic-gate   `MinCompression' is a parameter to deflateInit2, or 0 if deflateInit
319*0Sstevel@tonic-gate   is used.
320*0Sstevel@tonic-gate 
321*0Sstevel@tonic-gate     If the parameter flush is set to Z_FINISH, all pending input is processed,
322*0Sstevel@tonic-gate   all pending output is flushed and deflate returns with Z_STREAM_END if there
323*0Sstevel@tonic-gate   was enough output space; if deflate returns with Z_OK, this function must be
324*0Sstevel@tonic-gate   called again with Z_FINISH and more output space (updated avail_out) but no
325*0Sstevel@tonic-gate   more input data, until it returns with Z_STREAM_END or an error. After
326*0Sstevel@tonic-gate   deflate has returned Z_STREAM_END, the only possible operations on the
327*0Sstevel@tonic-gate   stream are deflateReset or deflateEnd.
328*0Sstevel@tonic-gate 
329*0Sstevel@tonic-gate     Z_FINISH can be used immediately after deflateInit if all the compression
330*0Sstevel@tonic-gate   is to be done in a single step. In this case, avail_out must be at least
331*0Sstevel@tonic-gate   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
332*0Sstevel@tonic-gate   Z_STREAM_END, then it must be called again as described above.
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate     deflate() may update data_type if it can make a good guess about
335*0Sstevel@tonic-gate   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
336*0Sstevel@tonic-gate   binary. This field is only for information purposes and does not affect
337*0Sstevel@tonic-gate   the compression algorithm in any manner.
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate     deflate() returns Z_OK if some progress has been made (more input
340*0Sstevel@tonic-gate   processed or more output produced), Z_STREAM_END if all input has been
341*0Sstevel@tonic-gate   consumed and all output has been produced (only when flush is set to
342*0Sstevel@tonic-gate   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
343*0Sstevel@tonic-gate   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
344*0Sstevel@tonic-gate */
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate extern int deflateEnd OF((z_stream *strm));
348*0Sstevel@tonic-gate /*
349*0Sstevel@tonic-gate      All dynamically allocated data structures for this stream are freed.
350*0Sstevel@tonic-gate    This function discards any unprocessed input and does not flush any
351*0Sstevel@tonic-gate    pending output.
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
354*0Sstevel@tonic-gate    stream state was inconsistent. In the error case, msg may be set
355*0Sstevel@tonic-gate    but then points to a static string (which must not be deallocated).
356*0Sstevel@tonic-gate */
357*0Sstevel@tonic-gate 
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate extern int inflateInit OF((z_stream *strm));
360*0Sstevel@tonic-gate /*
361*0Sstevel@tonic-gate      Initializes the internal stream state for decompression. The fields
362*0Sstevel@tonic-gate    zalloc and zfree must be initialized before by the caller.  If zalloc and
363*0Sstevel@tonic-gate    zfree are set to Z_NULL, inflateInit updates them to use default allocation
364*0Sstevel@tonic-gate    functions.
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
367*0Sstevel@tonic-gate    enough memory.  msg is set to null if there is no error message.
368*0Sstevel@tonic-gate    inflateInit does not perform any decompression: this will be done by
369*0Sstevel@tonic-gate    inflate().
370*0Sstevel@tonic-gate */
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate 
373*0Sstevel@tonic-gate extern int inflate OF((z_stream *strm, int flush));
374*0Sstevel@tonic-gate /*
375*0Sstevel@tonic-gate   Performs one or both of the following actions:
376*0Sstevel@tonic-gate 
377*0Sstevel@tonic-gate   - Decompress more input starting at next_in and update next_in and avail_in
378*0Sstevel@tonic-gate     accordingly. If not all input can be processed (because there is not
379*0Sstevel@tonic-gate     enough room in the output buffer), next_in is updated and processing
380*0Sstevel@tonic-gate     will resume at this point for the next call of inflate().
381*0Sstevel@tonic-gate 
382*0Sstevel@tonic-gate   - Provide more output starting at next_out and update next_out and avail_out
383*0Sstevel@tonic-gate     accordingly.  inflate() always provides as much output as possible
384*0Sstevel@tonic-gate     (until there is no more input data or no more space in the output buffer).
385*0Sstevel@tonic-gate 
386*0Sstevel@tonic-gate   Before the call of inflate(), the application should ensure that at least
387*0Sstevel@tonic-gate   one of the actions is possible, by providing more input and/or consuming
388*0Sstevel@tonic-gate   more output, and updating the next_* and avail_* values accordingly.
389*0Sstevel@tonic-gate   The application can consume the uncompressed output when it wants, for
390*0Sstevel@tonic-gate   example when the output buffer is full (avail_out == 0), or after each
391*0Sstevel@tonic-gate   call of inflate().
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate     If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
394*0Sstevel@tonic-gate   inflate flushes as much output as possible to the output buffer. The
395*0Sstevel@tonic-gate   flushing behavior of inflate is not specified for values of the flush
396*0Sstevel@tonic-gate   parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
397*0Sstevel@tonic-gate   current implementation actually flushes as much output as possible
398*0Sstevel@tonic-gate   anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
399*0Sstevel@tonic-gate   has been consumed, it is expecting to see the length field of a stored
400*0Sstevel@tonic-gate   block; if not, it returns Z_DATA_ERROR.
401*0Sstevel@tonic-gate 
402*0Sstevel@tonic-gate     inflate() should normally be called until it returns Z_STREAM_END or an
403*0Sstevel@tonic-gate   error. However if all decompression is to be performed in a single step
404*0Sstevel@tonic-gate   (a single call of inflate), the parameter flush should be set to
405*0Sstevel@tonic-gate   Z_FINISH. In this case all pending input is processed and all pending
406*0Sstevel@tonic-gate   output is flushed; avail_out must be large enough to hold all the
407*0Sstevel@tonic-gate   uncompressed data. (The size of the uncompressed data may have been saved
408*0Sstevel@tonic-gate   by the compressor for this purpose.) The next operation on this stream must
409*0Sstevel@tonic-gate   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
410*0Sstevel@tonic-gate   is never required, but can be used to inform inflate that a faster routine
411*0Sstevel@tonic-gate   may be used for the single inflate() call.
412*0Sstevel@tonic-gate 
413*0Sstevel@tonic-gate     inflate() returns Z_OK if some progress has been made (more input
414*0Sstevel@tonic-gate   processed or more output produced), Z_STREAM_END if the end of the
415*0Sstevel@tonic-gate   compressed data has been reached and all uncompressed output has been
416*0Sstevel@tonic-gate   produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
417*0Sstevel@tonic-gate   the stream structure was inconsistent (for example if next_in or next_out
418*0Sstevel@tonic-gate   was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
419*0Sstevel@tonic-gate   progress is possible or if there was not enough room in the output buffer
420*0Sstevel@tonic-gate   when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
421*0Sstevel@tonic-gate   call inflateSync to look for a good compression block.  */
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate extern int inflateEnd OF((z_stream *strm));
425*0Sstevel@tonic-gate /*
426*0Sstevel@tonic-gate      All dynamically allocated data structures for this stream are freed.
427*0Sstevel@tonic-gate    This function discards any unprocessed input and does not flush any
428*0Sstevel@tonic-gate    pending output.
429*0Sstevel@tonic-gate 
430*0Sstevel@tonic-gate      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
431*0Sstevel@tonic-gate    was inconsistent. In the error case, msg may be set but then points to a
432*0Sstevel@tonic-gate    static string (which must not be deallocated).
433*0Sstevel@tonic-gate */
434*0Sstevel@tonic-gate 
435*0Sstevel@tonic-gate                         /* advanced functions */
436*0Sstevel@tonic-gate 
437*0Sstevel@tonic-gate /*
438*0Sstevel@tonic-gate     The following functions are needed only in some special applications.
439*0Sstevel@tonic-gate */
440*0Sstevel@tonic-gate 
441*0Sstevel@tonic-gate extern int deflateInit2 OF((z_stream *strm,
442*0Sstevel@tonic-gate                             int  level,
443*0Sstevel@tonic-gate                             int  method,
444*0Sstevel@tonic-gate                             int  windowBits,
445*0Sstevel@tonic-gate                             int  memLevel,
446*0Sstevel@tonic-gate                             int  strategy,
447*0Sstevel@tonic-gate 			    int  minCompression));
448*0Sstevel@tonic-gate /*
449*0Sstevel@tonic-gate      This is another version of deflateInit with more compression options. The
450*0Sstevel@tonic-gate    fields next_in, zalloc and zfree must be initialized before by the caller.
451*0Sstevel@tonic-gate 
452*0Sstevel@tonic-gate      The method parameter is the compression method. It must be 8 in this
453*0Sstevel@tonic-gate    version of the library. (Method 9 will allow a 64K history buffer and
454*0Sstevel@tonic-gate    partial block flushes.)
455*0Sstevel@tonic-gate 
456*0Sstevel@tonic-gate      The windowBits parameter is the base two logarithm of the window size
457*0Sstevel@tonic-gate    (the size of the history buffer).  It should be in the range 8..15 for this
458*0Sstevel@tonic-gate    version of the library (the value 16 will be allowed for method 9). Larger
459*0Sstevel@tonic-gate    values of this parameter result in better compression at the expense of
460*0Sstevel@tonic-gate    memory usage. The default value is 15 if deflateInit is used instead.
461*0Sstevel@tonic-gate 
462*0Sstevel@tonic-gate     The memLevel parameter specifies how much memory should be allocated
463*0Sstevel@tonic-gate    for the internal compression state. memLevel=1 uses minimum memory but
464*0Sstevel@tonic-gate    is slow and reduces compression ratio; memLevel=9 uses maximum memory
465*0Sstevel@tonic-gate    for optimal speed. The default value is 8. See zconf.h for total memory
466*0Sstevel@tonic-gate    usage as a function of windowBits and memLevel.
467*0Sstevel@tonic-gate 
468*0Sstevel@tonic-gate      The strategy parameter is used to tune the compression algorithm. Use
469*0Sstevel@tonic-gate    the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
470*0Sstevel@tonic-gate    produced by a filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman
471*0Sstevel@tonic-gate    encoding only (no string match).  Filtered data consists mostly of small
472*0Sstevel@tonic-gate    values with a somewhat random distribution. In this case, the
473*0Sstevel@tonic-gate    compression algorithm is tuned to compress them better. The strategy
474*0Sstevel@tonic-gate    parameter only affects the compression ratio but not the correctness of
475*0Sstevel@tonic-gate    the compressed output even if it is not set appropriately.
476*0Sstevel@tonic-gate 
477*0Sstevel@tonic-gate      The minCompression parameter specifies the minimum reduction in size
478*0Sstevel@tonic-gate    required for a compressed block to be output when Z_PACKET_FLUSH is
479*0Sstevel@tonic-gate    used (see the description of deflate above).
480*0Sstevel@tonic-gate 
481*0Sstevel@tonic-gate      If next_in is not null, the library will use this buffer to hold also
482*0Sstevel@tonic-gate    some history information; the buffer must either hold the entire input
483*0Sstevel@tonic-gate    data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
484*0Sstevel@tonic-gate    is null, the library will allocate its own history buffer (and leave next_in
485*0Sstevel@tonic-gate    null). next_out need not be provided here but must be provided by the
486*0Sstevel@tonic-gate    application for the next call of deflate().
487*0Sstevel@tonic-gate 
488*0Sstevel@tonic-gate      If the history buffer is provided by the application, next_in must
489*0Sstevel@tonic-gate    must never be changed by the application since the compressor maintains
490*0Sstevel@tonic-gate    information inside this buffer from call to call; the application
491*0Sstevel@tonic-gate    must provide more input only by increasing avail_in. next_in is always
492*0Sstevel@tonic-gate    reset by the library in this case.
493*0Sstevel@tonic-gate 
494*0Sstevel@tonic-gate       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
495*0Sstevel@tonic-gate    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
496*0Sstevel@tonic-gate    an invalid method). msg is set to null if there is no error message.
497*0Sstevel@tonic-gate    deflateInit2 does not perform any compression: this will be done by
498*0Sstevel@tonic-gate    deflate().
499*0Sstevel@tonic-gate */
500*0Sstevel@tonic-gate 
501*0Sstevel@tonic-gate extern int deflateCopy OF((z_stream *dest,
502*0Sstevel@tonic-gate                            z_stream *source));
503*0Sstevel@tonic-gate /*
504*0Sstevel@tonic-gate      Sets the destination stream as a complete copy of the source stream.  If
505*0Sstevel@tonic-gate    the source stream is using an application-supplied history buffer, a new
506*0Sstevel@tonic-gate    buffer is allocated for the destination stream.  The compressed output
507*0Sstevel@tonic-gate    buffer is always application-supplied. It's the responsibility of the
508*0Sstevel@tonic-gate    application to provide the correct values of next_out and avail_out for the
509*0Sstevel@tonic-gate    next call of deflate.
510*0Sstevel@tonic-gate 
511*0Sstevel@tonic-gate      This function is useful when several compression strategies will be
512*0Sstevel@tonic-gate    tried, for example when there are several ways of pre-processing the input
513*0Sstevel@tonic-gate    data with a filter. The streams that will be discarded should then be freed
514*0Sstevel@tonic-gate    by calling deflateEnd.  Note that deflateCopy duplicates the internal
515*0Sstevel@tonic-gate    compression state which can be quite large, so this strategy is slow and
516*0Sstevel@tonic-gate    can consume lots of memory.
517*0Sstevel@tonic-gate 
518*0Sstevel@tonic-gate       deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
519*0Sstevel@tonic-gate    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
520*0Sstevel@tonic-gate    (such as zalloc being NULL). msg is left unchanged in both source and
521*0Sstevel@tonic-gate    destination.
522*0Sstevel@tonic-gate */
523*0Sstevel@tonic-gate 
524*0Sstevel@tonic-gate extern int deflateReset OF((z_stream *strm));
525*0Sstevel@tonic-gate /*
526*0Sstevel@tonic-gate      This function is equivalent to deflateEnd followed by deflateInit,
527*0Sstevel@tonic-gate    but does not free and reallocate all the internal compression state.
528*0Sstevel@tonic-gate    The stream will keep the same compression level and any other attributes
529*0Sstevel@tonic-gate    that may have been set by deflateInit2.
530*0Sstevel@tonic-gate 
531*0Sstevel@tonic-gate       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
532*0Sstevel@tonic-gate    stream state was inconsistent (such as zalloc or state being NULL).
533*0Sstevel@tonic-gate */
534*0Sstevel@tonic-gate 
535*0Sstevel@tonic-gate extern int inflateInit2 OF((z_stream *strm,
536*0Sstevel@tonic-gate                             int  windowBits));
537*0Sstevel@tonic-gate /*
538*0Sstevel@tonic-gate      This is another version of inflateInit with more compression options. The
539*0Sstevel@tonic-gate    fields next_out, zalloc and zfree must be initialized before by the caller.
540*0Sstevel@tonic-gate 
541*0Sstevel@tonic-gate      The windowBits parameter is the base two logarithm of the maximum window
542*0Sstevel@tonic-gate    size (the size of the history buffer).  It should be in the range 8..15 for
543*0Sstevel@tonic-gate    this version of the library (the value 16 will be allowed soon). The
544*0Sstevel@tonic-gate    default value is 15 if inflateInit is used instead. If a compressed stream
545*0Sstevel@tonic-gate    with a larger window size is given as input, inflate() will return with
546*0Sstevel@tonic-gate    the error code Z_DATA_ERROR instead of trying to allocate a larger window.
547*0Sstevel@tonic-gate 
548*0Sstevel@tonic-gate      If next_out is not null, the library will use this buffer for the history
549*0Sstevel@tonic-gate    buffer; the buffer must either be large enough to hold the entire output
550*0Sstevel@tonic-gate    data, or have at least 1<<windowBits bytes.  If next_out is null, the
551*0Sstevel@tonic-gate    library will allocate its own buffer (and leave next_out null). next_in
552*0Sstevel@tonic-gate    need not be provided here but must be provided by the application for the
553*0Sstevel@tonic-gate    next call of inflate().
554*0Sstevel@tonic-gate 
555*0Sstevel@tonic-gate      If the history buffer is provided by the application, next_out must
556*0Sstevel@tonic-gate    never be changed by the application since the decompressor maintains
557*0Sstevel@tonic-gate    history information inside this buffer from call to call; the application
558*0Sstevel@tonic-gate    can only reset next_out to the beginning of the history buffer when
559*0Sstevel@tonic-gate    avail_out is zero and all output has been consumed.
560*0Sstevel@tonic-gate 
561*0Sstevel@tonic-gate       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
562*0Sstevel@tonic-gate    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
563*0Sstevel@tonic-gate    windowBits < 8). msg is set to null if there is no error message.
564*0Sstevel@tonic-gate    inflateInit2 does not perform any decompression: this will be done by
565*0Sstevel@tonic-gate    inflate().
566*0Sstevel@tonic-gate */
567*0Sstevel@tonic-gate 
568*0Sstevel@tonic-gate extern int inflateSync OF((z_stream *strm));
569*0Sstevel@tonic-gate /*
570*0Sstevel@tonic-gate     Skips invalid compressed data until the special marker (see deflate()
571*0Sstevel@tonic-gate   above) can be found, or until all available input is skipped. No output
572*0Sstevel@tonic-gate   is provided.
573*0Sstevel@tonic-gate 
574*0Sstevel@tonic-gate     inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
575*0Sstevel@tonic-gate   if no more input was provided, Z_DATA_ERROR if no marker has been found,
576*0Sstevel@tonic-gate   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
577*0Sstevel@tonic-gate   case, the application may save the current current value of total_in which
578*0Sstevel@tonic-gate   indicates where valid compressed data was found. In the error case, the
579*0Sstevel@tonic-gate   application may repeatedly call inflateSync, providing more input each time,
580*0Sstevel@tonic-gate   until success or end of the input data.
581*0Sstevel@tonic-gate */
582*0Sstevel@tonic-gate 
583*0Sstevel@tonic-gate extern int inflateReset OF((z_stream *strm));
584*0Sstevel@tonic-gate /*
585*0Sstevel@tonic-gate      This function is equivalent to inflateEnd followed by inflateInit,
586*0Sstevel@tonic-gate    but does not free and reallocate all the internal decompression state.
587*0Sstevel@tonic-gate    The stream will keep attributes that may have been set by inflateInit2.
588*0Sstevel@tonic-gate 
589*0Sstevel@tonic-gate       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
590*0Sstevel@tonic-gate    stream state was inconsistent (such as zalloc or state being NULL).
591*0Sstevel@tonic-gate */
592*0Sstevel@tonic-gate 
593*0Sstevel@tonic-gate extern int inflateIncomp OF((z_stream *strm));
594*0Sstevel@tonic-gate /*
595*0Sstevel@tonic-gate      This function adds the data at next_in (avail_in bytes) to the output
596*0Sstevel@tonic-gate    history without performing any output.  There must be no pending output,
597*0Sstevel@tonic-gate    and the decompressor must be expecting to see the start of a block.
598*0Sstevel@tonic-gate    Calling this function is equivalent to decompressing a stored block
599*0Sstevel@tonic-gate    containing the data at next_in (except that the data is not output).
600*0Sstevel@tonic-gate */
601*0Sstevel@tonic-gate 
602*0Sstevel@tonic-gate                         /* checksum functions */
603*0Sstevel@tonic-gate 
604*0Sstevel@tonic-gate /*
605*0Sstevel@tonic-gate      This function is not related to compression but is exported
606*0Sstevel@tonic-gate    anyway because it might be useful in applications using the
607*0Sstevel@tonic-gate    compression library.
608*0Sstevel@tonic-gate */
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
611*0Sstevel@tonic-gate 
612*0Sstevel@tonic-gate /*
613*0Sstevel@tonic-gate      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
614*0Sstevel@tonic-gate    return the updated checksum. If buf is NULL, this function returns
615*0Sstevel@tonic-gate    the required initial value for the checksum.
616*0Sstevel@tonic-gate    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
617*0Sstevel@tonic-gate    much faster. Usage example:
618*0Sstevel@tonic-gate 
619*0Sstevel@tonic-gate      uLong adler = adler32(0L, Z_NULL, 0);
620*0Sstevel@tonic-gate 
621*0Sstevel@tonic-gate      while (read_buffer(buffer, length) != EOF) {
622*0Sstevel@tonic-gate        adler = adler32(adler, buffer, length);
623*0Sstevel@tonic-gate      }
624*0Sstevel@tonic-gate      if (adler != original_adler) error();
625*0Sstevel@tonic-gate */
626*0Sstevel@tonic-gate 
627*0Sstevel@tonic-gate #ifndef _Z_UTIL_H
628*0Sstevel@tonic-gate     struct internal_state {int dummy;}; /* hack for buggy compilers */
629*0Sstevel@tonic-gate #endif
630*0Sstevel@tonic-gate 
631*0Sstevel@tonic-gate #endif /* _ZLIB_H */
632