1*86d7f5d3SJohn Marino /* $FreeBSD: src/sys/net/zlib.h,v 1.7.2.1 2002/07/31 14:13:05 rwatson Exp $ */ 2*86d7f5d3SJohn Marino /* $DragonFly: src/sys/net/zlib.h,v 1.5 2006/05/20 02:42:08 dillon Exp $ */ 3*86d7f5d3SJohn Marino 4*86d7f5d3SJohn Marino /* 5*86d7f5d3SJohn Marino * This file is derived from zlib.h and zconf.h from the zlib-1.0.4 6*86d7f5d3SJohn Marino * distribution by Jean-loup Gailly and Mark Adler, with some additions 7*86d7f5d3SJohn Marino * by Paul Mackerras to aid in implementing Deflate compression and 8*86d7f5d3SJohn Marino * decompression for PPP packets. 9*86d7f5d3SJohn Marino */ 10*86d7f5d3SJohn Marino 11*86d7f5d3SJohn Marino /* 12*86d7f5d3SJohn Marino * ==FILEVERSION 971127== 13*86d7f5d3SJohn Marino * 14*86d7f5d3SJohn Marino * This marker is used by the Linux installation script to determine 15*86d7f5d3SJohn Marino * whether an up-to-date version of this file is already installed. 16*86d7f5d3SJohn Marino */ 17*86d7f5d3SJohn Marino 18*86d7f5d3SJohn Marino 19*86d7f5d3SJohn Marino /* +++ zlib.h */ 20*86d7f5d3SJohn Marino /* zlib.h -- interface of the 'zlib' general purpose compression library 21*86d7f5d3SJohn Marino version 1.0.4, Jul 24th, 1996. 22*86d7f5d3SJohn Marino 23*86d7f5d3SJohn Marino Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler 24*86d7f5d3SJohn Marino 25*86d7f5d3SJohn Marino This software is provided 'as-is', without any express or implied 26*86d7f5d3SJohn Marino warranty. In no event will the authors be held liable for any damages 27*86d7f5d3SJohn Marino arising from the use of this software. 28*86d7f5d3SJohn Marino 29*86d7f5d3SJohn Marino Permission is granted to anyone to use this software for any purpose, 30*86d7f5d3SJohn Marino including commercial applications, and to alter it and redistribute it 31*86d7f5d3SJohn Marino freely, subject to the following restrictions: 32*86d7f5d3SJohn Marino 33*86d7f5d3SJohn Marino 1. The origin of this software must not be misrepresented; you must not 34*86d7f5d3SJohn Marino claim that you wrote the original software. If you use this software 35*86d7f5d3SJohn Marino in a product, an acknowledgment in the product documentation would be 36*86d7f5d3SJohn Marino appreciated but is not required. 37*86d7f5d3SJohn Marino 2. Altered source versions must be plainly marked as such, and must not be 38*86d7f5d3SJohn Marino misrepresented as being the original software. 39*86d7f5d3SJohn Marino 3. This notice may not be removed or altered from any source distribution. 40*86d7f5d3SJohn Marino 41*86d7f5d3SJohn Marino Jean-loup Gailly Mark Adler 42*86d7f5d3SJohn Marino gzip@prep.ai.mit.edu madler@alumni.caltech.edu 43*86d7f5d3SJohn Marino 44*86d7f5d3SJohn Marino 45*86d7f5d3SJohn Marino The data format used by the zlib library is described by RFCs (Request for 46*86d7f5d3SJohn Marino Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt 47*86d7f5d3SJohn Marino (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 48*86d7f5d3SJohn Marino */ 49*86d7f5d3SJohn Marino 50*86d7f5d3SJohn Marino #ifndef _NET_ZLIB_H_ 51*86d7f5d3SJohn Marino #define _NET_ZLIB_H_ 52*86d7f5d3SJohn Marino 53*86d7f5d3SJohn Marino #ifdef __cplusplus 54*86d7f5d3SJohn Marino extern "C" { 55*86d7f5d3SJohn Marino #endif 56*86d7f5d3SJohn Marino 57*86d7f5d3SJohn Marino 58*86d7f5d3SJohn Marino /* +++ zconf.h */ 59*86d7f5d3SJohn Marino /* zconf.h -- configuration of the zlib compression library 60*86d7f5d3SJohn Marino * Copyright (C) 1995-1996 Jean-loup Gailly. 61*86d7f5d3SJohn Marino * For conditions of distribution and use, see copyright notice in zlib.h 62*86d7f5d3SJohn Marino */ 63*86d7f5d3SJohn Marino 64*86d7f5d3SJohn Marino /* From: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */ 65*86d7f5d3SJohn Marino 66*86d7f5d3SJohn Marino #ifndef _ZCONF_H 67*86d7f5d3SJohn Marino #define _ZCONF_H 68*86d7f5d3SJohn Marino 69*86d7f5d3SJohn Marino /* 70*86d7f5d3SJohn Marino * If you *really* need a unique prefix for all types and library functions, 71*86d7f5d3SJohn Marino * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 72*86d7f5d3SJohn Marino */ 73*86d7f5d3SJohn Marino #ifdef Z_PREFIX 74*86d7f5d3SJohn Marino # define deflateInit_ z_deflateInit_ 75*86d7f5d3SJohn Marino # define deflate z_deflate 76*86d7f5d3SJohn Marino # define deflateEnd z_deflateEnd 77*86d7f5d3SJohn Marino # define inflateInit_ z_inflateInit_ 78*86d7f5d3SJohn Marino # define inflate z_inflate 79*86d7f5d3SJohn Marino # define inflateEnd z_inflateEnd 80*86d7f5d3SJohn Marino # define deflateInit2_ z_deflateInit2_ 81*86d7f5d3SJohn Marino # define deflateSetDictionary z_deflateSetDictionary 82*86d7f5d3SJohn Marino # define deflateCopy z_deflateCopy 83*86d7f5d3SJohn Marino # define deflateReset z_deflateReset 84*86d7f5d3SJohn Marino # define deflateParams z_deflateParams 85*86d7f5d3SJohn Marino # define inflateInit2_ z_inflateInit2_ 86*86d7f5d3SJohn Marino # define inflateSetDictionary z_inflateSetDictionary 87*86d7f5d3SJohn Marino # define inflateSync z_inflateSync 88*86d7f5d3SJohn Marino # define inflateReset z_inflateReset 89*86d7f5d3SJohn Marino # define compress z_compress 90*86d7f5d3SJohn Marino # define uncompress z_uncompress 91*86d7f5d3SJohn Marino # define adler32 z_adler32 92*86d7f5d3SJohn Marino #if 0 93*86d7f5d3SJohn Marino # define crc32 z_crc32 94*86d7f5d3SJohn Marino # define get_crc_table z_get_crc_table 95*86d7f5d3SJohn Marino #endif 96*86d7f5d3SJohn Marino 97*86d7f5d3SJohn Marino # define Byte z_Byte 98*86d7f5d3SJohn Marino # define uInt z_uInt 99*86d7f5d3SJohn Marino # define uLong z_uLong 100*86d7f5d3SJohn Marino # define Bytef z_Bytef 101*86d7f5d3SJohn Marino # define charf z_charf 102*86d7f5d3SJohn Marino # define intf z_intf 103*86d7f5d3SJohn Marino # define uIntf z_uIntf 104*86d7f5d3SJohn Marino # define uLongf z_uLongf 105*86d7f5d3SJohn Marino # define voidpf z_voidpf 106*86d7f5d3SJohn Marino # define voidp z_voidp 107*86d7f5d3SJohn Marino #endif 108*86d7f5d3SJohn Marino 109*86d7f5d3SJohn Marino #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) 110*86d7f5d3SJohn Marino # define WIN32 111*86d7f5d3SJohn Marino #endif 112*86d7f5d3SJohn Marino #if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) 113*86d7f5d3SJohn Marino # ifndef __32BIT__ 114*86d7f5d3SJohn Marino # define __32BIT__ 115*86d7f5d3SJohn Marino # endif 116*86d7f5d3SJohn Marino #endif 117*86d7f5d3SJohn Marino #if defined(__MSDOS__) && !defined(MSDOS) 118*86d7f5d3SJohn Marino # define MSDOS 119*86d7f5d3SJohn Marino #endif 120*86d7f5d3SJohn Marino 121*86d7f5d3SJohn Marino /* 122*86d7f5d3SJohn Marino * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 123*86d7f5d3SJohn Marino * than 64k bytes at a time (needed on systems with 16-bit int). 124*86d7f5d3SJohn Marino */ 125*86d7f5d3SJohn Marino #if defined(MSDOS) && !defined(__32BIT__) 126*86d7f5d3SJohn Marino # define MAXSEG_64K 127*86d7f5d3SJohn Marino #endif 128*86d7f5d3SJohn Marino #ifdef MSDOS 129*86d7f5d3SJohn Marino # define UNALIGNED_OK 130*86d7f5d3SJohn Marino #endif 131*86d7f5d3SJohn Marino 132*86d7f5d3SJohn Marino #if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) 133*86d7f5d3SJohn Marino # define STDC 134*86d7f5d3SJohn Marino #endif 135*86d7f5d3SJohn Marino #if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC) 136*86d7f5d3SJohn Marino # define STDC 137*86d7f5d3SJohn Marino #endif 138*86d7f5d3SJohn Marino 139*86d7f5d3SJohn Marino #ifndef STDC 140*86d7f5d3SJohn Marino # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 141*86d7f5d3SJohn Marino # define const 142*86d7f5d3SJohn Marino # endif 143*86d7f5d3SJohn Marino #endif 144*86d7f5d3SJohn Marino 145*86d7f5d3SJohn Marino /* Some Mac compilers merge all .h files incorrectly: */ 146*86d7f5d3SJohn Marino #if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) 147*86d7f5d3SJohn Marino # define NO_DUMMY_DECL 148*86d7f5d3SJohn Marino #endif 149*86d7f5d3SJohn Marino 150*86d7f5d3SJohn Marino /* Maximum value for memLevel in deflateInit2 */ 151*86d7f5d3SJohn Marino #ifndef MAX_MEM_LEVEL 152*86d7f5d3SJohn Marino # ifdef MAXSEG_64K 153*86d7f5d3SJohn Marino # define MAX_MEM_LEVEL 8 154*86d7f5d3SJohn Marino # else 155*86d7f5d3SJohn Marino # define MAX_MEM_LEVEL 9 156*86d7f5d3SJohn Marino # endif 157*86d7f5d3SJohn Marino #endif 158*86d7f5d3SJohn Marino 159*86d7f5d3SJohn Marino /* Maximum value for windowBits in deflateInit2 and inflateInit2 */ 160*86d7f5d3SJohn Marino #ifndef MAX_WBITS 161*86d7f5d3SJohn Marino # define MAX_WBITS 15 /* 32K LZ77 window */ 162*86d7f5d3SJohn Marino #endif 163*86d7f5d3SJohn Marino 164*86d7f5d3SJohn Marino /* The memory requirements for deflate are (in bytes): 165*86d7f5d3SJohn Marino 1 << (windowBits+2) + 1 << (memLevel+9) 166*86d7f5d3SJohn Marino that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 167*86d7f5d3SJohn Marino plus a few kilobytes for small objects. For example, if you want to reduce 168*86d7f5d3SJohn Marino the default memory requirements from 256K to 128K, compile with 169*86d7f5d3SJohn Marino make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 170*86d7f5d3SJohn Marino Of course this will generally degrade compression (there's no free lunch). 171*86d7f5d3SJohn Marino 172*86d7f5d3SJohn Marino The memory requirements for inflate are (in bytes) 1 << windowBits 173*86d7f5d3SJohn Marino that is, 32K for windowBits=15 (default value) plus a few kilobytes 174*86d7f5d3SJohn Marino for small objects. 175*86d7f5d3SJohn Marino */ 176*86d7f5d3SJohn Marino 177*86d7f5d3SJohn Marino /* Type declarations */ 178*86d7f5d3SJohn Marino 179*86d7f5d3SJohn Marino #ifndef OF /* function prototypes */ 180*86d7f5d3SJohn Marino # ifdef STDC 181*86d7f5d3SJohn Marino # define OF(args) args 182*86d7f5d3SJohn Marino # else 183*86d7f5d3SJohn Marino # define OF(args) () 184*86d7f5d3SJohn Marino # endif 185*86d7f5d3SJohn Marino #endif 186*86d7f5d3SJohn Marino 187*86d7f5d3SJohn Marino /* The following definitions for FAR are needed only for MSDOS mixed 188*86d7f5d3SJohn Marino * model programming (small or medium model with some far allocations). 189*86d7f5d3SJohn Marino * This was tested only with MSC; for other MSDOS compilers you may have 190*86d7f5d3SJohn Marino * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 191*86d7f5d3SJohn Marino * just define FAR to be empty. 192*86d7f5d3SJohn Marino */ 193*86d7f5d3SJohn Marino #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) 194*86d7f5d3SJohn Marino /* MSC small or medium model */ 195*86d7f5d3SJohn Marino # define SMALL_MEDIUM 196*86d7f5d3SJohn Marino # ifdef _MSC_VER 197*86d7f5d3SJohn Marino # define FAR __far 198*86d7f5d3SJohn Marino # else 199*86d7f5d3SJohn Marino # define FAR far 200*86d7f5d3SJohn Marino # endif 201*86d7f5d3SJohn Marino #endif 202*86d7f5d3SJohn Marino #if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) 203*86d7f5d3SJohn Marino # ifndef __32BIT__ 204*86d7f5d3SJohn Marino # define SMALL_MEDIUM 205*86d7f5d3SJohn Marino # define FAR __far 206*86d7f5d3SJohn Marino # endif 207*86d7f5d3SJohn Marino #endif 208*86d7f5d3SJohn Marino #ifndef FAR 209*86d7f5d3SJohn Marino # define FAR 210*86d7f5d3SJohn Marino #endif 211*86d7f5d3SJohn Marino 212*86d7f5d3SJohn Marino typedef unsigned char Byte; /* 8 bits */ 213*86d7f5d3SJohn Marino typedef unsigned int uInt; /* 16 bits or more */ 214*86d7f5d3SJohn Marino typedef unsigned long uLong; /* 32 bits or more */ 215*86d7f5d3SJohn Marino 216*86d7f5d3SJohn Marino #if defined(__BORLANDC__) && defined(SMALL_MEDIUM) 217*86d7f5d3SJohn Marino /* Borland C/C++ ignores FAR inside typedef */ 218*86d7f5d3SJohn Marino # define Bytef Byte FAR 219*86d7f5d3SJohn Marino #else 220*86d7f5d3SJohn Marino typedef Byte FAR Bytef; 221*86d7f5d3SJohn Marino #endif 222*86d7f5d3SJohn Marino typedef char FAR charf; 223*86d7f5d3SJohn Marino typedef int FAR intf; 224*86d7f5d3SJohn Marino typedef uInt FAR uIntf; 225*86d7f5d3SJohn Marino typedef uLong FAR uLongf; 226*86d7f5d3SJohn Marino 227*86d7f5d3SJohn Marino #ifdef STDC 228*86d7f5d3SJohn Marino typedef void FAR *voidpf; 229*86d7f5d3SJohn Marino typedef void *voidp; 230*86d7f5d3SJohn Marino #else 231*86d7f5d3SJohn Marino typedef Byte FAR *voidpf; 232*86d7f5d3SJohn Marino typedef Byte *voidp; 233*86d7f5d3SJohn Marino #endif 234*86d7f5d3SJohn Marino 235*86d7f5d3SJohn Marino 236*86d7f5d3SJohn Marino /* Compile with -DZLIB_DLL for Windows DLL support */ 237*86d7f5d3SJohn Marino #if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL) 238*86d7f5d3SJohn Marino # include <windows.h> 239*86d7f5d3SJohn Marino # define EXPORT WINAPI 240*86d7f5d3SJohn Marino #else 241*86d7f5d3SJohn Marino # define EXPORT 242*86d7f5d3SJohn Marino #endif 243*86d7f5d3SJohn Marino 244*86d7f5d3SJohn Marino #endif /* _ZCONF_H */ 245*86d7f5d3SJohn Marino /* --- zconf.h */ 246*86d7f5d3SJohn Marino 247*86d7f5d3SJohn Marino #define ZLIB_VERSION "1.0.4P" 248*86d7f5d3SJohn Marino 249*86d7f5d3SJohn Marino /* 250*86d7f5d3SJohn Marino The 'zlib' compression library provides in-memory compression and 251*86d7f5d3SJohn Marino decompression functions, including integrity checks of the uncompressed 252*86d7f5d3SJohn Marino data. This version of the library supports only one compression method 253*86d7f5d3SJohn Marino (deflation) but other algorithms may be added later and will have the same 254*86d7f5d3SJohn Marino stream interface. 255*86d7f5d3SJohn Marino 256*86d7f5d3SJohn Marino For compression the application must provide the output buffer and 257*86d7f5d3SJohn Marino may optionally provide the input buffer for optimization. For decompression, 258*86d7f5d3SJohn Marino the application must provide the input buffer and may optionally provide 259*86d7f5d3SJohn Marino the output buffer for optimization. 260*86d7f5d3SJohn Marino 261*86d7f5d3SJohn Marino Compression can be done in a single step if the buffers are large 262*86d7f5d3SJohn Marino enough (for example if an input file is mmap'ed), or can be done by 263*86d7f5d3SJohn Marino repeated calls of the compression function. In the latter case, the 264*86d7f5d3SJohn Marino application must provide more input and/or consume the output 265*86d7f5d3SJohn Marino (providing more output space) before each call. 266*86d7f5d3SJohn Marino 267*86d7f5d3SJohn Marino The library does not install any signal handler. It is recommended to 268*86d7f5d3SJohn Marino add at least a handler for SIGSEGV when decompressing; the library checks 269*86d7f5d3SJohn Marino the consistency of the input data whenever possible but may go nuts 270*86d7f5d3SJohn Marino for some forms of corrupted input. 271*86d7f5d3SJohn Marino */ 272*86d7f5d3SJohn Marino 273*86d7f5d3SJohn Marino typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 274*86d7f5d3SJohn Marino typedef void (*free_func) OF((voidpf opaque, voidpf address)); 275*86d7f5d3SJohn Marino 276*86d7f5d3SJohn Marino struct internal_state; 277*86d7f5d3SJohn Marino 278*86d7f5d3SJohn Marino typedef struct z_stream_s { 279*86d7f5d3SJohn Marino Bytef *next_in; /* next input byte */ 280*86d7f5d3SJohn Marino uInt avail_in; /* number of bytes available at next_in */ 281*86d7f5d3SJohn Marino uLong total_in; /* total nb of input bytes read so far */ 282*86d7f5d3SJohn Marino 283*86d7f5d3SJohn Marino Bytef *next_out; /* next output byte should be put there */ 284*86d7f5d3SJohn Marino uInt avail_out; /* remaining free space at next_out */ 285*86d7f5d3SJohn Marino uLong total_out; /* total nb of bytes output so far */ 286*86d7f5d3SJohn Marino 287*86d7f5d3SJohn Marino const char *msg; /* last error message, NULL if no error */ 288*86d7f5d3SJohn Marino struct internal_state FAR *state; /* not visible by applications */ 289*86d7f5d3SJohn Marino 290*86d7f5d3SJohn Marino alloc_func zalloc; /* used to allocate the internal state */ 291*86d7f5d3SJohn Marino free_func zfree; /* used to free the internal state */ 292*86d7f5d3SJohn Marino voidpf opaque; /* private data object passed to zalloc and zfree */ 293*86d7f5d3SJohn Marino 294*86d7f5d3SJohn Marino int data_type; /* best guess about the data type: ascii or binary */ 295*86d7f5d3SJohn Marino uLong adler; /* adler32 value of the uncompressed data */ 296*86d7f5d3SJohn Marino uLong reserved; /* reserved for future use */ 297*86d7f5d3SJohn Marino } z_stream; 298*86d7f5d3SJohn Marino 299*86d7f5d3SJohn Marino typedef z_stream FAR *z_streamp; 300*86d7f5d3SJohn Marino 301*86d7f5d3SJohn Marino /* 302*86d7f5d3SJohn Marino The application must update next_in and avail_in when avail_in has 303*86d7f5d3SJohn Marino dropped to zero. It must update next_out and avail_out when avail_out 304*86d7f5d3SJohn Marino has dropped to zero. The application must initialize zalloc, zfree and 305*86d7f5d3SJohn Marino opaque before calling the init function. All other fields are set by the 306*86d7f5d3SJohn Marino compression library and must not be updated by the application. 307*86d7f5d3SJohn Marino 308*86d7f5d3SJohn Marino The opaque value provided by the application will be passed as the first 309*86d7f5d3SJohn Marino parameter for calls of zalloc and zfree. This can be useful for custom 310*86d7f5d3SJohn Marino memory management. The compression library attaches no meaning to the 311*86d7f5d3SJohn Marino opaque value. 312*86d7f5d3SJohn Marino 313*86d7f5d3SJohn Marino zalloc must return Z_NULL if there is not enough memory for the object. 314*86d7f5d3SJohn Marino On 16-bit systems, the functions zalloc and zfree must be able to allocate 315*86d7f5d3SJohn Marino exactly 65536 bytes, but will not be required to allocate more than this 316*86d7f5d3SJohn Marino if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 317*86d7f5d3SJohn Marino pointers returned by zalloc for objects of exactly 65536 bytes *must* 318*86d7f5d3SJohn Marino have their offset normalized to zero. The default allocation function 319*86d7f5d3SJohn Marino provided by this library ensures this (see zutil.c). To reduce memory 320*86d7f5d3SJohn Marino requirements and avoid any allocation of 64K objects, at the expense of 321*86d7f5d3SJohn Marino compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 322*86d7f5d3SJohn Marino 323*86d7f5d3SJohn Marino The fields total_in and total_out can be used for statistics or 324*86d7f5d3SJohn Marino progress reports. After compression, total_in holds the total size of 325*86d7f5d3SJohn Marino the uncompressed data and may be saved for use in the decompressor 326*86d7f5d3SJohn Marino (particularly if the decompressor wants to decompress everything in 327*86d7f5d3SJohn Marino a single step). 328*86d7f5d3SJohn Marino */ 329*86d7f5d3SJohn Marino 330*86d7f5d3SJohn Marino /* constants */ 331*86d7f5d3SJohn Marino 332*86d7f5d3SJohn Marino #define Z_NO_FLUSH 0 333*86d7f5d3SJohn Marino #define Z_PARTIAL_FLUSH 1 334*86d7f5d3SJohn Marino #define Z_PACKET_FLUSH 2 335*86d7f5d3SJohn Marino #define Z_SYNC_FLUSH 3 336*86d7f5d3SJohn Marino #define Z_FULL_FLUSH 4 337*86d7f5d3SJohn Marino #define Z_FINISH 5 338*86d7f5d3SJohn Marino /* Allowed flush values; see deflate() below for details */ 339*86d7f5d3SJohn Marino 340*86d7f5d3SJohn Marino #define Z_OK 0 341*86d7f5d3SJohn Marino #define Z_STREAM_END 1 342*86d7f5d3SJohn Marino #define Z_NEED_DICT 2 343*86d7f5d3SJohn Marino #define Z_ERRNO (-1) 344*86d7f5d3SJohn Marino #define Z_STREAM_ERROR (-2) 345*86d7f5d3SJohn Marino #define Z_DATA_ERROR (-3) 346*86d7f5d3SJohn Marino #define Z_MEM_ERROR (-4) 347*86d7f5d3SJohn Marino #define Z_BUF_ERROR (-5) 348*86d7f5d3SJohn Marino #define Z_VERSION_ERROR (-6) 349*86d7f5d3SJohn Marino /* Return codes for the compression/decompression functions. Negative 350*86d7f5d3SJohn Marino * values are errors, positive values are used for special but normal events. 351*86d7f5d3SJohn Marino */ 352*86d7f5d3SJohn Marino 353*86d7f5d3SJohn Marino #define Z_NO_COMPRESSION 0 354*86d7f5d3SJohn Marino #define Z_BEST_SPEED 1 355*86d7f5d3SJohn Marino #define Z_BEST_COMPRESSION 9 356*86d7f5d3SJohn Marino #define Z_DEFAULT_COMPRESSION (-1) 357*86d7f5d3SJohn Marino /* compression levels */ 358*86d7f5d3SJohn Marino 359*86d7f5d3SJohn Marino #define Z_FILTERED 1 360*86d7f5d3SJohn Marino #define Z_HUFFMAN_ONLY 2 361*86d7f5d3SJohn Marino #define Z_DEFAULT_STRATEGY 0 362*86d7f5d3SJohn Marino /* compression strategy; see deflateInit2() below for details */ 363*86d7f5d3SJohn Marino 364*86d7f5d3SJohn Marino #define Z_BINARY 0 365*86d7f5d3SJohn Marino #define Z_ASCII 1 366*86d7f5d3SJohn Marino #define Z_UNKNOWN 2 367*86d7f5d3SJohn Marino /* Possible values of the data_type field */ 368*86d7f5d3SJohn Marino 369*86d7f5d3SJohn Marino #define Z_DEFLATED 8 370*86d7f5d3SJohn Marino /* The deflate compression method (the only one supported in this version) */ 371*86d7f5d3SJohn Marino 372*86d7f5d3SJohn Marino #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 373*86d7f5d3SJohn Marino 374*86d7f5d3SJohn Marino #define zlib_version zlibVersion() 375*86d7f5d3SJohn Marino /* for compatibility with versions < 1.0.2 */ 376*86d7f5d3SJohn Marino 377*86d7f5d3SJohn Marino /* basic functions */ 378*86d7f5d3SJohn Marino 379*86d7f5d3SJohn Marino extern const char * EXPORT zlibVersion OF((void)); 380*86d7f5d3SJohn Marino /* The application can compare zlibVersion and ZLIB_VERSION for consistency. 381*86d7f5d3SJohn Marino If the first character differs, the library code actually used is 382*86d7f5d3SJohn Marino not compatible with the zlib.h header file used by the application. 383*86d7f5d3SJohn Marino This check is automatically made by deflateInit and inflateInit. 384*86d7f5d3SJohn Marino */ 385*86d7f5d3SJohn Marino 386*86d7f5d3SJohn Marino /* 387*86d7f5d3SJohn Marino extern int EXPORT deflateInit OF((z_streamp strm, int level)); 388*86d7f5d3SJohn Marino 389*86d7f5d3SJohn Marino Initializes the internal stream state for compression. The fields 390*86d7f5d3SJohn Marino zalloc, zfree and opaque must be initialized before by the caller. 391*86d7f5d3SJohn Marino If zalloc and zfree are set to Z_NULL, deflateInit updates them to 392*86d7f5d3SJohn Marino use default allocation functions. 393*86d7f5d3SJohn Marino 394*86d7f5d3SJohn Marino The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 395*86d7f5d3SJohn Marino 1 gives best speed, 9 gives best compression, 0 gives no compression at 396*86d7f5d3SJohn Marino all (the input data is simply copied a block at a time). 397*86d7f5d3SJohn Marino Z_DEFAULT_COMPRESSION requests a default compromise between speed and 398*86d7f5d3SJohn Marino compression (currently equivalent to level 6). 399*86d7f5d3SJohn Marino 400*86d7f5d3SJohn Marino deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 401*86d7f5d3SJohn Marino enough memory, Z_STREAM_ERROR if level is not a valid compression level, 402*86d7f5d3SJohn Marino Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 403*86d7f5d3SJohn Marino with the version assumed by the caller (ZLIB_VERSION). 404*86d7f5d3SJohn Marino msg is set to null if there is no error message. deflateInit does not 405*86d7f5d3SJohn Marino perform any compression: this will be done by deflate(). 406*86d7f5d3SJohn Marino */ 407*86d7f5d3SJohn Marino 408*86d7f5d3SJohn Marino 409*86d7f5d3SJohn Marino extern int EXPORT deflate OF((z_streamp strm, int flush)); 410*86d7f5d3SJohn Marino /* 411*86d7f5d3SJohn Marino Performs one or both of the following actions: 412*86d7f5d3SJohn Marino 413*86d7f5d3SJohn Marino - Compress more input starting at next_in and update next_in and avail_in 414*86d7f5d3SJohn Marino accordingly. If not all input can be processed (because there is not 415*86d7f5d3SJohn Marino enough room in the output buffer), next_in and avail_in are updated and 416*86d7f5d3SJohn Marino processing will resume at this point for the next call of deflate(). 417*86d7f5d3SJohn Marino 418*86d7f5d3SJohn Marino - Provide more output starting at next_out and update next_out and avail_out 419*86d7f5d3SJohn Marino accordingly. This action is forced if the parameter flush is non zero. 420*86d7f5d3SJohn Marino Forcing flush frequently degrades the compression ratio, so this parameter 421*86d7f5d3SJohn Marino should be set only when necessary (in interactive applications). 422*86d7f5d3SJohn Marino Some output may be provided even if flush is not set. 423*86d7f5d3SJohn Marino 424*86d7f5d3SJohn Marino Before the call of deflate(), the application should ensure that at least 425*86d7f5d3SJohn Marino one of the actions is possible, by providing more input and/or consuming 426*86d7f5d3SJohn Marino more output, and updating avail_in or avail_out accordingly; avail_out 427*86d7f5d3SJohn Marino should never be zero before the call. The application can consume the 428*86d7f5d3SJohn Marino compressed output when it wants, for example when the output buffer is full 429*86d7f5d3SJohn Marino (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 430*86d7f5d3SJohn Marino and with zero avail_out, it must be called again after making room in the 431*86d7f5d3SJohn Marino output buffer because there might be more output pending. 432*86d7f5d3SJohn Marino 433*86d7f5d3SJohn Marino If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression 434*86d7f5d3SJohn Marino block is terminated and flushed to the output buffer so that the 435*86d7f5d3SJohn Marino decompressor can get all input data available so far. For method 9, a future 436*86d7f5d3SJohn Marino variant on method 8, the current block will be flushed but not terminated. 437*86d7f5d3SJohn Marino Z_SYNC_FLUSH has the same effect as partial flush except that the compressed 438*86d7f5d3SJohn Marino output is byte aligned (the compressor can clear its internal bit buffer) 439*86d7f5d3SJohn Marino and the current block is always terminated; this can be useful if the 440*86d7f5d3SJohn Marino compressor has to be restarted from scratch after an interruption (in which 441*86d7f5d3SJohn Marino case the internal state of the compressor may be lost). 442*86d7f5d3SJohn Marino If flush is set to Z_FULL_FLUSH, the compression block is terminated, a 443*86d7f5d3SJohn Marino special marker is output and the compression dictionary is discarded; this 444*86d7f5d3SJohn Marino is useful to allow the decompressor to synchronize if one compressed block 445*86d7f5d3SJohn Marino has been damaged (see inflateSync below). Flushing degrades compression and 446*86d7f5d3SJohn Marino so should be used only when necessary. Using Z_FULL_FLUSH too often can 447*86d7f5d3SJohn Marino seriously degrade the compression. If deflate returns with avail_out == 0, 448*86d7f5d3SJohn Marino this function must be called again with the same value of the flush 449*86d7f5d3SJohn Marino parameter and more output space (updated avail_out), until the flush is 450*86d7f5d3SJohn Marino complete (deflate returns with non-zero avail_out). 451*86d7f5d3SJohn Marino 452*86d7f5d3SJohn Marino If the parameter flush is set to Z_PACKET_FLUSH, the compression 453*86d7f5d3SJohn Marino block is terminated, and a zero-length stored block is output, 454*86d7f5d3SJohn Marino omitting the length bytes (the effect of this is that the 3-bit type 455*86d7f5d3SJohn Marino code 000 for a stored block is output, and the output is then 456*86d7f5d3SJohn Marino byte-aligned). This is designed for use at the end of a PPP packet. 457*86d7f5d3SJohn Marino 458*86d7f5d3SJohn Marino If the parameter flush is set to Z_FINISH, pending input is processed, 459*86d7f5d3SJohn Marino pending output is flushed and deflate returns with Z_STREAM_END if there 460*86d7f5d3SJohn Marino was enough output space; if deflate returns with Z_OK, this function must be 461*86d7f5d3SJohn Marino called again with Z_FINISH and more output space (updated avail_out) but no 462*86d7f5d3SJohn Marino more input data, until it returns with Z_STREAM_END or an error. After 463*86d7f5d3SJohn Marino deflate has returned Z_STREAM_END, the only possible operations on the 464*86d7f5d3SJohn Marino stream are deflateReset or deflateEnd. 465*86d7f5d3SJohn Marino 466*86d7f5d3SJohn Marino Z_FINISH can be used immediately after deflateInit if all the compression 467*86d7f5d3SJohn Marino is to be done in a single step. In this case, avail_out must be at least 468*86d7f5d3SJohn Marino 0.1% larger than avail_in plus 12 bytes. If deflate does not return 469*86d7f5d3SJohn Marino Z_STREAM_END, then it must be called again as described above. 470*86d7f5d3SJohn Marino 471*86d7f5d3SJohn Marino deflate() may update data_type if it can make a good guess about 472*86d7f5d3SJohn Marino the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered 473*86d7f5d3SJohn Marino binary. This field is only for information purposes and does not affect 474*86d7f5d3SJohn Marino the compression algorithm in any manner. 475*86d7f5d3SJohn Marino 476*86d7f5d3SJohn Marino deflate() returns Z_OK if some progress has been made (more input 477*86d7f5d3SJohn Marino processed or more output produced), Z_STREAM_END if all input has been 478*86d7f5d3SJohn Marino consumed and all output has been produced (only when flush is set to 479*86d7f5d3SJohn Marino Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 480*86d7f5d3SJohn Marino if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible. 481*86d7f5d3SJohn Marino */ 482*86d7f5d3SJohn Marino 483*86d7f5d3SJohn Marino 484*86d7f5d3SJohn Marino extern int EXPORT deflateEnd OF((z_streamp strm)); 485*86d7f5d3SJohn Marino /* 486*86d7f5d3SJohn Marino All dynamically allocated data structures for this stream are freed. 487*86d7f5d3SJohn Marino This function discards any unprocessed input and does not flush any 488*86d7f5d3SJohn Marino pending output. 489*86d7f5d3SJohn Marino 490*86d7f5d3SJohn Marino deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 491*86d7f5d3SJohn Marino stream state was inconsistent, Z_DATA_ERROR if the stream was freed 492*86d7f5d3SJohn Marino prematurely (some input or output was discarded). In the error case, 493*86d7f5d3SJohn Marino msg may be set but then points to a static string (which must not be 494*86d7f5d3SJohn Marino deallocated). 495*86d7f5d3SJohn Marino */ 496*86d7f5d3SJohn Marino 497*86d7f5d3SJohn Marino 498*86d7f5d3SJohn Marino /* 499*86d7f5d3SJohn Marino extern int EXPORT inflateInit OF((z_streamp strm)); 500*86d7f5d3SJohn Marino 501*86d7f5d3SJohn Marino Initializes the internal stream state for decompression. The fields 502*86d7f5d3SJohn Marino zalloc, zfree and opaque must be initialized before by the caller. If 503*86d7f5d3SJohn Marino zalloc and zfree are set to Z_NULL, inflateInit updates them to use default 504*86d7f5d3SJohn Marino allocation functions. 505*86d7f5d3SJohn Marino 506*86d7f5d3SJohn Marino inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 507*86d7f5d3SJohn Marino enough memory, Z_VERSION_ERROR if the zlib library version is incompatible 508*86d7f5d3SJohn Marino with the version assumed by the caller. msg is set to null if there is no 509*86d7f5d3SJohn Marino error message. inflateInit does not perform any decompression: this will be 510*86d7f5d3SJohn Marino done by inflate(). 511*86d7f5d3SJohn Marino */ 512*86d7f5d3SJohn Marino 513*86d7f5d3SJohn Marino #if (defined(__DragonFly__) || defined(__FreeBSD__)) && defined(_KERNEL) 514*86d7f5d3SJohn Marino #define inflate inflate_ppp /* FreeBSD already has an inflate :-( */ 515*86d7f5d3SJohn Marino #endif 516*86d7f5d3SJohn Marino 517*86d7f5d3SJohn Marino extern int EXPORT inflate OF((z_streamp strm, int flush)); 518*86d7f5d3SJohn Marino /* 519*86d7f5d3SJohn Marino Performs one or both of the following actions: 520*86d7f5d3SJohn Marino 521*86d7f5d3SJohn Marino - Decompress more input starting at next_in and update next_in and avail_in 522*86d7f5d3SJohn Marino accordingly. If not all input can be processed (because there is not 523*86d7f5d3SJohn Marino enough room in the output buffer), next_in is updated and processing 524*86d7f5d3SJohn Marino will resume at this point for the next call of inflate(). 525*86d7f5d3SJohn Marino 526*86d7f5d3SJohn Marino - Provide more output starting at next_out and update next_out and avail_out 527*86d7f5d3SJohn Marino accordingly. inflate() provides as much output as possible, until there 528*86d7f5d3SJohn Marino is no more input data or no more space in the output buffer (see below 529*86d7f5d3SJohn Marino about the flush parameter). 530*86d7f5d3SJohn Marino 531*86d7f5d3SJohn Marino Before the call of inflate(), the application should ensure that at least 532*86d7f5d3SJohn Marino one of the actions is possible, by providing more input and/or consuming 533*86d7f5d3SJohn Marino more output, and updating the next_* and avail_* values accordingly. 534*86d7f5d3SJohn Marino The application can consume the uncompressed output when it wants, for 535*86d7f5d3SJohn Marino example when the output buffer is full (avail_out == 0), or after each 536*86d7f5d3SJohn Marino call of inflate(). If inflate returns Z_OK and with zero avail_out, it 537*86d7f5d3SJohn Marino must be called again after making room in the output buffer because there 538*86d7f5d3SJohn Marino might be more output pending. 539*86d7f5d3SJohn Marino 540*86d7f5d3SJohn Marino If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH, 541*86d7f5d3SJohn Marino inflate flushes as much output as possible to the output buffer. The 542*86d7f5d3SJohn Marino flushing behavior of inflate is not specified for values of the flush 543*86d7f5d3SJohn Marino parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the 544*86d7f5d3SJohn Marino current implementation actually flushes as much output as possible 545*86d7f5d3SJohn Marino anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data 546*86d7f5d3SJohn Marino has been consumed, it is expecting to see the length field of a stored 547*86d7f5d3SJohn Marino block; if not, it returns Z_DATA_ERROR. 548*86d7f5d3SJohn Marino 549*86d7f5d3SJohn Marino inflate() should normally be called until it returns Z_STREAM_END or an 550*86d7f5d3SJohn Marino error. However if all decompression is to be performed in a single step 551*86d7f5d3SJohn Marino (a single call of inflate), the parameter flush should be set to 552*86d7f5d3SJohn Marino Z_FINISH. In this case all pending input is processed and all pending 553*86d7f5d3SJohn Marino output is flushed; avail_out must be large enough to hold all the 554*86d7f5d3SJohn Marino uncompressed data. (The size of the uncompressed data may have been saved 555*86d7f5d3SJohn Marino by the compressor for this purpose.) The next operation on this stream must 556*86d7f5d3SJohn Marino be inflateEnd to deallocate the decompression state. The use of Z_FINISH 557*86d7f5d3SJohn Marino is never required, but can be used to inform inflate that a faster routine 558*86d7f5d3SJohn Marino may be used for the single inflate() call. 559*86d7f5d3SJohn Marino 560*86d7f5d3SJohn Marino inflate() returns Z_OK if some progress has been made (more input 561*86d7f5d3SJohn Marino processed or more output produced), Z_STREAM_END if the end of the 562*86d7f5d3SJohn Marino compressed data has been reached and all uncompressed output has been 563*86d7f5d3SJohn Marino produced, Z_NEED_DICT if a preset dictionary is needed at this point (see 564*86d7f5d3SJohn Marino inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted, 565*86d7f5d3SJohn Marino Z_STREAM_ERROR if the stream structure was inconsistent (for example if 566*86d7f5d3SJohn Marino next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, 567*86d7f5d3SJohn Marino Z_BUF_ERROR if no progress is possible or if there was not enough room in 568*86d7f5d3SJohn Marino the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the 569*86d7f5d3SJohn Marino application may then call inflateSync to look for a good compression block. 570*86d7f5d3SJohn Marino In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the 571*86d7f5d3SJohn Marino dictionary chosen by the compressor. 572*86d7f5d3SJohn Marino */ 573*86d7f5d3SJohn Marino 574*86d7f5d3SJohn Marino 575*86d7f5d3SJohn Marino extern int EXPORT inflateEnd OF((z_streamp strm)); 576*86d7f5d3SJohn Marino /* 577*86d7f5d3SJohn Marino All dynamically allocated data structures for this stream are freed. 578*86d7f5d3SJohn Marino This function discards any unprocessed input and does not flush any 579*86d7f5d3SJohn Marino pending output. 580*86d7f5d3SJohn Marino 581*86d7f5d3SJohn Marino inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 582*86d7f5d3SJohn Marino was inconsistent. In the error case, msg may be set but then points to a 583*86d7f5d3SJohn Marino static string (which must not be deallocated). 584*86d7f5d3SJohn Marino */ 585*86d7f5d3SJohn Marino 586*86d7f5d3SJohn Marino /* Advanced functions */ 587*86d7f5d3SJohn Marino 588*86d7f5d3SJohn Marino /* 589*86d7f5d3SJohn Marino The following functions are needed only in some special applications. 590*86d7f5d3SJohn Marino */ 591*86d7f5d3SJohn Marino 592*86d7f5d3SJohn Marino /* 593*86d7f5d3SJohn Marino extern int EXPORT deflateInit2 OF((z_streamp strm, 594*86d7f5d3SJohn Marino int level, 595*86d7f5d3SJohn Marino int method, 596*86d7f5d3SJohn Marino int windowBits, 597*86d7f5d3SJohn Marino int memLevel, 598*86d7f5d3SJohn Marino int strategy)); 599*86d7f5d3SJohn Marino 600*86d7f5d3SJohn Marino This is another version of deflateInit with more compression options. The 601*86d7f5d3SJohn Marino fields next_in, zalloc, zfree and opaque must be initialized before by 602*86d7f5d3SJohn Marino the caller. 603*86d7f5d3SJohn Marino 604*86d7f5d3SJohn Marino The method parameter is the compression method. It must be Z_DEFLATED in 605*86d7f5d3SJohn Marino this version of the library. (Method 9 will allow a 64K history buffer and 606*86d7f5d3SJohn Marino partial block flushes.) 607*86d7f5d3SJohn Marino 608*86d7f5d3SJohn Marino The windowBits parameter is the base two logarithm of the window size 609*86d7f5d3SJohn Marino (the size of the history buffer). It should be in the range 8..15 for this 610*86d7f5d3SJohn Marino version of the library (the value 16 will be allowed for method 9). Larger 611*86d7f5d3SJohn Marino values of this parameter result in better compression at the expense of 612*86d7f5d3SJohn Marino memory usage. The default value is 15 if deflateInit is used instead. 613*86d7f5d3SJohn Marino 614*86d7f5d3SJohn Marino The memLevel parameter specifies how much memory should be allocated 615*86d7f5d3SJohn Marino for the internal compression state. memLevel=1 uses minimum memory but 616*86d7f5d3SJohn Marino is slow and reduces compression ratio; memLevel=9 uses maximum memory 617*86d7f5d3SJohn Marino for optimal speed. The default value is 8. See zconf.h for total memory 618*86d7f5d3SJohn Marino usage as a function of windowBits and memLevel. 619*86d7f5d3SJohn Marino 620*86d7f5d3SJohn Marino The strategy parameter is used to tune the compression algorithm. Use the 621*86d7f5d3SJohn Marino value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 622*86d7f5d3SJohn Marino filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no 623*86d7f5d3SJohn Marino string match). Filtered data consists mostly of small values with a 624*86d7f5d3SJohn Marino somewhat random distribution. In this case, the compression algorithm is 625*86d7f5d3SJohn Marino tuned to compress them better. The effect of Z_FILTERED is to force more 626*86d7f5d3SJohn Marino Huffman coding and less string matching; it is somewhat intermediate 627*86d7f5d3SJohn Marino between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects 628*86d7f5d3SJohn Marino the compression ratio but not the correctness of the compressed output even 629*86d7f5d3SJohn Marino if it is not set appropriately. 630*86d7f5d3SJohn Marino 631*86d7f5d3SJohn Marino If next_in is not null, the library will use this buffer to hold also 632*86d7f5d3SJohn Marino some history information; the buffer must either hold the entire input 633*86d7f5d3SJohn Marino data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in 634*86d7f5d3SJohn Marino is null, the library will allocate its own history buffer (and leave next_in 635*86d7f5d3SJohn Marino null). next_out need not be provided here but must be provided by the 636*86d7f5d3SJohn Marino application for the next call of deflate(). 637*86d7f5d3SJohn Marino 638*86d7f5d3SJohn Marino If the history buffer is provided by the application, next_in must 639*86d7f5d3SJohn Marino must never be changed by the application since the compressor maintains 640*86d7f5d3SJohn Marino information inside this buffer from call to call; the application 641*86d7f5d3SJohn Marino must provide more input only by increasing avail_in. next_in is always 642*86d7f5d3SJohn Marino reset by the library in this case. 643*86d7f5d3SJohn Marino 644*86d7f5d3SJohn Marino deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 645*86d7f5d3SJohn Marino not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as 646*86d7f5d3SJohn Marino an invalid method). msg is set to null if there is no error message. 647*86d7f5d3SJohn Marino deflateInit2 does not perform any compression: this will be done by 648*86d7f5d3SJohn Marino deflate(). 649*86d7f5d3SJohn Marino */ 650*86d7f5d3SJohn Marino 651*86d7f5d3SJohn Marino extern int EXPORT deflateSetDictionary OF((z_streamp strm, 652*86d7f5d3SJohn Marino const Bytef *dictionary, 653*86d7f5d3SJohn Marino uInt dictLength)); 654*86d7f5d3SJohn Marino /* 655*86d7f5d3SJohn Marino Initializes the compression dictionary (history buffer) from the given 656*86d7f5d3SJohn Marino byte sequence without producing any compressed output. This function must 657*86d7f5d3SJohn Marino be called immediately after deflateInit or deflateInit2, before any call 658*86d7f5d3SJohn Marino of deflate. The compressor and decompressor must use exactly the same 659*86d7f5d3SJohn Marino dictionary (see inflateSetDictionary). 660*86d7f5d3SJohn Marino The dictionary should consist of strings (byte sequences) that are likely 661*86d7f5d3SJohn Marino to be encountered later in the data to be compressed, with the most commonly 662*86d7f5d3SJohn Marino used strings preferably put towards the end of the dictionary. Using a 663*86d7f5d3SJohn Marino dictionary is most useful when the data to be compressed is short and 664*86d7f5d3SJohn Marino can be predicted with good accuracy; the data can then be compressed better 665*86d7f5d3SJohn Marino than with the default empty dictionary. In this version of the library, 666*86d7f5d3SJohn Marino only the last 32K bytes of the dictionary are used. 667*86d7f5d3SJohn Marino Upon return of this function, strm->adler is set to the Adler32 value 668*86d7f5d3SJohn Marino of the dictionary; the decompressor may later use this value to determine 669*86d7f5d3SJohn Marino which dictionary has been used by the compressor. (The Adler32 value 670*86d7f5d3SJohn Marino applies to the whole dictionary even if only a subset of the dictionary is 671*86d7f5d3SJohn Marino actually used by the compressor.) 672*86d7f5d3SJohn Marino 673*86d7f5d3SJohn Marino deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 674*86d7f5d3SJohn Marino parameter is invalid (such as NULL dictionary) or the stream state 675*86d7f5d3SJohn Marino is inconsistent (for example if deflate has already been called for this 676*86d7f5d3SJohn Marino stream). deflateSetDictionary does not perform any compression: this will 677*86d7f5d3SJohn Marino be done by deflate(). 678*86d7f5d3SJohn Marino */ 679*86d7f5d3SJohn Marino 680*86d7f5d3SJohn Marino extern int EXPORT deflateCopy OF((z_streamp dest, 681*86d7f5d3SJohn Marino z_streamp source)); 682*86d7f5d3SJohn Marino /* 683*86d7f5d3SJohn Marino Sets the destination stream as a complete copy of the source stream. If 684*86d7f5d3SJohn Marino the source stream is using an application-supplied history buffer, a new 685*86d7f5d3SJohn Marino buffer is allocated for the destination stream. The compressed output 686*86d7f5d3SJohn Marino buffer is always application-supplied. It's the responsibility of the 687*86d7f5d3SJohn Marino application to provide the correct values of next_out and avail_out for the 688*86d7f5d3SJohn Marino next call of deflate. 689*86d7f5d3SJohn Marino 690*86d7f5d3SJohn Marino This function can be useful when several compression strategies will be 691*86d7f5d3SJohn Marino tried, for example when there are several ways of pre-processing the input 692*86d7f5d3SJohn Marino data with a filter. The streams that will be discarded should then be freed 693*86d7f5d3SJohn Marino by calling deflateEnd. Note that deflateCopy duplicates the internal 694*86d7f5d3SJohn Marino compression state which can be quite large, so this strategy is slow and 695*86d7f5d3SJohn Marino can consume lots of memory. 696*86d7f5d3SJohn Marino 697*86d7f5d3SJohn Marino deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 698*86d7f5d3SJohn Marino enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 699*86d7f5d3SJohn Marino (such as zalloc being NULL). msg is left unchanged in both source and 700*86d7f5d3SJohn Marino destination. 701*86d7f5d3SJohn Marino */ 702*86d7f5d3SJohn Marino 703*86d7f5d3SJohn Marino extern int EXPORT deflateReset OF((z_streamp strm)); 704*86d7f5d3SJohn Marino /* 705*86d7f5d3SJohn Marino This function is equivalent to deflateEnd followed by deflateInit, 706*86d7f5d3SJohn Marino but does not free and reallocate all the internal compression state. 707*86d7f5d3SJohn Marino The stream will keep the same compression level and any other attributes 708*86d7f5d3SJohn Marino that may have been set by deflateInit2. 709*86d7f5d3SJohn Marino 710*86d7f5d3SJohn Marino deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 711*86d7f5d3SJohn Marino stream state was inconsistent (such as zalloc or state being NULL). 712*86d7f5d3SJohn Marino */ 713*86d7f5d3SJohn Marino 714*86d7f5d3SJohn Marino extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy)); 715*86d7f5d3SJohn Marino /* 716*86d7f5d3SJohn Marino Dynamically update the compression level and compression strategy. 717*86d7f5d3SJohn Marino This can be used to switch between compression and straight copy of 718*86d7f5d3SJohn Marino the input data, or to switch to a different kind of input data requiring 719*86d7f5d3SJohn Marino a different strategy. If the compression level is changed, the input 720*86d7f5d3SJohn Marino available so far is compressed with the old level (and may be flushed); 721*86d7f5d3SJohn Marino the new level will take effect only at the next call of deflate(). 722*86d7f5d3SJohn Marino 723*86d7f5d3SJohn Marino Before the call of deflateParams, the stream state must be set as for 724*86d7f5d3SJohn Marino a call of deflate(), since the currently available input may have to 725*86d7f5d3SJohn Marino be compressed and flushed. In particular, strm->avail_out must be non-zero. 726*86d7f5d3SJohn Marino 727*86d7f5d3SJohn Marino deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 728*86d7f5d3SJohn Marino stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 729*86d7f5d3SJohn Marino if strm->avail_out was zero. 730*86d7f5d3SJohn Marino */ 731*86d7f5d3SJohn Marino 732*86d7f5d3SJohn Marino extern int EXPORT deflateOutputPending OF((z_streamp strm)); 733*86d7f5d3SJohn Marino /* 734*86d7f5d3SJohn Marino Returns the number of bytes of output which are immediately 735*86d7f5d3SJohn Marino available from the compressor (i.e. without any further input 736*86d7f5d3SJohn Marino or flush). 737*86d7f5d3SJohn Marino */ 738*86d7f5d3SJohn Marino 739*86d7f5d3SJohn Marino /* 740*86d7f5d3SJohn Marino extern int EXPORT inflateInit2 OF((z_streamp strm, 741*86d7f5d3SJohn Marino int windowBits)); 742*86d7f5d3SJohn Marino 743*86d7f5d3SJohn Marino This is another version of inflateInit with more compression options. The 744*86d7f5d3SJohn Marino fields next_out, zalloc, zfree and opaque must be initialized before by 745*86d7f5d3SJohn Marino the caller. 746*86d7f5d3SJohn Marino 747*86d7f5d3SJohn Marino The windowBits parameter is the base two logarithm of the maximum window 748*86d7f5d3SJohn Marino size (the size of the history buffer). It should be in the range 8..15 for 749*86d7f5d3SJohn Marino this version of the library (the value 16 will be allowed soon). The 750*86d7f5d3SJohn Marino default value is 15 if inflateInit is used instead. If a compressed stream 751*86d7f5d3SJohn Marino with a larger window size is given as input, inflate() will return with 752*86d7f5d3SJohn Marino the error code Z_DATA_ERROR instead of trying to allocate a larger window. 753*86d7f5d3SJohn Marino 754*86d7f5d3SJohn Marino If next_out is not null, the library will use this buffer for the history 755*86d7f5d3SJohn Marino buffer; the buffer must either be large enough to hold the entire output 756*86d7f5d3SJohn Marino data, or have at least 1<<windowBits bytes. If next_out is null, the 757*86d7f5d3SJohn Marino library will allocate its own buffer (and leave next_out null). next_in 758*86d7f5d3SJohn Marino need not be provided here but must be provided by the application for the 759*86d7f5d3SJohn Marino next call of inflate(). 760*86d7f5d3SJohn Marino 761*86d7f5d3SJohn Marino If the history buffer is provided by the application, next_out must 762*86d7f5d3SJohn Marino never be changed by the application since the decompressor maintains 763*86d7f5d3SJohn Marino history information inside this buffer from call to call; the application 764*86d7f5d3SJohn Marino can only reset next_out to the beginning of the history buffer when 765*86d7f5d3SJohn Marino avail_out is zero and all output has been consumed. 766*86d7f5d3SJohn Marino 767*86d7f5d3SJohn Marino inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 768*86d7f5d3SJohn Marino not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as 769*86d7f5d3SJohn Marino windowBits < 8). msg is set to null if there is no error message. 770*86d7f5d3SJohn Marino inflateInit2 does not perform any decompression: this will be done by 771*86d7f5d3SJohn Marino inflate(). 772*86d7f5d3SJohn Marino */ 773*86d7f5d3SJohn Marino 774*86d7f5d3SJohn Marino extern int EXPORT inflateSetDictionary OF((z_streamp strm, 775*86d7f5d3SJohn Marino const Bytef *dictionary, 776*86d7f5d3SJohn Marino uInt dictLength)); 777*86d7f5d3SJohn Marino /* 778*86d7f5d3SJohn Marino Initializes the decompression dictionary (history buffer) from the given 779*86d7f5d3SJohn Marino uncompressed byte sequence. This function must be called immediately after 780*86d7f5d3SJohn Marino a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen 781*86d7f5d3SJohn Marino by the compressor can be determined from the Adler32 value returned by this 782*86d7f5d3SJohn Marino call of inflate. The compressor and decompressor must use exactly the same 783*86d7f5d3SJohn Marino dictionary (see deflateSetDictionary). 784*86d7f5d3SJohn Marino 785*86d7f5d3SJohn Marino inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 786*86d7f5d3SJohn Marino parameter is invalid (such as NULL dictionary) or the stream state is 787*86d7f5d3SJohn Marino inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 788*86d7f5d3SJohn Marino expected one (incorrect Adler32 value). inflateSetDictionary does not 789*86d7f5d3SJohn Marino perform any decompression: this will be done by subsequent calls of 790*86d7f5d3SJohn Marino inflate(). 791*86d7f5d3SJohn Marino */ 792*86d7f5d3SJohn Marino 793*86d7f5d3SJohn Marino extern int EXPORT inflateSync OF((z_streamp strm)); 794*86d7f5d3SJohn Marino /* 795*86d7f5d3SJohn Marino Skips invalid compressed data until the special marker (see deflate() 796*86d7f5d3SJohn Marino above) can be found, or until all available input is skipped. No output 797*86d7f5d3SJohn Marino is provided. 798*86d7f5d3SJohn Marino 799*86d7f5d3SJohn Marino inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR 800*86d7f5d3SJohn Marino if no more input was provided, Z_DATA_ERROR if no marker has been found, 801*86d7f5d3SJohn Marino or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 802*86d7f5d3SJohn Marino case, the application may save the current current value of total_in which 803*86d7f5d3SJohn Marino indicates where valid compressed data was found. In the error case, the 804*86d7f5d3SJohn Marino application may repeatedly call inflateSync, providing more input each time, 805*86d7f5d3SJohn Marino until success or end of the input data. 806*86d7f5d3SJohn Marino */ 807*86d7f5d3SJohn Marino 808*86d7f5d3SJohn Marino extern int EXPORT inflateReset OF((z_streamp strm)); 809*86d7f5d3SJohn Marino /* 810*86d7f5d3SJohn Marino This function is equivalent to inflateEnd followed by inflateInit, 811*86d7f5d3SJohn Marino but does not free and reallocate all the internal decompression state. 812*86d7f5d3SJohn Marino The stream will keep attributes that may have been set by inflateInit2. 813*86d7f5d3SJohn Marino 814*86d7f5d3SJohn Marino inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 815*86d7f5d3SJohn Marino stream state was inconsistent (such as zalloc or state being NULL). 816*86d7f5d3SJohn Marino */ 817*86d7f5d3SJohn Marino 818*86d7f5d3SJohn Marino extern int inflateIncomp OF((z_stream *strm)); 819*86d7f5d3SJohn Marino /* 820*86d7f5d3SJohn Marino This function adds the data at next_in (avail_in bytes) to the output 821*86d7f5d3SJohn Marino history without performing any output. There must be no pending output, 822*86d7f5d3SJohn Marino and the decompressor must be expecting to see the start of a block. 823*86d7f5d3SJohn Marino Calling this function is equivalent to decompressing a stored block 824*86d7f5d3SJohn Marino containing the data at next_in (except that the data is not output). 825*86d7f5d3SJohn Marino */ 826*86d7f5d3SJohn Marino 827*86d7f5d3SJohn Marino /* utility functions */ 828*86d7f5d3SJohn Marino 829*86d7f5d3SJohn Marino /* 830*86d7f5d3SJohn Marino The following utility functions are implemented on top of the 831*86d7f5d3SJohn Marino basic stream-oriented functions. To simplify the interface, some 832*86d7f5d3SJohn Marino default options are assumed (compression level, window size, 833*86d7f5d3SJohn Marino standard memory allocation functions). The source code of these 834*86d7f5d3SJohn Marino utility functions can easily be modified if you need special options. 835*86d7f5d3SJohn Marino */ 836*86d7f5d3SJohn Marino 837*86d7f5d3SJohn Marino extern int EXPORT compress OF((Bytef *dest, uLongf *destLen, 838*86d7f5d3SJohn Marino const Bytef *source, uLong sourceLen)); 839*86d7f5d3SJohn Marino /* 840*86d7f5d3SJohn Marino Compresses the source buffer into the destination buffer. sourceLen is 841*86d7f5d3SJohn Marino the byte length of the source buffer. Upon entry, destLen is the total 842*86d7f5d3SJohn Marino size of the destination buffer, which must be at least 0.1% larger than 843*86d7f5d3SJohn Marino sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the 844*86d7f5d3SJohn Marino compressed buffer. 845*86d7f5d3SJohn Marino This function can be used to compress a whole file at once if the 846*86d7f5d3SJohn Marino input file is mmap'ed. 847*86d7f5d3SJohn Marino compress returns Z_OK if success, Z_MEM_ERROR if there was not 848*86d7f5d3SJohn Marino enough memory, Z_BUF_ERROR if there was not enough room in the output 849*86d7f5d3SJohn Marino buffer. 850*86d7f5d3SJohn Marino */ 851*86d7f5d3SJohn Marino 852*86d7f5d3SJohn Marino extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen, 853*86d7f5d3SJohn Marino const Bytef *source, uLong sourceLen)); 854*86d7f5d3SJohn Marino /* 855*86d7f5d3SJohn Marino Decompresses the source buffer into the destination buffer. sourceLen is 856*86d7f5d3SJohn Marino the byte length of the source buffer. Upon entry, destLen is the total 857*86d7f5d3SJohn Marino size of the destination buffer, which must be large enough to hold the 858*86d7f5d3SJohn Marino entire uncompressed data. (The size of the uncompressed data must have 859*86d7f5d3SJohn Marino been saved previously by the compressor and transmitted to the decompressor 860*86d7f5d3SJohn Marino by some mechanism outside the scope of this compression library.) 861*86d7f5d3SJohn Marino Upon exit, destLen is the actual size of the compressed buffer. 862*86d7f5d3SJohn Marino This function can be used to decompress a whole file at once if the 863*86d7f5d3SJohn Marino input file is mmap'ed. 864*86d7f5d3SJohn Marino 865*86d7f5d3SJohn Marino uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 866*86d7f5d3SJohn Marino enough memory, Z_BUF_ERROR if there was not enough room in the output 867*86d7f5d3SJohn Marino buffer, or Z_DATA_ERROR if the input data was corrupted. 868*86d7f5d3SJohn Marino */ 869*86d7f5d3SJohn Marino 870*86d7f5d3SJohn Marino 871*86d7f5d3SJohn Marino typedef voidp gzFile; 872*86d7f5d3SJohn Marino 873*86d7f5d3SJohn Marino extern gzFile EXPORT gzopen OF((const char *path, const char *mode)); 874*86d7f5d3SJohn Marino /* 875*86d7f5d3SJohn Marino Opens a gzip (.gz) file for reading or writing. The mode parameter 876*86d7f5d3SJohn Marino is as in fopen ("rb" or "wb") but can also include a compression level 877*86d7f5d3SJohn Marino ("wb9"). gzopen can be used to read a file which is not in gzip format; 878*86d7f5d3SJohn Marino in this case gzread will directly read from the file without decompression. 879*86d7f5d3SJohn Marino gzopen returns NULL if the file could not be opened or if there was 880*86d7f5d3SJohn Marino insufficient memory to allocate the (de)compression state; errno 881*86d7f5d3SJohn Marino can be checked to distinguish the two cases (if errno is zero, the 882*86d7f5d3SJohn Marino zlib error is Z_MEM_ERROR). 883*86d7f5d3SJohn Marino */ 884*86d7f5d3SJohn Marino 885*86d7f5d3SJohn Marino extern gzFile EXPORT gzdopen OF((int fd, const char *mode)); 886*86d7f5d3SJohn Marino /* 887*86d7f5d3SJohn Marino gzdopen() associates a gzFile with the file descriptor fd. File 888*86d7f5d3SJohn Marino descriptors are obtained from calls like open, dup, creat, pipe or 889*86d7f5d3SJohn Marino fileno (in the file has been previously opened with fopen). 890*86d7f5d3SJohn Marino The mode parameter is as in gzopen. 891*86d7f5d3SJohn Marino The next call of gzclose on the returned gzFile will also close the 892*86d7f5d3SJohn Marino file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 893*86d7f5d3SJohn Marino descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 894*86d7f5d3SJohn Marino gzdopen returns NULL if there was insufficient memory to allocate 895*86d7f5d3SJohn Marino the (de)compression state. 896*86d7f5d3SJohn Marino */ 897*86d7f5d3SJohn Marino 898*86d7f5d3SJohn Marino extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 899*86d7f5d3SJohn Marino /* 900*86d7f5d3SJohn Marino Reads the given number of uncompressed bytes from the compressed file. 901*86d7f5d3SJohn Marino If the input file was not in gzip format, gzread copies the given number 902*86d7f5d3SJohn Marino of bytes into the buffer. 903*86d7f5d3SJohn Marino gzread returns the number of uncompressed bytes actually read (0 for 904*86d7f5d3SJohn Marino end of file, -1 for error). */ 905*86d7f5d3SJohn Marino 906*86d7f5d3SJohn Marino extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len)); 907*86d7f5d3SJohn Marino /* 908*86d7f5d3SJohn Marino Writes the given number of uncompressed bytes into the compressed file. 909*86d7f5d3SJohn Marino gzwrite returns the number of uncompressed bytes actually written 910*86d7f5d3SJohn Marino (0 in case of error). 911*86d7f5d3SJohn Marino */ 912*86d7f5d3SJohn Marino 913*86d7f5d3SJohn Marino extern int EXPORT gzflush OF((gzFile file, int flush)); 914*86d7f5d3SJohn Marino /* 915*86d7f5d3SJohn Marino Flushes all pending output into the compressed file. The parameter 916*86d7f5d3SJohn Marino flush is as in the deflate() function. The return value is the zlib 917*86d7f5d3SJohn Marino error number (see function gzerror below). gzflush returns Z_OK if 918*86d7f5d3SJohn Marino the flush parameter is Z_FINISH and all output could be flushed. 919*86d7f5d3SJohn Marino gzflush should be called only when strictly necessary because it can 920*86d7f5d3SJohn Marino degrade compression. 921*86d7f5d3SJohn Marino */ 922*86d7f5d3SJohn Marino 923*86d7f5d3SJohn Marino extern int EXPORT gzclose OF((gzFile file)); 924*86d7f5d3SJohn Marino /* 925*86d7f5d3SJohn Marino Flushes all pending output if necessary, closes the compressed file 926*86d7f5d3SJohn Marino and deallocates all the (de)compression state. The return value is the zlib 927*86d7f5d3SJohn Marino error number (see function gzerror below). 928*86d7f5d3SJohn Marino */ 929*86d7f5d3SJohn Marino 930*86d7f5d3SJohn Marino extern const char * EXPORT gzerror OF((gzFile file, int *errnum)); 931*86d7f5d3SJohn Marino /* 932*86d7f5d3SJohn Marino Returns the error message for the last error which occurred on the 933*86d7f5d3SJohn Marino given compressed file. errnum is set to zlib error number. If an 934*86d7f5d3SJohn Marino error occurred in the file system and not in the compression library, 935*86d7f5d3SJohn Marino errnum is set to Z_ERRNO and the application may consult errno 936*86d7f5d3SJohn Marino to get the exact error code. 937*86d7f5d3SJohn Marino */ 938*86d7f5d3SJohn Marino 939*86d7f5d3SJohn Marino /* checksum functions */ 940*86d7f5d3SJohn Marino 941*86d7f5d3SJohn Marino /* 942*86d7f5d3SJohn Marino These functions are not related to compression but are exported 943*86d7f5d3SJohn Marino anyway because they might be useful in applications using the 944*86d7f5d3SJohn Marino compression library. 945*86d7f5d3SJohn Marino */ 946*86d7f5d3SJohn Marino 947*86d7f5d3SJohn Marino extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 948*86d7f5d3SJohn Marino 949*86d7f5d3SJohn Marino /* 950*86d7f5d3SJohn Marino Update a running Adler-32 checksum with the bytes buf[0..len-1] and 951*86d7f5d3SJohn Marino return the updated checksum. If buf is NULL, this function returns 952*86d7f5d3SJohn Marino the required initial value for the checksum. 953*86d7f5d3SJohn Marino An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 954*86d7f5d3SJohn Marino much faster. Usage example: 955*86d7f5d3SJohn Marino 956*86d7f5d3SJohn Marino uLong adler = adler32(0L, Z_NULL, 0); 957*86d7f5d3SJohn Marino 958*86d7f5d3SJohn Marino while (read_buffer(buffer, length) != EOF) { 959*86d7f5d3SJohn Marino adler = adler32(adler, buffer, length); 960*86d7f5d3SJohn Marino } 961*86d7f5d3SJohn Marino if (adler != original_adler) error(); 962*86d7f5d3SJohn Marino */ 963*86d7f5d3SJohn Marino 964*86d7f5d3SJohn Marino #if 0 965*86d7f5d3SJohn Marino extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 966*86d7f5d3SJohn Marino /* 967*86d7f5d3SJohn Marino Update a running crc with the bytes buf[0..len-1] and return the updated 968*86d7f5d3SJohn Marino crc. If buf is NULL, this function returns the required initial value 969*86d7f5d3SJohn Marino for the crc. Pre- and post-conditioning (one's complement) is performed 970*86d7f5d3SJohn Marino within this function so it shouldn't be done by the application. 971*86d7f5d3SJohn Marino Usage example: 972*86d7f5d3SJohn Marino 973*86d7f5d3SJohn Marino uLong crc = crc32(0L, Z_NULL, 0); 974*86d7f5d3SJohn Marino 975*86d7f5d3SJohn Marino while (read_buffer(buffer, length) != EOF) { 976*86d7f5d3SJohn Marino crc = crc32(crc, buffer, length); 977*86d7f5d3SJohn Marino } 978*86d7f5d3SJohn Marino if (crc != original_crc) error(); 979*86d7f5d3SJohn Marino */ 980*86d7f5d3SJohn Marino #endif 981*86d7f5d3SJohn Marino 982*86d7f5d3SJohn Marino 983*86d7f5d3SJohn Marino /* various hacks, don't look :) */ 984*86d7f5d3SJohn Marino 985*86d7f5d3SJohn Marino /* deflateInit and inflateInit are macros to allow checking the zlib version 986*86d7f5d3SJohn Marino * and the compiler's view of z_stream: 987*86d7f5d3SJohn Marino */ 988*86d7f5d3SJohn Marino extern int EXPORT deflateInit_ OF((z_streamp strm, int level, 989*86d7f5d3SJohn Marino const char *version, int stream_size)); 990*86d7f5d3SJohn Marino extern int EXPORT inflateInit_ OF((z_streamp strm, 991*86d7f5d3SJohn Marino const char *version, int stream_size)); 992*86d7f5d3SJohn Marino extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 993*86d7f5d3SJohn Marino int windowBits, int memLevel, int strategy, 994*86d7f5d3SJohn Marino const char *version, int stream_size)); 995*86d7f5d3SJohn Marino extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 996*86d7f5d3SJohn Marino const char *version, int stream_size)); 997*86d7f5d3SJohn Marino #define deflateInit(strm, level) \ 998*86d7f5d3SJohn Marino deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 999*86d7f5d3SJohn Marino #define inflateInit(strm) \ 1000*86d7f5d3SJohn Marino inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 1001*86d7f5d3SJohn Marino #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 1002*86d7f5d3SJohn Marino deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 1003*86d7f5d3SJohn Marino (strategy), ZLIB_VERSION, sizeof(z_stream)) 1004*86d7f5d3SJohn Marino #define inflateInit2(strm, windowBits) \ 1005*86d7f5d3SJohn Marino inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 1006*86d7f5d3SJohn Marino 1007*86d7f5d3SJohn Marino #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) 1008*86d7f5d3SJohn Marino struct internal_state {int dummy;}; /* hack for buggy compilers */ 1009*86d7f5d3SJohn Marino #endif 1010*86d7f5d3SJohn Marino 1011*86d7f5d3SJohn Marino uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */ 1012*86d7f5d3SJohn Marino 1013*86d7f5d3SJohn Marino #ifdef __cplusplus 1014*86d7f5d3SJohn Marino } 1015*86d7f5d3SJohn Marino #endif 1016*86d7f5d3SJohn Marino 1017*86d7f5d3SJohn Marino #endif /* _NET_ZLIB_H_ */ 1018*86d7f5d3SJohn Marino /* --- zlib.h */ 1019