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