annotate src/zlib-1.2.8/zutil.h @ 43:5ea0608b923f

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