Merge commit '7e934d3acc051b7ee3ef0d11571fd1225800a607'
[unleashed.git] / kernel / zmod / zutil.h
blob8bb8f06a799d6af143a42e38369a4e0a1379c646
1 /*
2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /* zutil.h -- internal interface and configuration of the compression library
7 * Copyright (C) 1995-2005 Jean-loup Gailly.
8 * For conditions of distribution and use, see copyright notice in zlib.h
9 */
11 /* WARNING: this file should *not* be used by applications. It is
12 part of the implementation of the compression library and is
13 subject to change. Applications should only use zlib.h.
16 #ifndef _ZUTIL_H
17 #define _ZUTIL_H
19 #define ZLIB_INTERNAL
20 #include "zlib.h"
22 #ifdef STDC
23 # ifndef _WIN32_WCE
24 # include <stddef.h>
25 # endif
26 # include <string.h>
27 # include <stdlib.h>
28 #endif
29 #ifdef NO_ERRNO_H
30 # ifdef _WIN32_WCE
31 /* The Microsoft C Run-Time Library for Windows CE doesn't have
32 * errno. We define it as a global variable to simplify porting.
33 * Its value is always 0 and should not be used. We rename it to
34 * avoid conflict with other libraries that use the same workaround.
36 # define errno z_errno
37 # endif
38 extern int errno;
39 #else
40 # ifndef _WIN32_WCE
41 # include <sys/errno.h>
42 # endif
43 #endif
45 #ifndef local
46 # define local static
47 #endif
48 /* compile with -Dlocal if your debugger can't find static symbols */
50 typedef unsigned char uch;
51 typedef uch FAR uchf;
52 typedef unsigned short ush;
53 typedef ush FAR ushf;
54 typedef unsigned long ulg;
56 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
57 /* (size given to avoid silly warnings with Visual C++) */
59 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
61 #define ERR_RETURN(strm,err) \
62 return (strm->msg = (char*)ERR_MSG(err), (err))
63 /* To be used only when the state is known to be valid */
65 /* common constants */
67 #ifndef DEF_WBITS
68 # define DEF_WBITS MAX_WBITS
69 #endif
70 /* default windowBits for decompression. MAX_WBITS is for compression only */
72 #if MAX_MEM_LEVEL >= 8
73 # define DEF_MEM_LEVEL 8
74 #else
75 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
76 #endif
77 /* default memLevel */
79 #define STORED_BLOCK 0
80 #define STATIC_TREES 1
81 #define DYN_TREES 2
82 /* The three kinds of block type */
84 #define MIN_MATCH 3
85 #define MAX_MATCH 258
86 /* The minimum and maximum match lengths */
88 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
90 /* target dependencies */
92 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
93 # define OS_CODE 0x00
94 # if defined(__TURBOC__) || defined(__BORLANDC__)
95 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
96 /* Allow compilation with ANSI keywords only enabled */
97 void _Cdecl farfree( void *block );
98 void *_Cdecl farmalloc( unsigned long nbytes );
99 # else
100 # include <alloc.h>
101 # endif
102 # else /* MSC or DJGPP */
103 # include <malloc.h>
104 # endif
105 #endif
107 #ifdef AMIGA
108 # define OS_CODE 0x01
109 #endif
111 #if defined(VAXC) || defined(VMS)
112 # define OS_CODE 0x02
113 # define F_OPEN(name, mode) \
114 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
115 #endif
117 #if defined(ATARI) || defined(atarist)
118 # define OS_CODE 0x05
119 #endif
121 #ifdef OS2
122 # define OS_CODE 0x06
123 # ifdef M_I86
124 #include <malloc.h>
125 # endif
126 #endif
128 #if defined(MACOS) || defined(TARGET_OS_MAC)
129 # define OS_CODE 0x07
130 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
131 # include <unix.h> /* for fdopen */
132 # else
133 # ifndef fdopen
134 # define fdopen(fd,mode) NULL /* No fdopen() */
135 # endif
136 # endif
137 #endif
139 #ifdef TOPS20
140 # define OS_CODE 0x0a
141 #endif
143 #ifdef WIN32
144 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
145 # define OS_CODE 0x0b
146 # endif
147 #endif
149 #ifdef __50SERIES /* Prime/PRIMOS */
150 # define OS_CODE 0x0f
151 #endif
153 #if defined(_BEOS_) || defined(RISCOS)
154 # define fdopen(fd,mode) NULL /* No fdopen() */
155 #endif
157 #if (defined(_MSC_VER) && (_MSC_VER > 600))
158 # if defined(_WIN32_WCE)
159 # define fdopen(fd,mode) NULL /* No fdopen() */
160 # ifndef _PTRDIFF_T_DEFINED
161 typedef int ptrdiff_t;
162 # define _PTRDIFF_T_DEFINED
163 # endif
164 # else
165 # define fdopen(fd,type) _fdopen(fd,type)
166 # endif
167 #endif
169 /* common defaults */
171 #ifndef OS_CODE
172 # define OS_CODE 0x03 /* assume Unix */
173 #endif
175 #ifndef F_OPEN
176 # define F_OPEN(name, mode) fopen((name), (mode))
177 #endif
179 /* functions */
181 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
182 # ifndef HAVE_VSNPRINTF
183 # define HAVE_VSNPRINTF
184 # endif
185 #endif
186 #if defined(__CYGWIN__)
187 # ifndef HAVE_VSNPRINTF
188 # define HAVE_VSNPRINTF
189 # endif
190 #endif
191 #ifndef HAVE_VSNPRINTF
192 # ifdef MSDOS
193 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
194 but for now we just assume it doesn't. */
195 # define NO_vsnprintf
196 # endif
197 # ifdef __TURBOC__
198 # define NO_vsnprintf
199 # endif
200 # ifdef WIN32
201 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
202 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
203 # define vsnprintf _vsnprintf
204 # endif
205 # endif
206 # ifdef __SASC
207 # define NO_vsnprintf
208 # endif
209 #endif
210 #ifdef VMS
211 # define NO_vsnprintf
212 #endif
214 #if defined(pyr)
215 # define NO_MEMCPY
216 #endif
217 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
218 /* Use our own functions for small and medium model with MSC <= 5.0.
219 * You may have to use the same strategy for Borland C (untested).
220 * The __SC__ check is for Symantec.
222 # define NO_MEMCPY
223 #endif
224 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
225 # define HAVE_MEMCPY
226 #endif
227 #ifdef HAVE_MEMCPY
228 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
229 # define zmemcpy _fmemcpy
230 # define zmemcmp _fmemcmp
231 # define zmemzero(dest, len) _fmemset(dest, 0, len)
232 # else
233 # define zmemcpy memcpy
234 # define zmemcmp memcmp
235 # define zmemzero(dest, len) memset(dest, 0, len)
236 # endif
237 #else
238 extern void zmemcpy OF((void* dest, const void* source, uInt len));
239 extern int zmemcmp OF((const void* s1, const void* s2, uInt len));
240 extern void zmemzero OF((void* dest, uInt len));
241 #endif
243 /* Diagnostic functions */
244 #ifdef DEBUG
245 # include <stdio.h>
246 extern int z_verbose;
247 extern void z_error OF((char *m));
248 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
249 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
250 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
251 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
252 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
253 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
254 #else
255 # define Assert(cond,msg)
256 # define Trace(x)
257 # define Tracev(x)
258 # define Tracevv(x)
259 # define Tracec(c,x)
260 # define Tracecv(c,x)
261 #endif
264 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
265 void zcfree OF((voidpf opaque, voidpf ptr));
267 #define ZALLOC(strm, items, size) \
268 (*((strm)->zalloc))((strm)->opaque, (items), (size))
269 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
270 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
272 #endif /* _ZUTIL_H */