xref: /openbsd-src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.h (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1b39c5158Smillert /* zutil.h -- internal interface and configuration of the compression library
2*3d61058aSafresh1  * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
3b39c5158Smillert  * For conditions of distribution and use, see copyright notice in zlib.h
4b39c5158Smillert  */
5b39c5158Smillert 
6b39c5158Smillert /* WARNING: this file should *not* be used by applications. It is
7b39c5158Smillert    part of the implementation of the compression library and is
8b39c5158Smillert    subject to change. Applications should only use zlib.h.
9b39c5158Smillert  */
10b39c5158Smillert 
11b39c5158Smillert /* @(#) $Id$ */
12b39c5158Smillert 
13b39c5158Smillert #ifndef ZUTIL_H
14b39c5158Smillert #define ZUTIL_H
15b39c5158Smillert 
16e9ce3842Safresh1 #ifdef HAVE_HIDDEN
1748950c12Ssthen #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
1848950c12Ssthen #else
19b39c5158Smillert #  define ZLIB_INTERNAL
2048950c12Ssthen #endif
2148950c12Ssthen 
22b39c5158Smillert #include "zlib.h"
23b39c5158Smillert 
24e9ce3842Safresh1 #if defined(STDC) && !defined(Z_SOLO)
2548950c12Ssthen #  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
26b39c5158Smillert #    include <stddef.h>
27b39c5158Smillert #  endif
28b39c5158Smillert #  include <string.h>
29b39c5158Smillert #  include <stdlib.h>
30b39c5158Smillert #endif
31b39c5158Smillert 
32b39c5158Smillert #ifndef local
33b39c5158Smillert #  define local static
34b39c5158Smillert #endif
359f11ffb7Safresh1 /* since "static" is used to mean two completely different things in C, we
369f11ffb7Safresh1    define "local" for the non-static meaning of "static", for readability
379f11ffb7Safresh1    (compile with -Dlocal if your debugger can't find static symbols) */
38b39c5158Smillert 
39b39c5158Smillert typedef unsigned char  uch;
40b39c5158Smillert typedef uch FAR uchf;
41b39c5158Smillert typedef unsigned short ush;
42b39c5158Smillert typedef ush FAR ushf;
43b39c5158Smillert typedef unsigned long  ulg;
44b39c5158Smillert 
45eac174f2Safresh1 #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
46eac174f2Safresh1 #  include <limits.h>
47eac174f2Safresh1 #  if (ULONG_MAX == 0xffffffffffffffff)
48eac174f2Safresh1 #    define Z_U8 unsigned long
49eac174f2Safresh1 #  elif (ULLONG_MAX == 0xffffffffffffffff)
50eac174f2Safresh1 #    define Z_U8 unsigned long long
51eac174f2Safresh1 #  elif (UINT_MAX == 0xffffffffffffffff)
52eac174f2Safresh1 #    define Z_U8 unsigned
53eac174f2Safresh1 #  endif
54eac174f2Safresh1 #endif
55eac174f2Safresh1 
56e5157e49Safresh1 extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
57b39c5158Smillert /* (size given to avoid silly warnings with Visual C++) */
58b39c5158Smillert 
59*3d61058aSafresh1 #define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
60b39c5158Smillert 
61b39c5158Smillert #define ERR_RETURN(strm,err) \
62e5157e49Safresh1   return (strm->msg = ERR_MSG(err), (err))
63b39c5158Smillert /* To be used only when the state is known to be valid */
64b39c5158Smillert 
65b39c5158Smillert         /* common constants */
66b39c5158Smillert 
67b39c5158Smillert #ifndef DEF_WBITS
68b39c5158Smillert #  define DEF_WBITS MAX_WBITS
69b39c5158Smillert #endif
70b39c5158Smillert /* default windowBits for decompression. MAX_WBITS is for compression only */
71b39c5158Smillert 
72b39c5158Smillert #if MAX_MEM_LEVEL >= 8
73b39c5158Smillert #  define DEF_MEM_LEVEL 8
74b39c5158Smillert #else
75b39c5158Smillert #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
76b39c5158Smillert #endif
77b39c5158Smillert /* default memLevel */
78b39c5158Smillert 
79b39c5158Smillert #define STORED_BLOCK 0
80b39c5158Smillert #define STATIC_TREES 1
81b39c5158Smillert #define DYN_TREES    2
82b39c5158Smillert /* The three kinds of block type */
83b39c5158Smillert 
84b39c5158Smillert #define MIN_MATCH  3
85b39c5158Smillert #define MAX_MATCH  258
86b39c5158Smillert /* The minimum and maximum match lengths */
87b39c5158Smillert 
88b39c5158Smillert #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
89b39c5158Smillert 
90b39c5158Smillert         /* target dependencies */
91b39c5158Smillert 
92b39c5158Smillert #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
93b39c5158Smillert #  define OS_CODE  0x00
94e9ce3842Safresh1 #  ifndef Z_SOLO
95b39c5158Smillert #    if defined(__TURBOC__) || defined(__BORLANDC__)
96b39c5158Smillert #      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
97b39c5158Smillert          /* Allow compilation with ANSI keywords only enabled */
98b39c5158Smillert          void _Cdecl farfree( void *block );
99b39c5158Smillert          void *_Cdecl farmalloc( unsigned long nbytes );
100b39c5158Smillert #      else
101b39c5158Smillert #        include <alloc.h>
102b39c5158Smillert #      endif
103b39c5158Smillert #    else /* MSC or DJGPP */
104b39c5158Smillert #      include <malloc.h>
105b39c5158Smillert #    endif
106b39c5158Smillert #  endif
107e9ce3842Safresh1 #endif
108b39c5158Smillert 
109b39c5158Smillert #ifdef AMIGA
1109f11ffb7Safresh1 #  define OS_CODE  1
111b39c5158Smillert #endif
112b39c5158Smillert 
113b39c5158Smillert #if defined(VAXC) || defined(VMS)
1149f11ffb7Safresh1 #  define OS_CODE  2
115b39c5158Smillert #  define F_OPEN(name, mode) \
116b39c5158Smillert      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
117b39c5158Smillert #endif
118b39c5158Smillert 
1199f11ffb7Safresh1 #ifdef __370__
1209f11ffb7Safresh1 #  if __TARGET_LIB__ < 0x20000000
1219f11ffb7Safresh1 #    define OS_CODE 4
1229f11ffb7Safresh1 #  elif __TARGET_LIB__ < 0x40000000
1239f11ffb7Safresh1 #    define OS_CODE 11
1249f11ffb7Safresh1 #  else
1259f11ffb7Safresh1 #    define OS_CODE 8
1269f11ffb7Safresh1 #  endif
1279f11ffb7Safresh1 #endif
1289f11ffb7Safresh1 
129b39c5158Smillert #if defined(ATARI) || defined(atarist)
1309f11ffb7Safresh1 #  define OS_CODE  5
131b39c5158Smillert #endif
132b39c5158Smillert 
133b39c5158Smillert #ifdef OS2
1349f11ffb7Safresh1 #  define OS_CODE  6
135e9ce3842Safresh1 #  if defined(M_I86) && !defined(Z_SOLO)
136b39c5158Smillert #    include <malloc.h>
137b39c5158Smillert #  endif
138b39c5158Smillert #endif
139b39c5158Smillert 
140*3d61058aSafresh1 #if defined(MACOS)
1419f11ffb7Safresh1 #  define OS_CODE  7
142e9ce3842Safresh1 #endif
143b39c5158Smillert 
1449f11ffb7Safresh1 #ifdef __acorn
1459f11ffb7Safresh1 #  define OS_CODE 13
146b39c5158Smillert #endif
147b39c5158Smillert 
1489f11ffb7Safresh1 #if defined(WIN32) && !defined(__CYGWIN__)
1499f11ffb7Safresh1 #  define OS_CODE  10
150b39c5158Smillert #endif
151b39c5158Smillert 
1529f11ffb7Safresh1 #ifdef _BEOS_
1539f11ffb7Safresh1 #  define OS_CODE  16
1549f11ffb7Safresh1 #endif
1559f11ffb7Safresh1 
1569f11ffb7Safresh1 #ifdef __TOS_OS400__
1579f11ffb7Safresh1 #  define OS_CODE 18
1589f11ffb7Safresh1 #endif
1599f11ffb7Safresh1 
1609f11ffb7Safresh1 #ifdef __APPLE__
1619f11ffb7Safresh1 #  define OS_CODE 19
162b39c5158Smillert #endif
163b39c5158Smillert 
164e9ce3842Safresh1 #if defined(__BORLANDC__) && !defined(MSDOS)
16548950c12Ssthen   #pragma warn -8004
16648950c12Ssthen   #pragma warn -8008
16748950c12Ssthen   #pragma warn -8066
16848950c12Ssthen #endif
16948950c12Ssthen 
17048950c12Ssthen /* provide prototypes for these when building zlib without LFS */
171e5157e49Safresh1 #if !defined(_WIN32) && \
172e5157e49Safresh1     (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
173*3d61058aSafresh1     ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
174*3d61058aSafresh1     ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
175*3d61058aSafresh1     ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
17648950c12Ssthen #endif
17748950c12Ssthen 
178b39c5158Smillert         /* common defaults */
179b39c5158Smillert 
180b39c5158Smillert #ifndef OS_CODE
1819f11ffb7Safresh1 #  define OS_CODE  3     /* assume Unix */
182b39c5158Smillert #endif
183b39c5158Smillert 
184b39c5158Smillert #ifndef F_OPEN
185b39c5158Smillert #  define F_OPEN(name, mode) fopen((name), (mode))
186b39c5158Smillert #endif
187b39c5158Smillert 
188b39c5158Smillert          /* functions */
189b39c5158Smillert 
190e9ce3842Safresh1 #if defined(pyr) || defined(Z_SOLO)
191b39c5158Smillert #  define NO_MEMCPY
192b39c5158Smillert #endif
193b39c5158Smillert #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
194b39c5158Smillert  /* Use our own functions for small and medium model with MSC <= 5.0.
195b39c5158Smillert   * You may have to use the same strategy for Borland C (untested).
196b39c5158Smillert   * The __SC__ check is for Symantec.
197b39c5158Smillert   */
198b39c5158Smillert #  define NO_MEMCPY
199b39c5158Smillert #endif
200b39c5158Smillert #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
201b39c5158Smillert #  define HAVE_MEMCPY
202b39c5158Smillert #endif
203b39c5158Smillert #ifdef HAVE_MEMCPY
204b39c5158Smillert #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
205b39c5158Smillert #    define zmemcpy _fmemcpy
206b39c5158Smillert #    define zmemcmp _fmemcmp
207b39c5158Smillert #    define zmemzero(dest, len) _fmemset(dest, 0, len)
208b39c5158Smillert #  else
209b39c5158Smillert #    define zmemcpy memcpy
210b39c5158Smillert #    define zmemcmp memcmp
211b39c5158Smillert #    define zmemzero(dest, len) memset(dest, 0, len)
212b39c5158Smillert #  endif
213b39c5158Smillert #else
214*3d61058aSafresh1    void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
215*3d61058aSafresh1    int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
216*3d61058aSafresh1    void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
217b39c5158Smillert #endif
218b39c5158Smillert 
219b39c5158Smillert /* Diagnostic functions */
2209f11ffb7Safresh1 #ifdef ZLIB_DEBUG
221b39c5158Smillert #  include <stdio.h>
22248950c12Ssthen    extern int ZLIB_INTERNAL z_verbose;
223*3d61058aSafresh1    extern void ZLIB_INTERNAL z_error(char *m);
224b39c5158Smillert #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
225b39c5158Smillert #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
226b39c5158Smillert #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
227b39c5158Smillert #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
228b39c5158Smillert #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
229b39c5158Smillert #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
230b39c5158Smillert #else
231b39c5158Smillert #  define Assert(cond,msg)
232b39c5158Smillert #  define Trace(x)
233b39c5158Smillert #  define Tracev(x)
234b39c5158Smillert #  define Tracevv(x)
235b39c5158Smillert #  define Tracec(c,x)
236b39c5158Smillert #  define Tracecv(c,x)
237b39c5158Smillert #endif
238b39c5158Smillert 
239e9ce3842Safresh1 #ifndef Z_SOLO
240*3d61058aSafresh1    voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
241*3d61058aSafresh1                                 unsigned size);
242*3d61058aSafresh1    void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
243e9ce3842Safresh1 #endif
244b39c5158Smillert 
245b39c5158Smillert #define ZALLOC(strm, items, size) \
246b39c5158Smillert            (*((strm)->zalloc))((strm)->opaque, (items), (size))
247b39c5158Smillert #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
248b39c5158Smillert #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
249b39c5158Smillert 
250e9ce3842Safresh1 /* Reverse the bytes in a 32-bit value */
251e9ce3842Safresh1 #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
252e9ce3842Safresh1                     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
253e9ce3842Safresh1 
254b39c5158Smillert #endif /* ZUTIL_H */
255