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