zutil.h 7.0 KB

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