]>
Commit | Line | Data |
---|---|---|
9bccf70c | 1 | /* $FreeBSD: src/sys/net/zlib.h,v 1.7 1999/12/29 04:38:38 peter Exp $ */ |
1c79356b A |
2 | |
3 | /* | |
9bccf70c A |
4 | * This file is derived from zlib.h and zconf.h from the zlib-1.1.4 |
5 | * distribution by Jean-loup Gailly and Mark Adler. | |
1c79356b A |
6 | */ |
7 | ||
1c79356b A |
8 | /* +++ zlib.h */ |
9 | /* zlib.h -- interface of the 'zlib' general purpose compression library | |
9bccf70c | 10 | version 1.1.4, March 11th, 2002 |
1c79356b | 11 | |
9bccf70c | 12 | Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler |
1c79356b A |
13 | |
14 | This software is provided 'as-is', without any express or implied | |
15 | warranty. In no event will the authors be held liable for any damages | |
16 | arising from the use of this software. | |
17 | ||
18 | Permission is granted to anyone to use this software for any purpose, | |
19 | including commercial applications, and to alter it and redistribute it | |
20 | freely, subject to the following restrictions: | |
21 | ||
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 | ||
30 | Jean-loup Gailly Mark Adler | |
9bccf70c | 31 | jloup@gzip.org madler@alumni.caltech.edu |
1c79356b A |
32 | |
33 | ||
34 | The data format used by the zlib library is described by RFCs (Request for | |
35 | Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt | |
36 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). | |
37 | */ | |
38 | ||
39 | #ifndef _ZLIB_H | |
40 | #define _ZLIB_H | |
9bccf70c A |
41 | #include <sys/appleapiopts.h> |
42 | ||
43 | #if !defined(KERNEL) || defined(__APPLE_API_PRIVATE) | |
1c79356b A |
44 | |
45 | #if __cplusplus | |
46 | extern "C" { | |
47 | #endif | |
48 | ||
49 | ||
50 | /* +++ zconf.h */ | |
51 | /* zconf.h -- configuration of the zlib compression library | |
9bccf70c | 52 | * Copyright (C) 1995-2002 Jean-loup Gailly. |
1c79356b A |
53 | * For conditions of distribution and use, see copyright notice in zlib.h |
54 | */ | |
55 | ||
1c79356b A |
56 | #ifndef _ZCONF_H |
57 | #define _ZCONF_H | |
58 | ||
59 | /* | |
60 | * 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. | |
62 | */ | |
9bccf70c | 63 | #ifdef Z_PREFIX |
1c79356b A |
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 inflateInit2_ z_inflateInit2_ | |
76 | # define inflateSetDictionary z_inflateSetDictionary | |
77 | # define inflateSync z_inflateSync | |
9bccf70c | 78 | # define inflateSyncPoint z_inflateSyncPoint |
1c79356b A |
79 | # define inflateReset z_inflateReset |
80 | # define compress z_compress | |
9bccf70c | 81 | # define compress2 z_compress2 |
1c79356b A |
82 | # define uncompress z_uncompress |
83 | # define adler32 z_adler32 | |
84 | # define crc32 z_crc32 | |
85 | # define get_crc_table z_get_crc_table | |
86 | ||
87 | # define Byte z_Byte | |
88 | # define uInt z_uInt | |
89 | # define uLong z_uLong | |
90 | # define Bytef z_Bytef | |
91 | # define charf z_charf | |
92 | # define intf z_intf | |
93 | # define uIntf z_uIntf | |
94 | # define uLongf z_uLongf | |
95 | # define voidpf z_voidpf | |
96 | # define voidp z_voidp | |
97 | #endif | |
98 | ||
99 | #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) | |
100 | # define WIN32 | |
101 | #endif | |
102 | #if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) | |
103 | # ifndef __32BIT__ | |
104 | # define __32BIT__ | |
105 | # endif | |
106 | #endif | |
107 | #if defined(__MSDOS__) && !defined(MSDOS) | |
108 | # define MSDOS | |
109 | #endif | |
110 | ||
111 | /* | |
112 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more | |
113 | * than 64k bytes at a time (needed on systems with 16-bit int). | |
114 | */ | |
115 | #if defined(MSDOS) && !defined(__32BIT__) | |
116 | # define MAXSEG_64K | |
117 | #endif | |
9bccf70c | 118 | #ifdef MSDOS |
1c79356b A |
119 | # define UNALIGNED_OK |
120 | #endif | |
121 | ||
122 | #if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) | |
123 | # define STDC | |
124 | #endif | |
9bccf70c A |
125 | #if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) |
126 | # ifndef STDC | |
127 | # define STDC | |
128 | # endif | |
1c79356b A |
129 | #endif |
130 | ||
131 | #ifndef STDC | |
132 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ | |
133 | # define const | |
134 | # endif | |
135 | #endif | |
136 | ||
137 | /* Some Mac compilers merge all .h files incorrectly: */ | |
138 | #if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) | |
139 | # define NO_DUMMY_DECL | |
140 | #endif | |
141 | ||
9bccf70c A |
142 | /* Old Borland C incorrectly complains about missing returns: */ |
143 | #if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) | |
144 | # define NEED_DUMMY_RETURN | |
145 | #endif | |
146 | ||
147 | ||
1c79356b A |
148 | /* Maximum value for memLevel in deflateInit2 */ |
149 | #ifndef MAX_MEM_LEVEL | |
150 | # ifdef MAXSEG_64K | |
151 | # define MAX_MEM_LEVEL 8 | |
152 | # else | |
153 | # define MAX_MEM_LEVEL 9 | |
154 | # endif | |
155 | #endif | |
156 | ||
9bccf70c A |
157 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. |
158 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files | |
159 | * created by gzip. (Files created by minigzip can still be extracted by | |
160 | * gzip.) | |
161 | */ | |
1c79356b A |
162 | #ifndef MAX_WBITS |
163 | # define MAX_WBITS 15 /* 32K LZ77 window */ | |
164 | #endif | |
165 | ||
166 | /* The memory requirements for deflate are (in bytes): | |
9bccf70c | 167 | (1 << (windowBits+2)) + (1 << (memLevel+9)) |
1c79356b A |
168 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) |
169 | plus a few kilobytes for small objects. For example, if you want to reduce | |
170 | the default memory requirements from 256K to 128K, compile with | |
171 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" | |
172 | Of course this will generally degrade compression (there's no free lunch). | |
173 | ||
174 | The memory requirements for inflate are (in bytes) 1 << windowBits | |
175 | that is, 32K for windowBits=15 (default value) plus a few kilobytes | |
176 | for small objects. | |
177 | */ | |
178 | ||
179 | /* Type declarations */ | |
180 | ||
181 | #ifndef OF /* function prototypes */ | |
182 | # ifdef STDC | |
183 | # define OF(args) args | |
184 | # else | |
185 | # define OF(args) () | |
186 | # endif | |
187 | #endif | |
188 | ||
189 | /* The following definitions for FAR are needed only for MSDOS mixed | |
190 | * model programming (small or medium model with some far allocations). | |
191 | * This was tested only with MSC; for other MSDOS compilers you may have | |
192 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, | |
193 | * just define FAR to be empty. | |
194 | */ | |
195 | #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) | |
196 | /* MSC small or medium model */ | |
197 | # define SMALL_MEDIUM | |
198 | # ifdef _MSC_VER | |
9bccf70c | 199 | # define FAR _far |
1c79356b A |
200 | # else |
201 | # define FAR far | |
202 | # endif | |
203 | #endif | |
204 | #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) | |
205 | # ifndef __32BIT__ | |
206 | # define SMALL_MEDIUM | |
9bccf70c | 207 | # define FAR _far |
1c79356b A |
208 | # endif |
209 | #endif | |
9bccf70c A |
210 | |
211 | /* Compile with -DZLIB_DLL for Windows DLL support */ | |
212 | #if defined(ZLIB_DLL) | |
213 | # if defined(_WINDOWS) || defined(WINDOWS) | |
214 | # ifdef FAR | |
215 | # undef FAR | |
216 | # endif | |
217 | # include <windows.h> | |
218 | # define ZEXPORT WINAPI | |
219 | # ifdef WIN32 | |
220 | # define ZEXPORTVA WINAPIV | |
221 | # else | |
222 | # define ZEXPORTVA FAR _cdecl _export | |
223 | # endif | |
224 | # endif | |
225 | # if defined (__BORLANDC__) | |
226 | # if (__BORLANDC__ >= 0x0500) && defined (WIN32) | |
227 | # include <windows.h> | |
228 | # define ZEXPORT __declspec(dllexport) WINAPI | |
229 | # define ZEXPORTRVA __declspec(dllexport) WINAPIV | |
230 | # else | |
231 | # if defined (_Windows) && defined (__DLL__) | |
232 | # define ZEXPORT _export | |
233 | # define ZEXPORTVA _export | |
234 | # endif | |
235 | # endif | |
236 | # endif | |
237 | #endif | |
238 | ||
239 | #if defined (__BEOS__) | |
240 | # if defined (ZLIB_DLL) | |
241 | # define ZEXTERN extern __declspec(dllexport) | |
242 | # else | |
243 | # define ZEXTERN extern __declspec(dllimport) | |
244 | # endif | |
245 | #endif | |
246 | ||
247 | #ifndef ZEXPORT | |
248 | # define ZEXPORT | |
249 | #endif | |
250 | #ifndef ZEXPORTVA | |
251 | # define ZEXPORTVA | |
252 | #endif | |
253 | #ifndef ZEXTERN | |
254 | # define ZEXTERN extern | |
255 | #endif | |
256 | ||
1c79356b A |
257 | #ifndef FAR |
258 | # define FAR | |
259 | #endif | |
260 | ||
9bccf70c | 261 | #if !defined(MACOS) && !defined(TARGET_OS_MAC) |
1c79356b | 262 | typedef unsigned char Byte; /* 8 bits */ |
9bccf70c | 263 | #endif |
1c79356b A |
264 | typedef unsigned int uInt; /* 16 bits or more */ |
265 | typedef unsigned long uLong; /* 32 bits or more */ | |
266 | ||
9bccf70c A |
267 | #ifdef SMALL_MEDIUM |
268 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ | |
1c79356b A |
269 | # define Bytef Byte FAR |
270 | #else | |
271 | typedef Byte FAR Bytef; | |
272 | #endif | |
273 | typedef char FAR charf; | |
274 | typedef int FAR intf; | |
275 | typedef uInt FAR uIntf; | |
276 | typedef uLong FAR uLongf; | |
277 | ||
278 | #ifdef STDC | |
279 | typedef void FAR *voidpf; | |
280 | typedef void *voidp; | |
281 | #else | |
282 | typedef Byte FAR *voidpf; | |
283 | typedef Byte *voidp; | |
284 | #endif | |
285 | ||
9bccf70c A |
286 | #ifdef HAVE_UNISTD_H |
287 | # include <sys/types.h> /* for off_t */ | |
288 | # include <unistd.h> /* for SEEK_* and off_t */ | |
289 | # define z_off_t off_t | |
290 | #endif | |
291 | #ifndef SEEK_SET | |
292 | # define SEEK_SET 0 /* Seek from beginning of file. */ | |
293 | # define SEEK_CUR 1 /* Seek from current position. */ | |
294 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ | |
295 | #endif | |
296 | #ifndef z_off_t | |
297 | # define z_off_t long | |
298 | #endif | |
1c79356b | 299 | |
9bccf70c A |
300 | /* MVS linker does not support external names larger than 8 bytes */ |
301 | #if defined(__MVS__) | |
302 | # pragma map(deflateInit_,"DEIN") | |
303 | # pragma map(deflateInit2_,"DEIN2") | |
304 | # pragma map(deflateEnd,"DEEND") | |
305 | # pragma map(inflateInit_,"ININ") | |
306 | # pragma map(inflateInit2_,"ININ2") | |
307 | # pragma map(inflateEnd,"INEND") | |
308 | # pragma map(inflateSync,"INSY") | |
309 | # pragma map(inflateSetDictionary,"INSEDI") | |
310 | # pragma map(inflate_blocks,"INBL") | |
311 | # pragma map(inflate_blocks_new,"INBLNE") | |
312 | # pragma map(inflate_blocks_free,"INBLFR") | |
313 | # pragma map(inflate_blocks_reset,"INBLRE") | |
314 | # pragma map(inflate_codes_free,"INCOFR") | |
315 | # pragma map(inflate_codes,"INCO") | |
316 | # pragma map(inflate_fast,"INFA") | |
317 | # pragma map(inflate_flush,"INFLU") | |
318 | # pragma map(inflate_mask,"INMA") | |
319 | # pragma map(inflate_set_dictionary,"INSEDI2") | |
320 | # pragma map(inflate_copyright,"INCOPY") | |
321 | # pragma map(inflate_trees_bits,"INTRBI") | |
322 | # pragma map(inflate_trees_dynamic,"INTRDY") | |
323 | # pragma map(inflate_trees_fixed,"INTRFI") | |
324 | # pragma map(inflate_trees_free,"INTRFR") | |
1c79356b A |
325 | #endif |
326 | ||
327 | #endif /* _ZCONF_H */ | |
328 | /* --- zconf.h */ | |
329 | ||
9bccf70c | 330 | #define ZLIB_VERSION "1.1.4" |
1c79356b A |
331 | |
332 | /* | |
333 | The 'zlib' compression library provides in-memory compression and | |
334 | decompression functions, including integrity checks of the uncompressed | |
335 | data. This version of the library supports only one compression method | |
9bccf70c | 336 | (deflation) but other algorithms will be added later and will have the same |
1c79356b A |
337 | stream interface. |
338 | ||
1c79356b A |
339 | Compression can be done in a single step if the buffers are large |
340 | enough (for example if an input file is mmap'ed), or can be done by | |
341 | repeated calls of the compression function. In the latter case, the | |
342 | application must provide more input and/or consume the output | |
343 | (providing more output space) before each call. | |
344 | ||
9bccf70c A |
345 | The library also supports reading and writing files in gzip (.gz) format |
346 | with an interface similar to that of stdio. | |
347 | ||
348 | The library does not install any signal handler. The decoder checks | |
349 | the consistency of the compressed data, so the library should never | |
350 | crash even in case of corrupted input. | |
1c79356b A |
351 | */ |
352 | ||
353 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); | |
354 | typedef void (*free_func) OF((voidpf opaque, voidpf address)); | |
355 | ||
356 | struct internal_state; | |
357 | ||
358 | typedef struct z_stream_s { | |
359 | Bytef *next_in; /* next input byte */ | |
360 | uInt avail_in; /* number of bytes available at next_in */ | |
361 | uLong total_in; /* total nb of input bytes read so far */ | |
362 | ||
363 | Bytef *next_out; /* next output byte should be put there */ | |
364 | uInt avail_out; /* remaining free space at next_out */ | |
365 | uLong total_out; /* total nb of bytes output so far */ | |
366 | ||
367 | char *msg; /* last error message, NULL if no error */ | |
368 | struct internal_state FAR *state; /* not visible by applications */ | |
369 | ||
370 | alloc_func zalloc; /* used to allocate the internal state */ | |
371 | free_func zfree; /* used to free the internal state */ | |
372 | voidpf opaque; /* private data object passed to zalloc and zfree */ | |
373 | ||
374 | int data_type; /* best guess about the data type: ascii or binary */ | |
375 | uLong adler; /* adler32 value of the uncompressed data */ | |
376 | uLong reserved; /* reserved for future use */ | |
377 | } z_stream; | |
378 | ||
379 | typedef z_stream FAR *z_streamp; | |
380 | ||
381 | /* | |
382 | The application must update next_in and avail_in when avail_in has | |
383 | dropped to zero. It must update next_out and avail_out when avail_out | |
384 | has dropped to zero. The application must initialize zalloc, zfree and | |
385 | opaque before calling the init function. All other fields are set by the | |
386 | compression library and must not be updated by the application. | |
387 | ||
388 | The opaque value provided by the application will be passed as the first | |
389 | parameter for calls of zalloc and zfree. This can be useful for custom | |
390 | memory management. The compression library attaches no meaning to the | |
391 | opaque value. | |
392 | ||
393 | zalloc must return Z_NULL if there is not enough memory for the object. | |
9bccf70c A |
394 | If zlib is used in a multi-threaded application, zalloc and zfree must be |
395 | thread safe. | |
396 | ||
1c79356b A |
397 | On 16-bit systems, the functions zalloc and zfree must be able to allocate |
398 | exactly 65536 bytes, but will not be required to allocate more than this | |
399 | if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, | |
400 | pointers returned by zalloc for objects of exactly 65536 bytes *must* | |
401 | have their offset normalized to zero. The default allocation function | |
402 | provided by this library ensures this (see zutil.c). To reduce memory | |
403 | requirements and avoid any allocation of 64K objects, at the expense of | |
404 | compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). | |
405 | ||
406 | The fields total_in and total_out can be used for statistics or | |
407 | progress reports. After compression, total_in holds the total size of | |
408 | the uncompressed data and may be saved for use in the decompressor | |
409 | (particularly if the decompressor wants to decompress everything in | |
410 | a single step). | |
411 | */ | |
412 | ||
413 | /* constants */ | |
414 | ||
415 | #define Z_NO_FLUSH 0 | |
9bccf70c | 416 | #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ |
1c79356b A |
417 | #define Z_PACKET_FLUSH 2 |
418 | #define Z_SYNC_FLUSH 3 | |
419 | #define Z_FULL_FLUSH 4 | |
420 | #define Z_FINISH 5 | |
421 | /* Allowed flush values; see deflate() below for details */ | |
422 | ||
423 | #define Z_OK 0 | |
424 | #define Z_STREAM_END 1 | |
425 | #define Z_NEED_DICT 2 | |
426 | #define Z_ERRNO (-1) | |
427 | #define Z_STREAM_ERROR (-2) | |
428 | #define Z_DATA_ERROR (-3) | |
429 | #define Z_MEM_ERROR (-4) | |
430 | #define Z_BUF_ERROR (-5) | |
431 | #define Z_VERSION_ERROR (-6) | |
432 | /* Return codes for the compression/decompression functions. Negative | |
433 | * values are errors, positive values are used for special but normal events. | |
434 | */ | |
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 | ||
442 | #define Z_FILTERED 1 | |
443 | #define Z_HUFFMAN_ONLY 2 | |
444 | #define Z_DEFAULT_STRATEGY 0 | |
445 | /* compression strategy; see deflateInit2() below for details */ | |
446 | ||
447 | #define Z_BINARY 0 | |
448 | #define Z_ASCII 1 | |
449 | #define Z_UNKNOWN 2 | |
450 | /* Possible values of the data_type field */ | |
451 | ||
452 | #define Z_DEFLATED 8 | |
453 | /* The deflate compression method (the only one supported in this version) */ | |
454 | ||
455 | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ | |
456 | ||
457 | #define zlib_version zlibVersion() | |
458 | /* for compatibility with versions < 1.0.2 */ | |
459 | ||
460 | /* basic functions */ | |
461 | ||
9bccf70c | 462 | ZEXTERN const char * ZEXPORT zlibVersion OF((void)); |
1c79356b A |
463 | /* The application can compare zlibVersion and ZLIB_VERSION for consistency. |
464 | If the first character differs, the library code actually used is | |
465 | not compatible with the zlib.h header file used by the application. | |
466 | This check is automatically made by deflateInit and inflateInit. | |
467 | */ | |
468 | ||
469 | /* | |
9bccf70c | 470 | ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); |
1c79356b A |
471 | |
472 | Initializes the internal stream state for compression. The fields | |
473 | zalloc, zfree and opaque must be initialized before by the caller. | |
474 | If zalloc and zfree are set to Z_NULL, deflateInit updates them to | |
475 | use default allocation functions. | |
476 | ||
477 | The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: | |
478 | 1 gives best speed, 9 gives best compression, 0 gives no compression at | |
479 | all (the input data is simply copied a block at a time). | |
480 | Z_DEFAULT_COMPRESSION requests a default compromise between speed and | |
481 | compression (currently equivalent to level 6). | |
482 | ||
483 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not | |
484 | enough memory, Z_STREAM_ERROR if level is not a valid compression level, | |
485 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible | |
486 | with the version assumed by the caller (ZLIB_VERSION). | |
487 | msg is set to null if there is no error message. deflateInit does not | |
488 | perform any compression: this will be done by deflate(). | |
489 | */ | |
490 | ||
491 | ||
9bccf70c | 492 | ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); |
1c79356b | 493 | /* |
9bccf70c A |
494 | deflate compresses as much data as possible, and stops when the input |
495 | buffer becomes empty or the output buffer becomes full. It may introduce some | |
496 | output latency (reading input without producing any output) except when | |
497 | forced to flush. | |
498 | ||
499 | The detailed semantics are as follows. deflate performs one or both of the | |
500 | following actions: | |
1c79356b A |
501 | |
502 | - Compress more input starting at next_in and update next_in and avail_in | |
503 | accordingly. If not all input can be processed (because there is not | |
504 | enough room in the output buffer), next_in and avail_in are updated and | |
505 | processing will resume at this point for the next call of deflate(). | |
506 | ||
507 | - Provide more output starting at next_out and update next_out and avail_out | |
508 | accordingly. This action is forced if the parameter flush is non zero. | |
509 | Forcing flush frequently degrades the compression ratio, so this parameter | |
510 | should be set only when necessary (in interactive applications). | |
511 | Some output may be provided even if flush is not set. | |
512 | ||
513 | Before the call of deflate(), the application should ensure that at least | |
514 | one of the actions is possible, by providing more input and/or consuming | |
515 | more output, and updating avail_in or avail_out accordingly; avail_out | |
516 | should never be zero before the call. The application can consume the | |
517 | compressed output when it wants, for example when the output buffer is full | |
518 | (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK | |
519 | and with zero avail_out, it must be called again after making room in the | |
520 | output buffer because there might be more output pending. | |
521 | ||
9bccf70c A |
522 | If the parameter flush is set to Z_SYNC_FLUSH, all pending output is |
523 | flushed to the output buffer and the output is aligned on a byte boundary, so | |
524 | that the decompressor can get all input data available so far. (In particular | |
525 | avail_in is zero after the call if enough output space has been provided | |
526 | before the call.) Flushing may degrade compression for some compression | |
527 | algorithms and so it should be used only when necessary. | |
528 | ||
529 | If flush is set to Z_FULL_FLUSH, all output is flushed as with | |
530 | Z_SYNC_FLUSH, and the compression state is reset so that decompression can | |
531 | restart from this point if previous compressed data has been damaged or if | |
532 | random access is desired. Using Z_FULL_FLUSH too often can seriously degrade | |
533 | the compression. | |
534 | ||
535 | If deflate returns with avail_out == 0, this function must be called again | |
536 | with the same value of the flush parameter and more output space (updated | |
537 | avail_out), until the flush is complete (deflate returns with non-zero | |
538 | avail_out). | |
1c79356b A |
539 | |
540 | If the parameter flush is set to Z_FINISH, pending input is processed, | |
541 | pending output is flushed and deflate returns with Z_STREAM_END if there | |
542 | was enough output space; if deflate returns with Z_OK, this function must be | |
543 | called again with Z_FINISH and more output space (updated avail_out) but no | |
544 | more input data, until it returns with Z_STREAM_END or an error. After | |
545 | deflate has returned Z_STREAM_END, the only possible operations on the | |
546 | stream are deflateReset or deflateEnd. | |
547 | ||
548 | Z_FINISH can be used immediately after deflateInit if all the compression | |
549 | is to be done in a single step. In this case, avail_out must be at least | |
550 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return | |
551 | Z_STREAM_END, then it must be called again as described above. | |
552 | ||
9bccf70c A |
553 | deflate() sets strm->adler to the adler32 checksum of all input read |
554 | so far (that is, total_in bytes). | |
555 | ||
1c79356b A |
556 | deflate() may update data_type if it can make a good guess about |
557 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered | |
558 | binary. This field is only for information purposes and does not affect | |
559 | the compression algorithm in any manner. | |
560 | ||
561 | deflate() returns Z_OK if some progress has been made (more input | |
562 | processed or more output produced), Z_STREAM_END if all input has been | |
563 | consumed and all output has been produced (only when flush is set to | |
564 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example | |
9bccf70c A |
565 | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible |
566 | (for example avail_in or avail_out was zero). | |
1c79356b A |
567 | */ |
568 | ||
569 | ||
9bccf70c | 570 | ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); |
1c79356b A |
571 | /* |
572 | All dynamically allocated data structures for this stream are freed. | |
573 | This function discards any unprocessed input and does not flush any | |
574 | pending output. | |
575 | ||
576 | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the | |
577 | stream state was inconsistent, Z_DATA_ERROR if the stream was freed | |
578 | prematurely (some input or output was discarded). In the error case, | |
579 | msg may be set but then points to a static string (which must not be | |
580 | deallocated). | |
581 | */ | |
582 | ||
583 | ||
584 | /* | |
9bccf70c | 585 | ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); |
1c79356b A |
586 | |
587 | Initializes the internal stream state for decompression. The fields | |
9bccf70c A |
588 | next_in, avail_in, zalloc, zfree and opaque must be initialized before by |
589 | the caller. If next_in is not Z_NULL and avail_in is large enough (the exact | |
590 | value depends on the compression method), inflateInit determines the | |
591 | compression method from the zlib header and allocates all data structures | |
592 | accordingly; otherwise the allocation will be deferred to the first call of | |
593 | inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to | |
594 | use default allocation functions. | |
1c79356b | 595 | |
9bccf70c A |
596 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough |
597 | memory, Z_VERSION_ERROR if the zlib library version is incompatible with the | |
598 | version assumed by the caller. msg is set to null if there is no error | |
599 | message. inflateInit does not perform any decompression apart from reading | |
600 | the zlib header if present: this will be done by inflate(). (So next_in and | |
601 | avail_in may be modified, but next_out and avail_out are unchanged.) | |
1c79356b A |
602 | */ |
603 | ||
1c79356b | 604 | |
9bccf70c | 605 | ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); |
1c79356b | 606 | /* |
9bccf70c A |
607 | inflate decompresses as much data as possible, and stops when the input |
608 | buffer becomes empty or the output buffer becomes full. It may some | |
609 | introduce some output latency (reading input without producing any output) | |
610 | except when forced to flush. | |
611 | ||
612 | The detailed semantics are as follows. inflate performs one or both of the | |
613 | following actions: | |
1c79356b A |
614 | |
615 | - Decompress more input starting at next_in and update next_in and avail_in | |
616 | accordingly. If not all input can be processed (because there is not | |
617 | enough room in the output buffer), next_in is updated and processing | |
618 | will resume at this point for the next call of inflate(). | |
619 | ||
620 | - Provide more output starting at next_out and update next_out and avail_out | |
621 | accordingly. inflate() provides as much output as possible, until there | |
622 | is no more input data or no more space in the output buffer (see below | |
623 | about the flush parameter). | |
624 | ||
625 | Before the call of inflate(), the application should ensure that at least | |
626 | one of the actions is possible, by providing more input and/or consuming | |
627 | more output, and updating the next_* and avail_* values accordingly. | |
628 | The application can consume the uncompressed output when it wants, for | |
629 | example when the output buffer is full (avail_out == 0), or after each | |
630 | call of inflate(). If inflate returns Z_OK and with zero avail_out, it | |
631 | must be called again after making room in the output buffer because there | |
632 | might be more output pending. | |
633 | ||
9bccf70c A |
634 | If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much |
635 | output as possible to the output buffer. The flushing behavior of inflate is | |
636 | not specified for values of the flush parameter other than Z_SYNC_FLUSH | |
637 | and Z_FINISH, but the current implementation actually flushes as much output | |
638 | as possible anyway. | |
1c79356b A |
639 | |
640 | inflate() should normally be called until it returns Z_STREAM_END or an | |
641 | error. However if all decompression is to be performed in a single step | |
642 | (a single call of inflate), the parameter flush should be set to | |
643 | Z_FINISH. In this case all pending input is processed and all pending | |
644 | output is flushed; avail_out must be large enough to hold all the | |
645 | uncompressed data. (The size of the uncompressed data may have been saved | |
646 | by the compressor for this purpose.) The next operation on this stream must | |
647 | be inflateEnd to deallocate the decompression state. The use of Z_FINISH | |
648 | is never required, but can be used to inform inflate that a faster routine | |
649 | may be used for the single inflate() call. | |
650 | ||
9bccf70c A |
651 | If a preset dictionary is needed at this point (see inflateSetDictionary |
652 | below), inflate sets strm-adler to the adler32 checksum of the | |
653 | dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise | |
654 | it sets strm->adler to the adler32 checksum of all output produced | |
655 | so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or | |
656 | an error code as described below. At the end of the stream, inflate() | |
657 | checks that its computed adler32 checksum is equal to that saved by the | |
658 | compressor and returns Z_STREAM_END only if the checksum is correct. | |
659 | ||
660 | inflate() returns Z_OK if some progress has been made (more input processed | |
661 | or more output produced), Z_STREAM_END if the end of the compressed data has | |
662 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a | |
663 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was | |
664 | corrupted (input stream not conforming to the zlib format or incorrect | |
665 | adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent | |
666 | (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not | |
667 | enough memory, Z_BUF_ERROR if no progress is possible or if there was not | |
668 | enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR | |
669 | case, the application may then call inflateSync to look for a good | |
670 | compression block. | |
1c79356b A |
671 | */ |
672 | ||
673 | ||
9bccf70c | 674 | ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); |
1c79356b A |
675 | /* |
676 | All dynamically allocated data structures for this stream are freed. | |
677 | This function discards any unprocessed input and does not flush any | |
678 | pending output. | |
679 | ||
680 | inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state | |
681 | was inconsistent. In the error case, msg may be set but then points to a | |
682 | static string (which must not be deallocated). | |
683 | */ | |
684 | ||
685 | /* Advanced functions */ | |
686 | ||
687 | /* | |
688 | The following functions are needed only in some special applications. | |
689 | */ | |
690 | ||
691 | /* | |
9bccf70c A |
692 | ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, |
693 | int level, | |
694 | int method, | |
695 | int windowBits, | |
696 | int memLevel, | |
697 | int strategy)); | |
1c79356b A |
698 | |
699 | This is another version of deflateInit with more compression options. The | |
700 | fields next_in, zalloc, zfree and opaque must be initialized before by | |
701 | the caller. | |
702 | ||
703 | The method parameter is the compression method. It must be Z_DEFLATED in | |
9bccf70c | 704 | this version of the library. |
1c79356b A |
705 | |
706 | The windowBits parameter is the base two logarithm of the window size | |
707 | (the size of the history buffer). It should be in the range 8..15 for this | |
9bccf70c A |
708 | version of the library. Larger values of this parameter result in better |
709 | compression at the expense of memory usage. The default value is 15 if | |
710 | deflateInit is used instead. | |
1c79356b A |
711 | |
712 | The memLevel parameter specifies how much memory should be allocated | |
713 | for the internal compression state. memLevel=1 uses minimum memory but | |
714 | is slow and reduces compression ratio; memLevel=9 uses maximum memory | |
715 | for optimal speed. The default value is 8. See zconf.h for total memory | |
716 | usage as a function of windowBits and memLevel. | |
717 | ||
718 | The strategy parameter is used to tune the compression algorithm. Use the | |
719 | value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a | |
720 | filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no | |
721 | string match). Filtered data consists mostly of small values with a | |
722 | somewhat random distribution. In this case, the compression algorithm is | |
723 | tuned to compress them better. The effect of Z_FILTERED is to force more | |
724 | Huffman coding and less string matching; it is somewhat intermediate | |
725 | between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects | |
726 | the compression ratio but not the correctness of the compressed output even | |
727 | if it is not set appropriately. | |
728 | ||
9bccf70c A |
729 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
730 | memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid | |
731 | method). msg is set to null if there is no error message. deflateInit2 does | |
732 | not perform any compression: this will be done by deflate(). | |
1c79356b A |
733 | */ |
734 | ||
9bccf70c A |
735 | ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, |
736 | const Bytef *dictionary, | |
737 | uInt dictLength)); | |
738 | /* | |
739 | Initializes the compression dictionary from the given byte sequence | |
740 | without producing any compressed output. This function must be called | |
741 | immediately after deflateInit, deflateInit2 or deflateReset, before any | |
742 | call of deflate. The compressor and decompressor must use exactly the same | |
1c79356b | 743 | dictionary (see inflateSetDictionary). |
9bccf70c | 744 | |
1c79356b A |
745 | The dictionary should consist of strings (byte sequences) that are likely |
746 | to be encountered later in the data to be compressed, with the most commonly | |
747 | used strings preferably put towards the end of the dictionary. Using a | |
9bccf70c A |
748 | dictionary is most useful when the data to be compressed is short and can be |
749 | predicted with good accuracy; the data can then be compressed better than | |
750 | with the default empty dictionary. | |
751 | ||
752 | Depending on the size of the compression data structures selected by | |
753 | deflateInit or deflateInit2, a part of the dictionary may in effect be | |
754 | discarded, for example if the dictionary is larger than the window size in | |
755 | deflate or deflate2. Thus the strings most likely to be useful should be | |
756 | put at the end of the dictionary, not at the front. | |
757 | ||
1c79356b A |
758 | Upon return of this function, strm->adler is set to the Adler32 value |
759 | of the dictionary; the decompressor may later use this value to determine | |
760 | which dictionary has been used by the compressor. (The Adler32 value | |
761 | applies to the whole dictionary even if only a subset of the dictionary is | |
762 | actually used by the compressor.) | |
763 | ||
764 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a | |
9bccf70c A |
765 | parameter is invalid (such as NULL dictionary) or the stream state is |
766 | inconsistent (for example if deflate has already been called for this stream | |
767 | or if the compression method is bsort). deflateSetDictionary does not | |
768 | perform any compression: this will be done by deflate(). | |
1c79356b A |
769 | */ |
770 | ||
9bccf70c A |
771 | ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, |
772 | z_streamp source)); | |
1c79356b | 773 | /* |
9bccf70c | 774 | Sets the destination stream as a complete copy of the source stream. |
1c79356b A |
775 | |
776 | This function can be useful when several compression strategies will be | |
777 | tried, for example when there are several ways of pre-processing the input | |
778 | data with a filter. The streams that will be discarded should then be freed | |
779 | by calling deflateEnd. Note that deflateCopy duplicates the internal | |
780 | compression state which can be quite large, so this strategy is slow and | |
781 | can consume lots of memory. | |
782 | ||
783 | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not | |
784 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent | |
785 | (such as zalloc being NULL). msg is left unchanged in both source and | |
786 | destination. | |
787 | */ | |
788 | ||
9bccf70c | 789 | ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); |
1c79356b A |
790 | /* |
791 | This function is equivalent to deflateEnd followed by deflateInit, | |
792 | but does not free and reallocate all the internal compression state. | |
793 | The stream will keep the same compression level and any other attributes | |
794 | that may have been set by deflateInit2. | |
795 | ||
796 | deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source | |
797 | stream state was inconsistent (such as zalloc or state being NULL). | |
798 | */ | |
799 | ||
9bccf70c A |
800 | ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, |
801 | int level, | |
802 | int strategy)); | |
1c79356b | 803 | /* |
9bccf70c A |
804 | Dynamically update the compression level and compression strategy. The |
805 | interpretation of level and strategy is as in deflateInit2. This can be | |
806 | used to switch between compression and straight copy of the input data, or | |
807 | to switch to a different kind of input data requiring a different | |
808 | strategy. If the compression level is changed, the input available so far | |
809 | is compressed with the old level (and may be flushed); the new level will | |
810 | take effect only at the next call of deflate(). | |
1c79356b A |
811 | |
812 | Before the call of deflateParams, the stream state must be set as for | |
813 | a call of deflate(), since the currently available input may have to | |
814 | be compressed and flushed. In particular, strm->avail_out must be non-zero. | |
815 | ||
816 | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source | |
817 | stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR | |
818 | if strm->avail_out was zero. | |
819 | */ | |
820 | ||
1c79356b | 821 | /* |
9bccf70c A |
822 | ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, |
823 | int windowBits)); | |
1c79356b | 824 | |
9bccf70c A |
825 | This is another version of inflateInit with an extra parameter. The |
826 | fields next_in, avail_in, zalloc, zfree and opaque must be initialized | |
827 | before by the caller. | |
1c79356b A |
828 | |
829 | The windowBits parameter is the base two logarithm of the maximum window | |
830 | size (the size of the history buffer). It should be in the range 8..15 for | |
9bccf70c A |
831 | this version of the library. The default value is 15 if inflateInit is used |
832 | instead. If a compressed stream with a larger window size is given as | |
833 | input, inflate() will return with the error code Z_DATA_ERROR instead of | |
834 | trying to allocate a larger window. | |
835 | ||
836 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | |
837 | memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative | |
838 | memLevel). msg is set to null if there is no error message. inflateInit2 | |
839 | does not perform any decompression apart from reading the zlib header if | |
840 | present: this will be done by inflate(). (So next_in and avail_in may be | |
841 | modified, but next_out and avail_out are unchanged.) | |
1c79356b A |
842 | */ |
843 | ||
9bccf70c A |
844 | ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, |
845 | const Bytef *dictionary, | |
846 | uInt dictLength)); | |
1c79356b | 847 | /* |
9bccf70c A |
848 | Initializes the decompression dictionary from the given uncompressed byte |
849 | sequence. This function must be called immediately after a call of inflate | |
850 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor | |
851 | can be determined from the Adler32 value returned by this call of | |
852 | inflate. The compressor and decompressor must use exactly the same | |
1c79356b A |
853 | dictionary (see deflateSetDictionary). |
854 | ||
855 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a | |
856 | parameter is invalid (such as NULL dictionary) or the stream state is | |
857 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the | |
858 | expected one (incorrect Adler32 value). inflateSetDictionary does not | |
859 | perform any decompression: this will be done by subsequent calls of | |
860 | inflate(). | |
861 | */ | |
862 | ||
9bccf70c | 863 | ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); |
1c79356b | 864 | /* |
9bccf70c A |
865 | Skips invalid compressed data until a full flush point (see above the |
866 | description of deflate with Z_FULL_FLUSH) can be found, or until all | |
867 | available input is skipped. No output is provided. | |
1c79356b | 868 | |
9bccf70c A |
869 | inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR |
870 | if no more input was provided, Z_DATA_ERROR if no flush point has been found, | |
1c79356b A |
871 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success |
872 | case, the application may save the current current value of total_in which | |
873 | indicates where valid compressed data was found. In the error case, the | |
874 | application may repeatedly call inflateSync, providing more input each time, | |
875 | until success or end of the input data. | |
876 | */ | |
877 | ||
9bccf70c | 878 | ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); |
1c79356b A |
879 | /* |
880 | This function is equivalent to inflateEnd followed by inflateInit, | |
881 | but does not free and reallocate all the internal decompression state. | |
882 | The stream will keep attributes that may have been set by inflateInit2. | |
883 | ||
884 | inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source | |
885 | stream state was inconsistent (such as zalloc or state being NULL). | |
886 | */ | |
887 | ||
1c79356b A |
888 | |
889 | /* utility functions */ | |
890 | ||
891 | /* | |
892 | The following utility functions are implemented on top of the | |
893 | basic stream-oriented functions. To simplify the interface, some | |
9bccf70c | 894 | default options are assumed (compression level and memory usage, |
1c79356b A |
895 | standard memory allocation functions). The source code of these |
896 | utility functions can easily be modified if you need special options. | |
897 | */ | |
898 | ||
9bccf70c A |
899 | ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, |
900 | const Bytef *source, uLong sourceLen)); | |
1c79356b A |
901 | /* |
902 | Compresses the source buffer into the destination buffer. sourceLen is | |
903 | the byte length of the source buffer. Upon entry, destLen is the total | |
904 | size of the destination buffer, which must be at least 0.1% larger than | |
905 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the | |
906 | compressed buffer. | |
907 | This function can be used to compress a whole file at once if the | |
908 | input file is mmap'ed. | |
909 | compress returns Z_OK if success, Z_MEM_ERROR if there was not | |
910 | enough memory, Z_BUF_ERROR if there was not enough room in the output | |
911 | buffer. | |
912 | */ | |
913 | ||
9bccf70c A |
914 | ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, |
915 | const Bytef *source, uLong sourceLen, | |
916 | int level)); | |
917 | /* | |
918 | Compresses the source buffer into the destination buffer. The level | |
919 | parameter has the same meaning as in deflateInit. sourceLen is the byte | |
920 | length of the source buffer. Upon entry, destLen is the total size of the | |
921 | destination buffer, which must be at least 0.1% larger than sourceLen plus | |
922 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. | |
923 | ||
924 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | |
925 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, | |
926 | Z_STREAM_ERROR if the level parameter is invalid. | |
927 | */ | |
928 | ||
929 | ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, | |
930 | const Bytef *source, uLong sourceLen)); | |
1c79356b A |
931 | /* |
932 | Decompresses the source buffer into the destination buffer. sourceLen is | |
933 | the byte length of the source buffer. Upon entry, destLen is the total | |
934 | size of the destination buffer, which must be large enough to hold the | |
935 | entire uncompressed data. (The size of the uncompressed data must have | |
936 | been saved previously by the compressor and transmitted to the decompressor | |
937 | by some mechanism outside the scope of this compression library.) | |
938 | Upon exit, destLen is the actual size of the compressed buffer. | |
939 | This function can be used to decompress a whole file at once if the | |
940 | input file is mmap'ed. | |
941 | ||
942 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not | |
943 | enough memory, Z_BUF_ERROR if there was not enough room in the output | |
944 | buffer, or Z_DATA_ERROR if the input data was corrupted. | |
945 | */ | |
946 | ||
947 | ||
948 | typedef voidp gzFile; | |
949 | ||
9bccf70c | 950 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); |
1c79356b A |
951 | /* |
952 | Opens a gzip (.gz) file for reading or writing. The mode parameter | |
953 | is as in fopen ("rb" or "wb") but can also include a compression level | |
9bccf70c A |
954 | ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for |
955 | Huffman only compression as in "wb1h". (See the description | |
956 | of deflateInit2 for more information about the strategy parameter.) | |
957 | ||
958 | gzopen can be used to read a file which is not in gzip format; in this | |
959 | case gzread will directly read from the file without decompression. | |
960 | ||
1c79356b A |
961 | gzopen returns NULL if the file could not be opened or if there was |
962 | insufficient memory to allocate the (de)compression state; errno | |
963 | can be checked to distinguish the two cases (if errno is zero, the | |
9bccf70c | 964 | zlib error is Z_MEM_ERROR). */ |
1c79356b | 965 | |
9bccf70c | 966 | ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); |
1c79356b A |
967 | /* |
968 | gzdopen() associates a gzFile with the file descriptor fd. File | |
969 | descriptors are obtained from calls like open, dup, creat, pipe or | |
970 | fileno (in the file has been previously opened with fopen). | |
971 | The mode parameter is as in gzopen. | |
972 | The next call of gzclose on the returned gzFile will also close the | |
973 | file descriptor fd, just like fclose(fdopen(fd), mode) closes the file | |
974 | descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). | |
975 | gzdopen returns NULL if there was insufficient memory to allocate | |
976 | the (de)compression state. | |
977 | */ | |
978 | ||
9bccf70c A |
979 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); |
980 | /* | |
981 | Dynamically update the compression level or strategy. See the description | |
982 | of deflateInit2 for the meaning of these parameters. | |
983 | gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not | |
984 | opened for writing. | |
985 | */ | |
986 | ||
987 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | |
1c79356b A |
988 | /* |
989 | Reads the given number of uncompressed bytes from the compressed file. | |
990 | If the input file was not in gzip format, gzread copies the given number | |
991 | of bytes into the buffer. | |
992 | gzread returns the number of uncompressed bytes actually read (0 for | |
993 | end of file, -1 for error). */ | |
994 | ||
9bccf70c A |
995 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, |
996 | const voidp buf, unsigned len)); | |
1c79356b A |
997 | /* |
998 | Writes the given number of uncompressed bytes into the compressed file. | |
999 | gzwrite returns the number of uncompressed bytes actually written | |
1000 | (0 in case of error). | |
1001 | */ | |
1002 | ||
9bccf70c A |
1003 | ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); |
1004 | /* | |
1005 | Converts, formats, and writes the args to the compressed file under | |
1006 | control of the format string, as in fprintf. gzprintf returns the number of | |
1007 | uncompressed bytes actually written (0 in case of error). | |
1008 | */ | |
1009 | ||
1010 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); | |
1011 | /* | |
1012 | Writes the given null-terminated string to the compressed file, excluding | |
1013 | the terminating null character. | |
1014 | gzputs returns the number of characters written, or -1 in case of error. | |
1015 | */ | |
1016 | ||
1017 | ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); | |
1018 | /* | |
1019 | Reads bytes from the compressed file until len-1 characters are read, or | |
1020 | a newline character is read and transferred to buf, or an end-of-file | |
1021 | condition is encountered. The string is then terminated with a null | |
1022 | character. | |
1023 | gzgets returns buf, or Z_NULL in case of error. | |
1024 | */ | |
1025 | ||
1026 | ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); | |
1027 | /* | |
1028 | Writes c, converted to an unsigned char, into the compressed file. | |
1029 | gzputc returns the value that was written, or -1 in case of error. | |
1030 | */ | |
1031 | ||
1032 | ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); | |
1033 | /* | |
1034 | Reads one byte from the compressed file. gzgetc returns this byte | |
1035 | or -1 in case of end of file or error. | |
1036 | */ | |
1037 | ||
1038 | ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); | |
1c79356b A |
1039 | /* |
1040 | Flushes all pending output into the compressed file. The parameter | |
1041 | flush is as in the deflate() function. The return value is the zlib | |
1042 | error number (see function gzerror below). gzflush returns Z_OK if | |
1043 | the flush parameter is Z_FINISH and all output could be flushed. | |
1044 | gzflush should be called only when strictly necessary because it can | |
1045 | degrade compression. | |
1046 | */ | |
1047 | ||
9bccf70c A |
1048 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, |
1049 | z_off_t offset, int whence)); | |
1050 | /* | |
1051 | Sets the starting position for the next gzread or gzwrite on the | |
1052 | given compressed file. The offset represents a number of bytes in the | |
1053 | uncompressed data stream. The whence parameter is defined as in lseek(2); | |
1054 | the value SEEK_END is not supported. | |
1055 | If the file is opened for reading, this function is emulated but can be | |
1056 | extremely slow. If the file is opened for writing, only forward seeks are | |
1057 | supported; gzseek then compresses a sequence of zeroes up to the new | |
1058 | starting position. | |
1059 | ||
1060 | gzseek returns the resulting offset location as measured in bytes from | |
1061 | the beginning of the uncompressed stream, or -1 in case of error, in | |
1062 | particular if the file is opened for writing and the new starting position | |
1063 | would be before the current position. | |
1064 | */ | |
1065 | ||
1066 | ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); | |
1067 | /* | |
1068 | Rewinds the given file. This function is supported only for reading. | |
1069 | ||
1070 | gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) | |
1071 | */ | |
1072 | ||
1073 | ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); | |
1074 | /* | |
1075 | Returns the starting position for the next gzread or gzwrite on the | |
1076 | given compressed file. This position represents a number of bytes in the | |
1077 | uncompressed data stream. | |
1078 | ||
1079 | gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) | |
1080 | */ | |
1081 | ||
1082 | ZEXTERN int ZEXPORT gzeof OF((gzFile file)); | |
1083 | /* | |
1084 | Returns 1 when EOF has previously been detected reading the given | |
1085 | input stream, otherwise zero. | |
1086 | */ | |
1087 | ||
1088 | ZEXTERN int ZEXPORT gzclose OF((gzFile file)); | |
1c79356b A |
1089 | /* |
1090 | Flushes all pending output if necessary, closes the compressed file | |
1091 | and deallocates all the (de)compression state. The return value is the zlib | |
1092 | error number (see function gzerror below). | |
1093 | */ | |
1094 | ||
9bccf70c | 1095 | ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); |
1c79356b A |
1096 | /* |
1097 | Returns the error message for the last error which occurred on the | |
1098 | given compressed file. errnum is set to zlib error number. If an | |
1099 | error occurred in the file system and not in the compression library, | |
1100 | errnum is set to Z_ERRNO and the application may consult errno | |
1101 | to get the exact error code. | |
1102 | */ | |
1103 | ||
1104 | /* checksum functions */ | |
1105 | ||
1106 | /* | |
1107 | These functions are not related to compression but are exported | |
1108 | anyway because they might be useful in applications using the | |
1109 | compression library. | |
1110 | */ | |
1111 | ||
9bccf70c | 1112 | ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); |
1c79356b A |
1113 | |
1114 | /* | |
1115 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and | |
1116 | return the updated checksum. If buf is NULL, this function returns | |
1117 | the required initial value for the checksum. | |
1118 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed | |
1119 | much faster. Usage example: | |
1120 | ||
1121 | uLong adler = adler32(0L, Z_NULL, 0); | |
1122 | ||
1123 | while (read_buffer(buffer, length) != EOF) { | |
1124 | adler = adler32(adler, buffer, length); | |
1125 | } | |
1126 | if (adler != original_adler) error(); | |
1127 | */ | |
1128 | ||
9bccf70c | 1129 | ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); |
1c79356b A |
1130 | /* |
1131 | Update a running crc with the bytes buf[0..len-1] and return the updated | |
1132 | crc. If buf is NULL, this function returns the required initial value | |
1133 | for the crc. Pre- and post-conditioning (one's complement) is performed | |
1134 | within this function so it shouldn't be done by the application. | |
1135 | Usage example: | |
1136 | ||
1137 | uLong crc = crc32(0L, Z_NULL, 0); | |
1138 | ||
1139 | while (read_buffer(buffer, length) != EOF) { | |
1140 | crc = crc32(crc, buffer, length); | |
1141 | } | |
1142 | if (crc != original_crc) error(); | |
1143 | */ | |
1144 | ||
1145 | ||
1146 | /* various hacks, don't look :) */ | |
1147 | ||
1148 | /* deflateInit and inflateInit are macros to allow checking the zlib version | |
1149 | * and the compiler's view of z_stream: | |
1150 | */ | |
9bccf70c A |
1151 | ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, |
1152 | const char *version, int stream_size)); | |
1153 | ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, | |
1154 | const char *version, int stream_size)); | |
1155 | ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, | |
1156 | int windowBits, int memLevel, | |
1157 | int strategy, const char *version, | |
1158 | int stream_size)); | |
1159 | ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | |
1160 | const char *version, int stream_size)); | |
1c79356b A |
1161 | #define deflateInit(strm, level) \ |
1162 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) | |
1163 | #define inflateInit(strm) \ | |
1164 | inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) | |
1165 | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | |
1166 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | |
9bccf70c | 1167 | (strategy), ZLIB_VERSION, sizeof(z_stream)) |
1c79356b A |
1168 | #define inflateInit2(strm, windowBits) \ |
1169 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) | |
1170 | ||
9bccf70c | 1171 | |
1c79356b A |
1172 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) |
1173 | struct internal_state {int dummy;}; /* hack for buggy compilers */ | |
1174 | #endif | |
1175 | ||
9bccf70c A |
1176 | ZEXTERN const char * ZEXPORT zError OF((int err)); |
1177 | ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); | |
1178 | ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); | |
1c79356b | 1179 | |
9bccf70c | 1180 | #ifdef __cplusplus |
1c79356b A |
1181 | } |
1182 | #endif | |
1183 | ||
9bccf70c | 1184 | #endif /* !KERNEL || __APPLE_API_PRIVATE */ |
1c79356b A |
1185 | #endif /* _ZLIB_H */ |
1186 | /* --- zlib.h */ |