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