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