| 1 | /* $NetBSD: zlib.h,v 1.14 2009/03/25 01:26:12 darran 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 _NET_ZLIB_H_ |
| 34 | #define _NET_ZLIB_H_ |
| 35 | |
| 36 | #ifdef __NetBSD__ |
| 37 | #include <sys/cdefs.h> |
| 38 | #endif |
| 39 | |
| 40 | /* +++ zconf.h */ |
| 41 | /* zconf.h -- configuration of the zlib compression library |
| 42 | * Copyright (C) 1995-2002 Jean-loup Gailly. |
| 43 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 44 | */ |
| 45 | |
| 46 | /* @(#) $Id: zlib.h,v 1.14 2009/03/25 01:26:12 darran Exp $ */ |
| 47 | |
| 48 | #ifndef ZCONF_H |
| 49 | #define ZCONF_H |
| 50 | |
| 51 | /* |
| 52 | * Warning: This file pollutes the user's namespace with: |
| 53 | * Byte Bytef EXPORT FAR OF STDC |
| 54 | * charf intf uInt uIntf uLong uLonf |
| 55 | * Programs using this library appear to expect those... |
| 56 | */ |
| 57 | |
| 58 | #include <sys/types.h> |
| 59 | |
| 60 | /* |
| 61 | * If you *really* need a unique prefix for all types and library functions, |
| 62 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. |
| 63 | */ |
| 64 | #ifdef Z_PREFIX |
| 65 | # define deflateInit_ z_deflateInit_ |
| 66 | # define deflate z_deflate |
| 67 | # define deflateEnd z_deflateEnd |
| 68 | # define inflateInit_ z_inflateInit_ |
| 69 | # define inflate z_inflate |
| 70 | # define inflateEnd z_inflateEnd |
| 71 | # define deflateInit2_ z_deflateInit2_ |
| 72 | # define deflateSetDictionary z_deflateSetDictionary |
| 73 | # define deflateCopy z_deflateCopy |
| 74 | # define deflateReset z_deflateReset |
| 75 | # define deflateParams z_deflateParams |
| 76 | # define inflateInit2_ z_inflateInit2_ |
| 77 | # define inflateSetDictionary z_inflateSetDictionary |
| 78 | # define inflateSync z_inflateSync |
| 79 | # define inflateSyncPoint z_inflateSyncPoint |
| 80 | # define inflateReset z_inflateReset |
| 81 | # define compress z_compress |
| 82 | # define compress2 z_compress2 |
| 83 | # define uncompress z_uncompress |
| 84 | # define adler32 z_adler32 |
| 85 | # define crc32 z_crc32 |
| 86 | # define get_crc_table z_get_crc_table |
| 87 | |
| 88 | # define Byte z_Byte |
| 89 | # define uInt z_uInt |
| 90 | # define uLong z_uLong |
| 91 | # define Bytef z_Bytef |
| 92 | # define charf z_charf |
| 93 | # define intf z_intf |
| 94 | # define uIntf z_uIntf |
| 95 | # define uLongf z_uLongf |
| 96 | # define voidpf z_voidpf |
| 97 | # define voidp z_voidp |
| 98 | #endif |
| 99 | |
| 100 | #ifndef __32BIT__ |
| 101 | /* Don't be alarmed; this just means we have at least 32-bits */ |
| 102 | # define __32BIT__ |
| 103 | #endif |
| 104 | |
| 105 | /* |
| 106 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more |
| 107 | * than 64k bytes at a time (needed on systems with 16-bit int). |
| 108 | */ |
| 109 | #if defined(MSDOS) && !defined(__32BIT__) |
| 110 | # define MAXSEG_64K |
| 111 | #endif |
| 112 | |
| 113 | #if 0 |
| 114 | /* XXX: Are there machines where we should define this? m68k? */ |
| 115 | # define UNALIGNED_OK |
| 116 | #endif |
| 117 | |
| 118 | #if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC) |
| 119 | /* XXX: Look out - this is used in zutil.h and elsewhere... */ |
| 120 | # define STDC |
| 121 | #endif |
| 122 | #if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) |
| 123 | # ifndef STDC |
| 124 | # define STDC |
| 125 | # endif |
| 126 | #endif |
| 127 | |
| 128 | #ifndef STDC |
| 129 | # ifndef const |
| 130 | # define const |
| 131 | # endif |
| 132 | #endif |
| 133 | |
| 134 | /* Some Mac compilers merge all .h files incorrectly: */ |
| 135 | #if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) |
| 136 | # define NO_DUMMY_DECL |
| 137 | #endif |
| 138 | |
| 139 | /* Old Borland C incorrectly complains about missing returns: */ |
| 140 | #if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) |
| 141 | # define NEED_DUMMY_RETURN |
| 142 | #endif |
| 143 | |
| 144 | |
| 145 | /* Maximum value for memLevel in deflateInit2 */ |
| 146 | #ifndef MAX_MEM_LEVEL |
| 147 | # ifdef MAXSEG_64K |
| 148 | # define MAX_MEM_LEVEL 8 |
| 149 | # else |
| 150 | # define MAX_MEM_LEVEL 9 |
| 151 | # endif |
| 152 | #endif |
| 153 | |
| 154 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. |
| 155 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files |
| 156 | * created by gzip. (Files created by minigzip can still be extracted by |
| 157 | * gzip.) |
| 158 | */ |
| 159 | #ifndef MAX_WBITS |
| 160 | # define MAX_WBITS 15 /* 32K LZ77 window */ |
| 161 | #endif |
| 162 | |
| 163 | /* The memory requirements for deflate are (in bytes): |
| 164 | (1 << (windowBits+2)) + (1 << (memLevel+9)) |
| 165 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) |
| 166 | plus a few kilobytes for small objects. For example, if you want to reduce |
| 167 | the default memory requirements from 256K to 128K, compile with |
| 168 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" |
| 169 | Of course this will generally degrade compression (there's no free lunch). |
| 170 | |
| 171 | The memory requirements for inflate are (in bytes) 1 << windowBits |
| 172 | that is, 32K for windowBits=15 (default value) plus a few kilobytes |
| 173 | for small objects. |
| 174 | */ |
| 175 | |
| 176 | /* Type declarations */ |
| 177 | |
| 178 | #ifndef __P /* function prototypes */ |
| 179 | # ifdef STDC |
| 180 | # define __P(args) args |
| 181 | # else |
| 182 | # define __P(args) () |
| 183 | # endif |
| 184 | #endif |
| 185 | |
| 186 | /* The following definitions for FAR are needed only for MSDOS mixed |
| 187 | * model programming (small or medium model with some far allocations). |
| 188 | * This was tested only with MSC; for other MSDOS compilers you may have |
| 189 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, |
| 190 | * just define FAR to be empty. |
| 191 | */ |
| 192 | #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) |
| 193 | /* MSC small or medium model */ |
| 194 | # define SMALL_MEDIUM |
| 195 | # ifdef _MSC_VER |
| 196 | # define FAR _far |
| 197 | # else |
| 198 | # define FAR far |
| 199 | # endif |
| 200 | #endif |
| 201 | #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) |
| 202 | # ifndef __32BIT__ |
| 203 | # define SMALL_MEDIUM |
| 204 | # define FAR _far |
| 205 | # endif |
| 206 | #endif |
| 207 | |
| 208 | /* Compile with -DZLIB_DLL for Windows DLL support */ |
| 209 | #if defined(ZLIB_DLL) |
| 210 | # if defined(_WINDOWS) || defined(WINDOWS) |
| 211 | # ifdef FAR |
| 212 | # undef FAR |
| 213 | # endif |
| 214 | # include <windows.h> |
| 215 | # define ZEXPORT WINAPI |
| 216 | # ifdef WIN32 |
| 217 | # define ZEXPORTVA WINAPIV |
| 218 | # else |
| 219 | # define ZEXPORTVA FAR _cdecl _export |
| 220 | # endif |
| 221 | # endif |
| 222 | # if defined (__BORLANDC__) |
| 223 | # if (__BORLANDC__ >= 0x0500) && defined (WIN32) |
| 224 | # include <windows.h> |
| 225 | # define ZEXPORT __declspec(dllexport) WINAPI |
| 226 | # define ZEXPORTRVA __declspec(dllexport) WINAPIV |
| 227 | # else |
| 228 | # if defined (_Windows) && defined (__DLL__) |
| 229 | # define ZEXPORT _export |
| 230 | # define ZEXPORTVA _export |
| 231 | # endif |
| 232 | # endif |
| 233 | # endif |
| 234 | #endif |
| 235 | |
| 236 | #if defined (__BEOS__) |
| 237 | # if defined (ZLIB_DLL) |
| 238 | # define ZEXTERN extern __declspec(dllexport) |
| 239 | # else |
| 240 | # define ZEXTERN extern __declspec(dllimport) |
| 241 | # endif |
| 242 | #endif |
| 243 | |
| 244 | #ifndef ZEXPORT |
| 245 | # define ZEXPORT |
| 246 | #endif |
| 247 | #ifndef ZEXPORTVA |
| 248 | # define ZEXPORTVA |
| 249 | #endif |
| 250 | #ifndef ZEXTERN |
| 251 | # define ZEXTERN extern |
| 252 | #endif |
| 253 | |
| 254 | #ifndef FAR |
| 255 | # define FAR |
| 256 | #endif |
| 257 | |
| 258 | #if !defined(MACOS) && !defined(TARGET_OS_MAC) |
| 259 | typedef unsigned char Byte; /* 8 bits */ |
| 260 | #endif |
| 261 | typedef unsigned int uInt; /* 16 bits or more */ |
| 262 | typedef unsigned long uLong; /* 32 bits or more */ |
| 263 | |
| 264 | #ifdef SMALL_MEDIUM |
| 265 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ |
| 266 | # define Bytef Byte FAR |
| 267 | #else |
| 268 | typedef Byte FAR Bytef; |
| 269 | #endif |
| 270 | typedef char FAR charf; |
| 271 | typedef int FAR intf; |
| 272 | typedef uInt FAR uIntf; |
| 273 | typedef uLong FAR uLongf; |
| 274 | |
| 275 | #ifdef STDC |
| 276 | typedef void FAR *voidpf; |
| 277 | typedef void *voidp; |
| 278 | #else |
| 279 | typedef Byte FAR *voidpf; |
| 280 | typedef Byte *voidp; |
| 281 | #endif |
| 282 | |
| 283 | #if (defined(HAVE_UNISTD_H) || defined(__NetBSD__)) && !defined(_KERNEL) |
| 284 | # include <sys/types.h> /* for off_t */ |
| 285 | # include <unistd.h> /* for SEEK_* and off_t */ |
| 286 | # define z_off_t off_t |
| 287 | #endif |
| 288 | #ifndef SEEK_SET |
| 289 | # define SEEK_SET 0 /* Seek from beginning of file. */ |
| 290 | # define SEEK_CUR 1 /* Seek from current position. */ |
| 291 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ |
| 292 | #endif |
| 293 | #ifndef z_off_t |
| 294 | # define z_off_t long |
| 295 | #endif |
| 296 | |
| 297 | /* MVS linker does not support external names larger than 8 bytes */ |
| 298 | #if defined(__MVS__) |
| 299 | # pragma map(deflateInit_,"DEIN") |
| 300 | # pragma map(deflateInit2_,"DEIN2") |
| 301 | # pragma map(deflateEnd,"DEEND") |
| 302 | # pragma map(inflateInit_,"ININ") |
| 303 | # pragma map(inflateInit2_,"ININ2") |
| 304 | # pragma map(inflateEnd,"INEND") |
| 305 | # pragma map(inflateSync,"INSY") |
| 306 | # pragma map(inflateSetDictionary,"INSEDI") |
| 307 | # pragma map(inflate_blocks,"INBL") |
| 308 | # pragma map(inflate_blocks_new,"INBLNE") |
| 309 | # pragma map(inflate_blocks_free,"INBLFR") |
| 310 | # pragma map(inflate_blocks_reset,"INBLRE") |
| 311 | # pragma map(inflate_codes_free,"INCOFR") |
| 312 | # pragma map(inflate_codes,"INCO") |
| 313 | # pragma map(inflate_fast,"INFA") |
| 314 | # pragma map(inflate_flush,"INFLU") |
| 315 | # pragma map(inflate_mask,"INMA") |
| 316 | # pragma map(inflate_set_dictionary,"INSEDI2") |
| 317 | # pragma map(inflate_copyright,"INCOPY") |
| 318 | # pragma map(inflate_trees_bits,"INTRBI") |
| 319 | # pragma map(inflate_trees_dynamic,"INTRDY") |
| 320 | # pragma map(inflate_trees_fixed,"INTRFI") |
| 321 | # pragma map(inflate_trees_free,"INTRFR") |
| 322 | #endif |
| 323 | |
| 324 | #endif /* !ZCONF_H */ |
| 325 | /* --- zconf.h */ |
| 326 | |
| 327 | #ifndef ZLIB_H |
| 328 | #define ZLIB_H |
| 329 | #ifdef __cplusplus |
| 330 | extern "C" { |
| 331 | #endif |
| 332 | |
| 333 | #define ZLIB_VERSION "1.1.4" |
| 334 | |
| 335 | /* |
| 336 | The 'zlib' compression library provides in-memory compression and |
| 337 | decompression functions, including integrity checks of the uncompressed |
| 338 | data. This version of the library supports only one compression method |
| 339 | (deflation) but other algorithms will be added later and will have the same |
| 340 | stream interface. |
| 341 | |
| 342 | Compression can be done in a single step if the buffers are large |
| 343 | enough (for example if an input file is mmap'ed), or can be done by |
| 344 | repeated calls of the compression function. In the latter case, the |
| 345 | application must provide more input and/or consume the output |
| 346 | (providing more output space) before each call. |
| 347 | |
| 348 | The library also supports reading and writing files in gzip (.gz) format |
| 349 | with an interface similar to that of stdio. |
| 350 | |
| 351 | The library does not install any signal handler. The decoder checks |
| 352 | the consistency of the compressed data, so the library should never |
| 353 | crash even in case of corrupted input. |
| 354 | */ |
| 355 | |
| 356 | typedef voidpf (*alloc_func)(voidpf, uInt, uInt); |
| 357 | typedef void (*free_func)(voidpf, voidpf); |
| 358 | |
| 359 | struct internal_state; |
| 360 | |
| 361 | typedef struct z_stream_s { |
| 362 | Bytef *next_in; /* next input byte */ |
| 363 | uInt avail_in; /* number of bytes available at next_in */ |
| 364 | uLong total_in; /* total nb of input bytes read so far */ |
| 365 | |
| 366 | Bytef *next_out; /* next output byte should be put there */ |
| 367 | uInt avail_out; /* remaining free space at next_out */ |
| 368 | uLong total_out; /* total nb of bytes output so far */ |
| 369 | |
| 370 | const char *msg; /* last error message, NULL if no error */ |
| 371 | struct internal_state FAR *state; /* not visible by applications */ |
| 372 | |
| 373 | alloc_func zalloc; /* used to allocate the internal state */ |
| 374 | free_func zfree; /* used to free the internal state */ |
| 375 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
| 376 | |
| 377 | int data_type; /* best guess about the data type: ascii or binary */ |
| 378 | uLong adler; /* adler32 value of the uncompressed data */ |
| 379 | uLong reserved; /* reserved for future use */ |
| 380 | } z_stream; |
| 381 | |
| 382 | typedef z_stream FAR *z_streamp; |
| 383 | |
| 384 | /* |
| 385 | The application must update next_in and avail_in when avail_in has |
| 386 | dropped to zero. It must update next_out and avail_out when avail_out |
| 387 | has dropped to zero. The application must initialize zalloc, zfree and |
| 388 | opaque before calling the init function. All other fields are set by the |
| 389 | compression library and must not be updated by the application. |
| 390 | |
| 391 | The opaque value provided by the application will be passed as the first |
| 392 | parameter for calls of zalloc and zfree. This can be useful for custom |
| 393 | memory management. The compression library attaches no meaning to the |
| 394 | opaque value. |
| 395 | |
| 396 | zalloc must return Z_NULL if there is not enough memory for the object. |
| 397 | If zlib is used in a multi-threaded application, zalloc and zfree must be |
| 398 | thread safe. |
| 399 | |
| 400 | On 16-bit systems, the functions zalloc and zfree must be able to allocate |
| 401 | exactly 65536 bytes, but will not be required to allocate more than this |
| 402 | if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, |
| 403 | pointers returned by zalloc for objects of exactly 65536 bytes *must* |
| 404 | have their offset normalized to zero. The default allocation function |
| 405 | provided by this library ensures this (see zutil.c). To reduce memory |
| 406 | requirements and avoid any allocation of 64K objects, at the expense of |
| 407 | compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). |
| 408 | |
| 409 | The fields total_in and total_out can be used for statistics or |
| 410 | progress reports. After compression, total_in holds the total size of |
| 411 | the uncompressed data and may be saved for use in the decompressor |
| 412 | (particularly if the decompressor wants to decompress everything in |
| 413 | a single step). |
| 414 | */ |
| 415 | |
| 416 | /* constants */ |
| 417 | |
| 418 | #define Z_NO_FLUSH 0 |
| 419 | #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ |
| 420 | #define Z_PACKET_FLUSH 2 |
| 421 | #define Z_SYNC_FLUSH 3 |
| 422 | #define Z_FULL_FLUSH 4 |
| 423 | #define Z_FINISH 5 |
| 424 | /* Allowed flush values; see deflate() below for details */ |
| 425 | |
| 426 | #define Z_OK 0 |
| 427 | #define Z_STREAM_END 1 |
| 428 | #define Z_NEED_DICT 2 |
| 429 | #define Z_ERRNO (-1) |
| 430 | #define Z_STREAM_ERROR (-2) |
| 431 | #define Z_DATA_ERROR (-3) |
| 432 | #define Z_MEM_ERROR (-4) |
| 433 | #define Z_BUF_ERROR (-5) |
| 434 | #define Z_VERSION_ERROR (-6) |
| 435 | /* Return codes for the compression/decompression functions. Negative |
| 436 | * values are errors, positive values are used for special but normal events. |
| 437 | */ |
| 438 | |
| 439 | #define Z_NO_COMPRESSION 0 |
| 440 | #define Z_BEST_SPEED 1 |
| 441 | #define Z_BEST_COMPRESSION 9 |
| 442 | #define Z_DEFAULT_COMPRESSION (-1) |
| 443 | /* compression levels */ |
| 444 | |
| 445 | #define Z_FILTERED 1 |
| 446 | #define Z_HUFFMAN_ONLY 2 |
| 447 | #define Z_DEFAULT_STRATEGY 0 |
| 448 | /* compression strategy; see deflateInit2() below for details */ |
| 449 | |
| 450 | #define Z_BINARY 0 |
| 451 | #define Z_ASCII 1 |
| 452 | #define Z_UNKNOWN 2 |
| 453 | /* Possible values of the data_type field */ |
| 454 | |
| 455 | #define Z_DEFLATED 8 |
| 456 | /* The deflate compression method (the only one supported in this version) */ |
| 457 | |
| 458 | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ |
| 459 | |
| 460 | #define zlib_version zlibVersion() |
| 461 | /* for compatibility with versions < 1.0.2 */ |
| 462 | |
| 463 | /* basic functions */ |
| 464 | |
| 465 | ZEXTERN const char * ZEXPORT zlibVersion(void); |
| 466 | /* The application can compare zlibVersion and ZLIB_VERSION for consistency. |
| 467 | If the first character differs, the library code actually used is |
| 468 | not compatible with the zlib.h header file used by the application. |
| 469 | This check is automatically made by deflateInit and inflateInit. |
| 470 | */ |
| 471 | |
| 472 | /* |
| 473 | ZEXTERN int ZEXPORT deflateInit(z_streamp, int); |
| 474 | |
| 475 | Initializes the internal stream state for compression. The fields |
| 476 | zalloc, zfree and opaque must be initialized before by the caller. |
| 477 | If zalloc and zfree are set to Z_NULL, deflateInit updates them to |
| 478 | use default allocation functions. |
| 479 | |
| 480 | The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: |
| 481 | 1 gives best speed, 9 gives best compression, 0 gives no compression at |
| 482 | all (the input data is simply copied a block at a time). |
| 483 | Z_DEFAULT_COMPRESSION requests a default compromise between speed and |
| 484 | compression (currently equivalent to level 6). |
| 485 | |
| 486 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not |
| 487 | enough memory, Z_STREAM_ERROR if level is not a valid compression level, |
| 488 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible |
| 489 | with the version assumed by the caller (ZLIB_VERSION). |
| 490 | msg is set to null if there is no error message. deflateInit does not |
| 491 | perform any compression: this will be done by deflate(). |
| 492 | */ |
| 493 | |
| 494 | |
| 495 | ZEXTERN int ZEXPORT deflate(z_streamp, int); |
| 496 | /* |
| 497 | deflate compresses as much data as possible, and stops when the input |
| 498 | buffer becomes empty or the output buffer becomes full. It may introduce some |
| 499 | output latency (reading input without producing any output) except when |
| 500 | forced to flush. |
| 501 | |
| 502 | The detailed semantics are as follows. deflate performs one or both of the |
| 503 | following actions: |
| 504 | |
| 505 | - Compress more input starting at next_in and update next_in and avail_in |
| 506 | accordingly. If not all input can be processed (because there is not |
| 507 | enough room in the output buffer), next_in and avail_in are updated and |
| 508 | processing will resume at this point for the next call of deflate(). |
| 509 | |
| 510 | - Provide more output starting at next_out and update next_out and avail_out |
| 511 | accordingly. This action is forced if the parameter flush is non zero. |
| 512 | Forcing flush frequently degrades the compression ratio, so this parameter |
| 513 | should be set only when necessary (in interactive applications). |
| 514 | Some output may be provided even if flush is not set. |
| 515 | |
| 516 | Before the call of deflate(), the application should ensure that at least |
| 517 | one of the actions is possible, by providing more input and/or consuming |
| 518 | more output, and updating avail_in or avail_out accordingly; avail_out |
| 519 | should never be zero before the call. The application can consume the |
| 520 | compressed output when it wants, for example when the output buffer is full |
| 521 | (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK |
| 522 | and with zero avail_out, it must be called again after making room in the |
| 523 | output buffer because there might be more output pending. |
| 524 | |
| 525 | If the parameter flush is set to Z_SYNC_FLUSH, all pending output is |
| 526 | flushed to the output buffer and the output is aligned on a byte boundary, so |
| 527 | that the decompressor can get all input data available so far. (In particular |
| 528 | avail_in is zero after the call if enough output space has been provided |
| 529 | before the call.) Flushing may degrade compression for some compression |
| 530 | algorithms and so it should be used only when necessary. |
| 531 | |
| 532 | If flush is set to Z_FULL_FLUSH, all output is flushed as with |
| 533 | Z_SYNC_FLUSH, and the compression state is reset so that decompression can |
| 534 | restart from this point if previous compressed data has been damaged or if |
| 535 | random access is desired. Using Z_FULL_FLUSH too often can seriously degrade |
| 536 | the compression. |
| 537 | |
| 538 | If deflate returns with avail_out == 0, this function must be called again |
| 539 | with the same value of the flush parameter and more output space (updated |
| 540 | avail_out), until the flush is complete (deflate returns with non-zero |
| 541 | avail_out). |
| 542 | |
| 543 | If the parameter flush is set to Z_PACKET_FLUSH, the compression |
| 544 | block is terminated, and a zero-length stored block is output, |
| 545 | omitting the length bytes (the effect of this is that the 3-bit type |
| 546 | code 000 for a stored block is output, and the output is then |
| 547 | byte-aligned). This is designed for use at the end of a PPP packet. |
| 548 | |
| 549 | |
| 550 | If the parameter flush is set to Z_FINISH, pending input is processed, |
| 551 | pending output is flushed and deflate returns with Z_STREAM_END if there |
| 552 | was enough output space; if deflate returns with Z_OK, this function must be |
| 553 | called again with Z_FINISH and more output space (updated avail_out) but no |
| 554 | more input data, until it returns with Z_STREAM_END or an error. After |
| 555 | deflate has returned Z_STREAM_END, the only possible operations on the |
| 556 | stream are deflateReset or deflateEnd. |
| 557 | |
| 558 | Z_FINISH can be used immediately after deflateInit if all the compression |
| 559 | is to be done in a single step. In this case, avail_out must be at least |
| 560 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return |
| 561 | Z_STREAM_END, then it must be called again as described above. |
| 562 | |
| 563 | deflate() sets strm->adler to the adler32 checksum of all input read |
| 564 | so far (that is, total_in bytes). |
| 565 | |
| 566 | deflate() may update data_type if it can make a good guess about |
| 567 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered |
| 568 | binary. This field is only for information purposes and does not affect |
| 569 | the compression algorithm in any manner. |
| 570 | |
| 571 | deflate() returns Z_OK if some progress has been made (more input |
| 572 | processed or more output produced), Z_STREAM_END if all input has been |
| 573 | consumed and all output has been produced (only when flush is set to |
| 574 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example |
| 575 | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible |
| 576 | (for example avail_in or avail_out was zero). |
| 577 | */ |
| 578 | |
| 579 | |
| 580 | ZEXTERN int ZEXPORT deflateEnd(z_streamp); |
| 581 | /* |
| 582 | All dynamically allocated data structures for this stream are freed. |
| 583 | This function discards any unprocessed input and does not flush any |
| 584 | pending output. |
| 585 | |
| 586 | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the |
| 587 | stream state was inconsistent, Z_DATA_ERROR if the stream was freed |
| 588 | prematurely (some input or output was discarded). In the error case, |
| 589 | msg may be set but then points to a static string (which must not be |
| 590 | deallocated). |
| 591 | */ |
| 592 | |
| 593 | |
| 594 | /* |
| 595 | ZEXTERN int ZEXPORT inflateInit(z_streamp); |
| 596 | |
| 597 | Initializes the internal stream state for decompression. The fields |
| 598 | next_in, avail_in, zalloc, zfree and opaque must be initialized before by |
| 599 | the caller. If next_in is not Z_NULL and avail_in is large enough (the exact |
| 600 | value depends on the compression method), inflateInit determines the |
| 601 | compression method from the zlib header and allocates all data structures |
| 602 | accordingly; otherwise the allocation will be deferred to the first call of |
| 603 | inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to |
| 604 | use default allocation functions. |
| 605 | |
| 606 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough |
| 607 | memory, Z_VERSION_ERROR if the zlib library version is incompatible with the |
| 608 | version assumed by the caller. msg is set to null if there is no error |
| 609 | message. inflateInit does not perform any decompression apart from reading |
| 610 | the zlib header if present: this will be done by inflate(). (So next_in and |
| 611 | avail_in may be modified, but next_out and avail_out are unchanged.) |
| 612 | */ |
| 613 | |
| 614 | |
| 615 | ZEXTERN int ZEXPORT inflate(z_streamp, int); |
| 616 | /* |
| 617 | inflate decompresses as much data as possible, and stops when the input |
| 618 | buffer becomes empty or the output buffer becomes full. It may some |
| 619 | introduce some output latency (reading input without producing any output) |
| 620 | except when forced to flush. |
| 621 | |
| 622 | The detailed semantics are as follows. inflate performs one or both of the |
| 623 | following actions: |
| 624 | |
| 625 | - Decompress more input starting at next_in and update next_in and avail_in |
| 626 | accordingly. If not all input can be processed (because there is not |
| 627 | enough room in the output buffer), next_in is updated and processing |
| 628 | will resume at this point for the next call of inflate(). |
| 629 | |
| 630 | - Provide more output starting at next_out and update next_out and avail_out |
| 631 | accordingly. inflate() provides as much output as possible, until there |
| 632 | is no more input data or no more space in the output buffer (see below |
| 633 | about the flush parameter). |
| 634 | |
| 635 | Before the call of inflate(), the application should ensure that at least |
| 636 | one of the actions is possible, by providing more input and/or consuming |
| 637 | more output, and updating the next_* and avail_* values accordingly. |
| 638 | The application can consume the uncompressed output when it wants, for |
| 639 | example when the output buffer is full (avail_out == 0), or after each |
| 640 | call of inflate(). If inflate returns Z_OK and with zero avail_out, it |
| 641 | must be called again after making room in the output buffer because there |
| 642 | might be more output pending. |
| 643 | |
| 644 | If the parameter flush is set to Z_SYNC_FLUSH or Z_PACKET_FLUSH, |
| 645 | inflate flushes as much output as possible to the output buffer. The |
| 646 | flushing behavior of inflate is not specified for values of the flush |
| 647 | parameter other than Z_SYNC_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the |
| 648 | current implementation actually flushes as much output as possible |
| 649 | anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data |
| 650 | has been consumed, it is expecting to see the length field of a stored |
| 651 | block; if not, it returns Z_DATA_ERROR. |
| 652 | |
| 653 | inflate() should normally be called until it returns Z_STREAM_END or an |
| 654 | error. However if all decompression is to be performed in a single step |
| 655 | (a single call of inflate), the parameter flush should be set to |
| 656 | Z_FINISH. In this case all pending input is processed and all pending |
| 657 | output is flushed; avail_out must be large enough to hold all the |
| 658 | uncompressed data. (The size of the uncompressed data may have been saved |
| 659 | by the compressor for this purpose.) The next operation on this stream must |
| 660 | be inflateEnd to deallocate the decompression state. The use of Z_FINISH |
| 661 | is never required, but can be used to inform inflate that a faster routine |
| 662 | may be used for the single inflate() call. |
| 663 | |
| 664 | If a preset dictionary is needed at this point (see inflateSetDictionary |
| 665 | below), inflate sets strm-adler to the adler32 checksum of the |
| 666 | dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise |
| 667 | it sets strm->adler to the adler32 checksum of all output produced |
| 668 | so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or |
| 669 | an error code as described below. At the end of the stream, inflate() |
| 670 | checks that its computed adler32 checksum is equal to that saved by the |
| 671 | compressor and returns Z_STREAM_END only if the checksum is correct. |
| 672 | |
| 673 | inflate() returns Z_OK if some progress has been made (more input processed |
| 674 | or more output produced), Z_STREAM_END if the end of the compressed data has |
| 675 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a |
| 676 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was |
| 677 | corrupted (input stream not conforming to the zlib format or incorrect |
| 678 | adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent |
| 679 | (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not |
| 680 | enough memory, Z_BUF_ERROR if no progress is possible or if there was not |
| 681 | enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR |
| 682 | case, the application may then call inflateSync to look for a good |
| 683 | compression block. |
| 684 | */ |
| 685 | |
| 686 | |
| 687 | ZEXTERN int ZEXPORT inflateEnd(z_streamp); |
| 688 | /* |
| 689 | All dynamically allocated data structures for this stream are freed. |
| 690 | This function discards any unprocessed input and does not flush any |
| 691 | pending output. |
| 692 | |
| 693 | inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state |
| 694 | was inconsistent. In the error case, msg may be set but then points to a |
| 695 | static string (which must not be deallocated). |
| 696 | */ |
| 697 | |
| 698 | /* Advanced functions */ |
| 699 | |
| 700 | /* |
| 701 | The following functions are needed only in some special applications. |
| 702 | */ |
| 703 | |
| 704 | /* |
| 705 | ZEXTERN int ZEXPORT deflateInit2(z_streamp, int, int, int, int, int); |
| 706 | |
| 707 | This is another version of deflateInit with more compression options. The |
| 708 | fields next_in, zalloc, zfree and opaque must be initialized before by |
| 709 | the caller. |
| 710 | |
| 711 | The method parameter is the compression method. It must be Z_DEFLATED in |
| 712 | this version of the library. |
| 713 | |
| 714 | The windowBits parameter is the base two logarithm of the window size |
| 715 | (the size of the history buffer). It should be in the range 8..15 for this |
| 716 | version of the library. Larger values of this parameter result in better |
| 717 | compression at the expense of memory usage. The default value is 15 if |
| 718 | deflateInit is used instead. |
| 719 | |
| 720 | The memLevel parameter specifies how much memory should be allocated |
| 721 | for the internal compression state. memLevel=1 uses minimum memory but |
| 722 | is slow and reduces compression ratio; memLevel=9 uses maximum memory |
| 723 | for optimal speed. The default value is 8. See zconf.h for total memory |
| 724 | usage as a function of windowBits and memLevel. |
| 725 | |
| 726 | The strategy parameter is used to tune the compression algorithm. Use the |
| 727 | value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a |
| 728 | filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no |
| 729 | string match). Filtered data consists mostly of small values with a |
| 730 | somewhat random distribution. In this case, the compression algorithm is |
| 731 | tuned to compress them better. The effect of Z_FILTERED is to force more |
| 732 | Huffman coding and less string matching; it is somewhat intermediate |
| 733 | between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects |
| 734 | the compression ratio but not the correctness of the compressed output even |
| 735 | if it is not set appropriately. |
| 736 | |
| 737 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
| 738 | memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid |
| 739 | method). msg is set to null if there is no error message. deflateInit2 does |
| 740 | not perform any compression: this will be done by deflate(). |
| 741 | */ |
| 742 | |
| 743 | ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp, const Bytef *, uInt); |
| 744 | /* |
| 745 | Initializes the compression dictionary from the given byte sequence |
| 746 | without producing any compressed output. This function must be called |
| 747 | immediately after deflateInit, deflateInit2 or deflateReset, before any |
| 748 | call of deflate. The compressor and decompressor must use exactly the same |
| 749 | dictionary (see inflateSetDictionary). |
| 750 | |
| 751 | The dictionary should consist of strings (byte sequences) that are likely |
| 752 | to be encountered later in the data to be compressed, with the most commonly |
| 753 | used strings preferably put towards the end of the dictionary. Using a |
| 754 | dictionary is most useful when the data to be compressed is short and can be |
| 755 | predicted with good accuracy; the data can then be compressed better than |
| 756 | with the default empty dictionary. |
| 757 | |
| 758 | Depending on the size of the compression data structures selected by |
| 759 | deflateInit or deflateInit2, a part of the dictionary may in effect be |
| 760 | discarded, for example if the dictionary is larger than the window size in |
| 761 | deflate or deflate2. Thus the strings most likely to be useful should be |
| 762 | put at the end of the dictionary, not at the front. |
| 763 | |
| 764 | Upon return of this function, strm->adler is set to the Adler32 value |
| 765 | of the dictionary; the decompressor may later use this value to determine |
| 766 | which dictionary has been used by the compressor. (The Adler32 value |
| 767 | applies to the whole dictionary even if only a subset of the dictionary is |
| 768 | actually used by the compressor.) |
| 769 | |
| 770 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a |
| 771 | parameter is invalid (such as NULL dictionary) or the stream state is |
| 772 | inconsistent (for example if deflate has already been called for this stream |
| 773 | or if the compression method is bsort). deflateSetDictionary does not |
| 774 | perform any compression: this will be done by deflate(). |
| 775 | */ |
| 776 | |
| 777 | ZEXTERN int ZEXPORT deflateCopy(z_streamp, z_streamp); |
| 778 | /* |
| 779 | Sets the destination stream as a complete copy of the source stream. |
| 780 | |
| 781 | This function can be useful when several compression strategies will be |
| 782 | tried, for example when there are several ways of pre-processing the input |
| 783 | data with a filter. The streams that will be discarded should then be freed |
| 784 | by calling deflateEnd. Note that deflateCopy duplicates the internal |
| 785 | compression state which can be quite large, so this strategy is slow and |
| 786 | can consume lots of memory. |
| 787 | |
| 788 | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not |
| 789 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent |
| 790 | (such as zalloc being NULL). msg is left unchanged in both source and |
| 791 | destination. |
| 792 | */ |
| 793 | |
| 794 | extern int inflateIncomp(z_stream *); |
| 795 | /* |
| 796 | This function adds the data at next_in (avail_in bytes) to the output |
| 797 | history without performing any output. There must be no pending output, |
| 798 | and the decompressor must be expecting to see the start of a block. |
| 799 | Calling this function is equivalent to decompressing a stored block |
| 800 | containing the data at next_in (except that the data is not output). |
| 801 | */ |
| 802 | |
| 803 | ZEXTERN int ZEXPORT deflateReset(z_streamp); |
| 804 | /* |
| 805 | This function is equivalent to deflateEnd followed by deflateInit, |
| 806 | but does not free and reallocate all the internal compression state. |
| 807 | The stream will keep the same compression level and any other attributes |
| 808 | that may have been set by deflateInit2. |
| 809 | |
| 810 | deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
| 811 | stream state was inconsistent (such as zalloc or state being NULL). |
| 812 | */ |
| 813 | |
| 814 | ZEXTERN int ZEXPORT deflateParams(z_streamp, int, int); |
| 815 | /* |
| 816 | Dynamically update the compression level and compression strategy. The |
| 817 | interpretation of level and strategy is as in deflateInit2. This can be |
| 818 | used to switch between compression and straight copy of the input data, or |
| 819 | to switch to a different kind of input data requiring a different |
| 820 | strategy. If the compression level is changed, the input available so far |
| 821 | is compressed with the old level (and may be flushed); the new level will |
| 822 | take effect only at the next call of deflate(). |
| 823 | |
| 824 | Before the call of deflateParams, the stream state must be set as for |
| 825 | a call of deflate(), since the currently available input may have to |
| 826 | be compressed and flushed. In particular, strm->avail_out must be non-zero. |
| 827 | |
| 828 | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source |
| 829 | stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR |
| 830 | if strm->avail_out was zero. |
| 831 | */ |
| 832 | |
| 833 | ZEXTERN int ZEXPORT deflateOutputPending(z_streamp); |
| 834 | /* |
| 835 | Returns the number of bytes of output which are immediately |
| 836 | available from the compressor (i.e. without any further input |
| 837 | or flush). |
| 838 | */ |
| 839 | |
| 840 | /* |
| 841 | ZEXTERN int ZEXPORT inflateInit2(z_streamp, int); |
| 842 | |
| 843 | This is another version of inflateInit with an extra parameter. The |
| 844 | fields next_in, avail_in, zalloc, zfree and opaque must be initialized |
| 845 | before by the caller. |
| 846 | |
| 847 | The windowBits parameter is the base two logarithm of the maximum window |
| 848 | size (the size of the history buffer). It should be in the range 8..15 for |
| 849 | this version of the library. The default value is 15 if inflateInit is used |
| 850 | instead. If a compressed stream with a larger window size is given as |
| 851 | input, inflate() will return with the error code Z_DATA_ERROR instead of |
| 852 | trying to allocate a larger window. |
| 853 | |
| 854 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
| 855 | memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative |
| 856 | memLevel). msg is set to null if there is no error message. inflateInit2 |
| 857 | does not perform any decompression apart from reading the zlib header if |
| 858 | present: this will be done by inflate(). (So next_in and avail_in may be |
| 859 | modified, but next_out and avail_out are unchanged.) |
| 860 | */ |
| 861 | |
| 862 | ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp, const Bytef *, uInt); |
| 863 | /* |
| 864 | Initializes the decompression dictionary from the given uncompressed byte |
| 865 | sequence. This function must be called immediately after a call of inflate |
| 866 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor |
| 867 | can be determined from the Adler32 value returned by this call of |
| 868 | inflate. The compressor and decompressor must use exactly the same |
| 869 | dictionary (see deflateSetDictionary). |
| 870 | |
| 871 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
| 872 | parameter is invalid (such as NULL dictionary) or the stream state is |
| 873 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the |
| 874 | expected one (incorrect Adler32 value). inflateSetDictionary does not |
| 875 | perform any decompression: this will be done by subsequent calls of |
| 876 | inflate(). |
| 877 | */ |
| 878 | |
| 879 | ZEXTERN int ZEXPORT inflateSync(z_streamp); |
| 880 | /* |
| 881 | Skips invalid compressed data until a full flush point (see above the |
| 882 | description of deflate with Z_FULL_FLUSH) can be found, or until all |
| 883 | available input is skipped. No output is provided. |
| 884 | |
| 885 | inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR |
| 886 | if no more input was provided, Z_DATA_ERROR if no flush point has been found, |
| 887 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success |
| 888 | case, the application may save the current current value of total_in which |
| 889 | indicates where valid compressed data was found. In the error case, the |
| 890 | application may repeatedly call inflateSync, providing more input each time, |
| 891 | until success or end of the input data. |
| 892 | */ |
| 893 | |
| 894 | ZEXTERN int ZEXPORT inflateReset(z_streamp); |
| 895 | /* |
| 896 | This function is equivalent to inflateEnd followed by inflateInit, |
| 897 | but does not free and reallocate all the internal decompression state. |
| 898 | The stream will keep attributes that may have been set by inflateInit2. |
| 899 | |
| 900 | inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
| 901 | stream state was inconsistent (such as zalloc or state being NULL). |
| 902 | */ |
| 903 | |
| 904 | |
| 905 | /* utility functions */ |
| 906 | |
| 907 | /* |
| 908 | The following utility functions are implemented on top of the |
| 909 | basic stream-oriented functions. To simplify the interface, some |
| 910 | default options are assumed (compression level and memory usage, |
| 911 | standard memory allocation functions). The source code of these |
| 912 | utility functions can easily be modified if you need special options. |
| 913 | */ |
| 914 | |
| 915 | ZEXTERN int ZEXPORT compress(Bytef *, uLongf *, const Bytef *, uLong); |
| 916 | /* |
| 917 | Compresses the source buffer into the destination buffer. sourceLen is |
| 918 | the byte length of the source buffer. Upon entry, destLen is the total |
| 919 | size of the destination buffer, which must be at least 0.1% larger than |
| 920 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the |
| 921 | compressed buffer. |
| 922 | This function can be used to compress a whole file at once if the |
| 923 | input file is mmap'ed. |
| 924 | compress returns Z_OK if success, Z_MEM_ERROR if there was not |
| 925 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
| 926 | buffer. |
| 927 | */ |
| 928 | |
| 929 | ZEXTERN int ZEXPORT compress2(Bytef *, uLongf *, const Bytef *, |
| 930 | uLong, int); |
| 931 | /* |
| 932 | Compresses the source buffer into the destination buffer. The level |
| 933 | parameter has the same meaning as in deflateInit. sourceLen is the byte |
| 934 | length of the source buffer. Upon entry, destLen is the total size of the |
| 935 | destination buffer, which must be at least 0.1% larger than sourceLen plus |
| 936 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. |
| 937 | |
| 938 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
| 939 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, |
| 940 | Z_STREAM_ERROR if the level parameter is invalid. |
| 941 | */ |
| 942 | |
| 943 | ZEXTERN int ZEXPORT uncompress(Bytef *, uLongf *, const Bytef *, uLong); |
| 944 | /* |
| 945 | Decompresses the source buffer into the destination buffer. sourceLen is |
| 946 | the byte length of the source buffer. Upon entry, destLen is the total |
| 947 | size of the destination buffer, which must be large enough to hold the |
| 948 | entire uncompressed data. (The size of the uncompressed data must have |
| 949 | been saved previously by the compressor and transmitted to the decompressor |
| 950 | by some mechanism outside the scope of this compression library.) |
| 951 | Upon exit, destLen is the actual size of the compressed buffer. |
| 952 | This function can be used to decompress a whole file at once if the |
| 953 | input file is mmap'ed. |
| 954 | |
| 955 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
| 956 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
| 957 | buffer, or Z_DATA_ERROR if the input data was corrupted. |
| 958 | */ |
| 959 | |
| 960 | |
| 961 | typedef voidp gzFile; |
| 962 | |
| 963 | ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); |
| 964 | /* |
| 965 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
| 966 | is as in fopen ("rb" or "wb") but can also include a compression level |
| 967 | ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for |
| 968 | Huffman only compression as in "wb1h". (See the description |
| 969 | of deflateInit2 for more information about the strategy parameter.) |
| 970 | |
| 971 | gzopen can be used to read a file which is not in gzip format; in this |
| 972 | case gzread will directly read from the file without decompression. |
| 973 | |
| 974 | gzopen returns NULL if the file could not be opened or if there was |
| 975 | insufficient memory to allocate the (de)compression state; errno |
| 976 | can be checked to distinguish the two cases (if errno is zero, the |
| 977 | zlib error is Z_MEM_ERROR). */ |
| 978 | |
| 979 | ZEXTERN gzFile ZEXPORT gzdopen(int, const char *); |
| 980 | /* |
| 981 | gzdopen() associates a gzFile with the file descriptor fd. File |
| 982 | descriptors are obtained from calls like open, dup, creat, pipe or |
| 983 | fileno (in the file has been previously opened with fopen). |
| 984 | The mode parameter is as in gzopen. |
| 985 | The next call of gzclose on the returned gzFile will also close the |
| 986 | file descriptor fd, just like fclose(fdopen(fd), mode) closes the file |
| 987 | descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). |
| 988 | gzdopen returns NULL if there was insufficient memory to allocate |
| 989 | the (de)compression state. |
| 990 | */ |
| 991 | |
| 992 | ZEXTERN int ZEXPORT gzsetparams(gzFile, int, int); |
| 993 | /* |
| 994 | Dynamically update the compression level or strategy. See the description |
| 995 | of deflateInit2 for the meaning of these parameters. |
| 996 | gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not |
| 997 | opened for writing. |
| 998 | */ |
| 999 | |
| 1000 | ZEXTERN int ZEXPORT gzread(gzFile, voidp, unsigned); |
| 1001 | /* |
| 1002 | Reads the given number of uncompressed bytes from the compressed file. |
| 1003 | If the input file was not in gzip format, gzread copies the given number |
| 1004 | of bytes into the buffer. |
| 1005 | gzread returns the number of uncompressed bytes actually read (0 for |
| 1006 | end of file, -1 for error). */ |
| 1007 | |
| 1008 | ZEXTERN int ZEXPORT gzwrite(gzFile, const voidp, unsigned); |
| 1009 | /* |
| 1010 | Writes the given number of uncompressed bytes into the compressed file. |
| 1011 | gzwrite returns the number of uncompressed bytes actually written |
| 1012 | (0 in case of error). |
| 1013 | */ |
| 1014 | |
| 1015 | ZEXTERN int ZEXPORTVA gzprintf(gzFile, const char *, ...) |
| 1016 | __attribute__((__format__(__printf__, 2, 3))); |
| 1017 | /* |
| 1018 | Converts, formats, and writes the args to the compressed file under |
| 1019 | control of the format string, as in fprintf. gzprintf returns the number of |
| 1020 | uncompressed bytes actually written (0 in case of error). |
| 1021 | */ |
| 1022 | |
| 1023 | ZEXTERN int ZEXPORT gzputs(gzFile, const char *); |
| 1024 | /* |
| 1025 | Writes the given null-terminated string to the compressed file, excluding |
| 1026 | the terminating null character. |
| 1027 | gzputs returns the number of characters written, or -1 in case of error. |
| 1028 | */ |
| 1029 | |
| 1030 | ZEXTERN char * ZEXPORT gzgets(gzFile, char *, int); |
| 1031 | /* |
| 1032 | Reads bytes from the compressed file until len-1 characters are read, or |
| 1033 | a newline character is read and transferred to buf, or an end-of-file |
| 1034 | condition is encountered. The string is then terminated with a null |
| 1035 | character. |
| 1036 | gzgets returns buf, or Z_NULL in case of error. |
| 1037 | */ |
| 1038 | |
| 1039 | ZEXTERN int ZEXPORT gzputc(gzFile, int); |
| 1040 | /* |
| 1041 | Writes c, converted to an unsigned char, into the compressed file. |
| 1042 | gzputc returns the value that was written, or -1 in case of error. |
| 1043 | */ |
| 1044 | |
| 1045 | ZEXTERN int ZEXPORT gzgetc(gzFile); |
| 1046 | /* |
| 1047 | Reads one byte from the compressed file. gzgetc returns this byte |
| 1048 | or -1 in case of end of file or error. |
| 1049 | */ |
| 1050 | |
| 1051 | ZEXTERN int ZEXPORT gzflush(gzFile, int); |
| 1052 | /* |
| 1053 | Flushes all pending output into the compressed file. The parameter |
| 1054 | flush is as in the deflate() function. The return value is the zlib |
| 1055 | error number (see function gzerror below). gzflush returns Z_OK if |
| 1056 | the flush parameter is Z_FINISH and all output could be flushed. |
| 1057 | gzflush should be called only when strictly necessary because it can |
| 1058 | degrade compression. |
| 1059 | |
| 1060 | */ |
| 1061 | |
| 1062 | /* |
| 1063 | * NetBSD note: |
| 1064 | * "long" gzseek has been there till Oct 1999 (1.4L), which was wrong. |
| 1065 | */ |
| 1066 | ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); |
| 1067 | /* |
| 1068 | Sets the starting position for the next gzread or gzwrite on the |
| 1069 | given compressed file. The offset represents a number of bytes in the |
| 1070 | uncompressed data stream. The whence parameter is defined as in lseek(2); |
| 1071 | the value SEEK_END is not supported. |
| 1072 | If the file is opened for reading, this function is emulated but can be |
| 1073 | extremely slow. If the file is opened for writing, only forward seeks are |
| 1074 | supported; gzseek then compresses a sequence of zeroes up to the new |
| 1075 | starting position. |
| 1076 | |
| 1077 | gzseek returns the resulting offset location as measured in bytes from |
| 1078 | the beginning of the uncompressed stream, or -1 in case of error, in |
| 1079 | particular if the file is opened for writing and the new starting position |
| 1080 | would be before the current position. |
| 1081 | */ |
| 1082 | |
| 1083 | ZEXTERN int ZEXPORT gzrewind(gzFile); |
| 1084 | /* |
| 1085 | Rewinds the given file. This function is supported only for reading. |
| 1086 | |
| 1087 | gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) |
| 1088 | */ |
| 1089 | |
| 1090 | /* |
| 1091 | * NetBSD note: |
| 1092 | * "long" gztell has been there till Oct 1999 (1.4L), which was wrong. |
| 1093 | */ |
| 1094 | ZEXTERN z_off_t ZEXPORT gztell(gzFile); |
| 1095 | /* |
| 1096 | Returns the starting position for the next gzread or gzwrite on the |
| 1097 | given compressed file. This position represents a number of bytes in the |
| 1098 | uncompressed data stream. |
| 1099 | |
| 1100 | gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) |
| 1101 | */ |
| 1102 | |
| 1103 | ZEXTERN int ZEXPORT gzeof(gzFile); |
| 1104 | /* |
| 1105 | Returns 1 when EOF has previously been detected reading the given |
| 1106 | input stream, otherwise zero. |
| 1107 | */ |
| 1108 | |
| 1109 | ZEXTERN int ZEXPORT gzclose(gzFile); |
| 1110 | /* |
| 1111 | Flushes all pending output if necessary, closes the compressed file |
| 1112 | and deallocates all the (de)compression state. The return value is the zlib |
| 1113 | error number (see function gzerror below). |
| 1114 | */ |
| 1115 | |
| 1116 | ZEXTERN const char * ZEXPORT gzerror(gzFile, int *); |
| 1117 | /* |
| 1118 | Returns the error message for the last error which occurred on the |
| 1119 | given compressed file. errnum is set to zlib error number. If an |
| 1120 | error occurred in the file system and not in the compression library, |
| 1121 | errnum is set to Z_ERRNO and the application may consult errno |
| 1122 | to get the exact error code. |
| 1123 | */ |
| 1124 | |
| 1125 | /* checksum functions */ |
| 1126 | |
| 1127 | /* |
| 1128 | These functions are not related to compression but are exported |
| 1129 | anyway because they might be useful in applications using the |
| 1130 | compression library. |
| 1131 | */ |
| 1132 | |
| 1133 | ZEXTERN uLong ZEXPORT adler32(uLong, const Bytef *, uInt); |
| 1134 | |
| 1135 | /* |
| 1136 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
| 1137 | return the updated checksum. If buf is NULL, this function returns |
| 1138 | the required initial value for the checksum. |
| 1139 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed |
| 1140 | much faster. Usage example: |
| 1141 | |
| 1142 | uLong adler = adler32(0L, Z_NULL, 0); |
| 1143 | |
| 1144 | while (read_buffer(buffer, length) != EOF) { |
| 1145 | adler = adler32(adler, buffer, length); |
| 1146 | } |
| 1147 | if (adler != original_adler) error(); |
| 1148 | */ |
| 1149 | |
| 1150 | #ifdef STANDALONE |
| 1151 | ZEXTERN uLong ZEXPORT crc32(uLong, const Bytef *, uInt); |
| 1152 | #endif |
| 1153 | /* |
| 1154 | Update a running crc with the bytes buf[0..len-1] and return the updated |
| 1155 | crc. If buf is NULL, this function returns the required initial value |
| 1156 | for the crc. Pre- and post-conditioning (one's complement) is performed |
| 1157 | within this function so it shouldn't be done by the application. |
| 1158 | Usage example: |
| 1159 | |
| 1160 | uLong crc = crc32(0L, Z_NULL, 0); |
| 1161 | |
| 1162 | while (read_buffer(buffer, length) != EOF) { |
| 1163 | crc = crc32(crc, buffer, length); |
| 1164 | } |
| 1165 | if (crc != original_crc) error(); |
| 1166 | */ |
| 1167 | |
| 1168 | |
| 1169 | /* various hacks, don't look :) */ |
| 1170 | |
| 1171 | /* deflateInit and inflateInit are macros to allow checking the zlib version |
| 1172 | * and the compiler's view of z_stream: |
| 1173 | */ |
| 1174 | ZEXTERN int ZEXPORT deflateInit_(z_streamp, int, const char *, int); |
| 1175 | ZEXTERN int ZEXPORT inflateInit_(z_streamp, const char *, int); |
| 1176 | ZEXTERN int ZEXPORT deflateInit2_(z_streamp, int, int, int, int, |
| 1177 | int, const char *, int); |
| 1178 | ZEXTERN int ZEXPORT inflateInit2_(z_streamp, int, const char *, int); |
| 1179 | #define deflateInit(strm, level) \ |
| 1180 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) |
| 1181 | #define inflateInit(strm) \ |
| 1182 | inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) |
| 1183 | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ |
| 1184 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ |
| 1185 | (strategy), ZLIB_VERSION, sizeof(z_stream)) |
| 1186 | #define inflateInit2(strm, windowBits) \ |
| 1187 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) |
| 1188 | |
| 1189 | |
| 1190 | #if !defined(Z_UTIL_H) && !defined(NO_DUMMY_DECL) |
| 1191 | struct internal_state {int dummy;}; /* hack for buggy compilers */ |
| 1192 | #endif |
| 1193 | |
| 1194 | ZEXTERN const char * ZEXPORT zError(int); |
| 1195 | ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); |
| 1196 | ZEXTERN const uLongf * ZEXPORT get_crc_table(void); |
| 1197 | |
| 1198 | #ifdef __cplusplus |
| 1199 | } |
| 1200 | #endif |
| 1201 | #endif /* !ZLIB_H */ |
| 1202 | |
| 1203 | #endif /* !_NET_ZLIB_H_ */ |
| 1204 | /* -- zlib.h */ |
| 1205 | |