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