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