]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/net/zutil.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / net / 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 <net/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 memcpy(d, s, n)       bcopy((s), (d), (n))
36 #  define memset(d, v, n)       bzero((d), (n))
37 #  define memcmp                bcmp
38
39 #else
40 #if defined(__KERNEL__)
41 /* Assume this is a Linux kernel */
42 #include <linux/string.h>
43 #define HAVE_MEMCPY
44
45 #else /* not kernel */
46
47 #if defined(MSDOS)||defined(VMS)||defined(CRAY)||defined(WIN32)||defined(RISCOS)
48 #   include <stddef.h>
49 #   include <errno.h>
50 #else
51     extern int errno;
52 #endif
53 #ifdef STDC
54 #  include <string.h>
55 #  include <stdlib.h>
56 #endif
57 #endif /* __KERNEL__ */
58 #endif /* _KERNEL */
59
60 #ifndef local
61 #  define local static
62 #endif
63 /* compile with -Dlocal if your debugger can't find static symbols */
64
65 typedef unsigned char  uch;
66 typedef uch FAR uchf;
67 typedef unsigned short ush;
68 typedef ush FAR ushf;
69 typedef unsigned long  ulg;
70
71 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
72
73 #define ERR_RETURN(strm,err) \
74   return (strm->msg = (const char*)ERR_MSG(err), (err))
75 /* To be used only when the state is known to be valid */
76
77         /* common constants */
78
79 #ifndef DEF_WBITS
80 #  define DEF_WBITS MAX_WBITS
81 #endif
82 /* default windowBits for decompression. MAX_WBITS is for compression only */
83
84 #if MAX_MEM_LEVEL >= 8
85 #  define DEF_MEM_LEVEL 8
86 #else
87 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
88 #endif
89 /* default memLevel */
90
91 #define STORED_BLOCK 0
92 #define STATIC_TREES 1
93 #define DYN_TREES    2
94 /* The three kinds of block type */
95
96 #define MIN_MATCH  3
97 #define MAX_MATCH  258
98 /* The minimum and maximum match lengths */
99
100 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
101
102         /* target dependencies */
103
104 #ifdef MSDOS
105 #  define OS_CODE  0x00
106 #  ifdef __TURBOC__
107 #    include <alloc.h>
108 #  else /* MSC or DJGPP */
109 #    include <malloc.h>
110 #  endif
111 #endif
112
113 #ifdef OS2
114 #  define OS_CODE  0x06
115 #endif
116
117 #ifdef WIN32 /* Window 95 & Windows NT */
118 #  define OS_CODE  0x0b
119 #endif
120
121 #if defined(VAXC) || defined(VMS)
122 #  define OS_CODE  0x02
123 #  define FOPEN(name, mode) \
124      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
125 #endif
126
127 #ifdef AMIGA
128 #  define OS_CODE  0x01
129 #endif
130
131 #if defined(ATARI) || defined(atarist)
132 #  define OS_CODE  0x05
133 #endif
134
135 #ifdef MACOS
136 #  define OS_CODE  0x07
137 #endif
138
139 #ifdef __50SERIES /* Prime/PRIMOS */
140 #  define OS_CODE  0x0F
141 #endif
142
143 #ifdef TOPS20
144 #  define OS_CODE  0x0a
145 #endif
146
147 #if defined(_BEOS_) || defined(RISCOS)
148 #  define fdopen(fd,mode) NULL /* No fdopen() */
149 #endif
150
151         /* Common defaults */
152
153 #ifndef OS_CODE
154 #  define OS_CODE  0x03  /* assume Unix */
155 #endif
156
157 #ifndef FOPEN
158 #  define FOPEN(name, mode) fopen((name), (mode))
159 #endif
160
161          /* functions */
162
163 #ifdef HAVE_STRERROR
164    extern char *strerror OF((int));
165 #  define zstrerror(errnum) strerror(errnum)
166 #else
167 #  define zstrerror(errnum) ""
168 #endif
169
170 #if defined(pyr)
171 #  define NO_MEMCPY
172 #endif
173 #if (defined(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER)
174  /* Use our own functions for small and medium model with MSC <= 5.0.
175   * You may have to use the same strategy for Borland C (untested).
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  OF((Bytef* dest, Bytef* source, uInt len));
194    extern int  zmemcmp  OF((Bytef* s1,   Bytef* s2, uInt len));
195    extern void zmemzero OF((Bytef* dest, uInt len));
196 #endif
197
198 /* Diagnostic functions */
199 #ifdef DEBUG_ZLIB
200 #  include <stdio.h>
201 #  ifndef verbose
202 #    define verbose 0
203 #  endif
204    extern void z_error    OF((char *m));
205 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
206 #  define Trace(x) fprintf x
207 #  define Tracev(x) {if (verbose) fprintf x ;}
208 #  define Tracevv(x) {if (verbose>1) fprintf x ;}
209 #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
210 #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
211 #else
212 #  define Assert(cond,msg)
213 #  define Trace(x)
214 #  define Tracev(x)
215 #  define Tracevv(x)
216 #  define Tracec(c,x)
217 #  define Tracecv(c,x)
218 #endif
219
220
221 typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len));
222
223 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
224 void   zcfree  OF((voidpf opaque, voidpf ptr));
225
226 #define ZALLOC(strm, items, size) \
227            (*((strm)->zalloc))((strm)->opaque, (items), (size))
228 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
229 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
230
231 #endif /* _Z_UTIL_H */