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