Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
5.4 KiB

  1. /* zutil.h -- internal interface and configuration of the compression library
  2. * Copyright (C) 1995-2002 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$ */
  10. #ifndef _Z_UTIL_H
  11. #define _Z_UTIL_H
  12. #include "zlib.h"
  13. #ifdef STDC
  14. # include <stddef.h>
  15. # include <string.h>
  16. # include <stdlib.h>
  17. #endif
  18. #ifdef NO_ERRNO_H
  19. extern int errno;
  20. #else
  21. # include <errno.h>
  22. #endif
  23. #ifndef local
  24. # define local static
  25. #endif
  26. /* compile with -Dlocal if your debugger can't find static symbols */
  27. typedef unsigned char uch;
  28. typedef uch FAR uchf;
  29. typedef unsigned short ush;
  30. typedef ush FAR ushf;
  31. typedef unsigned long ulg;
  32. extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
  33. /* (size given to avoid silly warnings with Visual C++) */
  34. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  35. #define ERR_RETURN(strm,err) \
  36. return (strm->msg = (char*)ERR_MSG(err), (err))
  37. /* To be used only when the state is known to be valid */
  38. /* common constants */
  39. #ifndef DEF_WBITS
  40. # define DEF_WBITS MAX_WBITS
  41. #endif
  42. /* default windowBits for decompression. MAX_WBITS is for compression only */
  43. #if MAX_MEM_LEVEL >= 8
  44. # define DEF_MEM_LEVEL 8
  45. #else
  46. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  47. #endif
  48. /* default memLevel */
  49. #define STORED_BLOCK 0
  50. #define STATIC_TREES 1
  51. #define DYN_TREES 2
  52. /* The three kinds of block type */
  53. #define MIN_MATCH 3
  54. #define MAX_MATCH 258
  55. /* The minimum and maximum match lengths */
  56. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  57. /* target dependencies */
  58. #ifdef MSDOS
  59. # define OS_CODE 0x00
  60. # if defined(__TURBOC__) || defined(__BORLANDC__)
  61. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  62. /* Allow compilation with ANSI keywords only enabled */
  63. void _Cdecl farfree( void *block );
  64. void *_Cdecl farmalloc( unsigned long nbytes );
  65. # else
  66. # include <alloc.h>
  67. # endif
  68. # else /* MSC or DJGPP */
  69. # include <malloc.h>
  70. # endif
  71. #endif
  72. #ifdef OS2
  73. # define OS_CODE 0x06
  74. #endif
  75. #ifdef WIN32 /* Window 95 & Windows NT */
  76. # define OS_CODE 0x0b
  77. #endif
  78. #if defined(VAXC) || defined(VMS)
  79. # define OS_CODE 0x02
  80. # define F_OPEN(name, mode) \
  81. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  82. #endif
  83. #ifdef AMIGA
  84. # define OS_CODE 0x01
  85. #endif
  86. #if defined(ATARI) || defined(atarist)
  87. # define OS_CODE 0x05
  88. #endif
  89. #if defined(MACOS) || defined(TARGET_OS_MAC)
  90. # define OS_CODE 0x07
  91. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  92. # include <unix.h> /* for fdopen */
  93. # else
  94. # ifndef fdopen
  95. # define fdopen(fd,mode) NULL /* No fdopen() */
  96. # endif
  97. # endif
  98. #endif
  99. #ifdef __50SERIES /* Prime/PRIMOS */
  100. # define OS_CODE 0x0F
  101. #endif
  102. #ifdef TOPS20
  103. # define OS_CODE 0x0a
  104. #endif
  105. #if defined(_BEOS_) || defined(RISCOS)
  106. # define fdopen(fd,mode) NULL /* No fdopen() */
  107. #endif
  108. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  109. # define fdopen(fd,type) _fdopen(fd,type)
  110. #endif
  111. /* Common defaults */
  112. #ifndef OS_CODE
  113. # define OS_CODE 0x03 /* assume Unix */
  114. #endif
  115. #ifndef F_OPEN
  116. # define F_OPEN(name, mode) fopen((name), (mode))
  117. #endif
  118. /* functions */
  119. #ifdef HAVE_STRERROR
  120. extern char *strerror OF((int));
  121. # define zstrerror(errnum) strerror(errnum)
  122. #else
  123. # define zstrerror(errnum) ""
  124. #endif
  125. #if defined(pyr)
  126. # define NO_MEMCPY
  127. #endif
  128. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  129. /* Use our own functions for small and medium model with MSC <= 5.0.
  130. * You may have to use the same strategy for Borland C (untested).
  131. * The __SC__ check is for Symantec.
  132. */
  133. # define NO_MEMCPY
  134. #endif
  135. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  136. # define HAVE_MEMCPY
  137. #endif
  138. #ifdef HAVE_MEMCPY
  139. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  140. # define zmemcpy _fmemcpy
  141. # define zmemcmp _fmemcmp
  142. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  143. # else
  144. # define zmemcpy memcpy
  145. # define zmemcmp memcmp
  146. # define zmemzero(dest, len) memset(dest, 0, len)
  147. # endif
  148. #else
  149. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  150. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  151. extern void zmemzero OF((Bytef* dest, uInt len));
  152. #endif
  153. /* Diagnostic functions */
  154. #ifdef DEBUG
  155. # include <stdio.h>
  156. extern int z_verbose;
  157. extern void z_error OF((char *m));
  158. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  159. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  160. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  161. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  162. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  163. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  164. #else
  165. # define Assert(cond,msg)
  166. # define Trace(x)
  167. # define Tracev(x)
  168. # define Tracevv(x)
  169. # define Tracec(c,x)
  170. # define Tracecv(c,x)
  171. #endif
  172. typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
  173. uInt len));
  174. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  175. void zcfree OF((voidpf opaque, voidpf ptr));
  176. #define ZALLOC(strm, items, size) \
  177. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  178. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  179. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  180. #endif /* _Z_UTIL_H */