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