]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/zutil.h
Upgrade Unbound to 1.6.8. More to follow.
[FreeBSD/FreeBSD.git] / sys / sys / zutil.h
1 /* zutil.h -- internal interface and configuration of the compression library
2  * Copyright (C) 1995-1996 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 /* From: zutil.h,v 1.16 1996/07/24 13:41:13 me Exp $ */
12 /* $FreeBSD$ */
13
14 #ifndef _Z_UTIL_H
15 #define _Z_UTIL_H
16
17 #define ZEXPORT
18
19 #ifdef _KERNEL
20 #include <sys/zlib.h>
21 #else
22 #include "zlib.h"
23 #endif
24
25 #ifdef _KERNEL
26 /* Assume this is a *BSD or SVR4 kernel */
27 #include <sys/types.h>
28 #include <sys/time.h>
29 #include <sys/systm.h>
30 #include <sys/module.h>
31 #include <sys/errno.h>
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #  define HAVE_MEMCPY
35 #  define memset(d, v, n)       bzero((d), (n))
36 #  define memcmp                bcmp
37
38 #else
39 #if defined(__KERNEL__)
40 /* Assume this is a Linux kernel */
41 #include <linux/string.h>
42 #define HAVE_MEMCPY
43
44 #else /* not kernel */
45
46 #if defined(MSDOS)||defined(VMS)||defined(CRAY)||defined(WIN32)||defined(RISCOS)
47 #   include <stddef.h>
48 #   include <errno.h>
49 #else
50     extern int errno;
51 #endif
52 #ifdef STDC
53 #  include <string.h>
54 #  include <stdlib.h>
55 #endif
56 #endif /* __KERNEL__ */
57 #endif /* _KERNEL */
58
59 #ifndef local
60 #  define local static
61 #endif
62 /* compile with -Dlocal if your debugger can't find static symbols */
63
64 typedef unsigned char  uch;
65 typedef uch FAR uchf;
66 typedef unsigned short ush;
67 typedef ush FAR ushf;
68 typedef unsigned long  ulg;
69
70 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
71
72 #define ERR_RETURN(strm,err) \
73   return (strm->msg = (const char*)ERR_MSG(err), (err))
74 /* To be used only when the state is known to be valid */
75
76         /* common constants */
77
78 #ifndef DEF_WBITS
79 #  define DEF_WBITS MAX_WBITS
80 #endif
81 /* default windowBits for decompression. MAX_WBITS is for compression only */
82
83 #if MAX_MEM_LEVEL >= 8
84 #  define DEF_MEM_LEVEL 8
85 #else
86 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
87 #endif
88 /* default memLevel */
89
90 #define STORED_BLOCK 0
91 #define STATIC_TREES 1
92 #define DYN_TREES    2
93 /* The three kinds of block type */
94
95 #define MIN_MATCH  3
96 #define MAX_MATCH  258
97 /* The minimum and maximum match lengths */
98
99 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
100
101         /* target dependencies */
102
103 #ifdef MSDOS
104 #  define OS_CODE  0x00
105 #  ifdef __TURBOC__
106 #    include <alloc.h>
107 #  else /* MSC or DJGPP */
108 #    include <malloc.h>
109 #  endif
110 #endif
111
112 #ifdef OS2
113 #  define OS_CODE  0x06
114 #endif
115
116 #ifdef WIN32 /* Window 95 & Windows NT */
117 #  define OS_CODE  0x0b
118 #endif
119
120 #if defined(VAXC) || defined(VMS)
121 #  define OS_CODE  0x02
122 #  define FOPEN(name, mode) \
123      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
124 #endif
125
126 #ifdef AMIGA
127 #  define OS_CODE  0x01
128 #endif
129
130 #if defined(ATARI) || defined(atarist)
131 #  define OS_CODE  0x05
132 #endif
133
134 #ifdef MACOS
135 #  define OS_CODE  0x07
136 #endif
137
138 #ifdef __50SERIES /* Prime/PRIMOS */
139 #  define OS_CODE  0x0F
140 #endif
141
142 #ifdef TOPS20
143 #  define OS_CODE  0x0a
144 #endif
145
146 #if defined(_BEOS_) || defined(RISCOS)
147 #  define fdopen(fd,mode) NULL /* No fdopen() */
148 #endif
149
150         /* Common defaults */
151
152 #ifndef OS_CODE
153 #  define OS_CODE  0x03  /* assume Unix */
154 #endif
155
156 #ifndef FOPEN
157 #  define FOPEN(name, mode) fopen((name), (mode))
158 #endif
159
160          /* functions */
161
162 #ifdef HAVE_STRERROR
163    extern char *strerror OF((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(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER)
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   */
176 #  define NO_MEMCPY
177 #endif
178 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
179 #  define HAVE_MEMCPY
180 #endif
181 #ifdef HAVE_MEMCPY
182 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
183 #    define zmemcpy _fmemcpy
184 #    define zmemcmp _fmemcmp
185 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
186 #  else
187 #    define zmemcpy memcpy
188 #    define zmemcmp memcmp
189 #    define zmemzero(dest, len) memset(dest, 0, len)
190 #  endif
191 #else
192    extern void zmemcpy  OF((Bytef* dest, Bytef* source, uInt len));
193    extern int  zmemcmp  OF((Bytef* s1,   Bytef* s2, uInt len));
194    extern void zmemzero OF((Bytef* dest, uInt len));
195 #endif
196
197 /* Diagnostic functions */
198 #ifdef DEBUG_ZLIB
199 #  include <stdio.h>
200 #  ifndef verbose
201 #    define verbose 0
202 #  endif
203    extern void z_error    OF((char *m));
204 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
205 #  define Trace(x) fprintf x
206 #  define Tracev(x) {if (verbose) fprintf x ;}
207 #  define Tracevv(x) {if (verbose>1) fprintf x ;}
208 #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
209 #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
210 #else
211 #  define Assert(cond,msg)
212 #  define Trace(x)
213 #  define Tracev(x)
214 #  define Tracevv(x)
215 #  define Tracec(c,x)
216 #  define Tracecv(c,x)
217 #endif
218
219
220 typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len));
221
222 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
223 void   zcfree  OF((voidpf opaque, voidpf ptr));
224
225 #define ZALLOC(strm, items, size) \
226            (*((strm)->zalloc))((strm)->opaque, (items), (size))
227 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
228 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
229
230 #endif /* _Z_UTIL_H */