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