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