xref: /rk3399_rockchip-uboot/include/u-boot/zlib.h (revision 3e4d27b06d7484040355e22eec2cbce7335d6dab)
1a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
2dce3d797SGiuseppe CONDORELLI  * This file is derived from zlib.h and zconf.h from the zlib-1.2.3
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
16dce3d797SGiuseppe CONDORELLI   version 1.2.3, July 18th, 2005
17a31e091aSJean-Christophe PLAGNIOL-VILLARD 
18dce3d797SGiuseppe CONDORELLI   Copyright (C) 1995-2005 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
37dce3d797SGiuseppe CONDORELLI   jloup@gzip.org          madler@alumni.caltech.edu
38dce3d797SGiuseppe CONDORELLI 
39dce3d797SGiuseppe CONDORELLI 
40dce3d797SGiuseppe CONDORELLI   The data format used by the zlib library is described by RFCs (Request for
41dce3d797SGiuseppe CONDORELLI   Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
42dce3d797SGiuseppe CONDORELLI   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
43a31e091aSJean-Christophe PLAGNIOL-VILLARD */
44a31e091aSJean-Christophe PLAGNIOL-VILLARD 
45dce3d797SGiuseppe CONDORELLI #ifndef ZLIB_H
46dce3d797SGiuseppe CONDORELLI #define ZLIB_H
47dce3d797SGiuseppe CONDORELLI 
48dce3d797SGiuseppe CONDORELLI #ifdef __cplusplus
49dce3d797SGiuseppe CONDORELLI extern "C" {
50dce3d797SGiuseppe CONDORELLI #endif
51dce3d797SGiuseppe CONDORELLI 
52dce3d797SGiuseppe CONDORELLI #define ZLIB_VERSION "1.2.3"
53dce3d797SGiuseppe CONDORELLI #define ZLIB_VERNUM 0x1230
54a31e091aSJean-Christophe PLAGNIOL-VILLARD 
55a31e091aSJean-Christophe PLAGNIOL-VILLARD /* #include "zconf.h" */        /* included directly here */
56a31e091aSJean-Christophe PLAGNIOL-VILLARD /* zconf.h -- configuration of the zlib compression library
57dce3d797SGiuseppe CONDORELLI  * Copyright (C) 1995-2005 Jean-loup Gailly.
58a31e091aSJean-Christophe PLAGNIOL-VILLARD  * For conditions of distribution and use, see copyright notice in zlib.h
59a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
60a31e091aSJean-Christophe PLAGNIOL-VILLARD 
61dce3d797SGiuseppe CONDORELLI /* Begin of new zconf.h */
62a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
63dce3d797SGiuseppe CONDORELLI  * If you *really* need a unique prefix for all types and library functions,
64dce3d797SGiuseppe CONDORELLI  * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
65a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
66dce3d797SGiuseppe CONDORELLI #ifdef Z_PREFIX
67dce3d797SGiuseppe CONDORELLI #  define deflateInit_          z_deflateInit_
68dce3d797SGiuseppe CONDORELLI #  define deflate               z_deflate
69dce3d797SGiuseppe CONDORELLI #  define deflateEnd            z_deflateEnd
70dce3d797SGiuseppe CONDORELLI #  define inflateInit_          z_inflateInit_
71dce3d797SGiuseppe CONDORELLI #  define inflate               z_inflate
72dce3d797SGiuseppe CONDORELLI #  define inflateEnd            z_inflateEnd
73dce3d797SGiuseppe CONDORELLI #  define deflateInit2_         z_deflateInit2_
74dce3d797SGiuseppe CONDORELLI #  define deflateSetDictionary  z_deflateSetDictionary
75dce3d797SGiuseppe CONDORELLI #  define deflateCopy           z_deflateCopy
76dce3d797SGiuseppe CONDORELLI #  define deflateReset          z_deflateReset
77dce3d797SGiuseppe CONDORELLI #  define deflateParams         z_deflateParams
78dce3d797SGiuseppe CONDORELLI #  define deflateBound          z_deflateBound
79dce3d797SGiuseppe CONDORELLI #  define deflatePrime          z_deflatePrime
80dce3d797SGiuseppe CONDORELLI #  define inflateInit2_         z_inflateInit2_
81dce3d797SGiuseppe CONDORELLI #  define inflateSetDictionary  z_inflateSetDictionary
82dce3d797SGiuseppe CONDORELLI #  define inflateSync           z_inflateSync
83dce3d797SGiuseppe CONDORELLI #  define inflateSyncPoint      z_inflateSyncPoint
84dce3d797SGiuseppe CONDORELLI #  define inflateCopy           z_inflateCopy
85dce3d797SGiuseppe CONDORELLI #  define inflateReset          z_inflateReset
86dce3d797SGiuseppe CONDORELLI #  define inflateBack           z_inflateBack
87dce3d797SGiuseppe CONDORELLI #  define inflateBackEnd        z_inflateBackEnd
88dce3d797SGiuseppe CONDORELLI #  define compress              z_compress
89dce3d797SGiuseppe CONDORELLI #  define compress2             z_compress2
90dce3d797SGiuseppe CONDORELLI #  define compressBound         z_compressBound
91dce3d797SGiuseppe CONDORELLI #  define uncompress            z_uncompress
92dce3d797SGiuseppe CONDORELLI #  define adler32               z_adler32
93dce3d797SGiuseppe CONDORELLI #  define crc32                 z_crc32
94dce3d797SGiuseppe CONDORELLI #  define get_crc_table         z_get_crc_table
95dce3d797SGiuseppe CONDORELLI #  define zError                z_zError
96dce3d797SGiuseppe CONDORELLI 
97dce3d797SGiuseppe CONDORELLI #  define alloc_func            z_alloc_func
98dce3d797SGiuseppe CONDORELLI #  define free_func             z_free_func
99dce3d797SGiuseppe CONDORELLI #  define in_func               z_in_func
100dce3d797SGiuseppe CONDORELLI #  define out_func              z_out_func
101dce3d797SGiuseppe CONDORELLI #  define Byte                  z_Byte
102dce3d797SGiuseppe CONDORELLI #  define uInt                  z_uInt
103dce3d797SGiuseppe CONDORELLI #  define uLong                 z_uLong
104dce3d797SGiuseppe CONDORELLI #  define Bytef                 z_Bytef
105dce3d797SGiuseppe CONDORELLI #  define charf                 z_charf
106dce3d797SGiuseppe CONDORELLI #  define intf                  z_intf
107dce3d797SGiuseppe CONDORELLI #  define uIntf                 z_uIntf
108dce3d797SGiuseppe CONDORELLI #  define uLongf                z_uLongf
109dce3d797SGiuseppe CONDORELLI #  define voidpf                z_voidpf
110dce3d797SGiuseppe CONDORELLI #  define voidp                 z_voidp
111dce3d797SGiuseppe CONDORELLI #endif
112dce3d797SGiuseppe CONDORELLI 
113dce3d797SGiuseppe CONDORELLI #if defined(__MSDOS__) && !defined(MSDOS)
114dce3d797SGiuseppe CONDORELLI #  define MSDOS
115dce3d797SGiuseppe CONDORELLI #endif
116dce3d797SGiuseppe CONDORELLI #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
117dce3d797SGiuseppe CONDORELLI #  define OS2
118dce3d797SGiuseppe CONDORELLI #endif
119dce3d797SGiuseppe CONDORELLI #if defined(_WINDOWS) && !defined(WINDOWS)
120dce3d797SGiuseppe CONDORELLI #  define WINDOWS
121dce3d797SGiuseppe CONDORELLI #endif
122dce3d797SGiuseppe CONDORELLI #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
123dce3d797SGiuseppe CONDORELLI #  ifndef WIN32
124dce3d797SGiuseppe CONDORELLI #    define WIN32
125dce3d797SGiuseppe CONDORELLI #  endif
126dce3d797SGiuseppe CONDORELLI #endif
127dce3d797SGiuseppe CONDORELLI #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
128dce3d797SGiuseppe CONDORELLI #  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
129dce3d797SGiuseppe CONDORELLI #    ifndef SYS16BIT
130dce3d797SGiuseppe CONDORELLI #      define SYS16BIT
131dce3d797SGiuseppe CONDORELLI #    endif
132dce3d797SGiuseppe CONDORELLI #  endif
133dce3d797SGiuseppe CONDORELLI #endif
134a31e091aSJean-Christophe PLAGNIOL-VILLARD 
135a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
136a31e091aSJean-Christophe PLAGNIOL-VILLARD  * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
137a31e091aSJean-Christophe PLAGNIOL-VILLARD  * than 64k bytes at a time (needed on systems with 16-bit int).
138a31e091aSJean-Christophe PLAGNIOL-VILLARD  */
139dce3d797SGiuseppe CONDORELLI #ifdef SYS16BIT
140dce3d797SGiuseppe CONDORELLI #  define MAXSEG_64K
141dce3d797SGiuseppe CONDORELLI #endif
142dce3d797SGiuseppe CONDORELLI #ifdef MSDOS
143dce3d797SGiuseppe CONDORELLI #  define UNALIGNED_OK
144dce3d797SGiuseppe CONDORELLI #endif
145b201171fSGiuseppe CONDORELLI 
146dce3d797SGiuseppe CONDORELLI #ifdef __STDC_VERSION__
147b201171fSGiuseppe CONDORELLI #  ifndef STDC
148f33b325aSWolfgang Denk #    define STDC
149b201171fSGiuseppe CONDORELLI #  endif
150dce3d797SGiuseppe CONDORELLI #  if __STDC_VERSION__ >= 199901L
151dce3d797SGiuseppe CONDORELLI #    ifndef STDC99
152dce3d797SGiuseppe CONDORELLI #      define STDC99
153dce3d797SGiuseppe CONDORELLI #    endif
154dce3d797SGiuseppe CONDORELLI #  endif
155dce3d797SGiuseppe CONDORELLI #endif
156dce3d797SGiuseppe CONDORELLI #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
157dce3d797SGiuseppe CONDORELLI #  define STDC
158dce3d797SGiuseppe CONDORELLI #endif
159dce3d797SGiuseppe CONDORELLI #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
160dce3d797SGiuseppe CONDORELLI #  define STDC
161dce3d797SGiuseppe CONDORELLI #endif
162dce3d797SGiuseppe CONDORELLI #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
163dce3d797SGiuseppe CONDORELLI #  define STDC
164dce3d797SGiuseppe CONDORELLI #endif
165dce3d797SGiuseppe CONDORELLI #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
166dce3d797SGiuseppe CONDORELLI #  define STDC
167b201171fSGiuseppe CONDORELLI #endif
168b201171fSGiuseppe CONDORELLI 
169dce3d797SGiuseppe CONDORELLI #if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */
170dce3d797SGiuseppe CONDORELLI #  define STDC
171dce3d797SGiuseppe CONDORELLI #endif
172dce3d797SGiuseppe CONDORELLI 
173dce3d797SGiuseppe CONDORELLI #ifndef STDC
174dce3d797SGiuseppe CONDORELLI #  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
175dce3d797SGiuseppe CONDORELLI #    define const       /* note: need a more gentle solution here */
176dce3d797SGiuseppe CONDORELLI #  endif
177dce3d797SGiuseppe CONDORELLI #endif
178dce3d797SGiuseppe CONDORELLI 
179dce3d797SGiuseppe CONDORELLI /* Some Mac compilers merge all .h files incorrectly: */
180dce3d797SGiuseppe CONDORELLI #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
181dce3d797SGiuseppe CONDORELLI #  define NO_DUMMY_DECL
182a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
183a31e091aSJean-Christophe PLAGNIOL-VILLARD 
184a31e091aSJean-Christophe PLAGNIOL-VILLARD /* Maximum value for memLevel in deflateInit2 */
185a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef MAX_MEM_LEVEL
186a31e091aSJean-Christophe PLAGNIOL-VILLARD #  ifdef MAXSEG_64K
187a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define MAX_MEM_LEVEL 8
188a31e091aSJean-Christophe PLAGNIOL-VILLARD #  else
189a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define MAX_MEM_LEVEL 9
190a31e091aSJean-Christophe PLAGNIOL-VILLARD #  endif
191a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
192a31e091aSJean-Christophe PLAGNIOL-VILLARD 
193dce3d797SGiuseppe CONDORELLI /* Maximum value for windowBits in deflateInit2 and inflateInit2.
194dce3d797SGiuseppe CONDORELLI  * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
195dce3d797SGiuseppe CONDORELLI  * created by gzip. (Files created by minigzip can still be extracted by
196dce3d797SGiuseppe CONDORELLI  * gzip.)
197dce3d797SGiuseppe CONDORELLI  */
198a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef MAX_WBITS
199a31e091aSJean-Christophe PLAGNIOL-VILLARD #  define MAX_WBITS   15 /* 32K LZ77 window */
200a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
201a31e091aSJean-Christophe PLAGNIOL-VILLARD 
202a31e091aSJean-Christophe PLAGNIOL-VILLARD /* The memory requirements for deflate are (in bytes):
203dce3d797SGiuseppe CONDORELLI             (1 << (windowBits+2)) +  (1 << (memLevel+9))
204a31e091aSJean-Christophe PLAGNIOL-VILLARD  that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
205a31e091aSJean-Christophe PLAGNIOL-VILLARD  plus a few kilobytes for small objects. For example, if you want to reduce
206a31e091aSJean-Christophe PLAGNIOL-VILLARD  the default memory requirements from 256K to 128K, compile with
207a31e091aSJean-Christophe PLAGNIOL-VILLARD      make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
208a31e091aSJean-Christophe PLAGNIOL-VILLARD  Of course this will generally degrade compression (there's no free lunch).
209a31e091aSJean-Christophe PLAGNIOL-VILLARD 
210a31e091aSJean-Christophe PLAGNIOL-VILLARD    The memory requirements for inflate are (in bytes) 1 << windowBits
211a31e091aSJean-Christophe PLAGNIOL-VILLARD  that is, 32K for windowBits=15 (default value) plus a few kilobytes
212a31e091aSJean-Christophe PLAGNIOL-VILLARD  for small objects.
213a31e091aSJean-Christophe PLAGNIOL-VILLARD */
214a31e091aSJean-Christophe PLAGNIOL-VILLARD 
215a31e091aSJean-Christophe PLAGNIOL-VILLARD                         /* Type declarations */
216a31e091aSJean-Christophe PLAGNIOL-VILLARD 
217a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifndef OF /* function prototypes */
218a31e091aSJean-Christophe PLAGNIOL-VILLARD #  ifdef STDC
219a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define OF(args)  args
220a31e091aSJean-Christophe PLAGNIOL-VILLARD #  else
221a31e091aSJean-Christophe PLAGNIOL-VILLARD #    define OF(args)  ()
222a31e091aSJean-Christophe PLAGNIOL-VILLARD #  endif
223a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
224a31e091aSJean-Christophe PLAGNIOL-VILLARD 
225dce3d797SGiuseppe CONDORELLI /* The following definitions for FAR are needed only for MSDOS mixed
226dce3d797SGiuseppe CONDORELLI  * model programming (small or medium model with some far allocations).
227dce3d797SGiuseppe CONDORELLI  * This was tested only with MSC; for other MSDOS compilers you may have
228dce3d797SGiuseppe CONDORELLI  * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
229dce3d797SGiuseppe CONDORELLI  * just define FAR to be empty.
230dce3d797SGiuseppe CONDORELLI  */
231dce3d797SGiuseppe CONDORELLI #ifdef SYS16BIT
232dce3d797SGiuseppe CONDORELLI #  if defined(M_I86SM) || defined(M_I86MM)
233dce3d797SGiuseppe CONDORELLI      /* MSC small or medium model */
234dce3d797SGiuseppe CONDORELLI #    define SMALL_MEDIUM
235dce3d797SGiuseppe CONDORELLI #    ifdef _MSC_VER
236dce3d797SGiuseppe CONDORELLI #      define FAR _far
237dce3d797SGiuseppe CONDORELLI #    else
238dce3d797SGiuseppe CONDORELLI #      define FAR far
239dce3d797SGiuseppe CONDORELLI #    endif
240dce3d797SGiuseppe CONDORELLI #  endif
241dce3d797SGiuseppe CONDORELLI #  if (defined(__SMALL__) || defined(__MEDIUM__))
242dce3d797SGiuseppe CONDORELLI      /* Turbo C small or medium model */
243dce3d797SGiuseppe CONDORELLI #    define SMALL_MEDIUM
244dce3d797SGiuseppe CONDORELLI #    ifdef __BORLANDC__
245dce3d797SGiuseppe CONDORELLI #      define FAR _far
246dce3d797SGiuseppe CONDORELLI #    else
247dce3d797SGiuseppe CONDORELLI #      define FAR far
248dce3d797SGiuseppe CONDORELLI #    endif
249dce3d797SGiuseppe CONDORELLI #  endif
250dce3d797SGiuseppe CONDORELLI #endif
251dce3d797SGiuseppe CONDORELLI 
252dce3d797SGiuseppe CONDORELLI #if defined(WINDOWS) || defined(WIN32)
253dce3d797SGiuseppe CONDORELLI    /* If building or using zlib as a DLL, define ZLIB_DLL.
254dce3d797SGiuseppe CONDORELLI     * This is not mandatory, but it offers a little performance increase.
255dce3d797SGiuseppe CONDORELLI     */
256dce3d797SGiuseppe CONDORELLI #  ifdef ZLIB_DLL
257dce3d797SGiuseppe CONDORELLI #    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
258dce3d797SGiuseppe CONDORELLI #      ifdef ZLIB_INTERNAL
259dce3d797SGiuseppe CONDORELLI #        define ZEXTERN extern __declspec(dllexport)
260dce3d797SGiuseppe CONDORELLI #      else
261dce3d797SGiuseppe CONDORELLI #        define ZEXTERN extern __declspec(dllimport)
262dce3d797SGiuseppe CONDORELLI #      endif
263dce3d797SGiuseppe CONDORELLI #    endif
264dce3d797SGiuseppe CONDORELLI #  endif  /* ZLIB_DLL */
265dce3d797SGiuseppe CONDORELLI    /* If building or using zlib with the WINAPI/WINAPIV calling convention,
266dce3d797SGiuseppe CONDORELLI     * define ZLIB_WINAPI.
267dce3d797SGiuseppe CONDORELLI     * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
268dce3d797SGiuseppe CONDORELLI     */
269dce3d797SGiuseppe CONDORELLI #  ifdef ZLIB_WINAPI
270dce3d797SGiuseppe CONDORELLI #    ifdef FAR
271dce3d797SGiuseppe CONDORELLI #      undef FAR
272dce3d797SGiuseppe CONDORELLI #    endif
273dce3d797SGiuseppe CONDORELLI #    include <windows.h>
274dce3d797SGiuseppe CONDORELLI      /* No need for _export, use ZLIB.DEF instead. */
275dce3d797SGiuseppe CONDORELLI      /* For complete Windows compatibility, use WINAPI, not __stdcall. */
276dce3d797SGiuseppe CONDORELLI #    define ZEXPORT WINAPI
277dce3d797SGiuseppe CONDORELLI #    ifdef WIN32
278dce3d797SGiuseppe CONDORELLI #      define ZEXPORTVA WINAPIV
279dce3d797SGiuseppe CONDORELLI #    else
280dce3d797SGiuseppe CONDORELLI #      define ZEXPORTVA FAR CDECL
281dce3d797SGiuseppe CONDORELLI #    endif
282dce3d797SGiuseppe CONDORELLI #  endif
283dce3d797SGiuseppe CONDORELLI #endif
284dce3d797SGiuseppe CONDORELLI 
285dce3d797SGiuseppe CONDORELLI #if defined (__BEOS__)
286dce3d797SGiuseppe CONDORELLI #  ifdef ZLIB_DLL
287dce3d797SGiuseppe CONDORELLI #    ifdef ZLIB_INTERNAL
288dce3d797SGiuseppe CONDORELLI #      define ZEXPORT   __declspec(dllexport)
289dce3d797SGiuseppe CONDORELLI #      define ZEXPORTVA __declspec(dllexport)
290dce3d797SGiuseppe CONDORELLI #    else
291dce3d797SGiuseppe CONDORELLI #      define ZEXPORT   __declspec(dllimport)
292dce3d797SGiuseppe CONDORELLI #      define ZEXPORTVA __declspec(dllimport)
293dce3d797SGiuseppe CONDORELLI #    endif
294dce3d797SGiuseppe CONDORELLI #  endif
295dce3d797SGiuseppe CONDORELLI #endif
296dce3d797SGiuseppe CONDORELLI 
297dce3d797SGiuseppe CONDORELLI #ifndef ZEXTERN
298dce3d797SGiuseppe CONDORELLI #  define ZEXTERN extern
299dce3d797SGiuseppe CONDORELLI #endif
300dce3d797SGiuseppe CONDORELLI #ifndef ZEXPORT
301dce3d797SGiuseppe CONDORELLI #  define ZEXPORT
302dce3d797SGiuseppe CONDORELLI #endif
303dce3d797SGiuseppe CONDORELLI #ifndef ZEXPORTVA
304dce3d797SGiuseppe CONDORELLI #  define ZEXPORTVA
305dce3d797SGiuseppe CONDORELLI #endif
306dce3d797SGiuseppe CONDORELLI 
307dce3d797SGiuseppe CONDORELLI #ifndef FAR
308dce3d797SGiuseppe CONDORELLI #  define FAR
309dce3d797SGiuseppe CONDORELLI #endif
310dce3d797SGiuseppe CONDORELLI 
311dce3d797SGiuseppe CONDORELLI #if !defined(__MACTYPES__)
312a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef unsigned char  Byte;  /* 8 bits */
313dce3d797SGiuseppe CONDORELLI #endif
314a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef unsigned int   uInt;  /* 16 bits or more */
315a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef unsigned long  uLong; /* 32 bits or more */
316a31e091aSJean-Christophe PLAGNIOL-VILLARD 
317dce3d797SGiuseppe CONDORELLI #ifdef SMALL_MEDIUM
318dce3d797SGiuseppe CONDORELLI    /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
319dce3d797SGiuseppe CONDORELLI #  define Bytef Byte FAR
320dce3d797SGiuseppe CONDORELLI #else
321a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef Byte  FAR Bytef;
322dce3d797SGiuseppe CONDORELLI #endif
323a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef char  FAR charf;
324a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef int   FAR intf;
325a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef uInt  FAR uIntf;
326a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef uLong FAR uLongf;
327a31e091aSJean-Christophe PLAGNIOL-VILLARD 
328a31e091aSJean-Christophe PLAGNIOL-VILLARD #ifdef STDC
329dce3d797SGiuseppe CONDORELLI    typedef void const *voidpc;
330a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef void FAR   *voidpf;
331a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef void       *voidp;
332a31e091aSJean-Christophe PLAGNIOL-VILLARD #else
333dce3d797SGiuseppe CONDORELLI    typedef Byte const *voidpc;
334a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef Byte FAR   *voidpf;
335a31e091aSJean-Christophe PLAGNIOL-VILLARD    typedef Byte       *voidp;
336a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
337a31e091aSJean-Christophe PLAGNIOL-VILLARD 
338dce3d797SGiuseppe CONDORELLI #  ifdef VMS
339dce3d797SGiuseppe CONDORELLI #    include <unixio.h>   /* for off_t */
340dce3d797SGiuseppe CONDORELLI #  endif
341dce3d797SGiuseppe CONDORELLI #  define z_off_t off_t
342dce3d797SGiuseppe CONDORELLI #ifndef SEEK_SET
343dce3d797SGiuseppe CONDORELLI #  define SEEK_SET        0       /* Seek from beginning of file.  */
344dce3d797SGiuseppe CONDORELLI #  define SEEK_CUR        1       /* Seek from current position.  */
345dce3d797SGiuseppe CONDORELLI #  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
346dce3d797SGiuseppe CONDORELLI #endif
347dce3d797SGiuseppe CONDORELLI #ifndef z_off_t
348dce3d797SGiuseppe CONDORELLI #  define z_off_t long
349dce3d797SGiuseppe CONDORELLI #endif
350a31e091aSJean-Christophe PLAGNIOL-VILLARD 
351dce3d797SGiuseppe CONDORELLI #if defined(__OS400__)
352dce3d797SGiuseppe CONDORELLI #  define NO_vsnprintf
353dce3d797SGiuseppe CONDORELLI #endif
354dce3d797SGiuseppe CONDORELLI 
355dce3d797SGiuseppe CONDORELLI #if defined(__MVS__)
356dce3d797SGiuseppe CONDORELLI #  define NO_vsnprintf
357dce3d797SGiuseppe CONDORELLI #  ifdef FAR
358dce3d797SGiuseppe CONDORELLI #    undef FAR
359dce3d797SGiuseppe CONDORELLI #  endif
360dce3d797SGiuseppe CONDORELLI #endif
361dce3d797SGiuseppe CONDORELLI 
362dce3d797SGiuseppe CONDORELLI /* MVS linker does not support external names larger than 8 bytes */
363dce3d797SGiuseppe CONDORELLI #if defined(__MVS__)
364dce3d797SGiuseppe CONDORELLI #   pragma map(deflateInit_,"DEIN")
365dce3d797SGiuseppe CONDORELLI #   pragma map(deflateInit2_,"DEIN2")
366dce3d797SGiuseppe CONDORELLI #   pragma map(deflateEnd,"DEEND")
367dce3d797SGiuseppe CONDORELLI #   pragma map(deflateBound,"DEBND")
368dce3d797SGiuseppe CONDORELLI #   pragma map(inflateInit_,"ININ")
369dce3d797SGiuseppe CONDORELLI #   pragma map(inflateInit2_,"ININ2")
370dce3d797SGiuseppe CONDORELLI #   pragma map(inflateEnd,"INEND")
371dce3d797SGiuseppe CONDORELLI #   pragma map(inflateSync,"INSY")
372dce3d797SGiuseppe CONDORELLI #   pragma map(inflateSetDictionary,"INSEDI")
373dce3d797SGiuseppe CONDORELLI #   pragma map(compressBound,"CMBND")
374dce3d797SGiuseppe CONDORELLI #   pragma map(inflate_table,"INTABL")
375dce3d797SGiuseppe CONDORELLI #   pragma map(inflate_fast,"INFA")
376dce3d797SGiuseppe CONDORELLI #   pragma map(inflate_copyright,"INCOPY")
377dce3d797SGiuseppe CONDORELLI #endif
378dce3d797SGiuseppe CONDORELLI /* End of new zconf.h */
379a31e091aSJean-Christophe PLAGNIOL-VILLARD 
380a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
381a31e091aSJean-Christophe PLAGNIOL-VILLARD      The 'zlib' compression library provides in-memory compression and
382a31e091aSJean-Christophe PLAGNIOL-VILLARD   decompression functions, including integrity checks of the uncompressed
383a31e091aSJean-Christophe PLAGNIOL-VILLARD   data.  This version of the library supports only one compression method
384dce3d797SGiuseppe CONDORELLI   (deflation) but other algorithms will be added later and will have the same
385a31e091aSJean-Christophe PLAGNIOL-VILLARD   stream interface.
386a31e091aSJean-Christophe PLAGNIOL-VILLARD 
387a31e091aSJean-Christophe PLAGNIOL-VILLARD      Compression can be done in a single step if the buffers are large
388a31e091aSJean-Christophe PLAGNIOL-VILLARD   enough (for example if an input file is mmap'ed), or can be done by
389a31e091aSJean-Christophe PLAGNIOL-VILLARD   repeated calls of the compression function.  In the latter case, the
390a31e091aSJean-Christophe PLAGNIOL-VILLARD   application must provide more input and/or consume the output
391a31e091aSJean-Christophe PLAGNIOL-VILLARD   (providing more output space) before each call.
392dce3d797SGiuseppe CONDORELLI 
393dce3d797SGiuseppe CONDORELLI      The compressed data format used by default by the in-memory functions is
394dce3d797SGiuseppe CONDORELLI   the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
395dce3d797SGiuseppe CONDORELLI   around a deflate stream, which is itself documented in RFC 1951.
396dce3d797SGiuseppe CONDORELLI 
397dce3d797SGiuseppe CONDORELLI      The library also supports reading and writing files in gzip (.gz) format
398dce3d797SGiuseppe CONDORELLI   with an interface similar to that of stdio using the functions that start
399dce3d797SGiuseppe CONDORELLI   with "gz".  The gzip format is different from the zlib format.  gzip is a
400dce3d797SGiuseppe CONDORELLI   gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
401dce3d797SGiuseppe CONDORELLI 
402dce3d797SGiuseppe CONDORELLI      This library can optionally read and write gzip streams in memory as well.
403dce3d797SGiuseppe CONDORELLI 
404dce3d797SGiuseppe CONDORELLI      The zlib format was designed to be compact and fast for use in memory
405dce3d797SGiuseppe CONDORELLI   and on communications channels.  The gzip format was designed for single-
406dce3d797SGiuseppe CONDORELLI   file compression on file systems, has a larger header than zlib to maintain
407dce3d797SGiuseppe CONDORELLI   directory information, and uses a different, slower check method than zlib.
408dce3d797SGiuseppe CONDORELLI 
409dce3d797SGiuseppe CONDORELLI      The library does not install any signal handler. The decoder checks
410dce3d797SGiuseppe CONDORELLI   the consistency of the compressed data, so the library should never
411dce3d797SGiuseppe CONDORELLI   crash even in case of corrupted input.
412a31e091aSJean-Christophe PLAGNIOL-VILLARD */
413a31e091aSJean-Christophe PLAGNIOL-VILLARD 
414a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
415dce3d797SGiuseppe CONDORELLI typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt size));
416a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef void   (*cb_func)    OF((Bytef *buf, uInt len));
417a31e091aSJean-Christophe PLAGNIOL-VILLARD 
418a31e091aSJean-Christophe PLAGNIOL-VILLARD struct internal_state;
419a31e091aSJean-Christophe PLAGNIOL-VILLARD 
420a31e091aSJean-Christophe PLAGNIOL-VILLARD typedef struct z_stream_s {
421a31e091aSJean-Christophe PLAGNIOL-VILLARD 	Bytef	*next_in; /* next input byte */
422a31e091aSJean-Christophe PLAGNIOL-VILLARD 	uInt	avail_in; /* number of bytes available at next_in */
423a31e091aSJean-Christophe PLAGNIOL-VILLARD 	uLong	total_in; /* total nb of input bytes read so far */
424a31e091aSJean-Christophe PLAGNIOL-VILLARD 	Bytef	*next_out; /* next output byte should be put there */
425a31e091aSJean-Christophe PLAGNIOL-VILLARD 	uInt	avail_out; /* remaining free space at next_out */
426a31e091aSJean-Christophe PLAGNIOL-VILLARD 	uLong	total_out; /* total nb of bytes output so far */
427a31e091aSJean-Christophe PLAGNIOL-VILLARD 	char	*msg;	/* last error message, NULL if no error */
428a31e091aSJean-Christophe PLAGNIOL-VILLARD 	struct	internal_state FAR *state; /* not visible by applications */
429a31e091aSJean-Christophe PLAGNIOL-VILLARD 	alloc_func	zalloc;	/* used to allocate the internal state */
430a31e091aSJean-Christophe PLAGNIOL-VILLARD 	free_func	zfree;	/* used to free the internal state */
431dce3d797SGiuseppe CONDORELLI 	voidpf	opaque;	/* private data object passed to zalloc and zfree */
432dce3d797SGiuseppe CONDORELLI 	int	data_type;	/* best guess about the data type:
433dce3d797SGiuseppe CONDORELLI 					binary or text */
434a31e091aSJean-Christophe PLAGNIOL-VILLARD 	cb_func	outcb;	/* called regularly just before blocks of output */
435dce3d797SGiuseppe CONDORELLI 	uLong	adler;	/* adler32 value of the uncompressed data */
436dce3d797SGiuseppe CONDORELLI 	uLong	reserved;	/* reserved for future use */
437a31e091aSJean-Christophe PLAGNIOL-VILLARD } z_stream;
438a31e091aSJean-Christophe PLAGNIOL-VILLARD 
439dce3d797SGiuseppe CONDORELLI typedef z_stream FAR *z_streamp;
440dce3d797SGiuseppe CONDORELLI 
441a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
442dce3d797SGiuseppe CONDORELLI      gzip header information passed to and from zlib routines.  See RFC 1952
443dce3d797SGiuseppe CONDORELLI   for more details on the meanings of these fields.
444f33b325aSWolfgang Denk */
445dce3d797SGiuseppe CONDORELLI typedef struct gz_header_s {
446dce3d797SGiuseppe CONDORELLI 	int	text;	/* true if compressed data believed to be text */
447dce3d797SGiuseppe CONDORELLI 	uLong	time;	/* modification time */
448dce3d797SGiuseppe CONDORELLI 	int	xflags;	/* extra flags (not used when writing a gzip file) */
449dce3d797SGiuseppe CONDORELLI 	int	os;	/* operating system */
450dce3d797SGiuseppe CONDORELLI 	Bytef	*extra;	/* pointer to extra field or Z_NULL if none */
451dce3d797SGiuseppe CONDORELLI 	uInt	extra_len; /* extra field length (valid if extra != Z_NULL) */
452dce3d797SGiuseppe CONDORELLI 	uInt	extra_max; /* space at extra (only when reading header) */
453dce3d797SGiuseppe CONDORELLI 	Bytef	*name; /* pointer to zero-terminated file name or Z_NULL */
454dce3d797SGiuseppe CONDORELLI 	uInt	name_max; /* space at name (only when reading header) */
455dce3d797SGiuseppe CONDORELLI 	Bytef	*comment; /* pointer to zero-terminated comment or Z_NULL */
456dce3d797SGiuseppe CONDORELLI 	uInt	comm_max; /* space at comment (only when reading header) */
457dce3d797SGiuseppe CONDORELLI 	int	hcrc; /* true if there was or will be a header crc */
458dce3d797SGiuseppe CONDORELLI 	int	done; /* true when done reading gzip header (not used
459dce3d797SGiuseppe CONDORELLI 			when writing a gzip file) */
460dce3d797SGiuseppe CONDORELLI } gz_header;
461dce3d797SGiuseppe CONDORELLI 
462dce3d797SGiuseppe CONDORELLI typedef gz_header FAR *gz_headerp;
463a31e091aSJean-Christophe PLAGNIOL-VILLARD 
464a31e091aSJean-Christophe PLAGNIOL-VILLARD                         /* constants */
465a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_NO_FLUSH      0
466dce3d797SGiuseppe CONDORELLI #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
467dce3d797SGiuseppe CONDORELLI #define Z_SYNC_FLUSH    2
468dce3d797SGiuseppe CONDORELLI #define Z_FULL_FLUSH    3
469a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_FINISH        4
470dce3d797SGiuseppe CONDORELLI #define Z_BLOCK         5
471dce3d797SGiuseppe CONDORELLI /* Allowed flush values; see deflate() and inflate() below for details */
472a31e091aSJean-Christophe PLAGNIOL-VILLARD 
473a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_OK            0
474a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_STREAM_END    1
475dce3d797SGiuseppe CONDORELLI #define Z_NEED_DICT     2
476a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_ERRNO        (-1)
477a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_STREAM_ERROR (-2)
478a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_DATA_ERROR   (-3)
479a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_MEM_ERROR    (-4)
480a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BUF_ERROR    (-5)
481dce3d797SGiuseppe CONDORELLI #define Z_VERSION_ERROR (-6)
482dce3d797SGiuseppe CONDORELLI /* Return codes for the compression/decompression functions. Negative
483dce3d797SGiuseppe CONDORELLI  * values are errors, positive values are used for special but normal events.
484dce3d797SGiuseppe CONDORELLI  */
485a31e091aSJean-Christophe PLAGNIOL-VILLARD 
486dce3d797SGiuseppe CONDORELLI #define Z_NO_COMPRESSION         0
487a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BEST_SPEED             1
488a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BEST_COMPRESSION       9
489a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_DEFAULT_COMPRESSION  (-1)
490a31e091aSJean-Christophe PLAGNIOL-VILLARD /* compression levels */
491a31e091aSJean-Christophe PLAGNIOL-VILLARD 
492a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_FILTERED            1
493a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_HUFFMAN_ONLY        2
494dce3d797SGiuseppe CONDORELLI #define Z_RLE                 3
495dce3d797SGiuseppe CONDORELLI #define Z_FIXED               4
496a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_DEFAULT_STRATEGY    0
497dce3d797SGiuseppe CONDORELLI /* compression strategy; see deflateInit2() below for details */
498a31e091aSJean-Christophe PLAGNIOL-VILLARD 
499a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_BINARY   0
500dce3d797SGiuseppe CONDORELLI #define Z_TEXT     1
501dce3d797SGiuseppe CONDORELLI #define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
502a31e091aSJean-Christophe PLAGNIOL-VILLARD #define Z_UNKNOWN  2
503dce3d797SGiuseppe CONDORELLI /* Possible values of the data_type field (though see inflate()) */
504dce3d797SGiuseppe CONDORELLI 
505dce3d797SGiuseppe CONDORELLI #define Z_DEFLATED   8
506dce3d797SGiuseppe CONDORELLI /* The deflate compression method (the only one supported in this version) */
507a31e091aSJean-Christophe PLAGNIOL-VILLARD 
508*ee820b5eSKim Phillips #define Z_NULL  (void *)0  /* for initializing zalloc, zfree, opaque */
509a31e091aSJean-Christophe PLAGNIOL-VILLARD 
510f33b325aSWolfgang Denk                         /* basic functions */
511a31e091aSJean-Christophe PLAGNIOL-VILLARD 
512dce3d797SGiuseppe CONDORELLI /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
513dce3d797SGiuseppe CONDORELLI    If the first character differs, the library code actually used is
514dce3d797SGiuseppe CONDORELLI    not compatible with the zlib.h header file used by the application.
515dce3d797SGiuseppe CONDORELLI    This check is automatically made by deflateInit and inflateInit.
516f33b325aSWolfgang Denk    */
517f33b325aSWolfgang Denk 
5187a32b98dSLei Wen ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
5197a32b98dSLei Wen ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
5207a32b98dSLei Wen 			const char *version, int stream_size));
5217a32b98dSLei Wen ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
5227a32b98dSLei Wen ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
5237a32b98dSLei Wen 			int windowBits, int memLevel,
5247a32b98dSLei Wen 			int strategy, const char *version,
525dce3d797SGiuseppe CONDORELLI 			int stream_size));
5267a32b98dSLei Wen ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
5277a32b98dSLei Wen ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
5287a32b98dSLei Wen 			const Bytef *dictionary,
5297a32b98dSLei Wen 			uInt  dictLength));
5307a32b98dSLei Wen ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
5317a32b98dSLei Wen 			gz_headerp head));
5327a32b98dSLei Wen ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
5337a32b98dSLei Wen 			int bits,
5347a32b98dSLei Wen 			int value));
5357a32b98dSLei Wen ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
5367a32b98dSLei Wen 			int level,
5377a32b98dSLei Wen 			int strategy));
5387a32b98dSLei Wen ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
5397a32b98dSLei Wen 			int good_length,
5407a32b98dSLei Wen 			int max_lazy,
5417a32b98dSLei Wen 			int nice_length,
5427a32b98dSLei Wen 			int max_chain));
5437a32b98dSLei Wen ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
5447a32b98dSLei Wen 			uLong sourceLen));
5457a32b98dSLei Wen ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
5467a32b98dSLei Wen 			z_streamp source));
547f33b325aSWolfgang Denk 
5487a32b98dSLei Wen 
5497a32b98dSLei Wen ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
5507a32b98dSLei Wen 			const char *version, int stream_size));
551dce3d797SGiuseppe CONDORELLI ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
552f33b325aSWolfgang Denk /*
553dce3d797SGiuseppe CONDORELLI     inflate decompresses as much data as possible, and stops when the input
554dce3d797SGiuseppe CONDORELLI   buffer becomes empty or the output buffer becomes full. It may introduce
555dce3d797SGiuseppe CONDORELLI   some output latency (reading input without producing any output) except when
556dce3d797SGiuseppe CONDORELLI   forced to flush.
557dce3d797SGiuseppe CONDORELLI 
558dce3d797SGiuseppe CONDORELLI   The detailed semantics are as follows. inflate performs one or both of the
559dce3d797SGiuseppe CONDORELLI   following actions:
560a31e091aSJean-Christophe PLAGNIOL-VILLARD 
561a31e091aSJean-Christophe PLAGNIOL-VILLARD   - Decompress more input starting at next_in and update next_in and avail_in
562a31e091aSJean-Christophe PLAGNIOL-VILLARD     accordingly. If not all input can be processed (because there is not
563a31e091aSJean-Christophe PLAGNIOL-VILLARD     enough room in the output buffer), next_in is updated and processing
564a31e091aSJean-Christophe PLAGNIOL-VILLARD     will resume at this point for the next call of inflate().
565a31e091aSJean-Christophe PLAGNIOL-VILLARD 
566a31e091aSJean-Christophe PLAGNIOL-VILLARD   - Provide more output starting at next_out and update next_out and avail_out
567dce3d797SGiuseppe CONDORELLI     accordingly.  inflate() provides as much output as possible, until there
568dce3d797SGiuseppe CONDORELLI     is no more input data or no more space in the output buffer (see below
569dce3d797SGiuseppe CONDORELLI     about the flush parameter).
570a31e091aSJean-Christophe PLAGNIOL-VILLARD 
571a31e091aSJean-Christophe PLAGNIOL-VILLARD   Before the call of inflate(), the application should ensure that at least
572a31e091aSJean-Christophe PLAGNIOL-VILLARD   one of the actions is possible, by providing more input and/or consuming
573a31e091aSJean-Christophe PLAGNIOL-VILLARD   more output, and updating the next_* and avail_* values accordingly.
574a31e091aSJean-Christophe PLAGNIOL-VILLARD   The application can consume the uncompressed output when it wants, for
575a31e091aSJean-Christophe PLAGNIOL-VILLARD   example when the output buffer is full (avail_out == 0), or after each
576dce3d797SGiuseppe CONDORELLI   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
577dce3d797SGiuseppe CONDORELLI   must be called again after making room in the output buffer because there
578dce3d797SGiuseppe CONDORELLI   might be more output pending.
579a31e091aSJean-Christophe PLAGNIOL-VILLARD 
580dce3d797SGiuseppe CONDORELLI     The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
581dce3d797SGiuseppe CONDORELLI   Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
582dce3d797SGiuseppe CONDORELLI   output as possible to the output buffer. Z_BLOCK requests that inflate() stop
583dce3d797SGiuseppe CONDORELLI   if and when it gets to the next deflate block boundary. When decoding the
584dce3d797SGiuseppe CONDORELLI   zlib or gzip format, this will cause inflate() to return immediately after
585dce3d797SGiuseppe CONDORELLI   the header and before the first block. When doing a raw inflate, inflate()
586dce3d797SGiuseppe CONDORELLI   will go ahead and process the first block, and will return when it gets to
587dce3d797SGiuseppe CONDORELLI   the end of that block, or when it runs out of data.
588dce3d797SGiuseppe CONDORELLI 
589dce3d797SGiuseppe CONDORELLI     The Z_BLOCK option assists in appending to or combining deflate streams.
590dce3d797SGiuseppe CONDORELLI   Also to assist in this, on return inflate() will set strm->data_type to the
591dce3d797SGiuseppe CONDORELLI   number of unused bits in the last byte taken from strm->next_in, plus 64
592dce3d797SGiuseppe CONDORELLI   if inflate() is currently decoding the last block in the deflate stream,
593dce3d797SGiuseppe CONDORELLI   plus 128 if inflate() returned immediately after decoding an end-of-block
594dce3d797SGiuseppe CONDORELLI   code or decoding the complete header up to just before the first byte of the
595dce3d797SGiuseppe CONDORELLI   deflate stream. The end-of-block will not be indicated until all of the
596dce3d797SGiuseppe CONDORELLI   uncompressed data from that block has been written to strm->next_out.  The
597dce3d797SGiuseppe CONDORELLI   number of unused bits may in general be greater than seven, except when
598dce3d797SGiuseppe CONDORELLI   bit 7 of data_type is set, in which case the number of unused bits will be
599dce3d797SGiuseppe CONDORELLI   less than eight.
600a31e091aSJean-Christophe PLAGNIOL-VILLARD 
601a31e091aSJean-Christophe PLAGNIOL-VILLARD     inflate() should normally be called until it returns Z_STREAM_END or an
602a31e091aSJean-Christophe PLAGNIOL-VILLARD   error. However if all decompression is to be performed in a single step
603a31e091aSJean-Christophe PLAGNIOL-VILLARD   (a single call of inflate), the parameter flush should be set to
604a31e091aSJean-Christophe PLAGNIOL-VILLARD   Z_FINISH. In this case all pending input is processed and all pending
605a31e091aSJean-Christophe PLAGNIOL-VILLARD   output is flushed; avail_out must be large enough to hold all the
606a31e091aSJean-Christophe PLAGNIOL-VILLARD   uncompressed data. (The size of the uncompressed data may have been saved
607a31e091aSJean-Christophe PLAGNIOL-VILLARD   by the compressor for this purpose.) The next operation on this stream must
608a31e091aSJean-Christophe PLAGNIOL-VILLARD   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
609dce3d797SGiuseppe CONDORELLI   is never required, but can be used to inform inflate that a faster approach
610a31e091aSJean-Christophe PLAGNIOL-VILLARD   may be used for the single inflate() call.
611a31e091aSJean-Christophe PLAGNIOL-VILLARD 
612dce3d797SGiuseppe CONDORELLI      In this implementation, inflate() always flushes as much output as
613dce3d797SGiuseppe CONDORELLI   possible to the output buffer, and always uses the faster approach on the
614dce3d797SGiuseppe CONDORELLI   first call. So the only effect of the flush parameter in this implementation
615dce3d797SGiuseppe CONDORELLI   is on the return value of inflate(), as noted below, or when it returns early
616dce3d797SGiuseppe CONDORELLI   because Z_BLOCK is used.
617a31e091aSJean-Christophe PLAGNIOL-VILLARD 
618dce3d797SGiuseppe CONDORELLI      If a preset dictionary is needed after this call (see inflateSetDictionary
619dce3d797SGiuseppe CONDORELLI   below), inflate sets strm->adler to the adler32 checksum of the dictionary
620dce3d797SGiuseppe CONDORELLI   chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
621dce3d797SGiuseppe CONDORELLI   strm->adler to the adler32 checksum of all output produced so far (that is,
622dce3d797SGiuseppe CONDORELLI   total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
623dce3d797SGiuseppe CONDORELLI   below. At the end of the stream, inflate() checks that its computed adler32
624dce3d797SGiuseppe CONDORELLI   checksum is equal to that saved by the compressor and returns Z_STREAM_END
625dce3d797SGiuseppe CONDORELLI   only if the checksum is correct.
626a31e091aSJean-Christophe PLAGNIOL-VILLARD 
627dce3d797SGiuseppe CONDORELLI     inflate() will decompress and check either zlib-wrapped or gzip-wrapped
628dce3d797SGiuseppe CONDORELLI   deflate data.  The header type is detected automatically.  Any information
629dce3d797SGiuseppe CONDORELLI   contained in the gzip header is not retained, so applications that need that
630dce3d797SGiuseppe CONDORELLI   information should instead use raw inflate, see inflateInit2() below, or
631dce3d797SGiuseppe CONDORELLI   inflateBack() and perform their own processing of the gzip header and
632dce3d797SGiuseppe CONDORELLI   trailer.
633dce3d797SGiuseppe CONDORELLI 
634dce3d797SGiuseppe CONDORELLI     inflate() returns Z_OK if some progress has been made (more input processed
635dce3d797SGiuseppe CONDORELLI   or more output produced), Z_STREAM_END if the end of the compressed data has
636dce3d797SGiuseppe CONDORELLI   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
637dce3d797SGiuseppe CONDORELLI   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
638dce3d797SGiuseppe CONDORELLI   corrupted (input stream not conforming to the zlib format or incorrect check
639dce3d797SGiuseppe CONDORELLI   value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
640dce3d797SGiuseppe CONDORELLI   if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
641dce3d797SGiuseppe CONDORELLI   Z_BUF_ERROR if no progress is possible or if there was not enough room in the
642dce3d797SGiuseppe CONDORELLI   output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
643dce3d797SGiuseppe CONDORELLI   inflate() can be called again with more input and more output space to
644dce3d797SGiuseppe CONDORELLI   continue decompressing. If Z_DATA_ERROR is returned, the application may then
645dce3d797SGiuseppe CONDORELLI   call inflateSync() to look for a good compression block if a partial recovery
646dce3d797SGiuseppe CONDORELLI   of the data is desired.
647dce3d797SGiuseppe CONDORELLI */
648dce3d797SGiuseppe CONDORELLI 
649dce3d797SGiuseppe CONDORELLI ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
650a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
651a31e091aSJean-Christophe PLAGNIOL-VILLARD      All dynamically allocated data structures for this stream are freed.
652a31e091aSJean-Christophe PLAGNIOL-VILLARD    This function discards any unprocessed input and does not flush any
653a31e091aSJean-Christophe PLAGNIOL-VILLARD    pending output.
654a31e091aSJean-Christophe PLAGNIOL-VILLARD 
655a31e091aSJean-Christophe PLAGNIOL-VILLARD      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
656a31e091aSJean-Christophe PLAGNIOL-VILLARD    was inconsistent. In the error case, msg may be set but then points to a
657a31e091aSJean-Christophe PLAGNIOL-VILLARD    static string (which must not be deallocated).
658a31e091aSJean-Christophe PLAGNIOL-VILLARD */
659a31e091aSJean-Christophe PLAGNIOL-VILLARD 
660dce3d797SGiuseppe CONDORELLI                         /* Advanced functions */
661a31e091aSJean-Christophe PLAGNIOL-VILLARD 
662dce3d797SGiuseppe CONDORELLI ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
663f33b325aSWolfgang Denk 
664dce3d797SGiuseppe CONDORELLI                         /* utility functions */
665f33b325aSWolfgang Denk 
666f33b325aSWolfgang Denk /*
667dce3d797SGiuseppe CONDORELLI      The following utility functions are implemented on top of the
668dce3d797SGiuseppe CONDORELLI    basic stream-oriented functions. To simplify the interface, some
669dce3d797SGiuseppe CONDORELLI    default options are assumed (compression level and memory usage,
670dce3d797SGiuseppe CONDORELLI    standard memory allocation functions). The source code of these
671dce3d797SGiuseppe CONDORELLI    utility functions can easily be modified if you need special options.
672f33b325aSWolfgang Denk */
673f33b325aSWolfgang Denk 
674dce3d797SGiuseppe CONDORELLI ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
675a31e091aSJean-Christophe PLAGNIOL-VILLARD /*
676a31e091aSJean-Christophe PLAGNIOL-VILLARD      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
677a31e091aSJean-Christophe PLAGNIOL-VILLARD    return the updated checksum. If buf is NULL, this function returns
678a31e091aSJean-Christophe PLAGNIOL-VILLARD    the required initial value for the checksum.
679a31e091aSJean-Christophe PLAGNIOL-VILLARD    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
680a31e091aSJean-Christophe PLAGNIOL-VILLARD    much faster. Usage example:
681a31e091aSJean-Christophe PLAGNIOL-VILLARD 
682a31e091aSJean-Christophe PLAGNIOL-VILLARD      uLong adler = adler32(0L, Z_NULL, 0);
683a31e091aSJean-Christophe PLAGNIOL-VILLARD 
684a31e091aSJean-Christophe PLAGNIOL-VILLARD      while (read_buffer(buffer, length) != EOF) {
685a31e091aSJean-Christophe PLAGNIOL-VILLARD        adler = adler32(adler, buffer, length);
686a31e091aSJean-Christophe PLAGNIOL-VILLARD      }
687a31e091aSJean-Christophe PLAGNIOL-VILLARD      if (adler != original_adler) error();
688a31e091aSJean-Christophe PLAGNIOL-VILLARD */
689a31e091aSJean-Christophe PLAGNIOL-VILLARD 
690dce3d797SGiuseppe CONDORELLI /*
691dce3d797SGiuseppe CONDORELLI      Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
692dce3d797SGiuseppe CONDORELLI    and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
693dce3d797SGiuseppe CONDORELLI    each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
694dce3d797SGiuseppe CONDORELLI    seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
695dce3d797SGiuseppe CONDORELLI */
696dce3d797SGiuseppe CONDORELLI 
697dce3d797SGiuseppe CONDORELLI ZEXTERN  uInt ZEXPORT crc32  OF((uInt crc, const Bytef *buf, uInt len));
698dce3d797SGiuseppe CONDORELLI /*
699dce3d797SGiuseppe CONDORELLI      Update a running CRC-32 with the bytes buf[0..len-1] and return the
700dce3d797SGiuseppe CONDORELLI    updated CRC-32. If buf is NULL, this function returns the required initial
701dce3d797SGiuseppe CONDORELLI    value for the for the crc. Pre- and post-conditioning (one's complement) is
702dce3d797SGiuseppe CONDORELLI    performed within this function so it shouldn't be done by the application.
703dce3d797SGiuseppe CONDORELLI    Usage example:
704dce3d797SGiuseppe CONDORELLI 
705dce3d797SGiuseppe CONDORELLI      uLong crc = crc32(0L, Z_NULL, 0);
706dce3d797SGiuseppe CONDORELLI 
707dce3d797SGiuseppe CONDORELLI      while (read_buffer(buffer, length) != EOF) {
708dce3d797SGiuseppe CONDORELLI        crc = crc32(crc, buffer, length);
709dce3d797SGiuseppe CONDORELLI      }
710dce3d797SGiuseppe CONDORELLI      if (crc != original_crc) error();
711dce3d797SGiuseppe CONDORELLI */
712dce3d797SGiuseppe CONDORELLI 
713dce3d797SGiuseppe CONDORELLI ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
714dce3d797SGiuseppe CONDORELLI                                       const char *version, int stream_size));
715dce3d797SGiuseppe CONDORELLI #define inflateInit(strm) \
716dce3d797SGiuseppe CONDORELLI 	inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
717dce3d797SGiuseppe CONDORELLI #define inflateInit2(strm, windowBits) \
718dce3d797SGiuseppe CONDORELLI 	inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
719dce3d797SGiuseppe CONDORELLI 
720dce3d797SGiuseppe CONDORELLI #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
721a31e091aSJean-Christophe PLAGNIOL-VILLARD 	struct internal_state {int dummy;}; /* hack for buggy compilers */
722a31e091aSJean-Christophe PLAGNIOL-VILLARD #endif
723a31e091aSJean-Christophe PLAGNIOL-VILLARD 
724e3ed0575SMike Frysinger extern void *gzalloc(void *, unsigned, unsigned);
725e3ed0575SMike Frysinger extern void gzfree(void *, void *, unsigned);
726e3ed0575SMike Frysinger 
727dce3d797SGiuseppe CONDORELLI #ifdef __cplusplus
728dce3d797SGiuseppe CONDORELLI }
729dce3d797SGiuseppe CONDORELLI #endif
730dce3d797SGiuseppe CONDORELLI 
731dce3d797SGiuseppe CONDORELLI #endif /* ZLIB_H */
732