zlib.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. /* $Id: zlib.h,v 1.7 1997/11/27 06:03:33 paulus Exp $ */
  2. /*
  3. * This file is derived from zlib.h and zconf.h from the zlib-1.0.4
  4. * distribution by Jean-loup Gailly and Mark Adler, with some additions
  5. * by Paul Mackerras to aid in implementing Deflate compression and
  6. * decompression for PPP packets.
  7. */
  8. /*
  9. * ==FILEVERSION 971127==
  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. */
  14. /* +++ zlib.h */
  15. /* zlib.h -- interface of the 'zlib' general purpose compression library
  16. version 1.0.4, Jul 24th, 1996.
  17. Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
  18. This software is provided 'as-is', without any express or implied
  19. warranty. In no event will the authors be held liable for any damages
  20. arising from the use of this software.
  21. Permission is granted to anyone to use this software for any purpose,
  22. including commercial applications, and to alter it and redistribute it
  23. freely, subject to the following restrictions:
  24. 1. The origin of this software must not be misrepresented; you must not
  25. claim that you wrote the original software. If you use this software
  26. in a product, an acknowledgment in the product documentation would be
  27. appreciated but is not required.
  28. 2. Altered source versions must be plainly marked as such, and must not be
  29. misrepresented as being the original software.
  30. 3. This notice may not be removed or altered from any source distribution.
  31. Jean-loup Gailly Mark Adler
  32. gzip@prep.ai.mit.edu madler@alumni.caltech.edu
  33. The data format used by the zlib library is described by RFCs (Request for
  34. Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
  35. (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  36. */
  37. #ifndef _ZLIB_H
  38. #define _ZLIB_H
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /* +++ zconf.h */
  43. /* zconf.h -- configuration of the zlib compression library
  44. * Copyright (C) 1995-1996 Jean-loup Gailly.
  45. * For conditions of distribution and use, see copyright notice in zlib.h
  46. */
  47. /* From: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */
  48. #ifndef _ZCONF_H
  49. #define _ZCONF_H
  50. /*
  51. * If you *really* need a unique prefix for all types and library functions,
  52. * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
  53. */
  54. #ifdef Z_PREFIX
  55. # define deflateInit_ z_deflateInit_
  56. # define deflate z_deflate
  57. # define deflateEnd z_deflateEnd
  58. # define inflateInit_ z_inflateInit_
  59. # define inflate z_inflate
  60. # define inflateEnd z_inflateEnd
  61. # define deflateInit2_ z_deflateInit2_
  62. # define deflateSetDictionary z_deflateSetDictionary
  63. # define deflateCopy z_deflateCopy
  64. # define deflateReset z_deflateReset
  65. # define deflateParams z_deflateParams
  66. # define inflateInit2_ z_inflateInit2_
  67. # define inflateSetDictionary z_inflateSetDictionary
  68. # define inflateSync z_inflateSync
  69. # define inflateReset z_inflateReset
  70. # define compress z_compress
  71. # define uncompress z_uncompress
  72. # define adler32 z_adler32
  73. # define crc32 z_crc32
  74. # define get_crc_table z_get_crc_table
  75. # define Byte z_Byte
  76. # define uInt z_uInt
  77. # define uLong z_uLong
  78. # define Bytef z_Bytef
  79. # define charf z_charf
  80. # define intf z_intf
  81. # define uIntf z_uIntf
  82. # define uLongf z_uLongf
  83. # define voidpf z_voidpf
  84. # define voidp z_voidp
  85. #endif
  86. #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
  87. # define WIN32
  88. #endif
  89. #if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
  90. # ifndef __32BIT__
  91. # define __32BIT__
  92. # endif
  93. #endif
  94. #if defined(__MSDOS__) && !defined(MSDOS)
  95. # define MSDOS
  96. #endif
  97. /*
  98. * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
  99. * than 64k bytes at a time (needed on systems with 16-bit int).
  100. */
  101. #if defined(MSDOS) && !defined(__32BIT__)
  102. # define MAXSEG_64K
  103. #endif
  104. #ifdef MSDOS
  105. # define UNALIGNED_OK
  106. #endif
  107. #if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
  108. # define STDC
  109. #endif
  110. #if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
  111. # define STDC
  112. #endif
  113. #ifndef STDC
  114. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  115. # define const
  116. # endif
  117. #endif
  118. /* Some Mac compilers merge all .h files incorrectly: */
  119. #if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
  120. # define NO_DUMMY_DECL
  121. #endif
  122. /* Maximum value for memLevel in deflateInit2 */
  123. #ifndef MAX_MEM_LEVEL
  124. # ifdef MAXSEG_64K
  125. # define MAX_MEM_LEVEL 8
  126. # else
  127. # define MAX_MEM_LEVEL 9
  128. # endif
  129. #endif
  130. /* Maximum value for windowBits in deflateInit2 and inflateInit2 */
  131. #ifndef MAX_WBITS
  132. # define MAX_WBITS 15 /* 32K LZ77 window */
  133. #endif
  134. /* The memory requirements for deflate are (in bytes):
  135. 1 << (windowBits+2) + 1 << (memLevel+9)
  136. that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
  137. plus a few kilobytes for small objects. For example, if you want to reduce
  138. the default memory requirements from 256K to 128K, compile with
  139. make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
  140. Of course this will generally degrade compression (there's no free lunch).
  141. The memory requirements for inflate are (in bytes) 1 << windowBits
  142. that is, 32K for windowBits=15 (default value) plus a few kilobytes
  143. for small objects.
  144. */
  145. /* Type declarations */
  146. #ifndef OF /* function prototypes */
  147. # ifdef STDC
  148. # define OF(args) args
  149. # else
  150. # define OF(args) ()
  151. # endif
  152. #endif
  153. /* The following definitions for FAR are needed only for MSDOS mixed
  154. * model programming (small or medium model with some far allocations).
  155. * This was tested only with MSC; for other MSDOS compilers you may have
  156. * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
  157. * just define FAR to be empty.
  158. */
  159. #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
  160. /* MSC small or medium model */
  161. # define SMALL_MEDIUM
  162. # ifdef _MSC_VER
  163. # define FAR __far
  164. # else
  165. # define FAR far
  166. # endif
  167. #endif
  168. #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
  169. # ifndef __32BIT__
  170. # define SMALL_MEDIUM
  171. # define FAR __far
  172. # endif
  173. #endif
  174. #ifndef FAR
  175. # define FAR
  176. #endif
  177. typedef unsigned char Byte; /* 8 bits */
  178. typedef unsigned int uInt; /* 16 bits or more */
  179. typedef unsigned long uLong; /* 32 bits or more */
  180. #if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
  181. /* Borland C/C++ ignores FAR inside typedef */
  182. # define Bytef Byte FAR
  183. #else
  184. typedef Byte FAR Bytef;
  185. #endif
  186. typedef char FAR charf;
  187. typedef int FAR intf;
  188. typedef uInt FAR uIntf;
  189. typedef uLong FAR uLongf;
  190. #ifdef STDC
  191. typedef void FAR *voidpf;
  192. typedef void *voidp;
  193. #else
  194. typedef Byte FAR *voidpf;
  195. typedef Byte *voidp;
  196. #endif
  197. /* Compile with -DZLIB_DLL for Windows DLL support */
  198. #if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
  199. # include <windows.h>
  200. # define EXPORT WINAPI
  201. #else
  202. # define EXPORT
  203. #endif
  204. #endif /* _ZCONF_H */
  205. /* --- zconf.h */
  206. #define ZLIB_VERSION "1.0.4P"
  207. /*
  208. The 'zlib' compression library provides in-memory compression and
  209. decompression functions, including integrity checks of the uncompressed
  210. data. This version of the library supports only one compression method
  211. (deflation) but other algorithms may be added later and will have the same
  212. stream interface.
  213. For compression the application must provide the output buffer and
  214. may optionally provide the input buffer for optimization. For decompression,
  215. the application must provide the input buffer and may optionally provide
  216. the output buffer for optimization.
  217. Compression can be done in a single step if the buffers are large
  218. enough (for example if an input file is mmap'ed), or can be done by
  219. repeated calls of the compression function. In the latter case, the
  220. application must provide more input and/or consume the output
  221. (providing more output space) before each call.
  222. The library does not install any signal handler. It is recommended to
  223. add at least a handler for SIGSEGV when decompressing; the library checks
  224. the consistency of the input data whenever possible but may go nuts
  225. for some forms of corrupted input.
  226. */
  227. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  228. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  229. struct internal_state;
  230. typedef struct z_stream_s {
  231. Bytef *next_in; /* next input byte */
  232. uInt avail_in; /* number of bytes available at next_in */
  233. uLong total_in; /* total nb of input bytes read so far */
  234. Bytef *next_out; /* next output byte should be put there */
  235. uInt avail_out; /* remaining free space at next_out */
  236. uLong total_out; /* total nb of bytes output so far */
  237. char *msg; /* last error message, NULL if no error */
  238. struct internal_state FAR *state; /* not visible by applications */
  239. alloc_func zalloc; /* used to allocate the internal state */
  240. free_func zfree; /* used to free the internal state */
  241. voidpf opaque; /* private data object passed to zalloc and zfree */
  242. int data_type; /* best guess about the data type: ascii or binary */
  243. uLong adler; /* adler32 value of the uncompressed data */
  244. uLong reserved; /* reserved for future use */
  245. } z_stream;
  246. typedef z_stream FAR *z_streamp;
  247. /*
  248. The application must update next_in and avail_in when avail_in has
  249. dropped to zero. It must update next_out and avail_out when avail_out
  250. has dropped to zero. The application must initialize zalloc, zfree and
  251. opaque before calling the init function. All other fields are set by the
  252. compression library and must not be updated by the application.
  253. The opaque value provided by the application will be passed as the first
  254. parameter for calls of zalloc and zfree. This can be useful for custom
  255. memory management. The compression library attaches no meaning to the
  256. opaque value.
  257. zalloc must return Z_NULL if there is not enough memory for the object.
  258. On 16-bit systems, the functions zalloc and zfree must be able to allocate
  259. exactly 65536 bytes, but will not be required to allocate more than this
  260. if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
  261. pointers returned by zalloc for objects of exactly 65536 bytes *must*
  262. have their offset normalized to zero. The default allocation function
  263. provided by this library ensures this (see zutil.c). To reduce memory
  264. requirements and avoid any allocation of 64K objects, at the expense of
  265. compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
  266. The fields total_in and total_out can be used for statistics or
  267. progress reports. After compression, total_in holds the total size of
  268. the uncompressed data and may be saved for use in the decompressor
  269. (particularly if the decompressor wants to decompress everything in
  270. a single step).
  271. */
  272. /* constants */
  273. #define Z_NO_FLUSH 0
  274. #define Z_PARTIAL_FLUSH 1
  275. #define Z_PACKET_FLUSH 2
  276. #define Z_SYNC_FLUSH 3
  277. #define Z_FULL_FLUSH 4
  278. #define Z_FINISH 5
  279. /* Allowed flush values; see deflate() below for details */
  280. #define Z_OK 0
  281. #define Z_STREAM_END 1
  282. #define Z_NEED_DICT 2
  283. #define Z_ERRNO (-1)
  284. #define Z_STREAM_ERROR (-2)
  285. #define Z_DATA_ERROR (-3)
  286. #define Z_MEM_ERROR (-4)
  287. #define Z_BUF_ERROR (-5)
  288. #define Z_VERSION_ERROR (-6)
  289. /* Return codes for the compression/decompression functions. Negative
  290. * values are errors, positive values are used for special but normal events.
  291. */
  292. #define Z_NO_COMPRESSION 0
  293. #define Z_BEST_SPEED 1
  294. #define Z_BEST_COMPRESSION 9
  295. #define Z_DEFAULT_COMPRESSION (-1)
  296. /* compression levels */
  297. #define Z_FILTERED 1
  298. #define Z_HUFFMAN_ONLY 2
  299. #define Z_DEFAULT_STRATEGY 0
  300. /* compression strategy; see deflateInit2() below for details */
  301. #define Z_BINARY 0
  302. #define Z_ASCII 1
  303. #define Z_UNKNOWN 2
  304. /* Possible values of the data_type field */
  305. #define Z_DEFLATED 8
  306. /* The deflate compression method (the only one supported in this version) */
  307. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  308. #define zlib_version zlibVersion()
  309. /* for compatibility with versions < 1.0.2 */
  310. /* basic functions */
  311. extern const char * EXPORT zlibVersion OF((void));
  312. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
  313. If the first character differs, the library code actually used is
  314. not compatible with the zlib.h header file used by the application.
  315. This check is automatically made by deflateInit and inflateInit.
  316. */
  317. /*
  318. extern int EXPORT deflateInit OF((z_streamp strm, int level));
  319. Initializes the internal stream state for compression. The fields
  320. zalloc, zfree and opaque must be initialized before by the caller.
  321. If zalloc and zfree are set to Z_NULL, deflateInit updates them to
  322. use default allocation functions.
  323. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
  324. 1 gives best speed, 9 gives best compression, 0 gives no compression at
  325. all (the input data is simply copied a block at a time).
  326. Z_DEFAULT_COMPRESSION requests a default compromise between speed and
  327. compression (currently equivalent to level 6).
  328. deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  329. enough memory, Z_STREAM_ERROR if level is not a valid compression level,
  330. Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
  331. with the version assumed by the caller (ZLIB_VERSION).
  332. msg is set to null if there is no error message. deflateInit does not
  333. perform any compression: this will be done by deflate().
  334. */
  335. extern int EXPORT deflate OF((z_streamp strm, int flush));
  336. /*
  337. Performs one or both of the following actions:
  338. - Compress more input starting at next_in and update next_in and avail_in
  339. accordingly. If not all input can be processed (because there is not
  340. enough room in the output buffer), next_in and avail_in are updated and
  341. processing will resume at this point for the next call of deflate().
  342. - Provide more output starting at next_out and update next_out and avail_out
  343. accordingly. This action is forced if the parameter flush is non zero.
  344. Forcing flush frequently degrades the compression ratio, so this parameter
  345. should be set only when necessary (in interactive applications).
  346. Some output may be provided even if flush is not set.
  347. Before the call of deflate(), the application should ensure that at least
  348. one of the actions is possible, by providing more input and/or consuming
  349. more output, and updating avail_in or avail_out accordingly; avail_out
  350. should never be zero before the call. The application can consume the
  351. compressed output when it wants, for example when the output buffer is full
  352. (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
  353. and with zero avail_out, it must be called again after making room in the
  354. output buffer because there might be more output pending.
  355. If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
  356. block is terminated and flushed to the output buffer so that the
  357. decompressor can get all input data available so far. For method 9, a future
  358. variant on method 8, the current block will be flushed but not terminated.
  359. Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
  360. output is byte aligned (the compressor can clear its internal bit buffer)
  361. and the current block is always terminated; this can be useful if the
  362. compressor has to be restarted from scratch after an interruption (in which
  363. case the internal state of the compressor may be lost).
  364. If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
  365. special marker is output and the compression dictionary is discarded; this
  366. is useful to allow the decompressor to synchronize if one compressed block
  367. has been damaged (see inflateSync below). Flushing degrades compression and
  368. so should be used only when necessary. Using Z_FULL_FLUSH too often can
  369. seriously degrade the compression. If deflate returns with avail_out == 0,
  370. this function must be called again with the same value of the flush
  371. parameter and more output space (updated avail_out), until the flush is
  372. complete (deflate returns with non-zero avail_out).
  373. If the parameter flush is set to Z_PACKET_FLUSH, the compression
  374. block is terminated, and a zero-length stored block is output,
  375. omitting the length bytes (the effect of this is that the 3-bit type
  376. code 000 for a stored block is output, and the output is then
  377. byte-aligned). This is designed for use at the end of a PPP packet.
  378. If the parameter flush is set to Z_FINISH, pending input is processed,
  379. pending output is flushed and deflate returns with Z_STREAM_END if there
  380. was enough output space; if deflate returns with Z_OK, this function must be
  381. called again with Z_FINISH and more output space (updated avail_out) but no
  382. more input data, until it returns with Z_STREAM_END or an error. After
  383. deflate has returned Z_STREAM_END, the only possible operations on the
  384. stream are deflateReset or deflateEnd.
  385. Z_FINISH can be used immediately after deflateInit if all the compression
  386. is to be done in a single step. In this case, avail_out must be at least
  387. 0.1% larger than avail_in plus 12 bytes. If deflate does not return
  388. Z_STREAM_END, then it must be called again as described above.
  389. deflate() may update data_type if it can make a good guess about
  390. the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
  391. binary. This field is only for information purposes and does not affect
  392. the compression algorithm in any manner.
  393. deflate() returns Z_OK if some progress has been made (more input
  394. processed or more output produced), Z_STREAM_END if all input has been
  395. consumed and all output has been produced (only when flush is set to
  396. Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
  397. if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
  398. */
  399. extern int EXPORT deflateEnd OF((z_streamp strm));
  400. /*
  401. All dynamically allocated data structures for this stream are freed.
  402. This function discards any unprocessed input and does not flush any
  403. pending output.
  404. deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
  405. stream state was inconsistent, Z_DATA_ERROR if the stream was freed
  406. prematurely (some input or output was discarded). In the error case,
  407. msg may be set but then points to a static string (which must not be
  408. deallocated).
  409. */
  410. /*
  411. extern int EXPORT inflateInit OF((z_streamp strm));
  412. Initializes the internal stream state for decompression. The fields
  413. zalloc, zfree and opaque must be initialized before by the caller. If
  414. zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
  415. allocation functions.
  416. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  417. enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
  418. with the version assumed by the caller. msg is set to null if there is no
  419. error message. inflateInit does not perform any decompression: this will be
  420. done by inflate().
  421. */
  422. extern int EXPORT inflate OF((z_streamp strm, int flush));
  423. /*
  424. Performs one or both of the following actions:
  425. - Decompress more input starting at next_in and update next_in and avail_in
  426. accordingly. If not all input can be processed (because there is not
  427. enough room in the output buffer), next_in is updated and processing
  428. will resume at this point for the next call of inflate().
  429. - Provide more output starting at next_out and update next_out and avail_out
  430. accordingly. inflate() provides as much output as possible, until there
  431. is no more input data or no more space in the output buffer (see below
  432. about the flush parameter).
  433. Before the call of inflate(), the application should ensure that at least
  434. one of the actions is possible, by providing more input and/or consuming
  435. more output, and updating the next_* and avail_* values accordingly.
  436. The application can consume the uncompressed output when it wants, for
  437. example when the output buffer is full (avail_out == 0), or after each
  438. call of inflate(). If inflate returns Z_OK and with zero avail_out, it
  439. must be called again after making room in the output buffer because there
  440. might be more output pending.
  441. If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
  442. inflate flushes as much output as possible to the output buffer. The
  443. flushing behavior of inflate is not specified for values of the flush
  444. parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
  445. current implementation actually flushes as much output as possible
  446. anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data
  447. has been consumed, it is expecting to see the length field of a stored
  448. block; if not, it returns Z_DATA_ERROR.
  449. inflate() should normally be called until it returns Z_STREAM_END or an
  450. error. However if all decompression is to be performed in a single step
  451. (a single call of inflate), the parameter flush should be set to
  452. Z_FINISH. In this case all pending input is processed and all pending
  453. output is flushed; avail_out must be large enough to hold all the
  454. uncompressed data. (The size of the uncompressed data may have been saved
  455. by the compressor for this purpose.) The next operation on this stream must
  456. be inflateEnd to deallocate the decompression state. The use of Z_FINISH
  457. is never required, but can be used to inform inflate that a faster routine
  458. may be used for the single inflate() call.
  459. inflate() returns Z_OK if some progress has been made (more input
  460. processed or more output produced), Z_STREAM_END if the end of the
  461. compressed data has been reached and all uncompressed output has been
  462. produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
  463. inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
  464. Z_STREAM_ERROR if the stream structure was inconsistent (for example if
  465. next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
  466. Z_BUF_ERROR if no progress is possible or if there was not enough room in
  467. the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
  468. application may then call inflateSync to look for a good compression block.
  469. In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
  470. dictionary chosen by the compressor.
  471. */
  472. extern int EXPORT inflateEnd OF((z_streamp strm));
  473. /*
  474. All dynamically allocated data structures for this stream are freed.
  475. This function discards any unprocessed input and does not flush any
  476. pending output.
  477. inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
  478. was inconsistent. In the error case, msg may be set but then points to a
  479. static string (which must not be deallocated).
  480. */
  481. /* Advanced functions */
  482. /*
  483. The following functions are needed only in some special applications.
  484. */
  485. /*
  486. extern int EXPORT deflateInit2 OF((z_streamp strm,
  487. int level,
  488. int method,
  489. int windowBits,
  490. int memLevel,
  491. int strategy));
  492. This is another version of deflateInit with more compression options. The
  493. fields next_in, zalloc, zfree and opaque must be initialized before by
  494. the caller.
  495. The method parameter is the compression method. It must be Z_DEFLATED in
  496. this version of the library. (Method 9 will allow a 64K history buffer and
  497. partial block flushes.)
  498. The windowBits parameter is the base two logarithm of the window size
  499. (the size of the history buffer). It should be in the range 8..15 for this
  500. version of the library (the value 16 will be allowed for method 9). Larger
  501. values of this parameter result in better compression at the expense of
  502. memory usage. The default value is 15 if deflateInit is used instead.
  503. The memLevel parameter specifies how much memory should be allocated
  504. for the internal compression state. memLevel=1 uses minimum memory but
  505. is slow and reduces compression ratio; memLevel=9 uses maximum memory
  506. for optimal speed. The default value is 8. See zconf.h for total memory
  507. usage as a function of windowBits and memLevel.
  508. The strategy parameter is used to tune the compression algorithm. Use the
  509. value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
  510. filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
  511. string match). Filtered data consists mostly of small values with a
  512. somewhat random distribution. In this case, the compression algorithm is
  513. tuned to compress them better. The effect of Z_FILTERED is to force more
  514. Huffman coding and less string matching; it is somewhat intermediate
  515. between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
  516. the compression ratio but not the correctness of the compressed output even
  517. if it is not set appropriately.
  518. If next_in is not null, the library will use this buffer to hold also
  519. some history information; the buffer must either hold the entire input
  520. data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
  521. is null, the library will allocate its own history buffer (and leave next_in
  522. null). next_out need not be provided here but must be provided by the
  523. application for the next call of deflate().
  524. If the history buffer is provided by the application, next_in must
  525. must never be changed by the application since the compressor maintains
  526. information inside this buffer from call to call; the application
  527. must provide more input only by increasing avail_in. next_in is always
  528. reset by the library in this case.
  529. deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
  530. not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
  531. an invalid method). msg is set to null if there is no error message.
  532. deflateInit2 does not perform any compression: this will be done by
  533. deflate().
  534. */
  535. extern int EXPORT deflateSetDictionary OF((z_streamp strm,
  536. const Bytef *dictionary,
  537. uInt dictLength));
  538. /*
  539. Initializes the compression dictionary (history buffer) from the given
  540. byte sequence without producing any compressed output. This function must
  541. be called immediately after deflateInit or deflateInit2, before any call
  542. of deflate. The compressor and decompressor must use exactly the same
  543. dictionary (see inflateSetDictionary).
  544. The dictionary should consist of strings (byte sequences) that are likely
  545. to be encountered later in the data to be compressed, with the most commonly
  546. used strings preferably put towards the end of the dictionary. Using a
  547. dictionary is most useful when the data to be compressed is short and
  548. can be predicted with good accuracy; the data can then be compressed better
  549. than with the default empty dictionary. In this version of the library,
  550. only the last 32K bytes of the dictionary are used.
  551. Upon return of this function, strm->adler is set to the Adler32 value
  552. of the dictionary; the decompressor may later use this value to determine
  553. which dictionary has been used by the compressor. (The Adler32 value
  554. applies to the whole dictionary even if only a subset of the dictionary is
  555. actually used by the compressor.)
  556. deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
  557. parameter is invalid (such as NULL dictionary) or the stream state
  558. is inconsistent (for example if deflate has already been called for this
  559. stream). deflateSetDictionary does not perform any compression: this will
  560. be done by deflate().
  561. */
  562. extern int EXPORT deflateCopy OF((z_streamp dest,
  563. z_streamp source));
  564. /*
  565. Sets the destination stream as a complete copy of the source stream. If
  566. the source stream is using an application-supplied history buffer, a new
  567. buffer is allocated for the destination stream. The compressed output
  568. buffer is always application-supplied. It's the responsibility of the
  569. application to provide the correct values of next_out and avail_out for the
  570. next call of deflate.
  571. This function can be useful when several compression strategies will be
  572. tried, for example when there are several ways of pre-processing the input
  573. data with a filter. The streams that will be discarded should then be freed
  574. by calling deflateEnd. Note that deflateCopy duplicates the internal
  575. compression state which can be quite large, so this strategy is slow and
  576. can consume lots of memory.
  577. deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
  578. enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
  579. (such as zalloc being NULL). msg is left unchanged in both source and
  580. destination.
  581. */
  582. extern int EXPORT deflateReset OF((z_streamp strm));
  583. /*
  584. This function is equivalent to deflateEnd followed by deflateInit,
  585. but does not free and reallocate all the internal compression state.
  586. The stream will keep the same compression level and any other attributes
  587. that may have been set by deflateInit2.
  588. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  589. stream state was inconsistent (such as zalloc or state being NULL).
  590. */
  591. extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
  592. /*
  593. Dynamically update the compression level and compression strategy.
  594. This can be used to switch between compression and straight copy of
  595. the input data, or to switch to a different kind of input data requiring
  596. a different strategy. If the compression level is changed, the input
  597. available so far is compressed with the old level (and may be flushed);
  598. the new level will take effect only at the next call of deflate().
  599. Before the call of deflateParams, the stream state must be set as for
  600. a call of deflate(), since the currently available input may have to
  601. be compressed and flushed. In particular, strm->avail_out must be non-zero.
  602. deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
  603. stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
  604. if strm->avail_out was zero.
  605. */
  606. extern int EXPORT deflateOutputPending OF((z_streamp strm));
  607. /*
  608. Returns the number of bytes of output which are immediately
  609. available from the compressor (i.e. without any further input
  610. or flush).
  611. */
  612. /*
  613. extern int EXPORT inflateInit2 OF((z_streamp strm,
  614. int windowBits));
  615. This is another version of inflateInit with more compression options. The
  616. fields next_out, zalloc, zfree and opaque must be initialized before by
  617. the caller.
  618. The windowBits parameter is the base two logarithm of the maximum window
  619. size (the size of the history buffer). It should be in the range 8..15 for
  620. this version of the library (the value 16 will be allowed soon). The
  621. default value is 15 if inflateInit is used instead. If a compressed stream
  622. with a larger window size is given as input, inflate() will return with
  623. the error code Z_DATA_ERROR instead of trying to allocate a larger window.
  624. If next_out is not null, the library will use this buffer for the history
  625. buffer; the buffer must either be large enough to hold the entire output
  626. data, or have at least 1<<windowBits bytes. If next_out is null, the
  627. library will allocate its own buffer (and leave next_out null). next_in
  628. need not be provided here but must be provided by the application for the
  629. next call of inflate().
  630. If the history buffer is provided by the application, next_out must
  631. never be changed by the application since the decompressor maintains
  632. history information inside this buffer from call to call; the application
  633. can only reset next_out to the beginning of the history buffer when
  634. avail_out is zero and all output has been consumed.
  635. inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
  636. not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
  637. windowBits < 8). msg is set to null if there is no error message.
  638. inflateInit2 does not perform any decompression: this will be done by
  639. inflate().
  640. */
  641. extern int EXPORT inflateSetDictionary OF((z_streamp strm,
  642. const Bytef *dictionary,
  643. uInt dictLength));
  644. /*
  645. Initializes the decompression dictionary (history buffer) from the given
  646. uncompressed byte sequence. This function must be called immediately after
  647. a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
  648. by the compressor can be determined from the Adler32 value returned by this
  649. call of inflate. The compressor and decompressor must use exactly the same
  650. dictionary (see deflateSetDictionary).
  651. inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
  652. parameter is invalid (such as NULL dictionary) or the stream state is
  653. inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
  654. expected one (incorrect Adler32 value). inflateSetDictionary does not
  655. perform any decompression: this will be done by subsequent calls of
  656. inflate().
  657. */
  658. extern int EXPORT inflateSync OF((z_streamp strm));
  659. /*
  660. Skips invalid compressed data until the special marker (see deflate()
  661. above) can be found, or until all available input is skipped. No output
  662. is provided.
  663. inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
  664. if no more input was provided, Z_DATA_ERROR if no marker has been found,
  665. or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
  666. case, the application may save the current current value of total_in which
  667. indicates where valid compressed data was found. In the error case, the
  668. application may repeatedly call inflateSync, providing more input each time,
  669. until success or end of the input data.
  670. */
  671. extern int EXPORT inflateReset OF((z_streamp strm));
  672. /*
  673. This function is equivalent to inflateEnd followed by inflateInit,
  674. but does not free and reallocate all the internal decompression state.
  675. The stream will keep attributes that may have been set by inflateInit2.
  676. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  677. stream state was inconsistent (such as zalloc or state being NULL).
  678. */
  679. extern int inflateIncomp OF((z_stream *strm));
  680. /*
  681. This function adds the data at next_in (avail_in bytes) to the output
  682. history without performing any output. There must be no pending output,
  683. and the decompressor must be expecting to see the start of a block.
  684. Calling this function is equivalent to decompressing a stored block
  685. containing the data at next_in (except that the data is not output).
  686. */
  687. /* utility functions */
  688. /*
  689. The following utility functions are implemented on top of the
  690. basic stream-oriented functions. To simplify the interface, some
  691. default options are assumed (compression level, window size,
  692. standard memory allocation functions). The source code of these
  693. utility functions can easily be modified if you need special options.
  694. */
  695. extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
  696. const Bytef *source, uLong sourceLen));
  697. /*
  698. Compresses the source buffer into the destination buffer. sourceLen is
  699. the byte length of the source buffer. Upon entry, destLen is the total
  700. size of the destination buffer, which must be at least 0.1% larger than
  701. sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
  702. compressed buffer.
  703. This function can be used to compress a whole file at once if the
  704. input file is mmap'ed.
  705. compress returns Z_OK if success, Z_MEM_ERROR if there was not
  706. enough memory, Z_BUF_ERROR if there was not enough room in the output
  707. buffer.
  708. */
  709. extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  710. const Bytef *source, uLong sourceLen));
  711. /*
  712. Decompresses the source buffer into the destination buffer. sourceLen is
  713. the byte length of the source buffer. Upon entry, destLen is the total
  714. size of the destination buffer, which must be large enough to hold the
  715. entire uncompressed data. (The size of the uncompressed data must have
  716. been saved previously by the compressor and transmitted to the decompressor
  717. by some mechanism outside the scope of this compression library.)
  718. Upon exit, destLen is the actual size of the compressed buffer.
  719. This function can be used to decompress a whole file at once if the
  720. input file is mmap'ed.
  721. uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
  722. enough memory, Z_BUF_ERROR if there was not enough room in the output
  723. buffer, or Z_DATA_ERROR if the input data was corrupted.
  724. */
  725. typedef voidp gzFile;
  726. extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
  727. /*
  728. Opens a gzip (.gz) file for reading or writing. The mode parameter
  729. is as in fopen ("rb" or "wb") but can also include a compression level
  730. ("wb9"). gzopen can be used to read a file which is not in gzip format;
  731. in this case gzread will directly read from the file without decompression.
  732. gzopen returns NULL if the file could not be opened or if there was
  733. insufficient memory to allocate the (de)compression state; errno
  734. can be checked to distinguish the two cases (if errno is zero, the
  735. zlib error is Z_MEM_ERROR).
  736. */
  737. extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
  738. /*
  739. gzdopen() associates a gzFile with the file descriptor fd. File
  740. descriptors are obtained from calls like open, dup, creat, pipe or
  741. fileno (in the file has been previously opened with fopen).
  742. The mode parameter is as in gzopen.
  743. The next call of gzclose on the returned gzFile will also close the
  744. file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
  745. descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
  746. gzdopen returns NULL if there was insufficient memory to allocate
  747. the (de)compression state.
  748. */
  749. extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  750. /*
  751. Reads the given number of uncompressed bytes from the compressed file.
  752. If the input file was not in gzip format, gzread copies the given number
  753. of bytes into the buffer.
  754. gzread returns the number of uncompressed bytes actually read (0 for
  755. end of file, -1 for error). */
  756. extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
  757. /*
  758. Writes the given number of uncompressed bytes into the compressed file.
  759. gzwrite returns the number of uncompressed bytes actually written
  760. (0 in case of error).
  761. */
  762. extern int EXPORT gzflush OF((gzFile file, int flush));
  763. /*
  764. Flushes all pending output into the compressed file. The parameter
  765. flush is as in the deflate() function. The return value is the zlib
  766. error number (see function gzerror below). gzflush returns Z_OK if
  767. the flush parameter is Z_FINISH and all output could be flushed.
  768. gzflush should be called only when strictly necessary because it can
  769. degrade compression.
  770. */
  771. extern int EXPORT gzclose OF((gzFile file));
  772. /*
  773. Flushes all pending output if necessary, closes the compressed file
  774. and deallocates all the (de)compression state. The return value is the zlib
  775. error number (see function gzerror below).
  776. */
  777. extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
  778. /*
  779. Returns the error message for the last error which occurred on the
  780. given compressed file. errnum is set to zlib error number. If an
  781. error occurred in the file system and not in the compression library,
  782. errnum is set to Z_ERRNO and the application may consult errno
  783. to get the exact error code.
  784. */
  785. /* checksum functions */
  786. /*
  787. These functions are not related to compression but are exported
  788. anyway because they might be useful in applications using the
  789. compression library.
  790. */
  791. extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  792. /*
  793. Update a running Adler-32 checksum with the bytes buf[0..len-1] and
  794. return the updated checksum. If buf is NULL, this function returns
  795. the required initial value for the checksum.
  796. An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
  797. much faster. Usage example:
  798. uLong adler = adler32(0L, Z_NULL, 0);
  799. while (read_buffer(buffer, length) != EOF) {
  800. adler = adler32(adler, buffer, length);
  801. }
  802. if (adler != original_adler) error();
  803. */
  804. extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  805. /*
  806. Update a running crc with the bytes buf[0..len-1] and return the updated
  807. crc. If buf is NULL, this function returns the required initial value
  808. for the crc. Pre- and post-conditioning (one's complement) is performed
  809. within this function so it shouldn't be done by the application.
  810. Usage example:
  811. uLong crc = crc32(0L, Z_NULL, 0);
  812. while (read_buffer(buffer, length) != EOF) {
  813. crc = crc32(crc, buffer, length);
  814. }
  815. if (crc != original_crc) error();
  816. */
  817. /* various hacks, don't look :) */
  818. /* deflateInit and inflateInit are macros to allow checking the zlib version
  819. * and the compiler's view of z_stream:
  820. */
  821. extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
  822. const char *version, int stream_size));
  823. extern int EXPORT inflateInit_ OF((z_streamp strm,
  824. const char *version, int stream_size));
  825. extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  826. int windowBits, int memLevel, int strategy,
  827. const char *version, int stream_size));
  828. extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  829. const char *version, int stream_size));
  830. #define deflateInit(strm, level) \
  831. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  832. #define inflateInit(strm) \
  833. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  834. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  835. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  836. (strategy), ZLIB_VERSION, sizeof(z_stream))
  837. #define inflateInit2(strm, windowBits) \
  838. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  839. #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
  840. struct internal_state {int dummy;}; /* hack for buggy compilers */
  841. #endif
  842. uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
  843. #ifdef __cplusplus
  844. }
  845. #endif
  846. #endif /* _ZLIB_H */
  847. /* --- zlib.h */