zutil.h 6.3 KB

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