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