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