zutil.h 6.7 KB

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