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