1 /* zutil.h -- internal interface and configuration of the compression library
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
6 /* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
12 /* @(#) $Id: zutil.h,v 1.2 2007/09/11 15:22:29 david.cole Exp $ */
14 /* @(#) $Id: zutil.h,v 1.3 2008-09-15 21:53:28 hoffman Exp $ */
32 /* The Microsoft C Run-Time Library for Windows CE doesn't have
33 * errno. We define it as a global variable to simplify porting.
34 * Its value is always 0 and should not be used. We rename it to
35 * avoid conflict with other libraries that use the same workaround.
37 # define errno z_errno
49 /* compile with -Dlocal if your debugger can't find static symbols */
51 typedef unsigned char uch
;
53 typedef unsigned short ush
;
55 typedef unsigned long ulg
;
57 extern const char * const z_errmsg
[10]; /* indexed by 2-zlib_error */
58 /* (size given to avoid silly warnings with Visual C++) */
60 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
62 #define ERR_RETURN(strm,err) \
63 return (strm->msg = (char*)ERR_MSG(err), (err))
64 /* To be used only when the state is known to be valid */
66 /* common constants */
69 # define DEF_WBITS MAX_WBITS
71 /* default windowBits for decompression. MAX_WBITS is for compression only */
73 #if MAX_MEM_LEVEL >= 8
74 # define DEF_MEM_LEVEL 8
76 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
78 /* default memLevel */
80 #define STORED_BLOCK 0
81 #define STATIC_TREES 1
83 /* The three kinds of block type */
87 /* The minimum and maximum match lengths */
89 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
91 /* target dependencies */
93 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
95 # if defined(__TURBOC__) || defined(__BORLANDC__)
96 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
97 /* Allow compilation with ANSI keywords only enabled */
98 void _Cdecl
farfree( void *block
);
99 void *_Cdecl
farmalloc( unsigned long nbytes
);
103 # else /* MSC or DJGPP */
109 # define OS_CODE 0x01
112 #if defined(VAXC) || defined(VMS)
113 # define OS_CODE 0x02
114 # define F_OPEN(name, mode) \
115 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
118 #if defined(ATARI) || defined(atarist)
119 # define OS_CODE 0x05
123 # define OS_CODE 0x06
129 #if defined(MACOS) || defined(TARGET_OS_MAC)
130 # define OS_CODE 0x07
131 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
132 # include <unix.h> /* for fdopen */
135 # define fdopen(fd,mode) NULL /* No fdopen() */
141 # define OS_CODE 0x0a
145 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
146 # define OS_CODE 0x0b
150 #ifdef __50SERIES /* Prime/PRIMOS */
151 # define OS_CODE 0x0f
154 /* Haiku defines both __HAIKU__ and __BEOS__ (for now) */
155 /* many BeOS workarounds are no longer needed in Haiku */
156 #if defined(__HAIKU__) && defined(__BEOS__)
160 #if defined(_BEOS_) || defined(RISCOS)
161 # define fdopen(fd,mode) NULL /* No fdopen() */
164 #if (defined(_MSC_VER) && (_MSC_VER > 600))
165 # if defined(_WIN32_WCE)
166 # define fdopen(fd,mode) NULL /* No fdopen() */
167 # ifndef _PTRDIFF_T_DEFINED
168 typedef int ptrdiff_t;
169 # define _PTRDIFF_T_DEFINED
172 # define fdopen(fd,type) _fdopen(fd,type)
176 /* common defaults */
179 # define OS_CODE 0x03 /* assume Unix */
183 # define F_OPEN(name, mode) fopen((name), (mode))
188 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
189 # ifndef HAVE_VSNPRINTF
190 # define HAVE_VSNPRINTF
193 #if defined(__CYGWIN__)
194 # ifndef HAVE_VSNPRINTF
195 # define HAVE_VSNPRINTF
198 #ifndef HAVE_VSNPRINTF
200 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
201 but for now we just assume it doesn't. */
202 # define NO_vsnprintf
205 # define NO_vsnprintf
208 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
209 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
210 # define vsnprintf _vsnprintf
214 # define NO_vsnprintf
218 # define NO_vsnprintf
224 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
225 /* Use our own functions for small and medium model with MSC <= 5.0.
226 * You may have to use the same strategy for Borland C (untested).
227 * The __SC__ check is for Symantec.
231 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
235 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
236 # define zmemcpy _fmemcpy
237 # define zmemcmp _fmemcmp
238 # define zmemzero(dest, len) _fmemset(dest, 0, len)
240 # define zmemcpy memcpy
241 # define zmemcmp memcmp
242 # define zmemzero(dest, len) memset(dest, 0, len)
245 extern void zmemcpy
OF((Bytef
* dest
, const Bytef
* source
, uInt len
));
246 extern int zmemcmp
OF((const Bytef
* s1
, const Bytef
* s2
, uInt len
));
247 extern void zmemzero
OF((Bytef
* dest
, uInt len
));
250 /* Diagnostic functions */
253 extern int z_verbose
;
254 extern void z_error
OF((char *m
));
255 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
256 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
257 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
258 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
259 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
260 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
262 # define Assert(cond,msg)
267 # define Tracecv(c,x)
271 voidpf zcalloc
OF((voidpf opaque
, unsigned items
, unsigned size
));
272 void zcfree
OF((voidpf opaque
, voidpf ptr
));
274 #define ZALLOC(strm, items, size) \
275 (*((strm)->zalloc))((strm)->opaque, (items), (size))
276 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
277 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}