zlib.h 28 KB

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