ef3b388ef7de83498fef5fe2dca733ba405d9b5e
[platform/upstream/libwebsockets.git] / win32port / zlib / zutil.h
1 /* zutil.h -- internal interface and configuration of the compression library\r
2  * Copyright (C) 1995-2010 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 #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) && !defined(_WIN32)\r
17 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))\r
18 #else\r
19 #  define ZLIB_INTERNAL\r
20 #endif\r
21 \r
22 #include "zlib.h"\r
23 \r
24 #ifdef STDC\r
25 #  if !(defined(_WIN32_WCE) && defined(_MSC_VER))\r
26 #    include <stddef.h>\r
27 #  endif\r
28 #  include <string.h>\r
29 #  include <stdlib.h>\r
30 #endif\r
31 \r
32 #ifndef local\r
33 #  define local static\r
34 #endif\r
35 /* compile with -Dlocal if your debugger can't find static symbols */\r
36 \r
37 typedef unsigned char  uch;\r
38 typedef uch FAR uchf;\r
39 typedef unsigned short ush;\r
40 typedef ush FAR ushf;\r
41 typedef unsigned long  ulg;\r
42 \r
43 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */\r
44 /* (size given to avoid silly warnings with Visual C++) */\r
45 \r
46 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]\r
47 \r
48 #define ERR_RETURN(strm,err) \\r
49   return (strm->msg = (char*)ERR_MSG(err), (err))\r
50 /* To be used only when the state is known to be valid */\r
51 \r
52         /* common constants */\r
53 \r
54 #ifndef DEF_WBITS\r
55 #  define DEF_WBITS MAX_WBITS\r
56 #endif\r
57 /* default windowBits for decompression. MAX_WBITS is for compression only */\r
58 \r
59 #if MAX_MEM_LEVEL >= 8\r
60 #  define DEF_MEM_LEVEL 8\r
61 #else\r
62 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL\r
63 #endif\r
64 /* default memLevel */\r
65 \r
66 #define STORED_BLOCK 0\r
67 #define STATIC_TREES 1\r
68 #define DYN_TREES    2\r
69 /* The three kinds of block type */\r
70 \r
71 #define MIN_MATCH  3\r
72 #define MAX_MATCH  258\r
73 /* The minimum and maximum match lengths */\r
74 \r
75 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */\r
76 \r
77         /* target dependencies */\r
78 \r
79 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))\r
80 #  define OS_CODE  0x00\r
81 #  if defined(__TURBOC__) || defined(__BORLANDC__)\r
82 #    if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))\r
83        /* Allow compilation with ANSI keywords only enabled */\r
84        void _Cdecl farfree( void *block );\r
85        void *_Cdecl farmalloc( unsigned long nbytes );\r
86 #    else\r
87 #      include <alloc.h>\r
88 #    endif\r
89 #  else /* MSC or DJGPP */\r
90 #    include <malloc.h>\r
91 #  endif\r
92 #endif\r
93 \r
94 #ifdef AMIGA\r
95 #  define OS_CODE  0x01\r
96 #endif\r
97 \r
98 #if defined(VAXC) || defined(VMS)\r
99 #  define OS_CODE  0x02\r
100 #  define F_OPEN(name, mode) \\r
101      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")\r
102 #endif\r
103 \r
104 #if defined(ATARI) || defined(atarist)\r
105 #  define OS_CODE  0x05\r
106 #endif\r
107 \r
108 #ifdef OS2\r
109 #  define OS_CODE  0x06\r
110 #  ifdef M_I86\r
111 #    include <malloc.h>\r
112 #  endif\r
113 #endif\r
114 \r
115 #if defined(MACOS) || defined(TARGET_OS_MAC)\r
116 #  define OS_CODE  0x07\r
117 #  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os\r
118 #    include <unix.h> /* for fdopen */\r
119 #  else\r
120 #    ifndef fdopen\r
121 #      define fdopen(fd,mode) NULL /* No fdopen() */\r
122 #    endif\r
123 #  endif\r
124 #endif\r
125 \r
126 #ifdef TOPS20\r
127 #  define OS_CODE  0x0a\r
128 #endif\r
129 \r
130 #ifdef WIN32\r
131 #  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */\r
132 #    define OS_CODE  0x0b\r
133 #  endif\r
134 #endif\r
135 \r
136 #ifdef __50SERIES /* Prime/PRIMOS */\r
137 #  define OS_CODE  0x0f\r
138 #endif\r
139 \r
140 #if defined(_BEOS_) || defined(RISCOS)\r
141 #  define fdopen(fd,mode) NULL /* No fdopen() */\r
142 #endif\r
143 \r
144 #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX\r
145 #  if defined(_WIN32_WCE)\r
146 #    define fdopen(fd,mode) NULL /* No fdopen() */\r
147 #    ifndef _PTRDIFF_T_DEFINED\r
148        typedef int ptrdiff_t;\r
149 #      define _PTRDIFF_T_DEFINED\r
150 #    endif\r
151 #  else\r
152 #    define fdopen(fd,type)  _fdopen(fd,type)\r
153 #  endif\r
154 #endif\r
155 \r
156 #if defined(__BORLANDC__)\r
157   #pragma warn -8004\r
158   #pragma warn -8008\r
159   #pragma warn -8066\r
160 #endif\r
161 \r
162 /* provide prototypes for these when building zlib without LFS */\r
163 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0\r
164     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));\r
165     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));\r
166 #endif\r
167 \r
168         /* common defaults */\r
169 \r
170 #ifndef OS_CODE\r
171 #  define OS_CODE  0x03  /* assume Unix */\r
172 #endif\r
173 \r
174 #ifndef F_OPEN\r
175 #  define F_OPEN(name, mode) fopen((name), (mode))\r
176 #endif\r
177 \r
178          /* functions */\r
179 \r
180 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)\r
181 #  ifndef HAVE_VSNPRINTF\r
182 #    define HAVE_VSNPRINTF\r
183 #  endif\r
184 #endif\r
185 #if defined(__CYGWIN__)\r
186 #  ifndef HAVE_VSNPRINTF\r
187 #    define HAVE_VSNPRINTF\r
188 #  endif\r
189 #endif\r
190 #ifndef HAVE_VSNPRINTF\r
191 #  ifdef MSDOS\r
192      /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),\r
193         but for now we just assume it doesn't. */\r
194 #    define NO_vsnprintf\r
195 #  endif\r
196 #  ifdef __TURBOC__\r
197 #    define NO_vsnprintf\r
198 #  endif\r
199 #  ifdef WIN32\r
200      /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */\r
201 #    if !defined(vsnprintf) && !defined(NO_vsnprintf)\r
202 #      if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )\r
203 #         define vsnprintf _vsnprintf\r
204 #      endif\r
205 #    endif\r
206 #  endif\r
207 #  ifdef __SASC\r
208 #    define NO_vsnprintf\r
209 #  endif\r
210 #endif\r
211 #ifdef VMS\r
212 #  define NO_vsnprintf\r
213 #endif\r
214 \r
215 #if defined(pyr)\r
216 #  define NO_MEMCPY\r
217 #endif\r
218 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)\r
219  /* Use our own functions for small and medium model with MSC <= 5.0.\r
220   * You may have to use the same strategy for Borland C (untested).\r
221   * The __SC__ check is for Symantec.\r
222   */\r
223 #  define NO_MEMCPY\r
224 #endif\r
225 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)\r
226 #  define HAVE_MEMCPY\r
227 #endif\r
228 #ifdef HAVE_MEMCPY\r
229 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */\r
230 #    define zmemcpy _fmemcpy\r
231 #    define zmemcmp _fmemcmp\r
232 #    define zmemzero(dest, len) _fmemset(dest, 0, len)\r
233 #  else\r
234 #    define zmemcpy memcpy\r
235 #    define zmemcmp memcmp\r
236 #    define zmemzero(dest, len) memset(dest, 0, len)\r
237 #  endif\r
238 #else\r
239    void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));\r
240    int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));\r
241    void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));\r
242 #endif\r
243 \r
244 /* Diagnostic functions */\r
245 #ifdef DEBUG\r
246 #  include <stdio.h>\r
247    extern int ZLIB_INTERNAL z_verbose;\r
248    extern void ZLIB_INTERNAL z_error OF((char *m));\r
249 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}\r
250 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}\r
251 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}\r
252 #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}\r
253 #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}\r
254 #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}\r
255 #else\r
256 #  define Assert(cond,msg)\r
257 #  define Trace(x)\r
258 #  define Tracev(x)\r
259 #  define Tracevv(x)\r
260 #  define Tracec(c,x)\r
261 #  define Tracecv(c,x)\r
262 #endif\r
263 \r
264 \r
265 voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,\r
266                         unsigned size));\r
267 void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));\r
268 \r
269 #define ZALLOC(strm, items, size) \\r
270            (*((strm)->zalloc))((strm)->opaque, (items), (size))\r
271 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))\r
272 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}\r
273 \r
274 #endif /* ZUTIL_H */\r