cannam@128: /* zutil.h -- internal interface and configuration of the compression library cannam@128: * Copyright (C) 1995-2013 Jean-loup Gailly. cannam@128: * For conditions of distribution and use, see copyright notice in zlib.h cannam@128: */ cannam@128: cannam@128: /* WARNING: this file should *not* be used by applications. It is cannam@128: part of the implementation of the compression library and is cannam@128: subject to change. Applications should only use zlib.h. cannam@128: */ cannam@128: cannam@128: /* @(#) $Id$ */ cannam@128: cannam@128: #ifndef ZUTIL_H cannam@128: #define ZUTIL_H cannam@128: cannam@128: #ifdef HAVE_HIDDEN cannam@128: # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) cannam@128: #else cannam@128: # define ZLIB_INTERNAL cannam@128: #endif cannam@128: cannam@128: #include "zlib.h" cannam@128: cannam@128: #if defined(STDC) && !defined(Z_SOLO) cannam@128: # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) cannam@128: # include cannam@128: # endif cannam@128: # include cannam@128: # include cannam@128: #endif cannam@128: cannam@128: #ifdef Z_SOLO cannam@128: typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ cannam@128: #endif cannam@128: cannam@128: #ifndef local cannam@128: # define local static cannam@128: #endif cannam@128: /* compile with -Dlocal if your debugger can't find static symbols */ cannam@128: cannam@128: typedef unsigned char uch; cannam@128: typedef uch FAR uchf; cannam@128: typedef unsigned short ush; cannam@128: typedef ush FAR ushf; cannam@128: typedef unsigned long ulg; cannam@128: cannam@128: extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ cannam@128: /* (size given to avoid silly warnings with Visual C++) */ cannam@128: cannam@128: #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] cannam@128: cannam@128: #define ERR_RETURN(strm,err) \ cannam@128: return (strm->msg = ERR_MSG(err), (err)) cannam@128: /* To be used only when the state is known to be valid */ cannam@128: cannam@128: /* common constants */ cannam@128: cannam@128: #ifndef DEF_WBITS cannam@128: # define DEF_WBITS MAX_WBITS cannam@128: #endif cannam@128: /* default windowBits for decompression. MAX_WBITS is for compression only */ cannam@128: cannam@128: #if MAX_MEM_LEVEL >= 8 cannam@128: # define DEF_MEM_LEVEL 8 cannam@128: #else cannam@128: # define DEF_MEM_LEVEL MAX_MEM_LEVEL cannam@128: #endif cannam@128: /* default memLevel */ cannam@128: cannam@128: #define STORED_BLOCK 0 cannam@128: #define STATIC_TREES 1 cannam@128: #define DYN_TREES 2 cannam@128: /* The three kinds of block type */ cannam@128: cannam@128: #define MIN_MATCH 3 cannam@128: #define MAX_MATCH 258 cannam@128: /* The minimum and maximum match lengths */ cannam@128: cannam@128: #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ cannam@128: cannam@128: /* target dependencies */ cannam@128: cannam@128: #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) cannam@128: # define OS_CODE 0x00 cannam@128: # ifndef Z_SOLO cannam@128: # if defined(__TURBOC__) || defined(__BORLANDC__) cannam@128: # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) cannam@128: /* Allow compilation with ANSI keywords only enabled */ cannam@128: void _Cdecl farfree( void *block ); cannam@128: void *_Cdecl farmalloc( unsigned long nbytes ); cannam@128: # else cannam@128: # include cannam@128: # endif cannam@128: # else /* MSC or DJGPP */ cannam@128: # include cannam@128: # endif cannam@128: # endif cannam@128: #endif cannam@128: cannam@128: #ifdef AMIGA cannam@128: # define OS_CODE 0x01 cannam@128: #endif cannam@128: cannam@128: #if defined(VAXC) || defined(VMS) cannam@128: # define OS_CODE 0x02 cannam@128: # define F_OPEN(name, mode) \ cannam@128: fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") cannam@128: #endif cannam@128: cannam@128: #if defined(ATARI) || defined(atarist) cannam@128: # define OS_CODE 0x05 cannam@128: #endif cannam@128: cannam@128: #ifdef OS2 cannam@128: # define OS_CODE 0x06 cannam@128: # if defined(M_I86) && !defined(Z_SOLO) cannam@128: # include cannam@128: # endif cannam@128: #endif cannam@128: cannam@128: #if defined(MACOS) || defined(TARGET_OS_MAC) cannam@128: # define OS_CODE 0x07 cannam@128: # ifndef Z_SOLO cannam@128: # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os cannam@128: # include /* for fdopen */ cannam@128: # else cannam@128: # ifndef fdopen cannam@128: # define fdopen(fd,mode) NULL /* No fdopen() */ cannam@128: # endif cannam@128: # endif cannam@128: # endif cannam@128: #endif cannam@128: cannam@128: #ifdef TOPS20 cannam@128: # define OS_CODE 0x0a cannam@128: #endif cannam@128: cannam@128: #ifdef WIN32 cannam@128: # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ cannam@128: # define OS_CODE 0x0b cannam@128: # endif cannam@128: #endif cannam@128: cannam@128: #ifdef __50SERIES /* Prime/PRIMOS */ cannam@128: # define OS_CODE 0x0f cannam@128: #endif cannam@128: cannam@128: #if defined(_BEOS_) || defined(RISCOS) cannam@128: # define fdopen(fd,mode) NULL /* No fdopen() */ cannam@128: #endif cannam@128: cannam@128: #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX cannam@128: # if defined(_WIN32_WCE) cannam@128: # define fdopen(fd,mode) NULL /* No fdopen() */ cannam@128: # ifndef _PTRDIFF_T_DEFINED cannam@128: typedef int ptrdiff_t; cannam@128: # define _PTRDIFF_T_DEFINED cannam@128: # endif cannam@128: # else cannam@128: # define fdopen(fd,type) _fdopen(fd,type) cannam@128: # endif cannam@128: #endif cannam@128: cannam@128: #if defined(__BORLANDC__) && !defined(MSDOS) cannam@128: #pragma warn -8004 cannam@128: #pragma warn -8008 cannam@128: #pragma warn -8066 cannam@128: #endif cannam@128: cannam@128: /* provide prototypes for these when building zlib without LFS */ cannam@128: #if !defined(_WIN32) && \ cannam@128: (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) cannam@128: ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); cannam@128: ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); cannam@128: #endif cannam@128: cannam@128: /* common defaults */ cannam@128: cannam@128: #ifndef OS_CODE cannam@128: # define OS_CODE 0x03 /* assume Unix */ cannam@128: #endif cannam@128: cannam@128: #ifndef F_OPEN cannam@128: # define F_OPEN(name, mode) fopen((name), (mode)) cannam@128: #endif cannam@128: cannam@128: /* functions */ cannam@128: cannam@128: #if defined(pyr) || defined(Z_SOLO) cannam@128: # define NO_MEMCPY cannam@128: #endif cannam@128: #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) cannam@128: /* Use our own functions for small and medium model with MSC <= 5.0. cannam@128: * You may have to use the same strategy for Borland C (untested). cannam@128: * The __SC__ check is for Symantec. cannam@128: */ cannam@128: # define NO_MEMCPY cannam@128: #endif cannam@128: #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) cannam@128: # define HAVE_MEMCPY cannam@128: #endif cannam@128: #ifdef HAVE_MEMCPY cannam@128: # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ cannam@128: # define zmemcpy _fmemcpy cannam@128: # define zmemcmp _fmemcmp cannam@128: # define zmemzero(dest, len) _fmemset(dest, 0, len) cannam@128: # else cannam@128: # define zmemcpy memcpy cannam@128: # define zmemcmp memcmp cannam@128: # define zmemzero(dest, len) memset(dest, 0, len) cannam@128: # endif cannam@128: #else cannam@128: void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); cannam@128: int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); cannam@128: void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); cannam@128: #endif cannam@128: cannam@128: /* Diagnostic functions */ cannam@128: #ifdef DEBUG cannam@128: # include cannam@128: extern int ZLIB_INTERNAL z_verbose; cannam@128: extern void ZLIB_INTERNAL z_error OF((char *m)); cannam@128: # define Assert(cond,msg) {if(!(cond)) z_error(msg);} cannam@128: # define Trace(x) {if (z_verbose>=0) fprintf x ;} cannam@128: # define Tracev(x) {if (z_verbose>0) fprintf x ;} cannam@128: # define Tracevv(x) {if (z_verbose>1) fprintf x ;} cannam@128: # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} cannam@128: # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} cannam@128: #else cannam@128: # define Assert(cond,msg) cannam@128: # define Trace(x) cannam@128: # define Tracev(x) cannam@128: # define Tracevv(x) cannam@128: # define Tracec(c,x) cannam@128: # define Tracecv(c,x) cannam@128: #endif cannam@128: cannam@128: #ifndef Z_SOLO cannam@128: voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, cannam@128: unsigned size)); cannam@128: void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); cannam@128: #endif cannam@128: cannam@128: #define ZALLOC(strm, items, size) \ cannam@128: (*((strm)->zalloc))((strm)->opaque, (items), (size)) cannam@128: #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) cannam@128: #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} cannam@128: cannam@128: /* Reverse the bytes in a 32-bit value */ cannam@128: #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ cannam@128: (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) cannam@128: cannam@128: #endif /* ZUTIL_H */