1*c9431fa1Sahl /* zlib.h -- interface of the 'zlib' general purpose compression library 2*c9431fa1Sahl version 1.2.3, July 18th, 2005 37c478bd9Sstevel@tonic-gate 4*c9431fa1Sahl Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler 5*c9431fa1Sahl 6*c9431fa1Sahl This software is provided 'as-is', without any express or implied 7*c9431fa1Sahl warranty. In no event will the authors be held liable for any damages 8*c9431fa1Sahl arising from the use of this software. 9*c9431fa1Sahl 10*c9431fa1Sahl Permission is granted to anyone to use this software for any purpose, 11*c9431fa1Sahl including commercial applications, and to alter it and redistribute it 12*c9431fa1Sahl freely, subject to the following restrictions: 13*c9431fa1Sahl 14*c9431fa1Sahl 1. The origin of this software must not be misrepresented; you must not 15*c9431fa1Sahl claim that you wrote the original software. If you use this software 16*c9431fa1Sahl in a product, an acknowledgment in the product documentation would be 17*c9431fa1Sahl appreciated but is not required. 18*c9431fa1Sahl 2. Altered source versions must be plainly marked as such, and must not be 19*c9431fa1Sahl misrepresented as being the original software. 20*c9431fa1Sahl 3. This notice may not be removed or altered from any source distribution. 21*c9431fa1Sahl 22*c9431fa1Sahl Jean-loup Gailly Mark Adler 23*c9431fa1Sahl jloup@gzip.org madler@alumni.caltech.edu 24*c9431fa1Sahl 25*c9431fa1Sahl 26*c9431fa1Sahl The data format used by the zlib library is described by RFCs (Request for 27*c9431fa1Sahl Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt 28*c9431fa1Sahl (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _ZLIB_H 327c478bd9Sstevel@tonic-gate #define _ZLIB_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 357c478bd9Sstevel@tonic-gate 36*c9431fa1Sahl #include "zconf.h" 37*c9431fa1Sahl 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 42*c9431fa1Sahl #define ZLIB_VERSION "1.2.3" 43*c9431fa1Sahl #define ZLIB_VERNUM 0x1230 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate The 'zlib' compression library provides in-memory compression and 477c478bd9Sstevel@tonic-gate decompression functions, including integrity checks of the uncompressed 487c478bd9Sstevel@tonic-gate data. This version of the library supports only one compression method 497c478bd9Sstevel@tonic-gate (deflation) but other algorithms will be added later and will have the same 507c478bd9Sstevel@tonic-gate stream interface. 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate Compression can be done in a single step if the buffers are large 537c478bd9Sstevel@tonic-gate enough (for example if an input file is mmap'ed), or can be done by 547c478bd9Sstevel@tonic-gate repeated calls of the compression function. In the latter case, the 557c478bd9Sstevel@tonic-gate application must provide more input and/or consume the output 567c478bd9Sstevel@tonic-gate (providing more output space) before each call. 577c478bd9Sstevel@tonic-gate 58*c9431fa1Sahl The compressed data format used by default by the in-memory functions is 59*c9431fa1Sahl the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 60*c9431fa1Sahl around a deflate stream, which is itself documented in RFC 1951. 61*c9431fa1Sahl 627c478bd9Sstevel@tonic-gate The library also supports reading and writing files in gzip (.gz) format 63*c9431fa1Sahl with an interface similar to that of stdio using the functions that start 64*c9431fa1Sahl with "gz". The gzip format is different from the zlib format. gzip is a 65*c9431fa1Sahl gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 66*c9431fa1Sahl 67*c9431fa1Sahl This library can optionally read and write gzip streams in memory as well. 68*c9431fa1Sahl 69*c9431fa1Sahl The zlib format was designed to be compact and fast for use in memory 70*c9431fa1Sahl and on communications channels. The gzip format was designed for single- 71*c9431fa1Sahl file compression on file systems, has a larger header than zlib to maintain 72*c9431fa1Sahl directory information, and uses a different, slower check method than zlib. 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate The library does not install any signal handler. The decoder checks 757c478bd9Sstevel@tonic-gate the consistency of the compressed data, so the library should never 767c478bd9Sstevel@tonic-gate crash even in case of corrupted input. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 807c478bd9Sstevel@tonic-gate typedef void (*free_func) OF((voidpf opaque, voidpf address)); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate struct internal_state; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate typedef struct z_stream_s { 857c478bd9Sstevel@tonic-gate Bytef *next_in; /* next input byte */ 867c478bd9Sstevel@tonic-gate uInt avail_in; /* number of bytes available at next_in */ 877c478bd9Sstevel@tonic-gate uLong total_in; /* total nb of input bytes read so far */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate Bytef *next_out; /* next output byte should be put there */ 907c478bd9Sstevel@tonic-gate uInt avail_out; /* remaining free space at next_out */ 917c478bd9Sstevel@tonic-gate uLong total_out; /* total nb of bytes output so far */ 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate char *msg; /* last error message, NULL if no error */ 947c478bd9Sstevel@tonic-gate struct internal_state FAR *state; /* not visible by applications */ 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate alloc_func zalloc; /* used to allocate the internal state */ 977c478bd9Sstevel@tonic-gate free_func zfree; /* used to free the internal state */ 987c478bd9Sstevel@tonic-gate voidpf opaque; /* private data object passed to zalloc and zfree */ 997c478bd9Sstevel@tonic-gate 100*c9431fa1Sahl int data_type; /* best guess about the data type: binary or text */ 1017c478bd9Sstevel@tonic-gate uLong adler; /* adler32 value of the uncompressed data */ 1027c478bd9Sstevel@tonic-gate uLong reserved; /* reserved for future use */ 1037c478bd9Sstevel@tonic-gate } z_stream; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate typedef z_stream FAR *z_streamp; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 108*c9431fa1Sahl gzip header information passed to and from zlib routines. See RFC 1952 109*c9431fa1Sahl for more details on the meanings of these fields. 110*c9431fa1Sahl */ 111*c9431fa1Sahl typedef struct gz_header_s { 112*c9431fa1Sahl int text; /* true if compressed data believed to be text */ 113*c9431fa1Sahl uLong time; /* modification time */ 114*c9431fa1Sahl int xflags; /* extra flags (not used when writing a gzip file) */ 115*c9431fa1Sahl int os; /* operating system */ 116*c9431fa1Sahl Bytef *extra; /* pointer to extra field or Z_NULL if none */ 117*c9431fa1Sahl uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 118*c9431fa1Sahl uInt extra_max; /* space at extra (only when reading header) */ 119*c9431fa1Sahl Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 120*c9431fa1Sahl uInt name_max; /* space at name (only when reading header) */ 121*c9431fa1Sahl Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 122*c9431fa1Sahl uInt comm_max; /* space at comment (only when reading header) */ 123*c9431fa1Sahl int hcrc; /* true if there was or will be a header crc */ 124*c9431fa1Sahl int done; /* true when done reading gzip header (not used 125*c9431fa1Sahl when writing a gzip file) */ 126*c9431fa1Sahl } gz_header; 127*c9431fa1Sahl 128*c9431fa1Sahl typedef gz_header FAR *gz_headerp; 129*c9431fa1Sahl 130*c9431fa1Sahl /* 1317c478bd9Sstevel@tonic-gate The application must update next_in and avail_in when avail_in has 1327c478bd9Sstevel@tonic-gate dropped to zero. It must update next_out and avail_out when avail_out 1337c478bd9Sstevel@tonic-gate has dropped to zero. The application must initialize zalloc, zfree and 1347c478bd9Sstevel@tonic-gate opaque before calling the init function. All other fields are set by the 1357c478bd9Sstevel@tonic-gate compression library and must not be updated by the application. 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate The opaque value provided by the application will be passed as the first 1387c478bd9Sstevel@tonic-gate parameter for calls of zalloc and zfree. This can be useful for custom 1397c478bd9Sstevel@tonic-gate memory management. The compression library attaches no meaning to the 1407c478bd9Sstevel@tonic-gate opaque value. 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate zalloc must return Z_NULL if there is not enough memory for the object. 1437c478bd9Sstevel@tonic-gate If zlib is used in a multi-threaded application, zalloc and zfree must be 1447c478bd9Sstevel@tonic-gate thread safe. 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate On 16-bit systems, the functions zalloc and zfree must be able to allocate 1477c478bd9Sstevel@tonic-gate exactly 65536 bytes, but will not be required to allocate more than this 1487c478bd9Sstevel@tonic-gate if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 1497c478bd9Sstevel@tonic-gate pointers returned by zalloc for objects of exactly 65536 bytes *must* 1507c478bd9Sstevel@tonic-gate have their offset normalized to zero. The default allocation function 1517c478bd9Sstevel@tonic-gate provided by this library ensures this (see zutil.c). To reduce memory 1527c478bd9Sstevel@tonic-gate requirements and avoid any allocation of 64K objects, at the expense of 1537c478bd9Sstevel@tonic-gate compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate The fields total_in and total_out can be used for statistics or 1567c478bd9Sstevel@tonic-gate progress reports. After compression, total_in holds the total size of 1577c478bd9Sstevel@tonic-gate the uncompressed data and may be saved for use in the decompressor 1587c478bd9Sstevel@tonic-gate (particularly if the decompressor wants to decompress everything in 1597c478bd9Sstevel@tonic-gate a single step). 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* constants */ 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #define Z_NO_FLUSH 0 1657c478bd9Sstevel@tonic-gate #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 1667c478bd9Sstevel@tonic-gate #define Z_SYNC_FLUSH 2 1677c478bd9Sstevel@tonic-gate #define Z_FULL_FLUSH 3 1687c478bd9Sstevel@tonic-gate #define Z_FINISH 4 169*c9431fa1Sahl #define Z_BLOCK 5 170*c9431fa1Sahl /* Allowed flush values; see deflate() and inflate() below for details */ 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #define Z_OK 0 1737c478bd9Sstevel@tonic-gate #define Z_STREAM_END 1 1747c478bd9Sstevel@tonic-gate #define Z_NEED_DICT 2 1757c478bd9Sstevel@tonic-gate #define Z_ERRNO (-1) 1767c478bd9Sstevel@tonic-gate #define Z_STREAM_ERROR (-2) 1777c478bd9Sstevel@tonic-gate #define Z_DATA_ERROR (-3) 1787c478bd9Sstevel@tonic-gate #define Z_MEM_ERROR (-4) 1797c478bd9Sstevel@tonic-gate #define Z_BUF_ERROR (-5) 1807c478bd9Sstevel@tonic-gate #define Z_VERSION_ERROR (-6) 1817c478bd9Sstevel@tonic-gate /* Return codes for the compression/decompression functions. Negative 1827c478bd9Sstevel@tonic-gate * values are errors, positive values are used for special but normal events. 1837c478bd9Sstevel@tonic-gate */ 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate #define Z_NO_COMPRESSION 0 1867c478bd9Sstevel@tonic-gate #define Z_BEST_SPEED 1 1877c478bd9Sstevel@tonic-gate #define Z_BEST_COMPRESSION 9 1887c478bd9Sstevel@tonic-gate #define Z_DEFAULT_COMPRESSION (-1) 1897c478bd9Sstevel@tonic-gate /* compression levels */ 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate #define Z_FILTERED 1 1927c478bd9Sstevel@tonic-gate #define Z_HUFFMAN_ONLY 2 193*c9431fa1Sahl #define Z_RLE 3 194*c9431fa1Sahl #define Z_FIXED 4 1957c478bd9Sstevel@tonic-gate #define Z_DEFAULT_STRATEGY 0 1967c478bd9Sstevel@tonic-gate /* compression strategy; see deflateInit2() below for details */ 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #define Z_BINARY 0 199*c9431fa1Sahl #define Z_TEXT 1 200*c9431fa1Sahl #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 2017c478bd9Sstevel@tonic-gate #define Z_UNKNOWN 2 202*c9431fa1Sahl /* Possible values of the data_type field (though see inflate()) */ 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #define Z_DEFLATED 8 2057c478bd9Sstevel@tonic-gate /* The deflate compression method (the only one supported in this version) */ 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #define zlib_version zlibVersion() 2107c478bd9Sstevel@tonic-gate /* for compatibility with versions < 1.0.2 */ 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* basic functions */ 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 2157c478bd9Sstevel@tonic-gate /* The application can compare zlibVersion and ZLIB_VERSION for consistency. 2167c478bd9Sstevel@tonic-gate If the first character differs, the library code actually used is 2177c478bd9Sstevel@tonic-gate not compatible with the zlib.h header file used by the application. 2187c478bd9Sstevel@tonic-gate This check is automatically made by deflateInit and inflateInit. 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* 2227c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate Initializes the internal stream state for compression. The fields 2257c478bd9Sstevel@tonic-gate zalloc, zfree and opaque must be initialized before by the caller. 2267c478bd9Sstevel@tonic-gate If zalloc and zfree are set to Z_NULL, deflateInit updates them to 2277c478bd9Sstevel@tonic-gate use default allocation functions. 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 2307c478bd9Sstevel@tonic-gate 1 gives best speed, 9 gives best compression, 0 gives no compression at 2317c478bd9Sstevel@tonic-gate all (the input data is simply copied a block at a time). 2327c478bd9Sstevel@tonic-gate Z_DEFAULT_COMPRESSION requests a default compromise between speed and 2337c478bd9Sstevel@tonic-gate compression (currently equivalent to level 6). 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 2367c478bd9Sstevel@tonic-gate enough memory, Z_STREAM_ERROR if level is not a valid compression level, 2377c478bd9Sstevel@tonic-gate Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 2387c478bd9Sstevel@tonic-gate with the version assumed by the caller (ZLIB_VERSION). 2397c478bd9Sstevel@tonic-gate msg is set to null if there is no error message. deflateInit does not 2407c478bd9Sstevel@tonic-gate perform any compression: this will be done by deflate(). 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 2457c478bd9Sstevel@tonic-gate /* 2467c478bd9Sstevel@tonic-gate deflate compresses as much data as possible, and stops when the input 2477c478bd9Sstevel@tonic-gate buffer becomes empty or the output buffer becomes full. It may introduce some 2487c478bd9Sstevel@tonic-gate output latency (reading input without producing any output) except when 2497c478bd9Sstevel@tonic-gate forced to flush. 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate The detailed semantics are as follows. deflate performs one or both of the 2527c478bd9Sstevel@tonic-gate following actions: 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate - Compress more input starting at next_in and update next_in and avail_in 2557c478bd9Sstevel@tonic-gate accordingly. If not all input can be processed (because there is not 2567c478bd9Sstevel@tonic-gate enough room in the output buffer), next_in and avail_in are updated and 2577c478bd9Sstevel@tonic-gate processing will resume at this point for the next call of deflate(). 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate - Provide more output starting at next_out and update next_out and avail_out 2607c478bd9Sstevel@tonic-gate accordingly. This action is forced if the parameter flush is non zero. 2617c478bd9Sstevel@tonic-gate Forcing flush frequently degrades the compression ratio, so this parameter 2627c478bd9Sstevel@tonic-gate should be set only when necessary (in interactive applications). 2637c478bd9Sstevel@tonic-gate Some output may be provided even if flush is not set. 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate Before the call of deflate(), the application should ensure that at least 2667c478bd9Sstevel@tonic-gate one of the actions is possible, by providing more input and/or consuming 2677c478bd9Sstevel@tonic-gate more output, and updating avail_in or avail_out accordingly; avail_out 2687c478bd9Sstevel@tonic-gate should never be zero before the call. The application can consume the 2697c478bd9Sstevel@tonic-gate compressed output when it wants, for example when the output buffer is full 2707c478bd9Sstevel@tonic-gate (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 2717c478bd9Sstevel@tonic-gate and with zero avail_out, it must be called again after making room in the 2727c478bd9Sstevel@tonic-gate output buffer because there might be more output pending. 2737c478bd9Sstevel@tonic-gate 274*c9431fa1Sahl Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 275*c9431fa1Sahl decide how much data to accumualte before producing output, in order to 276*c9431fa1Sahl maximize compression. 277*c9431fa1Sahl 2787c478bd9Sstevel@tonic-gate If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 2797c478bd9Sstevel@tonic-gate flushed to the output buffer and the output is aligned on a byte boundary, so 2807c478bd9Sstevel@tonic-gate that the decompressor can get all input data available so far. (In particular 2817c478bd9Sstevel@tonic-gate avail_in is zero after the call if enough output space has been provided 2827c478bd9Sstevel@tonic-gate before the call.) Flushing may degrade compression for some compression 2837c478bd9Sstevel@tonic-gate algorithms and so it should be used only when necessary. 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate If flush is set to Z_FULL_FLUSH, all output is flushed as with 2867c478bd9Sstevel@tonic-gate Z_SYNC_FLUSH, and the compression state is reset so that decompression can 2877c478bd9Sstevel@tonic-gate restart from this point if previous compressed data has been damaged or if 2887c478bd9Sstevel@tonic-gate random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 289*c9431fa1Sahl compression. 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate If deflate returns with avail_out == 0, this function must be called again 2927c478bd9Sstevel@tonic-gate with the same value of the flush parameter and more output space (updated 2937c478bd9Sstevel@tonic-gate avail_out), until the flush is complete (deflate returns with non-zero 294*c9431fa1Sahl avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 295*c9431fa1Sahl avail_out is greater than six to avoid repeated flush markers due to 296*c9431fa1Sahl avail_out == 0 on return. 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate If the parameter flush is set to Z_FINISH, pending input is processed, 2997c478bd9Sstevel@tonic-gate pending output is flushed and deflate returns with Z_STREAM_END if there 3007c478bd9Sstevel@tonic-gate was enough output space; if deflate returns with Z_OK, this function must be 3017c478bd9Sstevel@tonic-gate called again with Z_FINISH and more output space (updated avail_out) but no 3027c478bd9Sstevel@tonic-gate more input data, until it returns with Z_STREAM_END or an error. After 3037c478bd9Sstevel@tonic-gate deflate has returned Z_STREAM_END, the only possible operations on the 3047c478bd9Sstevel@tonic-gate stream are deflateReset or deflateEnd. 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate Z_FINISH can be used immediately after deflateInit if all the compression 3077c478bd9Sstevel@tonic-gate is to be done in a single step. In this case, avail_out must be at least 308*c9431fa1Sahl the value returned by deflateBound (see below). If deflate does not return 3097c478bd9Sstevel@tonic-gate Z_STREAM_END, then it must be called again as described above. 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate deflate() sets strm->adler to the adler32 checksum of all input read 3127c478bd9Sstevel@tonic-gate so far (that is, total_in bytes). 3137c478bd9Sstevel@tonic-gate 314*c9431fa1Sahl deflate() may update strm->data_type if it can make a good guess about 315*c9431fa1Sahl the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 3167c478bd9Sstevel@tonic-gate binary. This field is only for information purposes and does not affect 3177c478bd9Sstevel@tonic-gate the compression algorithm in any manner. 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate deflate() returns Z_OK if some progress has been made (more input 3207c478bd9Sstevel@tonic-gate processed or more output produced), Z_STREAM_END if all input has been 3217c478bd9Sstevel@tonic-gate consumed and all output has been produced (only when flush is set to 3227c478bd9Sstevel@tonic-gate Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 3237c478bd9Sstevel@tonic-gate if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 324*c9431fa1Sahl (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 325*c9431fa1Sahl fatal, and deflate() can be called again with more input and more output 326*c9431fa1Sahl space to continue compressing. 3277c478bd9Sstevel@tonic-gate */ 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 3317c478bd9Sstevel@tonic-gate /* 3327c478bd9Sstevel@tonic-gate All dynamically allocated data structures for this stream are freed. 3337c478bd9Sstevel@tonic-gate This function discards any unprocessed input and does not flush any 3347c478bd9Sstevel@tonic-gate pending output. 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 3377c478bd9Sstevel@tonic-gate stream state was inconsistent, Z_DATA_ERROR if the stream was freed 3387c478bd9Sstevel@tonic-gate prematurely (some input or output was discarded). In the error case, 3397c478bd9Sstevel@tonic-gate msg may be set but then points to a static string (which must not be 3407c478bd9Sstevel@tonic-gate deallocated). 3417c478bd9Sstevel@tonic-gate */ 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate Initializes the internal stream state for decompression. The fields 3487c478bd9Sstevel@tonic-gate next_in, avail_in, zalloc, zfree and opaque must be initialized before by 3497c478bd9Sstevel@tonic-gate the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 3507c478bd9Sstevel@tonic-gate value depends on the compression method), inflateInit determines the 3517c478bd9Sstevel@tonic-gate compression method from the zlib header and allocates all data structures 3527c478bd9Sstevel@tonic-gate accordingly; otherwise the allocation will be deferred to the first call of 3537c478bd9Sstevel@tonic-gate inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 3547c478bd9Sstevel@tonic-gate use default allocation functions. 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 3577c478bd9Sstevel@tonic-gate memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 3587c478bd9Sstevel@tonic-gate version assumed by the caller. msg is set to null if there is no error 3597c478bd9Sstevel@tonic-gate message. inflateInit does not perform any decompression apart from reading 3607c478bd9Sstevel@tonic-gate the zlib header if present: this will be done by inflate(). (So next_in and 3617c478bd9Sstevel@tonic-gate avail_in may be modified, but next_out and avail_out are unchanged.) 3627c478bd9Sstevel@tonic-gate */ 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 3667c478bd9Sstevel@tonic-gate /* 3677c478bd9Sstevel@tonic-gate inflate decompresses as much data as possible, and stops when the input 368*c9431fa1Sahl buffer becomes empty or the output buffer becomes full. It may introduce 369*c9431fa1Sahl some output latency (reading input without producing any output) except when 370*c9431fa1Sahl forced to flush. 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate The detailed semantics are as follows. inflate performs one or both of the 3737c478bd9Sstevel@tonic-gate following actions: 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate - Decompress more input starting at next_in and update next_in and avail_in 3767c478bd9Sstevel@tonic-gate accordingly. If not all input can be processed (because there is not 3777c478bd9Sstevel@tonic-gate enough room in the output buffer), next_in is updated and processing 3787c478bd9Sstevel@tonic-gate will resume at this point for the next call of inflate(). 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate - Provide more output starting at next_out and update next_out and avail_out 3817c478bd9Sstevel@tonic-gate accordingly. inflate() provides as much output as possible, until there 3827c478bd9Sstevel@tonic-gate is no more input data or no more space in the output buffer (see below 3837c478bd9Sstevel@tonic-gate about the flush parameter). 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate Before the call of inflate(), the application should ensure that at least 3867c478bd9Sstevel@tonic-gate one of the actions is possible, by providing more input and/or consuming 3877c478bd9Sstevel@tonic-gate more output, and updating the next_* and avail_* values accordingly. 3887c478bd9Sstevel@tonic-gate The application can consume the uncompressed output when it wants, for 3897c478bd9Sstevel@tonic-gate example when the output buffer is full (avail_out == 0), or after each 3907c478bd9Sstevel@tonic-gate call of inflate(). If inflate returns Z_OK and with zero avail_out, it 3917c478bd9Sstevel@tonic-gate must be called again after making room in the output buffer because there 3927c478bd9Sstevel@tonic-gate might be more output pending. 3937c478bd9Sstevel@tonic-gate 394*c9431fa1Sahl The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, 395*c9431fa1Sahl Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much 396*c9431fa1Sahl output as possible to the output buffer. Z_BLOCK requests that inflate() stop 397*c9431fa1Sahl if and when it gets to the next deflate block boundary. When decoding the 398*c9431fa1Sahl zlib or gzip format, this will cause inflate() to return immediately after 399*c9431fa1Sahl the header and before the first block. When doing a raw inflate, inflate() 400*c9431fa1Sahl will go ahead and process the first block, and will return when it gets to 401*c9431fa1Sahl the end of that block, or when it runs out of data. 402*c9431fa1Sahl 403*c9431fa1Sahl The Z_BLOCK option assists in appending to or combining deflate streams. 404*c9431fa1Sahl Also to assist in this, on return inflate() will set strm->data_type to the 405*c9431fa1Sahl number of unused bits in the last byte taken from strm->next_in, plus 64 406*c9431fa1Sahl if inflate() is currently decoding the last block in the deflate stream, 407*c9431fa1Sahl plus 128 if inflate() returned immediately after decoding an end-of-block 408*c9431fa1Sahl code or decoding the complete header up to just before the first byte of the 409*c9431fa1Sahl deflate stream. The end-of-block will not be indicated until all of the 410*c9431fa1Sahl uncompressed data from that block has been written to strm->next_out. The 411*c9431fa1Sahl number of unused bits may in general be greater than seven, except when 412*c9431fa1Sahl bit 7 of data_type is set, in which case the number of unused bits will be 413*c9431fa1Sahl less than eight. 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate inflate() should normally be called until it returns Z_STREAM_END or an 4167c478bd9Sstevel@tonic-gate error. However if all decompression is to be performed in a single step 4177c478bd9Sstevel@tonic-gate (a single call of inflate), the parameter flush should be set to 4187c478bd9Sstevel@tonic-gate Z_FINISH. In this case all pending input is processed and all pending 4197c478bd9Sstevel@tonic-gate output is flushed; avail_out must be large enough to hold all the 4207c478bd9Sstevel@tonic-gate uncompressed data. (The size of the uncompressed data may have been saved 4217c478bd9Sstevel@tonic-gate by the compressor for this purpose.) The next operation on this stream must 4227c478bd9Sstevel@tonic-gate be inflateEnd to deallocate the decompression state. The use of Z_FINISH 423*c9431fa1Sahl is never required, but can be used to inform inflate that a faster approach 4247c478bd9Sstevel@tonic-gate may be used for the single inflate() call. 4257c478bd9Sstevel@tonic-gate 426*c9431fa1Sahl In this implementation, inflate() always flushes as much output as 427*c9431fa1Sahl possible to the output buffer, and always uses the faster approach on the 428*c9431fa1Sahl first call. So the only effect of the flush parameter in this implementation 429*c9431fa1Sahl is on the return value of inflate(), as noted below, or when it returns early 430*c9431fa1Sahl because Z_BLOCK is used. 431*c9431fa1Sahl 432*c9431fa1Sahl If a preset dictionary is needed after this call (see inflateSetDictionary 433*c9431fa1Sahl below), inflate sets strm->adler to the adler32 checksum of the dictionary 434*c9431fa1Sahl chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 435*c9431fa1Sahl strm->adler to the adler32 checksum of all output produced so far (that is, 436*c9431fa1Sahl total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 437*c9431fa1Sahl below. At the end of the stream, inflate() checks that its computed adler32 438*c9431fa1Sahl checksum is equal to that saved by the compressor and returns Z_STREAM_END 439*c9431fa1Sahl only if the checksum is correct. 440*c9431fa1Sahl 441*c9431fa1Sahl inflate() will decompress and check either zlib-wrapped or gzip-wrapped 442*c9431fa1Sahl deflate data. The header type is detected automatically. Any information 443*c9431fa1Sahl contained in the gzip header is not retained, so applications that need that 444*c9431fa1Sahl information should instead use raw inflate, see inflateInit2() below, or 445*c9431fa1Sahl inflateBack() and perform their own processing of the gzip header and 446*c9431fa1Sahl trailer. 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate inflate() returns Z_OK if some progress has been made (more input processed 4497c478bd9Sstevel@tonic-gate or more output produced), Z_STREAM_END if the end of the compressed data has 4507c478bd9Sstevel@tonic-gate been reached and all uncompressed output has been produced, Z_NEED_DICT if a 4517c478bd9Sstevel@tonic-gate preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 452*c9431fa1Sahl corrupted (input stream not conforming to the zlib format or incorrect check 453*c9431fa1Sahl value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 454*c9431fa1Sahl if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, 455*c9431fa1Sahl Z_BUF_ERROR if no progress is possible or if there was not enough room in the 456*c9431fa1Sahl output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 457*c9431fa1Sahl inflate() can be called again with more input and more output space to 458*c9431fa1Sahl continue decompressing. If Z_DATA_ERROR is returned, the application may then 459*c9431fa1Sahl call inflateSync() to look for a good compression block if a partial recovery 460*c9431fa1Sahl of the data is desired. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 4657c478bd9Sstevel@tonic-gate /* 4667c478bd9Sstevel@tonic-gate All dynamically allocated data structures for this stream are freed. 4677c478bd9Sstevel@tonic-gate This function discards any unprocessed input and does not flush any 4687c478bd9Sstevel@tonic-gate pending output. 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 4717c478bd9Sstevel@tonic-gate was inconsistent. In the error case, msg may be set but then points to a 4727c478bd9Sstevel@tonic-gate static string (which must not be deallocated). 4737c478bd9Sstevel@tonic-gate */ 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* Advanced functions */ 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate /* 4787c478bd9Sstevel@tonic-gate The following functions are needed only in some special applications. 4797c478bd9Sstevel@tonic-gate */ 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 4837c478bd9Sstevel@tonic-gate int level, 4847c478bd9Sstevel@tonic-gate int method, 4857c478bd9Sstevel@tonic-gate int windowBits, 4867c478bd9Sstevel@tonic-gate int memLevel, 4877c478bd9Sstevel@tonic-gate int strategy)); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate This is another version of deflateInit with more compression options. The 4907c478bd9Sstevel@tonic-gate fields next_in, zalloc, zfree and opaque must be initialized before by 4917c478bd9Sstevel@tonic-gate the caller. 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate The method parameter is the compression method. It must be Z_DEFLATED in 4947c478bd9Sstevel@tonic-gate this version of the library. 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate The windowBits parameter is the base two logarithm of the window size 4977c478bd9Sstevel@tonic-gate (the size of the history buffer). It should be in the range 8..15 for this 4987c478bd9Sstevel@tonic-gate version of the library. Larger values of this parameter result in better 4997c478bd9Sstevel@tonic-gate compression at the expense of memory usage. The default value is 15 if 5007c478bd9Sstevel@tonic-gate deflateInit is used instead. 5017c478bd9Sstevel@tonic-gate 502*c9431fa1Sahl windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 503*c9431fa1Sahl determines the window size. deflate() will then generate raw deflate data 504*c9431fa1Sahl with no zlib header or trailer, and will not compute an adler32 check value. 505*c9431fa1Sahl 506*c9431fa1Sahl windowBits can also be greater than 15 for optional gzip encoding. Add 507*c9431fa1Sahl 16 to windowBits to write a simple gzip header and trailer around the 508*c9431fa1Sahl compressed data instead of a zlib wrapper. The gzip header will have no 509*c9431fa1Sahl file name, no extra data, no comment, no modification time (set to zero), 510*c9431fa1Sahl no header crc, and the operating system will be set to 255 (unknown). If a 511*c9431fa1Sahl gzip stream is being written, strm->adler is a crc32 instead of an adler32. 512*c9431fa1Sahl 5137c478bd9Sstevel@tonic-gate The memLevel parameter specifies how much memory should be allocated 5147c478bd9Sstevel@tonic-gate for the internal compression state. memLevel=1 uses minimum memory but 5157c478bd9Sstevel@tonic-gate is slow and reduces compression ratio; memLevel=9 uses maximum memory 5167c478bd9Sstevel@tonic-gate for optimal speed. The default value is 8. See zconf.h for total memory 5177c478bd9Sstevel@tonic-gate usage as a function of windowBits and memLevel. 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate The strategy parameter is used to tune the compression algorithm. Use the 5207c478bd9Sstevel@tonic-gate value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 521*c9431fa1Sahl filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 522*c9431fa1Sahl string match), or Z_RLE to limit match distances to one (run-length 523*c9431fa1Sahl encoding). Filtered data consists mostly of small values with a somewhat 524*c9431fa1Sahl random distribution. In this case, the compression algorithm is tuned to 525*c9431fa1Sahl compress them better. The effect of Z_FILTERED is to force more Huffman 526*c9431fa1Sahl coding and less string matching; it is somewhat intermediate between 527*c9431fa1Sahl Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as 528*c9431fa1Sahl Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy 529*c9431fa1Sahl parameter only affects the compression ratio but not the correctness of the 530*c9431fa1Sahl compressed output even if it is not set appropriately. Z_FIXED prevents the 531*c9431fa1Sahl use of dynamic Huffman codes, allowing for a simpler decoder for special 532*c9431fa1Sahl applications. 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 5357c478bd9Sstevel@tonic-gate memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 5367c478bd9Sstevel@tonic-gate method). msg is set to null if there is no error message. deflateInit2 does 5377c478bd9Sstevel@tonic-gate not perform any compression: this will be done by deflate(). 5387c478bd9Sstevel@tonic-gate */ 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 5417c478bd9Sstevel@tonic-gate const Bytef *dictionary, 5427c478bd9Sstevel@tonic-gate uInt dictLength)); 5437c478bd9Sstevel@tonic-gate /* 5447c478bd9Sstevel@tonic-gate Initializes the compression dictionary from the given byte sequence 5457c478bd9Sstevel@tonic-gate without producing any compressed output. This function must be called 5467c478bd9Sstevel@tonic-gate immediately after deflateInit, deflateInit2 or deflateReset, before any 5477c478bd9Sstevel@tonic-gate call of deflate. The compressor and decompressor must use exactly the same 5487c478bd9Sstevel@tonic-gate dictionary (see inflateSetDictionary). 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate The dictionary should consist of strings (byte sequences) that are likely 5517c478bd9Sstevel@tonic-gate to be encountered later in the data to be compressed, with the most commonly 5527c478bd9Sstevel@tonic-gate used strings preferably put towards the end of the dictionary. Using a 5537c478bd9Sstevel@tonic-gate dictionary is most useful when the data to be compressed is short and can be 5547c478bd9Sstevel@tonic-gate predicted with good accuracy; the data can then be compressed better than 5557c478bd9Sstevel@tonic-gate with the default empty dictionary. 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate Depending on the size of the compression data structures selected by 5587c478bd9Sstevel@tonic-gate deflateInit or deflateInit2, a part of the dictionary may in effect be 5597c478bd9Sstevel@tonic-gate discarded, for example if the dictionary is larger than the window size in 5607c478bd9Sstevel@tonic-gate deflate or deflate2. Thus the strings most likely to be useful should be 561*c9431fa1Sahl put at the end of the dictionary, not at the front. In addition, the 562*c9431fa1Sahl current implementation of deflate will use at most the window size minus 563*c9431fa1Sahl 262 bytes of the provided dictionary. 5647c478bd9Sstevel@tonic-gate 565*c9431fa1Sahl Upon return of this function, strm->adler is set to the adler32 value 5667c478bd9Sstevel@tonic-gate of the dictionary; the decompressor may later use this value to determine 567*c9431fa1Sahl which dictionary has been used by the compressor. (The adler32 value 5687c478bd9Sstevel@tonic-gate applies to the whole dictionary even if only a subset of the dictionary is 569*c9431fa1Sahl actually used by the compressor.) If a raw deflate was requested, then the 570*c9431fa1Sahl adler32 value is not computed and strm->adler is not set. 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 5737c478bd9Sstevel@tonic-gate parameter is invalid (such as NULL dictionary) or the stream state is 5747c478bd9Sstevel@tonic-gate inconsistent (for example if deflate has already been called for this stream 5757c478bd9Sstevel@tonic-gate or if the compression method is bsort). deflateSetDictionary does not 5767c478bd9Sstevel@tonic-gate perform any compression: this will be done by deflate(). 5777c478bd9Sstevel@tonic-gate */ 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 5807c478bd9Sstevel@tonic-gate z_streamp source)); 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate Sets the destination stream as a complete copy of the source stream. 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate This function can be useful when several compression strategies will be 5857c478bd9Sstevel@tonic-gate tried, for example when there are several ways of pre-processing the input 5867c478bd9Sstevel@tonic-gate data with a filter. The streams that will be discarded should then be freed 5877c478bd9Sstevel@tonic-gate by calling deflateEnd. Note that deflateCopy duplicates the internal 5887c478bd9Sstevel@tonic-gate compression state which can be quite large, so this strategy is slow and 5897c478bd9Sstevel@tonic-gate can consume lots of memory. 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 5927c478bd9Sstevel@tonic-gate enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 5937c478bd9Sstevel@tonic-gate (such as zalloc being NULL). msg is left unchanged in both source and 5947c478bd9Sstevel@tonic-gate destination. 5957c478bd9Sstevel@tonic-gate */ 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 5987c478bd9Sstevel@tonic-gate /* 5997c478bd9Sstevel@tonic-gate This function is equivalent to deflateEnd followed by deflateInit, 6007c478bd9Sstevel@tonic-gate but does not free and reallocate all the internal compression state. 6017c478bd9Sstevel@tonic-gate The stream will keep the same compression level and any other attributes 6027c478bd9Sstevel@tonic-gate that may have been set by deflateInit2. 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 6057c478bd9Sstevel@tonic-gate stream state was inconsistent (such as zalloc or state being NULL). 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 6097c478bd9Sstevel@tonic-gate int level, 6107c478bd9Sstevel@tonic-gate int strategy)); 6117c478bd9Sstevel@tonic-gate /* 6127c478bd9Sstevel@tonic-gate Dynamically update the compression level and compression strategy. The 6137c478bd9Sstevel@tonic-gate interpretation of level and strategy is as in deflateInit2. This can be 6147c478bd9Sstevel@tonic-gate used to switch between compression and straight copy of the input data, or 6157c478bd9Sstevel@tonic-gate to switch to a different kind of input data requiring a different 6167c478bd9Sstevel@tonic-gate strategy. If the compression level is changed, the input available so far 6177c478bd9Sstevel@tonic-gate is compressed with the old level (and may be flushed); the new level will 6187c478bd9Sstevel@tonic-gate take effect only at the next call of deflate(). 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate Before the call of deflateParams, the stream state must be set as for 6217c478bd9Sstevel@tonic-gate a call of deflate(), since the currently available input may have to 6227c478bd9Sstevel@tonic-gate be compressed and flushed. In particular, strm->avail_out must be non-zero. 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 6257c478bd9Sstevel@tonic-gate stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 6267c478bd9Sstevel@tonic-gate if strm->avail_out was zero. 6277c478bd9Sstevel@tonic-gate */ 6287c478bd9Sstevel@tonic-gate 629*c9431fa1Sahl ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 630*c9431fa1Sahl int good_length, 631*c9431fa1Sahl int max_lazy, 632*c9431fa1Sahl int nice_length, 633*c9431fa1Sahl int max_chain)); 634*c9431fa1Sahl /* 635*c9431fa1Sahl Fine tune deflate's internal compression parameters. This should only be 636*c9431fa1Sahl used by someone who understands the algorithm used by zlib's deflate for 637*c9431fa1Sahl searching for the best matching string, and even then only by the most 638*c9431fa1Sahl fanatic optimizer trying to squeeze out the last compressed bit for their 639*c9431fa1Sahl specific input data. Read the deflate.c source code for the meaning of the 640*c9431fa1Sahl max_lazy, good_length, nice_length, and max_chain parameters. 641*c9431fa1Sahl 642*c9431fa1Sahl deflateTune() can be called after deflateInit() or deflateInit2(), and 643*c9431fa1Sahl returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 644*c9431fa1Sahl */ 645*c9431fa1Sahl 646*c9431fa1Sahl ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 647*c9431fa1Sahl uLong sourceLen)); 648*c9431fa1Sahl /* 649*c9431fa1Sahl deflateBound() returns an upper bound on the compressed size after 650*c9431fa1Sahl deflation of sourceLen bytes. It must be called after deflateInit() 651*c9431fa1Sahl or deflateInit2(). This would be used to allocate an output buffer 652*c9431fa1Sahl for deflation in a single pass, and so would be called before deflate(). 653*c9431fa1Sahl */ 654*c9431fa1Sahl 655*c9431fa1Sahl ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 656*c9431fa1Sahl int bits, 657*c9431fa1Sahl int value)); 658*c9431fa1Sahl /* 659*c9431fa1Sahl deflatePrime() inserts bits in the deflate output stream. The intent 660*c9431fa1Sahl is that this function is used to start off the deflate output with the 661*c9431fa1Sahl bits leftover from a previous deflate stream when appending to it. As such, 662*c9431fa1Sahl this function can only be used for raw deflate, and must be used before the 663*c9431fa1Sahl first deflate() call after a deflateInit2() or deflateReset(). bits must be 664*c9431fa1Sahl less than or equal to 16, and that many of the least significant bits of 665*c9431fa1Sahl value will be inserted in the output. 666*c9431fa1Sahl 667*c9431fa1Sahl deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 668*c9431fa1Sahl stream state was inconsistent. 669*c9431fa1Sahl */ 670*c9431fa1Sahl 671*c9431fa1Sahl ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 672*c9431fa1Sahl gz_headerp head)); 673*c9431fa1Sahl /* 674*c9431fa1Sahl deflateSetHeader() provides gzip header information for when a gzip 675*c9431fa1Sahl stream is requested by deflateInit2(). deflateSetHeader() may be called 676*c9431fa1Sahl after deflateInit2() or deflateReset() and before the first call of 677*c9431fa1Sahl deflate(). The text, time, os, extra field, name, and comment information 678*c9431fa1Sahl in the provided gz_header structure are written to the gzip header (xflag is 679*c9431fa1Sahl ignored -- the extra flags are set according to the compression level). The 680*c9431fa1Sahl caller must assure that, if not Z_NULL, name and comment are terminated with 681*c9431fa1Sahl a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 682*c9431fa1Sahl available there. If hcrc is true, a gzip header crc is included. Note that 683*c9431fa1Sahl the current versions of the command-line version of gzip (up through version 684*c9431fa1Sahl 1.3.x) do not support header crc's, and will report that it is a "multi-part 685*c9431fa1Sahl gzip file" and give up. 686*c9431fa1Sahl 687*c9431fa1Sahl If deflateSetHeader is not used, the default gzip header has text false, 688*c9431fa1Sahl the time set to zero, and os set to 255, with no extra, name, or comment 689*c9431fa1Sahl fields. The gzip header is returned to the default state by deflateReset(). 690*c9431fa1Sahl 691*c9431fa1Sahl deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 692*c9431fa1Sahl stream state was inconsistent. 693*c9431fa1Sahl */ 694*c9431fa1Sahl 6957c478bd9Sstevel@tonic-gate /* 6967c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 6977c478bd9Sstevel@tonic-gate int windowBits)); 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate This is another version of inflateInit with an extra parameter. The 7007c478bd9Sstevel@tonic-gate fields next_in, avail_in, zalloc, zfree and opaque must be initialized 7017c478bd9Sstevel@tonic-gate before by the caller. 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate The windowBits parameter is the base two logarithm of the maximum window 7047c478bd9Sstevel@tonic-gate size (the size of the history buffer). It should be in the range 8..15 for 7057c478bd9Sstevel@tonic-gate this version of the library. The default value is 15 if inflateInit is used 706*c9431fa1Sahl instead. windowBits must be greater than or equal to the windowBits value 707*c9431fa1Sahl provided to deflateInit2() while compressing, or it must be equal to 15 if 708*c9431fa1Sahl deflateInit2() was not used. If a compressed stream with a larger window 709*c9431fa1Sahl size is given as input, inflate() will return with the error code 710*c9431fa1Sahl Z_DATA_ERROR instead of trying to allocate a larger window. 711*c9431fa1Sahl 712*c9431fa1Sahl windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 713*c9431fa1Sahl determines the window size. inflate() will then process raw deflate data, 714*c9431fa1Sahl not looking for a zlib or gzip header, not generating a check value, and not 715*c9431fa1Sahl looking for any check values for comparison at the end of the stream. This 716*c9431fa1Sahl is for use with other formats that use the deflate compressed data format 717*c9431fa1Sahl such as zip. Those formats provide their own check values. If a custom 718*c9431fa1Sahl format is developed using the raw deflate format for compressed data, it is 719*c9431fa1Sahl recommended that a check value such as an adler32 or a crc32 be applied to 720*c9431fa1Sahl the uncompressed data as is done in the zlib, gzip, and zip formats. For 721*c9431fa1Sahl most applications, the zlib format should be used as is. Note that comments 722*c9431fa1Sahl above on the use in deflateInit2() applies to the magnitude of windowBits. 723*c9431fa1Sahl 724*c9431fa1Sahl windowBits can also be greater than 15 for optional gzip decoding. Add 725*c9431fa1Sahl 32 to windowBits to enable zlib and gzip decoding with automatic header 726*c9431fa1Sahl detection, or add 16 to decode only the gzip format (the zlib format will 727*c9431fa1Sahl return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 728*c9431fa1Sahl a crc32 instead of an adler32. 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 731*c9431fa1Sahl memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg 732*c9431fa1Sahl is set to null if there is no error message. inflateInit2 does not perform 733*c9431fa1Sahl any decompression apart from reading the zlib header if present: this will 734*c9431fa1Sahl be done by inflate(). (So next_in and avail_in may be modified, but next_out 735*c9431fa1Sahl and avail_out are unchanged.) 7367c478bd9Sstevel@tonic-gate */ 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 7397c478bd9Sstevel@tonic-gate const Bytef *dictionary, 7407c478bd9Sstevel@tonic-gate uInt dictLength)); 7417c478bd9Sstevel@tonic-gate /* 7427c478bd9Sstevel@tonic-gate Initializes the decompression dictionary from the given uncompressed byte 743*c9431fa1Sahl sequence. This function must be called immediately after a call of inflate, 744*c9431fa1Sahl if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 745*c9431fa1Sahl can be determined from the adler32 value returned by that call of inflate. 746*c9431fa1Sahl The compressor and decompressor must use exactly the same dictionary (see 747*c9431fa1Sahl deflateSetDictionary). For raw inflate, this function can be called 748*c9431fa1Sahl immediately after inflateInit2() or inflateReset() and before any call of 749*c9431fa1Sahl inflate() to set the dictionary. The application must insure that the 750*c9431fa1Sahl dictionary that was used for compression is provided. 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 7537c478bd9Sstevel@tonic-gate parameter is invalid (such as NULL dictionary) or the stream state is 7547c478bd9Sstevel@tonic-gate inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 755*c9431fa1Sahl expected one (incorrect adler32 value). inflateSetDictionary does not 7567c478bd9Sstevel@tonic-gate perform any decompression: this will be done by subsequent calls of 7577c478bd9Sstevel@tonic-gate inflate(). 7587c478bd9Sstevel@tonic-gate */ 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 7617c478bd9Sstevel@tonic-gate /* 7627c478bd9Sstevel@tonic-gate Skips invalid compressed data until a full flush point (see above the 7637c478bd9Sstevel@tonic-gate description of deflate with Z_FULL_FLUSH) can be found, or until all 7647c478bd9Sstevel@tonic-gate available input is skipped. No output is provided. 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 7677c478bd9Sstevel@tonic-gate if no more input was provided, Z_DATA_ERROR if no flush point has been found, 7687c478bd9Sstevel@tonic-gate or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 7697c478bd9Sstevel@tonic-gate case, the application may save the current current value of total_in which 7707c478bd9Sstevel@tonic-gate indicates where valid compressed data was found. In the error case, the 7717c478bd9Sstevel@tonic-gate application may repeatedly call inflateSync, providing more input each time, 7727c478bd9Sstevel@tonic-gate until success or end of the input data. 7737c478bd9Sstevel@tonic-gate */ 7747c478bd9Sstevel@tonic-gate 775*c9431fa1Sahl ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 776*c9431fa1Sahl z_streamp source)); 777*c9431fa1Sahl /* 778*c9431fa1Sahl Sets the destination stream as a complete copy of the source stream. 779*c9431fa1Sahl 780*c9431fa1Sahl This function can be useful when randomly accessing a large stream. The 781*c9431fa1Sahl first pass through the stream can periodically record the inflate state, 782*c9431fa1Sahl allowing restarting inflate at those points when randomly accessing the 783*c9431fa1Sahl stream. 784*c9431fa1Sahl 785*c9431fa1Sahl inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 786*c9431fa1Sahl enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 787*c9431fa1Sahl (such as zalloc being NULL). msg is left unchanged in both source and 788*c9431fa1Sahl destination. 789*c9431fa1Sahl */ 790*c9431fa1Sahl 7917c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 7927c478bd9Sstevel@tonic-gate /* 7937c478bd9Sstevel@tonic-gate This function is equivalent to inflateEnd followed by inflateInit, 7947c478bd9Sstevel@tonic-gate but does not free and reallocate all the internal decompression state. 7957c478bd9Sstevel@tonic-gate The stream will keep attributes that may have been set by inflateInit2. 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 7987c478bd9Sstevel@tonic-gate stream state was inconsistent (such as zalloc or state being NULL). 7997c478bd9Sstevel@tonic-gate */ 8007c478bd9Sstevel@tonic-gate 801*c9431fa1Sahl ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 802*c9431fa1Sahl int bits, 803*c9431fa1Sahl int value)); 804*c9431fa1Sahl /* 805*c9431fa1Sahl This function inserts bits in the inflate input stream. The intent is 806*c9431fa1Sahl that this function is used to start inflating at a bit position in the 807*c9431fa1Sahl middle of a byte. The provided bits will be used before any bytes are used 808*c9431fa1Sahl from next_in. This function should only be used with raw inflate, and 809*c9431fa1Sahl should be used before the first inflate() call after inflateInit2() or 810*c9431fa1Sahl inflateReset(). bits must be less than or equal to 16, and that many of the 811*c9431fa1Sahl least significant bits of value will be inserted in the input. 812*c9431fa1Sahl 813*c9431fa1Sahl inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 814*c9431fa1Sahl stream state was inconsistent. 815*c9431fa1Sahl */ 816*c9431fa1Sahl 817*c9431fa1Sahl ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 818*c9431fa1Sahl gz_headerp head)); 819*c9431fa1Sahl /* 820*c9431fa1Sahl inflateGetHeader() requests that gzip header information be stored in the 821*c9431fa1Sahl provided gz_header structure. inflateGetHeader() may be called after 822*c9431fa1Sahl inflateInit2() or inflateReset(), and before the first call of inflate(). 823*c9431fa1Sahl As inflate() processes the gzip stream, head->done is zero until the header 824*c9431fa1Sahl is completed, at which time head->done is set to one. If a zlib stream is 825*c9431fa1Sahl being decoded, then head->done is set to -1 to indicate that there will be 826*c9431fa1Sahl no gzip header information forthcoming. Note that Z_BLOCK can be used to 827*c9431fa1Sahl force inflate() to return immediately after header processing is complete 828*c9431fa1Sahl and before any actual data is decompressed. 829*c9431fa1Sahl 830*c9431fa1Sahl The text, time, xflags, and os fields are filled in with the gzip header 831*c9431fa1Sahl contents. hcrc is set to true if there is a header CRC. (The header CRC 832*c9431fa1Sahl was valid if done is set to one.) If extra is not Z_NULL, then extra_max 833*c9431fa1Sahl contains the maximum number of bytes to write to extra. Once done is true, 834*c9431fa1Sahl extra_len contains the actual extra field length, and extra contains the 835*c9431fa1Sahl extra field, or that field truncated if extra_max is less than extra_len. 836*c9431fa1Sahl If name is not Z_NULL, then up to name_max characters are written there, 837*c9431fa1Sahl terminated with a zero unless the length is greater than name_max. If 838*c9431fa1Sahl comment is not Z_NULL, then up to comm_max characters are written there, 839*c9431fa1Sahl terminated with a zero unless the length is greater than comm_max. When 840*c9431fa1Sahl any of extra, name, or comment are not Z_NULL and the respective field is 841*c9431fa1Sahl not present in the header, then that field is set to Z_NULL to signal its 842*c9431fa1Sahl absence. This allows the use of deflateSetHeader() with the returned 843*c9431fa1Sahl structure to duplicate the header. However if those fields are set to 844*c9431fa1Sahl allocated memory, then the application will need to save those pointers 845*c9431fa1Sahl elsewhere so that they can be eventually freed. 846*c9431fa1Sahl 847*c9431fa1Sahl If inflateGetHeader is not used, then the header information is simply 848*c9431fa1Sahl discarded. The header is always checked for validity, including the header 849*c9431fa1Sahl CRC if present. inflateReset() will reset the process to discard the header 850*c9431fa1Sahl information. The application would need to call inflateGetHeader() again to 851*c9431fa1Sahl retrieve the header from the next gzip stream. 852*c9431fa1Sahl 853*c9431fa1Sahl inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 854*c9431fa1Sahl stream state was inconsistent. 855*c9431fa1Sahl */ 856*c9431fa1Sahl 857*c9431fa1Sahl /* 858*c9431fa1Sahl ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 859*c9431fa1Sahl unsigned char FAR *window)); 860*c9431fa1Sahl 861*c9431fa1Sahl Initialize the internal stream state for decompression using inflateBack() 862*c9431fa1Sahl calls. The fields zalloc, zfree and opaque in strm must be initialized 863*c9431fa1Sahl before the call. If zalloc and zfree are Z_NULL, then the default library- 864*c9431fa1Sahl derived memory allocation routines are used. windowBits is the base two 865*c9431fa1Sahl logarithm of the window size, in the range 8..15. window is a caller 866*c9431fa1Sahl supplied buffer of that size. Except for special applications where it is 867*c9431fa1Sahl assured that deflate was used with small window sizes, windowBits must be 15 868*c9431fa1Sahl and a 32K byte window must be supplied to be able to decompress general 869*c9431fa1Sahl deflate streams. 870*c9431fa1Sahl 871*c9431fa1Sahl See inflateBack() for the usage of these routines. 872*c9431fa1Sahl 873*c9431fa1Sahl inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 874*c9431fa1Sahl the paramaters are invalid, Z_MEM_ERROR if the internal state could not 875*c9431fa1Sahl be allocated, or Z_VERSION_ERROR if the version of the library does not 876*c9431fa1Sahl match the version of the header file. 877*c9431fa1Sahl */ 878*c9431fa1Sahl 879*c9431fa1Sahl typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 880*c9431fa1Sahl typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 881*c9431fa1Sahl 882*c9431fa1Sahl ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 883*c9431fa1Sahl in_func in, void FAR *in_desc, 884*c9431fa1Sahl out_func out, void FAR *out_desc)); 885*c9431fa1Sahl /* 886*c9431fa1Sahl inflateBack() does a raw inflate with a single call using a call-back 887*c9431fa1Sahl interface for input and output. This is more efficient than inflate() for 888*c9431fa1Sahl file i/o applications in that it avoids copying between the output and the 889*c9431fa1Sahl sliding window by simply making the window itself the output buffer. This 890*c9431fa1Sahl function trusts the application to not change the output buffer passed by 891*c9431fa1Sahl the output function, at least until inflateBack() returns. 892*c9431fa1Sahl 893*c9431fa1Sahl inflateBackInit() must be called first to allocate the internal state 894*c9431fa1Sahl and to initialize the state with the user-provided window buffer. 895*c9431fa1Sahl inflateBack() may then be used multiple times to inflate a complete, raw 896*c9431fa1Sahl deflate stream with each call. inflateBackEnd() is then called to free 897*c9431fa1Sahl the allocated state. 898*c9431fa1Sahl 899*c9431fa1Sahl A raw deflate stream is one with no zlib or gzip header or trailer. 900*c9431fa1Sahl This routine would normally be used in a utility that reads zip or gzip 901*c9431fa1Sahl files and writes out uncompressed files. The utility would decode the 902*c9431fa1Sahl header and process the trailer on its own, hence this routine expects 903*c9431fa1Sahl only the raw deflate stream to decompress. This is different from the 904*c9431fa1Sahl normal behavior of inflate(), which expects either a zlib or gzip header and 905*c9431fa1Sahl trailer around the deflate stream. 906*c9431fa1Sahl 907*c9431fa1Sahl inflateBack() uses two subroutines supplied by the caller that are then 908*c9431fa1Sahl called by inflateBack() for input and output. inflateBack() calls those 909*c9431fa1Sahl routines until it reads a complete deflate stream and writes out all of the 910*c9431fa1Sahl uncompressed data, or until it encounters an error. The function's 911*c9431fa1Sahl parameters and return types are defined above in the in_func and out_func 912*c9431fa1Sahl typedefs. inflateBack() will call in(in_desc, &buf) which should return the 913*c9431fa1Sahl number of bytes of provided input, and a pointer to that input in buf. If 914*c9431fa1Sahl there is no input available, in() must return zero--buf is ignored in that 915*c9431fa1Sahl case--and inflateBack() will return a buffer error. inflateBack() will call 916*c9431fa1Sahl out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 917*c9431fa1Sahl should return zero on success, or non-zero on failure. If out() returns 918*c9431fa1Sahl non-zero, inflateBack() will return with an error. Neither in() nor out() 919*c9431fa1Sahl are permitted to change the contents of the window provided to 920*c9431fa1Sahl inflateBackInit(), which is also the buffer that out() uses to write from. 921*c9431fa1Sahl The length written by out() will be at most the window size. Any non-zero 922*c9431fa1Sahl amount of input may be provided by in(). 923*c9431fa1Sahl 924*c9431fa1Sahl For convenience, inflateBack() can be provided input on the first call by 925*c9431fa1Sahl setting strm->next_in and strm->avail_in. If that input is exhausted, then 926*c9431fa1Sahl in() will be called. Therefore strm->next_in must be initialized before 927*c9431fa1Sahl calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 928*c9431fa1Sahl immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 929*c9431fa1Sahl must also be initialized, and then if strm->avail_in is not zero, input will 930*c9431fa1Sahl initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 931*c9431fa1Sahl 932*c9431fa1Sahl The in_desc and out_desc parameters of inflateBack() is passed as the 933*c9431fa1Sahl first parameter of in() and out() respectively when they are called. These 934*c9431fa1Sahl descriptors can be optionally used to pass any information that the caller- 935*c9431fa1Sahl supplied in() and out() functions need to do their job. 936*c9431fa1Sahl 937*c9431fa1Sahl On return, inflateBack() will set strm->next_in and strm->avail_in to 938*c9431fa1Sahl pass back any unused input that was provided by the last in() call. The 939*c9431fa1Sahl return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 940*c9431fa1Sahl if in() or out() returned an error, Z_DATA_ERROR if there was a format 941*c9431fa1Sahl error in the deflate stream (in which case strm->msg is set to indicate the 942*c9431fa1Sahl nature of the error), or Z_STREAM_ERROR if the stream was not properly 943*c9431fa1Sahl initialized. In the case of Z_BUF_ERROR, an input or output error can be 944*c9431fa1Sahl distinguished using strm->next_in which will be Z_NULL only if in() returned 945*c9431fa1Sahl an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to 946*c9431fa1Sahl out() returning non-zero. (in() will always be called before out(), so 947*c9431fa1Sahl strm->next_in is assured to be defined if out() returns non-zero.) Note 948*c9431fa1Sahl that inflateBack() cannot return Z_OK. 949*c9431fa1Sahl */ 950*c9431fa1Sahl 951*c9431fa1Sahl ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 952*c9431fa1Sahl /* 953*c9431fa1Sahl All memory allocated by inflateBackInit() is freed. 954*c9431fa1Sahl 955*c9431fa1Sahl inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 956*c9431fa1Sahl state was inconsistent. 957*c9431fa1Sahl */ 958*c9431fa1Sahl 959*c9431fa1Sahl ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 960*c9431fa1Sahl /* Return flags indicating compile-time options. 961*c9431fa1Sahl 962*c9431fa1Sahl Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 963*c9431fa1Sahl 1.0: size of uInt 964*c9431fa1Sahl 3.2: size of uLong 965*c9431fa1Sahl 5.4: size of voidpf (pointer) 966*c9431fa1Sahl 7.6: size of z_off_t 967*c9431fa1Sahl 968*c9431fa1Sahl Compiler, assembler, and debug options: 969*c9431fa1Sahl 8: DEBUG 970*c9431fa1Sahl 9: ASMV or ASMINF -- use ASM code 971*c9431fa1Sahl 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 972*c9431fa1Sahl 11: 0 (reserved) 973*c9431fa1Sahl 974*c9431fa1Sahl One-time table building (smaller code, but not thread-safe if true): 975*c9431fa1Sahl 12: BUILDFIXED -- build static block decoding tables when needed 976*c9431fa1Sahl 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 977*c9431fa1Sahl 14,15: 0 (reserved) 978*c9431fa1Sahl 979*c9431fa1Sahl Library content (indicates missing functionality): 980*c9431fa1Sahl 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 981*c9431fa1Sahl deflate code when not needed) 982*c9431fa1Sahl 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 983*c9431fa1Sahl and decode gzip streams (to avoid linking crc code) 984*c9431fa1Sahl 18-19: 0 (reserved) 985*c9431fa1Sahl 986*c9431fa1Sahl Operation variations (changes in library functionality): 987*c9431fa1Sahl 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 988*c9431fa1Sahl 21: FASTEST -- deflate algorithm with only one, lowest compression level 989*c9431fa1Sahl 22,23: 0 (reserved) 990*c9431fa1Sahl 991*c9431fa1Sahl The sprintf variant used by gzprintf (zero is best): 992*c9431fa1Sahl 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 993*c9431fa1Sahl 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 994*c9431fa1Sahl 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 995*c9431fa1Sahl 996*c9431fa1Sahl Remainder: 997*c9431fa1Sahl 27-31: 0 (reserved) 998*c9431fa1Sahl */ 999*c9431fa1Sahl 1000*c9431fa1Sahl 1001*c9431fa1Sahl /* utility functions */ 1002*c9431fa1Sahl 1003*c9431fa1Sahl /* 1004*c9431fa1Sahl The following utility functions are implemented on top of the 1005*c9431fa1Sahl basic stream-oriented functions. To simplify the interface, some 1006*c9431fa1Sahl default options are assumed (compression level and memory usage, 1007*c9431fa1Sahl standard memory allocation functions). The source code of these 1008*c9431fa1Sahl utility functions can easily be modified if you need special options. 1009*c9431fa1Sahl */ 1010*c9431fa1Sahl 1011*c9431fa1Sahl ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 1012*c9431fa1Sahl const Bytef *source, uLong sourceLen)); 1013*c9431fa1Sahl /* 1014*c9431fa1Sahl Compresses the source buffer into the destination buffer. sourceLen is 1015*c9431fa1Sahl the byte length of the source buffer. Upon entry, destLen is the total 1016*c9431fa1Sahl size of the destination buffer, which must be at least the value returned 1017*c9431fa1Sahl by compressBound(sourceLen). Upon exit, destLen is the actual size of the 1018*c9431fa1Sahl compressed buffer. 1019*c9431fa1Sahl This function can be used to compress a whole file at once if the 1020*c9431fa1Sahl input file is mmap'ed. 1021*c9431fa1Sahl compress returns Z_OK if success, Z_MEM_ERROR if there was not 1022*c9431fa1Sahl enough memory, Z_BUF_ERROR if there was not enough room in the output 1023*c9431fa1Sahl buffer. 1024*c9431fa1Sahl */ 1025*c9431fa1Sahl 1026*c9431fa1Sahl ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 1027*c9431fa1Sahl const Bytef *source, uLong sourceLen, 1028*c9431fa1Sahl int level)); 1029*c9431fa1Sahl /* 1030*c9431fa1Sahl Compresses the source buffer into the destination buffer. The level 1031*c9431fa1Sahl parameter has the same meaning as in deflateInit. sourceLen is the byte 1032*c9431fa1Sahl length of the source buffer. Upon entry, destLen is the total size of the 1033*c9431fa1Sahl destination buffer, which must be at least the value returned by 1034*c9431fa1Sahl compressBound(sourceLen). Upon exit, destLen is the actual size of the 1035*c9431fa1Sahl compressed buffer. 1036*c9431fa1Sahl 1037*c9431fa1Sahl compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 1038*c9431fa1Sahl memory, Z_BUF_ERROR if there was not enough room in the output buffer, 1039*c9431fa1Sahl Z_STREAM_ERROR if the level parameter is invalid. 1040*c9431fa1Sahl */ 1041*c9431fa1Sahl 1042*c9431fa1Sahl ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 1043*c9431fa1Sahl /* 1044*c9431fa1Sahl compressBound() returns an upper bound on the compressed size after 1045*c9431fa1Sahl compress() or compress2() on sourceLen bytes. It would be used before 1046*c9431fa1Sahl a compress() or compress2() call to allocate the destination buffer. 1047*c9431fa1Sahl */ 1048*c9431fa1Sahl 1049*c9431fa1Sahl ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 1050*c9431fa1Sahl const Bytef *source, uLong sourceLen)); 1051*c9431fa1Sahl /* 1052*c9431fa1Sahl Decompresses the source buffer into the destination buffer. sourceLen is 1053*c9431fa1Sahl the byte length of the source buffer. Upon entry, destLen is the total 1054*c9431fa1Sahl size of the destination buffer, which must be large enough to hold the 1055*c9431fa1Sahl entire uncompressed data. (The size of the uncompressed data must have 1056*c9431fa1Sahl been saved previously by the compressor and transmitted to the decompressor 1057*c9431fa1Sahl by some mechanism outside the scope of this compression library.) 1058*c9431fa1Sahl Upon exit, destLen is the actual size of the compressed buffer. 1059*c9431fa1Sahl This function can be used to decompress a whole file at once if the 1060*c9431fa1Sahl input file is mmap'ed. 1061*c9431fa1Sahl 1062*c9431fa1Sahl uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1063*c9431fa1Sahl enough memory, Z_BUF_ERROR if there was not enough room in the output 1064*c9431fa1Sahl buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. 1065*c9431fa1Sahl */ 1066*c9431fa1Sahl 1067*c9431fa1Sahl 1068*c9431fa1Sahl typedef voidp gzFile; 1069*c9431fa1Sahl 1070*c9431fa1Sahl ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 1071*c9431fa1Sahl /* 1072*c9431fa1Sahl Opens a gzip (.gz) file for reading or writing. The mode parameter 1073*c9431fa1Sahl is as in fopen ("rb" or "wb") but can also include a compression level 1074*c9431fa1Sahl ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 1075*c9431fa1Sahl Huffman only compression as in "wb1h", or 'R' for run-length encoding 1076*c9431fa1Sahl as in "wb1R". (See the description of deflateInit2 for more information 1077*c9431fa1Sahl about the strategy parameter.) 1078*c9431fa1Sahl 1079*c9431fa1Sahl gzopen can be used to read a file which is not in gzip format; in this 1080*c9431fa1Sahl case gzread will directly read from the file without decompression. 1081*c9431fa1Sahl 1082*c9431fa1Sahl gzopen returns NULL if the file could not be opened or if there was 1083*c9431fa1Sahl insufficient memory to allocate the (de)compression state; errno 1084*c9431fa1Sahl can be checked to distinguish the two cases (if errno is zero, the 1085*c9431fa1Sahl zlib error is Z_MEM_ERROR). */ 1086*c9431fa1Sahl 1087*c9431fa1Sahl ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 1088*c9431fa1Sahl /* 1089*c9431fa1Sahl gzdopen() associates a gzFile with the file descriptor fd. File 1090*c9431fa1Sahl descriptors are obtained from calls like open, dup, creat, pipe or 1091*c9431fa1Sahl fileno (in the file has been previously opened with fopen). 1092*c9431fa1Sahl The mode parameter is as in gzopen. 1093*c9431fa1Sahl The next call of gzclose on the returned gzFile will also close the 1094*c9431fa1Sahl file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 1095*c9431fa1Sahl descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 1096*c9431fa1Sahl gzdopen returns NULL if there was insufficient memory to allocate 1097*c9431fa1Sahl the (de)compression state. 1098*c9431fa1Sahl */ 1099*c9431fa1Sahl 1100*c9431fa1Sahl ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 1101*c9431fa1Sahl /* 1102*c9431fa1Sahl Dynamically update the compression level or strategy. See the description 1103*c9431fa1Sahl of deflateInit2 for the meaning of these parameters. 1104*c9431fa1Sahl gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 1105*c9431fa1Sahl opened for writing. 1106*c9431fa1Sahl */ 1107*c9431fa1Sahl 1108*c9431fa1Sahl ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 1109*c9431fa1Sahl /* 1110*c9431fa1Sahl Reads the given number of uncompressed bytes from the compressed file. 1111*c9431fa1Sahl If the input file was not in gzip format, gzread copies the given number 1112*c9431fa1Sahl of bytes into the buffer. 1113*c9431fa1Sahl gzread returns the number of uncompressed bytes actually read (0 for 1114*c9431fa1Sahl end of file, -1 for error). */ 1115*c9431fa1Sahl 1116*c9431fa1Sahl ZEXTERN int ZEXPORT gzwrite OF((gzFile file, 1117*c9431fa1Sahl voidpc buf, unsigned len)); 1118*c9431fa1Sahl /* 1119*c9431fa1Sahl Writes the given number of uncompressed bytes into the compressed file. 1120*c9431fa1Sahl gzwrite returns the number of uncompressed bytes actually written 1121*c9431fa1Sahl (0 in case of error). 1122*c9431fa1Sahl */ 1123*c9431fa1Sahl 1124*c9431fa1Sahl ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 1125*c9431fa1Sahl /* 1126*c9431fa1Sahl Converts, formats, and writes the args to the compressed file under 1127*c9431fa1Sahl control of the format string, as in fprintf. gzprintf returns the number of 1128*c9431fa1Sahl uncompressed bytes actually written (0 in case of error). The number of 1129*c9431fa1Sahl uncompressed bytes written is limited to 4095. The caller should assure that 1130*c9431fa1Sahl this limit is not exceeded. If it is exceeded, then gzprintf() will return 1131*c9431fa1Sahl return an error (0) with nothing written. In this case, there may also be a 1132*c9431fa1Sahl buffer overflow with unpredictable consequences, which is possible only if 1133*c9431fa1Sahl zlib was compiled with the insecure functions sprintf() or vsprintf() 1134*c9431fa1Sahl because the secure snprintf() or vsnprintf() functions were not available. 1135*c9431fa1Sahl */ 1136*c9431fa1Sahl 1137*c9431fa1Sahl ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 1138*c9431fa1Sahl /* 1139*c9431fa1Sahl Writes the given null-terminated string to the compressed file, excluding 1140*c9431fa1Sahl the terminating null character. 1141*c9431fa1Sahl gzputs returns the number of characters written, or -1 in case of error. 1142*c9431fa1Sahl */ 1143*c9431fa1Sahl 1144*c9431fa1Sahl ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 1145*c9431fa1Sahl /* 1146*c9431fa1Sahl Reads bytes from the compressed file until len-1 characters are read, or 1147*c9431fa1Sahl a newline character is read and transferred to buf, or an end-of-file 1148*c9431fa1Sahl condition is encountered. The string is then terminated with a null 1149*c9431fa1Sahl character. 1150*c9431fa1Sahl gzgets returns buf, or Z_NULL in case of error. 1151*c9431fa1Sahl */ 1152*c9431fa1Sahl 1153*c9431fa1Sahl ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 1154*c9431fa1Sahl /* 1155*c9431fa1Sahl Writes c, converted to an unsigned char, into the compressed file. 1156*c9431fa1Sahl gzputc returns the value that was written, or -1 in case of error. 1157*c9431fa1Sahl */ 1158*c9431fa1Sahl 1159*c9431fa1Sahl ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 1160*c9431fa1Sahl /* 1161*c9431fa1Sahl Reads one byte from the compressed file. gzgetc returns this byte 1162*c9431fa1Sahl or -1 in case of end of file or error. 1163*c9431fa1Sahl */ 1164*c9431fa1Sahl 1165*c9431fa1Sahl ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 1166*c9431fa1Sahl /* 1167*c9431fa1Sahl Push one character back onto the stream to be read again later. 1168*c9431fa1Sahl Only one character of push-back is allowed. gzungetc() returns the 1169*c9431fa1Sahl character pushed, or -1 on failure. gzungetc() will fail if a 1170*c9431fa1Sahl character has been pushed but not read yet, or if c is -1. The pushed 1171*c9431fa1Sahl character will be discarded if the stream is repositioned with gzseek() 1172*c9431fa1Sahl or gzrewind(). 1173*c9431fa1Sahl */ 1174*c9431fa1Sahl 1175*c9431fa1Sahl ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 1176*c9431fa1Sahl /* 1177*c9431fa1Sahl Flushes all pending output into the compressed file. The parameter 1178*c9431fa1Sahl flush is as in the deflate() function. The return value is the zlib 1179*c9431fa1Sahl error number (see function gzerror below). gzflush returns Z_OK if 1180*c9431fa1Sahl the flush parameter is Z_FINISH and all output could be flushed. 1181*c9431fa1Sahl gzflush should be called only when strictly necessary because it can 1182*c9431fa1Sahl degrade compression. 1183*c9431fa1Sahl */ 1184*c9431fa1Sahl 1185*c9431fa1Sahl ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 1186*c9431fa1Sahl z_off_t offset, int whence)); 1187*c9431fa1Sahl /* 1188*c9431fa1Sahl Sets the starting position for the next gzread or gzwrite on the 1189*c9431fa1Sahl given compressed file. The offset represents a number of bytes in the 1190*c9431fa1Sahl uncompressed data stream. The whence parameter is defined as in lseek(2); 1191*c9431fa1Sahl the value SEEK_END is not supported. 1192*c9431fa1Sahl If the file is opened for reading, this function is emulated but can be 1193*c9431fa1Sahl extremely slow. If the file is opened for writing, only forward seeks are 1194*c9431fa1Sahl supported; gzseek then compresses a sequence of zeroes up to the new 1195*c9431fa1Sahl starting position. 1196*c9431fa1Sahl 1197*c9431fa1Sahl gzseek returns the resulting offset location as measured in bytes from 1198*c9431fa1Sahl the beginning of the uncompressed stream, or -1 in case of error, in 1199*c9431fa1Sahl particular if the file is opened for writing and the new starting position 1200*c9431fa1Sahl would be before the current position. 1201*c9431fa1Sahl */ 1202*c9431fa1Sahl 1203*c9431fa1Sahl ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 1204*c9431fa1Sahl /* 1205*c9431fa1Sahl Rewinds the given file. This function is supported only for reading. 1206*c9431fa1Sahl 1207*c9431fa1Sahl gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 1208*c9431fa1Sahl */ 1209*c9431fa1Sahl 1210*c9431fa1Sahl ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 1211*c9431fa1Sahl /* 1212*c9431fa1Sahl Returns the starting position for the next gzread or gzwrite on the 1213*c9431fa1Sahl given compressed file. This position represents a number of bytes in the 1214*c9431fa1Sahl uncompressed data stream. 1215*c9431fa1Sahl 1216*c9431fa1Sahl gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 1217*c9431fa1Sahl */ 1218*c9431fa1Sahl 1219*c9431fa1Sahl ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 1220*c9431fa1Sahl /* 1221*c9431fa1Sahl Returns 1 when EOF has previously been detected reading the given 1222*c9431fa1Sahl input stream, otherwise zero. 1223*c9431fa1Sahl */ 1224*c9431fa1Sahl 1225*c9431fa1Sahl ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 1226*c9431fa1Sahl /* 1227*c9431fa1Sahl Returns 1 if file is being read directly without decompression, otherwise 1228*c9431fa1Sahl zero. 1229*c9431fa1Sahl */ 1230*c9431fa1Sahl 1231*c9431fa1Sahl ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 1232*c9431fa1Sahl /* 1233*c9431fa1Sahl Flushes all pending output if necessary, closes the compressed file 1234*c9431fa1Sahl and deallocates all the (de)compression state. The return value is the zlib 1235*c9431fa1Sahl error number (see function gzerror below). 1236*c9431fa1Sahl */ 1237*c9431fa1Sahl 1238*c9431fa1Sahl ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 1239*c9431fa1Sahl /* 1240*c9431fa1Sahl Returns the error message for the last error which occurred on the 1241*c9431fa1Sahl given compressed file. errnum is set to zlib error number. If an 1242*c9431fa1Sahl error occurred in the file system and not in the compression library, 1243*c9431fa1Sahl errnum is set to Z_ERRNO and the application may consult errno 1244*c9431fa1Sahl to get the exact error code. 1245*c9431fa1Sahl */ 1246*c9431fa1Sahl 1247*c9431fa1Sahl ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 1248*c9431fa1Sahl /* 1249*c9431fa1Sahl Clears the error and end-of-file flags for file. This is analogous to the 1250*c9431fa1Sahl clearerr() function in stdio. This is useful for continuing to read a gzip 1251*c9431fa1Sahl file that is being written concurrently. 1252*c9431fa1Sahl */ 1253*c9431fa1Sahl 12547c478bd9Sstevel@tonic-gate /* checksum functions */ 12557c478bd9Sstevel@tonic-gate 12567c478bd9Sstevel@tonic-gate /* 12577c478bd9Sstevel@tonic-gate These functions are not related to compression but are exported 12587c478bd9Sstevel@tonic-gate anyway because they might be useful in applications using the 12597c478bd9Sstevel@tonic-gate compression library. 12607c478bd9Sstevel@tonic-gate */ 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 12637c478bd9Sstevel@tonic-gate /* 12647c478bd9Sstevel@tonic-gate Update a running Adler-32 checksum with the bytes buf[0..len-1] and 12657c478bd9Sstevel@tonic-gate return the updated checksum. If buf is NULL, this function returns 12667c478bd9Sstevel@tonic-gate the required initial value for the checksum. 12677c478bd9Sstevel@tonic-gate An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 12687c478bd9Sstevel@tonic-gate much faster. Usage example: 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate uLong adler = adler32(0L, Z_NULL, 0); 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate while (read_buffer(buffer, length) != EOF) { 12737c478bd9Sstevel@tonic-gate adler = adler32(adler, buffer, length); 12747c478bd9Sstevel@tonic-gate } 12757c478bd9Sstevel@tonic-gate if (adler != original_adler) error(); 12767c478bd9Sstevel@tonic-gate */ 12777c478bd9Sstevel@tonic-gate 1278*c9431fa1Sahl ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 1279*c9431fa1Sahl z_off_t len2)); 1280*c9431fa1Sahl /* 1281*c9431fa1Sahl Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 1282*c9431fa1Sahl and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 1283*c9431fa1Sahl each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 1284*c9431fa1Sahl seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. 1285*c9431fa1Sahl */ 1286*c9431fa1Sahl 12877c478bd9Sstevel@tonic-gate ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 12887c478bd9Sstevel@tonic-gate /* 1289*c9431fa1Sahl Update a running CRC-32 with the bytes buf[0..len-1] and return the 1290*c9431fa1Sahl updated CRC-32. If buf is NULL, this function returns the required initial 1291*c9431fa1Sahl value for the for the crc. Pre- and post-conditioning (one's complement) is 1292*c9431fa1Sahl performed within this function so it shouldn't be done by the application. 12937c478bd9Sstevel@tonic-gate Usage example: 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate uLong crc = crc32(0L, Z_NULL, 0); 12967c478bd9Sstevel@tonic-gate 12977c478bd9Sstevel@tonic-gate while (read_buffer(buffer, length) != EOF) { 12987c478bd9Sstevel@tonic-gate crc = crc32(crc, buffer, length); 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate if (crc != original_crc) error(); 13017c478bd9Sstevel@tonic-gate */ 13027c478bd9Sstevel@tonic-gate 1303*c9431fa1Sahl ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 1304*c9431fa1Sahl 1305*c9431fa1Sahl /* 1306*c9431fa1Sahl Combine two CRC-32 check values into one. For two sequences of bytes, 1307*c9431fa1Sahl seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 1308*c9431fa1Sahl calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 1309*c9431fa1Sahl check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 1310*c9431fa1Sahl len2. 1311*c9431fa1Sahl */ 1312*c9431fa1Sahl 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate /* various hacks, don't look :) */ 13157c478bd9Sstevel@tonic-gate 13167c478bd9Sstevel@tonic-gate /* deflateInit and inflateInit are macros to allow checking the zlib version 13177c478bd9Sstevel@tonic-gate * and the compiler's view of z_stream: 13187c478bd9Sstevel@tonic-gate */ 13197c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 13207c478bd9Sstevel@tonic-gate const char *version, int stream_size)); 13217c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 13227c478bd9Sstevel@tonic-gate const char *version, int stream_size)); 13237c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 13247c478bd9Sstevel@tonic-gate int windowBits, int memLevel, 13257c478bd9Sstevel@tonic-gate int strategy, const char *version, 13267c478bd9Sstevel@tonic-gate int stream_size)); 13277c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 13287c478bd9Sstevel@tonic-gate const char *version, int stream_size)); 1329*c9431fa1Sahl ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 1330*c9431fa1Sahl unsigned char FAR *window, 1331*c9431fa1Sahl const char *version, 1332*c9431fa1Sahl int stream_size)); 13337c478bd9Sstevel@tonic-gate #define deflateInit(strm, level) \ 13347c478bd9Sstevel@tonic-gate deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 13357c478bd9Sstevel@tonic-gate #define inflateInit(strm) \ 13367c478bd9Sstevel@tonic-gate inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 13377c478bd9Sstevel@tonic-gate #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 13387c478bd9Sstevel@tonic-gate deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 13397c478bd9Sstevel@tonic-gate (strategy), ZLIB_VERSION, sizeof(z_stream)) 13407c478bd9Sstevel@tonic-gate #define inflateInit2(strm, windowBits) \ 13417c478bd9Sstevel@tonic-gate inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 1342*c9431fa1Sahl #define inflateBackInit(strm, windowBits, window) \ 1343*c9431fa1Sahl inflateBackInit_((strm), (windowBits), (window), \ 1344*c9431fa1Sahl ZLIB_VERSION, sizeof(z_stream)) 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate 1347*c9431fa1Sahl #if !defined(_ZUTIL_H) && !defined(NO_DUMMY_DECL) 1348*c9431fa1Sahl struct internal_state {int dummy;}; /* hack for buggy compilers */ 1349*c9431fa1Sahl #endif 1350*c9431fa1Sahl 1351*c9431fa1Sahl ZEXTERN const char * ZEXPORT zError OF((int)); 13527c478bd9Sstevel@tonic-gate ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); 13537c478bd9Sstevel@tonic-gate ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); 13547c478bd9Sstevel@tonic-gate 13557c478bd9Sstevel@tonic-gate #ifdef __cplusplus 13567c478bd9Sstevel@tonic-gate } 13577c478bd9Sstevel@tonic-gate #endif 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate #endif /* _ZLIB_H */ 1360