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