1*9c15b0b0Sagc /* $NetBSD: zlib.h,v 1.2 2020/05/04 00:18:34 agc Exp $ */ 22a988851Sagc 32a988851Sagc /* zlib.h -- interface of the 'zlib' general purpose compression library 42a988851Sagc version 1.2.3, July 18th, 2005 52a988851Sagc 62a988851Sagc Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler 72a988851Sagc 82a988851Sagc This software is provided 'as-is', without any express or implied 92a988851Sagc warranty. In no event will the authors be held liable for any damages 102a988851Sagc arising from the use of this software. 112a988851Sagc 122a988851Sagc Permission is granted to anyone to use this software for any purpose, 132a988851Sagc including commercial applications, and to alter it and redistribute it 142a988851Sagc freely, subject to the following restrictions: 152a988851Sagc 162a988851Sagc 1. The origin of this software must not be misrepresented; you must not 172a988851Sagc claim that you wrote the original software. If you use this software 182a988851Sagc in a product, an acknowledgment in the product documentation would be 192a988851Sagc appreciated but is not required. 202a988851Sagc 2. Altered source versions must be plainly marked as such, and must not be 212a988851Sagc misrepresented as being the original software. 222a988851Sagc 3. This notice may not be removed or altered from any source distribution. 232a988851Sagc 242a988851Sagc Jean-loup Gailly Mark Adler 252a988851Sagc jloup@gzip.org madler@alumni.caltech.edu 262a988851Sagc 272a988851Sagc 282a988851Sagc The data format used by the zlib library is described by RFCs (Request for 292a988851Sagc Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt 302a988851Sagc (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 312a988851Sagc */ 322a988851Sagc 332a988851Sagc #ifndef ZLIB_H 342a988851Sagc #define ZLIB_H 352a988851Sagc 362a988851Sagc #include "config.h" 372a988851Sagc 38*9c15b0b0Sagc /* $NetBSD: zlib.h,v 1.2 2020/05/04 00:18:34 agc Exp $ */ 392a988851Sagc 402a988851Sagc /* zconf.h -- configuration of the zlib compression library 412a988851Sagc * Copyright (C) 1995-2005 Jean-loup Gailly. 422a988851Sagc * For conditions of distribution and use, see copyright notice in zlib.h 432a988851Sagc */ 442a988851Sagc 452a988851Sagc /* @(#) Id */ 462a988851Sagc 472a988851Sagc #ifndef ZCONF_H 482a988851Sagc #define ZCONF_H 492a988851Sagc 502a988851Sagc #include <sys/types.h> 512a988851Sagc 52*9c15b0b0Sagc /* we don't want these colliding with anything else out there */ 53*9c15b0b0Sagc #define Z_PREFIX 1 54*9c15b0b0Sagc 552a988851Sagc /* 562a988851Sagc * If you *really* need a unique prefix for all types and library functions, 572a988851Sagc * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 582a988851Sagc */ 592a988851Sagc #ifdef Z_PREFIX 60*9c15b0b0Sagc # define deflateInit_ netpgpv_z_deflateInit_ 61*9c15b0b0Sagc # define deflate netpgpv_z_deflate 62*9c15b0b0Sagc # define deflateEnd netpgpv_z_deflateEnd 63*9c15b0b0Sagc # define inflateInit_ netpgpv_z_inflateInit_ 64*9c15b0b0Sagc # define inflate netpgpv_z_inflate 65*9c15b0b0Sagc # define inflateEnd netpgpv_z_inflateEnd 66*9c15b0b0Sagc # define deflateInit2_ netpgpv_z_deflateInit2_ 67*9c15b0b0Sagc # define deflateSetDictionary netpgpv_z_deflateSetDictionary 68*9c15b0b0Sagc # define deflateCopy netpgpv_z_deflateCopy 69*9c15b0b0Sagc # define deflateReset netpgpv_z_deflateReset 70*9c15b0b0Sagc # define deflateParams netpgpv_z_deflateParams 71*9c15b0b0Sagc # define deflateBound netpgpv_z_deflateBound 72*9c15b0b0Sagc # define deflatePrime netpgpv_z_deflatePrime 73*9c15b0b0Sagc # define inflateInit2_ netpgpv_z_inflateInit2_ 74*9c15b0b0Sagc # define inflateSetDictionary netpgpv_z_inflateSetDictionary 75*9c15b0b0Sagc # define inflateSync netpgpv_z_inflateSync 76*9c15b0b0Sagc # define inflateSyncPoint netpgpv_z_inflateSyncPoint 77*9c15b0b0Sagc # define inflateCopy netpgpv_z_inflateCopy 78*9c15b0b0Sagc # define inflateReset netpgpv_z_inflateReset 79*9c15b0b0Sagc # define inflateBack netpgpv_z_inflateBack 80*9c15b0b0Sagc # define inflateBackEnd netpgpv_z_inflateBackEnd 81*9c15b0b0Sagc # define compress netpgpv_z_compress 82*9c15b0b0Sagc # define compress2 netpgpv_z_compress2 83*9c15b0b0Sagc # define compressBound netpgpv_z_compressBound 84*9c15b0b0Sagc # define uncompress netpgpv_z_uncompress 85*9c15b0b0Sagc # define adler32 netpgpv_z_adler32 86*9c15b0b0Sagc # define crc32 netpgpv_z_crc32 87*9c15b0b0Sagc # define get_crc_table netpgpv_z_get_crc_table 88*9c15b0b0Sagc # define zError netpgpv_z_zError 892a988851Sagc 90*9c15b0b0Sagc # define alloc_func netpgpv_z_alloc_func 91*9c15b0b0Sagc # define free_func netpgpv_z_free_func 92*9c15b0b0Sagc # define in_func netpgpv_z_in_func 93*9c15b0b0Sagc # define out_func netpgpv_z_out_func 94*9c15b0b0Sagc # define Byte netpgpv_z_Byte 95*9c15b0b0Sagc # define uInt netpgpv_z_uInt 96*9c15b0b0Sagc # define uLong netpgpv_z_uLong 97*9c15b0b0Sagc # define Bytef netpgpv_z_Bytef 98*9c15b0b0Sagc # define charf netpgpv_z_charf 99*9c15b0b0Sagc # define intf netpgpv_z_intf 100*9c15b0b0Sagc # define uIntf netpgpv_z_uIntf 101*9c15b0b0Sagc # define uLongf netpgpv_z_uLongf 102*9c15b0b0Sagc # define voidpf netpgpv_z_voidpf 103*9c15b0b0Sagc # define voidp netpgpv_z_voidp 1042a988851Sagc #endif 1052a988851Sagc 1062a988851Sagc #if defined(__MSDOS__) && !defined(MSDOS) 1072a988851Sagc # define MSDOS 1082a988851Sagc #endif 1092a988851Sagc #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 1102a988851Sagc # define OS2 1112a988851Sagc #endif 1122a988851Sagc #if defined(_WINDOWS) && !defined(WINDOWS) 1132a988851Sagc # define WINDOWS 1142a988851Sagc #endif 1152a988851Sagc #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 1162a988851Sagc # ifndef WIN32 1172a988851Sagc # define WIN32 1182a988851Sagc # endif 1192a988851Sagc #endif 1202a988851Sagc #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 1212a988851Sagc # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 1222a988851Sagc # ifndef SYS16BIT 1232a988851Sagc # define SYS16BIT 1242a988851Sagc # endif 1252a988851Sagc # endif 1262a988851Sagc #endif 1272a988851Sagc 1282a988851Sagc /* 1292a988851Sagc * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 1302a988851Sagc * than 64k bytes at a time (needed on systems with 16-bit int). 1312a988851Sagc */ 1322a988851Sagc #ifdef SYS16BIT 1332a988851Sagc # define MAXSEG_64K 1342a988851Sagc #endif 1352a988851Sagc #ifdef MSDOS 1362a988851Sagc # define UNALIGNED_OK 1372a988851Sagc #endif 1382a988851Sagc 1392a988851Sagc #ifdef __STDC_VERSION__ 1402a988851Sagc # ifndef STDC 1412a988851Sagc # define STDC 1422a988851Sagc # endif 1432a988851Sagc # if __STDC_VERSION__ >= 199901L 1442a988851Sagc # ifndef STDC99 1452a988851Sagc # define STDC99 1462a988851Sagc # endif 1472a988851Sagc # endif 1482a988851Sagc #endif 1492a988851Sagc #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 1502a988851Sagc # define STDC 1512a988851Sagc #endif 1522a988851Sagc #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 1532a988851Sagc # define STDC 1542a988851Sagc #endif 1552a988851Sagc #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 1562a988851Sagc # define STDC 1572a988851Sagc #endif 1582a988851Sagc #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 1592a988851Sagc # define STDC 1602a988851Sagc #endif 1612a988851Sagc 1622a988851Sagc #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 1632a988851Sagc # define STDC 1642a988851Sagc #endif 1652a988851Sagc 1662a988851Sagc #ifndef STDC 1672a988851Sagc # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 1682a988851Sagc # define const /* note: need a more gentle solution here */ 1692a988851Sagc # endif 1702a988851Sagc #endif 1712a988851Sagc 1722a988851Sagc /* Some Mac compilers merge all .h files incorrectly: */ 1732a988851Sagc #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 1742a988851Sagc # define NO_DUMMY_DECL 1752a988851Sagc #endif 1762a988851Sagc 1772a988851Sagc /* Maximum value for memLevel in deflateInit2 */ 1782a988851Sagc #ifndef MAX_MEM_LEVEL 1792a988851Sagc # ifdef MAXSEG_64K 1802a988851Sagc # define MAX_MEM_LEVEL 8 1812a988851Sagc # else 1822a988851Sagc # define MAX_MEM_LEVEL 9 1832a988851Sagc # endif 1842a988851Sagc #endif 1852a988851Sagc 1862a988851Sagc /* Maximum value for windowBits in deflateInit2 and inflateInit2. 1872a988851Sagc * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 1882a988851Sagc * created by gzip. (Files created by minigzip can still be extracted by 1892a988851Sagc * gzip.) 1902a988851Sagc */ 1912a988851Sagc #ifndef MAX_WBITS 1922a988851Sagc # define MAX_WBITS 15 /* 32K LZ77 window */ 1932a988851Sagc #endif 1942a988851Sagc 1952a988851Sagc /* The memory requirements for deflate are (in bytes): 1962a988851Sagc (1 << (windowBits+2)) + (1 << (memLevel+9)) 1972a988851Sagc that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 1982a988851Sagc plus a few kilobytes for small objects. For example, if you want to reduce 1992a988851Sagc the default memory requirements from 256K to 128K, compile with 2002a988851Sagc make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 2012a988851Sagc Of course this will generally degrade compression (there's no free lunch). 2022a988851Sagc 2032a988851Sagc The memory requirements for inflate are (in bytes) 1 << windowBits 2042a988851Sagc that is, 32K for windowBits=15 (default value) plus a few kilobytes 2052a988851Sagc for small objects. 2062a988851Sagc */ 2072a988851Sagc 2082a988851Sagc /* Type declarations */ 2092a988851Sagc 2102a988851Sagc #ifndef OF /* function prototypes */ 2112a988851Sagc # ifdef STDC 2122a988851Sagc # define OF(args) args 2132a988851Sagc # else 2142a988851Sagc # define OF(args) () 2152a988851Sagc # endif 2162a988851Sagc #endif 2172a988851Sagc 2182a988851Sagc /* The following definitions for FAR are needed only for MSDOS mixed 2192a988851Sagc * model programming (small or medium model with some far allocations). 2202a988851Sagc * This was tested only with MSC; for other MSDOS compilers you may have 2212a988851Sagc * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 2222a988851Sagc * just define FAR to be empty. 2232a988851Sagc */ 2242a988851Sagc #ifdef SYS16BIT 2252a988851Sagc # if defined(M_I86SM) || defined(M_I86MM) 2262a988851Sagc /* MSC small or medium model */ 2272a988851Sagc # define SMALL_MEDIUM 2282a988851Sagc # ifdef _MSC_VER 2292a988851Sagc # define FAR _far 2302a988851Sagc # else 2312a988851Sagc # define FAR far 2322a988851Sagc # endif 2332a988851Sagc # endif 2342a988851Sagc # if (defined(__SMALL__) || defined(__MEDIUM__)) 2352a988851Sagc /* Turbo C small or medium model */ 2362a988851Sagc # define SMALL_MEDIUM 2372a988851Sagc # ifdef __BORLANDC__ 2382a988851Sagc # define FAR _far 2392a988851Sagc # else 2402a988851Sagc # define FAR far 2412a988851Sagc # endif 2422a988851Sagc # endif 2432a988851Sagc #endif 2442a988851Sagc 2452a988851Sagc #if defined(WINDOWS) || defined(WIN32) 2462a988851Sagc /* If building or using zlib as a DLL, define ZLIB_DLL. 2472a988851Sagc * This is not mandatory, but it offers a little performance increase. 2482a988851Sagc */ 2492a988851Sagc # ifdef ZLIB_DLL 2502a988851Sagc # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 2512a988851Sagc # ifdef ZLIB_INTERNAL 2522a988851Sagc # define ZEXTERN extern __declspec(dllexport) 2532a988851Sagc # else 2542a988851Sagc # define ZEXTERN extern __declspec(dllimport) 2552a988851Sagc # endif 2562a988851Sagc # endif 2572a988851Sagc # endif /* ZLIB_DLL */ 2582a988851Sagc /* If building or using zlib with the WINAPI/WINAPIV calling convention, 2592a988851Sagc * define ZLIB_WINAPI. 2602a988851Sagc * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 2612a988851Sagc */ 2622a988851Sagc # ifdef ZLIB_WINAPI 2632a988851Sagc # ifdef FAR 2642a988851Sagc # undef FAR 2652a988851Sagc # endif 2662a988851Sagc # include <windows.h> 2672a988851Sagc /* No need for _export, use ZLIB.DEF instead. */ 2682a988851Sagc /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 2692a988851Sagc # define ZEXPORT WINAPI 2702a988851Sagc # ifdef WIN32 2712a988851Sagc # define ZEXPORTVA WINAPIV 2722a988851Sagc # else 2732a988851Sagc # define ZEXPORTVA FAR CDECL 2742a988851Sagc # endif 2752a988851Sagc # endif 2762a988851Sagc #endif 2772a988851Sagc 2782a988851Sagc #if defined (__BEOS__) 2792a988851Sagc # ifdef ZLIB_DLL 2802a988851Sagc # ifdef ZLIB_INTERNAL 2812a988851Sagc # define ZEXPORT __declspec(dllexport) 2822a988851Sagc # define ZEXPORTVA __declspec(dllexport) 2832a988851Sagc # else 2842a988851Sagc # define ZEXPORT __declspec(dllimport) 2852a988851Sagc # define ZEXPORTVA __declspec(dllimport) 2862a988851Sagc # endif 2872a988851Sagc # endif 2882a988851Sagc #endif 2892a988851Sagc 2902a988851Sagc #ifndef ZEXTERN 2912a988851Sagc # define ZEXTERN extern 2922a988851Sagc #endif 2932a988851Sagc #ifndef ZEXPORT 2942a988851Sagc # define ZEXPORT 2952a988851Sagc #endif 2962a988851Sagc #ifndef ZEXPORTVA 2972a988851Sagc # define ZEXPORTVA 2982a988851Sagc #endif 2992a988851Sagc 3002a988851Sagc #ifndef FAR 3012a988851Sagc # define FAR 3022a988851Sagc #endif 3032a988851Sagc 3042a988851Sagc #if !defined(__MACTYPES__) 3052a988851Sagc typedef unsigned char Byte; /* 8 bits */ 3062a988851Sagc #endif 3072a988851Sagc typedef unsigned int uInt; /* 16 bits or more */ 3082a988851Sagc typedef unsigned long uLong; /* 32 bits or more */ 3092a988851Sagc 3102a988851Sagc #ifdef SMALL_MEDIUM 3112a988851Sagc /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 3122a988851Sagc # define Bytef Byte FAR 3132a988851Sagc #else 3142a988851Sagc typedef Byte FAR Bytef; 3152a988851Sagc #endif 3162a988851Sagc typedef char FAR charf; 3172a988851Sagc typedef int FAR intf; 3182a988851Sagc typedef uInt FAR uIntf; 3192a988851Sagc typedef uLong FAR uLongf; 3202a988851Sagc 3212a988851Sagc #ifdef STDC 3222a988851Sagc typedef void const *voidpc; 3232a988851Sagc typedef void FAR *voidpf; 3242a988851Sagc typedef void *voidp; 3252a988851Sagc #else 3262a988851Sagc typedef Byte const *voidpc; 3272a988851Sagc typedef Byte FAR *voidpf; 3282a988851Sagc typedef Byte *voidp; 3292a988851Sagc #endif 3302a988851Sagc 3312a988851Sagc #if defined(HAVE_UNISTD_H) || (defined(__NetBSD__) && (!defined(_KERNEL) && !defined(_STANDALONE))) 3322a988851Sagc # include <sys/types.h> /* for off_t */ 3332a988851Sagc # include <unistd.h> /* for SEEK_* and off_t */ 3342a988851Sagc # ifdef VMS 3352a988851Sagc # include <unixio.h> /* for off_t */ 3362a988851Sagc # endif 3372a988851Sagc # define z_off_t off_t 3382a988851Sagc # define z_ptrdiff_t ptrdiff_t 3392a988851Sagc #endif 3402a988851Sagc #ifndef SEEK_SET 3412a988851Sagc # define SEEK_SET 0 /* Seek from beginning of file. */ 3422a988851Sagc # define SEEK_CUR 1 /* Seek from current position. */ 3432a988851Sagc # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 3442a988851Sagc #endif 3452a988851Sagc #ifndef z_off_t 3462a988851Sagc # define z_off_t long 3472a988851Sagc #endif 3482a988851Sagc #ifndef z_ptrdiff_t 3492a988851Sagc # define z_ptrdiff_t long 3502a988851Sagc #endif 3512a988851Sagc 3522a988851Sagc #if defined(__OS400__) 3532a988851Sagc # define NO_vsnprintf 3542a988851Sagc #endif 3552a988851Sagc 3562a988851Sagc #if defined(__MVS__) 3572a988851Sagc # define NO_vsnprintf 3582a988851Sagc # ifdef FAR 3592a988851Sagc # undef FAR 3602a988851Sagc # endif 3612a988851Sagc #endif 3622a988851Sagc 3632a988851Sagc /* MVS linker does not support external names larger than 8 bytes */ 3642a988851Sagc #if defined(__MVS__) 3652a988851Sagc # pragma map(deflateInit_,"DEIN") 3662a988851Sagc # pragma map(deflateInit2_,"DEIN2") 3672a988851Sagc # pragma map(deflateEnd,"DEEND") 3682a988851Sagc # pragma map(deflateBound,"DEBND") 3692a988851Sagc # pragma map(inflateInit_,"ININ") 3702a988851Sagc # pragma map(inflateInit2_,"ININ2") 3712a988851Sagc # pragma map(inflateEnd,"INEND") 3722a988851Sagc # pragma map(inflateSync,"INSY") 3732a988851Sagc # pragma map(inflateSetDictionary,"INSEDI") 3742a988851Sagc # pragma map(compressBound,"CMBND") 3752a988851Sagc # pragma map(inflate_table,"INTABL") 3762a988851Sagc # pragma map(inflate_fast,"INFA") 3772a988851Sagc # pragma map(inflate_copyright,"INCOPY") 3782a988851Sagc #endif 3792a988851Sagc 3802a988851Sagc #endif /* ZCONF_H */ 3812a988851Sagc #ifdef __cplusplus 3822a988851Sagc extern "C" { 3832a988851Sagc #endif 3842a988851Sagc 3852a988851Sagc #define ZLIB_VERSION "1.2.3" 3862a988851Sagc #define ZLIB_VERNUM 0x1230 3872a988851Sagc 3882a988851Sagc /* 3892a988851Sagc The 'zlib' compression library provides in-memory compression and 3902a988851Sagc decompression functions, including integrity checks of the uncompressed 3912a988851Sagc data. This version of the library supports only one compression method 3922a988851Sagc (deflation) but other algorithms will be added later and will have the same 3932a988851Sagc stream interface. 3942a988851Sagc 3952a988851Sagc Compression can be done in a single step if the buffers are large 3962a988851Sagc enough (for example if an input file is mmap'ed), or can be done by 3972a988851Sagc repeated calls of the compression function. In the latter case, the 3982a988851Sagc application must provide more input and/or consume the output 3992a988851Sagc (providing more output space) before each call. 4002a988851Sagc 4012a988851Sagc The compressed data format used by default by the in-memory functions is 4022a988851Sagc the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 4032a988851Sagc around a deflate stream, which is itself documented in RFC 1951. 4042a988851Sagc 4052a988851Sagc The library also supports reading and writing files in gzip (.gz) format 4062a988851Sagc with an interface similar to that of stdio using the functions that start 4072a988851Sagc with "gz". The gzip format is different from the zlib format. gzip is a 4082a988851Sagc gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 4092a988851Sagc 4102a988851Sagc This library can optionally read and write gzip streams in memory as well. 4112a988851Sagc 4122a988851Sagc The zlib format was designed to be compact and fast for use in memory 4132a988851Sagc and on communications channels. The gzip format was designed for single- 4142a988851Sagc file compression on file systems, has a larger header than zlib to maintain 4152a988851Sagc directory information, and uses a different, slower check method than zlib. 4162a988851Sagc 4172a988851Sagc The library does not install any signal handler. The decoder checks 4182a988851Sagc the consistency of the compressed data, so the library should never 4192a988851Sagc crash even in case of corrupted input. 4202a988851Sagc */ 4212a988851Sagc 4222a988851Sagc typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 4232a988851Sagc typedef void (*free_func) OF((voidpf opaque, voidpf address)); 4242a988851Sagc 4252a988851Sagc struct internal_state; 4262a988851Sagc 4272a988851Sagc typedef struct z_stream_s { 4282a988851Sagc Bytef *next_in; /* next input byte */ 4292a988851Sagc uInt avail_in; /* number of bytes available at next_in */ 4302a988851Sagc uLong total_in; /* total nb of input bytes read so far */ 4312a988851Sagc 4322a988851Sagc Bytef *next_out; /* next output byte should be put there */ 4332a988851Sagc uInt avail_out; /* remaining free space at next_out */ 4342a988851Sagc uLong total_out; /* total nb of bytes output so far */ 4352a988851Sagc 4362a988851Sagc char *msg; /* last error message, NULL if no error */ 4372a988851Sagc struct internal_state FAR *state; /* not visible by applications */ 4382a988851Sagc 4392a988851Sagc alloc_func zalloc; /* used to allocate the internal state */ 4402a988851Sagc free_func zfree; /* used to free the internal state */ 4412a988851Sagc voidpf opaque; /* private data object passed to zalloc and zfree */ 4422a988851Sagc 4432a988851Sagc int data_type; /* best guess about the data type: binary or text */ 4442a988851Sagc uLong adler; /* adler32 value of the uncompressed data */ 4452a988851Sagc uLong reserved; /* reserved for future use */ 4462a988851Sagc } z_stream; 4472a988851Sagc 4482a988851Sagc typedef z_stream FAR *z_streamp; 4492a988851Sagc 4502a988851Sagc /* 4512a988851Sagc gzip header information passed to and from zlib routines. See RFC 1952 4522a988851Sagc for more details on the meanings of these fields. 4532a988851Sagc */ 4542a988851Sagc typedef struct gz_header_s { 4552a988851Sagc int text; /* true if compressed data believed to be text */ 4562a988851Sagc uLong time; /* modification time */ 4572a988851Sagc int xflags; /* extra flags (not used when writing a gzip file) */ 4582a988851Sagc int os; /* operating system */ 4592a988851Sagc Bytef *extra; /* pointer to extra field or Z_NULL if none */ 4602a988851Sagc uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 4612a988851Sagc uInt extra_max; /* space at extra (only when reading header) */ 4622a988851Sagc Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 4632a988851Sagc uInt name_max; /* space at name (only when reading header) */ 4642a988851Sagc Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 4652a988851Sagc uInt comm_max; /* space at comment (only when reading header) */ 4662a988851Sagc int hcrc; /* true if there was or will be a header crc */ 4672a988851Sagc int done; /* true when done reading gzip header (not used 4682a988851Sagc when writing a gzip file) */ 4692a988851Sagc } gz_header; 4702a988851Sagc 4712a988851Sagc typedef gz_header FAR *gz_headerp; 4722a988851Sagc 4732a988851Sagc /* 4742a988851Sagc The application must update next_in and avail_in when avail_in has 4752a988851Sagc dropped to zero. It must update next_out and avail_out when avail_out 4762a988851Sagc has dropped to zero. The application must initialize zalloc, zfree and 4772a988851Sagc opaque before calling the init function. All other fields are set by the 4782a988851Sagc compression library and must not be updated by the application. 4792a988851Sagc 4802a988851Sagc The opaque value provided by the application will be passed as the first 4812a988851Sagc parameter for calls of zalloc and zfree. This can be useful for custom 4822a988851Sagc memory management. The compression library attaches no meaning to the 4832a988851Sagc opaque value. 4842a988851Sagc 4852a988851Sagc zalloc must return Z_NULL if there is not enough memory for the object. 4862a988851Sagc If zlib is used in a multi-threaded application, zalloc and zfree must be 4872a988851Sagc thread safe. 4882a988851Sagc 4892a988851Sagc On 16-bit systems, the functions zalloc and zfree must be able to allocate 4902a988851Sagc exactly 65536 bytes, but will not be required to allocate more than this 4912a988851Sagc if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 4922a988851Sagc pointers returned by zalloc for objects of exactly 65536 bytes *must* 4932a988851Sagc have their offset normalized to zero. The default allocation function 4942a988851Sagc provided by this library ensures this (see zutil.c). To reduce memory 4952a988851Sagc requirements and avoid any allocation of 64K objects, at the expense of 4962a988851Sagc compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 4972a988851Sagc 4982a988851Sagc The fields total_in and total_out can be used for statistics or 4992a988851Sagc progress reports. After compression, total_in holds the total size of 5002a988851Sagc the uncompressed data and may be saved for use in the decompressor 5012a988851Sagc (particularly if the decompressor wants to decompress everything in 5022a988851Sagc a single step). 5032a988851Sagc */ 5042a988851Sagc 5052a988851Sagc /* constants */ 5062a988851Sagc 5072a988851Sagc #define Z_NO_FLUSH 0 5082a988851Sagc #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 5092a988851Sagc #define Z_SYNC_FLUSH 2 5102a988851Sagc #define Z_FULL_FLUSH 3 5112a988851Sagc #define Z_FINISH 4 5122a988851Sagc #define Z_BLOCK 5 5132a988851Sagc /* Allowed flush values; see deflate() and inflate() below for details */ 5142a988851Sagc 5152a988851Sagc #define Z_OK 0 5162a988851Sagc #define Z_STREAM_END 1 5172a988851Sagc #define Z_NEED_DICT 2 5182a988851Sagc #define Z_ERRNO (-1) 5192a988851Sagc #define Z_STREAM_ERROR (-2) 5202a988851Sagc #define Z_DATA_ERROR (-3) 5212a988851Sagc #define Z_MEM_ERROR (-4) 5222a988851Sagc #define Z_BUF_ERROR (-5) 5232a988851Sagc #define Z_VERSION_ERROR (-6) 5242a988851Sagc /* Return codes for the compression/decompression functions. Negative 5252a988851Sagc * values are errors, positive values are used for special but normal events. 5262a988851Sagc */ 5272a988851Sagc 5282a988851Sagc #define Z_NO_COMPRESSION 0 5292a988851Sagc #define Z_BEST_SPEED 1 5302a988851Sagc #define Z_BEST_COMPRESSION 9 5312a988851Sagc #define Z_DEFAULT_COMPRESSION (-1) 5322a988851Sagc /* compression levels */ 5332a988851Sagc 5342a988851Sagc #define Z_FILTERED 1 5352a988851Sagc #define Z_HUFFMAN_ONLY 2 5362a988851Sagc #define Z_RLE 3 5372a988851Sagc #define Z_FIXED 4 5382a988851Sagc #define Z_DEFAULT_STRATEGY 0 5392a988851Sagc /* compression strategy; see deflateInit2() below for details */ 5402a988851Sagc 5412a988851Sagc #define Z_BINARY 0 5422a988851Sagc #define Z_TEXT 1 5432a988851Sagc #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 5442a988851Sagc #define Z_UNKNOWN 2 5452a988851Sagc /* Possible values of the data_type field (though see inflate()) */ 5462a988851Sagc 5472a988851Sagc #define Z_DEFLATED 8 5482a988851Sagc /* The deflate compression method (the only one supported in this version) */ 5492a988851Sagc 5502a988851Sagc #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 5512a988851Sagc 5522a988851Sagc #define zlib_version zlibVersion() 5532a988851Sagc /* for compatibility with versions < 1.0.2 */ 5542a988851Sagc 5552a988851Sagc /* basic functions */ 5562a988851Sagc 5572a988851Sagc ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 5582a988851Sagc /* The application can compare zlibVersion and ZLIB_VERSION for consistency. 5592a988851Sagc If the first character differs, the library code actually used is 5602a988851Sagc not compatible with the zlib.h header file used by the application. 5612a988851Sagc This check is automatically made by deflateInit and inflateInit. 5622a988851Sagc */ 5632a988851Sagc 5642a988851Sagc /* 5652a988851Sagc ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 5662a988851Sagc 5672a988851Sagc Initializes the internal stream state for compression. The fields 5682a988851Sagc zalloc, zfree and opaque must be initialized before by the caller. 5692a988851Sagc If zalloc and zfree are set to Z_NULL, deflateInit updates them to 5702a988851Sagc use default allocation functions. 5712a988851Sagc 5722a988851Sagc The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 5732a988851Sagc 1 gives best speed, 9 gives best compression, 0 gives no compression at 5742a988851Sagc all (the input data is simply copied a block at a time). 5752a988851Sagc Z_DEFAULT_COMPRESSION requests a default compromise between speed and 5762a988851Sagc compression (currently equivalent to level 6). 5772a988851Sagc 5782a988851Sagc deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 5792a988851Sagc enough memory, Z_STREAM_ERROR if level is not a valid compression level, 5802a988851Sagc Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 5812a988851Sagc with the version assumed by the caller (ZLIB_VERSION). 5822a988851Sagc msg is set to null if there is no error message. deflateInit does not 5832a988851Sagc perform any compression: this will be done by deflate(). 5842a988851Sagc */ 5852a988851Sagc 5862a988851Sagc 5872a988851Sagc ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 5882a988851Sagc /* 5892a988851Sagc deflate compresses as much data as possible, and stops when the input 5902a988851Sagc buffer becomes empty or the output buffer becomes full. It may introduce some 5912a988851Sagc output latency (reading input without producing any output) except when 5922a988851Sagc forced to flush. 5932a988851Sagc 5942a988851Sagc The detailed semantics are as follows. deflate performs one or both of the 5952a988851Sagc following actions: 5962a988851Sagc 5972a988851Sagc - Compress more input starting at next_in and update next_in and avail_in 5982a988851Sagc accordingly. If not all input can be processed (because there is not 5992a988851Sagc enough room in the output buffer), next_in and avail_in are updated and 6002a988851Sagc processing will resume at this point for the next call of deflate(). 6012a988851Sagc 6022a988851Sagc - Provide more output starting at next_out and update next_out and avail_out 6032a988851Sagc accordingly. This action is forced if the parameter flush is non zero. 6042a988851Sagc Forcing flush frequently degrades the compression ratio, so this parameter 6052a988851Sagc should be set only when necessary (in interactive applications). 6062a988851Sagc Some output may be provided even if flush is not set. 6072a988851Sagc 6082a988851Sagc Before the call of deflate(), the application should ensure that at least 6092a988851Sagc one of the actions is possible, by providing more input and/or consuming 6102a988851Sagc more output, and updating avail_in or avail_out accordingly; avail_out 6112a988851Sagc should never be zero before the call. The application can consume the 6122a988851Sagc compressed output when it wants, for example when the output buffer is full 6132a988851Sagc (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 6142a988851Sagc and with zero avail_out, it must be called again after making room in the 6152a988851Sagc output buffer because there might be more output pending. 6162a988851Sagc 6172a988851Sagc Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 6182a988851Sagc decide how much data to accumualte before producing output, in order to 6192a988851Sagc maximize compression. 6202a988851Sagc 6212a988851Sagc If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 6222a988851Sagc flushed to the output buffer and the output is aligned on a byte boundary, so 6232a988851Sagc that the decompressor can get all input data available so far. (In particular 6242a988851Sagc avail_in is zero after the call if enough output space has been provided 6252a988851Sagc before the call.) Flushing may degrade compression for some compression 6262a988851Sagc algorithms and so it should be used only when necessary. 6272a988851Sagc 6282a988851Sagc If flush is set to Z_FULL_FLUSH, all output is flushed as with 6292a988851Sagc Z_SYNC_FLUSH, and the compression state is reset so that decompression can 6302a988851Sagc restart from this point if previous compressed data has been damaged or if 6312a988851Sagc random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 6322a988851Sagc compression. 6332a988851Sagc 6342a988851Sagc If deflate returns with avail_out == 0, this function must be called again 6352a988851Sagc with the same value of the flush parameter and more output space (updated 6362a988851Sagc avail_out), until the flush is complete (deflate returns with non-zero 6372a988851Sagc avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 6382a988851Sagc avail_out is greater than six to avoid repeated flush markers due to 6392a988851Sagc avail_out == 0 on return. 6402a988851Sagc 6412a988851Sagc If the parameter flush is set to Z_FINISH, pending input is processed, 6422a988851Sagc pending output is flushed and deflate returns with Z_STREAM_END if there 6432a988851Sagc was enough output space; if deflate returns with Z_OK, this function must be 6442a988851Sagc called again with Z_FINISH and more output space (updated avail_out) but no 6452a988851Sagc more input data, until it returns with Z_STREAM_END or an error. After 6462a988851Sagc deflate has returned Z_STREAM_END, the only possible operations on the 6472a988851Sagc stream are deflateReset or deflateEnd. 6482a988851Sagc 6492a988851Sagc Z_FINISH can be used immediately after deflateInit if all the compression 6502a988851Sagc is to be done in a single step. In this case, avail_out must be at least 6512a988851Sagc the value returned by deflateBound (see below). If deflate does not return 6522a988851Sagc Z_STREAM_END, then it must be called again as described above. 6532a988851Sagc 6542a988851Sagc deflate() sets strm->adler to the adler32 checksum of all input read 6552a988851Sagc so far (that is, total_in bytes). 6562a988851Sagc 6572a988851Sagc deflate() may update strm->data_type if it can make a good guess about 6582a988851Sagc the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 6592a988851Sagc binary. This field is only for information purposes and does not affect 6602a988851Sagc the compression algorithm in any manner. 6612a988851Sagc 6622a988851Sagc deflate() returns Z_OK if some progress has been made (more input 6632a988851Sagc processed or more output produced), Z_STREAM_END if all input has been 6642a988851Sagc consumed and all output has been produced (only when flush is set to 6652a988851Sagc Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 6662a988851Sagc if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 6672a988851Sagc (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 6682a988851Sagc fatal, and deflate() can be called again with more input and more output 6692a988851Sagc space to continue compressing. 6702a988851Sagc */ 6712a988851Sagc 6722a988851Sagc 6732a988851Sagc ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 6742a988851Sagc /* 6752a988851Sagc All dynamically allocated data structures for this stream are freed. 6762a988851Sagc This function discards any unprocessed input and does not flush any 6772a988851Sagc pending output. 6782a988851Sagc 6792a988851Sagc deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 6802a988851Sagc stream state was inconsistent, Z_DATA_ERROR if the stream was freed 6812a988851Sagc prematurely (some input or output was discarded). In the error case, 6822a988851Sagc msg may be set but then points to a static string (which must not be 6832a988851Sagc deallocated). 6842a988851Sagc */ 6852a988851Sagc 6862a988851Sagc 6872a988851Sagc /* 6882a988851Sagc ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 6892a988851Sagc 6902a988851Sagc Initializes the internal stream state for decompression. The fields 6912a988851Sagc next_in, avail_in, zalloc, zfree and opaque must be initialized before by 6922a988851Sagc the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 6932a988851Sagc value depends on the compression method), inflateInit determines the 6942a988851Sagc compression method from the zlib header and allocates all data structures 6952a988851Sagc accordingly; otherwise the allocation will be deferred to the first call of 6962a988851Sagc inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 6972a988851Sagc use default allocation functions. 6982a988851Sagc 6992a988851Sagc inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 7002a988851Sagc memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 7012a988851Sagc version assumed by the caller. msg is set to null if there is no error 7022a988851Sagc message. inflateInit does not perform any decompression apart from reading 7032a988851Sagc the zlib header if present: this will be done by inflate(). (So next_in and 7042a988851Sagc avail_in may be modified, but next_out and avail_out are unchanged.) 7052a988851Sagc */ 7062a988851Sagc 7072a988851Sagc 7082a988851Sagc ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 7092a988851Sagc /* 7102a988851Sagc inflate decompresses as much data as possible, and stops when the input 7112a988851Sagc buffer becomes empty or the output buffer becomes full. It may introduce 7122a988851Sagc some output latency (reading input without producing any output) except when 7132a988851Sagc forced to flush. 7142a988851Sagc 7152a988851Sagc The detailed semantics are as follows. inflate performs one or both of the 7162a988851Sagc following actions: 7172a988851Sagc 7182a988851Sagc - Decompress more input starting at next_in and update next_in and avail_in 7192a988851Sagc accordingly. If not all input can be processed (because there is not 7202a988851Sagc enough room in the output buffer), next_in is updated and processing 7212a988851Sagc will resume at this point for the next call of inflate(). 7222a988851Sagc 7232a988851Sagc - Provide more output starting at next_out and update next_out and avail_out 7242a988851Sagc accordingly. inflate() provides as much output as possible, until there 7252a988851Sagc is no more input data or no more space in the output buffer (see below 7262a988851Sagc about the flush parameter). 7272a988851Sagc 7282a988851Sagc Before the call of inflate(), the application should ensure that at least 7292a988851Sagc one of the actions is possible, by providing more input and/or consuming 7302a988851Sagc more output, and updating the next_* and avail_* values accordingly. 7312a988851Sagc The application can consume the uncompressed output when it wants, for 7322a988851Sagc example when the output buffer is full (avail_out == 0), or after each 7332a988851Sagc call of inflate(). If inflate returns Z_OK and with zero avail_out, it 7342a988851Sagc must be called again after making room in the output buffer because there 7352a988851Sagc might be more output pending. 7362a988851Sagc 7372a988851Sagc The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, 7382a988851Sagc Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much 7392a988851Sagc output as possible to the output buffer. Z_BLOCK requests that inflate() stop 7402a988851Sagc if and when it gets to the next deflate block boundary. When decoding the 7412a988851Sagc zlib or gzip format, this will cause inflate() to return immediately after 7422a988851Sagc the header and before the first block. When doing a raw inflate, inflate() 7432a988851Sagc will go ahead and process the first block, and will return when it gets to 7442a988851Sagc the end of that block, or when it runs out of data. 7452a988851Sagc 7462a988851Sagc The Z_BLOCK option assists in appending to or combining deflate streams. 7472a988851Sagc Also to assist in this, on return inflate() will set strm->data_type to the 7482a988851Sagc number of unused bits in the last byte taken from strm->next_in, plus 64 7492a988851Sagc if inflate() is currently decoding the last block in the deflate stream, 7502a988851Sagc plus 128 if inflate() returned immediately after decoding an end-of-block 7512a988851Sagc code or decoding the complete header up to just before the first byte of the 7522a988851Sagc deflate stream. The end-of-block will not be indicated until all of the 7532a988851Sagc uncompressed data from that block has been written to strm->next_out. The 7542a988851Sagc number of unused bits may in general be greater than seven, except when 7552a988851Sagc bit 7 of data_type is set, in which case the number of unused bits will be 7562a988851Sagc less than eight. 7572a988851Sagc 7582a988851Sagc inflate() should normally be called until it returns Z_STREAM_END or an 7592a988851Sagc error. However if all decompression is to be performed in a single step 7602a988851Sagc (a single call of inflate), the parameter flush should be set to 7612a988851Sagc Z_FINISH. In this case all pending input is processed and all pending 7622a988851Sagc output is flushed; avail_out must be large enough to hold all the 7632a988851Sagc uncompressed data. (The size of the uncompressed data may have been saved 7642a988851Sagc by the compressor for this purpose.) The next operation on this stream must 7652a988851Sagc be inflateEnd to deallocate the decompression state. The use of Z_FINISH 7662a988851Sagc is never required, but can be used to inform inflate that a faster approach 7672a988851Sagc may be used for the single inflate() call. 7682a988851Sagc 7692a988851Sagc In this implementation, inflate() always flushes as much output as 7702a988851Sagc possible to the output buffer, and always uses the faster approach on the 7712a988851Sagc first call. So the only effect of the flush parameter in this implementation 7722a988851Sagc is on the return value of inflate(), as noted below, or when it returns early 7732a988851Sagc because Z_BLOCK is used. 7742a988851Sagc 7752a988851Sagc If a preset dictionary is needed after this call (see inflateSetDictionary 7762a988851Sagc below), inflate sets strm->adler to the adler32 checksum of the dictionary 7772a988851Sagc chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 7782a988851Sagc strm->adler to the adler32 checksum of all output produced so far (that is, 7792a988851Sagc total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 7802a988851Sagc below. At the end of the stream, inflate() checks that its computed adler32 7812a988851Sagc checksum is equal to that saved by the compressor and returns Z_STREAM_END 7822a988851Sagc only if the checksum is correct. 7832a988851Sagc 7842a988851Sagc inflate() will decompress and check either zlib-wrapped or gzip-wrapped 7852a988851Sagc deflate data. The header type is detected automatically. Any information 7862a988851Sagc contained in the gzip header is not retained, so applications that need that 7872a988851Sagc information should instead use raw inflate, see inflateInit2() below, or 7882a988851Sagc inflateBack() and perform their own processing of the gzip header and 7892a988851Sagc trailer. 7902a988851Sagc 7912a988851Sagc inflate() returns Z_OK if some progress has been made (more input processed 7922a988851Sagc or more output produced), Z_STREAM_END if the end of the compressed data has 7932a988851Sagc been reached and all uncompressed output has been produced, Z_NEED_DICT if a 7942a988851Sagc preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 7952a988851Sagc corrupted (input stream not conforming to the zlib format or incorrect check 7962a988851Sagc value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 7972a988851Sagc if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, 7982a988851Sagc Z_BUF_ERROR if no progress is possible or if there was not enough room in the 7992a988851Sagc output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 8002a988851Sagc inflate() can be called again with more input and more output space to 8012a988851Sagc continue decompressing. If Z_DATA_ERROR is returned, the application may then 8022a988851Sagc call inflateSync() to look for a good compression block if a partial recovery 8032a988851Sagc of the data is desired. 8042a988851Sagc */ 8052a988851Sagc 8062a988851Sagc 8072a988851Sagc ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 8082a988851Sagc /* 8092a988851Sagc All dynamically allocated data structures for this stream are freed. 8102a988851Sagc This function discards any unprocessed input and does not flush any 8112a988851Sagc pending output. 8122a988851Sagc 8132a988851Sagc inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 8142a988851Sagc was inconsistent. In the error case, msg may be set but then points to a 8152a988851Sagc static string (which must not be deallocated). 8162a988851Sagc */ 8172a988851Sagc 8182a988851Sagc /* Advanced functions */ 8192a988851Sagc 8202a988851Sagc /* 8212a988851Sagc The following functions are needed only in some special applications. 8222a988851Sagc */ 8232a988851Sagc 8242a988851Sagc /* 8252a988851Sagc ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 8262a988851Sagc int level, 8272a988851Sagc int method, 8282a988851Sagc int windowBits, 8292a988851Sagc int memLevel, 8302a988851Sagc int strategy)); 8312a988851Sagc 8322a988851Sagc This is another version of deflateInit with more compression options. The 8332a988851Sagc fields next_in, zalloc, zfree and opaque must be initialized before by 8342a988851Sagc the caller. 8352a988851Sagc 8362a988851Sagc The method parameter is the compression method. It must be Z_DEFLATED in 8372a988851Sagc this version of the library. 8382a988851Sagc 8392a988851Sagc The windowBits parameter is the base two logarithm of the window size 8402a988851Sagc (the size of the history buffer). It should be in the range 8..15 for this 8412a988851Sagc version of the library. Larger values of this parameter result in better 8422a988851Sagc compression at the expense of memory usage. The default value is 15 if 8432a988851Sagc deflateInit is used instead. 8442a988851Sagc 8452a988851Sagc windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 8462a988851Sagc determines the window size. deflate() will then generate raw deflate data 8472a988851Sagc with no zlib header or trailer, and will not compute an adler32 check value. 8482a988851Sagc 8492a988851Sagc windowBits can also be greater than 15 for optional gzip encoding. Add 8502a988851Sagc 16 to windowBits to write a simple gzip header and trailer around the 8512a988851Sagc compressed data instead of a zlib wrapper. The gzip header will have no 8522a988851Sagc file name, no extra data, no comment, no modification time (set to zero), 8532a988851Sagc no header crc, and the operating system will be set to 255 (unknown). If a 8542a988851Sagc gzip stream is being written, strm->adler is a crc32 instead of an adler32. 8552a988851Sagc 8562a988851Sagc The memLevel parameter specifies how much memory should be allocated 8572a988851Sagc for the internal compression state. memLevel=1 uses minimum memory but 8582a988851Sagc is slow and reduces compression ratio; memLevel=9 uses maximum memory 8592a988851Sagc for optimal speed. The default value is 8. See zconf.h for total memory 8602a988851Sagc usage as a function of windowBits and memLevel. 8612a988851Sagc 8622a988851Sagc The strategy parameter is used to tune the compression algorithm. Use the 8632a988851Sagc value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 8642a988851Sagc filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 8652a988851Sagc string match), or Z_RLE to limit match distances to one (run-length 8662a988851Sagc encoding). Filtered data consists mostly of small values with a somewhat 8672a988851Sagc random distribution. In this case, the compression algorithm is tuned to 8682a988851Sagc compress them better. The effect of Z_FILTERED is to force more Huffman 8692a988851Sagc coding and less string matching; it is somewhat intermediate between 8702a988851Sagc Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as 8712a988851Sagc Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy 8722a988851Sagc parameter only affects the compression ratio but not the correctness of the 8732a988851Sagc compressed output even if it is not set appropriately. Z_FIXED prevents the 8742a988851Sagc use of dynamic Huffman codes, allowing for a simpler decoder for special 8752a988851Sagc applications. 8762a988851Sagc 8772a988851Sagc deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 8782a988851Sagc memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 8792a988851Sagc method). msg is set to null if there is no error message. deflateInit2 does 8802a988851Sagc not perform any compression: this will be done by deflate(). 8812a988851Sagc */ 8822a988851Sagc 8832a988851Sagc ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 8842a988851Sagc const Bytef *dictionary, 8852a988851Sagc uInt dictLength)); 8862a988851Sagc /* 8872a988851Sagc Initializes the compression dictionary from the given byte sequence 8882a988851Sagc without producing any compressed output. This function must be called 8892a988851Sagc immediately after deflateInit, deflateInit2 or deflateReset, before any 8902a988851Sagc call of deflate. The compressor and decompressor must use exactly the same 8912a988851Sagc dictionary (see inflateSetDictionary). 8922a988851Sagc 8932a988851Sagc The dictionary should consist of strings (byte sequences) that are likely 8942a988851Sagc to be encountered later in the data to be compressed, with the most commonly 8952a988851Sagc used strings preferably put towards the end of the dictionary. Using a 8962a988851Sagc dictionary is most useful when the data to be compressed is short and can be 8972a988851Sagc predicted with good accuracy; the data can then be compressed better than 8982a988851Sagc with the default empty dictionary. 8992a988851Sagc 9002a988851Sagc Depending on the size of the compression data structures selected by 9012a988851Sagc deflateInit or deflateInit2, a part of the dictionary may in effect be 9022a988851Sagc discarded, for example if the dictionary is larger than the window size in 9032a988851Sagc deflate or deflate2. Thus the strings most likely to be useful should be 9042a988851Sagc put at the end of the dictionary, not at the front. In addition, the 9052a988851Sagc current implementation of deflate will use at most the window size minus 9062a988851Sagc 262 bytes of the provided dictionary. 9072a988851Sagc 9082a988851Sagc Upon return of this function, strm->adler is set to the adler32 value 9092a988851Sagc of the dictionary; the decompressor may later use this value to determine 9102a988851Sagc which dictionary has been used by the compressor. (The adler32 value 9112a988851Sagc applies to the whole dictionary even if only a subset of the dictionary is 9122a988851Sagc actually used by the compressor.) If a raw deflate was requested, then the 9132a988851Sagc adler32 value is not computed and strm->adler is not set. 9142a988851Sagc 9152a988851Sagc deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 9162a988851Sagc parameter is invalid (such as NULL dictionary) or the stream state is 9172a988851Sagc inconsistent (for example if deflate has already been called for this stream 9182a988851Sagc or if the compression method is bsort). deflateSetDictionary does not 9192a988851Sagc perform any compression: this will be done by deflate(). 9202a988851Sagc */ 9212a988851Sagc 9222a988851Sagc ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 9232a988851Sagc z_streamp source)); 9242a988851Sagc /* 9252a988851Sagc Sets the destination stream as a complete copy of the source stream. 9262a988851Sagc 9272a988851Sagc This function can be useful when several compression strategies will be 9282a988851Sagc tried, for example when there are several ways of pre-processing the input 9292a988851Sagc data with a filter. The streams that will be discarded should then be freed 9302a988851Sagc by calling deflateEnd. Note that deflateCopy duplicates the internal 9312a988851Sagc compression state which can be quite large, so this strategy is slow and 9322a988851Sagc can consume lots of memory. 9332a988851Sagc 9342a988851Sagc deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 9352a988851Sagc enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 9362a988851Sagc (such as zalloc being NULL). msg is left unchanged in both source and 9372a988851Sagc destination. 9382a988851Sagc */ 9392a988851Sagc 9402a988851Sagc ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 9412a988851Sagc /* 9422a988851Sagc This function is equivalent to deflateEnd followed by deflateInit, 9432a988851Sagc but does not free and reallocate all the internal compression state. 9442a988851Sagc The stream will keep the same compression level and any other attributes 9452a988851Sagc that may have been set by deflateInit2. 9462a988851Sagc 9472a988851Sagc deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 9482a988851Sagc stream state was inconsistent (such as zalloc or state being NULL). 9492a988851Sagc */ 9502a988851Sagc 9512a988851Sagc ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 9522a988851Sagc int level, 9532a988851Sagc int strategy)); 9542a988851Sagc /* 9552a988851Sagc Dynamically update the compression level and compression strategy. The 9562a988851Sagc interpretation of level and strategy is as in deflateInit2. This can be 9572a988851Sagc used to switch between compression and straight copy of the input data, or 9582a988851Sagc to switch to a different kind of input data requiring a different 9592a988851Sagc strategy. If the compression level is changed, the input available so far 9602a988851Sagc is compressed with the old level (and may be flushed); the new level will 9612a988851Sagc take effect only at the next call of deflate(). 9622a988851Sagc 9632a988851Sagc Before the call of deflateParams, the stream state must be set as for 9642a988851Sagc a call of deflate(), since the currently available input may have to 9652a988851Sagc be compressed and flushed. In particular, strm->avail_out must be non-zero. 9662a988851Sagc 9672a988851Sagc deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 9682a988851Sagc stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 9692a988851Sagc if strm->avail_out was zero. 9702a988851Sagc */ 9712a988851Sagc 9722a988851Sagc ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 9732a988851Sagc int good_length, 9742a988851Sagc int max_lazy, 9752a988851Sagc int nice_length, 9762a988851Sagc int max_chain)); 9772a988851Sagc /* 9782a988851Sagc Fine tune deflate's internal compression parameters. This should only be 9792a988851Sagc used by someone who understands the algorithm used by zlib's deflate for 9802a988851Sagc searching for the best matching string, and even then only by the most 9812a988851Sagc fanatic optimizer trying to squeeze out the last compressed bit for their 9822a988851Sagc specific input data. Read the deflate.c source code for the meaning of the 9832a988851Sagc max_lazy, good_length, nice_length, and max_chain parameters. 9842a988851Sagc 9852a988851Sagc deflateTune() can be called after deflateInit() or deflateInit2(), and 9862a988851Sagc returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 9872a988851Sagc */ 9882a988851Sagc 9892a988851Sagc ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 9902a988851Sagc uLong sourceLen)); 9912a988851Sagc /* 9922a988851Sagc deflateBound() returns an upper bound on the compressed size after 9932a988851Sagc deflation of sourceLen bytes. It must be called after deflateInit() 9942a988851Sagc or deflateInit2(). This would be used to allocate an output buffer 9952a988851Sagc for deflation in a single pass, and so would be called before deflate(). 9962a988851Sagc */ 9972a988851Sagc 9982a988851Sagc ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 9992a988851Sagc int bits, 10002a988851Sagc int value)); 10012a988851Sagc /* 10022a988851Sagc deflatePrime() inserts bits in the deflate output stream. The intent 10032a988851Sagc is that this function is used to start off the deflate output with the 10042a988851Sagc bits leftover from a previous deflate stream when appending to it. As such, 10052a988851Sagc this function can only be used for raw deflate, and must be used before the 10062a988851Sagc first deflate() call after a deflateInit2() or deflateReset(). bits must be 10072a988851Sagc less than or equal to 16, and that many of the least significant bits of 10082a988851Sagc value will be inserted in the output. 10092a988851Sagc 10102a988851Sagc deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 10112a988851Sagc stream state was inconsistent. 10122a988851Sagc */ 10132a988851Sagc 10142a988851Sagc ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 10152a988851Sagc gz_headerp head)); 10162a988851Sagc /* 10172a988851Sagc deflateSetHeader() provides gzip header information for when a gzip 10182a988851Sagc stream is requested by deflateInit2(). deflateSetHeader() may be called 10192a988851Sagc after deflateInit2() or deflateReset() and before the first call of 10202a988851Sagc deflate(). The text, time, os, extra field, name, and comment information 10212a988851Sagc in the provided gz_header structure are written to the gzip header (xflag is 10222a988851Sagc ignored -- the extra flags are set according to the compression level). The 10232a988851Sagc caller must assure that, if not Z_NULL, name and comment are terminated with 10242a988851Sagc a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 10252a988851Sagc available there. If hcrc is true, a gzip header crc is included. Note that 10262a988851Sagc the current versions of the command-line version of gzip (up through version 10272a988851Sagc 1.3.x) do not support header crc's, and will report that it is a "multi-part 10282a988851Sagc gzip file" and give up. 10292a988851Sagc 10302a988851Sagc If deflateSetHeader is not used, the default gzip header has text false, 10312a988851Sagc the time set to zero, and os set to 255, with no extra, name, or comment 10322a988851Sagc fields. The gzip header is returned to the default state by deflateReset(). 10332a988851Sagc 10342a988851Sagc deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 10352a988851Sagc stream state was inconsistent. 10362a988851Sagc */ 10372a988851Sagc 10382a988851Sagc /* 10392a988851Sagc ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 10402a988851Sagc int windowBits)); 10412a988851Sagc 10422a988851Sagc This is another version of inflateInit with an extra parameter. The 10432a988851Sagc fields next_in, avail_in, zalloc, zfree and opaque must be initialized 10442a988851Sagc before by the caller. 10452a988851Sagc 10462a988851Sagc The windowBits parameter is the base two logarithm of the maximum window 10472a988851Sagc size (the size of the history buffer). It should be in the range 8..15 for 10482a988851Sagc this version of the library. The default value is 15 if inflateInit is used 10492a988851Sagc instead. windowBits must be greater than or equal to the windowBits value 10502a988851Sagc provided to deflateInit2() while compressing, or it must be equal to 15 if 10512a988851Sagc deflateInit2() was not used. If a compressed stream with a larger window 10522a988851Sagc size is given as input, inflate() will return with the error code 10532a988851Sagc Z_DATA_ERROR instead of trying to allocate a larger window. 10542a988851Sagc 10552a988851Sagc windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 10562a988851Sagc determines the window size. inflate() will then process raw deflate data, 10572a988851Sagc not looking for a zlib or gzip header, not generating a check value, and not 10582a988851Sagc looking for any check values for comparison at the end of the stream. This 10592a988851Sagc is for use with other formats that use the deflate compressed data format 10602a988851Sagc such as zip. Those formats provide their own check values. If a custom 10612a988851Sagc format is developed using the raw deflate format for compressed data, it is 10622a988851Sagc recommended that a check value such as an adler32 or a crc32 be applied to 10632a988851Sagc the uncompressed data as is done in the zlib, gzip, and zip formats. For 10642a988851Sagc most applications, the zlib format should be used as is. Note that comments 10652a988851Sagc above on the use in deflateInit2() applies to the magnitude of windowBits. 10662a988851Sagc 10672a988851Sagc windowBits can also be greater than 15 for optional gzip decoding. Add 10682a988851Sagc 32 to windowBits to enable zlib and gzip decoding with automatic header 10692a988851Sagc detection, or add 16 to decode only the gzip format (the zlib format will 10702a988851Sagc return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 10712a988851Sagc a crc32 instead of an adler32. 10722a988851Sagc 10732a988851Sagc inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 10742a988851Sagc memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg 10752a988851Sagc is set to null if there is no error message. inflateInit2 does not perform 10762a988851Sagc any decompression apart from reading the zlib header if present: this will 10772a988851Sagc be done by inflate(). (So next_in and avail_in may be modified, but next_out 10782a988851Sagc and avail_out are unchanged.) 10792a988851Sagc */ 10802a988851Sagc 10812a988851Sagc ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 10822a988851Sagc const Bytef *dictionary, 10832a988851Sagc uInt dictLength)); 10842a988851Sagc /* 10852a988851Sagc Initializes the decompression dictionary from the given uncompressed byte 10862a988851Sagc sequence. This function must be called immediately after a call of inflate, 10872a988851Sagc if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 10882a988851Sagc can be determined from the adler32 value returned by that call of inflate. 10892a988851Sagc The compressor and decompressor must use exactly the same dictionary (see 10902a988851Sagc deflateSetDictionary). For raw inflate, this function can be called 10912a988851Sagc immediately after inflateInit2() or inflateReset() and before any call of 10922a988851Sagc inflate() to set the dictionary. The application must insure that the 10932a988851Sagc dictionary that was used for compression is provided. 10942a988851Sagc 10952a988851Sagc inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 10962a988851Sagc parameter is invalid (such as NULL dictionary) or the stream state is 10972a988851Sagc inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 10982a988851Sagc expected one (incorrect adler32 value). inflateSetDictionary does not 10992a988851Sagc perform any decompression: this will be done by subsequent calls of 11002a988851Sagc inflate(). 11012a988851Sagc */ 11022a988851Sagc 11032a988851Sagc ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 11042a988851Sagc /* 11052a988851Sagc Skips invalid compressed data until a full flush point (see above the 11062a988851Sagc description of deflate with Z_FULL_FLUSH) can be found, or until all 11072a988851Sagc available input is skipped. No output is provided. 11082a988851Sagc 11092a988851Sagc inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 11102a988851Sagc if no more input was provided, Z_DATA_ERROR if no flush point has been found, 11112a988851Sagc or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 11122a988851Sagc case, the application may save the current current value of total_in which 11132a988851Sagc indicates where valid compressed data was found. In the error case, the 11142a988851Sagc application may repeatedly call inflateSync, providing more input each time, 11152a988851Sagc until success or end of the input data. 11162a988851Sagc */ 11172a988851Sagc 11182a988851Sagc ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 11192a988851Sagc z_streamp source)); 11202a988851Sagc /* 11212a988851Sagc Sets the destination stream as a complete copy of the source stream. 11222a988851Sagc 11232a988851Sagc This function can be useful when randomly accessing a large stream. The 11242a988851Sagc first pass through the stream can periodically record the inflate state, 11252a988851Sagc allowing restarting inflate at those points when randomly accessing the 11262a988851Sagc stream. 11272a988851Sagc 11282a988851Sagc inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 11292a988851Sagc enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 11302a988851Sagc (such as zalloc being NULL). msg is left unchanged in both source and 11312a988851Sagc destination. 11322a988851Sagc */ 11332a988851Sagc 11342a988851Sagc ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 11352a988851Sagc /* 11362a988851Sagc This function is equivalent to inflateEnd followed by inflateInit, 11372a988851Sagc but does not free and reallocate all the internal decompression state. 11382a988851Sagc The stream will keep attributes that may have been set by inflateInit2. 11392a988851Sagc 11402a988851Sagc inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 11412a988851Sagc stream state was inconsistent (such as zalloc or state being NULL). 11422a988851Sagc */ 11432a988851Sagc 1144*9c15b0b0Sagc ZEXTERN int ZEXPORT netpgpv_inflatePrime OF((z_streamp strm, 11452a988851Sagc int bits, 11462a988851Sagc int value)); 11472a988851Sagc /* 11482a988851Sagc This function inserts bits in the inflate input stream. The intent is 11492a988851Sagc that this function is used to start inflating at a bit position in the 11502a988851Sagc middle of a byte. The provided bits will be used before any bytes are used 11512a988851Sagc from next_in. This function should only be used with raw inflate, and 11522a988851Sagc should be used before the first inflate() call after inflateInit2() or 11532a988851Sagc inflateReset(). bits must be less than or equal to 16, and that many of the 11542a988851Sagc least significant bits of value will be inserted in the input. 11552a988851Sagc 1156*9c15b0b0Sagc netpgpv_inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 11572a988851Sagc stream state was inconsistent. 11582a988851Sagc */ 11592a988851Sagc 1160*9c15b0b0Sagc ZEXTERN int ZEXPORT netpgpv_inflateGetHeader OF((z_streamp strm, 11612a988851Sagc gz_headerp head)); 11622a988851Sagc /* 1163*9c15b0b0Sagc netpgpv_inflateGetHeader() requests that gzip header information be stored in the 1164*9c15b0b0Sagc provided gz_header structure. netpgpv_inflateGetHeader() may be called after 11652a988851Sagc inflateInit2() or inflateReset(), and before the first call of inflate(). 11662a988851Sagc As inflate() processes the gzip stream, head->done is zero until the header 11672a988851Sagc is completed, at which time head->done is set to one. If a zlib stream is 11682a988851Sagc being decoded, then head->done is set to -1 to indicate that there will be 11692a988851Sagc no gzip header information forthcoming. Note that Z_BLOCK can be used to 11702a988851Sagc force inflate() to return immediately after header processing is complete 11712a988851Sagc and before any actual data is decompressed. 11722a988851Sagc 11732a988851Sagc The text, time, xflags, and os fields are filled in with the gzip header 11742a988851Sagc contents. hcrc is set to true if there is a header CRC. (The header CRC 11752a988851Sagc was valid if done is set to one.) If extra is not Z_NULL, then extra_max 11762a988851Sagc contains the maximum number of bytes to write to extra. Once done is true, 11772a988851Sagc extra_len contains the actual extra field length, and extra contains the 11782a988851Sagc extra field, or that field truncated if extra_max is less than extra_len. 11792a988851Sagc If name is not Z_NULL, then up to name_max characters are written there, 11802a988851Sagc terminated with a zero unless the length is greater than name_max. If 11812a988851Sagc comment is not Z_NULL, then up to comm_max characters are written there, 11822a988851Sagc terminated with a zero unless the length is greater than comm_max. When 11832a988851Sagc any of extra, name, or comment are not Z_NULL and the respective field is 11842a988851Sagc not present in the header, then that field is set to Z_NULL to signal its 11852a988851Sagc absence. This allows the use of deflateSetHeader() with the returned 11862a988851Sagc structure to duplicate the header. However if those fields are set to 11872a988851Sagc allocated memory, then the application will need to save those pointers 11882a988851Sagc elsewhere so that they can be eventually freed. 11892a988851Sagc 1190*9c15b0b0Sagc If netpgpv_inflateGetHeader is not used, then the header information is simply 11912a988851Sagc discarded. The header is always checked for validity, including the header 11922a988851Sagc CRC if present. inflateReset() will reset the process to discard the header 1193*9c15b0b0Sagc information. The application would need to call netpgpv_inflateGetHeader() again to 11942a988851Sagc retrieve the header from the next gzip stream. 11952a988851Sagc 1196*9c15b0b0Sagc netpgpv_inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 11972a988851Sagc stream state was inconsistent. 11982a988851Sagc */ 11992a988851Sagc 12002a988851Sagc /* 12012a988851Sagc ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 12022a988851Sagc unsigned char FAR *window)); 12032a988851Sagc 12042a988851Sagc Initialize the internal stream state for decompression using inflateBack() 12052a988851Sagc calls. The fields zalloc, zfree and opaque in strm must be initialized 12062a988851Sagc before the call. If zalloc and zfree are Z_NULL, then the default library- 12072a988851Sagc derived memory allocation routines are used. windowBits is the base two 12082a988851Sagc logarithm of the window size, in the range 8..15. window is a caller 12092a988851Sagc supplied buffer of that size. Except for special applications where it is 12102a988851Sagc assured that deflate was used with small window sizes, windowBits must be 15 12112a988851Sagc and a 32K byte window must be supplied to be able to decompress general 12122a988851Sagc deflate streams. 12132a988851Sagc 12142a988851Sagc See inflateBack() for the usage of these routines. 12152a988851Sagc 12162a988851Sagc inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 12172a988851Sagc the paramaters are invalid, Z_MEM_ERROR if the internal state could not 12182a988851Sagc be allocated, or Z_VERSION_ERROR if the version of the library does not 12192a988851Sagc match the version of the header file. 12202a988851Sagc */ 12212a988851Sagc 12222a988851Sagc typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 12232a988851Sagc typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 12242a988851Sagc 12252a988851Sagc ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 12262a988851Sagc in_func in, void FAR *in_desc, 12272a988851Sagc out_func out, void FAR *out_desc)); 12282a988851Sagc /* 12292a988851Sagc inflateBack() does a raw inflate with a single call using a call-back 12302a988851Sagc interface for input and output. This is more efficient than inflate() for 12312a988851Sagc file i/o applications in that it avoids copying between the output and the 12322a988851Sagc sliding window by simply making the window itself the output buffer. This 12332a988851Sagc function trusts the application to not change the output buffer passed by 12342a988851Sagc the output function, at least until inflateBack() returns. 12352a988851Sagc 12362a988851Sagc inflateBackInit() must be called first to allocate the internal state 12372a988851Sagc and to initialize the state with the user-provided window buffer. 12382a988851Sagc inflateBack() may then be used multiple times to inflate a complete, raw 12392a988851Sagc deflate stream with each call. inflateBackEnd() is then called to free 12402a988851Sagc the allocated state. 12412a988851Sagc 12422a988851Sagc A raw deflate stream is one with no zlib or gzip header or trailer. 12432a988851Sagc This routine would normally be used in a utility that reads zip or gzip 12442a988851Sagc files and writes out uncompressed files. The utility would decode the 12452a988851Sagc header and process the trailer on its own, hence this routine expects 12462a988851Sagc only the raw deflate stream to decompress. This is different from the 12472a988851Sagc normal behavior of inflate(), which expects either a zlib or gzip header and 12482a988851Sagc trailer around the deflate stream. 12492a988851Sagc 12502a988851Sagc inflateBack() uses two subroutines supplied by the caller that are then 12512a988851Sagc called by inflateBack() for input and output. inflateBack() calls those 12522a988851Sagc routines until it reads a complete deflate stream and writes out all of the 12532a988851Sagc uncompressed data, or until it encounters an error. The function's 12542a988851Sagc parameters and return types are defined above in the in_func and out_func 12552a988851Sagc typedefs. inflateBack() will call in(in_desc, &buf) which should return the 12562a988851Sagc number of bytes of provided input, and a pointer to that input in buf. If 12572a988851Sagc there is no input available, in() must return zero--buf is ignored in that 12582a988851Sagc case--and inflateBack() will return a buffer error. inflateBack() will call 12592a988851Sagc out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 12602a988851Sagc should return zero on success, or non-zero on failure. If out() returns 12612a988851Sagc non-zero, inflateBack() will return with an error. Neither in() nor out() 12622a988851Sagc are permitted to change the contents of the window provided to 12632a988851Sagc inflateBackInit(), which is also the buffer that out() uses to write from. 12642a988851Sagc The length written by out() will be at most the window size. Any non-zero 12652a988851Sagc amount of input may be provided by in(). 12662a988851Sagc 12672a988851Sagc For convenience, inflateBack() can be provided input on the first call by 12682a988851Sagc setting strm->next_in and strm->avail_in. If that input is exhausted, then 12692a988851Sagc in() will be called. Therefore strm->next_in must be initialized before 12702a988851Sagc calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 12712a988851Sagc immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 12722a988851Sagc must also be initialized, and then if strm->avail_in is not zero, input will 12732a988851Sagc initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 12742a988851Sagc 12752a988851Sagc The in_desc and out_desc parameters of inflateBack() is passed as the 12762a988851Sagc first parameter of in() and out() respectively when they are called. These 12772a988851Sagc descriptors can be optionally used to pass any information that the caller- 12782a988851Sagc supplied in() and out() functions need to do their job. 12792a988851Sagc 12802a988851Sagc On return, inflateBack() will set strm->next_in and strm->avail_in to 12812a988851Sagc pass back any unused input that was provided by the last in() call. The 12822a988851Sagc return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 12832a988851Sagc if in() or out() returned an error, Z_DATA_ERROR if there was a format 12842a988851Sagc error in the deflate stream (in which case strm->msg is set to indicate the 12852a988851Sagc nature of the error), or Z_STREAM_ERROR if the stream was not properly 12862a988851Sagc initialized. In the case of Z_BUF_ERROR, an input or output error can be 12872a988851Sagc distinguished using strm->next_in which will be Z_NULL only if in() returned 12882a988851Sagc an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to 12892a988851Sagc out() returning non-zero. (in() will always be called before out(), so 12902a988851Sagc strm->next_in is assured to be defined if out() returns non-zero.) Note 12912a988851Sagc that inflateBack() cannot return Z_OK. 12922a988851Sagc */ 12932a988851Sagc 12942a988851Sagc ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 12952a988851Sagc /* 12962a988851Sagc All memory allocated by inflateBackInit() is freed. 12972a988851Sagc 12982a988851Sagc inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 12992a988851Sagc state was inconsistent. 13002a988851Sagc */ 13012a988851Sagc 13022a988851Sagc ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 13032a988851Sagc /* Return flags indicating compile-time options. 13042a988851Sagc 13052a988851Sagc Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 13062a988851Sagc 1.0: size of uInt 13072a988851Sagc 3.2: size of uLong 13082a988851Sagc 5.4: size of voidpf (pointer) 13092a988851Sagc 7.6: size of z_off_t 13102a988851Sagc 13112a988851Sagc Compiler, assembler, and debug options: 13122a988851Sagc 8: ZLIB_DEBUG 13132a988851Sagc 9: ASMV or ASMINF -- use ASM code 13142a988851Sagc 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 13152a988851Sagc 11: 0 (reserved) 13162a988851Sagc 13172a988851Sagc One-time table building (smaller code, but not thread-safe if true): 13182a988851Sagc 12: BUILDFIXED -- build static block decoding tables when needed 13192a988851Sagc 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 13202a988851Sagc 14,15: 0 (reserved) 13212a988851Sagc 13222a988851Sagc Library content (indicates missing functionality): 13232a988851Sagc 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 13242a988851Sagc deflate code when not needed) 13252a988851Sagc 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 13262a988851Sagc and decode gzip streams (to avoid linking crc code) 13272a988851Sagc 18-19: 0 (reserved) 13282a988851Sagc 13292a988851Sagc Operation variations (changes in library functionality): 13302a988851Sagc 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 13312a988851Sagc 21: FASTEST -- deflate algorithm with only one, lowest compression level 13322a988851Sagc 22,23: 0 (reserved) 13332a988851Sagc 13342a988851Sagc The sprintf variant used by gzprintf (zero is best): 13352a988851Sagc 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 13362a988851Sagc 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 13372a988851Sagc 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 13382a988851Sagc 13392a988851Sagc Remainder: 13402a988851Sagc 27-31: 0 (reserved) 13412a988851Sagc */ 13422a988851Sagc 13432a988851Sagc 13442a988851Sagc /* utility functions */ 13452a988851Sagc 13462a988851Sagc /* 13472a988851Sagc The following utility functions are implemented on top of the 13482a988851Sagc basic stream-oriented functions. To simplify the interface, some 13492a988851Sagc default options are assumed (compression level and memory usage, 13502a988851Sagc standard memory allocation functions). The source code of these 13512a988851Sagc utility functions can easily be modified if you need special options. 13522a988851Sagc */ 13532a988851Sagc 13542a988851Sagc ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 13552a988851Sagc const Bytef *source, uLong sourceLen)); 13562a988851Sagc /* 13572a988851Sagc Compresses the source buffer into the destination buffer. sourceLen is 13582a988851Sagc the byte length of the source buffer. Upon entry, destLen is the total 13592a988851Sagc size of the destination buffer, which must be at least the value returned 13602a988851Sagc by compressBound(sourceLen). Upon exit, destLen is the actual size of the 13612a988851Sagc compressed buffer. 13622a988851Sagc This function can be used to compress a whole file at once if the 13632a988851Sagc input file is mmap'ed. 13642a988851Sagc compress returns Z_OK if success, Z_MEM_ERROR if there was not 13652a988851Sagc enough memory, Z_BUF_ERROR if there was not enough room in the output 13662a988851Sagc buffer. 13672a988851Sagc */ 13682a988851Sagc 13692a988851Sagc ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 13702a988851Sagc const Bytef *source, uLong sourceLen, 13712a988851Sagc int level)); 13722a988851Sagc /* 13732a988851Sagc Compresses the source buffer into the destination buffer. The level 13742a988851Sagc parameter has the same meaning as in deflateInit. sourceLen is the byte 13752a988851Sagc length of the source buffer. Upon entry, destLen is the total size of the 13762a988851Sagc destination buffer, which must be at least the value returned by 13772a988851Sagc compressBound(sourceLen). Upon exit, destLen is the actual size of the 13782a988851Sagc compressed buffer. 13792a988851Sagc 13802a988851Sagc compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 13812a988851Sagc memory, Z_BUF_ERROR if there was not enough room in the output buffer, 13822a988851Sagc Z_STREAM_ERROR if the level parameter is invalid. 13832a988851Sagc */ 13842a988851Sagc 13852a988851Sagc ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 13862a988851Sagc /* 13872a988851Sagc compressBound() returns an upper bound on the compressed size after 13882a988851Sagc compress() or compress2() on sourceLen bytes. It would be used before 13892a988851Sagc a compress() or compress2() call to allocate the destination buffer. 13902a988851Sagc */ 13912a988851Sagc 13922a988851Sagc ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 13932a988851Sagc const Bytef *source, uLong sourceLen)); 13942a988851Sagc /* 13952a988851Sagc Decompresses the source buffer into the destination buffer. sourceLen is 13962a988851Sagc the byte length of the source buffer. Upon entry, destLen is the total 13972a988851Sagc size of the destination buffer, which must be large enough to hold the 13982a988851Sagc entire uncompressed data. (The size of the uncompressed data must have 13992a988851Sagc been saved previously by the compressor and transmitted to the decompressor 14002a988851Sagc by some mechanism outside the scope of this compression library.) 14012a988851Sagc Upon exit, destLen is the actual size of the compressed buffer. 14022a988851Sagc This function can be used to decompress a whole file at once if the 14032a988851Sagc input file is mmap'ed. 14042a988851Sagc 14052a988851Sagc uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 14062a988851Sagc enough memory, Z_BUF_ERROR if there was not enough room in the output 14072a988851Sagc buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. 14082a988851Sagc */ 14092a988851Sagc 14102a988851Sagc 14112a988851Sagc typedef voidp gzFile; 14122a988851Sagc 14132a988851Sagc ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 14142a988851Sagc /* 14152a988851Sagc Opens a gzip (.gz) file for reading or writing. The mode parameter 14162a988851Sagc is as in fopen ("rb" or "wb") but can also include a compression level 14172a988851Sagc ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 14182a988851Sagc Huffman only compression as in "wb1h", or 'R' for run-length encoding 14192a988851Sagc as in "wb1R". (See the description of deflateInit2 for more information 14202a988851Sagc about the strategy parameter.) 14212a988851Sagc 14222a988851Sagc gzopen can be used to read a file which is not in gzip format; in this 14232a988851Sagc case gzread will directly read from the file without decompression. 14242a988851Sagc 14252a988851Sagc gzopen returns NULL if the file could not be opened or if there was 14262a988851Sagc insufficient memory to allocate the (de)compression state; errno 14272a988851Sagc can be checked to distinguish the two cases (if errno is zero, the 14282a988851Sagc zlib error is Z_MEM_ERROR). */ 14292a988851Sagc 14302a988851Sagc ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 14312a988851Sagc /* 14322a988851Sagc gzdopen() associates a gzFile with the file descriptor fd. File 14332a988851Sagc descriptors are obtained from calls like open, dup, creat, pipe or 14342a988851Sagc fileno (in the file has been previously opened with fopen). 14352a988851Sagc The mode parameter is as in gzopen. 14362a988851Sagc The next call of gzclose on the returned gzFile will also close the 14372a988851Sagc file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 14382a988851Sagc descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 14392a988851Sagc gzdopen returns NULL if there was insufficient memory to allocate 14402a988851Sagc the (de)compression state. 14412a988851Sagc */ 14422a988851Sagc 14432a988851Sagc ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 14442a988851Sagc /* 14452a988851Sagc Dynamically update the compression level or strategy. See the description 14462a988851Sagc of deflateInit2 for the meaning of these parameters. 14472a988851Sagc gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 14482a988851Sagc opened for writing. 14492a988851Sagc */ 14502a988851Sagc 14512a988851Sagc ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 14522a988851Sagc /* 14532a988851Sagc Reads the given number of uncompressed bytes from the compressed file. 14542a988851Sagc If the input file was not in gzip format, gzread copies the given number 14552a988851Sagc of bytes into the buffer. 14562a988851Sagc gzread returns the number of uncompressed bytes actually read (0 for 14572a988851Sagc end of file, -1 for error). */ 14582a988851Sagc 14592a988851Sagc ZEXTERN int ZEXPORT gzwrite OF((gzFile file, 14602a988851Sagc voidpc buf, unsigned len)); 14612a988851Sagc /* 14622a988851Sagc Writes the given number of uncompressed bytes into the compressed file. 14632a988851Sagc gzwrite returns the number of uncompressed bytes actually written 14642a988851Sagc (0 in case of error). 14652a988851Sagc */ 14662a988851Sagc 14672a988851Sagc ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 14682a988851Sagc /* 14692a988851Sagc Converts, formats, and writes the args to the compressed file under 14702a988851Sagc control of the format string, as in fprintf. gzprintf returns the number of 14712a988851Sagc uncompressed bytes actually written (0 in case of error). The number of 14722a988851Sagc uncompressed bytes written is limited to 4095. The caller should assure that 14732a988851Sagc this limit is not exceeded. If it is exceeded, then gzprintf() will return 14742a988851Sagc return an error (0) with nothing written. In this case, there may also be a 14752a988851Sagc buffer overflow with unpredictable consequences, which is possible only if 14762a988851Sagc zlib was compiled with the insecure functions sprintf() or vsprintf() 14772a988851Sagc because the secure snprintf() or vsnprintf() functions were not available. 14782a988851Sagc */ 14792a988851Sagc 14802a988851Sagc ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 14812a988851Sagc /* 14822a988851Sagc Writes the given null-terminated string to the compressed file, excluding 14832a988851Sagc the terminating null character. 14842a988851Sagc gzputs returns the number of characters written, or -1 in case of error. 14852a988851Sagc */ 14862a988851Sagc 14872a988851Sagc ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 14882a988851Sagc /* 14892a988851Sagc Reads bytes from the compressed file until len-1 characters are read, or 14902a988851Sagc a newline character is read and transferred to buf, or an end-of-file 14912a988851Sagc condition is encountered. The string is then terminated with a null 14922a988851Sagc character. 14932a988851Sagc gzgets returns buf, or Z_NULL in case of error. 14942a988851Sagc */ 14952a988851Sagc 14962a988851Sagc ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 14972a988851Sagc /* 14982a988851Sagc Writes c, converted to an unsigned char, into the compressed file. 14992a988851Sagc gzputc returns the value that was written, or -1 in case of error. 15002a988851Sagc */ 15012a988851Sagc 15022a988851Sagc ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 15032a988851Sagc /* 15042a988851Sagc Reads one byte from the compressed file. gzgetc returns this byte 15052a988851Sagc or -1 in case of end of file or error. 15062a988851Sagc */ 15072a988851Sagc 15082a988851Sagc ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 15092a988851Sagc /* 15102a988851Sagc Push one character back onto the stream to be read again later. 15112a988851Sagc Only one character of push-back is allowed. gzungetc() returns the 15122a988851Sagc character pushed, or -1 on failure. gzungetc() will fail if a 15132a988851Sagc character has been pushed but not read yet, or if c is -1. The pushed 15142a988851Sagc character will be discarded if the stream is repositioned with gzseek() 15152a988851Sagc or gzrewind(). 15162a988851Sagc */ 15172a988851Sagc 15182a988851Sagc ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 15192a988851Sagc /* 15202a988851Sagc Flushes all pending output into the compressed file. The parameter 15212a988851Sagc flush is as in the deflate() function. The return value is the zlib 15222a988851Sagc error number (see function gzerror below). gzflush returns Z_OK if 15232a988851Sagc the flush parameter is Z_FINISH and all output could be flushed. 15242a988851Sagc gzflush should be called only when strictly necessary because it can 15252a988851Sagc degrade compression. 15262a988851Sagc */ 15272a988851Sagc 15282a988851Sagc ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 15292a988851Sagc z_off_t offset, int whence)); 15302a988851Sagc /* 15312a988851Sagc Sets the starting position for the next gzread or gzwrite on the 15322a988851Sagc given compressed file. The offset represents a number of bytes in the 15332a988851Sagc uncompressed data stream. The whence parameter is defined as in lseek(2); 15342a988851Sagc the value SEEK_END is not supported. 15352a988851Sagc If the file is opened for reading, this function is emulated but can be 15362a988851Sagc extremely slow. If the file is opened for writing, only forward seeks are 15372a988851Sagc supported; gzseek then compresses a sequence of zeroes up to the new 15382a988851Sagc starting position. 15392a988851Sagc 15402a988851Sagc gzseek returns the resulting offset location as measured in bytes from 15412a988851Sagc the beginning of the uncompressed stream, or -1 in case of error, in 15422a988851Sagc particular if the file is opened for writing and the new starting position 15432a988851Sagc would be before the current position. 15442a988851Sagc */ 15452a988851Sagc 15462a988851Sagc ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 15472a988851Sagc /* 15482a988851Sagc Rewinds the given file. This function is supported only for reading. 15492a988851Sagc 15502a988851Sagc gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 15512a988851Sagc */ 15522a988851Sagc 15532a988851Sagc ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 15542a988851Sagc /* 15552a988851Sagc Returns the starting position for the next gzread or gzwrite on the 15562a988851Sagc given compressed file. This position represents a number of bytes in the 15572a988851Sagc uncompressed data stream. 15582a988851Sagc 15592a988851Sagc gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 15602a988851Sagc */ 15612a988851Sagc 15622a988851Sagc ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 15632a988851Sagc /* 15642a988851Sagc Returns 1 when EOF has previously been detected reading the given 15652a988851Sagc input stream, otherwise zero. 15662a988851Sagc */ 15672a988851Sagc 15682a988851Sagc ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 15692a988851Sagc /* 15702a988851Sagc Returns 1 if file is being read directly without decompression, otherwise 15712a988851Sagc zero. 15722a988851Sagc */ 15732a988851Sagc 15742a988851Sagc ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 15752a988851Sagc /* 15762a988851Sagc Flushes all pending output if necessary, closes the compressed file 15772a988851Sagc and deallocates all the (de)compression state. The return value is the zlib 15782a988851Sagc error number (see function gzerror below). 15792a988851Sagc */ 15802a988851Sagc 15812a988851Sagc ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 15822a988851Sagc /* 15832a988851Sagc Returns the error message for the last error which occurred on the 15842a988851Sagc given compressed file. errnum is set to zlib error number. If an 15852a988851Sagc error occurred in the file system and not in the compression library, 15862a988851Sagc errnum is set to Z_ERRNO and the application may consult errno 15872a988851Sagc to get the exact error code. 15882a988851Sagc */ 15892a988851Sagc 15902a988851Sagc ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 15912a988851Sagc /* 15922a988851Sagc Clears the error and end-of-file flags for file. This is analogous to the 15932a988851Sagc clearerr() function in stdio. This is useful for continuing to read a gzip 15942a988851Sagc file that is being written concurrently. 15952a988851Sagc */ 15962a988851Sagc 15972a988851Sagc /* checksum functions */ 15982a988851Sagc 15992a988851Sagc /* 16002a988851Sagc These functions are not related to compression but are exported 16012a988851Sagc anyway because they might be useful in applications using the 16022a988851Sagc compression library. 16032a988851Sagc */ 16042a988851Sagc 16052a988851Sagc ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 16062a988851Sagc /* 16072a988851Sagc Update a running Adler-32 checksum with the bytes buf[0..len-1] and 16082a988851Sagc return the updated checksum. If buf is NULL, this function returns 16092a988851Sagc the required initial value for the checksum. 16102a988851Sagc An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 16112a988851Sagc much faster. Usage example: 16122a988851Sagc 16132a988851Sagc uLong adler = adler32(0L, Z_NULL, 0); 16142a988851Sagc 16152a988851Sagc while (read_buffer(buffer, length) != EOF) { 16162a988851Sagc adler = adler32(adler, buffer, length); 16172a988851Sagc } 16182a988851Sagc if (adler != original_adler) error(); 16192a988851Sagc */ 16202a988851Sagc 16212a988851Sagc ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 16222a988851Sagc z_off_t len2)); 16232a988851Sagc /* 16242a988851Sagc Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 16252a988851Sagc and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 16262a988851Sagc each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 16272a988851Sagc seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. 16282a988851Sagc */ 16292a988851Sagc 16302a988851Sagc #if !defined(_KERNEL) && !defined(_STANDALONE) 16312a988851Sagc ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 16322a988851Sagc #endif 16332a988851Sagc /* 16342a988851Sagc Update a running CRC-32 with the bytes buf[0..len-1] and return the 16352a988851Sagc updated CRC-32. If buf is NULL, this function returns the required initial 16362a988851Sagc value for the for the crc. Pre- and post-conditioning (one's complement) is 16372a988851Sagc performed within this function so it shouldn't be done by the application. 16382a988851Sagc Usage example: 16392a988851Sagc 16402a988851Sagc uLong crc = crc32(0L, Z_NULL, 0); 16412a988851Sagc 16422a988851Sagc while (read_buffer(buffer, length) != EOF) { 16432a988851Sagc crc = crc32(crc, buffer, length); 16442a988851Sagc } 16452a988851Sagc if (crc != original_crc) error(); 16462a988851Sagc */ 16472a988851Sagc 16482a988851Sagc ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 16492a988851Sagc 16502a988851Sagc /* 16512a988851Sagc Combine two CRC-32 check values into one. For two sequences of bytes, 16522a988851Sagc seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 16532a988851Sagc calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 16542a988851Sagc check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 16552a988851Sagc len2. 16562a988851Sagc */ 16572a988851Sagc 16582a988851Sagc 16592a988851Sagc /* various hacks, don't look :) */ 16602a988851Sagc 16612a988851Sagc /* deflateInit and inflateInit are macros to allow checking the zlib version 16622a988851Sagc * and the compiler's view of z_stream: 16632a988851Sagc */ 16642a988851Sagc ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 16652a988851Sagc const char *version, int stream_size)); 16662a988851Sagc ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 16672a988851Sagc const char *version, int stream_size)); 16682a988851Sagc ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 16692a988851Sagc int windowBits, int memLevel, 16702a988851Sagc int strategy, const char *version, 16712a988851Sagc int stream_size)); 16722a988851Sagc ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 16732a988851Sagc const char *version, int stream_size)); 16742a988851Sagc ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 16752a988851Sagc unsigned char FAR *window, 16762a988851Sagc const char *version, 16772a988851Sagc int stream_size)); 16782a988851Sagc #define deflateInit(strm, level) \ 16792a988851Sagc deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 16802a988851Sagc #define inflateInit(strm) \ 16812a988851Sagc inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 16822a988851Sagc #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 16832a988851Sagc deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 16842a988851Sagc (strategy), ZLIB_VERSION, sizeof(z_stream)) 16852a988851Sagc #define inflateInit2(strm, windowBits) \ 16862a988851Sagc inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 16872a988851Sagc #define inflateBackInit(strm, windowBits, window) \ 16882a988851Sagc inflateBackInit_((strm), (windowBits), (window), \ 16892a988851Sagc ZLIB_VERSION, sizeof(z_stream)) 16902a988851Sagc 16912a988851Sagc 16922a988851Sagc #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) 16932a988851Sagc struct internal_state {int dummy;}; /* hack for buggy compilers */ 16942a988851Sagc #endif 16952a988851Sagc 16962a988851Sagc ZEXTERN const char * ZEXPORT zError OF((int)); 16972a988851Sagc ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); 16982a988851Sagc ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); 16992a988851Sagc 17002a988851Sagc #ifdef __cplusplus 17012a988851Sagc } 17022a988851Sagc #endif 17032a988851Sagc 17042a988851Sagc #endif /* ZLIB_H */ 1705