Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / net / zlib.h
1 /* $FreeBSD: src/sys/net/zlib.h,v 1.7.2.1 2002/07/31 14:13:05 rwatson Exp $     */
2
3 /*
4  * This file is derived from zlib.h and zconf.h from the zlib-1.0.4
5  * distribution by Jean-loup Gailly and Mark Adler, with some additions
6  * by Paul Mackerras to aid in implementing Deflate compression and
7  * decompression for PPP packets.
8  */
9
10 /*
11  *  ==FILEVERSION 971127==
12  *
13  * This marker is used by the Linux installation script to determine
14  * whether an up-to-date version of this file is already installed.
15  */
16
17
18 /* +++ zlib.h */
19 /* zlib.h -- interface of the 'zlib' general purpose compression library
20   version 1.0.4, Jul 24th, 1996.
21
22   Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
23
24   This software is provided 'as-is', without any express or implied
25   warranty.  In no event will the authors be held liable for any damages
26   arising from the use of this software.
27
28   Permission is granted to anyone to use this software for any purpose,
29   including commercial applications, and to alter it and redistribute it
30   freely, subject to the following restrictions:
31
32   1. The origin of this software must not be misrepresented; you must not
33      claim that you wrote the original software. If you use this software
34      in a product, an acknowledgment in the product documentation would be
35      appreciated but is not required.
36   2. Altered source versions must be plainly marked as such, and must not be
37      misrepresented as being the original software.
38   3. This notice may not be removed or altered from any source distribution.
39
40   Jean-loup Gailly        Mark Adler
41   gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
42
43
44   The data format used by the zlib library is described by RFCs (Request for
45   Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
46   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
47 */
48
49 #ifndef _ZLIB_H
50 #define _ZLIB_H
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56
57 /* +++ zconf.h */
58 /* zconf.h -- configuration of the zlib compression library
59  * Copyright (C) 1995-1996 Jean-loup Gailly.
60  * For conditions of distribution and use, see copyright notice in zlib.h 
61  */
62
63 /* From: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */
64
65 #ifndef _ZCONF_H
66 #define _ZCONF_H
67
68 /*
69  * If you *really* need a unique prefix for all types and library functions,
70  * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
71  */
72 #ifdef Z_PREFIX
73 #  define deflateInit_  z_deflateInit_
74 #  define deflate       z_deflate
75 #  define deflateEnd    z_deflateEnd
76 #  define inflateInit_  z_inflateInit_
77 #  define inflate       z_inflate
78 #  define inflateEnd    z_inflateEnd
79 #  define deflateInit2_ z_deflateInit2_
80 #  define deflateSetDictionary z_deflateSetDictionary
81 #  define deflateCopy   z_deflateCopy
82 #  define deflateReset  z_deflateReset
83 #  define deflateParams z_deflateParams
84 #  define inflateInit2_ z_inflateInit2_
85 #  define inflateSetDictionary z_inflateSetDictionary
86 #  define inflateSync   z_inflateSync
87 #  define inflateReset  z_inflateReset
88 #  define compress      z_compress
89 #  define uncompress    z_uncompress
90 #  define adler32       z_adler32
91 #if 0
92 #  define crc32         z_crc32
93 #  define get_crc_table z_get_crc_table
94 #endif
95
96 #  define Byte          z_Byte
97 #  define uInt          z_uInt
98 #  define uLong         z_uLong
99 #  define Bytef         z_Bytef
100 #  define charf         z_charf
101 #  define intf          z_intf
102 #  define uIntf         z_uIntf
103 #  define uLongf        z_uLongf
104 #  define voidpf        z_voidpf
105 #  define voidp         z_voidp
106 #endif
107
108 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
109 #  define WIN32
110 #endif
111 #if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
112 #  ifndef __32BIT__
113 #    define __32BIT__
114 #  endif
115 #endif
116 #if defined(__MSDOS__) && !defined(MSDOS)
117 #  define MSDOS
118 #endif
119
120 /*
121  * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
122  * than 64k bytes at a time (needed on systems with 16-bit int).
123  */
124 #if defined(MSDOS) && !defined(__32BIT__)
125 #  define MAXSEG_64K
126 #endif
127 #ifdef MSDOS
128 #  define UNALIGNED_OK
129 #endif
130
131 #if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32))  && !defined(STDC)
132 #  define STDC
133 #endif
134 #if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
135 #  define STDC
136 #endif
137
138 #ifndef STDC
139 #  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
140 #    define const
141 #  endif
142 #endif
143
144 /* Some Mac compilers merge all .h files incorrectly: */
145 #if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
146 #  define NO_DUMMY_DECL
147 #endif
148
149 /* Maximum value for memLevel in deflateInit2 */
150 #ifndef MAX_MEM_LEVEL
151 #  ifdef MAXSEG_64K
152 #    define MAX_MEM_LEVEL 8
153 #  else
154 #    define MAX_MEM_LEVEL 9
155 #  endif
156 #endif
157
158 /* Maximum value for windowBits in deflateInit2 and inflateInit2 */
159 #ifndef MAX_WBITS
160 #  define MAX_WBITS   15 /* 32K LZ77 window */
161 #endif
162
163 /* The memory requirements for deflate are (in bytes):
164             1 << (windowBits+2)   +  1 << (memLevel+9)
165  that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
166  plus a few kilobytes for small objects. For example, if you want to reduce
167  the default memory requirements from 256K to 128K, compile with
168      make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
169  Of course this will generally degrade compression (there's no free lunch).
170
171    The memory requirements for inflate are (in bytes) 1 << windowBits
172  that is, 32K for windowBits=15 (default value) plus a few kilobytes
173  for small objects.
174 */
175
176                         /* Type declarations */
177
178 #ifndef OF /* function prototypes */
179 #  ifdef STDC
180 #    define OF(args)  args
181 #  else
182 #    define OF(args)  ()
183 #  endif
184 #endif
185
186 /* The following definitions for FAR are needed only for MSDOS mixed
187  * model programming (small or medium model with some far allocations).
188  * This was tested only with MSC; for other MSDOS compilers you may have
189  * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
190  * just define FAR to be empty.
191  */
192 #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
193    /* MSC small or medium model */
194 #  define SMALL_MEDIUM
195 #  ifdef _MSC_VER
196 #    define FAR __far
197 #  else
198 #    define FAR far
199 #  endif
200 #endif
201 #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
202 #  ifndef __32BIT__
203 #    define SMALL_MEDIUM
204 #    define FAR __far
205 #  endif
206 #endif
207 #ifndef FAR
208 #   define FAR
209 #endif
210
211 typedef unsigned char  Byte;  /* 8 bits */
212 typedef unsigned int   uInt;  /* 16 bits or more */
213 typedef unsigned long  uLong; /* 32 bits or more */
214
215 #if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
216    /* Borland C/C++ ignores FAR inside typedef */
217 #  define Bytef Byte FAR
218 #else
219    typedef Byte  FAR Bytef;
220 #endif
221 typedef char  FAR charf;
222 typedef int   FAR intf;
223 typedef uInt  FAR uIntf;
224 typedef uLong FAR uLongf;
225
226 #ifdef STDC
227    typedef void FAR *voidpf;
228    typedef void     *voidp;
229 #else
230    typedef Byte FAR *voidpf;
231    typedef Byte     *voidp;
232 #endif
233
234
235 /* Compile with -DZLIB_DLL for Windows DLL support */
236 #if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
237 #  include <windows.h>
238 #  define EXPORT  WINAPI
239 #else
240 #  define EXPORT
241 #endif
242
243 #endif /* _ZCONF_H */
244 /* --- zconf.h */
245
246 #define ZLIB_VERSION "1.0.4P"
247
248 /* 
249      The 'zlib' compression library provides in-memory compression and
250   decompression functions, including integrity checks of the uncompressed
251   data.  This version of the library supports only one compression method
252   (deflation) but other algorithms may be added later and will have the same
253   stream interface.
254
255      For compression the application must provide the output buffer and
256   may optionally provide the input buffer for optimization. For decompression,
257   the application must provide the input buffer and may optionally provide
258   the output buffer for optimization.
259
260      Compression can be done in a single step if the buffers are large
261   enough (for example if an input file is mmap'ed), or can be done by
262   repeated calls of the compression function.  In the latter case, the
263   application must provide more input and/or consume the output
264   (providing more output space) before each call.
265
266      The library does not install any signal handler. It is recommended to
267   add at least a handler for SIGSEGV when decompressing; the library checks
268   the consistency of the input data whenever possible but may go nuts
269   for some forms of corrupted input.
270 */
271
272 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
273 typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
274
275 struct internal_state;
276
277 typedef struct z_stream_s {
278     Bytef    *next_in;  /* next input byte */
279     uInt     avail_in;  /* number of bytes available at next_in */
280     uLong    total_in;  /* total nb of input bytes read so far */
281
282     Bytef    *next_out; /* next output byte should be put there */
283     uInt     avail_out; /* remaining free space at next_out */
284     uLong    total_out; /* total nb of bytes output so far */
285
286     const char     *msg; /* last error message, NULL if no error */
287     struct internal_state FAR *state; /* not visible by applications */
288
289     alloc_func zalloc;  /* used to allocate the internal state */
290     free_func  zfree;   /* used to free the internal state */
291     voidpf     opaque;  /* private data object passed to zalloc and zfree */
292
293     int     data_type;  /* best guess about the data type: ascii or binary */
294     uLong   adler;      /* adler32 value of the uncompressed data */
295     uLong   reserved;   /* reserved for future use */
296 } z_stream;
297
298 typedef z_stream FAR *z_streamp;
299
300 /*
301    The application must update next_in and avail_in when avail_in has
302    dropped to zero. It must update next_out and avail_out when avail_out
303    has dropped to zero. The application must initialize zalloc, zfree and
304    opaque before calling the init function. All other fields are set by the
305    compression library and must not be updated by the application.
306
307    The opaque value provided by the application will be passed as the first
308    parameter for calls of zalloc and zfree. This can be useful for custom
309    memory management. The compression library attaches no meaning to the
310    opaque value.
311
312    zalloc must return Z_NULL if there is not enough memory for the object.
313    On 16-bit systems, the functions zalloc and zfree must be able to allocate
314    exactly 65536 bytes, but will not be required to allocate more than this
315    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
316    pointers returned by zalloc for objects of exactly 65536 bytes *must*
317    have their offset normalized to zero. The default allocation function
318    provided by this library ensures this (see zutil.c). To reduce memory
319    requirements and avoid any allocation of 64K objects, at the expense of
320    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
321
322    The fields total_in and total_out can be used for statistics or
323    progress reports. After compression, total_in holds the total size of
324    the uncompressed data and may be saved for use in the decompressor
325    (particularly if the decompressor wants to decompress everything in
326    a single step).
327 */
328
329                         /* constants */
330
331 #define Z_NO_FLUSH      0
332 #define Z_PARTIAL_FLUSH 1
333 #define Z_PACKET_FLUSH  2
334 #define Z_SYNC_FLUSH    3
335 #define Z_FULL_FLUSH    4
336 #define Z_FINISH        5
337 /* Allowed flush values; see deflate() below for details */
338
339 #define Z_OK            0
340 #define Z_STREAM_END    1
341 #define Z_NEED_DICT     2
342 #define Z_ERRNO        (-1)
343 #define Z_STREAM_ERROR (-2)
344 #define Z_DATA_ERROR   (-3)
345 #define Z_MEM_ERROR    (-4)
346 #define Z_BUF_ERROR    (-5)
347 #define Z_VERSION_ERROR (-6)
348 /* Return codes for the compression/decompression functions. Negative
349  * values are errors, positive values are used for special but normal events.
350  */
351
352 #define Z_NO_COMPRESSION         0
353 #define Z_BEST_SPEED             1
354 #define Z_BEST_COMPRESSION       9
355 #define Z_DEFAULT_COMPRESSION  (-1)
356 /* compression levels */
357
358 #define Z_FILTERED            1
359 #define Z_HUFFMAN_ONLY        2
360 #define Z_DEFAULT_STRATEGY    0
361 /* compression strategy; see deflateInit2() below for details */
362
363 #define Z_BINARY   0
364 #define Z_ASCII    1
365 #define Z_UNKNOWN  2
366 /* Possible values of the data_type field */
367
368 #define Z_DEFLATED   8
369 /* The deflate compression method (the only one supported in this version) */
370
371 #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
372
373 #define zlib_version zlibVersion()
374 /* for compatibility with versions < 1.0.2 */
375
376                         /* basic functions */
377
378 extern const char * EXPORT zlibVersion OF((void));
379 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
380    If the first character differs, the library code actually used is
381    not compatible with the zlib.h header file used by the application.
382    This check is automatically made by deflateInit and inflateInit.
383  */
384
385 /* 
386 extern int EXPORT deflateInit OF((z_streamp strm, int level));
387
388      Initializes the internal stream state for compression. The fields
389    zalloc, zfree and opaque must be initialized before by the caller.
390    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
391    use default allocation functions.
392
393      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
394    1 gives best speed, 9 gives best compression, 0 gives no compression at
395    all (the input data is simply copied a block at a time).
396    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
397    compression (currently equivalent to level 6).
398
399      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
400    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
401    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
402    with the version assumed by the caller (ZLIB_VERSION).
403    msg is set to null if there is no error message.  deflateInit does not
404    perform any compression: this will be done by deflate().
405 */
406
407
408 extern int EXPORT deflate OF((z_streamp strm, int flush));
409 /*
410   Performs one or both of the following actions:
411
412   - Compress more input starting at next_in and update next_in and avail_in
413     accordingly. If not all input can be processed (because there is not
414     enough room in the output buffer), next_in and avail_in are updated and
415     processing will resume at this point for the next call of deflate().
416
417   - Provide more output starting at next_out and update next_out and avail_out
418     accordingly. This action is forced if the parameter flush is non zero.
419     Forcing flush frequently degrades the compression ratio, so this parameter
420     should be set only when necessary (in interactive applications).
421     Some output may be provided even if flush is not set.
422
423   Before the call of deflate(), the application should ensure that at least
424   one of the actions is possible, by providing more input and/or consuming
425   more output, and updating avail_in or avail_out accordingly; avail_out
426   should never be zero before the call. The application can consume the
427   compressed output when it wants, for example when the output buffer is full
428   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
429   and with zero avail_out, it must be called again after making room in the
430   output buffer because there might be more output pending.
431
432     If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
433   block is terminated and flushed to the output buffer so that the
434   decompressor can get all input data available so far. For method 9, a future
435   variant on method 8, the current block will be flushed but not terminated.
436   Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
437   output is byte aligned (the compressor can clear its internal bit buffer)
438   and the current block is always terminated; this can be useful if the
439   compressor has to be restarted from scratch after an interruption (in which
440   case the internal state of the compressor may be lost).
441     If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
442   special marker is output and the compression dictionary is discarded; this
443   is useful to allow the decompressor to synchronize if one compressed block
444   has been damaged (see inflateSync below).  Flushing degrades compression and
445   so should be used only when necessary.  Using Z_FULL_FLUSH too often can
446   seriously degrade the compression. If deflate returns with avail_out == 0,
447   this function must be called again with the same value of the flush
448   parameter and more output space (updated avail_out), until the flush is
449   complete (deflate returns with non-zero avail_out).
450
451     If the parameter flush is set to Z_PACKET_FLUSH, the compression
452   block is terminated, and a zero-length stored block is output,
453   omitting the length bytes (the effect of this is that the 3-bit type
454   code 000 for a stored block is output, and the output is then
455   byte-aligned).  This is designed for use at the end of a PPP packet.
456
457     If the parameter flush is set to Z_FINISH, pending input is processed,
458   pending output is flushed and deflate returns with Z_STREAM_END if there
459   was enough output space; if deflate returns with Z_OK, this function must be
460   called again with Z_FINISH and more output space (updated avail_out) but no
461   more input data, until it returns with Z_STREAM_END or an error. After
462   deflate has returned Z_STREAM_END, the only possible operations on the
463   stream are deflateReset or deflateEnd.
464   
465     Z_FINISH can be used immediately after deflateInit if all the compression
466   is to be done in a single step. In this case, avail_out must be at least
467   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
468   Z_STREAM_END, then it must be called again as described above.
469
470     deflate() may update data_type if it can make a good guess about
471   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
472   binary. This field is only for information purposes and does not affect
473   the compression algorithm in any manner.
474
475     deflate() returns Z_OK if some progress has been made (more input
476   processed or more output produced), Z_STREAM_END if all input has been
477   consumed and all output has been produced (only when flush is set to
478   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
479   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
480 */
481
482
483 extern int EXPORT deflateEnd OF((z_streamp strm));
484 /*
485      All dynamically allocated data structures for this stream are freed.
486    This function discards any unprocessed input and does not flush any
487    pending output.
488
489      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
490    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
491    prematurely (some input or output was discarded). In the error case,
492    msg may be set but then points to a static string (which must not be
493    deallocated).
494 */
495
496
497 /* 
498 extern int EXPORT inflateInit OF((z_streamp strm));
499
500      Initializes the internal stream state for decompression. The fields
501    zalloc, zfree and opaque must be initialized before by the caller.  If
502    zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
503    allocation functions.
504
505      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
506    enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
507    with the version assumed by the caller.  msg is set to null if there is no
508    error message. inflateInit does not perform any decompression: this will be
509    done by inflate().
510 */
511
512 #if defined(__FreeBSD__) && defined(_KERNEL)
513 #define inflate       inflate_ppp     /* FreeBSD already has an inflate :-( */
514 #endif
515
516 extern int EXPORT inflate OF((z_streamp strm, int flush));
517 /*
518   Performs one or both of the following actions:
519
520   - Decompress more input starting at next_in and update next_in and avail_in
521     accordingly. If not all input can be processed (because there is not
522     enough room in the output buffer), next_in is updated and processing
523     will resume at this point for the next call of inflate().
524
525   - Provide more output starting at next_out and update next_out and avail_out
526     accordingly.  inflate() provides as much output as possible, until there
527     is no more input data or no more space in the output buffer (see below
528     about the flush parameter).
529
530   Before the call of inflate(), the application should ensure that at least
531   one of the actions is possible, by providing more input and/or consuming
532   more output, and updating the next_* and avail_* values accordingly.
533   The application can consume the uncompressed output when it wants, for
534   example when the output buffer is full (avail_out == 0), or after each
535   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
536   must be called again after making room in the output buffer because there
537   might be more output pending.
538
539     If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
540   inflate flushes as much output as possible to the output buffer. The
541   flushing behavior of inflate is not specified for values of the flush
542   parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
543   current implementation actually flushes as much output as possible
544   anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
545   has been consumed, it is expecting to see the length field of a stored
546   block; if not, it returns Z_DATA_ERROR.
547
548     inflate() should normally be called until it returns Z_STREAM_END or an
549   error. However if all decompression is to be performed in a single step
550   (a single call of inflate), the parameter flush should be set to
551   Z_FINISH. In this case all pending input is processed and all pending
552   output is flushed; avail_out must be large enough to hold all the
553   uncompressed data. (The size of the uncompressed data may have been saved
554   by the compressor for this purpose.) The next operation on this stream must
555   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
556   is never required, but can be used to inform inflate that a faster routine
557   may be used for the single inflate() call.
558
559     inflate() returns Z_OK if some progress has been made (more input
560   processed or more output produced), Z_STREAM_END if the end of the
561   compressed data has been reached and all uncompressed output has been
562   produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
563   inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
564   Z_STREAM_ERROR if the stream structure was inconsistent (for example if
565   next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
566   Z_BUF_ERROR if no progress is possible or if there was not enough room in
567   the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
568   application may then call inflateSync to look for a good compression block.
569   In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
570   dictionary chosen by the compressor.
571 */
572
573
574 extern int EXPORT inflateEnd OF((z_streamp strm));
575 /*
576      All dynamically allocated data structures for this stream are freed.
577    This function discards any unprocessed input and does not flush any
578    pending output.
579
580      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
581    was inconsistent. In the error case, msg may be set but then points to a
582    static string (which must not be deallocated).
583 */
584
585                         /* Advanced functions */
586
587 /*
588     The following functions are needed only in some special applications.
589 */
590
591 /*   
592 extern int EXPORT deflateInit2 OF((z_streamp strm,
593                                    int  level,
594                                    int  method,
595                                    int  windowBits,
596                                    int  memLevel,
597                                    int  strategy));
598
599      This is another version of deflateInit with more compression options. The
600    fields next_in, zalloc, zfree and opaque must be initialized before by
601    the caller.
602
603      The method parameter is the compression method. It must be Z_DEFLATED in
604    this version of the library. (Method 9 will allow a 64K history buffer and
605    partial block flushes.)
606
607      The windowBits parameter is the base two logarithm of the window size
608    (the size of the history buffer).  It should be in the range 8..15 for this
609    version of the library (the value 16 will be allowed for method 9). Larger
610    values of this parameter result in better compression at the expense of
611    memory usage. The default value is 15 if deflateInit is used instead.
612
613      The memLevel parameter specifies how much memory should be allocated
614    for the internal compression state. memLevel=1 uses minimum memory but
615    is slow and reduces compression ratio; memLevel=9 uses maximum memory
616    for optimal speed. The default value is 8. See zconf.h for total memory
617    usage as a function of windowBits and memLevel.
618
619      The strategy parameter is used to tune the compression algorithm. Use the
620    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
621    filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
622    string match).  Filtered data consists mostly of small values with a
623    somewhat random distribution. In this case, the compression algorithm is
624    tuned to compress them better. The effect of Z_FILTERED is to force more
625    Huffman coding and less string matching; it is somewhat intermediate
626    between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
627    the compression ratio but not the correctness of the compressed output even
628    if it is not set appropriately.
629
630      If next_in is not null, the library will use this buffer to hold also
631    some history information; the buffer must either hold the entire input
632    data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
633    is null, the library will allocate its own history buffer (and leave next_in
634    null). next_out need not be provided here but must be provided by the
635    application for the next call of deflate().
636
637      If the history buffer is provided by the application, next_in must
638    must never be changed by the application since the compressor maintains
639    information inside this buffer from call to call; the application
640    must provide more input only by increasing avail_in. next_in is always
641    reset by the library in this case.
642
643       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
644    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
645    an invalid method). msg is set to null if there is no error message.
646    deflateInit2 does not perform any compression: this will be done by
647    deflate(). 
648 */
649                             
650 extern int EXPORT deflateSetDictionary OF((z_streamp strm,
651                                            const Bytef *dictionary,
652                                            uInt  dictLength));
653 /*
654      Initializes the compression dictionary (history buffer) from the given
655    byte sequence without producing any compressed output. This function must
656    be called immediately after deflateInit or deflateInit2, before any call
657    of deflate. The compressor and decompressor must use exactly the same
658    dictionary (see inflateSetDictionary).
659      The dictionary should consist of strings (byte sequences) that are likely
660    to be encountered later in the data to be compressed, with the most commonly
661    used strings preferably put towards the end of the dictionary. Using a
662    dictionary is most useful when the data to be compressed is short and
663    can be predicted with good accuracy; the data can then be compressed better
664    than with the default empty dictionary. In this version of the library,
665    only the last 32K bytes of the dictionary are used.
666      Upon return of this function, strm->adler is set to the Adler32 value
667    of the dictionary; the decompressor may later use this value to determine
668    which dictionary has been used by the compressor. (The Adler32 value
669    applies to the whole dictionary even if only a subset of the dictionary is
670    actually used by the compressor.)
671
672      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
673    parameter is invalid (such as NULL dictionary) or the stream state
674    is inconsistent (for example if deflate has already been called for this
675    stream). deflateSetDictionary does not perform any compression: this will
676    be done by deflate(). 
677 */
678
679 extern int EXPORT deflateCopy OF((z_streamp dest,
680                                   z_streamp source));
681 /*
682      Sets the destination stream as a complete copy of the source stream.  If
683    the source stream is using an application-supplied history buffer, a new
684    buffer is allocated for the destination stream.  The compressed output
685    buffer is always application-supplied. It's the responsibility of the
686    application to provide the correct values of next_out and avail_out for the
687    next call of deflate.
688
689      This function can be useful when several compression strategies will be
690    tried, for example when there are several ways of pre-processing the input
691    data with a filter. The streams that will be discarded should then be freed
692    by calling deflateEnd.  Note that deflateCopy duplicates the internal
693    compression state which can be quite large, so this strategy is slow and
694    can consume lots of memory.
695
696      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
697    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
698    (such as zalloc being NULL). msg is left unchanged in both source and
699    destination.
700 */
701
702 extern int EXPORT deflateReset OF((z_streamp strm));
703 /*
704      This function is equivalent to deflateEnd followed by deflateInit,
705    but does not free and reallocate all the internal compression state.
706    The stream will keep the same compression level and any other attributes
707    that may have been set by deflateInit2.
708
709       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
710    stream state was inconsistent (such as zalloc or state being NULL).
711 */
712
713 extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
714 /*
715      Dynamically update the compression level and compression strategy.
716    This can be used to switch between compression and straight copy of
717    the input data, or to switch to a different kind of input data requiring
718    a different strategy. If the compression level is changed, the input
719    available so far is compressed with the old level (and may be flushed);
720    the new level will take effect only at the next call of deflate().
721
722      Before the call of deflateParams, the stream state must be set as for
723    a call of deflate(), since the currently available input may have to
724    be compressed and flushed. In particular, strm->avail_out must be non-zero.
725
726      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
727    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
728    if strm->avail_out was zero.
729 */
730
731 extern int EXPORT deflateOutputPending OF((z_streamp strm));
732 /*
733      Returns the number of bytes of output which are immediately
734    available from the compressor (i.e. without any further input
735    or flush).
736 */
737
738 /*   
739 extern int EXPORT inflateInit2 OF((z_streamp strm,
740                                    int  windowBits));
741
742      This is another version of inflateInit with more compression options. The
743    fields next_out, zalloc, zfree and opaque must be initialized before by
744    the caller.
745
746      The windowBits parameter is the base two logarithm of the maximum window
747    size (the size of the history buffer).  It should be in the range 8..15 for
748    this version of the library (the value 16 will be allowed soon). The
749    default value is 15 if inflateInit is used instead. If a compressed stream
750    with a larger window size is given as input, inflate() will return with
751    the error code Z_DATA_ERROR instead of trying to allocate a larger window.
752
753      If next_out is not null, the library will use this buffer for the history
754    buffer; the buffer must either be large enough to hold the entire output
755    data, or have at least 1<<windowBits bytes.  If next_out is null, the
756    library will allocate its own buffer (and leave next_out null). next_in
757    need not be provided here but must be provided by the application for the
758    next call of inflate().
759
760      If the history buffer is provided by the application, next_out must
761    never be changed by the application since the decompressor maintains
762    history information inside this buffer from call to call; the application
763    can only reset next_out to the beginning of the history buffer when
764    avail_out is zero and all output has been consumed.
765
766       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
767    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
768    windowBits < 8). msg is set to null if there is no error message.
769    inflateInit2 does not perform any decompression: this will be done by
770    inflate().
771 */
772
773 extern int EXPORT inflateSetDictionary OF((z_streamp strm,
774                                            const Bytef *dictionary,
775                                            uInt  dictLength));
776 /*
777      Initializes the decompression dictionary (history buffer) from the given
778    uncompressed byte sequence. This function must be called immediately after
779    a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
780    by the compressor can be determined from the Adler32 value returned by this
781    call of inflate. The compressor and decompressor must use exactly the same
782    dictionary (see deflateSetDictionary).
783
784      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
785    parameter is invalid (such as NULL dictionary) or the stream state is
786    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
787    expected one (incorrect Adler32 value). inflateSetDictionary does not
788    perform any decompression: this will be done by subsequent calls of
789    inflate().
790 */
791
792 extern int EXPORT inflateSync OF((z_streamp strm));
793 /* 
794     Skips invalid compressed data until the special marker (see deflate()
795   above) can be found, or until all available input is skipped. No output
796   is provided.
797
798     inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
799   if no more input was provided, Z_DATA_ERROR if no marker has been found,
800   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
801   case, the application may save the current current value of total_in which
802   indicates where valid compressed data was found. In the error case, the
803   application may repeatedly call inflateSync, providing more input each time,
804   until success or end of the input data.
805 */
806
807 extern int EXPORT inflateReset OF((z_streamp strm));
808 /*
809      This function is equivalent to inflateEnd followed by inflateInit,
810    but does not free and reallocate all the internal decompression state.
811    The stream will keep attributes that may have been set by inflateInit2.
812
813       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
814    stream state was inconsistent (such as zalloc or state being NULL).
815 */
816
817 extern int inflateIncomp OF((z_stream *strm));
818 /*
819      This function adds the data at next_in (avail_in bytes) to the output
820    history without performing any output.  There must be no pending output,
821    and the decompressor must be expecting to see the start of a block.
822    Calling this function is equivalent to decompressing a stored block
823    containing the data at next_in (except that the data is not output).
824 */
825
826                         /* utility functions */
827
828 /*
829      The following utility functions are implemented on top of the
830    basic stream-oriented functions. To simplify the interface, some
831    default options are assumed (compression level, window size,
832    standard memory allocation functions). The source code of these
833    utility functions can easily be modified if you need special options.
834 */
835
836 extern int EXPORT compress OF((Bytef *dest,   uLongf *destLen,
837                                const Bytef *source, uLong sourceLen));
838 /*
839      Compresses the source buffer into the destination buffer.  sourceLen is
840    the byte length of the source buffer. Upon entry, destLen is the total
841    size of the destination buffer, which must be at least 0.1% larger than
842    sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
843    compressed buffer.
844      This function can be used to compress a whole file at once if the
845    input file is mmap'ed.
846      compress returns Z_OK if success, Z_MEM_ERROR if there was not
847    enough memory, Z_BUF_ERROR if there was not enough room in the output
848    buffer.
849 */
850
851 extern int EXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
852                                  const Bytef *source, uLong sourceLen));
853 /*
854      Decompresses the source buffer into the destination buffer.  sourceLen is
855    the byte length of the source buffer. Upon entry, destLen is the total
856    size of the destination buffer, which must be large enough to hold the
857    entire uncompressed data. (The size of the uncompressed data must have
858    been saved previously by the compressor and transmitted to the decompressor
859    by some mechanism outside the scope of this compression library.)
860    Upon exit, destLen is the actual size of the compressed buffer.
861      This function can be used to decompress a whole file at once if the
862    input file is mmap'ed.
863
864      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
865    enough memory, Z_BUF_ERROR if there was not enough room in the output
866    buffer, or Z_DATA_ERROR if the input data was corrupted.
867 */
868
869
870 typedef voidp gzFile;
871
872 extern gzFile EXPORT gzopen  OF((const char *path, const char *mode));
873 /*
874      Opens a gzip (.gz) file for reading or writing. The mode parameter
875    is as in fopen ("rb" or "wb") but can also include a compression level
876    ("wb9").  gzopen can be used to read a file which is not in gzip format;
877    in this case gzread will directly read from the file without decompression.
878      gzopen returns NULL if the file could not be opened or if there was
879    insufficient memory to allocate the (de)compression state; errno
880    can be checked to distinguish the two cases (if errno is zero, the
881    zlib error is Z_MEM_ERROR).
882 */
883
884 extern gzFile EXPORT gzdopen  OF((int fd, const char *mode));
885 /*
886      gzdopen() associates a gzFile with the file descriptor fd.  File
887    descriptors are obtained from calls like open, dup, creat, pipe or
888    fileno (in the file has been previously opened with fopen).
889    The mode parameter is as in gzopen.
890      The next call of gzclose on the returned gzFile will also close the
891    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
892    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
893      gzdopen returns NULL if there was insufficient memory to allocate
894    the (de)compression state.
895 */
896
897 extern int EXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
898 /*
899      Reads the given number of uncompressed bytes from the compressed file.
900    If the input file was not in gzip format, gzread copies the given number
901    of bytes into the buffer.
902      gzread returns the number of uncompressed bytes actually read (0 for
903    end of file, -1 for error). */
904
905 extern int EXPORT    gzwrite OF((gzFile file, const voidp buf, unsigned len));
906 /*
907      Writes the given number of uncompressed bytes into the compressed file.
908    gzwrite returns the number of uncompressed bytes actually written
909    (0 in case of error).
910 */
911
912 extern int EXPORT    gzflush OF((gzFile file, int flush));
913 /*
914      Flushes all pending output into the compressed file. The parameter
915    flush is as in the deflate() function. The return value is the zlib
916    error number (see function gzerror below). gzflush returns Z_OK if
917    the flush parameter is Z_FINISH and all output could be flushed.
918      gzflush should be called only when strictly necessary because it can
919    degrade compression.
920 */
921
922 extern int EXPORT    gzclose OF((gzFile file));
923 /*
924      Flushes all pending output if necessary, closes the compressed file
925    and deallocates all the (de)compression state. The return value is the zlib
926    error number (see function gzerror below).
927 */
928
929 extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
930 /*
931      Returns the error message for the last error which occurred on the
932    given compressed file. errnum is set to zlib error number. If an
933    error occurred in the file system and not in the compression library,
934    errnum is set to Z_ERRNO and the application may consult errno
935    to get the exact error code.
936 */
937
938                         /* checksum functions */
939
940 /*
941      These functions are not related to compression but are exported
942    anyway because they might be useful in applications using the
943    compression library.
944 */
945
946 extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
947
948 /*
949      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
950    return the updated checksum. If buf is NULL, this function returns
951    the required initial value for the checksum.
952    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
953    much faster. Usage example:
954
955      uLong adler = adler32(0L, Z_NULL, 0);
956
957      while (read_buffer(buffer, length) != EOF) {
958        adler = adler32(adler, buffer, length);
959      }
960      if (adler != original_adler) error();
961 */
962
963 #if 0
964 extern uLong EXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
965 /*
966      Update a running crc with the bytes buf[0..len-1] and return the updated
967    crc. If buf is NULL, this function returns the required initial value
968    for the crc. Pre- and post-conditioning (one's complement) is performed
969    within this function so it shouldn't be done by the application.
970    Usage example:
971
972      uLong crc = crc32(0L, Z_NULL, 0);
973
974      while (read_buffer(buffer, length) != EOF) {
975        crc = crc32(crc, buffer, length);
976      }
977      if (crc != original_crc) error();
978 */
979 #endif
980
981
982                         /* various hacks, don't look :) */
983
984 /* deflateInit and inflateInit are macros to allow checking the zlib version
985  * and the compiler's view of z_stream:
986  */
987 extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
988                                    const char *version, int stream_size));
989 extern int EXPORT inflateInit_ OF((z_streamp strm,
990                                    const char *version, int stream_size));
991 extern int EXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
992                                     int windowBits, int memLevel, int strategy,
993                                     const char *version, int stream_size));
994 extern int EXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
995                                     const char *version, int stream_size));
996 #define deflateInit(strm, level) \
997         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
998 #define inflateInit(strm) \
999         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
1000 #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1001         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1002                       (strategy),           ZLIB_VERSION, sizeof(z_stream))
1003 #define inflateInit2(strm, windowBits) \
1004         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1005
1006 #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
1007     struct internal_state {int dummy;}; /* hack for buggy compilers */
1008 #endif
1009
1010 uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
1011
1012 #ifdef __cplusplus
1013 }
1014 #endif
1015
1016 #endif /* _ZLIB_H */
1017 /* --- zlib.h */