| 1 |
sysadm |
1.1 |
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
| 2 |
|
|
version 1.1.4, March 11th, 2002
|
| 3 |
|
|
|
| 4 |
|
|
Copyright (C) 1995-2002 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 |
|
|
jloup@gzip.org madler@alumni.caltech.edu
|
| 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 ftp://ds.internic.net/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 "zlib/pvpgn_zconf.h"
|
| 35 |
|
|
|
| 36 |
|
|
#ifdef __cplusplus
|
| 37 |
|
|
extern "C" {
|
| 38 |
|
|
#endif
|
| 39 |
|
|
|
| 40 |
|
|
#define ZLIB_VERSION "1.1.4"
|
| 41 |
|
|
|
| 42 |
|
|
/*
|
| 43 |
|
|
The 'zlib' compression library provides in-memory compression and
|
| 44 |
|
|
decompression functions, including integrity checks of the uncompressed
|
| 45 |
|
|
data. This version of the library supports only one compression method
|
| 46 |
|
|
(deflation) but other algorithms will be added later and will have the same
|
| 47 |
|
|
stream interface.
|
| 48 |
|
|
|
| 49 |
|
|
Compression can be done in a single step if the buffers are large
|
| 50 |
|
|
enough (for example if an input file is mmap'ed), or can be done by
|
| 51 |
|
|
repeated calls of the compression function. In the latter case, the
|
| 52 |
|
|
application must provide more input and/or consume the output
|
| 53 |
|
|
(providing more output space) before each call.
|
| 54 |
|
|
|
| 55 |
|
|
The library also supports reading and writing files in gzip (.gz) format
|
| 56 |
|
|
with an interface similar to that of stdio.
|
| 57 |
|
|
|
| 58 |
|
|
The library does not install any signal handler. The decoder checks
|
| 59 |
|
|
the consistency of the compressed data, so the library should never
|
| 60 |
|
|
crash even in case of corrupted input.
|
| 61 |
|
|
*/
|
| 62 |
|
|
|
| 63 |
|
|
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
| 64 |
|
|
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
| 65 |
|
|
|
| 66 |
|
|
struct internal_state;
|
| 67 |
|
|
|
| 68 |
|
|
typedef struct z_stream_s {
|
| 69 |
|
|
Bytef *next_in; /* next input byte */
|
| 70 |
|
|
uInt avail_in; /* number of bytes available at next_in */
|
| 71 |
|
|
uLong total_in; /* total nb of input bytes read so far */
|
| 72 |
|
|
|
| 73 |
|
|
Bytef *next_out; /* next output byte should be put there */
|
| 74 |
|
|
uInt avail_out; /* remaining free space at next_out */
|
| 75 |
|
|
uLong total_out; /* total nb of bytes output so far */
|
| 76 |
|
|
|
| 77 |
|
|
char *msg; /* last error message, NULL if no error */
|
| 78 |
|
|
struct internal_state FAR *state; /* not visible by applications */
|
| 79 |
|
|
|
| 80 |
|
|
alloc_func zalloc; /* used to allocate the internal state */
|
| 81 |
|
|
free_func zfree; /* used to free the internal state */
|
| 82 |
|
|
voidpf opaque; /* private data object passed to zalloc and zfree */
|
| 83 |
|
|
|
| 84 |
|
|
int data_type; /* best guess about the data type: ascii or binary */
|
| 85 |
|
|
uLong adler; /* adler32 value of the uncompressed data */
|
| 86 |
|
|
uLong reserved; /* reserved for future use */
|
| 87 |
|
|
} z_stream;
|
| 88 |
|
|
|
| 89 |
|
|
typedef z_stream FAR *z_streamp;
|
| 90 |
|
|
|
| 91 |
|
|
/*
|
| 92 |
|
|
The application must update next_in and avail_in when avail_in has
|
| 93 |
|
|
dropped to zero. It must update next_out and avail_out when avail_out
|
| 94 |
|
|
has dropped to zero. The application must initialize zalloc, zfree and
|
| 95 |
|
|
opaque before calling the init function. All other fields are set by the
|
| 96 |
|
|
compression library and must not be updated by the application.
|
| 97 |
|
|
|
| 98 |
|
|
The opaque value provided by the application will be passed as the first
|
| 99 |
|
|
parameter for calls of zalloc and zfree. This can be useful for custom
|
| 100 |
|
|
memory management. The compression library attaches no meaning to the
|
| 101 |
|
|
opaque value.
|
| 102 |
|
|
|
| 103 |
|
|
zalloc must return Z_NULL if there is not enough memory for the object.
|
| 104 |
|
|
If zlib is used in a multi-threaded application, zalloc and zfree must be
|
| 105 |
|
|
thread safe.
|
| 106 |
|
|
|
| 107 |
|
|
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
| 108 |
|
|
exactly 65536 bytes, but will not be required to allocate more than this
|
| 109 |
|
|
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
| 110 |
|
|
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
| 111 |
|
|
have their offset normalized to zero. The default allocation function
|
| 112 |
|
|
provided by this library ensures this (see zutil.c). To reduce memory
|
| 113 |
|
|
requirements and avoid any allocation of 64K objects, at the expense of
|
| 114 |
|
|
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
| 115 |
|
|
|
| 116 |
|
|
The fields total_in and total_out can be used for statistics or
|
| 117 |
|
|
progress reports. After compression, total_in holds the total size of
|
| 118 |
|
|
the uncompressed data and may be saved for use in the decompressor
|
| 119 |
|
|
(particularly if the decompressor wants to decompress everything in
|
| 120 |
|
|
a single step).
|
| 121 |
|
|
*/
|
| 122 |
|
|
|
| 123 |
|
|
/* constants */
|
| 124 |
|
|
|
| 125 |
|
|
#define Z_NO_FLUSH 0
|
| 126 |
|
|
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
| 127 |
|
|
#define Z_SYNC_FLUSH 2
|
| 128 |
|
|
#define Z_FULL_FLUSH 3
|
| 129 |
|
|
#define Z_FINISH 4
|
| 130 |
|
|
/* Allowed flush values; see deflate() below for details */
|
| 131 |
|
|
|
| 132 |
|
|
#define Z_OK 0
|
| 133 |
|
|
#define Z_STREAM_END 1
|
| 134 |
|
|
#define Z_NEED_DICT 2
|
| 135 |
|
|
#define Z_ERRNO (-1)
|
| 136 |
|
|
#define Z_STREAM_ERROR (-2)
|
| 137 |
|
|
#define Z_DATA_ERROR (-3)
|
| 138 |
|
|
#define Z_MEM_ERROR (-4)
|
| 139 |
|
|
#define Z_BUF_ERROR (-5)
|
| 140 |
|
|
#define Z_VERSION_ERROR (-6)
|
| 141 |
|
|
/* Return codes for the compression/decompression functions. Negative
|
| 142 |
|
|
* values are errors, positive values are used for special but normal events.
|
| 143 |
|
|
*/
|
| 144 |
|
|
|
| 145 |
|
|
#define Z_NO_COMPRESSION 0
|
| 146 |
|
|
#define Z_BEST_SPEED 1
|
| 147 |
|
|
#define Z_BEST_COMPRESSION 9
|
| 148 |
|
|
#define Z_DEFAULT_COMPRESSION (-1)
|
| 149 |
|
|
/* compression levels */
|
| 150 |
|
|
|
| 151 |
|
|
#define Z_FILTERED 1
|
| 152 |
|
|
#define Z_HUFFMAN_ONLY 2
|
| 153 |
|
|
#define Z_DEFAULT_STRATEGY 0
|
| 154 |
|
|
/* compression strategy; see deflateInit2() below for details */
|
| 155 |
|
|
|
| 156 |
|
|
#define Z_BINARY 0
|
| 157 |
|
|
#define Z_ASCII 1
|
| 158 |
|
|
#define Z_UNKNOWN 2
|
| 159 |
|
|
/* Possible values of the data_type field */
|
| 160 |
|
|
|
| 161 |
|
|
#define Z_DEFLATED 8
|
| 162 |
|
|
/* The deflate compression method (the only one supported in this version) */
|
| 163 |
|
|
|
| 164 |
|
|
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
|
| 165 |
|
|
|
| 166 |
|
|
#define zlib_version zlibVersion()
|
| 167 |
|
|
/* for compatibility with versions < 1.0.2 */
|
| 168 |
|
|
|
| 169 |
|
|
/* basic functions */
|
| 170 |
|
|
|
| 171 |
|
|
ZEXTERN const char * ZEXPORT pvpgn_zlibVersion OF((void));
|
| 172 |
|
|
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
| 173 |
|
|
If the first character differs, the library code actually used is
|
| 174 |
|
|
not compatible with the zlib.h header file used by the application.
|
| 175 |
|
|
This check is automatically made by deflateInit and inflateInit.
|
| 176 |
|
|
*/
|
| 177 |
|
|
|
| 178 |
|
|
/*
|
| 179 |
|
|
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
| 180 |
|
|
|
| 181 |
|
|
Initializes the internal stream state for compression. The fields
|
| 182 |
|
|
zalloc, zfree and opaque must be initialized before by the caller.
|
| 183 |
|
|
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
|
| 184 |
|
|
use default allocation functions.
|
| 185 |
|
|
|
| 186 |
|
|
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
|
| 187 |
|
|
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
| 188 |
|
|
all (the input data is simply copied a block at a time).
|
| 189 |
|
|
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
|
| 190 |
|
|
compression (currently equivalent to level 6).
|
| 191 |
|
|
|
| 192 |
|
|
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
| 193 |
|
|
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
|
| 194 |
|
|
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
|
| 195 |
|
|
with the version assumed by the caller (ZLIB_VERSION).
|
| 196 |
|
|
msg is set to null if there is no error message. deflateInit does not
|
| 197 |
|
|
perform any compression: this will be done by deflate().
|
| 198 |
|
|
*/
|
| 199 |
|
|
|
| 200 |
|
|
|
| 201 |
|
|
ZEXTERN int ZEXPORT pvpgn_deflate OF((z_streamp strm, int flush));
|
| 202 |
|
|
/*
|
| 203 |
|
|
deflate compresses as much data as possible, and stops when the input
|
| 204 |
|
|
buffer becomes empty or the output buffer becomes full. It may introduce some
|
| 205 |
|
|
output latency (reading input without producing any output) except when
|
| 206 |
|
|
forced to flush.
|
| 207 |
|
|
|
| 208 |
|
|
The detailed semantics are as follows. deflate performs one or both of the
|
| 209 |
|
|
following actions:
|
| 210 |
|
|
|
| 211 |
|
|
- Compress more input starting at next_in and update next_in and avail_in
|
| 212 |
|
|
accordingly. If not all input can be processed (because there is not
|
| 213 |
|
|
enough room in the output buffer), next_in and avail_in are updated and
|
| 214 |
|
|
processing will resume at this point for the next call of deflate().
|
| 215 |
|
|
|
| 216 |
|
|
- Provide more output starting at next_out and update next_out and avail_out
|
| 217 |
|
|
accordingly. This action is forced if the parameter flush is non zero.
|
| 218 |
|
|
Forcing flush frequently degrades the compression ratio, so this parameter
|
| 219 |
|
|
should be set only when necessary (in interactive applications).
|
| 220 |
|
|
Some output may be provided even if flush is not set.
|
| 221 |
|
|
|
| 222 |
|
|
Before the call of deflate(), the application should ensure that at least
|
| 223 |
|
|
one of the actions is possible, by providing more input and/or consuming
|
| 224 |
|
|
more output, and updating avail_in or avail_out accordingly; avail_out
|
| 225 |
|
|
should never be zero before the call. The application can consume the
|
| 226 |
|
|
compressed output when it wants, for example when the output buffer is full
|
| 227 |
|
|
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
|
| 228 |
|
|
and with zero avail_out, it must be called again after making room in the
|
| 229 |
|
|
output buffer because there might be more output pending.
|
| 230 |
|
|
|
| 231 |
|
|
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
| 232 |
|
|
flushed to the output buffer and the output is aligned on a byte boundary, so
|
| 233 |
|
|
that the decompressor can get all input data available so far. (In particular
|
| 234 |
|
|
avail_in is zero after the call if enough output space has been provided
|
| 235 |
|
|
before the call.) Flushing may degrade compression for some compression
|
| 236 |
|
|
algorithms and so it should be used only when necessary.
|
| 237 |
|
|
|
| 238 |
|
|
If flush is set to Z_FULL_FLUSH, all output is flushed as with
|
| 239 |
|
|
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
| 240 |
|
|
restart from this point if previous compressed data has been damaged or if
|
| 241 |
|
|
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
| 242 |
|
|
the compression.
|
| 243 |
|
|
|
| 244 |
|
|
If deflate returns with avail_out == 0, this function must be called again
|
| 245 |
|
|
with the same value of the flush parameter and more output space (updated
|
| 246 |
|
|
avail_out), until the flush is complete (deflate returns with non-zero
|
| 247 |
|
|
avail_out).
|
| 248 |
|
|
|
| 249 |
|
|
If the parameter flush is set to Z_FINISH, pending input is processed,
|
| 250 |
|
|
pending output is flushed and deflate returns with Z_STREAM_END if there
|
| 251 |
|
|
was enough output space; if deflate returns with Z_OK, this function must be
|
| 252 |
|
|
called again with Z_FINISH and more output space (updated avail_out) but no
|
| 253 |
|
|
more input data, until it returns with Z_STREAM_END or an error. After
|
| 254 |
|
|
deflate has returned Z_STREAM_END, the only possible operations on the
|
| 255 |
|
|
stream are deflateReset or deflateEnd.
|
| 256 |
|
|
|
| 257 |
|
|
Z_FINISH can be used immediately after deflateInit if all the compression
|
| 258 |
|
|
is to be done in a single step. In this case, avail_out must be at least
|
| 259 |
|
|
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
| 260 |
|
|
Z_STREAM_END, then it must be called again as described above.
|
| 261 |
|
|
|
| 262 |
|
|
deflate() sets strm->adler to the adler32 checksum of all input read
|
| 263 |
|
|
so far (that is, total_in bytes).
|
| 264 |
|
|
|
| 265 |
|
|
deflate() may update data_type if it can make a good guess about
|
| 266 |
|
|
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
| 267 |
|
|
binary. This field is only for information purposes and does not affect
|
| 268 |
|
|
the compression algorithm in any manner.
|
| 269 |
|
|
|
| 270 |
|
|
deflate() returns Z_OK if some progress has been made (more input
|
| 271 |
|
|
processed or more output produced), Z_STREAM_END if all input has been
|
| 272 |
|
|
consumed and all output has been produced (only when flush is set to
|
| 273 |
|
|
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
| 274 |
|
|
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
|
| 275 |
|
|
(for example avail_in or avail_out was zero).
|
| 276 |
|
|
*/
|
| 277 |
|
|
|
| 278 |
|
|
|
| 279 |
|
|
ZEXTERN int ZEXPORT pvpgn_deflateEnd OF((z_streamp strm));
|
| 280 |
|
|
/*
|
| 281 |
|
|
All dynamically allocated data structures for this stream are freed.
|
| 282 |
|
|
This function discards any unprocessed input and does not flush any
|
| 283 |
|
|
pending output.
|
| 284 |
|
|
|
| 285 |
|
|
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
|
| 286 |
|
|
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
|
| 287 |
|
|
prematurely (some input or output was discarded). In the error case,
|
| 288 |
|
|
msg may be set but then points to a static string (which must not be
|
| 289 |
|
|
deallocated).
|
| 290 |
|
|
*/
|
| 291 |
|
|
|
| 292 |
|
|
ZEXTERN int ZEXPORT pvpgn_deflateReset OF((z_streamp strm));
|
| 293 |
|
|
/*
|
| 294 |
|
|
This function is equivalent to deflateEnd followed by deflateInit,
|
| 295 |
|
|
but does not free and reallocate all the internal compression state.
|
| 296 |
|
|
The stream will keep the same compression level and any other attributes
|
| 297 |
|
|
that may have been set by deflateInit2.
|
| 298 |
|
|
|
| 299 |
|
|
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
| 300 |
|
|
stream state was inconsistent (such as zalloc or state being NULL).
|
| 301 |
|
|
*/
|
| 302 |
|
|
|
| 303 |
|
|
/* checksum functions */
|
| 304 |
|
|
|
| 305 |
|
|
/*
|
| 306 |
|
|
These functions are not related to compression but are exported
|
| 307 |
|
|
anyway because they might be useful in applications using the
|
| 308 |
|
|
compression library.
|
| 309 |
|
|
*/
|
| 310 |
|
|
|
| 311 |
|
|
ZEXTERN uLong ZEXPORT pvpgn_adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
| 312 |
|
|
|
| 313 |
|
|
/*
|
| 314 |
|
|
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
| 315 |
|
|
return the updated checksum. If buf is NULL, this function returns
|
| 316 |
|
|
the required initial value for the checksum.
|
| 317 |
|
|
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
| 318 |
|
|
much faster. Usage example:
|
| 319 |
|
|
|
| 320 |
|
|
uLong adler = adler32(0L, Z_NULL, 0);
|
| 321 |
|
|
|
| 322 |
|
|
while (read_buffer(buffer, length) != EOF) {
|
| 323 |
|
|
adler = adler32(adler, buffer, length);
|
| 324 |
|
|
}
|
| 325 |
|
|
if (adler != original_adler) error();
|
| 326 |
|
|
*/
|
| 327 |
|
|
|
| 328 |
|
|
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
| 329 |
|
|
* and the compiler's view of z_stream:
|
| 330 |
|
|
*/
|
| 331 |
|
|
ZEXTERN int ZEXPORT pvpgn_deflateInit_ OF((z_streamp strm, int level,
|
| 332 |
|
|
const char *version, int stream_size));
|
| 333 |
|
|
ZEXTERN int ZEXPORT pvpgn_deflateInit2_ OF((z_streamp strm, int level, int method,
|
| 334 |
|
|
int windowBits, int memLevel,
|
| 335 |
|
|
int strategy, const char *version,
|
| 336 |
|
|
int stream_size));
|
| 337 |
|
|
#define pvpgn_deflateInit(strm, level) \
|
| 338 |
|
|
pvpgn_deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
| 339 |
|
|
#define pvpgn_inflateInit(strm) \
|
| 340 |
|
|
pvpgn_inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
| 341 |
|
|
#define pvpgn_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
| 342 |
|
|
pvpgn_deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
| 343 |
|
|
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
| 344 |
|
|
#define pvpgn_inflateInit2(strm, windowBits) \
|
| 345 |
|
|
pvpgn_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
| 346 |
|
|
|
| 347 |
|
|
|
| 348 |
|
|
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
| 349 |
|
|
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
| 350 |
|
|
#endif
|
| 351 |
|
|
|
| 352 |
|
|
ZEXTERN const char * ZEXPORT pvpgn_zError OF((int err));
|
| 353 |
|
|
ZEXTERN const uLongf * ZEXPORT pvpgn_get_crc_table OF((void));
|
| 354 |
|
|
|
| 355 |
|
|
#ifdef __cplusplus
|
| 356 |
|
|
}
|
| 357 |
|
|
#endif
|
| 358 |
|
|
|
| 359 |
|
|
#endif /* _ZLIB_H */
|