source: trunk/src/3rdparty/zlib/zlib.h@ 352

Last change on this file since 352 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 64.9 KB
Line 
1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.3, July 18th, 2005
3
4 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
13
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
21
22 Jean-loup Gailly Mark Adler
23 [email protected] [email protected]
24
25
26 The data format used by the zlib library is described by RFCs (Request for
27 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
28 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29*/
30
31#ifndef ZLIB_H
32#define ZLIB_H
33
34#include "zconf.h"
35#include "qconfig.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#define ZLIB_VERSION "1.2.3"
42#define ZLIB_VERNUM 0x1230
43
44#if defined(QT_VISIBILITY_AVAILABLE)
45# define Q_ZEXPORT __attribute__((visibility("default")))
46#else
47# ifdef QT_MAKEDLL
48# define Q_ZEXPORT __declspec(dllexport)
49# else
50# define Q_ZEXPORT ZEXPORT
51# endif
52#endif
53
54/*
55 The 'zlib' compression library provides in-memory compression and
56 decompression functions, including integrity checks of the uncompressed
57 data. This version of the library supports only one compression method
58 (deflation) but other algorithms will be added later and will have the same
59 stream interface.
60
61 Compression can be done in a single step if the buffers are large
62 enough (for example if an input file is mmap'ed), or can be done by
63 repeated calls of the compression function. In the latter case, the
64 application must provide more input and/or consume the output
65 (providing more output space) before each call.
66
67 The compressed data format used by default by the in-memory functions is
68 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
69 around a deflate stream, which is itself documented in RFC 1951.
70
71 The library also supports reading and writing files in gzip (.gz) format
72 with an interface similar to that of stdio using the functions that start
73 with "gz". The gzip format is different from the zlib format. gzip is a
74 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
75
76 This library can optionally read and write gzip streams in memory as well.
77
78 The zlib format was designed to be compact and fast for use in memory
79 and on communications channels. The gzip format was designed for single-
80 file compression on file systems, has a larger header than zlib to maintain
81 directory information, and uses a different, slower check method than zlib.
82
83 The library does not install any signal handler. The decoder checks
84 the consistency of the compressed data, so the library should never
85 crash even in case of corrupted input.
86*/
87
88typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
89typedef void (*free_func) OF((voidpf opaque, voidpf address));
90
91struct internal_state;
92
93typedef struct z_stream_s {
94 Bytef *next_in; /* next input byte */
95 uInt avail_in; /* number of bytes available at next_in */
96 uLong total_in; /* total nb of input bytes read so far */
97
98 Bytef *next_out; /* next output byte should be put there */
99 uInt avail_out; /* remaining free space at next_out */
100 uLong total_out; /* total nb of bytes output so far */
101
102 char *msg; /* last error message, NULL if no error */
103 struct internal_state FAR *state; /* not visible by applications */
104
105 alloc_func zalloc; /* used to allocate the internal state */
106 free_func zfree; /* used to free the internal state */
107 voidpf opaque; /* private data object passed to zalloc and zfree */
108
109 int data_type; /* best guess about the data type: binary or text */
110 uLong adler; /* adler32 value of the uncompressed data */
111 uLong reserved; /* reserved for future use */
112} z_stream;
113
114typedef z_stream FAR *z_streamp;
115
116/*
117 gzip header information passed to and from zlib routines. See RFC 1952
118 for more details on the meanings of these fields.
119*/
120typedef struct gz_header_s {
121 int text; /* true if compressed data believed to be text */
122 uLong time; /* modification time */
123 int xflags; /* extra flags (not used when writing a gzip file) */
124 int os; /* operating system */
125 Bytef *extra; /* pointer to extra field or Z_NULL if none */
126 uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
127 uInt extra_max; /* space at extra (only when reading header) */
128 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
129 uInt name_max; /* space at name (only when reading header) */
130 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
131 uInt comm_max; /* space at comment (only when reading header) */
132 int hcrc; /* true if there was or will be a header crc */
133 int done; /* true when done reading gzip header (not used
134 when writing a gzip file) */
135} gz_header;
136
137typedef gz_header FAR *gz_headerp;
138
139/*
140 The application must update next_in and avail_in when avail_in has
141 dropped to zero. It must update next_out and avail_out when avail_out
142 has dropped to zero. The application must initialize zalloc, zfree and
143 opaque before calling the init function. All other fields are set by the
144 compression library and must not be updated by the application.
145
146 The opaque value provided by the application will be passed as the first
147 parameter for calls of zalloc and zfree. This can be useful for custom
148 memory management. The compression library attaches no meaning to the
149 opaque value.
150
151 zalloc must return Z_NULL if there is not enough memory for the object.
152 If zlib is used in a multi-threaded application, zalloc and zfree must be
153 thread safe.
154
155 On 16-bit systems, the functions zalloc and zfree must be able to allocate
156 exactly 65536 bytes, but will not be required to allocate more than this
157 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
158 pointers returned by zalloc for objects of exactly 65536 bytes *must*
159 have their offset normalized to zero. The default allocation function
160 provided by this library ensures this (see zutil.c). To reduce memory
161 requirements and avoid any allocation of 64K objects, at the expense of
162 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
163
164 The fields total_in and total_out can be used for statistics or
165 progress reports. After compression, total_in holds the total size of
166 the uncompressed data and may be saved for use in the decompressor
167 (particularly if the decompressor wants to decompress everything in
168 a single step).
169*/
170
171 /* constants */
172
173#define Z_NO_FLUSH 0
174#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
175#define Z_SYNC_FLUSH 2
176#define Z_FULL_FLUSH 3
177#define Z_FINISH 4
178#define Z_BLOCK 5
179/* Allowed flush values; see deflate() and inflate() below for details */
180
181#define Z_OK 0
182#define Z_STREAM_END 1
183#define Z_NEED_DICT 2
184#define Z_ERRNO (-1)
185#define Z_STREAM_ERROR (-2)
186#define Z_DATA_ERROR (-3)
187#define Z_MEM_ERROR (-4)
188#define Z_BUF_ERROR (-5)
189#define Z_VERSION_ERROR (-6)
190/* Return codes for the compression/decompression functions. Negative
191 * values are errors, positive values are used for special but normal events.
192 */
193
194#define Z_NO_COMPRESSION 0
195#define Z_BEST_SPEED 1
196#define Z_BEST_COMPRESSION 9
197#define Z_DEFAULT_COMPRESSION (-1)
198/* compression levels */
199
200#define Z_FILTERED 1
201#define Z_HUFFMAN_ONLY 2
202#define Z_RLE 3
203#define Z_FIXED 4
204#define Z_DEFAULT_STRATEGY 0
205/* compression strategy; see deflateInit2() below for details */
206
207#define Z_BINARY 0
208#define Z_TEXT 1
209#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
210#define Z_UNKNOWN 2
211/* Possible values of the data_type field (though see inflate()) */
212
213#define Z_DEFLATED 8
214/* The deflate compression method (the only one supported in this version) */
215
216#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
217
218#define zlib_version zlibVersion()
219/* for compatibility with versions < 1.0.2 */
220
221 /* basic functions */
222
223ZEXTERN Q_ZEXPORT const char * zlibVersion OF((void));
224/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
225 If the first character differs, the library code actually used is
226 not compatible with the zlib.h header file used by the application.
227 This check is automatically made by deflateInit and inflateInit.
228 */
229
230/*
231ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
232
233 Initializes the internal stream state for compression. The fields
234 zalloc, zfree and opaque must be initialized before by the caller.
235 If zalloc and zfree are set to Z_NULL, deflateInit updates them to
236 use default allocation functions.
237
238 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
239 1 gives best speed, 9 gives best compression, 0 gives no compression at
240 all (the input data is simply copied a block at a time).
241 Z_DEFAULT_COMPRESSION requests a default compromise between speed and
242 compression (currently equivalent to level 6).
243
244 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
245 enough memory, Z_STREAM_ERROR if level is not a valid compression level,
246 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
247 with the version assumed by the caller (ZLIB_VERSION).
248 msg is set to null if there is no error message. deflateInit does not
249 perform any compression: this will be done by deflate().
250*/
251
252
253ZEXTERN int Q_ZEXPORT deflate OF((z_streamp strm, int flush));
254/*
255 deflate compresses as much data as possible, and stops when the input
256 buffer becomes empty or the output buffer becomes full. It may introduce some
257 output latency (reading input without producing any output) except when
258 forced to flush.
259
260 The detailed semantics are as follows. deflate performs one or both of the
261 following actions:
262
263 - Compress more input starting at next_in and update next_in and avail_in
264 accordingly. If not all input can be processed (because there is not
265 enough room in the output buffer), next_in and avail_in are updated and
266 processing will resume at this point for the next call of deflate().
267
268 - Provide more output starting at next_out and update next_out and avail_out
269 accordingly. This action is forced if the parameter flush is non zero.
270 Forcing flush frequently degrades the compression ratio, so this parameter
271 should be set only when necessary (in interactive applications).
272 Some output may be provided even if flush is not set.
273
274 Before the call of deflate(), the application should ensure that at least
275 one of the actions is possible, by providing more input and/or consuming
276 more output, and updating avail_in or avail_out accordingly; avail_out
277 should never be zero before the call. The application can consume the
278 compressed output when it wants, for example when the output buffer is full
279 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
280 and with zero avail_out, it must be called again after making room in the
281 output buffer because there might be more output pending.
282
283 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
284 decide how much data to accumualte before producing output, in order to
285 maximize compression.
286
287 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
288 flushed to the output buffer and the output is aligned on a byte boundary, so
289 that the decompressor can get all input data available so far. (In particular
290 avail_in is zero after the call if enough output space has been provided
291 before the call.) Flushing may degrade compression for some compression
292 algorithms and so it should be used only when necessary.
293
294 If flush is set to Z_FULL_FLUSH, all output is flushed as with
295 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
296 restart from this point if previous compressed data has been damaged or if
297 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
298 compression.
299
300 If deflate returns with avail_out == 0, this function must be called again
301 with the same value of the flush parameter and more output space (updated
302 avail_out), until the flush is complete (deflate returns with non-zero
303 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
304 avail_out is greater than six to avoid repeated flush markers due to
305 avail_out == 0 on return.
306
307 If the parameter flush is set to Z_FINISH, pending input is processed,
308 pending output is flushed and deflate returns with Z_STREAM_END if there
309 was enough output space; if deflate returns with Z_OK, this function must be
310 called again with Z_FINISH and more output space (updated avail_out) but no
311 more input data, until it returns with Z_STREAM_END or an error. After
312 deflate has returned Z_STREAM_END, the only possible operations on the
313 stream are deflateReset or deflateEnd.
314
315 Z_FINISH can be used immediately after deflateInit if all the compression
316 is to be done in a single step. In this case, avail_out must be at least
317 the value returned by deflateBound (see below). If deflate does not return
318 Z_STREAM_END, then it must be called again as described above.
319
320 deflate() sets strm->adler to the adler32 checksum of all input read
321 so far (that is, total_in bytes).
322
323 deflate() may update strm->data_type if it can make a good guess about
324 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
325 binary. This field is only for information purposes and does not affect
326 the compression algorithm in any manner.
327
328 deflate() returns Z_OK if some progress has been made (more input
329 processed or more output produced), Z_STREAM_END if all input has been
330 consumed and all output has been produced (only when flush is set to
331 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
332 if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
333 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
334 fatal, and deflate() can be called again with more input and more output
335 space to continue compressing.
336*/
337
338
339ZEXTERN int Q_ZEXPORT deflateEnd OF((z_streamp strm));
340/*
341 All dynamically allocated data structures for this stream are freed.
342 This function discards any unprocessed input and does not flush any
343 pending output.
344
345 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
346 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
347 prematurely (some input or output was discarded). In the error case,
348 msg may be set but then points to a static string (which must not be
349 deallocated).
350*/
351
352
353/*
354ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
355
356 Initializes the internal stream state for decompression. The fields
357 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
358 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
359 value depends on the compression method), inflateInit determines the
360 compression method from the zlib header and allocates all data structures
361 accordingly; otherwise the allocation will be deferred to the first call of
362 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
363 use default allocation functions.
364
365 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
366 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
367 version assumed by the caller. msg is set to null if there is no error
368 message. inflateInit does not perform any decompression apart from reading
369 the zlib header if present: this will be done by inflate(). (So next_in and
370 avail_in may be modified, but next_out and avail_out are unchanged.)
371*/
372
373
374ZEXTERN int Q_ZEXPORT inflate OF((z_streamp strm, int flush));
375/*
376 inflate decompresses as much data as possible, and stops when the input
377 buffer becomes empty or the output buffer becomes full. It may introduce
378 some output latency (reading input without producing any output) except when
379 forced to flush.
380
381 The detailed semantics are as follows. inflate performs one or both of the
382 following actions:
383
384 - Decompress more input starting at next_in and update next_in and avail_in
385 accordingly. If not all input can be processed (because there is not
386 enough room in the output buffer), next_in is updated and processing
387 will resume at this point for the next call of inflate().
388
389 - Provide more output starting at next_out and update next_out and avail_out
390 accordingly. inflate() provides as much output as possible, until there
391 is no more input data or no more space in the output buffer (see below
392 about the flush parameter).
393
394 Before the call of inflate(), the application should ensure that at least
395 one of the actions is possible, by providing more input and/or consuming
396 more output, and updating the next_* and avail_* values accordingly.
397 The application can consume the uncompressed output when it wants, for
398 example when the output buffer is full (avail_out == 0), or after each
399 call of inflate(). If inflate returns Z_OK and with zero avail_out, it
400 must be called again after making room in the output buffer because there
401 might be more output pending.
402
403 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
404 Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
405 output as possible to the output buffer. Z_BLOCK requests that inflate() stop
406 if and when it gets to the next deflate block boundary. When decoding the
407 zlib or gzip format, this will cause inflate() to return immediately after
408 the header and before the first block. When doing a raw inflate, inflate()
409 will go ahead and process the first block, and will return when it gets to
410 the end of that block, or when it runs out of data.
411
412 The Z_BLOCK option assists in appending to or combining deflate streams.
413 Also to assist in this, on return inflate() will set strm->data_type to the
414 number of unused bits in the last byte taken from strm->next_in, plus 64
415 if inflate() is currently decoding the last block in the deflate stream,