zutil.h 6.8 KB

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