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