zutil.h 6.7 KB

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