zutil.h 6.9 KB

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