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