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