zutil.h 6.5 KB

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