blob: b611fe7c799302e6c3bd79e4670347ea8eb9ca79 [file] [log] [blame]
wdenk4a5b6a32001-04-28 17:59:11 +00001/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -04002 * This file is derived from zlib.h and zconf.h from the zlib-1.2.3
wdenk4a5b6a32001-04-28 17:59:11 +00003 * distribution by Jean-loup Gailly and Mark Adler, with some additions
4 * by Paul Mackerras to aid in implementing Deflate compression and
5 * decompression for PPP packets.
6 */
7
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -04008 /*
9 * ==FILEVERSION 960122==
10 *
11 * This marker is used by the Linux installation script to determine
12 * whether an up-to-date version of this file is already installed.
13 */
wdenk4a5b6a32001-04-28 17:59:11 +000014
15/* zlib.h -- interface of the 'zlib' general purpose compression library
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040016 version 1.2.3, July 18th, 2005
wdenk4a5b6a32001-04-28 17:59:11 +000017
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040018 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
wdenk4a5b6a32001-04-28 17:59:11 +000019
20 This software is provided 'as-is', without any express or implied
21 warranty. In no event will the authors be held liable for any damages
22 arising from the use of this software.
23
24 Permission is granted to anyone to use this software for any purpose,
25 including commercial applications, and to alter it and redistribute it
26 freely, subject to the following restrictions:
27
28 1. The origin of this software must not be misrepresented; you must not
29 claim that you wrote the original software. If you use this software
30 in a product, an acknowledgment in the product documentation would be
31 appreciated but is not required.
32 2. Altered source versions must be plainly marked as such, and must not be
33 misrepresented as being the original software.
34 3. This notice may not be removed or altered from any source distribution.
35
36 Jean-loup Gailly Mark Adler
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040037 jloup@gzip.org madler@alumni.caltech.edu
38
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -040039
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040040 The data format used by the zlib library is described by RFCs (Request for
41 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
42 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
43*/
44
45#ifndef ZLIB_H
46#define ZLIB_H
47
48#ifdef __cplusplus
49extern "C" {
50#endif
wdenk4a5b6a32001-04-28 17:59:11 +000051
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040052#define ZLIB_VERSION "1.2.3"
53#define ZLIB_VERNUM 0x1230
wdenk4a5b6a32001-04-28 17:59:11 +000054
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040055/* #include "zconf.h" */ /* included directly here */
wdenk4a5b6a32001-04-28 17:59:11 +000056/* zconf.h -- configuration of the zlib compression library
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040057 * Copyright (C) 1995-2005 Jean-loup Gailly.
wdenk4a5b6a32001-04-28 17:59:11 +000058 * For conditions of distribution and use, see copyright notice in zlib.h
59 */
60
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040061/* Begin of new zconf.h */
wdenk4a5b6a32001-04-28 17:59:11 +000062/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040063 * If you *really* need a unique prefix for all types and library functions,
64 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
wdenk4a5b6a32001-04-28 17:59:11 +000065 */
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040066#ifdef Z_PREFIX
67# define deflateInit_ z_deflateInit_
68# define deflate z_deflate
69# define deflateEnd z_deflateEnd
70# define inflateInit_ z_inflateInit_
71# define inflate z_inflate
72# define inflateEnd z_inflateEnd
73# define deflateInit2_ z_deflateInit2_
74# define deflateSetDictionary z_deflateSetDictionary
75# define deflateCopy z_deflateCopy
76# define deflateReset z_deflateReset
77# define deflateParams z_deflateParams
78# define deflateBound z_deflateBound
79# define deflatePrime z_deflatePrime
80# define inflateInit2_ z_inflateInit2_
81# define inflateSetDictionary z_inflateSetDictionary
82# define inflateSync z_inflateSync
83# define inflateSyncPoint z_inflateSyncPoint
84# define inflateCopy z_inflateCopy
85# define inflateReset z_inflateReset
86# define inflateBack z_inflateBack
87# define inflateBackEnd z_inflateBackEnd
88# define compress z_compress
89# define compress2 z_compress2
90# define compressBound z_compressBound
91# define uncompress z_uncompress
92# define adler32 z_adler32
93# define crc32 z_crc32
94# define get_crc_table z_get_crc_table
95# define zError z_zError
96
97# define alloc_func z_alloc_func
98# define free_func z_free_func
99# define in_func z_in_func
100# define out_func z_out_func
101# define Byte z_Byte
102# define uInt z_uInt
103# define uLong z_uLong
104# define Bytef z_Bytef
105# define charf z_charf
106# define intf z_intf
107# define uIntf z_uIntf
108# define uLongf z_uLongf
109# define voidpf z_voidpf
110# define voidp z_voidp
111#endif
112
113#if defined(__MSDOS__) && !defined(MSDOS)
114# define MSDOS
115#endif
116#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
117# define OS2
118#endif
119#if defined(_WINDOWS) && !defined(WINDOWS)
120# define WINDOWS
121#endif
122#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
123# ifndef WIN32
124# define WIN32
125# endif
126#endif
127#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
128# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
129# ifndef SYS16BIT
130# define SYS16BIT
131# endif
132# endif
133#endif
wdenk4a5b6a32001-04-28 17:59:11 +0000134
135/*
136 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
137 * than 64k bytes at a time (needed on systems with 16-bit int).
wdenk4a5b6a32001-04-28 17:59:11 +0000138 */
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400139#ifdef SYS16BIT
140# define MAXSEG_64K
141#endif
142#ifdef MSDOS
143# define UNALIGNED_OK
144#endif
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400145
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400146#ifdef __STDC_VERSION__
147# ifndef STDC
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200148# define STDC
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400149# endif
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400150# if __STDC_VERSION__ >= 199901L
151# ifndef STDC99
152# define STDC99
153# endif
154# endif
155#endif
156#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
157# define STDC
158#endif
159#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
160# define STDC
161#endif
162#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
163# define STDC
164#endif
165#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
166# define STDC
167#endif
168
169#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
170# define STDC
171#endif
172
173#ifndef STDC
174# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
175# define const /* note: need a more gentle solution here */
176# endif
wdenk4a5b6a32001-04-28 17:59:11 +0000177#endif
178
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400179/* Some Mac compilers merge all .h files incorrectly: */
180#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
181# define NO_DUMMY_DECL
wdenk4a5b6a32001-04-28 17:59:11 +0000182#endif
183
184/* Maximum value for memLevel in deflateInit2 */
185#ifndef MAX_MEM_LEVEL
186# ifdef MAXSEG_64K
187# define MAX_MEM_LEVEL 8
188# else
189# define MAX_MEM_LEVEL 9
190# endif
191#endif
192
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400193/* Maximum value for windowBits in deflateInit2 and inflateInit2.
194 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
195 * created by gzip. (Files created by minigzip can still be extracted by
196 * gzip.)
197 */
wdenk4a5b6a32001-04-28 17:59:11 +0000198#ifndef MAX_WBITS
199# define MAX_WBITS 15 /* 32K LZ77 window */
200#endif
201
202/* The memory requirements for deflate are (in bytes):
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400203 (1 << (windowBits+2)) + (1 << (memLevel+9))
wdenk4a5b6a32001-04-28 17:59:11 +0000204 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
205 plus a few kilobytes for small objects. For example, if you want to reduce
206 the default memory requirements from 256K to 128K, compile with
207 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
208 Of course this will generally degrade compression (there's no free lunch).
209
210 The memory requirements for inflate are (in bytes) 1 << windowBits
211 that is, 32K for windowBits=15 (default value) plus a few kilobytes
212 for small objects.
213*/
214
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400215 /* Type declarations */
wdenk4a5b6a32001-04-28 17:59:11 +0000216
217#ifndef OF /* function prototypes */
218# ifdef STDC
219# define OF(args) args
220# else
221# define OF(args) ()
222# endif
223#endif
224
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400225/* The following definitions for FAR are needed only for MSDOS mixed
226 * model programming (small or medium model with some far allocations).
227 * This was tested only with MSC; for other MSDOS compilers you may have
228 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
229 * just define FAR to be empty.
230 */
231#ifdef SYS16BIT
232# if defined(M_I86SM) || defined(M_I86MM)
233 /* MSC small or medium model */
234# define SMALL_MEDIUM
235# ifdef _MSC_VER
236# define FAR _far
237# else
238# define FAR far
239# endif
240# endif
241# if (defined(__SMALL__) || defined(__MEDIUM__))
242 /* Turbo C small or medium model */
243# define SMALL_MEDIUM
244# ifdef __BORLANDC__
245# define FAR _far
246# else
247# define FAR far
248# endif
249# endif
250#endif
251
252#if defined(WINDOWS) || defined(WIN32)
253 /* If building or using zlib as a DLL, define ZLIB_DLL.
254 * This is not mandatory, but it offers a little performance increase.
255 */
256# ifdef ZLIB_DLL
257# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
258# ifdef ZLIB_INTERNAL
259# define ZEXTERN extern __declspec(dllexport)
260# else
261# define ZEXTERN extern __declspec(dllimport)
262# endif
263# endif
264# endif /* ZLIB_DLL */
265 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
266 * define ZLIB_WINAPI.
267 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
268 */
269# ifdef ZLIB_WINAPI
270# ifdef FAR
271# undef FAR
272# endif
273# include <windows.h>
274 /* No need for _export, use ZLIB.DEF instead. */
275 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
276# define ZEXPORT WINAPI
277# ifdef WIN32
278# define ZEXPORTVA WINAPIV
279# else
280# define ZEXPORTVA FAR CDECL
281# endif
282# endif
283#endif
284
285#if defined (__BEOS__)
286# ifdef ZLIB_DLL
287# ifdef ZLIB_INTERNAL
288# define ZEXPORT __declspec(dllexport)
289# define ZEXPORTVA __declspec(dllexport)
290# else
291# define ZEXPORT __declspec(dllimport)
292# define ZEXPORTVA __declspec(dllimport)
293# endif
294# endif
295#endif
296
297#ifndef ZEXTERN
298# define ZEXTERN extern
299#endif
300#ifndef ZEXPORT
301# define ZEXPORT
302#endif
303#ifndef ZEXPORTVA
304# define ZEXPORTVA
305#endif
306
307#ifndef FAR
308# define FAR
309#endif
310
311#if !defined(__MACTYPES__)
wdenk4a5b6a32001-04-28 17:59:11 +0000312typedef unsigned char Byte; /* 8 bits */
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400313#endif
wdenk4a5b6a32001-04-28 17:59:11 +0000314typedef unsigned int uInt; /* 16 bits or more */
315typedef unsigned long uLong; /* 32 bits or more */
316
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400317#ifdef SMALL_MEDIUM
318 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
319# define Bytef Byte FAR
320#else
321 typedef Byte FAR Bytef;
322#endif
323typedef char FAR charf;
324typedef int FAR intf;
325typedef uInt FAR uIntf;
wdenk4a5b6a32001-04-28 17:59:11 +0000326typedef uLong FAR uLongf;
327
328#ifdef STDC
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400329 typedef void const *voidpc;
330 typedef void FAR *voidpf;
331 typedef void *voidp;
wdenk4a5b6a32001-04-28 17:59:11 +0000332#else
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400333 typedef Byte const *voidpc;
334 typedef Byte FAR *voidpf;
335 typedef Byte *voidp;
336#endif
337
338# ifdef VMS
339# include <unixio.h> /* for off_t */
340# endif
341# define z_off_t off_t
342#ifndef SEEK_SET
343# define SEEK_SET 0 /* Seek from beginning of file. */
344# define SEEK_CUR 1 /* Seek from current position. */
345# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
346#endif
347#ifndef z_off_t
348# define z_off_t long
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400349#endif
350
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400351#if defined(__OS400__)
352# define NO_vsnprintf
353#endif
354
355#if defined(__MVS__)
356# define NO_vsnprintf
357# ifdef FAR
358# undef FAR
359# endif
360#endif
wdenk4a5b6a32001-04-28 17:59:11 +0000361
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400362/* MVS linker does not support external names larger than 8 bytes */
363#if defined(__MVS__)
364# pragma map(deflateInit_,"DEIN")
365# pragma map(deflateInit2_,"DEIN2")
366# pragma map(deflateEnd,"DEEND")
367# pragma map(deflateBound,"DEBND")
368# pragma map(inflateInit_,"ININ")
369# pragma map(inflateInit2_,"ININ2")
370# pragma map(inflateEnd,"INEND")
371# pragma map(inflateSync,"INSY")
372# pragma map(inflateSetDictionary,"INSEDI")
373# pragma map(compressBound,"CMBND")
374# pragma map(inflate_table,"INTABL")
375# pragma map(inflate_fast,"INFA")
376# pragma map(inflate_copyright,"INCOPY")
377#endif
378/* End of new zconf.h */
wdenk4a5b6a32001-04-28 17:59:11 +0000379
380/*
381 The 'zlib' compression library provides in-memory compression and
382 decompression functions, including integrity checks of the uncompressed
383 data. This version of the library supports only one compression method
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400384 (deflation) but other algorithms will be added later and will have the same
wdenk4a5b6a32001-04-28 17:59:11 +0000385 stream interface.
386
wdenk4a5b6a32001-04-28 17:59:11 +0000387 Compression can be done in a single step if the buffers are large
388 enough (for example if an input file is mmap'ed), or can be done by
389 repeated calls of the compression function. In the latter case, the
390 application must provide more input and/or consume the output
391 (providing more output space) before each call.
wdenk4a5b6a32001-04-28 17:59:11 +0000392
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400393 The compressed data format used by default by the in-memory functions is
394 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
395 around a deflate stream, which is itself documented in RFC 1951.
wdenk4a5b6a32001-04-28 17:59:11 +0000396
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400397 The library also supports reading and writing files in gzip (.gz) format
398 with an interface similar to that of stdio using the functions that start
399 with "gz". The gzip format is different from the zlib format. gzip is a
400 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200401
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400402 This library can optionally read and write gzip streams in memory as well.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200403
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400404 The zlib format was designed to be compact and fast for use in memory
405 and on communications channels. The gzip format was designed for single-
406 file compression on file systems, has a larger header than zlib to maintain
407 directory information, and uses a different, slower check method than zlib.
wdenk4a5b6a32001-04-28 17:59:11 +0000408
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400409 The library does not install any signal handler. The decoder checks
410 the consistency of the compressed data, so the library should never
411 crash even in case of corrupted input.
412*/
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200413
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400414typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
415typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt size));
416typedef void (*cb_func) OF((Bytef *buf, uInt len));
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200417
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400418struct internal_state;
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200419
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400420typedef struct z_stream_s {
421 Bytef *next_in; /* next input byte */
422 uInt avail_in; /* number of bytes available at next_in */
423 uLong total_in; /* total nb of input bytes read so far */
424 Bytef *next_out; /* next output byte should be put there */
425 uInt avail_out; /* remaining free space at next_out */
426 uLong total_out; /* total nb of bytes output so far */
427 char *msg; /* last error message, NULL if no error */
428 struct internal_state FAR *state; /* not visible by applications */
429 alloc_func zalloc; /* used to allocate the internal state */
430 free_func zfree; /* used to free the internal state */
431 voidpf opaque; /* private data object passed to zalloc and zfree */
432 int data_type; /* best guess about the data type:
433 binary or text */
434 cb_func outcb; /* called regularly just before blocks of output */
435 uLong adler; /* adler32 value of the uncompressed data */
436 uLong reserved; /* reserved for future use */
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200437} z_stream;
wdenk4a5b6a32001-04-28 17:59:11 +0000438
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400439typedef z_stream FAR *z_streamp;
wdenk4a5b6a32001-04-28 17:59:11 +0000440
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400441/*
442 gzip header information passed to and from zlib routines. See RFC 1952
443 for more details on the meanings of these fields.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200444*/
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400445typedef struct gz_header_s {
446 int text; /* true if compressed data believed to be text */
447 uLong time; /* modification time */
448 int xflags; /* extra flags (not used when writing a gzip file) */
449 int os; /* operating system */
450 Bytef *extra; /* pointer to extra field or Z_NULL if none */
451 uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
452 uInt extra_max; /* space at extra (only when reading header) */
453 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
454 uInt name_max; /* space at name (only when reading header) */
455 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
456 uInt comm_max; /* space at comment (only when reading header) */
457 int hcrc; /* true if there was or will be a header crc */
458 int done; /* true when done reading gzip header (not used
459 when writing a gzip file) */
460} gz_header;
wdenk4a5b6a32001-04-28 17:59:11 +0000461
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400462typedef gz_header FAR *gz_headerp;
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200463
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400464 /* constants */
wdenk4a5b6a32001-04-28 17:59:11 +0000465#define Z_NO_FLUSH 0
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400466#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
467#define Z_SYNC_FLUSH 2
468#define Z_FULL_FLUSH 3
wdenk4a5b6a32001-04-28 17:59:11 +0000469#define Z_FINISH 4
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400470#define Z_BLOCK 5
471/* Allowed flush values; see deflate() and inflate() below for details */
wdenk4a5b6a32001-04-28 17:59:11 +0000472
473#define Z_OK 0
474#define Z_STREAM_END 1
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400475#define Z_NEED_DICT 2
wdenk4a5b6a32001-04-28 17:59:11 +0000476#define Z_ERRNO (-1)
477#define Z_STREAM_ERROR (-2)
478#define Z_DATA_ERROR (-3)
479#define Z_MEM_ERROR (-4)
480#define Z_BUF_ERROR (-5)
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400481#define Z_VERSION_ERROR (-6)
482/* Return codes for the compression/decompression functions. Negative
483 * values are errors, positive values are used for special but normal events.
484 */
wdenk4a5b6a32001-04-28 17:59:11 +0000485
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400486#define Z_NO_COMPRESSION 0
wdenk4a5b6a32001-04-28 17:59:11 +0000487#define Z_BEST_SPEED 1
488#define Z_BEST_COMPRESSION 9
489#define Z_DEFAULT_COMPRESSION (-1)
490/* compression levels */
491
492#define Z_FILTERED 1
493#define Z_HUFFMAN_ONLY 2
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400494#define Z_RLE 3
495#define Z_FIXED 4
wdenk4a5b6a32001-04-28 17:59:11 +0000496#define Z_DEFAULT_STRATEGY 0
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400497/* compression strategy; see deflateInit2() below for details */
wdenk4a5b6a32001-04-28 17:59:11 +0000498
499#define Z_BINARY 0
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400500#define Z_TEXT 1
501#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
wdenk4a5b6a32001-04-28 17:59:11 +0000502#define Z_UNKNOWN 2
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400503/* Possible values of the data_type field (though see inflate()) */
504
505#define Z_DEFLATED 8
506/* The deflate compression method (the only one supported in this version) */
wdenk4a5b6a32001-04-28 17:59:11 +0000507
508#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
509
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400510 /* basic functions */
511
512/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
wdenk4a5b6a32001-04-28 17:59:11 +0000513 If the first character differs, the library code actually used is
514 not compatible with the zlib.h header file used by the application.
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400515 This check is automatically made by deflateInit and inflateInit.
Lei Wen8dd348f2012-09-28 04:26:44 +0000516 */
wdenk4a5b6a32001-04-28 17:59:11 +0000517
Lei Wen8dd348f2012-09-28 04:26:44 +0000518ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
519ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
520 const char *version, int stream_size));
521ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
522ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
523 int windowBits, int memLevel,
524 int strategy, const char *version,
525 int stream_size));
526ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
527ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
528 const Bytef *dictionary,
529 uInt dictLength));
530ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
531 gz_headerp head));
532ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
533 int bits,
534 int value));
535ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
536 int level,
537 int strategy));
538ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
539 int good_length,
540 int max_lazy,
541 int nice_length,
542 int max_chain));
543ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
544 uLong sourceLen));
545ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
546 z_streamp source));
547
wdenk4a5b6a32001-04-28 17:59:11 +0000548
Lei Wen8dd348f2012-09-28 04:26:44 +0000549ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
550 const char *version, int stream_size));
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400551ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
wdenk4a5b6a32001-04-28 17:59:11 +0000552/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400553 inflate decompresses as much data as possible, and stops when the input
554 buffer becomes empty or the output buffer becomes full. It may introduce
555 some output latency (reading input without producing any output) except when
556 forced to flush.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200557
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400558 The detailed semantics are as follows. inflate performs one or both of the
559 following actions:
wdenk4a5b6a32001-04-28 17:59:11 +0000560
561 - Decompress more input starting at next_in and update next_in and avail_in
562 accordingly. If not all input can be processed (because there is not
563 enough room in the output buffer), next_in is updated and processing
564 will resume at this point for the next call of inflate().
565
566 - Provide more output starting at next_out and update next_out and avail_out
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400567 accordingly. inflate() provides as much output as possible, until there
568 is no more input data or no more space in the output buffer (see below
569 about the flush parameter).
wdenk4a5b6a32001-04-28 17:59:11 +0000570
571 Before the call of inflate(), the application should ensure that at least
572 one of the actions is possible, by providing more input and/or consuming
573 more output, and updating the next_* and avail_* values accordingly.
574 The application can consume the uncompressed output when it wants, for
575 example when the output buffer is full (avail_out == 0), or after each
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400576 call of inflate(). If inflate returns Z_OK and with zero avail_out, it
577 must be called again after making room in the output buffer because there
578 might be more output pending.
579
580 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
581 Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
582 output as possible to the output buffer. Z_BLOCK requests that inflate() stop
583 if and when it gets to the next deflate block boundary. When decoding the
584 zlib or gzip format, this will cause inflate() to return immediately after
585 the header and before the first block. When doing a raw inflate, inflate()
586 will go ahead and process the first block, and will return when it gets to
587 the end of that block, or when it runs out of data.
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400588
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400589 The Z_BLOCK option assists in appending to or combining deflate streams.
590 Also to assist in this, on return inflate() will set strm->data_type to the
591 number of unused bits in the last byte taken from strm->next_in, plus 64
592 if inflate() is currently decoding the last block in the deflate stream,
593 plus 128 if inflate() returned immediately after decoding an end-of-block
594 code or decoding the complete header up to just before the first byte of the
595 deflate stream. The end-of-block will not be indicated until all of the
596 uncompressed data from that block has been written to strm->next_out. The
597 number of unused bits may in general be greater than seven, except when
598 bit 7 of data_type is set, in which case the number of unused bits will be
599 less than eight.
wdenk4a5b6a32001-04-28 17:59:11 +0000600
601 inflate() should normally be called until it returns Z_STREAM_END or an
602 error. However if all decompression is to be performed in a single step
603 (a single call of inflate), the parameter flush should be set to
604 Z_FINISH. In this case all pending input is processed and all pending
605 output is flushed; avail_out must be large enough to hold all the
606 uncompressed data. (The size of the uncompressed data may have been saved
607 by the compressor for this purpose.) The next operation on this stream must
608 be inflateEnd to deallocate the decompression state. The use of Z_FINISH
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400609 is never required, but can be used to inform inflate that a faster approach
wdenk4a5b6a32001-04-28 17:59:11 +0000610 may be used for the single inflate() call.
611
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400612 In this implementation, inflate() always flushes as much output as
613 possible to the output buffer, and always uses the faster approach on the
614 first call. So the only effect of the flush parameter in this implementation
615 is on the return value of inflate(), as noted below, or when it returns early
616 because Z_BLOCK is used.
617
618 If a preset dictionary is needed after this call (see inflateSetDictionary
619 below), inflate sets strm->adler to the adler32 checksum of the dictionary
620 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
621 strm->adler to the adler32 checksum of all output produced so far (that is,
622 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
623 below. At the end of the stream, inflate() checks that its computed adler32
624 checksum is equal to that saved by the compressor and returns Z_STREAM_END
625 only if the checksum is correct.
626
627 inflate() will decompress and check either zlib-wrapped or gzip-wrapped
628 deflate data. The header type is detected automatically. Any information
629 contained in the gzip header is not retained, so applications that need that
630 information should instead use raw inflate, see inflateInit2() below, or
631 inflateBack() and perform their own processing of the gzip header and
632 trailer.
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400633
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400634 inflate() returns Z_OK if some progress has been made (more input processed
635 or more output produced), Z_STREAM_END if the end of the compressed data has
636 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
637 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
638 corrupted (input stream not conforming to the zlib format or incorrect check
639 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
640 if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
641 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
642 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
643 inflate() can be called again with more input and more output space to
644 continue decompressing. If Z_DATA_ERROR is returned, the application may then
645 call inflateSync() to look for a good compression block if a partial recovery
646 of the data is desired.
647*/
wdenk4a5b6a32001-04-28 17:59:11 +0000648
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400649ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
wdenk4a5b6a32001-04-28 17:59:11 +0000650/*
651 All dynamically allocated data structures for this stream are freed.
652 This function discards any unprocessed input and does not flush any
653 pending output.
654
655 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
656 was inconsistent. In the error case, msg may be set but then points to a
657 static string (which must not be deallocated).
658*/
659
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400660 /* Advanced functions */
wdenk4a5b6a32001-04-28 17:59:11 +0000661
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400662ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
wdenk4a5b6a32001-04-28 17:59:11 +0000663
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400664 /* utility functions */
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200665
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400666/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400667 The following utility functions are implemented on top of the
668 basic stream-oriented functions. To simplify the interface, some
669 default options are assumed (compression level and memory usage,
670 standard memory allocation functions). The source code of these
671 utility functions can easily be modified if you need special options.
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400672*/
673
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400674ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400675/*
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200676 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
677 return the updated checksum. If buf is NULL, this function returns
678 the required initial value for the checksum.
679 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
680 much faster. Usage example:
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400681
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200682 uLong adler = adler32(0L, Z_NULL, 0);
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400683
684 while (read_buffer(buffer, length) != EOF) {
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200685 adler = adler32(adler, buffer, length);
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400686 }
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200687 if (adler != original_adler) error();
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400688*/
689
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400690/*
691 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
692 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
693 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
694 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
695*/
696
697ZEXTERN uInt ZEXPORT crc32 OF((uInt crc, const Bytef *buf, uInt len));
698/*
699 Update a running CRC-32 with the bytes buf[0..len-1] and return the
700 updated CRC-32. If buf is NULL, this function returns the required initial
701 value for the for the crc. Pre- and post-conditioning (one's complement) is
702 performed within this function so it shouldn't be done by the application.
703 Usage example:
704
705 uLong crc = crc32(0L, Z_NULL, 0);
706
707 while (read_buffer(buffer, length) != EOF) {
708 crc = crc32(crc, buffer, length);
709 }
710 if (crc != original_crc) error();
711*/
712
713ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
714 const char *version, int stream_size));
715#define inflateInit(strm) \
716 inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
717#define inflateInit2(strm, windowBits) \
718 inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
719
720#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
721 struct internal_state {int dummy;}; /* hack for buggy compilers */
wdenk4a5b6a32001-04-28 17:59:11 +0000722#endif
723
Mike Frysinger802383b2012-04-09 13:39:53 +0000724extern void *gzalloc(void *, unsigned, unsigned);
725extern void gzfree(void *, void *, unsigned);
726
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400727#ifdef __cplusplus
728}
729#endif
730
731#endif /* ZLIB_H */