1 /* zutil.h -- internal interface and configuration of the compression library
2 * Copyright (C) 1995-2010 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.
20 # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
27 #if defined(UNDER_CE) && defined(NO_ERRNO_H)
28 # define zseterrno(ERR) SetLastError((DWORD)(ERR))
29 # define zerrno() ((int)GetLastError())
36 # define zseterrno(ERR) do { errno = (ERR); } while (0)
37 # define zerrno() errno
43 /* compile with -Dlocal if your debugger can't find static symbols */
45 typedef unsigned char uch
;
47 typedef unsigned short ush
;
49 typedef unsigned long ulg
;
51 extern const char * const z_errmsg
[10]; /* indexed by 2-zlib_error */
52 /* (size given to avoid silly warnings with Visual C++) */
54 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
56 #define ERR_RETURN(strm,err) \
57 return (strm->msg = (char*)ERR_MSG(err), (err))
58 /* To be used only when the state is known to be valid */
60 /* common constants */
63 # define DEF_WBITS MAX_WBITS
65 /* default windowBits for decompression. MAX_WBITS is for compression only */
67 #if MAX_MEM_LEVEL >= 8
68 # define DEF_MEM_LEVEL 8
70 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
72 /* default memLevel */
74 #define STORED_BLOCK 0
75 #define STATIC_TREES 1
77 /* The three kinds of block type */
81 /* The minimum and maximum match lengths */
83 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
85 /* target dependencies */
87 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
89 # if defined(__TURBOC__) || defined(__BORLANDC__)
90 # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
91 /* Allow compilation with ANSI keywords only enabled */
92 void _Cdecl
farfree( void *block
);
93 void *_Cdecl
farmalloc( unsigned long nbytes
);
97 # else /* MSC or DJGPP */
103 # define OS_CODE 0x01
106 #if defined(VAXC) || defined(VMS)
107 # define OS_CODE 0x02
108 # define F_OPEN(name, mode) \
109 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
112 #if defined(ATARI) || defined(atarist)
113 # define OS_CODE 0x05
117 # define OS_CODE 0x06
123 #if defined(MACOS) || defined(TARGET_OS_MAC)
124 # define OS_CODE 0x07
125 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
126 # include <unix.h> /* for fdopen */
129 # define fdopen(fd,mode) NULL /* No fdopen() */
135 # define OS_CODE 0x0a
139 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
140 # define OS_CODE 0x0b
144 #ifdef __50SERIES /* Prime/PRIMOS */
145 # define OS_CODE 0x0f
148 #if defined(_BEOS_) || defined(RISCOS)
149 # define fdopen(fd,mode) NULL /* No fdopen() */
152 #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
153 # if defined(_WIN32_WCE)
154 # define fdopen(fd,mode) NULL /* No fdopen() */
155 # ifndef _PTRDIFF_T_DEFINED
156 typedef int ptrdiff_t;
157 # define _PTRDIFF_T_DEFINED
160 # define fdopen(fd,type) _fdopen(fd,type)
164 #if defined(__BORLANDC__)
170 #ifdef _LARGEFILE64_SOURCE
171 # define z_off64_t off64_t
173 # define z_off64_t z_off_t
176 /* common defaults */
179 # define OS_CODE 0x03 /* assume Unix */
183 # define F_OPEN(name, mode) fopen((name), (mode))
186 #ifdef _LARGEFILE64_SOURCE
187 # define F_OPEN64(name, mode) fopen64((name), (mode))
189 # define F_OPEN64(name, mode) fopen((name), (mode))
194 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
195 # ifndef HAVE_VSNPRINTF
196 # define HAVE_VSNPRINTF
199 #if defined(__CYGWIN__)
200 # ifndef HAVE_VSNPRINTF
201 # define HAVE_VSNPRINTF
204 #ifndef HAVE_VSNPRINTF
206 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
207 but for now we just assume it doesn't. */
208 # define NO_vsnprintf
211 # define NO_vsnprintf
214 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
215 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
216 # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
217 # define vsnprintf _vsnprintf
222 # define NO_vsnprintf
226 # define NO_vsnprintf
232 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
233 /* Use our own functions for small and medium model with MSC <= 5.0.
234 * You may have to use the same strategy for Borland C (untested).
235 * The __SC__ check is for Symantec.
239 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
243 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
244 # define zmemcpy _fmemcpy
245 # define zmemcmp _fmemcmp
246 # define zmemzero(dest, len) _fmemset(dest, 0, len)
248 # define zmemcpy memcpy
249 # define zmemcmp memcmp
250 # define zmemzero(dest, len) memset(dest, 0, len)
253 extern void zmemcpy
OF((Bytef
* dest
, const Bytef
* source
, uInt len
));
254 extern int zmemcmp
OF((const Bytef
* s1
, const Bytef
* s2
, uInt len
));
255 extern void zmemzero
OF((Bytef
* dest
, uInt len
));
258 /* Diagnostic functions */
261 extern int z_verbose
;
262 extern void z_error
OF((char *m
));
263 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
264 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
265 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
266 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
267 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
268 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
270 # define Assert(cond,msg)
275 # define Tracecv(c,x)
279 voidpf zcalloc
OF((voidpf opaque
, uInt items
, uInt size
));
280 void zcfree
OF((voidpf opaque
, voidpf ptr
));
282 #define ZALLOC(strm, items, size) \
283 (*((strm)->zalloc))((strm)->opaque, (items), (size))
284 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
285 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}