blob: ee19f46095882c746c4c05e9017578bb955df17f [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/* #include "zconf.h" */ /* included directly here */
wdenk4a5b6a32001-04-28 17:59:11 +000053/* zconf.h -- configuration of the zlib compression library
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040054 * Copyright (C) 1995-2005 Jean-loup Gailly.
wdenk4a5b6a32001-04-28 17:59:11 +000055 * For conditions of distribution and use, see copyright notice in zlib.h
56 */
57
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040058/* Begin of new zconf.h */
wdenk4a5b6a32001-04-28 17:59:11 +000059/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040060 * If you *really* need a unique prefix for all types and library functions,
61 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
wdenk4a5b6a32001-04-28 17:59:11 +000062 */
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -040063#ifdef Z_PREFIX
64# define deflateInit_ z_deflateInit_
65# define deflate z_deflate
66# define deflateEnd z_deflateEnd
67# define inflateInit_ z_inflateInit_
68# define inflate z_inflate
69# define inflateEnd z_inflateEnd
70# define deflateInit2_ z_deflateInit2_
71# define deflateSetDictionary z_deflateSetDictionary
72# define deflateCopy z_deflateCopy
73# define deflateReset z_deflateReset
74# define deflateParams z_deflateParams
75# define deflateBound z_deflateBound
76# define deflatePrime z_deflatePrime
77# define inflateInit2_ z_inflateInit2_
78# define inflateSetDictionary z_inflateSetDictionary
79# define inflateSync z_inflateSync
80# define inflateSyncPoint z_inflateSyncPoint
81# define inflateCopy z_inflateCopy
82# define inflateReset z_inflateReset
83# define inflateBack z_inflateBack
84# define inflateBackEnd z_inflateBackEnd
85# define compress z_compress
86# define compress2 z_compress2
87# define compressBound z_compressBound
88# define uncompress z_uncompress
89# define adler32 z_adler32
90# define crc32 z_crc32
91# define get_crc_table z_get_crc_table
92# define zError z_zError
93
94# define alloc_func z_alloc_func
95# define free_func z_free_func
96# define in_func z_in_func
97# define out_func z_out_func
98# define Byte z_Byte
99# define uInt z_uInt
100# define uLong z_uLong
101# define Bytef z_Bytef
102# define charf z_charf
103# define intf z_intf
104# define uIntf z_uIntf
105# define uLongf z_uLongf
106# define voidpf z_voidpf
107# define voidp z_voidp
108#endif
109
Joao Marcos Costaae8abb12020-07-30 15:33:49 +0200110#if defined(ZLIB_CONST) && !defined(z_const)
111# define z_const const
112#else
113# define z_const
114#endif
115
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400116#if defined(__MSDOS__) && !defined(MSDOS)
117# define MSDOS
118#endif
119#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
120# define OS2
121#endif
122#if defined(_WINDOWS) && !defined(WINDOWS)
123# define WINDOWS
124#endif
125#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
126# ifndef WIN32
127# define WIN32
128# endif
129#endif
130#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
131# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
132# ifndef SYS16BIT
133# define SYS16BIT
134# endif
135# endif
136#endif
wdenk4a5b6a32001-04-28 17:59:11 +0000137
138/*
139 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
140 * than 64k bytes at a time (needed on systems with 16-bit int).
wdenk4a5b6a32001-04-28 17:59:11 +0000141 */
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400142#ifdef SYS16BIT
143# define MAXSEG_64K
144#endif
145#ifdef MSDOS
146# define UNALIGNED_OK
147#endif
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400148
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400149#ifdef __STDC_VERSION__
150# ifndef STDC
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200151# define STDC
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400152# endif
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400153# if __STDC_VERSION__ >= 199901L
154# ifndef STDC99
155# define STDC99
156# endif
157# endif
158#endif
159#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
160# define STDC
161#endif
162#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
163# define STDC
164#endif
165#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
166# define STDC
167#endif
168#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
169# define STDC
170#endif
171
172#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
173# define STDC
174#endif
175
176#ifndef STDC
177# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
178# define const /* note: need a more gentle solution here */
179# endif
wdenk4a5b6a32001-04-28 17:59:11 +0000180#endif
181
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400182/* Some Mac compilers merge all .h files incorrectly: */
183#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
184# define NO_DUMMY_DECL
wdenk4a5b6a32001-04-28 17:59:11 +0000185#endif
186
187/* Maximum value for memLevel in deflateInit2 */
188#ifndef MAX_MEM_LEVEL
189# ifdef MAXSEG_64K
190# define MAX_MEM_LEVEL 8
191# else
192# define MAX_MEM_LEVEL 9
193# endif
194#endif
195
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400196/* Maximum value for windowBits in deflateInit2 and inflateInit2.
197 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
198 * created by gzip. (Files created by minigzip can still be extracted by
199 * gzip.)
200 */
wdenk4a5b6a32001-04-28 17:59:11 +0000201#ifndef MAX_WBITS
202# define MAX_WBITS 15 /* 32K LZ77 window */
203#endif
204
205/* The memory requirements for deflate are (in bytes):
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400206 (1 << (windowBits+2)) + (1 << (memLevel+9))
wdenk4a5b6a32001-04-28 17:59:11 +0000207 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
208 plus a few kilobytes for small objects. For example, if you want to reduce
209 the default memory requirements from 256K to 128K, compile with
210 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
211 Of course this will generally degrade compression (there's no free lunch).
212
213 The memory requirements for inflate are (in bytes) 1 << windowBits
214 that is, 32K for windowBits=15 (default value) plus a few kilobytes
215 for small objects.
216*/
217
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400218 /* Type declarations */
wdenk4a5b6a32001-04-28 17:59:11 +0000219
220#ifndef OF /* function prototypes */
221# ifdef STDC
222# define OF(args) args
223# else
224# define OF(args) ()
225# endif
226#endif
227
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400228/* The following definitions for FAR are needed only for MSDOS mixed
229 * model programming (small or medium model with some far allocations).
230 * This was tested only with MSC; for other MSDOS compilers you may have
231 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
232 * just define FAR to be empty.
233 */
234#ifdef SYS16BIT
235# if defined(M_I86SM) || defined(M_I86MM)
236 /* MSC small or medium model */
237# define SMALL_MEDIUM
238# ifdef _MSC_VER
239# define FAR _far
240# else
241# define FAR far
242# endif
243# endif
244# if (defined(__SMALL__) || defined(__MEDIUM__))
245 /* Turbo C small or medium model */
246# define SMALL_MEDIUM
247# ifdef __BORLANDC__
248# define FAR _far
249# else
250# define FAR far
251# endif
252# endif
253#endif
254
255#if defined(WINDOWS) || defined(WIN32)
256 /* If building or using zlib as a DLL, define ZLIB_DLL.
257 * This is not mandatory, but it offers a little performance increase.
258 */
259# ifdef ZLIB_DLL
260# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
261# ifdef ZLIB_INTERNAL
262# define ZEXTERN extern __declspec(dllexport)
263# else
264# define ZEXTERN extern __declspec(dllimport)
265# endif
266# endif
267# endif /* ZLIB_DLL */
268 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
269 * define ZLIB_WINAPI.
270 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
271 */
272# ifdef ZLIB_WINAPI
273# ifdef FAR
274# undef FAR
275# endif
276# include <windows.h>
277 /* No need for _export, use ZLIB.DEF instead. */
278 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
279# define ZEXPORT WINAPI
280# ifdef WIN32
281# define ZEXPORTVA WINAPIV
282# else
283# define ZEXPORTVA FAR CDECL
284# endif
285# endif
286#endif
287
288#if defined (__BEOS__)
289# ifdef ZLIB_DLL
290# ifdef ZLIB_INTERNAL
291# define ZEXPORT __declspec(dllexport)
292# define ZEXPORTVA __declspec(dllexport)
293# else
294# define ZEXPORT __declspec(dllimport)
295# define ZEXPORTVA __declspec(dllimport)
296# endif
297# endif
298#endif
299
300#ifndef ZEXTERN
301# define ZEXTERN extern
302#endif
303#ifndef ZEXPORT
304# define ZEXPORT
305#endif
306#ifndef ZEXPORTVA
307# define ZEXPORTVA
308#endif
309
310#ifndef FAR
311# define FAR
312#endif
313
314#if !defined(__MACTYPES__)
wdenk4a5b6a32001-04-28 17:59:11 +0000315typedef unsigned char Byte; /* 8 bits */
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400316#endif
wdenk4a5b6a32001-04-28 17:59:11 +0000317typedef unsigned int uInt; /* 16 bits or more */
318typedef unsigned long uLong; /* 32 bits or more */
319
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400320#ifdef SMALL_MEDIUM
321 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
322# define Bytef Byte FAR
323#else
324 typedef Byte FAR Bytef;
325#endif
326typedef char FAR charf;
327typedef int FAR intf;
328typedef uInt FAR uIntf;
wdenk4a5b6a32001-04-28 17:59:11 +0000329typedef uLong FAR uLongf;
330
331#ifdef STDC
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400332 typedef void const *voidpc;
333 typedef void FAR *voidpf;
334 typedef void *voidp;
wdenk4a5b6a32001-04-28 17:59:11 +0000335#else
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400336 typedef Byte const *voidpc;
337 typedef Byte FAR *voidpf;
338 typedef Byte *voidp;
339#endif
340
341# ifdef VMS
342# include <unixio.h> /* for off_t */
343# endif
344# define z_off_t off_t
345#ifndef SEEK_SET
346# define SEEK_SET 0 /* Seek from beginning of file. */
347# define SEEK_CUR 1 /* Seek from current position. */
348# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
349#endif
350#ifndef z_off_t
351# define z_off_t long
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400352#endif
353
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400354#if defined(__OS400__)
355# define NO_vsnprintf
356#endif
357
358#if defined(__MVS__)
359# define NO_vsnprintf
360# ifdef FAR
361# undef FAR
362# endif
363#endif
wdenk4a5b6a32001-04-28 17:59:11 +0000364
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400365/* MVS linker does not support external names larger than 8 bytes */
366#if defined(__MVS__)
367# pragma map(deflateInit_,"DEIN")
368# pragma map(deflateInit2_,"DEIN2")
369# pragma map(deflateEnd,"DEEND")
370# pragma map(deflateBound,"DEBND")
371# pragma map(inflateInit_,"ININ")
372# pragma map(inflateInit2_,"ININ2")
373# pragma map(inflateEnd,"INEND")
374# pragma map(inflateSync,"INSY")
375# pragma map(inflateSetDictionary,"INSEDI")
376# pragma map(compressBound,"CMBND")
377# pragma map(inflate_table,"INTABL")
378# pragma map(inflate_fast,"INFA")
379# pragma map(inflate_copyright,"INCOPY")
380#endif
381/* End of new zconf.h */
wdenk4a5b6a32001-04-28 17:59:11 +0000382
383/*
384 The 'zlib' compression library provides in-memory compression and
385 decompression functions, including integrity checks of the uncompressed
386 data. This version of the library supports only one compression method
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400387 (deflation) but other algorithms will be added later and will have the same
wdenk4a5b6a32001-04-28 17:59:11 +0000388 stream interface.
389
wdenk4a5b6a32001-04-28 17:59:11 +0000390 Compression can be done in a single step if the buffers are large
391 enough (for example if an input file is mmap'ed), or can be done by
392 repeated calls of the compression function. In the latter case, the
393 application must provide more input and/or consume the output
394 (providing more output space) before each call.
wdenk4a5b6a32001-04-28 17:59:11 +0000395
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400396 The compressed data format used by default by the in-memory functions is
397 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
398 around a deflate stream, which is itself documented in RFC 1951.
wdenk4a5b6a32001-04-28 17:59:11 +0000399
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400400 The library also supports reading and writing files in gzip (.gz) format
401 with an interface similar to that of stdio using the functions that start
402 with "gz". The gzip format is different from the zlib format. gzip is a
403 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200404
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400405 This library can optionally read and write gzip streams in memory as well.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200406
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400407 The zlib format was designed to be compact and fast for use in memory
408 and on communications channels. The gzip format was designed for single-
409 file compression on file systems, has a larger header than zlib to maintain
410 directory information, and uses a different, slower check method than zlib.
wdenk4a5b6a32001-04-28 17:59:11 +0000411
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400412 The library does not install any signal handler. The decoder checks
413 the consistency of the compressed data, so the library should never
414 crash even in case of corrupted input.
415*/
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200416
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400417typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
418typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt size));
419typedef void (*cb_func) OF((Bytef *buf, uInt len));
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200420
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400421struct internal_state;
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200422
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400423typedef struct z_stream_s {
424 Bytef *next_in; /* next input byte */
425 uInt avail_in; /* number of bytes available at next_in */
426 uLong total_in; /* total nb of input bytes read so far */
427 Bytef *next_out; /* next output byte should be put there */
428 uInt avail_out; /* remaining free space at next_out */
429 uLong total_out; /* total nb of bytes output so far */
430 char *msg; /* last error message, NULL if no error */
431 struct internal_state FAR *state; /* not visible by applications */
432 alloc_func zalloc; /* used to allocate the internal state */
433 free_func zfree; /* used to free the internal state */
434 voidpf opaque; /* private data object passed to zalloc and zfree */
435 int data_type; /* best guess about the data type:
436 binary or text */
437 cb_func outcb; /* called regularly just before blocks of output */
438 uLong adler; /* adler32 value of the uncompressed data */
439 uLong reserved; /* reserved for future use */
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200440} z_stream;
wdenk4a5b6a32001-04-28 17:59:11 +0000441
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400442typedef z_stream FAR *z_streamp;
wdenk4a5b6a32001-04-28 17:59:11 +0000443
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400444/*
445 gzip header information passed to and from zlib routines. See RFC 1952
446 for more details on the meanings of these fields.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200447*/
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400448typedef struct gz_header_s {
449 int text; /* true if compressed data believed to be text */
450 uLong time; /* modification time */
451 int xflags; /* extra flags (not used when writing a gzip file) */
452 int os; /* operating system */
453 Bytef *extra; /* pointer to extra field or Z_NULL if none */
454 uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
455 uInt extra_max; /* space at extra (only when reading header) */
456 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
457 uInt name_max; /* space at name (only when reading header) */
458 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
459 uInt comm_max; /* space at comment (only when reading header) */
460 int hcrc; /* true if there was or will be a header crc */
461 int done; /* true when done reading gzip header (not used
462 when writing a gzip file) */
463} gz_header;
wdenk4a5b6a32001-04-28 17:59:11 +0000464
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400465typedef gz_header FAR *gz_headerp;
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200466
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400467 /* constants */
wdenk4a5b6a32001-04-28 17:59:11 +0000468#define Z_NO_FLUSH 0
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400469#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
470#define Z_SYNC_FLUSH 2
471#define Z_FULL_FLUSH 3
wdenk4a5b6a32001-04-28 17:59:11 +0000472#define Z_FINISH 4
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400473#define Z_BLOCK 5
474/* Allowed flush values; see deflate() and inflate() below for details */
wdenk4a5b6a32001-04-28 17:59:11 +0000475
476#define Z_OK 0
477#define Z_STREAM_END 1
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400478#define Z_NEED_DICT 2
wdenk4a5b6a32001-04-28 17:59:11 +0000479#define Z_ERRNO (-1)
480#define Z_STREAM_ERROR (-2)
481#define Z_DATA_ERROR (-3)
482#define Z_MEM_ERROR (-4)
483#define Z_BUF_ERROR (-5)
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400484/* Return codes for the compression/decompression functions. Negative
485 * values are errors, positive values are used for special but normal events.
486 */
wdenk4a5b6a32001-04-28 17:59:11 +0000487
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400488#define Z_NO_COMPRESSION 0
wdenk4a5b6a32001-04-28 17:59:11 +0000489#define Z_BEST_SPEED 1
490#define Z_BEST_COMPRESSION 9
491#define Z_DEFAULT_COMPRESSION (-1)
492/* compression levels */
493
494#define Z_FILTERED 1
495#define Z_HUFFMAN_ONLY 2
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400496#define Z_RLE 3
497#define Z_FIXED 4
wdenk4a5b6a32001-04-28 17:59:11 +0000498#define Z_DEFAULT_STRATEGY 0
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400499/* compression strategy; see deflateInit2() below for details */
wdenk4a5b6a32001-04-28 17:59:11 +0000500
501#define Z_BINARY 0
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400502#define Z_TEXT 1
503#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
wdenk4a5b6a32001-04-28 17:59:11 +0000504#define Z_UNKNOWN 2
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400505/* Possible values of the data_type field (though see inflate()) */
506
507#define Z_DEFLATED 8
508/* The deflate compression method (the only one supported in this version) */
wdenk4a5b6a32001-04-28 17:59:11 +0000509
Kim Phillips8eb69942012-10-29 13:34:35 +0000510#define Z_NULL (void *)0 /* for initializing zalloc, zfree, opaque */
wdenk4a5b6a32001-04-28 17:59:11 +0000511
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400512 /* basic functions */
513
514/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
wdenk4a5b6a32001-04-28 17:59:11 +0000515 If the first character differs, the library code actually used is
516 not compatible with the zlib.h header file used by the application.
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400517 This check is automatically made by deflateInit and inflateInit.
Lei Wen8dd348f2012-09-28 04:26:44 +0000518 */
wdenk4a5b6a32001-04-28 17:59:11 +0000519
Lei Wen8dd348f2012-09-28 04:26:44 +0000520ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
521ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
Michal Simekf555f192024-03-27 15:14:53 +0100522 int stream_size));
Lei Wen8dd348f2012-09-28 04:26:44 +0000523ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
524ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
525 int windowBits, int memLevel,
Michal Simekf555f192024-03-27 15:14:53 +0100526 int strategy,
Lei Wen8dd348f2012-09-28 04:26:44 +0000527 int stream_size));
528ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
529ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
530 const Bytef *dictionary,
531 uInt dictLength));
532ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
533 gz_headerp head));
534ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
535 int bits,
536 int value));
537ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
538 int level,
539 int strategy));
540ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
541 int good_length,
542 int max_lazy,
543 int nice_length,
544 int max_chain));
545ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
546 uLong sourceLen));
547ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
548 z_streamp source));
549
wdenk4a5b6a32001-04-28 17:59:11 +0000550
Lei Wen8dd348f2012-09-28 04:26:44 +0000551ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
Michal Simekf555f192024-03-27 15:14:53 +0100552 int stream_size));
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400553ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
wdenk4a5b6a32001-04-28 17:59:11 +0000554/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400555 inflate decompresses as much data as possible, and stops when the input
556 buffer becomes empty or the output buffer becomes full. It may introduce
557 some output latency (reading input without producing any output) except when
558 forced to flush.
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200559
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400560 The detailed semantics are as follows. inflate performs one or both of the
561 following actions:
wdenk4a5b6a32001-04-28 17:59:11 +0000562
563 - Decompress more input starting at next_in and update next_in and avail_in
564 accordingly. If not all input can be processed (because there is not
565 enough room in the output buffer), next_in is updated and processing
566 will resume at this point for the next call of inflate().
567
568 - Provide more output starting at next_out and update next_out and avail_out
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400569 accordingly. inflate() provides as much output as possible, until there
570 is no more input data or no more space in the output buffer (see below
571 about the flush parameter).
wdenk4a5b6a32001-04-28 17:59:11 +0000572
573 Before the call of inflate(), the application should ensure that at least
574 one of the actions is possible, by providing more input and/or consuming
575 more output, and updating the next_* and avail_* values accordingly.
576 The application can consume the uncompressed output when it wants, for
577 example when the output buffer is full (avail_out == 0), or after each
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400578 call of inflate(). If inflate returns Z_OK and with zero avail_out, it
579 must be called again after making room in the output buffer because there
580 might be more output pending.
581
582 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
583 Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
584 output as possible to the output buffer. Z_BLOCK requests that inflate() stop
585 if and when it gets to the next deflate block boundary. When decoding the
586 zlib or gzip format, this will cause inflate() to return immediately after
587 the header and before the first block. When doing a raw inflate, inflate()
588 will go ahead and process the first block, and will return when it gets to
589 the end of that block, or when it runs out of data.
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400590
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400591 The Z_BLOCK option assists in appending to or combining deflate streams.
592 Also to assist in this, on return inflate() will set strm->data_type to the
593 number of unused bits in the last byte taken from strm->next_in, plus 64
594 if inflate() is currently decoding the last block in the deflate stream,
595 plus 128 if inflate() returned immediately after decoding an end-of-block
596 code or decoding the complete header up to just before the first byte of the
597 deflate stream. The end-of-block will not be indicated until all of the
598 uncompressed data from that block has been written to strm->next_out. The
599 number of unused bits may in general be greater than seven, except when
600 bit 7 of data_type is set, in which case the number of unused bits will be
601 less than eight.
wdenk4a5b6a32001-04-28 17:59:11 +0000602
603 inflate() should normally be called until it returns Z_STREAM_END or an
604 error. However if all decompression is to be performed in a single step
605 (a single call of inflate), the parameter flush should be set to
606 Z_FINISH. In this case all pending input is processed and all pending
607 output is flushed; avail_out must be large enough to hold all the
608 uncompressed data. (The size of the uncompressed data may have been saved
609 by the compressor for this purpose.) The next operation on this stream must
610 be inflateEnd to deallocate the decompression state. The use of Z_FINISH
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400611 is never required, but can be used to inform inflate that a faster approach
wdenk4a5b6a32001-04-28 17:59:11 +0000612 may be used for the single inflate() call.
613
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400614 In this implementation, inflate() always flushes as much output as
615 possible to the output buffer, and always uses the faster approach on the
616 first call. So the only effect of the flush parameter in this implementation
617 is on the return value of inflate(), as noted below, or when it returns early
618 because Z_BLOCK is used.
619
620 If a preset dictionary is needed after this call (see inflateSetDictionary
621 below), inflate sets strm->adler to the adler32 checksum of the dictionary
622 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
623 strm->adler to the adler32 checksum of all output produced so far (that is,
624 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
625 below. At the end of the stream, inflate() checks that its computed adler32
626 checksum is equal to that saved by the compressor and returns Z_STREAM_END
627 only if the checksum is correct.
628
629 inflate() will decompress and check either zlib-wrapped or gzip-wrapped
630 deflate data. The header type is detected automatically. Any information
631 contained in the gzip header is not retained, so applications that need that
632 information should instead use raw inflate, see inflateInit2() below, or
633 inflateBack() and perform their own processing of the gzip header and
634 trailer.
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400635
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400636 inflate() returns Z_OK if some progress has been made (more input processed
637 or more output produced), Z_STREAM_END if the end of the compressed data has
638 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
639 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
640 corrupted (input stream not conforming to the zlib format or incorrect check
641 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
642 if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
643 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
644 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
645 inflate() can be called again with more input and more output space to
646 continue decompressing. If Z_DATA_ERROR is returned, the application may then
647 call inflateSync() to look for a good compression block if a partial recovery
648 of the data is desired.
649*/
wdenk4a5b6a32001-04-28 17:59:11 +0000650
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400651ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
wdenk4a5b6a32001-04-28 17:59:11 +0000652/*
653 All dynamically allocated data structures for this stream are freed.
654 This function discards any unprocessed input and does not flush any
655 pending output.
656
657 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
658 was inconsistent. In the error case, msg may be set but then points to a
659 static string (which must not be deallocated).
660*/
661
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400662 /* Advanced functions */
wdenk4a5b6a32001-04-28 17:59:11 +0000663
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400664ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
wdenk4a5b6a32001-04-28 17:59:11 +0000665
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400666 /* utility functions */
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200667
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400668/*
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400669 The following utility functions are implemented on top of the
670 basic stream-oriented functions. To simplify the interface, some
671 default options are assumed (compression level and memory usage,
672 standard memory allocation functions). The source code of these
673 utility functions can easily be modified if you need special options.
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400674*/
675
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400676ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400677/*
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200678 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
679 return the updated checksum. If buf is NULL, this function returns
680 the required initial value for the checksum.
681 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
682 much faster. Usage example:
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400683
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200684 uLong adler = adler32(0L, Z_NULL, 0);
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400685
686 while (read_buffer(buffer, length) != EOF) {
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200687 adler = adler32(adler, buffer, length);
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400688 }
Wolfgang Denk72d0bca2009-07-24 14:24:07 +0200689 if (adler != original_adler) error();
Giuseppe CONDORELLIb4a560a2009-07-23 04:54:45 -0400690*/
691
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400692/*
693 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
694 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
695 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
696 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
697*/
698
699ZEXTERN uInt ZEXPORT crc32 OF((uInt crc, const Bytef *buf, uInt len));
700/*
701 Update a running CRC-32 with the bytes buf[0..len-1] and return the
702 updated CRC-32. If buf is NULL, this function returns the required initial
703 value for the for the crc. Pre- and post-conditioning (one's complement) is
704 performed within this function so it shouldn't be done by the application.
705 Usage example:
706
707 uLong crc = crc32(0L, Z_NULL, 0);
708
709 while (read_buffer(buffer, length) != EOF) {
710 crc = crc32(crc, buffer, length);
711 }
712 if (crc != original_crc) error();
713*/
714
Joao Marcos Costaae8abb12020-07-30 15:33:49 +0200715ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
716 const Bytef *source, uLong sourceLen));
717/*
718 Decompresses the source buffer into the destination buffer. sourceLen is
719 the byte length of the source buffer. Upon entry, destLen is the total size
720 of the destination buffer, which must be large enough to hold the entire
721 uncompressed data. (The size of the uncompressed data must have been saved
722 previously by the compressor and transmitted to the decompressor by some
723 mechanism outside the scope of this compression library.) Upon exit, destLen
724 is the actual size of the uncompressed data.
725
726 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
727 enough memory, Z_BUF_ERROR if there was not enough room in the output
728 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
729 the case where there is not enough room, uncompress() will fill the output
730 buffer with the uncompressed data up to that point.
731*/
732
733ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
734 const Bytef *source, uLong *sourceLen));
735/*
736 Same as uncompress, except that sourceLen is a pointer, where the
737 length of the source is *sourceLen. On return, *sourceLen is the number of
738 source bytes consumed.
739*/
740
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400741ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
Michal Simekf555f192024-03-27 15:14:53 +0100742 int stream_size));
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400743#define inflateInit(strm) \
Michal Simekf555f192024-03-27 15:14:53 +0100744 inflateInit_((strm), sizeof(z_stream))
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400745#define inflateInit2(strm, windowBits) \
Michal Simekf555f192024-03-27 15:14:53 +0100746 inflateInit2_((strm), (windowBits), sizeof(z_stream))
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400747
748#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
749 struct internal_state {int dummy;}; /* hack for buggy compilers */
wdenk4a5b6a32001-04-28 17:59:11 +0000750#endif
751
Mike Frysinger802383b2012-04-09 13:39:53 +0000752extern void *gzalloc(void *, unsigned, unsigned);
753extern void gzfree(void *, void *, unsigned);
754
Giuseppe CONDORELLI5e7e8e82009-07-29 08:05:08 -0400755#ifdef __cplusplus
756}
757#endif
758
759#endif /* ZLIB_H */