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