Home | History | Annotate | Line # | Download | only in zlib
zutil.h revision 1.1
      1 /*	$NetBSD: zutil.h,v 1.1 2006/01/14 20:10:42 christos Exp $	*/
      2 
      3 /* zutil.h -- internal interface and configuration of the compression library
      4  * Copyright (C) 1995-2005 Jean-loup Gailly.
      5  * For conditions of distribution and use, see copyright notice in zlib.h
      6  */
      7 
      8 /* WARNING: this file should *not* be used by applications. It is
      9    part of the implementation of the compression library and is
     10    subject to change. Applications should only use zlib.h.
     11  */
     12 
     13 /* @(#) Id */
     14 
     15 #ifndef ZUTIL_H
     16 #define ZUTIL_H
     17 
     18 #define ZLIB_INTERNAL
     19 #include "zlib.h"
     20 
     21 #ifdef STDC
     22 #  ifndef _WIN32_WCE
     23 #    include <stddef.h>
     24 #  endif
     25 #  include <string.h>
     26 #  include <stdlib.h>
     27 #endif
     28 #ifdef NO_ERRNO_H
     29 #   ifdef _WIN32_WCE
     30       /* The Microsoft C Run-Time Library for Windows CE doesn't have
     31        * errno.  We define it as a global variable to simplify porting.
     32        * Its value is always 0 and should not be used.  We rename it to
     33        * avoid conflict with other libraries that use the same workaround.
     34        */
     35 #     define errno z_errno
     36 #   endif
     37     extern int errno;
     38 #else
     39 #  ifndef _WIN32_WCE
     40 #    include <errno.h>
     41 #  endif
     42 #endif
     43 
     44 #ifndef local
     45 #  define local static
     46 #endif
     47 /* compile with -Dlocal if your debugger can't find static symbols */
     48 
     49 typedef unsigned char  uch;
     50 typedef uch FAR uchf;
     51 typedef unsigned short ush;
     52 typedef ush FAR ushf;
     53 typedef unsigned long  ulg;
     54 
     55 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
     56 /* (size given to avoid silly warnings with Visual C++) */
     57 
     58 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
     59 
     60 #define ERR_RETURN(strm,err) \
     61   return (strm->msg = (char*)ERR_MSG(err), (err))
     62 /* To be used only when the state is known to be valid */
     63 
     64         /* common constants */
     65 
     66 #ifndef DEF_WBITS
     67 #  define DEF_WBITS MAX_WBITS
     68 #endif
     69 /* default windowBits for decompression. MAX_WBITS is for compression only */
     70 
     71 #if MAX_MEM_LEVEL >= 8
     72 #  define DEF_MEM_LEVEL 8
     73 #else
     74 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
     75 #endif
     76 /* default memLevel */
     77 
     78 #define STORED_BLOCK 0
     79 #define STATIC_TREES 1
     80 #define DYN_TREES    2
     81 /* The three kinds of block type */
     82 
     83 #define MIN_MATCH  3
     84 #define MAX_MATCH  258
     85 /* The minimum and maximum match lengths */
     86 
     87 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
     88 
     89         /* target dependencies */
     90 
     91 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
     92 #  define OS_CODE  0x00
     93 #  if defined(__TURBOC__) || defined(__BORLANDC__)
     94 #    if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
     95        /* Allow compilation with ANSI keywords only enabled */
     96        void _Cdecl farfree( void *block );
     97        void *_Cdecl farmalloc( unsigned long nbytes );
     98 #    else
     99 #      include <alloc.h>
    100 #    endif
    101 #  else /* MSC or DJGPP */
    102 #    include <malloc.h>
    103 #  endif
    104 #endif
    105 
    106 #ifdef AMIGA
    107 #  define OS_CODE  0x01
    108 #endif
    109 
    110 #if defined(VAXC) || defined(VMS)
    111 #  define OS_CODE  0x02
    112 #  define F_OPEN(name, mode) \
    113      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
    114 #endif
    115 
    116 #if defined(ATARI) || defined(atarist)
    117 #  define OS_CODE  0x05
    118 #endif
    119 
    120 #ifdef OS2
    121 #  define OS_CODE  0x06
    122 #  ifdef M_I86
    123      #include <malloc.h>
    124 #  endif
    125 #endif
    126 
    127 #if defined(MACOS) || defined(TARGET_OS_MAC)
    128 #  define OS_CODE  0x07
    129 #  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
    130 #    include <unix.h> /* for fdopen */
    131 #  else
    132 #    ifndef fdopen
    133 #      define fdopen(fd,mode) NULL /* No fdopen() */
    134 #    endif
    135 #  endif
    136 #endif
    137 
    138 #ifdef TOPS20
    139 #  define OS_CODE  0x0a
    140 #endif
    141 
    142 #ifdef WIN32
    143 #  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
    144 #    define OS_CODE  0x0b
    145 #  endif
    146 #endif
    147 
    148 #ifdef __50SERIES /* Prime/PRIMOS */
    149 #  define OS_CODE  0x0f
    150 #endif
    151 
    152 #if defined(_BEOS_) || defined(RISCOS)
    153 #  define fdopen(fd,mode) NULL /* No fdopen() */
    154 #endif
    155 
    156 #if (defined(_MSC_VER) && (_MSC_VER > 600))
    157 #  if defined(_WIN32_WCE)
    158 #    define fdopen(fd,mode) NULL /* No fdopen() */
    159 #    ifndef _PTRDIFF_T_DEFINED
    160        typedef int ptrdiff_t;
    161 #      define _PTRDIFF_T_DEFINED
    162 #    endif
    163 #  else
    164 #    define fdopen(fd,type)  _fdopen(fd,type)
    165 #  endif
    166 #endif
    167 
    168         /* common defaults */
    169 
    170 #ifndef OS_CODE
    171 #  define OS_CODE  0x03  /* assume Unix */
    172 #endif
    173 
    174 #ifndef F_OPEN
    175 #  define F_OPEN(name, mode) fopen((name), (mode))
    176 #endif
    177 
    178          /* functions */
    179 
    180 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
    181 #  ifndef HAVE_VSNPRINTF
    182 #    define HAVE_VSNPRINTF
    183 #  endif
    184 #endif
    185 #if defined(__CYGWIN__)
    186 #  ifndef HAVE_VSNPRINTF
    187 #    define HAVE_VSNPRINTF
    188 #  endif
    189 #endif
    190 #ifndef HAVE_VSNPRINTF
    191 #  ifdef MSDOS
    192      /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
    193         but for now we just assume it doesn't. */
    194 #    define NO_vsnprintf
    195 #  endif
    196 #  ifdef __TURBOC__
    197 #    define NO_vsnprintf
    198 #  endif
    199 #  ifdef WIN32
    200      /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
    201 #    if !defined(vsnprintf) && !defined(NO_vsnprintf)
    202 #      define vsnprintf _vsnprintf
    203 #    endif
    204 #  endif
    205 #  ifdef __SASC
    206 #    define NO_vsnprintf
    207 #  endif
    208 #endif
    209 #ifdef VMS
    210 #  define NO_vsnprintf
    211 #endif
    212 
    213 #if defined(pyr)
    214 #  define NO_MEMCPY
    215 #endif
    216 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
    217  /* Use our own functions for small and medium model with MSC <= 5.0.
    218   * You may have to use the same strategy for Borland C (untested).
    219   * The __SC__ check is for Symantec.
    220   */
    221 #  define NO_MEMCPY
    222 #endif
    223 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
    224 #  define HAVE_MEMCPY
    225 #endif
    226 #ifdef HAVE_MEMCPY
    227 #  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
    228 #    define zmemcpy _fmemcpy
    229 #    define zmemcmp _fmemcmp
    230 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
    231 #  else
    232 #    define zmemcpy memcpy
    233 #    define zmemcmp memcmp
    234 #    define zmemzero(dest, len) memset(dest, 0, len)
    235 #  endif
    236 #else
    237    extern void zmemcpy  OF((Bytef* dest, const Bytef* source, uInt len));
    238    extern int  zmemcmp  OF((const Bytef* s1, const Bytef* s2, uInt len));
    239    extern void zmemzero OF((Bytef* dest, uInt len));
    240 #endif
    241 
    242 /* Diagnostic functions */
    243 #ifdef DEBUG
    244 #  include <stdio.h>
    245    extern int z_verbose;
    246    extern void z_error    OF((char *m));
    247 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
    248 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}
    249 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}
    250 #  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
    251 #  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
    252 #  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
    253 #else
    254 #  define Assert(cond,msg)
    255 #  define Trace(x)
    256 #  define Tracev(x)
    257 #  define Tracevv(x)
    258 #  define Tracec(c,x)
    259 #  define Tracecv(c,x)
    260 #endif
    261 
    262 
    263 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
    264 void   zcfree  OF((voidpf opaque, voidpf ptr));
    265 
    266 #define ZALLOC(strm, items, size) \
    267            (*((strm)->zalloc))((strm)->opaque, (items), (size))
    268 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
    269 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
    270 
    271 #endif /* ZUTIL_H */
    272