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