xref: /rk3399_rockchip-uboot/include/u-boot/zlib.h (revision a31e091ad70915278fb15b79d6ae53ea2d44b251)
1*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
2*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * This file is derived from zlib.h and zconf.h from the zlib-0.95
3*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * distribution by Jean-loup Gailly and Mark Adler, with some additions
4*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * by Paul Mackerras to aid in implementing Deflate compression and
5*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * decompression for PPP packets.
6*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
7*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
8*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
9*a31e091aSJean-Christophe PLAGNIOL-VILLARD  *  ==FILEVERSION 960122==
10*a31e091aSJean-Christophe PLAGNIOL-VILLARD  *
11*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * This marker is used by the Linux installation script to determine
12*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * whether an up-to-date version of this file is already installed.
13*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
14*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
15*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* zlib.h -- interface of the 'zlib' general purpose compression library
16*a31e091aSJean-Christophe PLAGNIOL-VILLARD   version 0.95, Aug 16th, 1995.
17*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
18*a31e091aSJean-Christophe PLAGNIOL-VILLARD   Copyright (C) 1995 Jean-loup Gailly and Mark Adler
19*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
20*a31e091aSJean-Christophe PLAGNIOL-VILLARD   This software is provided 'as-is', without any express or implied
21*a31e091aSJean-Christophe PLAGNIOL-VILLARD   warranty.  In no event will the authors be held liable for any damages
22*a31e091aSJean-Christophe PLAGNIOL-VILLARD   arising from the use of this software.
23*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
24*a31e091aSJean-Christophe PLAGNIOL-VILLARD   Permission is granted to anyone to use this software for any purpose,
25*a31e091aSJean-Christophe PLAGNIOL-VILLARD   including commercial applications, and to alter it and redistribute it
26*a31e091aSJean-Christophe PLAGNIOL-VILLARD   freely, subject to the following restrictions:
27*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
28*a31e091aSJean-Christophe PLAGNIOL-VILLARD   1. The origin of this software must not be misrepresented; you must not
29*a31e091aSJean-Christophe PLAGNIOL-VILLARD      claim that you wrote the original software. If you use this software
30*a31e091aSJean-Christophe PLAGNIOL-VILLARD      in a product, an acknowledgment in the product documentation would be
31*a31e091aSJean-Christophe PLAGNIOL-VILLARD      appreciated but is not required.
32*a31e091aSJean-Christophe PLAGNIOL-VILLARD   2. Altered source versions must be plainly marked as such, and must not be
33*a31e091aSJean-Christophe PLAGNIOL-VILLARD      misrepresented as being the original software.
34*a31e091aSJean-Christophe PLAGNIOL-VILLARD   3. This notice may not be removed or altered from any source distribution.
35*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
36*a31e091aSJean-Christophe PLAGNIOL-VILLARD   Jean-loup Gailly        Mark Adler
37*a31e091aSJean-Christophe PLAGNIOL-VILLARD   gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
38*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
39*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
40*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef _ZLIB_H
41*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define _ZLIB_H
42*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
43*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* #include "zconf.h" */	/* included directly here */
44*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
45*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* zconf.h -- configuration of the zlib compression library
46*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * Copyright (C) 1995 Jean-loup Gailly.
47*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * For conditions of distribution and use, see copyright notice in zlib.h
48*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
49*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
50*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
51*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
52*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
53*a31e091aSJean-Christophe PLAGNIOL-VILLARD      The library does not install any signal handler. It is recommended to
54*a31e091aSJean-Christophe PLAGNIOL-VILLARD   add at least a handler for SIGSEGV when decompressing; the library checks
55*a31e091aSJean-Christophe PLAGNIOL-VILLARD   the consistency of the input data whenever possible but may go nuts
56*a31e091aSJean-Christophe PLAGNIOL-VILLARD   for some forms of corrupted input.
57*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
58*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
59*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
60*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
61*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * than 64k bytes at a time (needed on systems with 16-bit int).
62*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
63*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * at addresses which are not a multiple of their size.
64*a31e091aSJean-Christophe PLAGNIOL-VILLARD  * Under DOS, -DFAR=far or -DFAR=__far may be needed.
65*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
66*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
67*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef STDC
68*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
69*a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define STDC
70*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  endif
71*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
72*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
73*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifdef	__MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
74*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  include <unix.h>
75*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
76*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
77*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* Maximum value for memLevel in deflateInit2 */
78*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef MAX_MEM_LEVEL
79*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  ifdef MAXSEG_64K
80*a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define MAX_MEM_LEVEL 8
81*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  else
82*a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define MAX_MEM_LEVEL 9
83*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  endif
84*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
85*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
86*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef FAR
87*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  define FAR
88*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
89*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
90*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* Maximum value for windowBits in deflateInit2 and inflateInit2 */
91*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef MAX_WBITS
92*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  define MAX_WBITS   15 /* 32K LZ77 window */
93*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
94*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
95*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* The memory requirements for deflate are (in bytes):
96*a31e091aSJean-Christophe PLAGNIOL-VILLARD 	    1 << (windowBits+2)   +  1 << (memLevel+9)
97*a31e091aSJean-Christophe PLAGNIOL-VILLARD  that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
98*a31e091aSJean-Christophe PLAGNIOL-VILLARD  plus a few kilobytes for small objects. For example, if you want to reduce
99*a31e091aSJean-Christophe PLAGNIOL-VILLARD  the default memory requirements from 256K to 128K, compile with
100*a31e091aSJean-Christophe PLAGNIOL-VILLARD      make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
101*a31e091aSJean-Christophe PLAGNIOL-VILLARD  Of course this will generally degrade compression (there's no free lunch).
102*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
103*a31e091aSJean-Christophe PLAGNIOL-VILLARD    The memory requirements for inflate are (in bytes) 1 << windowBits
104*a31e091aSJean-Christophe PLAGNIOL-VILLARD  that is, 32K for windowBits=15 (default value) plus a few kilobytes
105*a31e091aSJean-Christophe PLAGNIOL-VILLARD  for small objects.
106*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
107*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
108*a31e091aSJean-Christophe PLAGNIOL-VILLARD 			/* Type declarations */
109*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
110*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef OF /* function prototypes */
111*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  ifdef STDC
112*a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define OF(args)  args
113*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  else
114*a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define OF(args)  ()
115*a31e091aSJean-Christophe PLAGNIOL-VILLARD #  endif
116*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
117*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
118*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef unsigned char  Byte;  /* 8 bits */
119*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef unsigned int   uInt;  /* 16 bits or more */
120*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef unsigned long  uLong; /* 32 bits or more */
121*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
122*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef Byte FAR Bytef;
123*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef char FAR charf;
124*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef int FAR intf;
125*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef uInt FAR uIntf;
126*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef uLong FAR uLongf;
127*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
128*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifdef STDC
129*a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef void FAR *voidpf;
130*a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef void     *voidp;
131*a31e091aSJean-Christophe PLAGNIOL-VILLARD #else
132*a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef Byte FAR *voidpf;
133*a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef Byte     *voidp;
134*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
135*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
136*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* end of original zconf.h */
137*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
138*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define ZLIB_VERSION "0.95P"
139*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
140*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
141*a31e091aSJean-Christophe PLAGNIOL-VILLARD      The 'zlib' compression library provides in-memory compression and
142*a31e091aSJean-Christophe PLAGNIOL-VILLARD   decompression functions, including integrity checks of the uncompressed
143*a31e091aSJean-Christophe PLAGNIOL-VILLARD   data.  This version of the library supports only one compression method
144*a31e091aSJean-Christophe PLAGNIOL-VILLARD   (deflation) but other algorithms may be added later and will have the same
145*a31e091aSJean-Christophe PLAGNIOL-VILLARD   stream interface.
146*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
147*a31e091aSJean-Christophe PLAGNIOL-VILLARD      For compression the application must provide the output buffer and
148*a31e091aSJean-Christophe PLAGNIOL-VILLARD   may optionally provide the input buffer for optimization. For decompression,
149*a31e091aSJean-Christophe PLAGNIOL-VILLARD   the application must provide the input buffer and may optionally provide
150*a31e091aSJean-Christophe PLAGNIOL-VILLARD   the output buffer for optimization.
151*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
152*a31e091aSJean-Christophe PLAGNIOL-VILLARD      Compression can be done in a single step if the buffers are large
153*a31e091aSJean-Christophe PLAGNIOL-VILLARD   enough (for example if an input file is mmap'ed), or can be done by
154*a31e091aSJean-Christophe PLAGNIOL-VILLARD   repeated calls of the compression function.  In the latter case, the
155*a31e091aSJean-Christophe PLAGNIOL-VILLARD   application must provide more input and/or consume the output
156*a31e091aSJean-Christophe PLAGNIOL-VILLARD   (providing more output space) before each call.
157*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
158*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
159*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
160*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt nbytes));
161*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
162*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef void   (*cb_func)    OF((Bytef *buf, uInt len));
163*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
164*a31e091aSJean-Christophe PLAGNIOL-VILLARD struct internal_state;
165*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
166*a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef struct z_stream_s {
167*a31e091aSJean-Christophe PLAGNIOL-VILLARD     Bytef    *next_in;  /* next input byte */
168*a31e091aSJean-Christophe PLAGNIOL-VILLARD     uInt     avail_in;  /* number of bytes available at next_in */
169*a31e091aSJean-Christophe PLAGNIOL-VILLARD     uLong    total_in;  /* total nb of input bytes read so far */
170*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
171*a31e091aSJean-Christophe PLAGNIOL-VILLARD     Bytef    *next_out; /* next output byte should be put there */
172*a31e091aSJean-Christophe PLAGNIOL-VILLARD     uInt     avail_out; /* remaining free space at next_out */
173*a31e091aSJean-Christophe PLAGNIOL-VILLARD     uLong    total_out; /* total nb of bytes output so far */
174*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
175*a31e091aSJean-Christophe PLAGNIOL-VILLARD     char     *msg;      /* last error message, NULL if no error */
176*a31e091aSJean-Christophe PLAGNIOL-VILLARD     struct internal_state FAR *state; /* not visible by applications */
177*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
178*a31e091aSJean-Christophe PLAGNIOL-VILLARD     alloc_func zalloc;  /* used to allocate the internal state */
179*a31e091aSJean-Christophe PLAGNIOL-VILLARD     free_func  zfree;   /* used to free the internal state */
180*a31e091aSJean-Christophe PLAGNIOL-VILLARD     voidp      opaque;  /* private data object passed to zalloc and zfree */
181*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
182*a31e091aSJean-Christophe PLAGNIOL-VILLARD     Byte     data_type; /* best guess about the data type: ascii or binary */
183*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
184*a31e091aSJean-Christophe PLAGNIOL-VILLARD     cb_func  outcb;	/* called regularly just before blocks of output */
185*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
186*a31e091aSJean-Christophe PLAGNIOL-VILLARD } z_stream;
187*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
188*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
189*a31e091aSJean-Christophe PLAGNIOL-VILLARD    The application must update next_in and avail_in when avail_in has
190*a31e091aSJean-Christophe PLAGNIOL-VILLARD    dropped to zero. It must update next_out and avail_out when avail_out
191*a31e091aSJean-Christophe PLAGNIOL-VILLARD    has dropped to zero. The application must initialize zalloc, zfree and
192*a31e091aSJean-Christophe PLAGNIOL-VILLARD    opaque before calling the init function. All other fields are set by the
193*a31e091aSJean-Christophe PLAGNIOL-VILLARD    compression library and must not be updated by the application.
194*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
195*a31e091aSJean-Christophe PLAGNIOL-VILLARD    The opaque value provided by the application will be passed as the first
196*a31e091aSJean-Christophe PLAGNIOL-VILLARD    parameter for calls of zalloc and zfree. This can be useful for custom
197*a31e091aSJean-Christophe PLAGNIOL-VILLARD    memory management. The compression library attaches no meaning to the
198*a31e091aSJean-Christophe PLAGNIOL-VILLARD    opaque value.
199*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
200*a31e091aSJean-Christophe PLAGNIOL-VILLARD    zalloc must return Z_NULL if there is not enough memory for the object.
201*a31e091aSJean-Christophe PLAGNIOL-VILLARD    On 16-bit systems, the functions zalloc and zfree must be able to allocate
202*a31e091aSJean-Christophe PLAGNIOL-VILLARD    exactly 65536 bytes, but will not be required to allocate more than this
203*a31e091aSJean-Christophe PLAGNIOL-VILLARD    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
204*a31e091aSJean-Christophe PLAGNIOL-VILLARD    pointers returned by zalloc for objects of exactly 65536 bytes *must*
205*a31e091aSJean-Christophe PLAGNIOL-VILLARD    have their offset normalized to zero. The default allocation function
206*a31e091aSJean-Christophe PLAGNIOL-VILLARD    provided by this library ensures this (see zutil.c). To reduce memory
207*a31e091aSJean-Christophe PLAGNIOL-VILLARD    requirements and avoid any allocation of 64K objects, at the expense of
208*a31e091aSJean-Christophe PLAGNIOL-VILLARD    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
209*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
210*a31e091aSJean-Christophe PLAGNIOL-VILLARD    The fields total_in and total_out can be used for statistics or
211*a31e091aSJean-Christophe PLAGNIOL-VILLARD    progress reports. After compression, total_in holds the total size of
212*a31e091aSJean-Christophe PLAGNIOL-VILLARD    the uncompressed data and may be saved for use in the decompressor
213*a31e091aSJean-Christophe PLAGNIOL-VILLARD    (particularly if the decompressor wants to decompress everything in
214*a31e091aSJean-Christophe PLAGNIOL-VILLARD    a single step).
215*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
216*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
217*a31e091aSJean-Christophe PLAGNIOL-VILLARD 			/* constants */
218*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
219*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_NO_FLUSH      0
220*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_PARTIAL_FLUSH 1
221*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_FULL_FLUSH    2
222*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_SYNC_FLUSH    3 /* experimental: partial_flush + byte align */
223*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_FINISH        4
224*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_PACKET_FLUSH	5
225*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* See deflate() below for the usage of these constants */
226*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
227*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_OK            0
228*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_STREAM_END    1
229*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_ERRNO        (-1)
230*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_STREAM_ERROR (-2)
231*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_DATA_ERROR   (-3)
232*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_MEM_ERROR    (-4)
233*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BUF_ERROR    (-5)
234*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* error codes for the compression/decompression functions */
235*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
236*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BEST_SPEED             1
237*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BEST_COMPRESSION       9
238*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_DEFAULT_COMPRESSION  (-1)
239*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* compression levels */
240*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
241*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_FILTERED            1
242*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_HUFFMAN_ONLY        2
243*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_DEFAULT_STRATEGY    0
244*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
245*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BINARY   0
246*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_ASCII    1
247*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_UNKNOWN  2
248*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* Used to set the data_type field */
249*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
250*a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
251*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
252*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern char *zlib_version;
253*a31e091aSJean-Christophe PLAGNIOL-VILLARD /* The application can compare zlib_version and ZLIB_VERSION for consistency.
254*a31e091aSJean-Christophe PLAGNIOL-VILLARD    If the first character differs, the library code actually used is
255*a31e091aSJean-Christophe PLAGNIOL-VILLARD    not compatible with the zlib.h header file used by the application.
256*a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
257*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
258*a31e091aSJean-Christophe PLAGNIOL-VILLARD 			/* basic functions */
259*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
260*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflateInit OF((z_stream *strm));
261*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
262*a31e091aSJean-Christophe PLAGNIOL-VILLARD      Initializes the internal stream state for decompression. The fields
263*a31e091aSJean-Christophe PLAGNIOL-VILLARD    zalloc and zfree must be initialized before by the caller.  If zalloc and
264*a31e091aSJean-Christophe PLAGNIOL-VILLARD    zfree are set to Z_NULL, inflateInit updates them to use default allocation
265*a31e091aSJean-Christophe PLAGNIOL-VILLARD    functions.
266*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
267*a31e091aSJean-Christophe PLAGNIOL-VILLARD      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
268*a31e091aSJean-Christophe PLAGNIOL-VILLARD    enough memory.  msg is set to null if there is no error message.
269*a31e091aSJean-Christophe PLAGNIOL-VILLARD    inflateInit does not perform any decompression: this will be done by
270*a31e091aSJean-Christophe PLAGNIOL-VILLARD    inflate().
271*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
272*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
273*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
274*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflate OF((z_stream *strm, int flush));
275*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
276*a31e091aSJean-Christophe PLAGNIOL-VILLARD   Performs one or both of the following actions:
277*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
278*a31e091aSJean-Christophe PLAGNIOL-VILLARD   - Decompress more input starting at next_in and update next_in and avail_in
279*a31e091aSJean-Christophe PLAGNIOL-VILLARD     accordingly. If not all input can be processed (because there is not
280*a31e091aSJean-Christophe PLAGNIOL-VILLARD     enough room in the output buffer), next_in is updated and processing
281*a31e091aSJean-Christophe PLAGNIOL-VILLARD     will resume at this point for the next call of inflate().
282*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
283*a31e091aSJean-Christophe PLAGNIOL-VILLARD   - Provide more output starting at next_out and update next_out and avail_out
284*a31e091aSJean-Christophe PLAGNIOL-VILLARD     accordingly.  inflate() always provides as much output as possible
285*a31e091aSJean-Christophe PLAGNIOL-VILLARD     (until there is no more input data or no more space in the output buffer).
286*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
287*a31e091aSJean-Christophe PLAGNIOL-VILLARD   Before the call of inflate(), the application should ensure that at least
288*a31e091aSJean-Christophe PLAGNIOL-VILLARD   one of the actions is possible, by providing more input and/or consuming
289*a31e091aSJean-Christophe PLAGNIOL-VILLARD   more output, and updating the next_* and avail_* values accordingly.
290*a31e091aSJean-Christophe PLAGNIOL-VILLARD   The application can consume the uncompressed output when it wants, for
291*a31e091aSJean-Christophe PLAGNIOL-VILLARD   example when the output buffer is full (avail_out == 0), or after each
292*a31e091aSJean-Christophe PLAGNIOL-VILLARD   call of inflate().
293*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
294*a31e091aSJean-Christophe PLAGNIOL-VILLARD     If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
295*a31e091aSJean-Christophe PLAGNIOL-VILLARD   inflate flushes as much output as possible to the output buffer. The
296*a31e091aSJean-Christophe PLAGNIOL-VILLARD   flushing behavior of inflate is not specified for values of the flush
297*a31e091aSJean-Christophe PLAGNIOL-VILLARD   parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
298*a31e091aSJean-Christophe PLAGNIOL-VILLARD   current implementation actually flushes as much output as possible
299*a31e091aSJean-Christophe PLAGNIOL-VILLARD   anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
300*a31e091aSJean-Christophe PLAGNIOL-VILLARD   has been consumed, it is expecting to see the length field of a stored
301*a31e091aSJean-Christophe PLAGNIOL-VILLARD   block; if not, it returns Z_DATA_ERROR.
302*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
303*a31e091aSJean-Christophe PLAGNIOL-VILLARD     inflate() should normally be called until it returns Z_STREAM_END or an
304*a31e091aSJean-Christophe PLAGNIOL-VILLARD   error. However if all decompression is to be performed in a single step
305*a31e091aSJean-Christophe PLAGNIOL-VILLARD   (a single call of inflate), the parameter flush should be set to
306*a31e091aSJean-Christophe PLAGNIOL-VILLARD   Z_FINISH. In this case all pending input is processed and all pending
307*a31e091aSJean-Christophe PLAGNIOL-VILLARD   output is flushed; avail_out must be large enough to hold all the
308*a31e091aSJean-Christophe PLAGNIOL-VILLARD   uncompressed data. (The size of the uncompressed data may have been saved
309*a31e091aSJean-Christophe PLAGNIOL-VILLARD   by the compressor for this purpose.) The next operation on this stream must
310*a31e091aSJean-Christophe PLAGNIOL-VILLARD   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
311*a31e091aSJean-Christophe PLAGNIOL-VILLARD   is never required, but can be used to inform inflate that a faster routine
312*a31e091aSJean-Christophe PLAGNIOL-VILLARD   may be used for the single inflate() call.
313*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
314*a31e091aSJean-Christophe PLAGNIOL-VILLARD     inflate() returns Z_OK if some progress has been made (more input
315*a31e091aSJean-Christophe PLAGNIOL-VILLARD   processed or more output produced), Z_STREAM_END if the end of the
316*a31e091aSJean-Christophe PLAGNIOL-VILLARD   compressed data has been reached and all uncompressed output has been
317*a31e091aSJean-Christophe PLAGNIOL-VILLARD   produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
318*a31e091aSJean-Christophe PLAGNIOL-VILLARD   the stream structure was inconsistent (for example if next_in or next_out
319*a31e091aSJean-Christophe PLAGNIOL-VILLARD   was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
320*a31e091aSJean-Christophe PLAGNIOL-VILLARD   progress is possible or if there was not enough room in the output buffer
321*a31e091aSJean-Christophe PLAGNIOL-VILLARD   when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
322*a31e091aSJean-Christophe PLAGNIOL-VILLARD   call inflateSync to look for a good compression block.  */
323*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
324*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
325*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflateEnd OF((z_stream *strm));
326*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
327*a31e091aSJean-Christophe PLAGNIOL-VILLARD      All dynamically allocated data structures for this stream are freed.
328*a31e091aSJean-Christophe PLAGNIOL-VILLARD    This function discards any unprocessed input and does not flush any
329*a31e091aSJean-Christophe PLAGNIOL-VILLARD    pending output.
330*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
331*a31e091aSJean-Christophe PLAGNIOL-VILLARD      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
332*a31e091aSJean-Christophe PLAGNIOL-VILLARD    was inconsistent. In the error case, msg may be set but then points to a
333*a31e091aSJean-Christophe PLAGNIOL-VILLARD    static string (which must not be deallocated).
334*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
335*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
336*a31e091aSJean-Christophe PLAGNIOL-VILLARD 			/* advanced functions */
337*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
338*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflateInit2 OF((z_stream *strm,
339*a31e091aSJean-Christophe PLAGNIOL-VILLARD 			    int  windowBits));
340*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
341*a31e091aSJean-Christophe PLAGNIOL-VILLARD      This is another version of inflateInit with more compression options. The
342*a31e091aSJean-Christophe PLAGNIOL-VILLARD    fields next_out, zalloc and zfree must be initialized before by the caller.
343*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
344*a31e091aSJean-Christophe PLAGNIOL-VILLARD      The windowBits parameter is the base two logarithm of the maximum window
345*a31e091aSJean-Christophe PLAGNIOL-VILLARD    size (the size of the history buffer).  It should be in the range 8..15 for
346*a31e091aSJean-Christophe PLAGNIOL-VILLARD    this version of the library (the value 16 will be allowed soon). The
347*a31e091aSJean-Christophe PLAGNIOL-VILLARD    default value is 15 if inflateInit is used instead. If a compressed stream
348*a31e091aSJean-Christophe PLAGNIOL-VILLARD    with a larger window size is given as input, inflate() will return with
349*a31e091aSJean-Christophe PLAGNIOL-VILLARD    the error code Z_DATA_ERROR instead of trying to allocate a larger window.
350*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
351*a31e091aSJean-Christophe PLAGNIOL-VILLARD      If next_out is not null, the library will use this buffer for the history
352*a31e091aSJean-Christophe PLAGNIOL-VILLARD    buffer; the buffer must either be large enough to hold the entire output
353*a31e091aSJean-Christophe PLAGNIOL-VILLARD    data, or have at least 1<<windowBits bytes.  If next_out is null, the
354*a31e091aSJean-Christophe PLAGNIOL-VILLARD    library will allocate its own buffer (and leave next_out null). next_in
355*a31e091aSJean-Christophe PLAGNIOL-VILLARD    need not be provided here but must be provided by the application for the
356*a31e091aSJean-Christophe PLAGNIOL-VILLARD    next call of inflate().
357*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
358*a31e091aSJean-Christophe PLAGNIOL-VILLARD      If the history buffer is provided by the application, next_out must
359*a31e091aSJean-Christophe PLAGNIOL-VILLARD    never be changed by the application since the decompressor maintains
360*a31e091aSJean-Christophe PLAGNIOL-VILLARD    history information inside this buffer from call to call; the application
361*a31e091aSJean-Christophe PLAGNIOL-VILLARD    can only reset next_out to the beginning of the history buffer when
362*a31e091aSJean-Christophe PLAGNIOL-VILLARD    avail_out is zero and all output has been consumed.
363*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
364*a31e091aSJean-Christophe PLAGNIOL-VILLARD       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
365*a31e091aSJean-Christophe PLAGNIOL-VILLARD    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
366*a31e091aSJean-Christophe PLAGNIOL-VILLARD    windowBits < 8). msg is set to null if there is no error message.
367*a31e091aSJean-Christophe PLAGNIOL-VILLARD    inflateInit2 does not perform any decompression: this will be done by
368*a31e091aSJean-Christophe PLAGNIOL-VILLARD    inflate().
369*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
370*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
371*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflateSync OF((z_stream *strm));
372*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
373*a31e091aSJean-Christophe PLAGNIOL-VILLARD     Skips invalid compressed data until the special marker (see deflate()
374*a31e091aSJean-Christophe PLAGNIOL-VILLARD   above) can be found, or until all available input is skipped. No output
375*a31e091aSJean-Christophe PLAGNIOL-VILLARD   is provided.
376*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
377*a31e091aSJean-Christophe PLAGNIOL-VILLARD     inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
378*a31e091aSJean-Christophe PLAGNIOL-VILLARD   if no more input was provided, Z_DATA_ERROR if no marker has been found,
379*a31e091aSJean-Christophe PLAGNIOL-VILLARD   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
380*a31e091aSJean-Christophe PLAGNIOL-VILLARD   case, the application may save the current current value of total_in which
381*a31e091aSJean-Christophe PLAGNIOL-VILLARD   indicates where valid compressed data was found. In the error case, the
382*a31e091aSJean-Christophe PLAGNIOL-VILLARD   application may repeatedly call inflateSync, providing more input each time,
383*a31e091aSJean-Christophe PLAGNIOL-VILLARD   until success or end of the input data.
384*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
385*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
386*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflateReset OF((z_stream *strm));
387*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
388*a31e091aSJean-Christophe PLAGNIOL-VILLARD      This function is equivalent to inflateEnd followed by inflateInit,
389*a31e091aSJean-Christophe PLAGNIOL-VILLARD    but does not free and reallocate all the internal decompression state.
390*a31e091aSJean-Christophe PLAGNIOL-VILLARD    The stream will keep attributes that may have been set by inflateInit2.
391*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
392*a31e091aSJean-Christophe PLAGNIOL-VILLARD       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
393*a31e091aSJean-Christophe PLAGNIOL-VILLARD    stream state was inconsistent (such as zalloc or state being NULL).
394*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
395*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
396*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern int inflateIncomp OF((z_stream *strm));
397*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
398*a31e091aSJean-Christophe PLAGNIOL-VILLARD      This function adds the data at next_in (avail_in bytes) to the output
399*a31e091aSJean-Christophe PLAGNIOL-VILLARD    history without performing any output.  There must be no pending output,
400*a31e091aSJean-Christophe PLAGNIOL-VILLARD    and the decompressor must be expecting to see the start of a block.
401*a31e091aSJean-Christophe PLAGNIOL-VILLARD    Calling this function is equivalent to decompressing a stored block
402*a31e091aSJean-Christophe PLAGNIOL-VILLARD    containing the data at next_in (except that the data is not output).
403*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
404*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
405*a31e091aSJean-Christophe PLAGNIOL-VILLARD 			/* checksum functions */
406*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
407*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
408*a31e091aSJean-Christophe PLAGNIOL-VILLARD      This function is not related to compression but is exported
409*a31e091aSJean-Christophe PLAGNIOL-VILLARD    anyway because it might be useful in applications using the
410*a31e091aSJean-Christophe PLAGNIOL-VILLARD    compression library.
411*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
412*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
413*a31e091aSJean-Christophe PLAGNIOL-VILLARD extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
414*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
415*a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
416*a31e091aSJean-Christophe PLAGNIOL-VILLARD      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
417*a31e091aSJean-Christophe PLAGNIOL-VILLARD    return the updated checksum. If buf is NULL, this function returns
418*a31e091aSJean-Christophe PLAGNIOL-VILLARD    the required initial value for the checksum.
419*a31e091aSJean-Christophe PLAGNIOL-VILLARD    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
420*a31e091aSJean-Christophe PLAGNIOL-VILLARD    much faster. Usage example:
421*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
422*a31e091aSJean-Christophe PLAGNIOL-VILLARD      uLong adler = adler32(0L, Z_NULL, 0);
423*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
424*a31e091aSJean-Christophe PLAGNIOL-VILLARD      while (read_buffer(buffer, length) != EOF) {
425*a31e091aSJean-Christophe PLAGNIOL-VILLARD        adler = adler32(adler, buffer, length);
426*a31e091aSJean-Christophe PLAGNIOL-VILLARD      }
427*a31e091aSJean-Christophe PLAGNIOL-VILLARD      if (adler != original_adler) error();
428*a31e091aSJean-Christophe PLAGNIOL-VILLARD */
429*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
430*a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef _Z_UTIL_H
431*a31e091aSJean-Christophe PLAGNIOL-VILLARD     struct internal_state {int dummy;}; /* hack for buggy compilers */
432*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
433*a31e091aSJean-Christophe PLAGNIOL-VILLARD 
434*a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif /* _ZLIB_H */
435