2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* zutil.h -- internal interface and configuration of the compression library
7 * Copyright (C) 1995-2005 Jean-loup Gailly.
8 * For conditions of distribution and use, see copyright notice in zlib.h
11 /* WARNING: this file should *not* be used by applications. It is
12 part of the implementation of the compression library and is
13 subject to change. Applications should only use zlib.h.
31 /* The Microsoft C Run-Time Library for Windows CE doesn't have
32 * errno. We define it as a global variable to simplify porting.
33 * Its value is always 0 and should not be used. We rename it to
34 * avoid conflict with other libraries that use the same workaround.
36 # define errno z_errno
41 # include <sys/errno.h>
48 /* compile with -Dlocal if your debugger can't find static symbols */
50 typedef unsigned char uch
;
52 typedef unsigned short ush
;
54 typedef unsigned long ulg
;
56 extern const char * const z_errmsg
[10]; /* indexed by 2-zlib_error */
57 /* (size given to avoid silly warnings with Visual C++) */
59 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
61 #define ERR_RETURN(strm,err) \
62 return (strm->msg = (char*)ERR_MSG(err), (err))
63 /* To be used only when the state is known to be valid */
65 /* common constants */
68 # define DEF_WBITS MAX_WBITS
70 /* default windowBits for decompression. MAX_WBITS is for compression only */
72 #if MAX_MEM_LEVEL >= 8
73 # define DEF_MEM_LEVEL 8
75 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
77 /* default memLevel */
79 #define STORED_BLOCK 0
80 #define STATIC_TREES 1
82 /* The three kinds of block type */
86 /* The minimum and maximum match lengths */
88 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
90 /* target dependencies */
92 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
94 # if defined(__TURBOC__) || defined(__BORLANDC__)
95 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
96 /* Allow compilation with ANSI keywords only enabled */
97 void _Cdecl
farfree( void *block
);
98 void *_Cdecl
farmalloc( unsigned long nbytes
);
102 # else /* MSC or DJGPP */
108 # define OS_CODE 0x01
111 #if defined(VAXC) || defined(VMS)
112 # define OS_CODE 0x02
113 # define F_OPEN(name, mode) \
114 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
117 #if defined(ATARI) || defined(atarist)
118 # define OS_CODE 0x05
122 # define OS_CODE 0x06
128 #if defined(MACOS) || defined(TARGET_OS_MAC)
129 # define OS_CODE 0x07
130 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
131 # include <unix.h> /* for fdopen */
134 # define fdopen(fd,mode) NULL /* No fdopen() */
140 # define OS_CODE 0x0a
144 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
145 # define OS_CODE 0x0b
149 #ifdef __50SERIES /* Prime/PRIMOS */
150 # define OS_CODE 0x0f
153 #if defined(_BEOS_) || defined(RISCOS)
154 # define fdopen(fd,mode) NULL /* No fdopen() */
157 #if (defined(_MSC_VER) && (_MSC_VER > 600))
158 # if defined(_WIN32_WCE)
159 # define fdopen(fd,mode) NULL /* No fdopen() */
160 # ifndef _PTRDIFF_T_DEFINED
161 typedef int ptrdiff_t;
162 # define _PTRDIFF_T_DEFINED
165 # define fdopen(fd,type) _fdopen(fd,type)
169 /* common defaults */
172 # define OS_CODE 0x03 /* assume Unix */
176 # define F_OPEN(name, mode) fopen((name), (mode))
181 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
182 # ifndef HAVE_VSNPRINTF
183 # define HAVE_VSNPRINTF
186 #if defined(__CYGWIN__)
187 # ifndef HAVE_VSNPRINTF
188 # define HAVE_VSNPRINTF
191 #ifndef HAVE_VSNPRINTF
193 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
194 but for now we just assume it doesn't. */
195 # define NO_vsnprintf
198 # define NO_vsnprintf
201 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
202 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
203 # define vsnprintf _vsnprintf
207 # define NO_vsnprintf
211 # define NO_vsnprintf
217 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
218 /* Use our own functions for small and medium model with MSC <= 5.0.
219 * You may have to use the same strategy for Borland C (untested).
220 * The __SC__ check is for Symantec.
224 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
228 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
229 # define zmemcpy _fmemcpy
230 # define zmemcmp _fmemcmp
231 # define zmemzero(dest, len) _fmemset(dest, 0, len)
233 # define zmemcpy memcpy
234 # define zmemcmp memcmp
235 # define zmemzero(dest, len) memset(dest, 0, len)
238 extern void zmemcpy
OF((void* dest
, const void* source
, uInt len
));
239 extern int zmemcmp
OF((const void* s1
, const void* s2
, uInt len
));
240 extern void zmemzero
OF((void* dest
, uInt len
));
243 /* Diagnostic functions */
246 extern int z_verbose
;
247 extern void z_error
OF((char *m
));
248 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
249 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
250 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
251 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
252 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
253 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
255 # define Assert(cond,msg)
260 # define Tracecv(c,x)
264 voidpf zcalloc
OF((voidpf opaque
, unsigned items
, unsigned size
));
265 void zcfree
OF((voidpf opaque
, voidpf ptr
));
267 #define ZALLOC(strm, items, size) \
268 (*((strm)->zalloc))((strm)->opaque, (items), (size))
269 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
270 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
272 #endif /* _ZUTIL_H */