]>
git.saurik.com Git - apple/xnu.git/blob - libkern/zlib/zutil.h
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* zutil.h -- internal interface and configuration of the compression library
29 * Copyright (C) 1995-2005 Jean-loup Gailly.
30 * For conditions of distribution and use, see copyright notice in zlib.h
33 /* WARNING: this file should *not* be used by applications. It is
34 part of the implementation of the compression library and is
35 subject to change. Applications should only use zlib.h.
46 # include <libkern/zlib.h>
67 /* The Microsoft C Run-Time Library for Windows CE doesn't have
68 * errno. We define it as a global variable to simplify porting.
69 * Its value is always 0 and should not be used. We rename it to
70 * avoid conflict with other libraries that use the same workaround.
72 # define errno z_errno
84 /* compile with -Dlocal if your debugger can't find static symbols */
86 typedef unsigned char uch
;
88 typedef unsigned short ush
;
90 typedef unsigned long ulg
;
92 extern const char * const z_errmsg
[10]; /* indexed by 2-zlib_error */
93 /* (size given to avoid silly warnings with Visual C++) */
95 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
97 #define ERR_RETURN(strm,err) \
98 return (strm->msg = (char*)ERR_MSG(err), (err))
99 /* To be used only when the state is known to be valid */
101 /* common constants */
104 # define DEF_WBITS MAX_WBITS
106 /* default windowBits for decompression. MAX_WBITS is for compression only */
108 #if MAX_MEM_LEVEL >= 8
109 # define DEF_MEM_LEVEL 8
111 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
113 /* default memLevel */
115 #define STORED_BLOCK 0
116 #define STATIC_TREES 1
118 /* The three kinds of block type */
121 #define MAX_MATCH 258
122 /* The minimum and maximum match lengths */
124 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
126 /* target dependencies */
128 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
129 # define OS_CODE 0x00
130 # if defined(__TURBOC__) || defined(__BORLANDC__)
131 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
132 /* Allow compilation with ANSI keywords only enabled */
133 void _Cdecl
farfree( void *block
);
134 void *_Cdecl
farmalloc( unsigned long nbytes
);
138 # else /* MSC or DJGPP */
144 # define OS_CODE 0x01
147 #if defined(VAXC) || defined(VMS)
148 # define OS_CODE 0x02
149 # define F_OPEN(name, mode) \
150 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
153 #if defined(ATARI) || defined(atarist)
154 # define OS_CODE 0x05
158 # define OS_CODE 0x06
164 #if defined(MACOS) || defined(TARGET_OS_MAC)
165 # define OS_CODE 0x07
166 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
167 # include <unix.h> /* for fdopen */
170 # define fdopen(fd,mode) NULL /* No fdopen() */
176 # define OS_CODE 0x0a
180 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
181 # define OS_CODE 0x0b
185 #ifdef __50SERIES /* Prime/PRIMOS */
186 # define OS_CODE 0x0f
189 #if defined(_BEOS_) || defined(RISCOS)
190 # define fdopen(fd,mode) NULL /* No fdopen() */
194 typedef long ptrdiff_t;
195 #elif (defined(_MSC_VER) && (_MSC_VER > 600))
196 # if defined(_WIN32_WCE)
197 # define fdopen(fd,mode) NULL /* No fdopen() */
198 # ifndef _PTRDIFF_T_DEFINED
199 typedef int ptrdiff_t;
200 # define _PTRDIFF_T_DEFINED
203 # define fdopen(fd,type) _fdopen(fd,type)
208 /* common defaults */
211 # define OS_CODE 0x03 /* assume Unix */
215 # define F_OPEN(name, mode) fopen((name), (mode))
220 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
221 # ifndef HAVE_VSNPRINTF
222 # define HAVE_VSNPRINTF
225 #if defined(__CYGWIN__)
226 # ifndef HAVE_VSNPRINTF
227 # define HAVE_VSNPRINTF
230 #ifndef HAVE_VSNPRINTF
232 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
233 but for now we just assume it doesn't. */
234 # define NO_vsnprintf
237 # define NO_vsnprintf
240 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
241 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
242 # define vsnprintf _vsnprintf
246 # define NO_vsnprintf
250 # define NO_vsnprintf
256 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
257 /* Use our own functions for small and medium model with MSC <= 5.0.
258 * You may have to use the same strategy for Borland C (untested).
259 * The __SC__ check is for Symantec.
263 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
267 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
268 # define zmemcpy _fmemcpy
269 # define zmemcmp _fmemcmp
270 # define zmemzero(dest, len) _fmemset(dest, 0, len)
272 # define zmemcpy memcpy
273 # define zmemcmp memcmp
274 # define zmemzero(dest, len) memset(dest, 0, len)
277 extern void zmemcpy
OF((Bytef
* dest
, const Bytef
* source
, uInt len
));
278 extern int zmemcmp
OF((const Bytef
* s1
, const Bytef
* s2
, uInt len
));
279 extern void zmemzero
OF((Bytef
* dest
, uInt len
));
282 /* Diagnostic functions */
283 #if defined(DEBUG) && !defined(KERNEL)
285 extern int z_verbose
;
286 extern void z_error
OF((char *m
));
287 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
288 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
289 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
290 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
291 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
292 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
294 # define Assert(cond,msg)
299 # define Tracecv(c,x)
304 voidpf zcalloc
OF((voidpf opaque
, unsigned items
, unsigned size
));
305 void zcfree
OF((voidpf opaque
, voidpf ptr
));
306 #endif /* NO_ZCFUNCS */
308 #define ZALLOC(strm, items, size) \
309 (*((strm)->zalloc))((strm)->opaque, (items), (size))
310 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
311 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}