File indexing completed on 2024-04-21 03:48:33

0001 /* zutil.h -- internal interface and configuration of the compression library
0002  * Copyright (C) 1995-2013 Jean-loup Gailly.
0003  * For conditions of distribution and use, see copyright notice in zlib.h
0004  */
0005 
0006 /* WARNING: this file should *not* be used by applications. It is
0007    part of the implementation of the compression library and is
0008    subject to change. Applications should only use zlib.h.
0009  */
0010 
0011 /* @(#) $Id$ */
0012 
0013 #ifndef ZUTIL_H
0014 #define ZUTIL_H
0015 
0016 #ifdef HAVE_HIDDEN
0017 #  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
0018 #else
0019 #  define ZLIB_INTERNAL
0020 #endif
0021 
0022 #include "zlib.h"
0023 
0024 #if defined(STDC) && !defined(Z_SOLO)
0025 #  if !(defined(_WIN32_WCE) && defined(_MSC_VER))
0026 #    include <stddef.h>
0027 #  endif
0028 #  include <string.h>
0029 #  include <stdlib.h>
0030 #endif
0031 
0032 #ifdef Z_SOLO
0033    typedef long ptrdiff_t;  /* guess -- will be caught if guess is wrong */
0034 #endif
0035 
0036 #ifndef local
0037 #  define local static
0038 #endif
0039 /* compile with -Dlocal if your debugger can't find static symbols */
0040 
0041 typedef unsigned char  uch;
0042 typedef uch FAR uchf;
0043 typedef unsigned short ush;
0044 typedef ush FAR ushf;
0045 typedef unsigned long  ulg;
0046 
0047 extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
0048 /* (size given to avoid silly warnings with Visual C++) */
0049 
0050 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
0051 
0052 #define ERR_RETURN(strm,err) \
0053   return (strm->msg = ERR_MSG(err), (err))
0054 /* To be used only when the state is known to be valid */
0055 
0056         /* common constants */
0057 
0058 #ifndef DEF_WBITS
0059 #  define DEF_WBITS MAX_WBITS
0060 #endif
0061 /* default windowBits for decompression. MAX_WBITS is for compression only */
0062 
0063 #if MAX_MEM_LEVEL >= 8
0064 #  define DEF_MEM_LEVEL 8
0065 #else
0066 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
0067 #endif
0068 /* default memLevel */
0069 
0070 #define STORED_BLOCK 0
0071 #define STATIC_TREES 1
0072 #define DYN_TREES    2
0073 /* The three kinds of block type */
0074 
0075 #define MIN_MATCH  3
0076 #define MAX_MATCH  258
0077 /* The minimum and maximum match lengths */
0078 
0079 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
0080 
0081         /* target dependencies */
0082 
0083 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
0084 #  define OS_CODE  0x00
0085 #  ifndef Z_SOLO
0086 #    if defined(__TURBOC__) || defined(__BORLANDC__)
0087 #      if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
0088          /* Allow compilation with ANSI keywords only enabled */
0089          void _Cdecl farfree( void *block );
0090          void *_Cdecl farmalloc( unsigned long nbytes );
0091 #      else
0092 #        include <alloc.h>
0093 #      endif
0094 #    else /* MSC or DJGPP */
0095 #      include <malloc.h>
0096 #    endif
0097 #  endif
0098 #endif
0099 
0100 #ifdef AMIGA
0101 #  define OS_CODE  0x01
0102 #endif
0103 
0104 #if defined(VAXC) || defined(VMS)
0105 #  define OS_CODE  0x02
0106 #  define F_OPEN(name, mode) \
0107      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
0108 #endif
0109 
0110 #if defined(ATARI) || defined(atarist)
0111 #  define OS_CODE  0x05
0112 #endif
0113 
0114 #ifdef OS2
0115 #  define OS_CODE  0x06
0116 #  if defined(M_I86) && !defined(Z_SOLO)
0117 #    include <malloc.h>
0118 #  endif
0119 #endif
0120 
0121 #if defined(MACOS) || defined(TARGET_OS_MAC)
0122 #  define OS_CODE  0x07
0123 #  ifndef Z_SOLO
0124 #    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
0125 #      include <unix.h> /* for fdopen */
0126 #    else
0127 #      ifndef fdopen
0128 #        define fdopen(fd,mode) NULL /* No fdopen() */
0129 #      endif
0130 #    endif
0131 #  endif
0132 #endif
0133 
0134 #ifdef TOPS20
0135 #  define OS_CODE  0x0a
0136 #endif
0137 
0138 #ifdef WIN32
0139 #  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
0140 #    define OS_CODE  0x0b
0141 #  endif
0142 #endif
0143 
0144 #ifdef __50SERIES /* Prime/PRIMOS */
0145 #  define OS_CODE  0x0f
0146 #endif
0147 
0148 #if defined(_BEOS_) || defined(RISCOS)
0149 #  define fdopen(fd,mode) NULL /* No fdopen() */
0150 #endif
0151 
0152 #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
0153 #  if defined(_WIN32_WCE)
0154 #    define fdopen(fd,mode) NULL /* No fdopen() */
0155 #    ifndef _PTRDIFF_T_DEFINED
0156        typedef int ptrdiff_t;
0157 #      define _PTRDIFF_T_DEFINED
0158 #    endif
0159 #  else
0160 #    define fdopen(fd,type)  _fdopen(fd,type)
0161 #  endif
0162 #endif
0163 
0164 #if defined(__BORLANDC__) && !defined(MSDOS)
0165   #pragma warn -8004
0166   #pragma warn -8008
0167   #pragma warn -8066
0168 #endif
0169 
0170 /* provide prototypes for these when building zlib without LFS */
0171 #if !defined(_WIN32) && \
0172     (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
0173     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
0174     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
0175 #endif
0176 
0177         /* common defaults */
0178 
0179 #ifndef OS_CODE
0180 #  define OS_CODE  0x03  /* assume Unix */
0181 #endif
0182 
0183 #ifndef F_OPEN
0184 #  define F_OPEN(name, mode) fopen((name), (mode))
0185 #endif
0186 
0187          /* functions */
0188 
0189 #if defined(pyr) || defined(Z_SOLO)
0190 #  define NO_MEMCPY
0191 #endif
0192 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
0193  /* Use our own functions for small and medium model with MSC <= 5.0.
0194   * You may have to use the same strategy for Borland C (untested).
0195   * The __SC__ check is for Symantec.
0196   */
0197 #  define NO_MEMCPY
0198 #endif
0199 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
0200 #  define HAVE_MEMCPY
0201 #endif
0202 #ifdef HAVE_MEMCPY
0203 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
0204 #    define zmemcpy _fmemcpy
0205 #    define zmemcmp _fmemcmp
0206 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
0207 #  else
0208 #    define zmemcpy memcpy
0209 #    define zmemcmp memcmp
0210 #    define zmemzero(dest, len) memset(dest, 0, len)
0211 #  endif
0212 #else
0213    void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
0214    int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
0215    void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
0216 #endif
0217 
0218 /* Diagnostic functions */
0219 #ifdef DEBUG
0220 #  include <stdio.h>
0221    extern int ZLIB_INTERNAL z_verbose;
0222    extern void ZLIB_INTERNAL z_error OF((char *m));
0223 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
0224 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
0225 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
0226 #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
0227 #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
0228 #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
0229 #else
0230 #  define Assert(cond,msg)
0231 #  define Trace(x)
0232 #  define Tracev(x)
0233 #  define Tracevv(x)
0234 #  define Tracec(c,x)
0235 #  define Tracecv(c,x)
0236 #endif
0237 
0238 #ifndef Z_SOLO
0239    voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
0240                                     unsigned size));
0241    void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));
0242 #endif
0243 
0244 #define ZALLOC(strm, items, size) \
0245            (*((strm)->zalloc))((strm)->opaque, (items), (size))
0246 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
0247 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
0248 
0249 /* Reverse the bytes in a 32-bit value */
0250 #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
0251                     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
0252 
0253 #endif /* ZUTIL_H */