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