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