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