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