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