0ba6e0208770caf71698f8012bb58d98def501b8
[shibboleth/cpp-opensaml.git] / saml / zlib / zutil.h
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
4  */\r
5 \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
9  */\r
10 \r
11 /* @(#) $Id$ */\r
12 \r
13 #ifndef ZUTIL_H\r
14 #define ZUTIL_H\r
15 \r
16 #define ZLIB_INTERNAL\r
17 #include "zlib.h"\r
18 \r
19 #ifdef STDC\r
20 #  ifndef _WIN32_WCE\r
21 #    include <stddef.h>\r
22 #  endif\r
23 #  include <string.h>\r
24 #  include <stdlib.h>\r
25 #endif\r
26 #ifdef NO_ERRNO_H\r
27 #   ifdef _WIN32_WCE\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
32        */\r
33 #     define errno z_errno\r
34 #   endif\r
35     extern int errno;\r
36 #else\r
37 #  ifndef _WIN32_WCE\r
38 #    include <errno.h>\r
39 #  endif\r
40 #endif\r
41 \r
42 #ifndef local\r
43 #  define local static\r
44 #endif\r
45 /* compile with -Dlocal if your debugger can't find static symbols */\r
46 \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
52 \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
55 \r
56 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]\r
57 \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
61 \r
62         /* common constants */\r
63 \r
64 #ifndef DEF_WBITS\r
65 #  define DEF_WBITS MAX_WBITS\r
66 #endif\r
67 /* default windowBits for decompression. MAX_WBITS is for compression only */\r
68 \r
69 #if MAX_MEM_LEVEL >= 8\r
70 #  define DEF_MEM_LEVEL 8\r
71 #else\r
72 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL\r
73 #endif\r
74 /* default memLevel */\r
75 \r
76 #define STORED_BLOCK 0\r
77 #define STATIC_TREES 1\r
78 #define DYN_TREES    2\r
79 /* The three kinds of block type */\r
80 \r
81 #define MIN_MATCH  3\r
82 #define MAX_MATCH  258\r
83 /* The minimum and maximum match lengths */\r
84 \r
85 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */\r
86 \r
87         /* target dependencies */\r
88 \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
96 #    else\r
97 #      include <alloc.h>\r
98 #    endif\r
99 #  else /* MSC or DJGPP */\r
100 #    include <malloc.h>\r
101 #  endif\r
102 #endif\r
103 \r
104 #ifdef AMIGA\r
105 #  define OS_CODE  0x01\r
106 #endif\r
107 \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
112 #endif\r
113 \r
114 #if defined(ATARI) || defined(atarist)\r
115 #  define OS_CODE  0x05\r
116 #endif\r
117 \r
118 #ifdef OS2\r
119 #  define OS_CODE  0x06\r
120 #  ifdef M_I86\r
121      #include <malloc.h>\r
122 #  endif\r
123 #endif\r
124 \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
129 #  else\r
130 #    ifndef fdopen\r
131 #      define fdopen(fd,mode) NULL /* No fdopen() */\r
132 #    endif\r
133 #  endif\r
134 #endif\r
135 \r
136 #ifdef TOPS20\r
137 #  define OS_CODE  0x0a\r
138 #endif\r
139 \r
140 #ifdef WIN32\r
141 #  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */\r
142 #    define OS_CODE  0x0b\r
143 #  endif\r
144 #endif\r
145 \r
146 #ifdef __50SERIES /* Prime/PRIMOS */\r
147 #  define OS_CODE  0x0f\r
148 #endif\r
149 \r
150 #if defined(_BEOS_) || defined(RISCOS)\r
151 #  define fdopen(fd,mode) NULL /* No fdopen() */\r
152 #endif\r
153 \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
160 #    endif\r
161 #  else\r
162 #    define fdopen(fd,type)  _fdopen(fd,type)\r
163 #  endif\r
164 #endif\r
165 \r
166         /* common defaults */\r
167 \r
168 #ifndef OS_CODE\r
169 #  define OS_CODE  0x03  /* assume Unix */\r
170 #endif\r
171 \r
172 #ifndef F_OPEN\r
173 #  define F_OPEN(name, mode) fopen((name), (mode))\r
174 #endif\r
175 \r
176          /* functions */\r
177 \r
178 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)\r
179 #  ifndef HAVE_VSNPRINTF\r
180 #    define HAVE_VSNPRINTF\r
181 #  endif\r
182 #endif\r
183 #if defined(__CYGWIN__)\r
184 #  ifndef HAVE_VSNPRINTF\r
185 #    define HAVE_VSNPRINTF\r
186 #  endif\r
187 #endif\r
188 #ifndef HAVE_VSNPRINTF\r
189 #  ifdef MSDOS\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
193 #  endif\r
194 #  ifdef __TURBOC__\r
195 #    define NO_vsnprintf\r
196 #  endif\r
197 #  ifdef WIN32\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
201 #    endif\r
202 #  endif\r
203 #  ifdef __SASC\r
204 #    define NO_vsnprintf\r
205 #  endif\r
206 #endif\r
207 #ifdef VMS\r
208 #  define NO_vsnprintf\r
209 #endif\r
210 \r
211 #if defined(pyr)\r
212 #  define NO_MEMCPY\r
213 #endif\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
218   */\r
219 #  define NO_MEMCPY\r
220 #endif\r
221 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)\r
222 #  define HAVE_MEMCPY\r
223 #endif\r
224 #ifdef 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
229 #  else\r
230 #    define zmemcpy memcpy\r
231 #    define zmemcmp memcmp\r
232 #    define zmemzero(dest, len) memset(dest, 0, len)\r
233 #  endif\r
234 #else\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
238 #endif\r
239 \r
240 /* Diagnostic functions */\r
241 #ifdef DEBUG\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
251 #else\r
252 #  define Assert(cond,msg)\r
253 #  define Trace(x)\r
254 #  define Tracev(x)\r
255 #  define Tracevv(x)\r
256 #  define Tracec(c,x)\r
257 #  define Tracecv(c,x)\r
258 #endif\r
259 \r
260 \r
261 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));\r
262 void   zcfree  OF((voidpf opaque, voidpf ptr));\r
263 \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
268 \r
269 #endif /* ZUTIL_H */\r