1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 * |
|
4 * This code is free software; you can redistribute it and/or modify it |
|
5 * under the terms of the GNU General Public License version 2 only, as |
|
6 * published by the Free Software Foundation. Oracle designates this |
|
7 * particular file as subject to the "Classpath" exception as provided |
|
8 * by Oracle in the LICENSE file that accompanied this code. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 */ |
|
24 |
|
25 /* zutil.h -- internal interface and configuration of the compression library |
|
26 * Copyright (C) 1995-2005 Jean-loup Gailly. |
|
27 * For conditions of distribution and use, see copyright notice in zlib.h |
|
28 */ |
|
29 |
|
30 /* WARNING: this file should *not* be used by applications. It is |
|
31 part of the implementation of the compression library and is |
|
32 subject to change. Applications should only use zlib.h. |
|
33 */ |
|
34 |
|
35 /* @(#) $Id$ */ |
|
36 |
|
37 #ifndef ZUTIL_H |
|
38 #define ZUTIL_H |
|
39 |
|
40 #define ZLIB_INTERNAL |
|
41 #include "zlib.h" |
|
42 |
|
43 #ifdef STDC |
|
44 # ifndef _WIN32_WCE |
|
45 # include <stddef.h> |
|
46 # endif |
|
47 # include <string.h> |
|
48 # include <stdlib.h> |
|
49 #endif |
|
50 #ifdef NO_ERRNO_H |
|
51 # ifdef _WIN32_WCE |
|
52 /* The Microsoft C Run-Time Library for Windows CE doesn't have |
|
53 * errno. We define it as a global variable to simplify porting. |
|
54 * Its value is always 0 and should not be used. We rename it to |
|
55 * avoid conflict with other libraries that use the same workaround. |
|
56 */ |
|
57 # define errno z_errno |
|
58 # endif |
|
59 extern int errno; |
|
60 #else |
|
61 # ifndef _WIN32_WCE |
|
62 # include <errno.h> |
|
63 # endif |
|
64 #endif |
|
65 |
|
66 #ifndef local |
|
67 # define local static |
|
68 #endif |
|
69 /* compile with -Dlocal if your debugger can't find static symbols */ |
|
70 |
|
71 typedef unsigned char uch; |
|
72 typedef uch FAR uchf; |
|
73 typedef unsigned short ush; |
|
74 typedef ush FAR ushf; |
|
75 typedef unsigned long ulg; |
|
76 |
|
77 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ |
|
78 /* (size given to avoid silly warnings with Visual C++) */ |
|
79 |
|
80 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] |
|
81 |
|
82 #define ERR_RETURN(strm,err) \ |
|
83 return (strm->msg = (char*)ERR_MSG(err), (err)) |
|
84 /* To be used only when the state is known to be valid */ |
|
85 |
|
86 /* common constants */ |
|
87 |
|
88 #ifndef DEF_WBITS |
|
89 # define DEF_WBITS MAX_WBITS |
|
90 #endif |
|
91 /* default windowBits for decompression. MAX_WBITS is for compression only */ |
|
92 |
|
93 #if MAX_MEM_LEVEL >= 8 |
|
94 # define DEF_MEM_LEVEL 8 |
|
95 #else |
|
96 # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
|
97 #endif |
|
98 /* default memLevel */ |
|
99 |
|
100 #define STORED_BLOCK 0 |
|
101 #define STATIC_TREES 1 |
|
102 #define DYN_TREES 2 |
|
103 /* The three kinds of block type */ |
|
104 |
|
105 #define MIN_MATCH 3 |
|
106 #define MAX_MATCH 258 |
|
107 /* The minimum and maximum match lengths */ |
|
108 |
|
109 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ |
|
110 |
|
111 /* target dependencies */ |
|
112 |
|
113 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) |
|
114 # define OS_CODE 0x00 |
|
115 # if defined(__TURBOC__) || defined(__BORLANDC__) |
|
116 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) |
|
117 /* Allow compilation with ANSI keywords only enabled */ |
|
118 void _Cdecl farfree( void *block ); |
|
119 void *_Cdecl farmalloc( unsigned long nbytes ); |
|
120 # else |
|
121 # include <alloc.h> |
|
122 # endif |
|
123 # else /* MSC or DJGPP */ |
|
124 # include <malloc.h> |
|
125 # endif |
|
126 #endif |
|
127 |
|
128 #ifdef AMIGA |
|
129 # define OS_CODE 0x01 |
|
130 #endif |
|
131 |
|
132 #if defined(VAXC) || defined(VMS) |
|
133 # define OS_CODE 0x02 |
|
134 # define F_OPEN(name, mode) \ |
|
135 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") |
|
136 #endif |
|
137 |
|
138 #if defined(ATARI) || defined(atarist) |
|
139 # define OS_CODE 0x05 |
|
140 #endif |
|
141 |
|
142 #ifdef OS2 |
|
143 # define OS_CODE 0x06 |
|
144 # ifdef M_I86 |
|
145 #include <malloc.h> |
|
146 # endif |
|
147 #endif |
|
148 |
|
149 #if defined(MACOS) || defined(TARGET_OS_MAC) |
|
150 # define OS_CODE 0x07 |
|
151 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os |
|
152 # include <unix.h> /* for fdopen */ |
|
153 # else |
|
154 # ifndef fdopen |
|
155 # define fdopen(fd,mode) NULL /* No fdopen() */ |
|
156 # endif |
|
157 # endif |
|
158 #endif |
|
159 |
|
160 #ifdef TOPS20 |
|
161 # define OS_CODE 0x0a |
|
162 #endif |
|
163 |
|
164 #ifdef WIN32 |
|
165 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ |
|
166 # define OS_CODE 0x0b |
|
167 # endif |
|
168 #endif |
|
169 |
|
170 #ifdef __50SERIES /* Prime/PRIMOS */ |
|
171 # define OS_CODE 0x0f |
|
172 #endif |
|
173 |
|
174 #if defined(_BEOS_) || defined(RISCOS) |
|
175 # define fdopen(fd,mode) NULL /* No fdopen() */ |
|
176 #endif |
|
177 |
|
178 #if (defined(_MSC_VER) && (_MSC_VER > 600)) |
|
179 # if defined(_WIN32_WCE) |
|
180 # define fdopen(fd,mode) NULL /* No fdopen() */ |
|
181 # ifndef _PTRDIFF_T_DEFINED |
|
182 typedef int ptrdiff_t; |
|
183 # define _PTRDIFF_T_DEFINED |
|
184 # endif |
|
185 # else |
|
186 # define fdopen(fd,type) _fdopen(fd,type) |
|
187 # endif |
|
188 #endif |
|
189 |
|
190 /* common defaults */ |
|
191 |
|
192 #ifndef OS_CODE |
|
193 # define OS_CODE 0x03 /* assume Unix */ |
|
194 #endif |
|
195 |
|
196 #ifndef F_OPEN |
|
197 # define F_OPEN(name, mode) fopen((name), (mode)) |
|
198 #endif |
|
199 |
|
200 /* functions */ |
|
201 |
|
202 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) |
|
203 # ifndef HAVE_VSNPRINTF |
|
204 # define HAVE_VSNPRINTF |
|
205 # endif |
|
206 #endif |
|
207 #if defined(__CYGWIN__) |
|
208 # ifndef HAVE_VSNPRINTF |
|
209 # define HAVE_VSNPRINTF |
|
210 # endif |
|
211 #endif |
|
212 #ifndef HAVE_VSNPRINTF |
|
213 # ifdef MSDOS |
|
214 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), |
|
215 but for now we just assume it doesn't. */ |
|
216 # define NO_vsnprintf |
|
217 # endif |
|
218 # ifdef __TURBOC__ |
|
219 # define NO_vsnprintf |
|
220 # endif |
|
221 # ifdef WIN32 |
|
222 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ |
|
223 # if !defined(vsnprintf) && !defined(NO_vsnprintf) && (!defined(_MSC_VER) || (_MSC_VER < 1500)) |
|
224 /* Only needed before Visual Studio 2008 */ |
|
225 # define vsnprintf _vsnprintf |
|
226 # endif |
|
227 # endif |
|
228 # ifdef __SASC |
|
229 # define NO_vsnprintf |
|
230 # endif |
|
231 #endif |
|
232 #ifdef VMS |
|
233 # define NO_vsnprintf |
|
234 #endif |
|
235 |
|
236 #if defined(pyr) |
|
237 # define NO_MEMCPY |
|
238 #endif |
|
239 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) |
|
240 /* Use our own functions for small and medium model with MSC <= 5.0. |
|
241 * You may have to use the same strategy for Borland C (untested). |
|
242 * The __SC__ check is for Symantec. |
|
243 */ |
|
244 # define NO_MEMCPY |
|
245 #endif |
|
246 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) |
|
247 # define HAVE_MEMCPY |
|
248 #endif |
|
249 #ifdef HAVE_MEMCPY |
|
250 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ |
|
251 # define zmemcpy _fmemcpy |
|
252 # define zmemcmp _fmemcmp |
|
253 # define zmemzero(dest, len) _fmemset(dest, 0, len) |
|
254 # else |
|
255 # define zmemcpy memcpy |
|
256 # define zmemcmp memcmp |
|
257 # define zmemzero(dest, len) memset(dest, 0, len) |
|
258 # endif |
|
259 #else |
|
260 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); |
|
261 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); |
|
262 extern void zmemzero OF((Bytef* dest, uInt len)); |
|
263 #endif |
|
264 |
|
265 /* Diagnostic functions */ |
|
266 #ifdef DEBUG |
|
267 # include <stdio.h> |
|
268 extern int z_verbose; |
|
269 extern void z_error OF((char *m)); |
|
270 # define Assert(cond,msg) {if(!(cond)) z_error(msg);} |
|
271 # define Trace(x) {if (z_verbose>=0) fprintf x ;} |
|
272 # define Tracev(x) {if (z_verbose>0) fprintf x ;} |
|
273 # define Tracevv(x) {if (z_verbose>1) fprintf x ;} |
|
274 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} |
|
275 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} |
|
276 #else |
|
277 # define Assert(cond,msg) |
|
278 # define Trace(x) |
|
279 # define Tracev(x) |
|
280 # define Tracevv(x) |
|
281 # define Tracec(c,x) |
|
282 # define Tracecv(c,x) |
|
283 #endif |
|
284 |
|
285 |
|
286 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); |
|
287 void zcfree OF((voidpf opaque, voidpf ptr)); |
|
288 |
|
289 #define ZALLOC(strm, items, size) \ |
|
290 (*((strm)->zalloc))((strm)->opaque, (items), (size)) |
|
291 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) |
|
292 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} |
|
293 |
|
294 #endif /* ZUTIL_H */ |
|