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