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