17777dab0Sopenharmony_ci/* zlib.h -- interface of the 'zlib' general purpose compression library 27777dab0Sopenharmony_ci version 1.3.1, January 22nd, 2024 37777dab0Sopenharmony_ci 47777dab0Sopenharmony_ci Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler 57777dab0Sopenharmony_ci 67777dab0Sopenharmony_ci This software is provided 'as-is', without any express or implied 77777dab0Sopenharmony_ci warranty. In no event will the authors be held liable for any damages 87777dab0Sopenharmony_ci arising from the use of this software. 97777dab0Sopenharmony_ci 107777dab0Sopenharmony_ci Permission is granted to anyone to use this software for any purpose, 117777dab0Sopenharmony_ci including commercial applications, and to alter it and redistribute it 127777dab0Sopenharmony_ci freely, subject to the following restrictions: 137777dab0Sopenharmony_ci 147777dab0Sopenharmony_ci 1. The origin of this software must not be misrepresented; you must not 157777dab0Sopenharmony_ci claim that you wrote the original software. If you use this software 167777dab0Sopenharmony_ci in a product, an acknowledgment in the product documentation would be 177777dab0Sopenharmony_ci appreciated but is not required. 187777dab0Sopenharmony_ci 2. Altered source versions must be plainly marked as such, and must not be 197777dab0Sopenharmony_ci misrepresented as being the original software. 207777dab0Sopenharmony_ci 3. This notice may not be removed or altered from any source distribution. 217777dab0Sopenharmony_ci 227777dab0Sopenharmony_ci Jean-loup Gailly Mark Adler 237777dab0Sopenharmony_ci jloup@gzip.org madler@alumni.caltech.edu 247777dab0Sopenharmony_ci 257777dab0Sopenharmony_ci 267777dab0Sopenharmony_ci The data format used by the zlib library is described by RFCs (Request for 277777dab0Sopenharmony_ci Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 287777dab0Sopenharmony_ci (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). 297777dab0Sopenharmony_ci*/ 307777dab0Sopenharmony_ci 317777dab0Sopenharmony_ci#ifndef ZLIB_H 327777dab0Sopenharmony_ci#define ZLIB_H 337777dab0Sopenharmony_ci 347777dab0Sopenharmony_ci#include "zconf.h" 357777dab0Sopenharmony_ci 367777dab0Sopenharmony_ci#ifdef __cplusplus 377777dab0Sopenharmony_ciextern "C" { 387777dab0Sopenharmony_ci#endif 397777dab0Sopenharmony_ci 407777dab0Sopenharmony_ci#define ZLIB_VERSION "1.3.1" 417777dab0Sopenharmony_ci#define ZLIB_VERNUM 0x1310 427777dab0Sopenharmony_ci#define ZLIB_VER_MAJOR 1 437777dab0Sopenharmony_ci#define ZLIB_VER_MINOR 3 447777dab0Sopenharmony_ci#define ZLIB_VER_REVISION 1 457777dab0Sopenharmony_ci#define ZLIB_VER_SUBREVISION 0 467777dab0Sopenharmony_ci 477777dab0Sopenharmony_ci/* 487777dab0Sopenharmony_ci The 'zlib' compression library provides in-memory compression and 497777dab0Sopenharmony_ci decompression functions, including integrity checks of the uncompressed data. 507777dab0Sopenharmony_ci This version of the library supports only one compression method (deflation) 517777dab0Sopenharmony_ci but other algorithms will be added later and will have the same stream 527777dab0Sopenharmony_ci interface. 537777dab0Sopenharmony_ci 547777dab0Sopenharmony_ci Compression can be done in a single step if the buffers are large enough, 557777dab0Sopenharmony_ci or can be done by repeated calls of the compression function. In the latter 567777dab0Sopenharmony_ci case, the application must provide more input and/or consume the output 577777dab0Sopenharmony_ci (providing more output space) before each call. 587777dab0Sopenharmony_ci 597777dab0Sopenharmony_ci The compressed data format used by default by the in-memory functions is 607777dab0Sopenharmony_ci the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 617777dab0Sopenharmony_ci around a deflate stream, which is itself documented in RFC 1951. 627777dab0Sopenharmony_ci 637777dab0Sopenharmony_ci The library also supports reading and writing files in gzip (.gz) format 647777dab0Sopenharmony_ci with an interface similar to that of stdio using the functions that start 657777dab0Sopenharmony_ci with "gz". The gzip format is different from the zlib format. gzip is a 667777dab0Sopenharmony_ci gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 677777dab0Sopenharmony_ci 687777dab0Sopenharmony_ci This library can optionally read and write gzip and raw deflate streams in 697777dab0Sopenharmony_ci memory as well. 707777dab0Sopenharmony_ci 717777dab0Sopenharmony_ci The zlib format was designed to be compact and fast for use in memory 727777dab0Sopenharmony_ci and on communications channels. The gzip format was designed for single- 737777dab0Sopenharmony_ci file compression on file systems, has a larger header than zlib to maintain 747777dab0Sopenharmony_ci directory information, and uses a different, slower check method than zlib. 757777dab0Sopenharmony_ci 767777dab0Sopenharmony_ci The library does not install any signal handler. The decoder checks 777777dab0Sopenharmony_ci the consistency of the compressed data, so the library should never crash 787777dab0Sopenharmony_ci even in the case of corrupted input. 797777dab0Sopenharmony_ci*/ 807777dab0Sopenharmony_ci 817777dab0Sopenharmony_citypedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); 827777dab0Sopenharmony_citypedef void (*free_func)(voidpf opaque, voidpf address); 837777dab0Sopenharmony_ci 847777dab0Sopenharmony_cistruct internal_state; 857777dab0Sopenharmony_ci 867777dab0Sopenharmony_citypedef struct z_stream_s { 877777dab0Sopenharmony_ci z_const Bytef *next_in; /* next input byte */ 887777dab0Sopenharmony_ci uInt avail_in; /* number of bytes available at next_in */ 897777dab0Sopenharmony_ci uLong total_in; /* total number of input bytes read so far */ 907777dab0Sopenharmony_ci 917777dab0Sopenharmony_ci Bytef *next_out; /* next output byte will go here */ 927777dab0Sopenharmony_ci uInt avail_out; /* remaining free space at next_out */ 937777dab0Sopenharmony_ci uLong total_out; /* total number of bytes output so far */ 947777dab0Sopenharmony_ci 957777dab0Sopenharmony_ci z_const char *msg; /* last error message, NULL if no error */ 967777dab0Sopenharmony_ci struct internal_state FAR *state; /* not visible by applications */ 977777dab0Sopenharmony_ci 987777dab0Sopenharmony_ci alloc_func zalloc; /* used to allocate the internal state */ 997777dab0Sopenharmony_ci free_func zfree; /* used to free the internal state */ 1007777dab0Sopenharmony_ci voidpf opaque; /* private data object passed to zalloc and zfree */ 1017777dab0Sopenharmony_ci 1027777dab0Sopenharmony_ci int data_type; /* best guess about the data type: binary or text 1037777dab0Sopenharmony_ci for deflate, or the decoding state for inflate */ 1047777dab0Sopenharmony_ci uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ 1057777dab0Sopenharmony_ci uLong reserved; /* reserved for future use */ 1067777dab0Sopenharmony_ci} z_stream; 1077777dab0Sopenharmony_ci 1087777dab0Sopenharmony_citypedef z_stream FAR *z_streamp; 1097777dab0Sopenharmony_ci 1107777dab0Sopenharmony_ci/* 1117777dab0Sopenharmony_ci gzip header information passed to and from zlib routines. See RFC 1952 1127777dab0Sopenharmony_ci for more details on the meanings of these fields. 1137777dab0Sopenharmony_ci*/ 1147777dab0Sopenharmony_citypedef struct gz_header_s { 1157777dab0Sopenharmony_ci int text; /* true if compressed data believed to be text */ 1167777dab0Sopenharmony_ci uLong time; /* modification time */ 1177777dab0Sopenharmony_ci int xflags; /* extra flags (not used when writing a gzip file) */ 1187777dab0Sopenharmony_ci int os; /* operating system */ 1197777dab0Sopenharmony_ci Bytef *extra; /* pointer to extra field or Z_NULL if none */ 1207777dab0Sopenharmony_ci uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 1217777dab0Sopenharmony_ci uInt extra_max; /* space at extra (only when reading header) */ 1227777dab0Sopenharmony_ci Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 1237777dab0Sopenharmony_ci uInt name_max; /* space at name (only when reading header) */ 1247777dab0Sopenharmony_ci Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 1257777dab0Sopenharmony_ci uInt comm_max; /* space at comment (only when reading header) */ 1267777dab0Sopenharmony_ci int hcrc; /* true if there was or will be a header crc */ 1277777dab0Sopenharmony_ci int done; /* true when done reading gzip header (not used 1287777dab0Sopenharmony_ci when writing a gzip file) */ 1297777dab0Sopenharmony_ci} gz_header; 1307777dab0Sopenharmony_ci 1317777dab0Sopenharmony_citypedef gz_header FAR *gz_headerp; 1327777dab0Sopenharmony_ci 1337777dab0Sopenharmony_ci/* 1347777dab0Sopenharmony_ci The application must update next_in and avail_in when avail_in has dropped 1357777dab0Sopenharmony_ci to zero. It must update next_out and avail_out when avail_out has dropped 1367777dab0Sopenharmony_ci to zero. The application must initialize zalloc, zfree and opaque before 1377777dab0Sopenharmony_ci calling the init function. All other fields are set by the compression 1387777dab0Sopenharmony_ci library and must not be updated by the application. 1397777dab0Sopenharmony_ci 1407777dab0Sopenharmony_ci The opaque value provided by the application will be passed as the first 1417777dab0Sopenharmony_ci parameter for calls of zalloc and zfree. This can be useful for custom 1427777dab0Sopenharmony_ci memory management. The compression library attaches no meaning to the 1437777dab0Sopenharmony_ci opaque value. 1447777dab0Sopenharmony_ci 1457777dab0Sopenharmony_ci zalloc must return Z_NULL if there is not enough memory for the object. 1467777dab0Sopenharmony_ci If zlib is used in a multi-threaded application, zalloc and zfree must be 1477777dab0Sopenharmony_ci thread safe. In that case, zlib is thread-safe. When zalloc and zfree are 1487777dab0Sopenharmony_ci Z_NULL on entry to the initialization function, they are set to internal 1497777dab0Sopenharmony_ci routines that use the standard library functions malloc() and free(). 1507777dab0Sopenharmony_ci 1517777dab0Sopenharmony_ci On 16-bit systems, the functions zalloc and zfree must be able to allocate 1527777dab0Sopenharmony_ci exactly 65536 bytes, but will not be required to allocate more than this if 1537777dab0Sopenharmony_ci the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers 1547777dab0Sopenharmony_ci returned by zalloc for objects of exactly 65536 bytes *must* have their 1557777dab0Sopenharmony_ci offset normalized to zero. The default allocation function provided by this 1567777dab0Sopenharmony_ci library ensures this (see zutil.c). To reduce memory requirements and avoid 1577777dab0Sopenharmony_ci any allocation of 64K objects, at the expense of compression ratio, compile 1587777dab0Sopenharmony_ci the library with -DMAX_WBITS=14 (see zconf.h). 1597777dab0Sopenharmony_ci 1607777dab0Sopenharmony_ci The fields total_in and total_out can be used for statistics or progress 1617777dab0Sopenharmony_ci reports. After compression, total_in holds the total size of the 1627777dab0Sopenharmony_ci uncompressed data and may be saved for use by the decompressor (particularly 1637777dab0Sopenharmony_ci if the decompressor wants to decompress everything in a single step). 1647777dab0Sopenharmony_ci*/ 1657777dab0Sopenharmony_ci 1667777dab0Sopenharmony_ci /* constants */ 1677777dab0Sopenharmony_ci 1687777dab0Sopenharmony_ci#define Z_NO_FLUSH 0 1697777dab0Sopenharmony_ci#define Z_PARTIAL_FLUSH 1 1707777dab0Sopenharmony_ci#define Z_SYNC_FLUSH 2 1717777dab0Sopenharmony_ci#define Z_FULL_FLUSH 3 1727777dab0Sopenharmony_ci#define Z_FINISH 4 1737777dab0Sopenharmony_ci#define Z_BLOCK 5 1747777dab0Sopenharmony_ci#define Z_TREES 6 1757777dab0Sopenharmony_ci/* Allowed flush values; see deflate() and inflate() below for details */ 1767777dab0Sopenharmony_ci 1777777dab0Sopenharmony_ci#define Z_OK 0 1787777dab0Sopenharmony_ci#define Z_STREAM_END 1 1797777dab0Sopenharmony_ci#define Z_NEED_DICT 2 1807777dab0Sopenharmony_ci#define Z_ERRNO (-1) 1817777dab0Sopenharmony_ci#define Z_STREAM_ERROR (-2) 1827777dab0Sopenharmony_ci#define Z_DATA_ERROR (-3) 1837777dab0Sopenharmony_ci#define Z_MEM_ERROR (-4) 1847777dab0Sopenharmony_ci#define Z_BUF_ERROR (-5) 1857777dab0Sopenharmony_ci#define Z_VERSION_ERROR (-6) 1867777dab0Sopenharmony_ci/* Return codes for the compression/decompression functions. Negative values 1877777dab0Sopenharmony_ci * are errors, positive values are used for special but normal events. 1887777dab0Sopenharmony_ci */ 1897777dab0Sopenharmony_ci 1907777dab0Sopenharmony_ci#define Z_NO_COMPRESSION 0 1917777dab0Sopenharmony_ci#define Z_BEST_SPEED 1 1927777dab0Sopenharmony_ci#define Z_BEST_COMPRESSION 9 1937777dab0Sopenharmony_ci#define Z_DEFAULT_COMPRESSION (-1) 1947777dab0Sopenharmony_ci/* compression levels */ 1957777dab0Sopenharmony_ci 1967777dab0Sopenharmony_ci#define Z_FILTERED 1 1977777dab0Sopenharmony_ci#define Z_HUFFMAN_ONLY 2 1987777dab0Sopenharmony_ci#define Z_RLE 3 1997777dab0Sopenharmony_ci#define Z_FIXED 4 2007777dab0Sopenharmony_ci#define Z_DEFAULT_STRATEGY 0 2017777dab0Sopenharmony_ci/* compression strategy; see deflateInit2() below for details */ 2027777dab0Sopenharmony_ci 2037777dab0Sopenharmony_ci#define Z_BINARY 0 2047777dab0Sopenharmony_ci#define Z_TEXT 1 2057777dab0Sopenharmony_ci#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 2067777dab0Sopenharmony_ci#define Z_UNKNOWN 2 2077777dab0Sopenharmony_ci/* Possible values of the data_type field for deflate() */ 2087777dab0Sopenharmony_ci 2097777dab0Sopenharmony_ci#define Z_DEFLATED 8 2107777dab0Sopenharmony_ci/* The deflate compression method (the only one supported in this version) */ 2117777dab0Sopenharmony_ci 2127777dab0Sopenharmony_ci#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 2137777dab0Sopenharmony_ci 2147777dab0Sopenharmony_ci#define zlib_version zlibVersion() 2157777dab0Sopenharmony_ci/* for compatibility with versions < 1.0.2 */ 2167777dab0Sopenharmony_ci 2177777dab0Sopenharmony_ci 2187777dab0Sopenharmony_ci /* basic functions */ 2197777dab0Sopenharmony_ci 2207777dab0Sopenharmony_ciZEXTERN const char * ZEXPORT zlibVersion(void); 2217777dab0Sopenharmony_ci/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 2227777dab0Sopenharmony_ci If the first character differs, the library code actually used is not 2237777dab0Sopenharmony_ci compatible with the zlib.h header file used by the application. This check 2247777dab0Sopenharmony_ci is automatically made by deflateInit and inflateInit. 2257777dab0Sopenharmony_ci */ 2267777dab0Sopenharmony_ci 2277777dab0Sopenharmony_ci/* 2287777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); 2297777dab0Sopenharmony_ci 2307777dab0Sopenharmony_ci Initializes the internal stream state for compression. The fields 2317777dab0Sopenharmony_ci zalloc, zfree and opaque must be initialized before by the caller. If 2327777dab0Sopenharmony_ci zalloc and zfree are set to Z_NULL, deflateInit updates them to use default 2337777dab0Sopenharmony_ci allocation functions. total_in, total_out, adler, and msg are initialized. 2347777dab0Sopenharmony_ci 2357777dab0Sopenharmony_ci The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 2367777dab0Sopenharmony_ci 1 gives best speed, 9 gives best compression, 0 gives no compression at all 2377777dab0Sopenharmony_ci (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION 2387777dab0Sopenharmony_ci requests a default compromise between speed and compression (currently 2397777dab0Sopenharmony_ci equivalent to level 6). 2407777dab0Sopenharmony_ci 2417777dab0Sopenharmony_ci deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 2427777dab0Sopenharmony_ci memory, Z_STREAM_ERROR if level is not a valid compression level, or 2437777dab0Sopenharmony_ci Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 2447777dab0Sopenharmony_ci with the version assumed by the caller (ZLIB_VERSION). msg is set to null 2457777dab0Sopenharmony_ci if there is no error message. deflateInit does not perform any compression: 2467777dab0Sopenharmony_ci this will be done by deflate(). 2477777dab0Sopenharmony_ci*/ 2487777dab0Sopenharmony_ci 2497777dab0Sopenharmony_ci 2507777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); 2517777dab0Sopenharmony_ci/* 2527777dab0Sopenharmony_ci deflate compresses as much data as possible, and stops when the input 2537777dab0Sopenharmony_ci buffer becomes empty or the output buffer becomes full. It may introduce 2547777dab0Sopenharmony_ci some output latency (reading input without producing any output) except when 2557777dab0Sopenharmony_ci forced to flush. 2567777dab0Sopenharmony_ci 2577777dab0Sopenharmony_ci The detailed semantics are as follows. deflate performs one or both of the 2587777dab0Sopenharmony_ci following actions: 2597777dab0Sopenharmony_ci 2607777dab0Sopenharmony_ci - Compress more input starting at next_in and update next_in and avail_in 2617777dab0Sopenharmony_ci accordingly. If not all input can be processed (because there is not 2627777dab0Sopenharmony_ci enough room in the output buffer), next_in and avail_in are updated and 2637777dab0Sopenharmony_ci processing will resume at this point for the next call of deflate(). 2647777dab0Sopenharmony_ci 2657777dab0Sopenharmony_ci - Generate more output starting at next_out and update next_out and avail_out 2667777dab0Sopenharmony_ci accordingly. This action is forced if the parameter flush is non zero. 2677777dab0Sopenharmony_ci Forcing flush frequently degrades the compression ratio, so this parameter 2687777dab0Sopenharmony_ci should be set only when necessary. Some output may be provided even if 2697777dab0Sopenharmony_ci flush is zero. 2707777dab0Sopenharmony_ci 2717777dab0Sopenharmony_ci Before the call of deflate(), the application should ensure that at least 2727777dab0Sopenharmony_ci one of the actions is possible, by providing more input and/or consuming more 2737777dab0Sopenharmony_ci output, and updating avail_in or avail_out accordingly; avail_out should 2747777dab0Sopenharmony_ci never be zero before the call. The application can consume the compressed 2757777dab0Sopenharmony_ci output when it wants, for example when the output buffer is full (avail_out 2767777dab0Sopenharmony_ci == 0), or after each call of deflate(). If deflate returns Z_OK and with 2777777dab0Sopenharmony_ci zero avail_out, it must be called again after making room in the output 2787777dab0Sopenharmony_ci buffer because there might be more output pending. See deflatePending(), 2797777dab0Sopenharmony_ci which can be used if desired to determine whether or not there is more output 2807777dab0Sopenharmony_ci in that case. 2817777dab0Sopenharmony_ci 2827777dab0Sopenharmony_ci Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 2837777dab0Sopenharmony_ci decide how much data to accumulate before producing output, in order to 2847777dab0Sopenharmony_ci maximize compression. 2857777dab0Sopenharmony_ci 2867777dab0Sopenharmony_ci If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 2877777dab0Sopenharmony_ci flushed to the output buffer and the output is aligned on a byte boundary, so 2887777dab0Sopenharmony_ci that the decompressor can get all input data available so far. (In 2897777dab0Sopenharmony_ci particular avail_in is zero after the call if enough output space has been 2907777dab0Sopenharmony_ci provided before the call.) Flushing may degrade compression for some 2917777dab0Sopenharmony_ci compression algorithms and so it should be used only when necessary. This 2927777dab0Sopenharmony_ci completes the current deflate block and follows it with an empty stored block 2937777dab0Sopenharmony_ci that is three bits plus filler bits to the next byte, followed by four bytes 2947777dab0Sopenharmony_ci (00 00 ff ff). 2957777dab0Sopenharmony_ci 2967777dab0Sopenharmony_ci If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the 2977777dab0Sopenharmony_ci output buffer, but the output is not aligned to a byte boundary. All of the 2987777dab0Sopenharmony_ci input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. 2997777dab0Sopenharmony_ci This completes the current deflate block and follows it with an empty fixed 3007777dab0Sopenharmony_ci codes block that is 10 bits long. This assures that enough bytes are output 3017777dab0Sopenharmony_ci in order for the decompressor to finish the block before the empty fixed 3027777dab0Sopenharmony_ci codes block. 3037777dab0Sopenharmony_ci 3047777dab0Sopenharmony_ci If flush is set to Z_BLOCK, a deflate block is completed and emitted, as 3057777dab0Sopenharmony_ci for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to 3067777dab0Sopenharmony_ci seven bits of the current block are held to be written as the next byte after 3077777dab0Sopenharmony_ci the next deflate block is completed. In this case, the decompressor may not 3087777dab0Sopenharmony_ci be provided enough bits at this point in order to complete decompression of 3097777dab0Sopenharmony_ci the data provided so far to the compressor. It may need to wait for the next 3107777dab0Sopenharmony_ci block to be emitted. This is for advanced applications that need to control 3117777dab0Sopenharmony_ci the emission of deflate blocks. 3127777dab0Sopenharmony_ci 3137777dab0Sopenharmony_ci If flush is set to Z_FULL_FLUSH, all output is flushed as with 3147777dab0Sopenharmony_ci Z_SYNC_FLUSH, and the compression state is reset so that decompression can 3157777dab0Sopenharmony_ci restart from this point if previous compressed data has been damaged or if 3167777dab0Sopenharmony_ci random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 3177777dab0Sopenharmony_ci compression. 3187777dab0Sopenharmony_ci 3197777dab0Sopenharmony_ci If deflate returns with avail_out == 0, this function must be called again 3207777dab0Sopenharmony_ci with the same value of the flush parameter and more output space (updated 3217777dab0Sopenharmony_ci avail_out), until the flush is complete (deflate returns with non-zero 3227777dab0Sopenharmony_ci avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 3237777dab0Sopenharmony_ci avail_out is greater than six when the flush marker begins, in order to avoid 3247777dab0Sopenharmony_ci repeated flush markers upon calling deflate() again when avail_out == 0. 3257777dab0Sopenharmony_ci 3267777dab0Sopenharmony_ci If the parameter flush is set to Z_FINISH, pending input is processed, 3277777dab0Sopenharmony_ci pending output is flushed and deflate returns with Z_STREAM_END if there was 3287777dab0Sopenharmony_ci enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this 3297777dab0Sopenharmony_ci function must be called again with Z_FINISH and more output space (updated 3307777dab0Sopenharmony_ci avail_out) but no more input data, until it returns with Z_STREAM_END or an 3317777dab0Sopenharmony_ci error. After deflate has returned Z_STREAM_END, the only possible operations 3327777dab0Sopenharmony_ci on the stream are deflateReset or deflateEnd. 3337777dab0Sopenharmony_ci 3347777dab0Sopenharmony_ci Z_FINISH can be used in the first deflate call after deflateInit if all the 3357777dab0Sopenharmony_ci compression is to be done in a single step. In order to complete in one 3367777dab0Sopenharmony_ci call, avail_out must be at least the value returned by deflateBound (see 3377777dab0Sopenharmony_ci below). Then deflate is guaranteed to return Z_STREAM_END. If not enough 3387777dab0Sopenharmony_ci output space is provided, deflate will not return Z_STREAM_END, and it must 3397777dab0Sopenharmony_ci be called again as described above. 3407777dab0Sopenharmony_ci 3417777dab0Sopenharmony_ci deflate() sets strm->adler to the Adler-32 checksum of all input read 3427777dab0Sopenharmony_ci so far (that is, total_in bytes). If a gzip stream is being generated, then 3437777dab0Sopenharmony_ci strm->adler will be the CRC-32 checksum of the input read so far. (See 3447777dab0Sopenharmony_ci deflateInit2 below.) 3457777dab0Sopenharmony_ci 3467777dab0Sopenharmony_ci deflate() may update strm->data_type if it can make a good guess about 3477777dab0Sopenharmony_ci the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is 3487777dab0Sopenharmony_ci considered binary. This field is only for information purposes and does not 3497777dab0Sopenharmony_ci affect the compression algorithm in any manner. 3507777dab0Sopenharmony_ci 3517777dab0Sopenharmony_ci deflate() returns Z_OK if some progress has been made (more input 3527777dab0Sopenharmony_ci processed or more output produced), Z_STREAM_END if all input has been 3537777dab0Sopenharmony_ci consumed and all output has been produced (only when flush is set to 3547777dab0Sopenharmony_ci Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 3557777dab0Sopenharmony_ci if next_in or next_out was Z_NULL or the state was inadvertently written over 3567777dab0Sopenharmony_ci by the application), or Z_BUF_ERROR if no progress is possible (for example 3577777dab0Sopenharmony_ci avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and 3587777dab0Sopenharmony_ci deflate() can be called again with more input and more output space to 3597777dab0Sopenharmony_ci continue compressing. 3607777dab0Sopenharmony_ci*/ 3617777dab0Sopenharmony_ci 3627777dab0Sopenharmony_ci 3637777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateEnd(z_streamp strm); 3647777dab0Sopenharmony_ci/* 3657777dab0Sopenharmony_ci All dynamically allocated data structures for this stream are freed. 3667777dab0Sopenharmony_ci This function discards any unprocessed input and does not flush any pending 3677777dab0Sopenharmony_ci output. 3687777dab0Sopenharmony_ci 3697777dab0Sopenharmony_ci deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 3707777dab0Sopenharmony_ci stream state was inconsistent, Z_DATA_ERROR if the stream was freed 3717777dab0Sopenharmony_ci prematurely (some input or output was discarded). In the error case, msg 3727777dab0Sopenharmony_ci may be set but then points to a static string (which must not be 3737777dab0Sopenharmony_ci deallocated). 3747777dab0Sopenharmony_ci*/ 3757777dab0Sopenharmony_ci 3767777dab0Sopenharmony_ci 3777777dab0Sopenharmony_ci/* 3787777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateInit(z_streamp strm); 3797777dab0Sopenharmony_ci 3807777dab0Sopenharmony_ci Initializes the internal stream state for decompression. The fields 3817777dab0Sopenharmony_ci next_in, avail_in, zalloc, zfree and opaque must be initialized before by 3827777dab0Sopenharmony_ci the caller. In the current version of inflate, the provided input is not 3837777dab0Sopenharmony_ci read or consumed. The allocation of a sliding window will be deferred to 3847777dab0Sopenharmony_ci the first call of inflate (if the decompression does not complete on the 3857777dab0Sopenharmony_ci first call). If zalloc and zfree are set to Z_NULL, inflateInit updates 3867777dab0Sopenharmony_ci them to use default allocation functions. total_in, total_out, adler, and 3877777dab0Sopenharmony_ci msg are initialized. 3887777dab0Sopenharmony_ci 3897777dab0Sopenharmony_ci inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 3907777dab0Sopenharmony_ci memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 3917777dab0Sopenharmony_ci version assumed by the caller, or Z_STREAM_ERROR if the parameters are 3927777dab0Sopenharmony_ci invalid, such as a null pointer to the structure. msg is set to null if 3937777dab0Sopenharmony_ci there is no error message. inflateInit does not perform any decompression. 3947777dab0Sopenharmony_ci Actual decompression will be done by inflate(). So next_in, and avail_in, 3957777dab0Sopenharmony_ci next_out, and avail_out are unused and unchanged. The current 3967777dab0Sopenharmony_ci implementation of inflateInit() does not process any header information -- 3977777dab0Sopenharmony_ci that is deferred until inflate() is called. 3987777dab0Sopenharmony_ci*/ 3997777dab0Sopenharmony_ci 4007777dab0Sopenharmony_ci 4017777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); 4027777dab0Sopenharmony_ci/* 4037777dab0Sopenharmony_ci inflate decompresses as much data as possible, and stops when the input 4047777dab0Sopenharmony_ci buffer becomes empty or the output buffer becomes full. It may introduce 4057777dab0Sopenharmony_ci some output latency (reading input without producing any output) except when 4067777dab0Sopenharmony_ci forced to flush. 4077777dab0Sopenharmony_ci 4087777dab0Sopenharmony_ci The detailed semantics are as follows. inflate performs one or both of the 4097777dab0Sopenharmony_ci following actions: 4107777dab0Sopenharmony_ci 4117777dab0Sopenharmony_ci - Decompress more input starting at next_in and update next_in and avail_in 4127777dab0Sopenharmony_ci accordingly. If not all input can be processed (because there is not 4137777dab0Sopenharmony_ci enough room in the output buffer), then next_in and avail_in are updated 4147777dab0Sopenharmony_ci accordingly, and processing will resume at this point for the next call of 4157777dab0Sopenharmony_ci inflate(). 4167777dab0Sopenharmony_ci 4177777dab0Sopenharmony_ci - Generate more output starting at next_out and update next_out and avail_out 4187777dab0Sopenharmony_ci accordingly. inflate() provides as much output as possible, until there is 4197777dab0Sopenharmony_ci no more input data or no more space in the output buffer (see below about 4207777dab0Sopenharmony_ci the flush parameter). 4217777dab0Sopenharmony_ci 4227777dab0Sopenharmony_ci Before the call of inflate(), the application should ensure that at least 4237777dab0Sopenharmony_ci one of the actions is possible, by providing more input and/or consuming more 4247777dab0Sopenharmony_ci output, and updating the next_* and avail_* values accordingly. If the 4257777dab0Sopenharmony_ci caller of inflate() does not provide both available input and available 4267777dab0Sopenharmony_ci output space, it is possible that there will be no progress made. The 4277777dab0Sopenharmony_ci application can consume the uncompressed output when it wants, for example 4287777dab0Sopenharmony_ci when the output buffer is full (avail_out == 0), or after each call of 4297777dab0Sopenharmony_ci inflate(). If inflate returns Z_OK and with zero avail_out, it must be 4307777dab0Sopenharmony_ci called again after making room in the output buffer because there might be 4317777dab0Sopenharmony_ci more output pending. 4327777dab0Sopenharmony_ci 4337777dab0Sopenharmony_ci The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, 4347777dab0Sopenharmony_ci Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much 4357777dab0Sopenharmony_ci output as possible to the output buffer. Z_BLOCK requests that inflate() 4367777dab0Sopenharmony_ci stop if and when it gets to the next deflate block boundary. When decoding 4377777dab0Sopenharmony_ci the zlib or gzip format, this will cause inflate() to return immediately 4387777dab0Sopenharmony_ci after the header and before the first block. When doing a raw inflate, 4397777dab0Sopenharmony_ci inflate() will go ahead and process the first block, and will return when it 4407777dab0Sopenharmony_ci gets to the end of that block, or when it runs out of data. 4417777dab0Sopenharmony_ci 4427777dab0Sopenharmony_ci The Z_BLOCK option assists in appending to or combining deflate streams. 4437777dab0Sopenharmony_ci To assist in this, on return inflate() always sets strm->data_type to the 4447777dab0Sopenharmony_ci number of unused bits in the last byte taken from strm->next_in, plus 64 if 4457777dab0Sopenharmony_ci inflate() is currently decoding the last block in the deflate stream, plus 4467777dab0Sopenharmony_ci 128 if inflate() returned immediately after decoding an end-of-block code or 4477777dab0Sopenharmony_ci decoding the complete header up to just before the first byte of the deflate 4487777dab0Sopenharmony_ci stream. The end-of-block will not be indicated until all of the uncompressed 4497777dab0Sopenharmony_ci data from that block has been written to strm->next_out. The number of 4507777dab0Sopenharmony_ci unused bits may in general be greater than seven, except when bit 7 of 4517777dab0Sopenharmony_ci data_type is set, in which case the number of unused bits will be less than 4527777dab0Sopenharmony_ci eight. data_type is set as noted here every time inflate() returns for all 4537777dab0Sopenharmony_ci flush options, and so can be used to determine the amount of currently 4547777dab0Sopenharmony_ci consumed input in bits. 4557777dab0Sopenharmony_ci 4567777dab0Sopenharmony_ci The Z_TREES option behaves as Z_BLOCK does, but it also returns when the 4577777dab0Sopenharmony_ci end of each deflate block header is reached, before any actual data in that 4587777dab0Sopenharmony_ci block is decoded. This allows the caller to determine the length of the 4597777dab0Sopenharmony_ci deflate block header for later use in random access within a deflate block. 4607777dab0Sopenharmony_ci 256 is added to the value of strm->data_type when inflate() returns 4617777dab0Sopenharmony_ci immediately after reaching the end of the deflate block header. 4627777dab0Sopenharmony_ci 4637777dab0Sopenharmony_ci inflate() should normally be called until it returns Z_STREAM_END or an 4647777dab0Sopenharmony_ci error. However if all decompression is to be performed in a single step (a 4657777dab0Sopenharmony_ci single call of inflate), the parameter flush should be set to Z_FINISH. In 4667777dab0Sopenharmony_ci this case all pending input is processed and all pending output is flushed; 4677777dab0Sopenharmony_ci avail_out must be large enough to hold all of the uncompressed data for the 4687777dab0Sopenharmony_ci operation to complete. (The size of the uncompressed data may have been 4697777dab0Sopenharmony_ci saved by the compressor for this purpose.) The use of Z_FINISH is not 4707777dab0Sopenharmony_ci required to perform an inflation in one step. However it may be used to 4717777dab0Sopenharmony_ci inform inflate that a faster approach can be used for the single inflate() 4727777dab0Sopenharmony_ci call. Z_FINISH also informs inflate to not maintain a sliding window if the 4737777dab0Sopenharmony_ci stream completes, which reduces inflate's memory footprint. If the stream 4747777dab0Sopenharmony_ci does not complete, either because not all of the stream is provided or not 4757777dab0Sopenharmony_ci enough output space is provided, then a sliding window will be allocated and 4767777dab0Sopenharmony_ci inflate() can be called again to continue the operation as if Z_NO_FLUSH had 4777777dab0Sopenharmony_ci been used. 4787777dab0Sopenharmony_ci 4797777dab0Sopenharmony_ci In this implementation, inflate() always flushes as much output as 4807777dab0Sopenharmony_ci possible to the output buffer, and always uses the faster approach on the 4817777dab0Sopenharmony_ci first call. So the effects of the flush parameter in this implementation are 4827777dab0Sopenharmony_ci on the return value of inflate() as noted below, when inflate() returns early 4837777dab0Sopenharmony_ci when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of 4847777dab0Sopenharmony_ci memory for a sliding window when Z_FINISH is used. 4857777dab0Sopenharmony_ci 4867777dab0Sopenharmony_ci If a preset dictionary is needed after this call (see inflateSetDictionary 4877777dab0Sopenharmony_ci below), inflate sets strm->adler to the Adler-32 checksum of the dictionary 4887777dab0Sopenharmony_ci chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 4897777dab0Sopenharmony_ci strm->adler to the Adler-32 checksum of all output produced so far (that is, 4907777dab0Sopenharmony_ci total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 4917777dab0Sopenharmony_ci below. At the end of the stream, inflate() checks that its computed Adler-32 4927777dab0Sopenharmony_ci checksum is equal to that saved by the compressor and returns Z_STREAM_END 4937777dab0Sopenharmony_ci only if the checksum is correct. 4947777dab0Sopenharmony_ci 4957777dab0Sopenharmony_ci inflate() can decompress and check either zlib-wrapped or gzip-wrapped 4967777dab0Sopenharmony_ci deflate data. The header type is detected automatically, if requested when 4977777dab0Sopenharmony_ci initializing with inflateInit2(). Any information contained in the gzip 4987777dab0Sopenharmony_ci header is not retained unless inflateGetHeader() is used. When processing 4997777dab0Sopenharmony_ci gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output 5007777dab0Sopenharmony_ci produced so far. The CRC-32 is checked against the gzip trailer, as is the 5017777dab0Sopenharmony_ci uncompressed length, modulo 2^32. 5027777dab0Sopenharmony_ci 5037777dab0Sopenharmony_ci inflate() returns Z_OK if some progress has been made (more input processed 5047777dab0Sopenharmony_ci or more output produced), Z_STREAM_END if the end of the compressed data has 5057777dab0Sopenharmony_ci been reached and all uncompressed output has been produced, Z_NEED_DICT if a 5067777dab0Sopenharmony_ci preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 5077777dab0Sopenharmony_ci corrupted (input stream not conforming to the zlib format or incorrect check 5087777dab0Sopenharmony_ci value, in which case strm->msg points to a string with a more specific 5097777dab0Sopenharmony_ci error), Z_STREAM_ERROR if the stream structure was inconsistent (for example 5107777dab0Sopenharmony_ci next_in or next_out was Z_NULL, or the state was inadvertently written over 5117777dab0Sopenharmony_ci by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR 5127777dab0Sopenharmony_ci if no progress was possible or if there was not enough room in the output 5137777dab0Sopenharmony_ci buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 5147777dab0Sopenharmony_ci inflate() can be called again with more input and more output space to 5157777dab0Sopenharmony_ci continue decompressing. If Z_DATA_ERROR is returned, the application may 5167777dab0Sopenharmony_ci then call inflateSync() to look for a good compression block if a partial 5177777dab0Sopenharmony_ci recovery of the data is to be attempted. 5187777dab0Sopenharmony_ci*/ 5197777dab0Sopenharmony_ci 5207777dab0Sopenharmony_ci 5217777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateEnd(z_streamp strm); 5227777dab0Sopenharmony_ci/* 5237777dab0Sopenharmony_ci All dynamically allocated data structures for this stream are freed. 5247777dab0Sopenharmony_ci This function discards any unprocessed input and does not flush any pending 5257777dab0Sopenharmony_ci output. 5267777dab0Sopenharmony_ci 5277777dab0Sopenharmony_ci inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state 5287777dab0Sopenharmony_ci was inconsistent. 5297777dab0Sopenharmony_ci*/ 5307777dab0Sopenharmony_ci 5317777dab0Sopenharmony_ci 5327777dab0Sopenharmony_ci /* Advanced functions */ 5337777dab0Sopenharmony_ci 5347777dab0Sopenharmony_ci/* 5357777dab0Sopenharmony_ci The following functions are needed only in some special applications. 5367777dab0Sopenharmony_ci*/ 5377777dab0Sopenharmony_ci 5387777dab0Sopenharmony_ci/* 5397777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateInit2(z_streamp strm, 5407777dab0Sopenharmony_ci int level, 5417777dab0Sopenharmony_ci int method, 5427777dab0Sopenharmony_ci int windowBits, 5437777dab0Sopenharmony_ci int memLevel, 5447777dab0Sopenharmony_ci int strategy); 5457777dab0Sopenharmony_ci 5467777dab0Sopenharmony_ci This is another version of deflateInit with more compression options. The 5477777dab0Sopenharmony_ci fields zalloc, zfree and opaque must be initialized before by the caller. 5487777dab0Sopenharmony_ci 5497777dab0Sopenharmony_ci The method parameter is the compression method. It must be Z_DEFLATED in 5507777dab0Sopenharmony_ci this version of the library. 5517777dab0Sopenharmony_ci 5527777dab0Sopenharmony_ci The windowBits parameter is the base two logarithm of the window size 5537777dab0Sopenharmony_ci (the size of the history buffer). It should be in the range 8..15 for this 5547777dab0Sopenharmony_ci version of the library. Larger values of this parameter result in better 5557777dab0Sopenharmony_ci compression at the expense of memory usage. The default value is 15 if 5567777dab0Sopenharmony_ci deflateInit is used instead. 5577777dab0Sopenharmony_ci 5587777dab0Sopenharmony_ci For the current implementation of deflate(), a windowBits value of 8 (a 5597777dab0Sopenharmony_ci window size of 256 bytes) is not supported. As a result, a request for 8 5607777dab0Sopenharmony_ci will result in 9 (a 512-byte window). In that case, providing 8 to 5617777dab0Sopenharmony_ci inflateInit2() will result in an error when the zlib header with 9 is 5627777dab0Sopenharmony_ci checked against the initialization of inflate(). The remedy is to not use 8 5637777dab0Sopenharmony_ci with deflateInit2() with this initialization, or at least in that case use 9 5647777dab0Sopenharmony_ci with inflateInit2(). 5657777dab0Sopenharmony_ci 5667777dab0Sopenharmony_ci windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 5677777dab0Sopenharmony_ci determines the window size. deflate() will then generate raw deflate data 5687777dab0Sopenharmony_ci with no zlib header or trailer, and will not compute a check value. 5697777dab0Sopenharmony_ci 5707777dab0Sopenharmony_ci windowBits can also be greater than 15 for optional gzip encoding. Add 5717777dab0Sopenharmony_ci 16 to windowBits to write a simple gzip header and trailer around the 5727777dab0Sopenharmony_ci compressed data instead of a zlib wrapper. The gzip header will have no 5737777dab0Sopenharmony_ci file name, no extra data, no comment, no modification time (set to zero), no 5747777dab0Sopenharmony_ci header crc, and the operating system will be set to the appropriate value, 5757777dab0Sopenharmony_ci if the operating system was determined at compile time. If a gzip stream is 5767777dab0Sopenharmony_ci being written, strm->adler is a CRC-32 instead of an Adler-32. 5777777dab0Sopenharmony_ci 5787777dab0Sopenharmony_ci For raw deflate or gzip encoding, a request for a 256-byte window is 5797777dab0Sopenharmony_ci rejected as invalid, since only the zlib header provides a means of 5807777dab0Sopenharmony_ci transmitting the window size to the decompressor. 5817777dab0Sopenharmony_ci 5827777dab0Sopenharmony_ci The memLevel parameter specifies how much memory should be allocated 5837777dab0Sopenharmony_ci for the internal compression state. memLevel=1 uses minimum memory but is 5847777dab0Sopenharmony_ci slow and reduces compression ratio; memLevel=9 uses maximum memory for 5857777dab0Sopenharmony_ci optimal speed. The default value is 8. See zconf.h for total memory usage 5867777dab0Sopenharmony_ci as a function of windowBits and memLevel. 5877777dab0Sopenharmony_ci 5887777dab0Sopenharmony_ci The strategy parameter is used to tune the compression algorithm. Use the 5897777dab0Sopenharmony_ci value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 5907777dab0Sopenharmony_ci filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 5917777dab0Sopenharmony_ci string match), or Z_RLE to limit match distances to one (run-length 5927777dab0Sopenharmony_ci encoding). Filtered data consists mostly of small values with a somewhat 5937777dab0Sopenharmony_ci random distribution. In this case, the compression algorithm is tuned to 5947777dab0Sopenharmony_ci compress them better. The effect of Z_FILTERED is to force more Huffman 5957777dab0Sopenharmony_ci coding and less string matching; it is somewhat intermediate between 5967777dab0Sopenharmony_ci Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as 5977777dab0Sopenharmony_ci fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The 5987777dab0Sopenharmony_ci strategy parameter only affects the compression ratio but not the 5997777dab0Sopenharmony_ci correctness of the compressed output even if it is not set appropriately. 6007777dab0Sopenharmony_ci Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler 6017777dab0Sopenharmony_ci decoder for special applications. 6027777dab0Sopenharmony_ci 6037777dab0Sopenharmony_ci deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 6047777dab0Sopenharmony_ci memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid 6057777dab0Sopenharmony_ci method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is 6067777dab0Sopenharmony_ci incompatible with the version assumed by the caller (ZLIB_VERSION). msg is 6077777dab0Sopenharmony_ci set to null if there is no error message. deflateInit2 does not perform any 6087777dab0Sopenharmony_ci compression: this will be done by deflate(). 6097777dab0Sopenharmony_ci*/ 6107777dab0Sopenharmony_ci 6117777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, 6127777dab0Sopenharmony_ci const Bytef *dictionary, 6137777dab0Sopenharmony_ci uInt dictLength); 6147777dab0Sopenharmony_ci/* 6157777dab0Sopenharmony_ci Initializes the compression dictionary from the given byte sequence 6167777dab0Sopenharmony_ci without producing any compressed output. When using the zlib format, this 6177777dab0Sopenharmony_ci function must be called immediately after deflateInit, deflateInit2 or 6187777dab0Sopenharmony_ci deflateReset, and before any call of deflate. When doing raw deflate, this 6197777dab0Sopenharmony_ci function must be called either before any call of deflate, or immediately 6207777dab0Sopenharmony_ci after the completion of a deflate block, i.e. after all input has been 6217777dab0Sopenharmony_ci consumed and all output has been delivered when using any of the flush 6227777dab0Sopenharmony_ci options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The 6237777dab0Sopenharmony_ci compressor and decompressor must use exactly the same dictionary (see 6247777dab0Sopenharmony_ci inflateSetDictionary). 6257777dab0Sopenharmony_ci 6267777dab0Sopenharmony_ci The dictionary should consist of strings (byte sequences) that are likely 6277777dab0Sopenharmony_ci to be encountered later in the data to be compressed, with the most commonly 6287777dab0Sopenharmony_ci used strings preferably put towards the end of the dictionary. Using a 6297777dab0Sopenharmony_ci dictionary is most useful when the data to be compressed is short and can be 6307777dab0Sopenharmony_ci predicted with good accuracy; the data can then be compressed better than 6317777dab0Sopenharmony_ci with the default empty dictionary. 6327777dab0Sopenharmony_ci 6337777dab0Sopenharmony_ci Depending on the size of the compression data structures selected by 6347777dab0Sopenharmony_ci deflateInit or deflateInit2, a part of the dictionary may in effect be 6357777dab0Sopenharmony_ci discarded, for example if the dictionary is larger than the window size 6367777dab0Sopenharmony_ci provided in deflateInit or deflateInit2. Thus the strings most likely to be 6377777dab0Sopenharmony_ci useful should be put at the end of the dictionary, not at the front. In 6387777dab0Sopenharmony_ci addition, the current implementation of deflate will use at most the window 6397777dab0Sopenharmony_ci size minus 262 bytes of the provided dictionary. 6407777dab0Sopenharmony_ci 6417777dab0Sopenharmony_ci Upon return of this function, strm->adler is set to the Adler-32 value 6427777dab0Sopenharmony_ci of the dictionary; the decompressor may later use this value to determine 6437777dab0Sopenharmony_ci which dictionary has been used by the compressor. (The Adler-32 value 6447777dab0Sopenharmony_ci applies to the whole dictionary even if only a subset of the dictionary is 6457777dab0Sopenharmony_ci actually used by the compressor.) If a raw deflate was requested, then the 6467777dab0Sopenharmony_ci Adler-32 value is not computed and strm->adler is not set. 6477777dab0Sopenharmony_ci 6487777dab0Sopenharmony_ci deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 6497777dab0Sopenharmony_ci parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 6507777dab0Sopenharmony_ci inconsistent (for example if deflate has already been called for this stream 6517777dab0Sopenharmony_ci or if not at a block boundary for raw deflate). deflateSetDictionary does 6527777dab0Sopenharmony_ci not perform any compression: this will be done by deflate(). 6537777dab0Sopenharmony_ci*/ 6547777dab0Sopenharmony_ci 6557777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, 6567777dab0Sopenharmony_ci Bytef *dictionary, 6577777dab0Sopenharmony_ci uInt *dictLength); 6587777dab0Sopenharmony_ci/* 6597777dab0Sopenharmony_ci Returns the sliding dictionary being maintained by deflate. dictLength is 6607777dab0Sopenharmony_ci set to the number of bytes in the dictionary, and that many bytes are copied 6617777dab0Sopenharmony_ci to dictionary. dictionary must have enough space, where 32768 bytes is 6627777dab0Sopenharmony_ci always enough. If deflateGetDictionary() is called with dictionary equal to 6637777dab0Sopenharmony_ci Z_NULL, then only the dictionary length is returned, and nothing is copied. 6647777dab0Sopenharmony_ci Similarly, if dictLength is Z_NULL, then it is not set. 6657777dab0Sopenharmony_ci 6667777dab0Sopenharmony_ci deflateGetDictionary() may return a length less than the window size, even 6677777dab0Sopenharmony_ci when more than the window size in input has been provided. It may return up 6687777dab0Sopenharmony_ci to 258 bytes less in that case, due to how zlib's implementation of deflate 6697777dab0Sopenharmony_ci manages the sliding window and lookahead for matches, where matches can be 6707777dab0Sopenharmony_ci up to 258 bytes long. If the application needs the last window-size bytes of 6717777dab0Sopenharmony_ci input, then that would need to be saved by the application outside of zlib. 6727777dab0Sopenharmony_ci 6737777dab0Sopenharmony_ci deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the 6747777dab0Sopenharmony_ci stream state is inconsistent. 6757777dab0Sopenharmony_ci*/ 6767777dab0Sopenharmony_ci 6777777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateCopy(z_streamp dest, 6787777dab0Sopenharmony_ci z_streamp source); 6797777dab0Sopenharmony_ci/* 6807777dab0Sopenharmony_ci Sets the destination stream as a complete copy of the source stream. 6817777dab0Sopenharmony_ci 6827777dab0Sopenharmony_ci This function can be useful when several compression strategies will be 6837777dab0Sopenharmony_ci tried, for example when there are several ways of pre-processing the input 6847777dab0Sopenharmony_ci data with a filter. The streams that will be discarded should then be freed 6857777dab0Sopenharmony_ci by calling deflateEnd. Note that deflateCopy duplicates the internal 6867777dab0Sopenharmony_ci compression state which can be quite large, so this strategy is slow and can 6877777dab0Sopenharmony_ci consume lots of memory. 6887777dab0Sopenharmony_ci 6897777dab0Sopenharmony_ci deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 6907777dab0Sopenharmony_ci enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 6917777dab0Sopenharmony_ci (such as zalloc being Z_NULL). msg is left unchanged in both source and 6927777dab0Sopenharmony_ci destination. 6937777dab0Sopenharmony_ci*/ 6947777dab0Sopenharmony_ci 6957777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateReset(z_streamp strm); 6967777dab0Sopenharmony_ci/* 6977777dab0Sopenharmony_ci This function is equivalent to deflateEnd followed by deflateInit, but 6987777dab0Sopenharmony_ci does not free and reallocate the internal compression state. The stream 6997777dab0Sopenharmony_ci will leave the compression level and any other attributes that may have been 7007777dab0Sopenharmony_ci set unchanged. total_in, total_out, adler, and msg are initialized. 7017777dab0Sopenharmony_ci 7027777dab0Sopenharmony_ci deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 7037777dab0Sopenharmony_ci stream state was inconsistent (such as zalloc or state being Z_NULL). 7047777dab0Sopenharmony_ci*/ 7057777dab0Sopenharmony_ci 7067777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateParams(z_streamp strm, 7077777dab0Sopenharmony_ci int level, 7087777dab0Sopenharmony_ci int strategy); 7097777dab0Sopenharmony_ci/* 7107777dab0Sopenharmony_ci Dynamically update the compression level and compression strategy. The 7117777dab0Sopenharmony_ci interpretation of level and strategy is as in deflateInit2(). This can be 7127777dab0Sopenharmony_ci used to switch between compression and straight copy of the input data, or 7137777dab0Sopenharmony_ci to switch to a different kind of input data requiring a different strategy. 7147777dab0Sopenharmony_ci If the compression approach (which is a function of the level) or the 7157777dab0Sopenharmony_ci strategy is changed, and if there have been any deflate() calls since the 7167777dab0Sopenharmony_ci state was initialized or reset, then the input available so far is 7177777dab0Sopenharmony_ci compressed with the old level and strategy using deflate(strm, Z_BLOCK). 7187777dab0Sopenharmony_ci There are three approaches for the compression levels 0, 1..3, and 4..9 7197777dab0Sopenharmony_ci respectively. The new level and strategy will take effect at the next call 7207777dab0Sopenharmony_ci of deflate(). 7217777dab0Sopenharmony_ci 7227777dab0Sopenharmony_ci If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does 7237777dab0Sopenharmony_ci not have enough output space to complete, then the parameter change will not 7247777dab0Sopenharmony_ci take effect. In this case, deflateParams() can be called again with the 7257777dab0Sopenharmony_ci same parameters and more output space to try again. 7267777dab0Sopenharmony_ci 7277777dab0Sopenharmony_ci In order to assure a change in the parameters on the first try, the 7287777dab0Sopenharmony_ci deflate stream should be flushed using deflate() with Z_BLOCK or other flush 7297777dab0Sopenharmony_ci request until strm.avail_out is not zero, before calling deflateParams(). 7307777dab0Sopenharmony_ci Then no more input data should be provided before the deflateParams() call. 7317777dab0Sopenharmony_ci If this is done, the old level and strategy will be applied to the data 7327777dab0Sopenharmony_ci compressed before deflateParams(), and the new level and strategy will be 7337777dab0Sopenharmony_ci applied to the data compressed after deflateParams(). 7347777dab0Sopenharmony_ci 7357777dab0Sopenharmony_ci deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream 7367777dab0Sopenharmony_ci state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if 7377777dab0Sopenharmony_ci there was not enough output space to complete the compression of the 7387777dab0Sopenharmony_ci available input data before a change in the strategy or approach. Note that 7397777dab0Sopenharmony_ci in the case of a Z_BUF_ERROR, the parameters are not changed. A return 7407777dab0Sopenharmony_ci value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be 7417777dab0Sopenharmony_ci retried with more output space. 7427777dab0Sopenharmony_ci*/ 7437777dab0Sopenharmony_ci 7447777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateTune(z_streamp strm, 7457777dab0Sopenharmony_ci int good_length, 7467777dab0Sopenharmony_ci int max_lazy, 7477777dab0Sopenharmony_ci int nice_length, 7487777dab0Sopenharmony_ci int max_chain); 7497777dab0Sopenharmony_ci/* 7507777dab0Sopenharmony_ci Fine tune deflate's internal compression parameters. This should only be 7517777dab0Sopenharmony_ci used by someone who understands the algorithm used by zlib's deflate for 7527777dab0Sopenharmony_ci searching for the best matching string, and even then only by the most 7537777dab0Sopenharmony_ci fanatic optimizer trying to squeeze out the last compressed bit for their 7547777dab0Sopenharmony_ci specific input data. Read the deflate.c source code for the meaning of the 7557777dab0Sopenharmony_ci max_lazy, good_length, nice_length, and max_chain parameters. 7567777dab0Sopenharmony_ci 7577777dab0Sopenharmony_ci deflateTune() can be called after deflateInit() or deflateInit2(), and 7587777dab0Sopenharmony_ci returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 7597777dab0Sopenharmony_ci */ 7607777dab0Sopenharmony_ci 7617777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, 7627777dab0Sopenharmony_ci uLong sourceLen); 7637777dab0Sopenharmony_ci/* 7647777dab0Sopenharmony_ci deflateBound() returns an upper bound on the compressed size after 7657777dab0Sopenharmony_ci deflation of sourceLen bytes. It must be called after deflateInit() or 7667777dab0Sopenharmony_ci deflateInit2(), and after deflateSetHeader(), if used. This would be used 7677777dab0Sopenharmony_ci to allocate an output buffer for deflation in a single pass, and so would be 7687777dab0Sopenharmony_ci called before deflate(). If that first deflate() call is provided the 7697777dab0Sopenharmony_ci sourceLen input bytes, an output buffer allocated to the size returned by 7707777dab0Sopenharmony_ci deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed 7717777dab0Sopenharmony_ci to return Z_STREAM_END. Note that it is possible for the compressed size to 7727777dab0Sopenharmony_ci be larger than the value returned by deflateBound() if flush options other 7737777dab0Sopenharmony_ci than Z_FINISH or Z_NO_FLUSH are used. 7747777dab0Sopenharmony_ci*/ 7757777dab0Sopenharmony_ci 7767777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflatePending(z_streamp strm, 7777777dab0Sopenharmony_ci unsigned *pending, 7787777dab0Sopenharmony_ci int *bits); 7797777dab0Sopenharmony_ci/* 7807777dab0Sopenharmony_ci deflatePending() returns the number of bytes and bits of output that have 7817777dab0Sopenharmony_ci been generated, but not yet provided in the available output. The bytes not 7827777dab0Sopenharmony_ci provided would be due to the available output space having being consumed. 7837777dab0Sopenharmony_ci The number of bits of output not provided are between 0 and 7, where they 7847777dab0Sopenharmony_ci await more bits to join them in order to fill out a full byte. If pending 7857777dab0Sopenharmony_ci or bits are Z_NULL, then those values are not set. 7867777dab0Sopenharmony_ci 7877777dab0Sopenharmony_ci deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source 7887777dab0Sopenharmony_ci stream state was inconsistent. 7897777dab0Sopenharmony_ci */ 7907777dab0Sopenharmony_ci 7917777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflatePrime(z_streamp strm, 7927777dab0Sopenharmony_ci int bits, 7937777dab0Sopenharmony_ci int value); 7947777dab0Sopenharmony_ci/* 7957777dab0Sopenharmony_ci deflatePrime() inserts bits in the deflate output stream. The intent 7967777dab0Sopenharmony_ci is that this function is used to start off the deflate output with the bits 7977777dab0Sopenharmony_ci leftover from a previous deflate stream when appending to it. As such, this 7987777dab0Sopenharmony_ci function can only be used for raw deflate, and must be used before the first 7997777dab0Sopenharmony_ci deflate() call after a deflateInit2() or deflateReset(). bits must be less 8007777dab0Sopenharmony_ci than or equal to 16, and that many of the least significant bits of value 8017777dab0Sopenharmony_ci will be inserted in the output. 8027777dab0Sopenharmony_ci 8037777dab0Sopenharmony_ci deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough 8047777dab0Sopenharmony_ci room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the 8057777dab0Sopenharmony_ci source stream state was inconsistent. 8067777dab0Sopenharmony_ci*/ 8077777dab0Sopenharmony_ci 8087777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, 8097777dab0Sopenharmony_ci gz_headerp head); 8107777dab0Sopenharmony_ci/* 8117777dab0Sopenharmony_ci deflateSetHeader() provides gzip header information for when a gzip 8127777dab0Sopenharmony_ci stream is requested by deflateInit2(). deflateSetHeader() may be called 8137777dab0Sopenharmony_ci after deflateInit2() or deflateReset() and before the first call of 8147777dab0Sopenharmony_ci deflate(). The text, time, os, extra field, name, and comment information 8157777dab0Sopenharmony_ci in the provided gz_header structure are written to the gzip header (xflag is 8167777dab0Sopenharmony_ci ignored -- the extra flags are set according to the compression level). The 8177777dab0Sopenharmony_ci caller must assure that, if not Z_NULL, name and comment are terminated with 8187777dab0Sopenharmony_ci a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 8197777dab0Sopenharmony_ci available there. If hcrc is true, a gzip header crc is included. Note that 8207777dab0Sopenharmony_ci the current versions of the command-line version of gzip (up through version 8217777dab0Sopenharmony_ci 1.3.x) do not support header crc's, and will report that it is a "multi-part 8227777dab0Sopenharmony_ci gzip file" and give up. 8237777dab0Sopenharmony_ci 8247777dab0Sopenharmony_ci If deflateSetHeader is not used, the default gzip header has text false, 8257777dab0Sopenharmony_ci the time set to zero, and os set to the current operating system, with no 8267777dab0Sopenharmony_ci extra, name, or comment fields. The gzip header is returned to the default 8277777dab0Sopenharmony_ci state by deflateReset(). 8287777dab0Sopenharmony_ci 8297777dab0Sopenharmony_ci deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 8307777dab0Sopenharmony_ci stream state was inconsistent. 8317777dab0Sopenharmony_ci*/ 8327777dab0Sopenharmony_ci 8337777dab0Sopenharmony_ci/* 8347777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateInit2(z_streamp strm, 8357777dab0Sopenharmony_ci int windowBits); 8367777dab0Sopenharmony_ci 8377777dab0Sopenharmony_ci This is another version of inflateInit with an extra parameter. The 8387777dab0Sopenharmony_ci fields next_in, avail_in, zalloc, zfree and opaque must be initialized 8397777dab0Sopenharmony_ci before by the caller. 8407777dab0Sopenharmony_ci 8417777dab0Sopenharmony_ci The windowBits parameter is the base two logarithm of the maximum window 8427777dab0Sopenharmony_ci size (the size of the history buffer). It should be in the range 8..15 for 8437777dab0Sopenharmony_ci this version of the library. The default value is 15 if inflateInit is used 8447777dab0Sopenharmony_ci instead. windowBits must be greater than or equal to the windowBits value 8457777dab0Sopenharmony_ci provided to deflateInit2() while compressing, or it must be equal to 15 if 8467777dab0Sopenharmony_ci deflateInit2() was not used. If a compressed stream with a larger window 8477777dab0Sopenharmony_ci size is given as input, inflate() will return with the error code 8487777dab0Sopenharmony_ci Z_DATA_ERROR instead of trying to allocate a larger window. 8497777dab0Sopenharmony_ci 8507777dab0Sopenharmony_ci windowBits can also be zero to request that inflate use the window size in 8517777dab0Sopenharmony_ci the zlib header of the compressed stream. 8527777dab0Sopenharmony_ci 8537777dab0Sopenharmony_ci windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 8547777dab0Sopenharmony_ci determines the window size. inflate() will then process raw deflate data, 8557777dab0Sopenharmony_ci not looking for a zlib or gzip header, not generating a check value, and not 8567777dab0Sopenharmony_ci looking for any check values for comparison at the end of the stream. This 8577777dab0Sopenharmony_ci is for use with other formats that use the deflate compressed data format 8587777dab0Sopenharmony_ci such as zip. Those formats provide their own check values. If a custom 8597777dab0Sopenharmony_ci format is developed using the raw deflate format for compressed data, it is 8607777dab0Sopenharmony_ci recommended that a check value such as an Adler-32 or a CRC-32 be applied to 8617777dab0Sopenharmony_ci the uncompressed data as is done in the zlib, gzip, and zip formats. For 8627777dab0Sopenharmony_ci most applications, the zlib format should be used as is. Note that comments 8637777dab0Sopenharmony_ci above on the use in deflateInit2() applies to the magnitude of windowBits. 8647777dab0Sopenharmony_ci 8657777dab0Sopenharmony_ci windowBits can also be greater than 15 for optional gzip decoding. Add 8667777dab0Sopenharmony_ci 32 to windowBits to enable zlib and gzip decoding with automatic header 8677777dab0Sopenharmony_ci detection, or add 16 to decode only the gzip format (the zlib format will 8687777dab0Sopenharmony_ci return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a 8697777dab0Sopenharmony_ci CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see 8707777dab0Sopenharmony_ci below), inflate() will *not* automatically decode concatenated gzip members. 8717777dab0Sopenharmony_ci inflate() will return Z_STREAM_END at the end of the gzip member. The state 8727777dab0Sopenharmony_ci would need to be reset to continue decoding a subsequent gzip member. This 8737777dab0Sopenharmony_ci *must* be done if there is more data after a gzip member, in order for the 8747777dab0Sopenharmony_ci decompression to be compliant with the gzip standard (RFC 1952). 8757777dab0Sopenharmony_ci 8767777dab0Sopenharmony_ci inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 8777777dab0Sopenharmony_ci memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 8787777dab0Sopenharmony_ci version assumed by the caller, or Z_STREAM_ERROR if the parameters are 8797777dab0Sopenharmony_ci invalid, such as a null pointer to the structure. msg is set to null if 8807777dab0Sopenharmony_ci there is no error message. inflateInit2 does not perform any decompression 8817777dab0Sopenharmony_ci apart from possibly reading the zlib header if present: actual decompression 8827777dab0Sopenharmony_ci will be done by inflate(). (So next_in and avail_in may be modified, but 8837777dab0Sopenharmony_ci next_out and avail_out are unused and unchanged.) The current implementation 8847777dab0Sopenharmony_ci of inflateInit2() does not process any header information -- that is 8857777dab0Sopenharmony_ci deferred until inflate() is called. 8867777dab0Sopenharmony_ci*/ 8877777dab0Sopenharmony_ci 8887777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, 8897777dab0Sopenharmony_ci const Bytef *dictionary, 8907777dab0Sopenharmony_ci uInt dictLength); 8917777dab0Sopenharmony_ci/* 8927777dab0Sopenharmony_ci Initializes the decompression dictionary from the given uncompressed byte 8937777dab0Sopenharmony_ci sequence. This function must be called immediately after a call of inflate, 8947777dab0Sopenharmony_ci if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 8957777dab0Sopenharmony_ci can be determined from the Adler-32 value returned by that call of inflate. 8967777dab0Sopenharmony_ci The compressor and decompressor must use exactly the same dictionary (see 8977777dab0Sopenharmony_ci deflateSetDictionary). For raw inflate, this function can be called at any 8987777dab0Sopenharmony_ci time to set the dictionary. If the provided dictionary is smaller than the 8997777dab0Sopenharmony_ci window and there is already data in the window, then the provided dictionary 9007777dab0Sopenharmony_ci will amend what's there. The application must insure that the dictionary 9017777dab0Sopenharmony_ci that was used for compression is provided. 9027777dab0Sopenharmony_ci 9037777dab0Sopenharmony_ci inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 9047777dab0Sopenharmony_ci parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 9057777dab0Sopenharmony_ci inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 9067777dab0Sopenharmony_ci expected one (incorrect Adler-32 value). inflateSetDictionary does not 9077777dab0Sopenharmony_ci perform any decompression: this will be done by subsequent calls of 9087777dab0Sopenharmony_ci inflate(). 9097777dab0Sopenharmony_ci*/ 9107777dab0Sopenharmony_ci 9117777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, 9127777dab0Sopenharmony_ci Bytef *dictionary, 9137777dab0Sopenharmony_ci uInt *dictLength); 9147777dab0Sopenharmony_ci/* 9157777dab0Sopenharmony_ci Returns the sliding dictionary being maintained by inflate. dictLength is 9167777dab0Sopenharmony_ci set to the number of bytes in the dictionary, and that many bytes are copied 9177777dab0Sopenharmony_ci to dictionary. dictionary must have enough space, where 32768 bytes is 9187777dab0Sopenharmony_ci always enough. If inflateGetDictionary() is called with dictionary equal to 9197777dab0Sopenharmony_ci Z_NULL, then only the dictionary length is returned, and nothing is copied. 9207777dab0Sopenharmony_ci Similarly, if dictLength is Z_NULL, then it is not set. 9217777dab0Sopenharmony_ci 9227777dab0Sopenharmony_ci inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the 9237777dab0Sopenharmony_ci stream state is inconsistent. 9247777dab0Sopenharmony_ci*/ 9257777dab0Sopenharmony_ci 9267777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateSync(z_streamp strm); 9277777dab0Sopenharmony_ci/* 9287777dab0Sopenharmony_ci Skips invalid compressed data until a possible full flush point (see above 9297777dab0Sopenharmony_ci for the description of deflate with Z_FULL_FLUSH) can be found, or until all 9307777dab0Sopenharmony_ci available input is skipped. No output is provided. 9317777dab0Sopenharmony_ci 9327777dab0Sopenharmony_ci inflateSync searches for a 00 00 FF FF pattern in the compressed data. 9337777dab0Sopenharmony_ci All full flush points have this pattern, but not all occurrences of this 9347777dab0Sopenharmony_ci pattern are full flush points. 9357777dab0Sopenharmony_ci 9367777dab0Sopenharmony_ci inflateSync returns Z_OK if a possible full flush point has been found, 9377777dab0Sopenharmony_ci Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point 9387777dab0Sopenharmony_ci has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. 9397777dab0Sopenharmony_ci In the success case, the application may save the current value of total_in 9407777dab0Sopenharmony_ci which indicates where valid compressed data was found. In the error case, 9417777dab0Sopenharmony_ci the application may repeatedly call inflateSync, providing more input each 9427777dab0Sopenharmony_ci time, until success or end of the input data. 9437777dab0Sopenharmony_ci*/ 9447777dab0Sopenharmony_ci 9457777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateCopy(z_streamp dest, 9467777dab0Sopenharmony_ci z_streamp source); 9477777dab0Sopenharmony_ci/* 9487777dab0Sopenharmony_ci Sets the destination stream as a complete copy of the source stream. 9497777dab0Sopenharmony_ci 9507777dab0Sopenharmony_ci This function can be useful when randomly accessing a large stream. The 9517777dab0Sopenharmony_ci first pass through the stream can periodically record the inflate state, 9527777dab0Sopenharmony_ci allowing restarting inflate at those points when randomly accessing the 9537777dab0Sopenharmony_ci stream. 9547777dab0Sopenharmony_ci 9557777dab0Sopenharmony_ci inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 9567777dab0Sopenharmony_ci enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 9577777dab0Sopenharmony_ci (such as zalloc being Z_NULL). msg is left unchanged in both source and 9587777dab0Sopenharmony_ci destination. 9597777dab0Sopenharmony_ci*/ 9607777dab0Sopenharmony_ci 9617777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateReset(z_streamp strm); 9627777dab0Sopenharmony_ci/* 9637777dab0Sopenharmony_ci This function is equivalent to inflateEnd followed by inflateInit, 9647777dab0Sopenharmony_ci but does not free and reallocate the internal decompression state. The 9657777dab0Sopenharmony_ci stream will keep attributes that may have been set by inflateInit2. 9667777dab0Sopenharmony_ci total_in, total_out, adler, and msg are initialized. 9677777dab0Sopenharmony_ci 9687777dab0Sopenharmony_ci inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 9697777dab0Sopenharmony_ci stream state was inconsistent (such as zalloc or state being Z_NULL). 9707777dab0Sopenharmony_ci*/ 9717777dab0Sopenharmony_ci 9727777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateReset2(z_streamp strm, 9737777dab0Sopenharmony_ci int windowBits); 9747777dab0Sopenharmony_ci/* 9757777dab0Sopenharmony_ci This function is the same as inflateReset, but it also permits changing 9767777dab0Sopenharmony_ci the wrap and window size requests. The windowBits parameter is interpreted 9777777dab0Sopenharmony_ci the same as it is for inflateInit2. If the window size is changed, then the 9787777dab0Sopenharmony_ci memory allocated for the window is freed, and the window will be reallocated 9797777dab0Sopenharmony_ci by inflate() if needed. 9807777dab0Sopenharmony_ci 9817777dab0Sopenharmony_ci inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 9827777dab0Sopenharmony_ci stream state was inconsistent (such as zalloc or state being Z_NULL), or if 9837777dab0Sopenharmony_ci the windowBits parameter is invalid. 9847777dab0Sopenharmony_ci*/ 9857777dab0Sopenharmony_ci 9867777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflatePrime(z_streamp strm, 9877777dab0Sopenharmony_ci int bits, 9887777dab0Sopenharmony_ci int value); 9897777dab0Sopenharmony_ci/* 9907777dab0Sopenharmony_ci This function inserts bits in the inflate input stream. The intent is 9917777dab0Sopenharmony_ci that this function is used to start inflating at a bit position in the 9927777dab0Sopenharmony_ci middle of a byte. The provided bits will be used before any bytes are used 9937777dab0Sopenharmony_ci from next_in. This function should only be used with raw inflate, and 9947777dab0Sopenharmony_ci should be used before the first inflate() call after inflateInit2() or 9957777dab0Sopenharmony_ci inflateReset(). bits must be less than or equal to 16, and that many of the 9967777dab0Sopenharmony_ci least significant bits of value will be inserted in the input. 9977777dab0Sopenharmony_ci 9987777dab0Sopenharmony_ci If bits is negative, then the input stream bit buffer is emptied. Then 9997777dab0Sopenharmony_ci inflatePrime() can be called again to put bits in the buffer. This is used 10007777dab0Sopenharmony_ci to clear out bits leftover after feeding inflate a block description prior 10017777dab0Sopenharmony_ci to feeding inflate codes. 10027777dab0Sopenharmony_ci 10037777dab0Sopenharmony_ci inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 10047777dab0Sopenharmony_ci stream state was inconsistent. 10057777dab0Sopenharmony_ci*/ 10067777dab0Sopenharmony_ci 10077777dab0Sopenharmony_ciZEXTERN long ZEXPORT inflateMark(z_streamp strm); 10087777dab0Sopenharmony_ci/* 10097777dab0Sopenharmony_ci This function returns two values, one in the lower 16 bits of the return 10107777dab0Sopenharmony_ci value, and the other in the remaining upper bits, obtained by shifting the 10117777dab0Sopenharmony_ci return value down 16 bits. If the upper value is -1 and the lower value is 10127777dab0Sopenharmony_ci zero, then inflate() is currently decoding information outside of a block. 10137777dab0Sopenharmony_ci If the upper value is -1 and the lower value is non-zero, then inflate is in 10147777dab0Sopenharmony_ci the middle of a stored block, with the lower value equaling the number of 10157777dab0Sopenharmony_ci bytes from the input remaining to copy. If the upper value is not -1, then 10167777dab0Sopenharmony_ci it is the number of bits back from the current bit position in the input of 10177777dab0Sopenharmony_ci the code (literal or length/distance pair) currently being processed. In 10187777dab0Sopenharmony_ci that case the lower value is the number of bytes already emitted for that 10197777dab0Sopenharmony_ci code. 10207777dab0Sopenharmony_ci 10217777dab0Sopenharmony_ci A code is being processed if inflate is waiting for more input to complete 10227777dab0Sopenharmony_ci decoding of the code, or if it has completed decoding but is waiting for 10237777dab0Sopenharmony_ci more output space to write the literal or match data. 10247777dab0Sopenharmony_ci 10257777dab0Sopenharmony_ci inflateMark() is used to mark locations in the input data for random 10267777dab0Sopenharmony_ci access, which may be at bit positions, and to note those cases where the 10277777dab0Sopenharmony_ci output of a code may span boundaries of random access blocks. The current 10287777dab0Sopenharmony_ci location in the input stream can be determined from avail_in and data_type 10297777dab0Sopenharmony_ci as noted in the description for the Z_BLOCK flush parameter for inflate. 10307777dab0Sopenharmony_ci 10317777dab0Sopenharmony_ci inflateMark returns the value noted above, or -65536 if the provided 10327777dab0Sopenharmony_ci source stream state was inconsistent. 10337777dab0Sopenharmony_ci*/ 10347777dab0Sopenharmony_ci 10357777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, 10367777dab0Sopenharmony_ci gz_headerp head); 10377777dab0Sopenharmony_ci/* 10387777dab0Sopenharmony_ci inflateGetHeader() requests that gzip header information be stored in the 10397777dab0Sopenharmony_ci provided gz_header structure. inflateGetHeader() may be called after 10407777dab0Sopenharmony_ci inflateInit2() or inflateReset(), and before the first call of inflate(). 10417777dab0Sopenharmony_ci As inflate() processes the gzip stream, head->done is zero until the header 10427777dab0Sopenharmony_ci is completed, at which time head->done is set to one. If a zlib stream is 10437777dab0Sopenharmony_ci being decoded, then head->done is set to -1 to indicate that there will be 10447777dab0Sopenharmony_ci no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be 10457777dab0Sopenharmony_ci used to force inflate() to return immediately after header processing is 10467777dab0Sopenharmony_ci complete and before any actual data is decompressed. 10477777dab0Sopenharmony_ci 10487777dab0Sopenharmony_ci The text, time, xflags, and os fields are filled in with the gzip header 10497777dab0Sopenharmony_ci contents. hcrc is set to true if there is a header CRC. (The header CRC 10507777dab0Sopenharmony_ci was valid if done is set to one.) If extra is not Z_NULL, then extra_max 10517777dab0Sopenharmony_ci contains the maximum number of bytes to write to extra. Once done is true, 10527777dab0Sopenharmony_ci extra_len contains the actual extra field length, and extra contains the 10537777dab0Sopenharmony_ci extra field, or that field truncated if extra_max is less than extra_len. 10547777dab0Sopenharmony_ci If name is not Z_NULL, then up to name_max characters are written there, 10557777dab0Sopenharmony_ci terminated with a zero unless the length is greater than name_max. If 10567777dab0Sopenharmony_ci comment is not Z_NULL, then up to comm_max characters are written there, 10577777dab0Sopenharmony_ci terminated with a zero unless the length is greater than comm_max. When any 10587777dab0Sopenharmony_ci of extra, name, or comment are not Z_NULL and the respective field is not 10597777dab0Sopenharmony_ci present in the header, then that field is set to Z_NULL to signal its 10607777dab0Sopenharmony_ci absence. This allows the use of deflateSetHeader() with the returned 10617777dab0Sopenharmony_ci structure to duplicate the header. However if those fields are set to 10627777dab0Sopenharmony_ci allocated memory, then the application will need to save those pointers 10637777dab0Sopenharmony_ci elsewhere so that they can be eventually freed. 10647777dab0Sopenharmony_ci 10657777dab0Sopenharmony_ci If inflateGetHeader is not used, then the header information is simply 10667777dab0Sopenharmony_ci discarded. The header is always checked for validity, including the header 10677777dab0Sopenharmony_ci CRC if present. inflateReset() will reset the process to discard the header 10687777dab0Sopenharmony_ci information. The application would need to call inflateGetHeader() again to 10697777dab0Sopenharmony_ci retrieve the header from the next gzip stream. 10707777dab0Sopenharmony_ci 10717777dab0Sopenharmony_ci inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 10727777dab0Sopenharmony_ci stream state was inconsistent. 10737777dab0Sopenharmony_ci*/ 10747777dab0Sopenharmony_ci 10757777dab0Sopenharmony_ci/* 10767777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, 10777777dab0Sopenharmony_ci unsigned char FAR *window); 10787777dab0Sopenharmony_ci 10797777dab0Sopenharmony_ci Initialize the internal stream state for decompression using inflateBack() 10807777dab0Sopenharmony_ci calls. The fields zalloc, zfree and opaque in strm must be initialized 10817777dab0Sopenharmony_ci before the call. If zalloc and zfree are Z_NULL, then the default library- 10827777dab0Sopenharmony_ci derived memory allocation routines are used. windowBits is the base two 10837777dab0Sopenharmony_ci logarithm of the window size, in the range 8..15. window is a caller 10847777dab0Sopenharmony_ci supplied buffer of that size. Except for special applications where it is 10857777dab0Sopenharmony_ci assured that deflate was used with small window sizes, windowBits must be 15 10867777dab0Sopenharmony_ci and a 32K byte window must be supplied to be able to decompress general 10877777dab0Sopenharmony_ci deflate streams. 10887777dab0Sopenharmony_ci 10897777dab0Sopenharmony_ci See inflateBack() for the usage of these routines. 10907777dab0Sopenharmony_ci 10917777dab0Sopenharmony_ci inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 10927777dab0Sopenharmony_ci the parameters are invalid, Z_MEM_ERROR if the internal state could not be 10937777dab0Sopenharmony_ci allocated, or Z_VERSION_ERROR if the version of the library does not match 10947777dab0Sopenharmony_ci the version of the header file. 10957777dab0Sopenharmony_ci*/ 10967777dab0Sopenharmony_ci 10977777dab0Sopenharmony_citypedef unsigned (*in_func)(void FAR *, 10987777dab0Sopenharmony_ci z_const unsigned char FAR * FAR *); 10997777dab0Sopenharmony_citypedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); 11007777dab0Sopenharmony_ci 11017777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateBack(z_streamp strm, 11027777dab0Sopenharmony_ci in_func in, void FAR *in_desc, 11037777dab0Sopenharmony_ci out_func out, void FAR *out_desc); 11047777dab0Sopenharmony_ci/* 11057777dab0Sopenharmony_ci inflateBack() does a raw inflate with a single call using a call-back 11067777dab0Sopenharmony_ci interface for input and output. This is potentially more efficient than 11077777dab0Sopenharmony_ci inflate() for file i/o applications, in that it avoids copying between the 11087777dab0Sopenharmony_ci output and the sliding window by simply making the window itself the output 11097777dab0Sopenharmony_ci buffer. inflate() can be faster on modern CPUs when used with large 11107777dab0Sopenharmony_ci buffers. inflateBack() trusts the application to not change the output 11117777dab0Sopenharmony_ci buffer passed by the output function, at least until inflateBack() returns. 11127777dab0Sopenharmony_ci 11137777dab0Sopenharmony_ci inflateBackInit() must be called first to allocate the internal state 11147777dab0Sopenharmony_ci and to initialize the state with the user-provided window buffer. 11157777dab0Sopenharmony_ci inflateBack() may then be used multiple times to inflate a complete, raw 11167777dab0Sopenharmony_ci deflate stream with each call. inflateBackEnd() is then called to free the 11177777dab0Sopenharmony_ci allocated state. 11187777dab0Sopenharmony_ci 11197777dab0Sopenharmony_ci A raw deflate stream is one with no zlib or gzip header or trailer. 11207777dab0Sopenharmony_ci This routine would normally be used in a utility that reads zip or gzip 11217777dab0Sopenharmony_ci files and writes out uncompressed files. The utility would decode the 11227777dab0Sopenharmony_ci header and process the trailer on its own, hence this routine expects only 11237777dab0Sopenharmony_ci the raw deflate stream to decompress. This is different from the default 11247777dab0Sopenharmony_ci behavior of inflate(), which expects a zlib header and trailer around the 11257777dab0Sopenharmony_ci deflate stream. 11267777dab0Sopenharmony_ci 11277777dab0Sopenharmony_ci inflateBack() uses two subroutines supplied by the caller that are then 11287777dab0Sopenharmony_ci called by inflateBack() for input and output. inflateBack() calls those 11297777dab0Sopenharmony_ci routines until it reads a complete deflate stream and writes out all of the 11307777dab0Sopenharmony_ci uncompressed data, or until it encounters an error. The function's 11317777dab0Sopenharmony_ci parameters and return types are defined above in the in_func and out_func 11327777dab0Sopenharmony_ci typedefs. inflateBack() will call in(in_desc, &buf) which should return the 11337777dab0Sopenharmony_ci number of bytes of provided input, and a pointer to that input in buf. If 11347777dab0Sopenharmony_ci there is no input available, in() must return zero -- buf is ignored in that 11357777dab0Sopenharmony_ci case -- and inflateBack() will return a buffer error. inflateBack() will 11367777dab0Sopenharmony_ci call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. 11377777dab0Sopenharmony_ci out() should return zero on success, or non-zero on failure. If out() 11387777dab0Sopenharmony_ci returns non-zero, inflateBack() will return with an error. Neither in() nor 11397777dab0Sopenharmony_ci out() are permitted to change the contents of the window provided to 11407777dab0Sopenharmony_ci inflateBackInit(), which is also the buffer that out() uses to write from. 11417777dab0Sopenharmony_ci The length written by out() will be at most the window size. Any non-zero 11427777dab0Sopenharmony_ci amount of input may be provided by in(). 11437777dab0Sopenharmony_ci 11447777dab0Sopenharmony_ci For convenience, inflateBack() can be provided input on the first call by 11457777dab0Sopenharmony_ci setting strm->next_in and strm->avail_in. If that input is exhausted, then 11467777dab0Sopenharmony_ci in() will be called. Therefore strm->next_in must be initialized before 11477777dab0Sopenharmony_ci calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 11487777dab0Sopenharmony_ci immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 11497777dab0Sopenharmony_ci must also be initialized, and then if strm->avail_in is not zero, input will 11507777dab0Sopenharmony_ci initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 11517777dab0Sopenharmony_ci 11527777dab0Sopenharmony_ci The in_desc and out_desc parameters of inflateBack() is passed as the 11537777dab0Sopenharmony_ci first parameter of in() and out() respectively when they are called. These 11547777dab0Sopenharmony_ci descriptors can be optionally used to pass any information that the caller- 11557777dab0Sopenharmony_ci supplied in() and out() functions need to do their job. 11567777dab0Sopenharmony_ci 11577777dab0Sopenharmony_ci On return, inflateBack() will set strm->next_in and strm->avail_in to 11587777dab0Sopenharmony_ci pass back any unused input that was provided by the last in() call. The 11597777dab0Sopenharmony_ci return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 11607777dab0Sopenharmony_ci if in() or out() returned an error, Z_DATA_ERROR if there was a format error 11617777dab0Sopenharmony_ci in the deflate stream (in which case strm->msg is set to indicate the nature 11627777dab0Sopenharmony_ci of the error), or Z_STREAM_ERROR if the stream was not properly initialized. 11637777dab0Sopenharmony_ci In the case of Z_BUF_ERROR, an input or output error can be distinguished 11647777dab0Sopenharmony_ci using strm->next_in which will be Z_NULL only if in() returned an error. If 11657777dab0Sopenharmony_ci strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning 11667777dab0Sopenharmony_ci non-zero. (in() will always be called before out(), so strm->next_in is 11677777dab0Sopenharmony_ci assured to be defined if out() returns non-zero.) Note that inflateBack() 11687777dab0Sopenharmony_ci cannot return Z_OK. 11697777dab0Sopenharmony_ci*/ 11707777dab0Sopenharmony_ci 11717777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); 11727777dab0Sopenharmony_ci/* 11737777dab0Sopenharmony_ci All memory allocated by inflateBackInit() is freed. 11747777dab0Sopenharmony_ci 11757777dab0Sopenharmony_ci inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 11767777dab0Sopenharmony_ci state was inconsistent. 11777777dab0Sopenharmony_ci*/ 11787777dab0Sopenharmony_ci 11797777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT zlibCompileFlags(void); 11807777dab0Sopenharmony_ci/* Return flags indicating compile-time options. 11817777dab0Sopenharmony_ci 11827777dab0Sopenharmony_ci Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 11837777dab0Sopenharmony_ci 1.0: size of uInt 11847777dab0Sopenharmony_ci 3.2: size of uLong 11857777dab0Sopenharmony_ci 5.4: size of voidpf (pointer) 11867777dab0Sopenharmony_ci 7.6: size of z_off_t 11877777dab0Sopenharmony_ci 11887777dab0Sopenharmony_ci Compiler, assembler, and debug options: 11897777dab0Sopenharmony_ci 8: ZLIB_DEBUG 11907777dab0Sopenharmony_ci 9: ASMV or ASMINF -- use ASM code 11917777dab0Sopenharmony_ci 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 11927777dab0Sopenharmony_ci 11: 0 (reserved) 11937777dab0Sopenharmony_ci 11947777dab0Sopenharmony_ci One-time table building (smaller code, but not thread-safe if true): 11957777dab0Sopenharmony_ci 12: BUILDFIXED -- build static block decoding tables when needed 11967777dab0Sopenharmony_ci 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 11977777dab0Sopenharmony_ci 14,15: 0 (reserved) 11987777dab0Sopenharmony_ci 11997777dab0Sopenharmony_ci Library content (indicates missing functionality): 12007777dab0Sopenharmony_ci 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 12017777dab0Sopenharmony_ci deflate code when not needed) 12027777dab0Sopenharmony_ci 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 12037777dab0Sopenharmony_ci and decode gzip streams (to avoid linking crc code) 12047777dab0Sopenharmony_ci 18-19: 0 (reserved) 12057777dab0Sopenharmony_ci 12067777dab0Sopenharmony_ci Operation variations (changes in library functionality): 12077777dab0Sopenharmony_ci 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 12087777dab0Sopenharmony_ci 21: FASTEST -- deflate algorithm with only one, lowest compression level 12097777dab0Sopenharmony_ci 22,23: 0 (reserved) 12107777dab0Sopenharmony_ci 12117777dab0Sopenharmony_ci The sprintf variant used by gzprintf (zero is best): 12127777dab0Sopenharmony_ci 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 12137777dab0Sopenharmony_ci 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 12147777dab0Sopenharmony_ci 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 12157777dab0Sopenharmony_ci 12167777dab0Sopenharmony_ci Remainder: 12177777dab0Sopenharmony_ci 27-31: 0 (reserved) 12187777dab0Sopenharmony_ci */ 12197777dab0Sopenharmony_ci 12207777dab0Sopenharmony_ci#ifndef Z_SOLO 12217777dab0Sopenharmony_ci 12227777dab0Sopenharmony_ci /* utility functions */ 12237777dab0Sopenharmony_ci 12247777dab0Sopenharmony_ci/* 12257777dab0Sopenharmony_ci The following utility functions are implemented on top of the basic 12267777dab0Sopenharmony_ci stream-oriented functions. To simplify the interface, some default options 12277777dab0Sopenharmony_ci are assumed (compression level and memory usage, standard memory allocation 12287777dab0Sopenharmony_ci functions). The source code of these utility functions can be modified if 12297777dab0Sopenharmony_ci you need special options. 12307777dab0Sopenharmony_ci*/ 12317777dab0Sopenharmony_ci 12327777dab0Sopenharmony_ciZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, 12337777dab0Sopenharmony_ci const Bytef *source, uLong sourceLen); 12347777dab0Sopenharmony_ci/* 12357777dab0Sopenharmony_ci Compresses the source buffer into the destination buffer. sourceLen is 12367777dab0Sopenharmony_ci the byte length of the source buffer. Upon entry, destLen is the total size 12377777dab0Sopenharmony_ci of the destination buffer, which must be at least the value returned by 12387777dab0Sopenharmony_ci compressBound(sourceLen). Upon exit, destLen is the actual size of the 12397777dab0Sopenharmony_ci compressed data. compress() is equivalent to compress2() with a level 12407777dab0Sopenharmony_ci parameter of Z_DEFAULT_COMPRESSION. 12417777dab0Sopenharmony_ci 12427777dab0Sopenharmony_ci compress returns Z_OK if success, Z_MEM_ERROR if there was not 12437777dab0Sopenharmony_ci enough memory, Z_BUF_ERROR if there was not enough room in the output 12447777dab0Sopenharmony_ci buffer. 12457777dab0Sopenharmony_ci*/ 12467777dab0Sopenharmony_ci 12477777dab0Sopenharmony_ciZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, 12487777dab0Sopenharmony_ci const Bytef *source, uLong sourceLen, 12497777dab0Sopenharmony_ci int level); 12507777dab0Sopenharmony_ci/* 12517777dab0Sopenharmony_ci Compresses the source buffer into the destination buffer. The level 12527777dab0Sopenharmony_ci parameter has the same meaning as in deflateInit. sourceLen is the byte 12537777dab0Sopenharmony_ci length of the source buffer. Upon entry, destLen is the total size of the 12547777dab0Sopenharmony_ci destination buffer, which must be at least the value returned by 12557777dab0Sopenharmony_ci compressBound(sourceLen). Upon exit, destLen is the actual size of the 12567777dab0Sopenharmony_ci compressed data. 12577777dab0Sopenharmony_ci 12587777dab0Sopenharmony_ci compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 12597777dab0Sopenharmony_ci memory, Z_BUF_ERROR if there was not enough room in the output buffer, 12607777dab0Sopenharmony_ci Z_STREAM_ERROR if the level parameter is invalid. 12617777dab0Sopenharmony_ci*/ 12627777dab0Sopenharmony_ci 12637777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); 12647777dab0Sopenharmony_ci/* 12657777dab0Sopenharmony_ci compressBound() returns an upper bound on the compressed size after 12667777dab0Sopenharmony_ci compress() or compress2() on sourceLen bytes. It would be used before a 12677777dab0Sopenharmony_ci compress() or compress2() call to allocate the destination buffer. 12687777dab0Sopenharmony_ci*/ 12697777dab0Sopenharmony_ci 12707777dab0Sopenharmony_ciZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, 12717777dab0Sopenharmony_ci const Bytef *source, uLong sourceLen); 12727777dab0Sopenharmony_ci/* 12737777dab0Sopenharmony_ci Decompresses the source buffer into the destination buffer. sourceLen is 12747777dab0Sopenharmony_ci the byte length of the source buffer. Upon entry, destLen is the total size 12757777dab0Sopenharmony_ci of the destination buffer, which must be large enough to hold the entire 12767777dab0Sopenharmony_ci uncompressed data. (The size of the uncompressed data must have been saved 12777777dab0Sopenharmony_ci previously by the compressor and transmitted to the decompressor by some 12787777dab0Sopenharmony_ci mechanism outside the scope of this compression library.) Upon exit, destLen 12797777dab0Sopenharmony_ci is the actual size of the uncompressed data. 12807777dab0Sopenharmony_ci 12817777dab0Sopenharmony_ci uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 12827777dab0Sopenharmony_ci enough memory, Z_BUF_ERROR if there was not enough room in the output 12837777dab0Sopenharmony_ci buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In 12847777dab0Sopenharmony_ci the case where there is not enough room, uncompress() will fill the output 12857777dab0Sopenharmony_ci buffer with the uncompressed data up to that point. 12867777dab0Sopenharmony_ci*/ 12877777dab0Sopenharmony_ci 12887777dab0Sopenharmony_ciZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, 12897777dab0Sopenharmony_ci const Bytef *source, uLong *sourceLen); 12907777dab0Sopenharmony_ci/* 12917777dab0Sopenharmony_ci Same as uncompress, except that sourceLen is a pointer, where the 12927777dab0Sopenharmony_ci length of the source is *sourceLen. On return, *sourceLen is the number of 12937777dab0Sopenharmony_ci source bytes consumed. 12947777dab0Sopenharmony_ci*/ 12957777dab0Sopenharmony_ci 12967777dab0Sopenharmony_ci /* gzip file access functions */ 12977777dab0Sopenharmony_ci 12987777dab0Sopenharmony_ci/* 12997777dab0Sopenharmony_ci This library supports reading and writing files in gzip (.gz) format with 13007777dab0Sopenharmony_ci an interface similar to that of stdio, using the functions that start with 13017777dab0Sopenharmony_ci "gz". The gzip format is different from the zlib format. gzip is a gzip 13027777dab0Sopenharmony_ci wrapper, documented in RFC 1952, wrapped around a deflate stream. 13037777dab0Sopenharmony_ci*/ 13047777dab0Sopenharmony_ci 13057777dab0Sopenharmony_citypedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ 13067777dab0Sopenharmony_ci 13077777dab0Sopenharmony_ci/* 13087777dab0Sopenharmony_ciZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); 13097777dab0Sopenharmony_ci 13107777dab0Sopenharmony_ci Open the gzip (.gz) file at path for reading and decompressing, or 13117777dab0Sopenharmony_ci compressing and writing. The mode parameter is as in fopen ("rb" or "wb") 13127777dab0Sopenharmony_ci but can also include a compression level ("wb9") or a strategy: 'f' for 13137777dab0Sopenharmony_ci filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h", 13147777dab0Sopenharmony_ci 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression 13157777dab0Sopenharmony_ci as in "wb9F". (See the description of deflateInit2 for more information 13167777dab0Sopenharmony_ci about the strategy parameter.) 'T' will request transparent writing or 13177777dab0Sopenharmony_ci appending with no compression and not using the gzip format. 13187777dab0Sopenharmony_ci 13197777dab0Sopenharmony_ci "a" can be used instead of "w" to request that the gzip stream that will 13207777dab0Sopenharmony_ci be written be appended to the file. "+" will result in an error, since 13217777dab0Sopenharmony_ci reading and writing to the same gzip file is not supported. The addition of 13227777dab0Sopenharmony_ci "x" when writing will create the file exclusively, which fails if the file 13237777dab0Sopenharmony_ci already exists. On systems that support it, the addition of "e" when 13247777dab0Sopenharmony_ci reading or writing will set the flag to close the file on an execve() call. 13257777dab0Sopenharmony_ci 13267777dab0Sopenharmony_ci These functions, as well as gzip, will read and decode a sequence of gzip 13277777dab0Sopenharmony_ci streams in a file. The append function of gzopen() can be used to create 13287777dab0Sopenharmony_ci such a file. (Also see gzflush() for another way to do this.) When 13297777dab0Sopenharmony_ci appending, gzopen does not test whether the file begins with a gzip stream, 13307777dab0Sopenharmony_ci nor does it look for the end of the gzip streams to begin appending. gzopen 13317777dab0Sopenharmony_ci will simply append a gzip stream to the existing file. 13327777dab0Sopenharmony_ci 13337777dab0Sopenharmony_ci gzopen can be used to read a file which is not in gzip format; in this 13347777dab0Sopenharmony_ci case gzread will directly read from the file without decompression. When 13357777dab0Sopenharmony_ci reading, this will be detected automatically by looking for the magic two- 13367777dab0Sopenharmony_ci byte gzip header. 13377777dab0Sopenharmony_ci 13387777dab0Sopenharmony_ci gzopen returns NULL if the file could not be opened, if there was 13397777dab0Sopenharmony_ci insufficient memory to allocate the gzFile state, or if an invalid mode was 13407777dab0Sopenharmony_ci specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). 13417777dab0Sopenharmony_ci errno can be checked to determine if the reason gzopen failed was that the 13427777dab0Sopenharmony_ci file could not be opened. 13437777dab0Sopenharmony_ci*/ 13447777dab0Sopenharmony_ci 13457777dab0Sopenharmony_ciZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); 13467777dab0Sopenharmony_ci/* 13477777dab0Sopenharmony_ci Associate a gzFile with the file descriptor fd. File descriptors are 13487777dab0Sopenharmony_ci obtained from calls like open, dup, creat, pipe or fileno (if the file has 13497777dab0Sopenharmony_ci been previously opened with fopen). The mode parameter is as in gzopen. 13507777dab0Sopenharmony_ci 13517777dab0Sopenharmony_ci The next call of gzclose on the returned gzFile will also close the file 13527777dab0Sopenharmony_ci descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor 13537777dab0Sopenharmony_ci fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, 13547777dab0Sopenharmony_ci mode);. The duplicated descriptor should be saved to avoid a leak, since 13557777dab0Sopenharmony_ci gzdopen does not close fd if it fails. If you are using fileno() to get the 13567777dab0Sopenharmony_ci file descriptor from a FILE *, then you will have to use dup() to avoid 13577777dab0Sopenharmony_ci double-close()ing the file descriptor. Both gzclose() and fclose() will 13587777dab0Sopenharmony_ci close the associated file descriptor, so they need to have different file 13597777dab0Sopenharmony_ci descriptors. 13607777dab0Sopenharmony_ci 13617777dab0Sopenharmony_ci gzdopen returns NULL if there was insufficient memory to allocate the 13627777dab0Sopenharmony_ci gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not 13637777dab0Sopenharmony_ci provided, or '+' was provided), or if fd is -1. The file descriptor is not 13647777dab0Sopenharmony_ci used until the next gz* read, write, seek, or close operation, so gzdopen 13657777dab0Sopenharmony_ci will not detect if fd is invalid (unless fd is -1). 13667777dab0Sopenharmony_ci*/ 13677777dab0Sopenharmony_ci 13687777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); 13697777dab0Sopenharmony_ci/* 13707777dab0Sopenharmony_ci Set the internal buffer size used by this library's functions for file to 13717777dab0Sopenharmony_ci size. The default buffer size is 8192 bytes. This function must be called 13727777dab0Sopenharmony_ci after gzopen() or gzdopen(), and before any other calls that read or write 13737777dab0Sopenharmony_ci the file. The buffer memory allocation is always deferred to the first read 13747777dab0Sopenharmony_ci or write. Three times that size in buffer space is allocated. A larger 13757777dab0Sopenharmony_ci buffer size of, for example, 64K or 128K bytes will noticeably increase the 13767777dab0Sopenharmony_ci speed of decompression (reading). 13777777dab0Sopenharmony_ci 13787777dab0Sopenharmony_ci The new buffer size also affects the maximum length for gzprintf(). 13797777dab0Sopenharmony_ci 13807777dab0Sopenharmony_ci gzbuffer() returns 0 on success, or -1 on failure, such as being called 13817777dab0Sopenharmony_ci too late. 13827777dab0Sopenharmony_ci*/ 13837777dab0Sopenharmony_ci 13847777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); 13857777dab0Sopenharmony_ci/* 13867777dab0Sopenharmony_ci Dynamically update the compression level and strategy for file. See the 13877777dab0Sopenharmony_ci description of deflateInit2 for the meaning of these parameters. Previously 13887777dab0Sopenharmony_ci provided data is flushed before applying the parameter changes. 13897777dab0Sopenharmony_ci 13907777dab0Sopenharmony_ci gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not 13917777dab0Sopenharmony_ci opened for writing, Z_ERRNO if there is an error writing the flushed data, 13927777dab0Sopenharmony_ci or Z_MEM_ERROR if there is a memory allocation error. 13937777dab0Sopenharmony_ci*/ 13947777dab0Sopenharmony_ci 13957777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); 13967777dab0Sopenharmony_ci/* 13977777dab0Sopenharmony_ci Read and decompress up to len uncompressed bytes from file into buf. If 13987777dab0Sopenharmony_ci the input file is not in gzip format, gzread copies the given number of 13997777dab0Sopenharmony_ci bytes into the buffer directly from the file. 14007777dab0Sopenharmony_ci 14017777dab0Sopenharmony_ci After reaching the end of a gzip stream in the input, gzread will continue 14027777dab0Sopenharmony_ci to read, looking for another gzip stream. Any number of gzip streams may be 14037777dab0Sopenharmony_ci concatenated in the input file, and will all be decompressed by gzread(). 14047777dab0Sopenharmony_ci If something other than a gzip stream is encountered after a gzip stream, 14057777dab0Sopenharmony_ci that remaining trailing garbage is ignored (and no error is returned). 14067777dab0Sopenharmony_ci 14077777dab0Sopenharmony_ci gzread can be used to read a gzip file that is being concurrently written. 14087777dab0Sopenharmony_ci Upon reaching the end of the input, gzread will return with the available 14097777dab0Sopenharmony_ci data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then 14107777dab0Sopenharmony_ci gzclearerr can be used to clear the end of file indicator in order to permit 14117777dab0Sopenharmony_ci gzread to be tried again. Z_OK indicates that a gzip stream was completed 14127777dab0Sopenharmony_ci on the last gzread. Z_BUF_ERROR indicates that the input file ended in the 14137777dab0Sopenharmony_ci middle of a gzip stream. Note that gzread does not return -1 in the event 14147777dab0Sopenharmony_ci of an incomplete gzip stream. This error is deferred until gzclose(), which 14157777dab0Sopenharmony_ci will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip 14167777dab0Sopenharmony_ci stream. Alternatively, gzerror can be used before gzclose to detect this 14177777dab0Sopenharmony_ci case. 14187777dab0Sopenharmony_ci 14197777dab0Sopenharmony_ci gzread returns the number of uncompressed bytes actually read, less than 14207777dab0Sopenharmony_ci len for end of file, or -1 for error. If len is too large to fit in an int, 14217777dab0Sopenharmony_ci then nothing is read, -1 is returned, and the error state is set to 14227777dab0Sopenharmony_ci Z_STREAM_ERROR. 14237777dab0Sopenharmony_ci*/ 14247777dab0Sopenharmony_ci 14257777dab0Sopenharmony_ciZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, 14267777dab0Sopenharmony_ci gzFile file); 14277777dab0Sopenharmony_ci/* 14287777dab0Sopenharmony_ci Read and decompress up to nitems items of size size from file into buf, 14297777dab0Sopenharmony_ci otherwise operating as gzread() does. This duplicates the interface of 14307777dab0Sopenharmony_ci stdio's fread(), with size_t request and return types. If the library 14317777dab0Sopenharmony_ci defines size_t, then z_size_t is identical to size_t. If not, then z_size_t 14327777dab0Sopenharmony_ci is an unsigned integer type that can contain a pointer. 14337777dab0Sopenharmony_ci 14347777dab0Sopenharmony_ci gzfread() returns the number of full items read of size size, or zero if 14357777dab0Sopenharmony_ci the end of the file was reached and a full item could not be read, or if 14367777dab0Sopenharmony_ci there was an error. gzerror() must be consulted if zero is returned in 14377777dab0Sopenharmony_ci order to determine if there was an error. If the multiplication of size and 14387777dab0Sopenharmony_ci nitems overflows, i.e. the product does not fit in a z_size_t, then nothing 14397777dab0Sopenharmony_ci is read, zero is returned, and the error state is set to Z_STREAM_ERROR. 14407777dab0Sopenharmony_ci 14417777dab0Sopenharmony_ci In the event that the end of file is reached and only a partial item is 14427777dab0Sopenharmony_ci available at the end, i.e. the remaining uncompressed data length is not a 14437777dab0Sopenharmony_ci multiple of size, then the final partial item is nevertheless read into buf 14447777dab0Sopenharmony_ci and the end-of-file flag is set. The length of the partial item read is not 14457777dab0Sopenharmony_ci provided, but could be inferred from the result of gztell(). This behavior 14467777dab0Sopenharmony_ci is the same as the behavior of fread() implementations in common libraries, 14477777dab0Sopenharmony_ci but it prevents the direct use of gzfread() to read a concurrently written 14487777dab0Sopenharmony_ci file, resetting and retrying on end-of-file, when size is not 1. 14497777dab0Sopenharmony_ci*/ 14507777dab0Sopenharmony_ci 14517777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); 14527777dab0Sopenharmony_ci/* 14537777dab0Sopenharmony_ci Compress and write the len uncompressed bytes at buf to file. gzwrite 14547777dab0Sopenharmony_ci returns the number of uncompressed bytes written or 0 in case of error. 14557777dab0Sopenharmony_ci*/ 14567777dab0Sopenharmony_ci 14577777dab0Sopenharmony_ciZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, 14587777dab0Sopenharmony_ci z_size_t nitems, gzFile file); 14597777dab0Sopenharmony_ci/* 14607777dab0Sopenharmony_ci Compress and write nitems items of size size from buf to file, duplicating 14617777dab0Sopenharmony_ci the interface of stdio's fwrite(), with size_t request and return types. If 14627777dab0Sopenharmony_ci the library defines size_t, then z_size_t is identical to size_t. If not, 14637777dab0Sopenharmony_ci then z_size_t is an unsigned integer type that can contain a pointer. 14647777dab0Sopenharmony_ci 14657777dab0Sopenharmony_ci gzfwrite() returns the number of full items written of size size, or zero 14667777dab0Sopenharmony_ci if there was an error. If the multiplication of size and nitems overflows, 14677777dab0Sopenharmony_ci i.e. the product does not fit in a z_size_t, then nothing is written, zero 14687777dab0Sopenharmony_ci is returned, and the error state is set to Z_STREAM_ERROR. 14697777dab0Sopenharmony_ci*/ 14707777dab0Sopenharmony_ci 14717777dab0Sopenharmony_ciZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); 14727777dab0Sopenharmony_ci/* 14737777dab0Sopenharmony_ci Convert, format, compress, and write the arguments (...) to file under 14747777dab0Sopenharmony_ci control of the string format, as in fprintf. gzprintf returns the number of 14757777dab0Sopenharmony_ci uncompressed bytes actually written, or a negative zlib error code in case 14767777dab0Sopenharmony_ci of error. The number of uncompressed bytes written is limited to 8191, or 14777777dab0Sopenharmony_ci one less than the buffer size given to gzbuffer(). The caller should assure 14787777dab0Sopenharmony_ci that this limit is not exceeded. If it is exceeded, then gzprintf() will 14797777dab0Sopenharmony_ci return an error (0) with nothing written. In this case, there may also be a 14807777dab0Sopenharmony_ci buffer overflow with unpredictable consequences, which is possible only if 14817777dab0Sopenharmony_ci zlib was compiled with the insecure functions sprintf() or vsprintf(), 14827777dab0Sopenharmony_ci because the secure snprintf() or vsnprintf() functions were not available. 14837777dab0Sopenharmony_ci This can be determined using zlibCompileFlags(). 14847777dab0Sopenharmony_ci*/ 14857777dab0Sopenharmony_ci 14867777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); 14877777dab0Sopenharmony_ci/* 14887777dab0Sopenharmony_ci Compress and write the given null-terminated string s to file, excluding 14897777dab0Sopenharmony_ci the terminating null character. 14907777dab0Sopenharmony_ci 14917777dab0Sopenharmony_ci gzputs returns the number of characters written, or -1 in case of error. 14927777dab0Sopenharmony_ci*/ 14937777dab0Sopenharmony_ci 14947777dab0Sopenharmony_ciZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); 14957777dab0Sopenharmony_ci/* 14967777dab0Sopenharmony_ci Read and decompress bytes from file into buf, until len-1 characters are 14977777dab0Sopenharmony_ci read, or until a newline character is read and transferred to buf, or an 14987777dab0Sopenharmony_ci end-of-file condition is encountered. If any characters are read or if len 14997777dab0Sopenharmony_ci is one, the string is terminated with a null character. If no characters 15007777dab0Sopenharmony_ci are read due to an end-of-file or len is less than one, then the buffer is 15017777dab0Sopenharmony_ci left untouched. 15027777dab0Sopenharmony_ci 15037777dab0Sopenharmony_ci gzgets returns buf which is a null-terminated string, or it returns NULL 15047777dab0Sopenharmony_ci for end-of-file or in case of error. If there was an error, the contents at 15057777dab0Sopenharmony_ci buf are indeterminate. 15067777dab0Sopenharmony_ci*/ 15077777dab0Sopenharmony_ci 15087777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzputc(gzFile file, int c); 15097777dab0Sopenharmony_ci/* 15107777dab0Sopenharmony_ci Compress and write c, converted to an unsigned char, into file. gzputc 15117777dab0Sopenharmony_ci returns the value that was written, or -1 in case of error. 15127777dab0Sopenharmony_ci*/ 15137777dab0Sopenharmony_ci 15147777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzgetc(gzFile file); 15157777dab0Sopenharmony_ci/* 15167777dab0Sopenharmony_ci Read and decompress one byte from file. gzgetc returns this byte or -1 15177777dab0Sopenharmony_ci in case of end of file or error. This is implemented as a macro for speed. 15187777dab0Sopenharmony_ci As such, it does not do all of the checking the other functions do. I.e. 15197777dab0Sopenharmony_ci it does not check to see if file is NULL, nor whether the structure file 15207777dab0Sopenharmony_ci points to has been clobbered or not. 15217777dab0Sopenharmony_ci*/ 15227777dab0Sopenharmony_ci 15237777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzungetc(int c, gzFile file); 15247777dab0Sopenharmony_ci/* 15257777dab0Sopenharmony_ci Push c back onto the stream for file to be read as the first character on 15267777dab0Sopenharmony_ci the next read. At least one character of push-back is always allowed. 15277777dab0Sopenharmony_ci gzungetc() returns the character pushed, or -1 on failure. gzungetc() will 15287777dab0Sopenharmony_ci fail if c is -1, and may fail if a character has been pushed but not read 15297777dab0Sopenharmony_ci yet. If gzungetc is used immediately after gzopen or gzdopen, at least the 15307777dab0Sopenharmony_ci output buffer size of pushed characters is allowed. (See gzbuffer above.) 15317777dab0Sopenharmony_ci The pushed character will be discarded if the stream is repositioned with 15327777dab0Sopenharmony_ci gzseek() or gzrewind(). 15337777dab0Sopenharmony_ci*/ 15347777dab0Sopenharmony_ci 15357777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzflush(gzFile file, int flush); 15367777dab0Sopenharmony_ci/* 15377777dab0Sopenharmony_ci Flush all pending output to file. The parameter flush is as in the 15387777dab0Sopenharmony_ci deflate() function. The return value is the zlib error number (see function 15397777dab0Sopenharmony_ci gzerror below). gzflush is only permitted when writing. 15407777dab0Sopenharmony_ci 15417777dab0Sopenharmony_ci If the flush parameter is Z_FINISH, the remaining data is written and the 15427777dab0Sopenharmony_ci gzip stream is completed in the output. If gzwrite() is called again, a new 15437777dab0Sopenharmony_ci gzip stream will be started in the output. gzread() is able to read such 15447777dab0Sopenharmony_ci concatenated gzip streams. 15457777dab0Sopenharmony_ci 15467777dab0Sopenharmony_ci gzflush should be called only when strictly necessary because it will 15477777dab0Sopenharmony_ci degrade compression if called too often. 15487777dab0Sopenharmony_ci*/ 15497777dab0Sopenharmony_ci 15507777dab0Sopenharmony_ci/* 15517777dab0Sopenharmony_ciZEXTERN z_off_t ZEXPORT gzseek(gzFile file, 15527777dab0Sopenharmony_ci z_off_t offset, int whence); 15537777dab0Sopenharmony_ci 15547777dab0Sopenharmony_ci Set the starting position to offset relative to whence for the next gzread 15557777dab0Sopenharmony_ci or gzwrite on file. The offset represents a number of bytes in the 15567777dab0Sopenharmony_ci uncompressed data stream. The whence parameter is defined as in lseek(2); 15577777dab0Sopenharmony_ci the value SEEK_END is not supported. 15587777dab0Sopenharmony_ci 15597777dab0Sopenharmony_ci If the file is opened for reading, this function is emulated but can be 15607777dab0Sopenharmony_ci extremely slow. If the file is opened for writing, only forward seeks are 15617777dab0Sopenharmony_ci supported; gzseek then compresses a sequence of zeroes up to the new 15627777dab0Sopenharmony_ci starting position. 15637777dab0Sopenharmony_ci 15647777dab0Sopenharmony_ci gzseek returns the resulting offset location as measured in bytes from 15657777dab0Sopenharmony_ci the beginning of the uncompressed stream, or -1 in case of error, in 15667777dab0Sopenharmony_ci particular if the file is opened for writing and the new starting position 15677777dab0Sopenharmony_ci would be before the current position. 15687777dab0Sopenharmony_ci*/ 15697777dab0Sopenharmony_ci 15707777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzrewind(gzFile file); 15717777dab0Sopenharmony_ci/* 15727777dab0Sopenharmony_ci Rewind file. This function is supported only for reading. 15737777dab0Sopenharmony_ci 15747777dab0Sopenharmony_ci gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET). 15757777dab0Sopenharmony_ci*/ 15767777dab0Sopenharmony_ci 15777777dab0Sopenharmony_ci/* 15787777dab0Sopenharmony_ciZEXTERN z_off_t ZEXPORT gztell(gzFile file); 15797777dab0Sopenharmony_ci 15807777dab0Sopenharmony_ci Return the starting position for the next gzread or gzwrite on file. 15817777dab0Sopenharmony_ci This position represents a number of bytes in the uncompressed data stream, 15827777dab0Sopenharmony_ci and is zero when starting, even if appending or reading a gzip stream from 15837777dab0Sopenharmony_ci the middle of a file using gzdopen(). 15847777dab0Sopenharmony_ci 15857777dab0Sopenharmony_ci gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 15867777dab0Sopenharmony_ci*/ 15877777dab0Sopenharmony_ci 15887777dab0Sopenharmony_ci/* 15897777dab0Sopenharmony_ciZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); 15907777dab0Sopenharmony_ci 15917777dab0Sopenharmony_ci Return the current compressed (actual) read or write offset of file. This 15927777dab0Sopenharmony_ci offset includes the count of bytes that precede the gzip stream, for example 15937777dab0Sopenharmony_ci when appending or when using gzdopen() for reading. When reading, the 15947777dab0Sopenharmony_ci offset does not include as yet unused buffered input. This information can 15957777dab0Sopenharmony_ci be used for a progress indicator. On error, gzoffset() returns -1. 15967777dab0Sopenharmony_ci*/ 15977777dab0Sopenharmony_ci 15987777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzeof(gzFile file); 15997777dab0Sopenharmony_ci/* 16007777dab0Sopenharmony_ci Return true (1) if the end-of-file indicator for file has been set while 16017777dab0Sopenharmony_ci reading, false (0) otherwise. Note that the end-of-file indicator is set 16027777dab0Sopenharmony_ci only if the read tried to go past the end of the input, but came up short. 16037777dab0Sopenharmony_ci Therefore, just like feof(), gzeof() may return false even if there is no 16047777dab0Sopenharmony_ci more data to read, in the event that the last read request was for the exact 16057777dab0Sopenharmony_ci number of bytes remaining in the input file. This will happen if the input 16067777dab0Sopenharmony_ci file size is an exact multiple of the buffer size. 16077777dab0Sopenharmony_ci 16087777dab0Sopenharmony_ci If gzeof() returns true, then the read functions will return no more data, 16097777dab0Sopenharmony_ci unless the end-of-file indicator is reset by gzclearerr() and the input file 16107777dab0Sopenharmony_ci has grown since the previous end of file was detected. 16117777dab0Sopenharmony_ci*/ 16127777dab0Sopenharmony_ci 16137777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzdirect(gzFile file); 16147777dab0Sopenharmony_ci/* 16157777dab0Sopenharmony_ci Return true (1) if file is being copied directly while reading, or false 16167777dab0Sopenharmony_ci (0) if file is a gzip stream being decompressed. 16177777dab0Sopenharmony_ci 16187777dab0Sopenharmony_ci If the input file is empty, gzdirect() will return true, since the input 16197777dab0Sopenharmony_ci does not contain a gzip stream. 16207777dab0Sopenharmony_ci 16217777dab0Sopenharmony_ci If gzdirect() is used immediately after gzopen() or gzdopen() it will 16227777dab0Sopenharmony_ci cause buffers to be allocated to allow reading the file to determine if it 16237777dab0Sopenharmony_ci is a gzip file. Therefore if gzbuffer() is used, it should be called before 16247777dab0Sopenharmony_ci gzdirect(). 16257777dab0Sopenharmony_ci 16267777dab0Sopenharmony_ci When writing, gzdirect() returns true (1) if transparent writing was 16277777dab0Sopenharmony_ci requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: 16287777dab0Sopenharmony_ci gzdirect() is not needed when writing. Transparent writing must be 16297777dab0Sopenharmony_ci explicitly requested, so the application already knows the answer. When 16307777dab0Sopenharmony_ci linking statically, using gzdirect() will include all of the zlib code for 16317777dab0Sopenharmony_ci gzip file reading and decompression, which may not be desired.) 16327777dab0Sopenharmony_ci*/ 16337777dab0Sopenharmony_ci 16347777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzclose(gzFile file); 16357777dab0Sopenharmony_ci/* 16367777dab0Sopenharmony_ci Flush all pending output for file, if necessary, close file and 16377777dab0Sopenharmony_ci deallocate the (de)compression state. Note that once file is closed, you 16387777dab0Sopenharmony_ci cannot call gzerror with file, since its structures have been deallocated. 16397777dab0Sopenharmony_ci gzclose must not be called more than once on the same file, just as free 16407777dab0Sopenharmony_ci must not be called more than once on the same allocation. 16417777dab0Sopenharmony_ci 16427777dab0Sopenharmony_ci gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a 16437777dab0Sopenharmony_ci file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the 16447777dab0Sopenharmony_ci last read ended in the middle of a gzip stream, or Z_OK on success. 16457777dab0Sopenharmony_ci*/ 16467777dab0Sopenharmony_ci 16477777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzclose_r(gzFile file); 16487777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzclose_w(gzFile file); 16497777dab0Sopenharmony_ci/* 16507777dab0Sopenharmony_ci Same as gzclose(), but gzclose_r() is only for use when reading, and 16517777dab0Sopenharmony_ci gzclose_w() is only for use when writing or appending. The advantage to 16527777dab0Sopenharmony_ci using these instead of gzclose() is that they avoid linking in zlib 16537777dab0Sopenharmony_ci compression or decompression code that is not used when only reading or only 16547777dab0Sopenharmony_ci writing respectively. If gzclose() is used, then both compression and 16557777dab0Sopenharmony_ci decompression code will be included the application when linking to a static 16567777dab0Sopenharmony_ci zlib library. 16577777dab0Sopenharmony_ci*/ 16587777dab0Sopenharmony_ci 16597777dab0Sopenharmony_ciZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); 16607777dab0Sopenharmony_ci/* 16617777dab0Sopenharmony_ci Return the error message for the last error which occurred on file. 16627777dab0Sopenharmony_ci errnum is set to zlib error number. If an error occurred in the file system 16637777dab0Sopenharmony_ci and not in the compression library, errnum is set to Z_ERRNO and the 16647777dab0Sopenharmony_ci application may consult errno to get the exact error code. 16657777dab0Sopenharmony_ci 16667777dab0Sopenharmony_ci The application must not modify the returned string. Future calls to 16677777dab0Sopenharmony_ci this function may invalidate the previously returned string. If file is 16687777dab0Sopenharmony_ci closed, then the string previously returned by gzerror will no longer be 16697777dab0Sopenharmony_ci available. 16707777dab0Sopenharmony_ci 16717777dab0Sopenharmony_ci gzerror() should be used to distinguish errors from end-of-file for those 16727777dab0Sopenharmony_ci functions above that do not distinguish those cases in their return values. 16737777dab0Sopenharmony_ci*/ 16747777dab0Sopenharmony_ci 16757777dab0Sopenharmony_ciZEXTERN void ZEXPORT gzclearerr(gzFile file); 16767777dab0Sopenharmony_ci/* 16777777dab0Sopenharmony_ci Clear the error and end-of-file flags for file. This is analogous to the 16787777dab0Sopenharmony_ci clearerr() function in stdio. This is useful for continuing to read a gzip 16797777dab0Sopenharmony_ci file that is being written concurrently. 16807777dab0Sopenharmony_ci*/ 16817777dab0Sopenharmony_ci 16827777dab0Sopenharmony_ci#endif /* !Z_SOLO */ 16837777dab0Sopenharmony_ci 16847777dab0Sopenharmony_ci /* checksum functions */ 16857777dab0Sopenharmony_ci 16867777dab0Sopenharmony_ci/* 16877777dab0Sopenharmony_ci These functions are not related to compression but are exported 16887777dab0Sopenharmony_ci anyway because they might be useful in applications using the compression 16897777dab0Sopenharmony_ci library. 16907777dab0Sopenharmony_ci*/ 16917777dab0Sopenharmony_ci 16927777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); 16937777dab0Sopenharmony_ci/* 16947777dab0Sopenharmony_ci Update a running Adler-32 checksum with the bytes buf[0..len-1] and 16957777dab0Sopenharmony_ci return the updated checksum. An Adler-32 value is in the range of a 32-bit 16967777dab0Sopenharmony_ci unsigned integer. If buf is Z_NULL, this function returns the required 16977777dab0Sopenharmony_ci initial value for the checksum. 16987777dab0Sopenharmony_ci 16997777dab0Sopenharmony_ci An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed 17007777dab0Sopenharmony_ci much faster. 17017777dab0Sopenharmony_ci 17027777dab0Sopenharmony_ci Usage example: 17037777dab0Sopenharmony_ci 17047777dab0Sopenharmony_ci uLong adler = adler32(0L, Z_NULL, 0); 17057777dab0Sopenharmony_ci 17067777dab0Sopenharmony_ci while (read_buffer(buffer, length) != EOF) { 17077777dab0Sopenharmony_ci adler = adler32(adler, buffer, length); 17087777dab0Sopenharmony_ci } 17097777dab0Sopenharmony_ci if (adler != original_adler) error(); 17107777dab0Sopenharmony_ci*/ 17117777dab0Sopenharmony_ci 17127777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, 17137777dab0Sopenharmony_ci z_size_t len); 17147777dab0Sopenharmony_ci/* 17157777dab0Sopenharmony_ci Same as adler32(), but with a size_t length. 17167777dab0Sopenharmony_ci*/ 17177777dab0Sopenharmony_ci 17187777dab0Sopenharmony_ci/* 17197777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, 17207777dab0Sopenharmony_ci z_off_t len2); 17217777dab0Sopenharmony_ci 17227777dab0Sopenharmony_ci Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 17237777dab0Sopenharmony_ci and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 17247777dab0Sopenharmony_ci each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 17257777dab0Sopenharmony_ci seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note 17267777dab0Sopenharmony_ci that the z_off_t type (like off_t) is a signed integer. If len2 is 17277777dab0Sopenharmony_ci negative, the result has no meaning or utility. 17287777dab0Sopenharmony_ci*/ 17297777dab0Sopenharmony_ci 17307777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); 17317777dab0Sopenharmony_ci/* 17327777dab0Sopenharmony_ci Update a running CRC-32 with the bytes buf[0..len-1] and return the 17337777dab0Sopenharmony_ci updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. 17347777dab0Sopenharmony_ci If buf is Z_NULL, this function returns the required initial value for the 17357777dab0Sopenharmony_ci crc. Pre- and post-conditioning (one's complement) is performed within this 17367777dab0Sopenharmony_ci function so it shouldn't be done by the application. 17377777dab0Sopenharmony_ci 17387777dab0Sopenharmony_ci Usage example: 17397777dab0Sopenharmony_ci 17407777dab0Sopenharmony_ci uLong crc = crc32(0L, Z_NULL, 0); 17417777dab0Sopenharmony_ci 17427777dab0Sopenharmony_ci while (read_buffer(buffer, length) != EOF) { 17437777dab0Sopenharmony_ci crc = crc32(crc, buffer, length); 17447777dab0Sopenharmony_ci } 17457777dab0Sopenharmony_ci if (crc != original_crc) error(); 17467777dab0Sopenharmony_ci*/ 17477777dab0Sopenharmony_ci 17487777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, 17497777dab0Sopenharmony_ci z_size_t len); 17507777dab0Sopenharmony_ci/* 17517777dab0Sopenharmony_ci Same as crc32(), but with a size_t length. 17527777dab0Sopenharmony_ci*/ 17537777dab0Sopenharmony_ci 17547777dab0Sopenharmony_ci/* 17557777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); 17567777dab0Sopenharmony_ci 17577777dab0Sopenharmony_ci Combine two CRC-32 check values into one. For two sequences of bytes, 17587777dab0Sopenharmony_ci seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 17597777dab0Sopenharmony_ci calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 17607777dab0Sopenharmony_ci check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 17617777dab0Sopenharmony_ci len2. len2 must be non-negative. 17627777dab0Sopenharmony_ci*/ 17637777dab0Sopenharmony_ci 17647777dab0Sopenharmony_ci/* 17657777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); 17667777dab0Sopenharmony_ci 17677777dab0Sopenharmony_ci Return the operator corresponding to length len2, to be used with 17687777dab0Sopenharmony_ci crc32_combine_op(). len2 must be non-negative. 17697777dab0Sopenharmony_ci*/ 17707777dab0Sopenharmony_ci 17717777dab0Sopenharmony_ciZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); 17727777dab0Sopenharmony_ci/* 17737777dab0Sopenharmony_ci Give the same result as crc32_combine(), using op in place of len2. op is 17747777dab0Sopenharmony_ci is generated from len2 by crc32_combine_gen(). This will be faster than 17757777dab0Sopenharmony_ci crc32_combine() if the generated op is used more than once. 17767777dab0Sopenharmony_ci*/ 17777777dab0Sopenharmony_ci 17787777dab0Sopenharmony_ci 17797777dab0Sopenharmony_ci /* various hacks, don't look :) */ 17807777dab0Sopenharmony_ci 17817777dab0Sopenharmony_ci/* deflateInit and inflateInit are macros to allow checking the zlib version 17827777dab0Sopenharmony_ci * and the compiler's view of z_stream: 17837777dab0Sopenharmony_ci */ 17847777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, 17857777dab0Sopenharmony_ci const char *version, int stream_size); 17867777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateInit_(z_streamp strm, 17877777dab0Sopenharmony_ci const char *version, int stream_size); 17887777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, 17897777dab0Sopenharmony_ci int windowBits, int memLevel, 17907777dab0Sopenharmony_ci int strategy, const char *version, 17917777dab0Sopenharmony_ci int stream_size); 17927777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, 17937777dab0Sopenharmony_ci const char *version, int stream_size); 17947777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, 17957777dab0Sopenharmony_ci unsigned char FAR *window, 17967777dab0Sopenharmony_ci const char *version, 17977777dab0Sopenharmony_ci int stream_size); 17987777dab0Sopenharmony_ci#ifdef Z_PREFIX_SET 17997777dab0Sopenharmony_ci# define z_deflateInit(strm, level) \ 18007777dab0Sopenharmony_ci deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) 18017777dab0Sopenharmony_ci# define z_inflateInit(strm) \ 18027777dab0Sopenharmony_ci inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) 18037777dab0Sopenharmony_ci# define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 18047777dab0Sopenharmony_ci deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 18057777dab0Sopenharmony_ci (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) 18067777dab0Sopenharmony_ci# define z_inflateInit2(strm, windowBits) \ 18077777dab0Sopenharmony_ci inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 18087777dab0Sopenharmony_ci (int)sizeof(z_stream)) 18097777dab0Sopenharmony_ci# define z_inflateBackInit(strm, windowBits, window) \ 18107777dab0Sopenharmony_ci inflateBackInit_((strm), (windowBits), (window), \ 18117777dab0Sopenharmony_ci ZLIB_VERSION, (int)sizeof(z_stream)) 18127777dab0Sopenharmony_ci#else 18137777dab0Sopenharmony_ci# define deflateInit(strm, level) \ 18147777dab0Sopenharmony_ci deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) 18157777dab0Sopenharmony_ci# define inflateInit(strm) \ 18167777dab0Sopenharmony_ci inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) 18177777dab0Sopenharmony_ci# define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 18187777dab0Sopenharmony_ci deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 18197777dab0Sopenharmony_ci (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) 18207777dab0Sopenharmony_ci# define inflateInit2(strm, windowBits) \ 18217777dab0Sopenharmony_ci inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 18227777dab0Sopenharmony_ci (int)sizeof(z_stream)) 18237777dab0Sopenharmony_ci# define inflateBackInit(strm, windowBits, window) \ 18247777dab0Sopenharmony_ci inflateBackInit_((strm), (windowBits), (window), \ 18257777dab0Sopenharmony_ci ZLIB_VERSION, (int)sizeof(z_stream)) 18267777dab0Sopenharmony_ci#endif 18277777dab0Sopenharmony_ci 18287777dab0Sopenharmony_ci#ifndef Z_SOLO 18297777dab0Sopenharmony_ci 18307777dab0Sopenharmony_ci/* gzgetc() macro and its supporting function and exposed data structure. Note 18317777dab0Sopenharmony_ci * that the real internal state is much larger than the exposed structure. 18327777dab0Sopenharmony_ci * This abbreviated structure exposes just enough for the gzgetc() macro. The 18337777dab0Sopenharmony_ci * user should not mess with these exposed elements, since their names or 18347777dab0Sopenharmony_ci * behavior could change in the future, perhaps even capriciously. They can 18357777dab0Sopenharmony_ci * only be used by the gzgetc() macro. You have been warned. 18367777dab0Sopenharmony_ci */ 18377777dab0Sopenharmony_cistruct gzFile_s { 18387777dab0Sopenharmony_ci unsigned have; 18397777dab0Sopenharmony_ci unsigned char *next; 18407777dab0Sopenharmony_ci z_off64_t pos; 18417777dab0Sopenharmony_ci}; 18427777dab0Sopenharmony_ciZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ 18437777dab0Sopenharmony_ci#ifdef Z_PREFIX_SET 18447777dab0Sopenharmony_ci# undef z_gzgetc 18457777dab0Sopenharmony_ci# define z_gzgetc(g) \ 18467777dab0Sopenharmony_ci ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) 18477777dab0Sopenharmony_ci#else 18487777dab0Sopenharmony_ci# define gzgetc(g) \ 18497777dab0Sopenharmony_ci ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) 18507777dab0Sopenharmony_ci#endif 18517777dab0Sopenharmony_ci 18527777dab0Sopenharmony_ci/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or 18537777dab0Sopenharmony_ci * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if 18547777dab0Sopenharmony_ci * both are true, the application gets the *64 functions, and the regular 18557777dab0Sopenharmony_ci * functions are changed to 64 bits) -- in case these are set on systems 18567777dab0Sopenharmony_ci * without large file support, _LFS64_LARGEFILE must also be true 18577777dab0Sopenharmony_ci */ 18587777dab0Sopenharmony_ci#ifdef Z_LARGE64 18597777dab0Sopenharmony_ci ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); 18607777dab0Sopenharmony_ci ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); 18617777dab0Sopenharmony_ci ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); 18627777dab0Sopenharmony_ci ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); 18637777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); 18647777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); 18657777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); 18667777dab0Sopenharmony_ci#endif 18677777dab0Sopenharmony_ci 18687777dab0Sopenharmony_ci#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) 18697777dab0Sopenharmony_ci# ifdef Z_PREFIX_SET 18707777dab0Sopenharmony_ci# define z_gzopen z_gzopen64 18717777dab0Sopenharmony_ci# define z_gzseek z_gzseek64 18727777dab0Sopenharmony_ci# define z_gztell z_gztell64 18737777dab0Sopenharmony_ci# define z_gzoffset z_gzoffset64 18747777dab0Sopenharmony_ci# define z_adler32_combine z_adler32_combine64 18757777dab0Sopenharmony_ci# define z_crc32_combine z_crc32_combine64 18767777dab0Sopenharmony_ci# define z_crc32_combine_gen z_crc32_combine_gen64 18777777dab0Sopenharmony_ci# else 18787777dab0Sopenharmony_ci# define gzopen gzopen64 18797777dab0Sopenharmony_ci# define gzseek gzseek64 18807777dab0Sopenharmony_ci# define gztell gztell64 18817777dab0Sopenharmony_ci# define gzoffset gzoffset64 18827777dab0Sopenharmony_ci# define adler32_combine adler32_combine64 18837777dab0Sopenharmony_ci# define crc32_combine crc32_combine64 18847777dab0Sopenharmony_ci# define crc32_combine_gen crc32_combine_gen64 18857777dab0Sopenharmony_ci# endif 18867777dab0Sopenharmony_ci# ifndef Z_LARGE64 18877777dab0Sopenharmony_ci ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); 18887777dab0Sopenharmony_ci ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); 18897777dab0Sopenharmony_ci ZEXTERN z_off_t ZEXPORT gztell64(gzFile); 18907777dab0Sopenharmony_ci ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); 18917777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); 18927777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); 18937777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); 18947777dab0Sopenharmony_ci# endif 18957777dab0Sopenharmony_ci#else 18967777dab0Sopenharmony_ci ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); 18977777dab0Sopenharmony_ci ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); 18987777dab0Sopenharmony_ci ZEXTERN z_off_t ZEXPORT gztell(gzFile); 18997777dab0Sopenharmony_ci ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); 19007777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); 19017777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); 19027777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); 19037777dab0Sopenharmony_ci#endif 19047777dab0Sopenharmony_ci 19057777dab0Sopenharmony_ci#else /* Z_SOLO */ 19067777dab0Sopenharmony_ci 19077777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); 19087777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); 19097777dab0Sopenharmony_ci ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); 19107777dab0Sopenharmony_ci 19117777dab0Sopenharmony_ci#endif /* !Z_SOLO */ 19127777dab0Sopenharmony_ci 19137777dab0Sopenharmony_ci/* undocumented functions */ 19147777dab0Sopenharmony_ciZEXTERN const char * ZEXPORT zError(int); 19157777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); 19167777dab0Sopenharmony_ciZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); 19177777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); 19187777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateValidate(z_streamp, int); 19197777dab0Sopenharmony_ciZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); 19207777dab0Sopenharmony_ciZEXTERN int ZEXPORT inflateResetKeep(z_streamp); 19217777dab0Sopenharmony_ciZEXTERN int ZEXPORT deflateResetKeep(z_streamp); 19227777dab0Sopenharmony_ci#if defined(_WIN32) && !defined(Z_SOLO) 19237777dab0Sopenharmony_ciZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, 19247777dab0Sopenharmony_ci const char *mode); 19257777dab0Sopenharmony_ci#endif 19267777dab0Sopenharmony_ci#if defined(STDC) || defined(Z_HAVE_STDARG_H) 19277777dab0Sopenharmony_ci# ifndef Z_SOLO 19287777dab0Sopenharmony_ciZEXTERN int ZEXPORTVA gzvprintf(gzFile file, 19297777dab0Sopenharmony_ci const char *format, 19307777dab0Sopenharmony_ci va_list va); 19317777dab0Sopenharmony_ci# endif 19327777dab0Sopenharmony_ci#endif 19337777dab0Sopenharmony_ci 19347777dab0Sopenharmony_ci#ifdef __cplusplus 19357777dab0Sopenharmony_ci} 19367777dab0Sopenharmony_ci#endif 19377777dab0Sopenharmony_ci 19387777dab0Sopenharmony_ci#endif /* ZLIB_H */ 1939