zutil.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* zutil.h -- internal interface and configuration of the compression library
  2. * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
  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. #ifdef HAVE_HIDDEN
  13. # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
  14. #else
  15. # define ZLIB_INTERNAL
  16. #endif
  17. #include "zlib.h"
  18. #if defined(STDC) && !defined(Z_SOLO)
  19. # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
  20. # include <stddef.h>
  21. # endif
  22. # include <string.h>
  23. # include <stdlib.h>
  24. #endif
  25. #ifdef NO_ERRNO_H
  26. # ifdef _WIN32_WCE
  27. /* The Microsoft C Run-Time Library for Windows CE doesn't have
  28. * errno. We define it as a global variable to simplify porting.
  29. * Its value is always 0 and should not be used. We rename it to
  30. * avoid conflict with other libraries that use the same workaround.
  31. */
  32. # define errno z_errno
  33. # endif
  34. extern int errno;
  35. #else
  36. # ifndef _WIN32_WCE
  37. # include <errno.h>
  38. # endif
  39. #endif
  40. #ifdef Z_SOLO
  41. typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
  42. #endif
  43. #ifndef local
  44. # define local static
  45. #endif
  46. /* since "static" is used to mean two completely different things in C, we
  47. define "local" for the non-static meaning of "static", for readability
  48. (compile with -Dlocal if your debugger can't find static symbols) */
  49. typedef unsigned char uch;
  50. typedef uch FAR uchf;
  51. typedef unsigned short ush;
  52. typedef ush FAR ushf;
  53. typedef unsigned long ulg;
  54. extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  55. /* (size given to avoid silly warnings with Visual C++) */
  56. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  57. #define ERR_RETURN(strm,err) \
  58. return (strm->msg = ERR_MSG(err), (err))
  59. /* To be used only when the state is known to be valid */
  60. /* common constants */
  61. #ifndef DEF_WBITS
  62. # define DEF_WBITS MAX_WBITS
  63. #endif
  64. /* default windowBits for decompression. MAX_WBITS is for compression only */
  65. #if MAX_MEM_LEVEL >= 8
  66. # define DEF_MEM_LEVEL 8
  67. #else
  68. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  69. #endif
  70. /* default memLevel */
  71. #define STORED_BLOCK 0
  72. #define STATIC_TREES 1
  73. #define DYN_TREES 2
  74. /* The three kinds of block type */
  75. #define MIN_MATCH 3
  76. #define MAX_MATCH 258
  77. /* The minimum and maximum match lengths */
  78. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  79. /* target dependencies */
  80. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  81. # define OS_CODE 0x00
  82. # ifndef Z_SOLO
  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. #endif
  96. #ifdef AMIGA
  97. # define OS_CODE 1
  98. #endif
  99. #if defined(VAXC) || defined(VMS)
  100. # define OS_CODE 2
  101. # define F_OPEN(name, mode) \
  102. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  103. #endif
  104. #ifdef __370__
  105. # if __TARGET_LIB__ < 0x20000000
  106. # define OS_CODE 4
  107. # elif __TARGET_LIB__ < 0x40000000
  108. # define OS_CODE 11
  109. # else
  110. # define OS_CODE 8
  111. # endif
  112. #endif
  113. #if defined(ATARI) || defined(atarist)
  114. # define OS_CODE 5
  115. #endif
  116. #ifdef OS2
  117. # define OS_CODE 6
  118. # if defined(M_I86) && !defined(Z_SOLO)
  119. # include <malloc.h>
  120. # endif
  121. #endif
  122. #if defined(MACOS) || defined(TARGET_OS_MAC)
  123. # define OS_CODE 7
  124. # ifndef Z_SOLO
  125. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  126. # include <unix.h> /* for fdopen */
  127. # else
  128. # ifndef fdopen
  129. # define fdopen(fd,mode) NULL /* No fdopen() */
  130. # endif
  131. # endif
  132. # endif
  133. #endif
  134. #ifdef __acorn
  135. # define OS_CODE 13
  136. #endif
  137. #if defined(WIN32) && !defined(__CYGWIN__)
  138. # define OS_CODE 10
  139. #endif
  140. #ifdef _BEOS_
  141. # define OS_CODE 16
  142. #endif
  143. #ifdef __TOS_OS400__
  144. # define OS_CODE 18
  145. #endif
  146. #ifdef __APPLE__
  147. # define OS_CODE 19
  148. #endif
  149. #if defined(_BEOS_) || defined(RISCOS)
  150. # define fdopen(fd,mode) NULL /* No fdopen() */
  151. #endif
  152. #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
  153. # if defined(_WIN32_WCE)
  154. # define fdopen(fd,mode) NULL /* No fdopen() */
  155. # ifndef _PTRDIFF_T_DEFINED
  156. typedef int ptrdiff_t;
  157. # define _PTRDIFF_T_DEFINED
  158. # endif
  159. # else
  160. # define fdopen(fd,type) _fdopen(fd,type)
  161. # endif
  162. #endif
  163. #if defined(__BORLANDC__) && !defined(MSDOS)
  164. #pragma warn -8004
  165. #pragma warn -8008
  166. #pragma warn -8066
  167. #endif
  168. /* provide prototypes for these when building zlib without LFS */
  169. #if !defined(_WIN32) && \
  170. (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
  171. ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
  172. ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
  173. #endif
  174. /* common defaults */
  175. #ifndef OS_CODE
  176. # define OS_CODE 3 /* assume Unix */
  177. #endif
  178. #ifndef F_OPEN
  179. # define F_OPEN(name, mode) fopen((name), (mode))
  180. #endif
  181. /* functions */
  182. #if defined(pyr) || defined(Z_SOLO)
  183. # define NO_MEMCPY
  184. #endif
  185. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  186. /* Use our own functions for small and medium model with MSC <= 5.0.
  187. * You may have to use the same strategy for Borland C (untested).
  188. * The __SC__ check is for Symantec.
  189. */
  190. # define NO_MEMCPY
  191. #endif
  192. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  193. # define HAVE_MEMCPY
  194. #endif
  195. #ifdef HAVE_MEMCPY
  196. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  197. # define zmemcpy _fmemcpy
  198. # define zmemcmp _fmemcmp
  199. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  200. # else
  201. # define zmemcpy memcpy
  202. # define zmemcmp memcmp
  203. # define zmemzero(dest, len) memset(dest, 0, len)
  204. # endif
  205. #else
  206. void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  207. int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  208. void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
  209. #endif
  210. /* Diagnostic functions */
  211. #ifdef ZLIB_DEBUG
  212. # include <stdio.h>
  213. extern int ZLIB_INTERNAL z_verbose;
  214. extern void ZLIB_INTERNAL z_error OF((char *m));
  215. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  216. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  217. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  218. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  219. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  220. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  221. #else
  222. # define Assert(cond,msg)
  223. # define Trace(x)
  224. # define Tracev(x)
  225. # define Tracevv(x)
  226. # define Tracec(c,x)
  227. # define Tracecv(c,x)
  228. #endif
  229. #ifndef Z_SOLO
  230. voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
  231. unsigned size));
  232. void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
  233. #endif
  234. #define ZALLOC(strm, items, size) \
  235. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  236. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  237. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  238. /* Reverse the bytes in a 32-bit value */
  239. #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  240. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  241. #ifdef _MSC_VER
  242. #define zalign(x) __declspec(align(x))
  243. #else
  244. #define zalign(x) __attribute__((aligned((x))))
  245. #endif
  246. #endif /* ZUTIL_H */