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