modules/zlib/src/zutil.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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

mercurial