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