zutil.h
Upload User: shengde
Upload Date: 2021-02-21
Package Size: 638k
Code Size: 7k
Development Platform:

Visual C++

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