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