xref: /netbsd-src/external/cddl/osnet/dist/uts/common/zmod/zutil.h (revision ba2539a9805a0544ff82c0003cc02fe1eee5603d)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /* zutil.h -- internal interface and configuration of the compression library
7  * Copyright (C) 1995-2005 Jean-loup Gailly.
8  * For conditions of distribution and use, see copyright notice in zlib.h
9  */
10 
11 /* WARNING: this file should *not* be used by applications. It is
12    part of the implementation of the compression library and is
13    subject to change. Applications should only use zlib.h.
14  */
15 
16 #ifndef _ZUTIL_H
17 #define _ZUTIL_H
18 
19 #pragma ident	"%Z%%M%	%I%	%E% SMI"
20 
21 #define ZLIB_INTERNAL
22 #include "zlib.h"
23 
24 #ifdef STDC
25 #  ifndef _WIN32_WCE
26 #    include <stddef.h>
27 #  endif
28 #  include <string.h>
29 #  include <stdlib.h>
30 #endif
31 #ifdef NO_ERRNO_H
32 #   ifdef _WIN32_WCE
33       /* The Microsoft C Run-Time Library for Windows CE doesn't have
34        * errno.  We define it as a global variable to simplify porting.
35        * Its value is always 0 and should not be used.  We rename it to
36        * avoid conflict with other libraries that use the same workaround.
37        */
38 #     define errno z_errno
39 #   endif
40     extern int errno;
41 #else
42 #  ifndef _WIN32_WCE
43 #    include <sys/errno.h>
44 #  endif
45 #endif
46 
47 #ifndef local
48 #  define local static
49 #endif
50 /* compile with -Dlocal if your debugger can't find static symbols */
51 
52 typedef unsigned char  uch;
53 typedef uch FAR uchf;
54 typedef unsigned short ush;
55 typedef ush FAR ushf;
56 typedef unsigned long  ulg;
57 
58 #define z_errmsg opensolaris_z_errmsg
59 
60 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
61 /* (size given to avoid silly warnings with Visual C++) */
62 
63 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
64 
65 #define ERR_RETURN(strm,err) \
66   return (strm->msg = (char*)ERR_MSG(err), (err))
67 /* To be used only when the state is known to be valid */
68 
69         /* common constants */
70 
71 #ifndef DEF_WBITS
72 #  define DEF_WBITS MAX_WBITS
73 #endif
74 /* default windowBits for decompression. MAX_WBITS is for compression only */
75 
76 #if MAX_MEM_LEVEL >= 8
77 #  define DEF_MEM_LEVEL 8
78 #else
79 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
80 #endif
81 /* default memLevel */
82 
83 #define STORED_BLOCK 0
84 #define STATIC_TREES 1
85 #define DYN_TREES    2
86 /* The three kinds of block type */
87 
88 #define MIN_MATCH  3
89 #define MAX_MATCH  258
90 /* The minimum and maximum match lengths */
91 
92 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
93 
94         /* target dependencies */
95 
96 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
97 #  define OS_CODE  0x00
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 
111 #ifdef AMIGA
112 #  define OS_CODE  0x01
113 #endif
114 
115 #if defined(VAXC) || defined(VMS)
116 #  define OS_CODE  0x02
117 #  define F_OPEN(name, mode) \
118      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
119 #endif
120 
121 #if defined(ATARI) || defined(atarist)
122 #  define OS_CODE  0x05
123 #endif
124 
125 #ifdef OS2
126 #  define OS_CODE  0x06
127 #  ifdef M_I86
128      #include <malloc.h>
129 #  endif
130 #endif
131 
132 #if defined(MACOS) || defined(TARGET_OS_MAC)
133 #  define OS_CODE  0x07
134 #  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
135 #    include <unix.h> /* for fdopen */
136 #  else
137 #    ifndef fdopen
138 #      define fdopen(fd,mode) NULL /* No fdopen() */
139 #    endif
140 #  endif
141 #endif
142 
143 #ifdef TOPS20
144 #  define OS_CODE  0x0a
145 #endif
146 
147 #ifdef WIN32
148 #  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
149 #    define OS_CODE  0x0b
150 #  endif
151 #endif
152 
153 #ifdef __50SERIES /* Prime/PRIMOS */
154 #  define OS_CODE  0x0f
155 #endif
156 
157 #if defined(_BEOS_) || defined(RISCOS)
158 #  define fdopen(fd,mode) NULL /* No fdopen() */
159 #endif
160 
161 #if (defined(_MSC_VER) && (_MSC_VER > 600))
162 #  if defined(_WIN32_WCE)
163 #    define fdopen(fd,mode) NULL /* No fdopen() */
164 #    ifndef _PTRDIFF_T_DEFINED
165        typedef int ptrdiff_t;
166 #      define _PTRDIFF_T_DEFINED
167 #    endif
168 #  else
169 #    define fdopen(fd,type)  _fdopen(fd,type)
170 #  endif
171 #endif
172 
173         /* common defaults */
174 
175 #ifndef OS_CODE
176 #  define OS_CODE  0x03  /* assume Unix */
177 #endif
178 
179 #ifndef F_OPEN
180 #  define F_OPEN(name, mode) fopen((name), (mode))
181 #endif
182 
183          /* functions */
184 
185 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
186 #  ifndef HAVE_VSNPRINTF
187 #    define HAVE_VSNPRINTF
188 #  endif
189 #endif
190 #if defined(__CYGWIN__)
191 #  ifndef HAVE_VSNPRINTF
192 #    define HAVE_VSNPRINTF
193 #  endif
194 #endif
195 #ifndef HAVE_VSNPRINTF
196 #  ifdef MSDOS
197      /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
198         but for now we just assume it doesn't. */
199 #    define NO_vsnprintf
200 #  endif
201 #  ifdef __TURBOC__
202 #    define NO_vsnprintf
203 #  endif
204 #  ifdef WIN32
205      /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
206 #    if !defined(vsnprintf) && !defined(NO_vsnprintf)
207 #      define vsnprintf _vsnprintf
208 #    endif
209 #  endif
210 #  ifdef __SASC
211 #    define NO_vsnprintf
212 #  endif
213 #endif
214 #ifdef VMS
215 #  define NO_vsnprintf
216 #endif
217 
218 #if defined(pyr)
219 #  define NO_MEMCPY
220 #endif
221 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
222  /* Use our own functions for small and medium model with MSC <= 5.0.
223   * You may have to use the same strategy for Borland C (untested).
224   * The __SC__ check is for Symantec.
225   */
226 #  define NO_MEMCPY
227 #endif
228 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
229 #  define HAVE_MEMCPY
230 #endif
231 #ifdef HAVE_MEMCPY
232 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
233 #    define zmemcpy _fmemcpy
234 #    define zmemcmp _fmemcmp
235 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
236 #  else
237 #    define zmemcpy memcpy
238 #    define zmemcmp memcmp
239 #    define zmemzero(dest, len) memset(dest, 0, len)
240 #  endif
241 #else
242    extern void zmemcpy  OF((void* dest, const void* source, uInt len));
243    extern int  zmemcmp  OF((const void* s1, const void* s2, uInt len));
244    extern void zmemzero OF((void* dest, uInt len));
245 #endif
246 
247 /* Diagnostic functions */
248 #ifdef DEBUG
249 #  include <stdio.h>
250    extern int z_verbose;
251    extern void z_error    OF((char *m));
252 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
253 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
254 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
255 #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
256 #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
257 #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
258 #else
259 #  define Assert(cond,msg)
260 #  define Trace(x)
261 #  define Tracev(x)
262 #  define Tracevv(x)
263 #  define Tracec(c,x)
264 #  define Tracecv(c,x)
265 #endif
266 
267 
268 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
269 void   zcfree  OF((voidpf opaque, voidpf ptr));
270 
271 #define ZALLOC(strm, items, size) \
272            (*((strm)->zalloc))((strm)->opaque, (items), (size))
273 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
274 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
275 
276 #endif /* _ZUTIL_H */
277