zutil.h 6.7 KB

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