1 /* zutil.h -- internal interface and configuration of the compression library
\r
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
\r
3 * For conditions of distribution and use, see copyright notice in zlib.h
\r
6 /* WARNING: this file should *not* be used by applications. It is
\r
7 part of the implementation of the compression library and is
\r
8 subject to change. Applications should only use zlib.h.
\r
16 #define ZLIB_INTERNAL
\r
21 # include <stddef.h>
\r
23 # include <string.h>
\r
24 # include <stdlib.h>
\r
28 /* The Microsoft C Run-Time Library for Windows CE doesn't have
\r
29 * errno. We define it as a global variable to simplify porting.
\r
30 * Its value is always 0 and should not be used. We rename it to
\r
31 * avoid conflict with other libraries that use the same workaround.
\r
33 # define errno z_errno
\r
43 # define local static
\r
45 /* compile with -Dlocal if your debugger can't find static symbols */
\r
47 typedef unsigned char uch;
\r
48 typedef uch FAR uchf;
\r
49 typedef unsigned short ush;
\r
50 typedef ush FAR ushf;
\r
51 typedef unsigned long ulg;
\r
53 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
\r
54 /* (size given to avoid silly warnings with Visual C++) */
\r
56 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
\r
58 #define ERR_RETURN(strm,err) \
\r
59 return (strm->msg = (char*)ERR_MSG(err), (err))
\r
60 /* To be used only when the state is known to be valid */
\r
62 /* common constants */
\r
65 # define DEF_WBITS MAX_WBITS
\r
67 /* default windowBits for decompression. MAX_WBITS is for compression only */
\r
69 #if MAX_MEM_LEVEL >= 8
\r
70 # define DEF_MEM_LEVEL 8
\r
72 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
\r
74 /* default memLevel */
\r
76 #define STORED_BLOCK 0
\r
77 #define STATIC_TREES 1
\r
79 /* The three kinds of block type */
\r
82 #define MAX_MATCH 258
\r
83 /* The minimum and maximum match lengths */
\r
85 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
\r
87 /* target dependencies */
\r
89 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
\r
90 # define OS_CODE 0x00
\r
91 # if defined(__TURBOC__) || defined(__BORLANDC__)
\r
92 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
\r
93 /* Allow compilation with ANSI keywords only enabled */
\r
94 void _Cdecl farfree( void *block );
\r
95 void *_Cdecl farmalloc( unsigned long nbytes );
\r
99 # else /* MSC or DJGPP */
\r
100 # include <malloc.h>
\r
105 # define OS_CODE 0x01
\r
108 #if defined(VAXC) || defined(VMS)
\r
109 # define OS_CODE 0x02
\r
110 # define F_OPEN(name, mode) \
\r
111 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
\r
114 #if defined(ATARI) || defined(atarist)
\r
115 # define OS_CODE 0x05
\r
119 # define OS_CODE 0x06
\r
121 #include <malloc.h>
\r
125 #if defined(MACOS) || defined(TARGET_OS_MAC)
\r
126 # define OS_CODE 0x07
\r
127 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
\r
128 # include <unix.h> /* for fdopen */
\r
131 # define fdopen(fd,mode) NULL /* No fdopen() */
\r
137 # define OS_CODE 0x0a
\r
141 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
\r
142 # define OS_CODE 0x0b
\r
146 #ifdef __50SERIES /* Prime/PRIMOS */
\r
147 # define OS_CODE 0x0f
\r
150 #if defined(_BEOS_) || defined(RISCOS)
\r
151 # define fdopen(fd,mode) NULL /* No fdopen() */
\r
154 #if (defined(_MSC_VER) && (_MSC_VER > 600))
\r
155 # if defined(_WIN32_WCE)
\r
156 # define fdopen(fd,mode) NULL /* No fdopen() */
\r
157 # ifndef _PTRDIFF_T_DEFINED
\r
158 typedef int ptrdiff_t;
\r
159 # define _PTRDIFF_T_DEFINED
\r
162 # define fdopen(fd,type) _fdopen(fd,type)
\r
166 /* common defaults */
\r
169 # define OS_CODE 0x03 /* assume Unix */
\r
173 # define F_OPEN(name, mode) fopen((name), (mode))
\r
178 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
\r
179 # ifndef HAVE_VSNPRINTF
\r
180 # define HAVE_VSNPRINTF
\r
183 #if defined(__CYGWIN__)
\r
184 # ifndef HAVE_VSNPRINTF
\r
185 # define HAVE_VSNPRINTF
\r
188 #ifndef HAVE_VSNPRINTF
\r
190 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
\r
191 but for now we just assume it doesn't. */
\r
192 # define NO_vsnprintf
\r
195 # define NO_vsnprintf
\r
198 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
\r
199 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
\r
200 # define vsnprintf _vsnprintf
\r
204 # define NO_vsnprintf
\r
208 # define NO_vsnprintf
\r
214 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
\r
215 /* Use our own functions for small and medium model with MSC <= 5.0.
\r
216 * You may have to use the same strategy for Borland C (untested).
\r
217 * The __SC__ check is for Symantec.
\r
221 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
\r
222 # define HAVE_MEMCPY
\r
225 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
\r
226 # define zmemcpy _fmemcpy
\r
227 # define zmemcmp _fmemcmp
\r
228 # define zmemzero(dest, len) _fmemset(dest, 0, len)
\r
230 # define zmemcpy memcpy
\r
231 # define zmemcmp memcmp
\r
232 # define zmemzero(dest, len) memset(dest, 0, len)
\r
235 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
\r
236 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
\r
237 extern void zmemzero OF((Bytef* dest, uInt len));
\r
240 /* Diagnostic functions */
\r
242 # include <stdio.h>
\r
243 extern int z_verbose;
\r
244 extern void z_error OF((char *m));
\r
245 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
\r
246 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
\r
247 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
\r
248 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
\r
249 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
\r
250 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
\r
252 # define Assert(cond,msg)
\r
255 # define Tracevv(x)
\r
256 # define Tracec(c,x)
\r
257 # define Tracecv(c,x)
\r
261 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
\r
262 void zcfree OF((voidpf opaque, voidpf ptr));
\r
264 #define ZALLOC(strm, items, size) \
\r
265 (*((strm)->zalloc))((strm)->opaque, (items), (size))
\r
266 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
\r
267 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
\r
269 #endif /* ZUTIL_H */
\r