gzguts.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* gzguts.h -- zlib internal header definitions for gz* operations
  2. * Copyright (C) 2004-2019 Mark Adler
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. #ifdef _LARGEFILE64_SOURCE
  6. # ifndef _LARGEFILE_SOURCE
  7. # define _LARGEFILE_SOURCE 1
  8. # endif
  9. # ifdef _FILE_OFFSET_BITS
  10. # undef _FILE_OFFSET_BITS
  11. # endif
  12. #endif
  13. #ifdef _WIN32
  14. # ifndef _CRT_SECURE_NO_WARNINGS
  15. # define _CRT_SECURE_NO_WARNINGS
  16. # endif // _CRT_SECURE_NO_WARNINGS
  17. # ifndef _CRT_NONSTDC_NO_DEPRECATE
  18. # define _CRT_NONSTDC_NO_DEPRECATE
  19. # endif // _CRT_NONSTDC_NO_DEPRECATE
  20. #endif // _WIN32
  21. #ifdef HAVE_HIDDEN
  22. # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
  23. #else
  24. # define ZLIB_INTERNAL
  25. #endif
  26. #include <stdio.h>
  27. #include "zlib.h"
  28. #ifdef STDC
  29. # include <string.h>
  30. # include <stdlib.h>
  31. # include <limits.h>
  32. #endif
  33. #ifndef _POSIX_SOURCE
  34. # define _POSIX_SOURCE
  35. #endif
  36. #include <fcntl.h>
  37. #ifdef _WIN32
  38. # include <stddef.h>
  39. #endif
  40. #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
  41. # include <io.h>
  42. #endif
  43. #if defined(_WIN32)
  44. # define WIDECHAR
  45. #endif
  46. #ifdef WINAPI_FAMILY
  47. # define open _open
  48. # define read _read
  49. # define write _write
  50. # define close _close
  51. #endif
  52. #ifdef NO_DEFLATE /* for compatibility with old definition */
  53. # define NO_GZCOMPRESS
  54. #endif
  55. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  56. # ifndef HAVE_VSNPRINTF
  57. # define HAVE_VSNPRINTF
  58. # endif
  59. #endif
  60. #if defined(__CYGWIN__)
  61. # ifndef HAVE_VSNPRINTF
  62. # define HAVE_VSNPRINTF
  63. # endif
  64. #endif
  65. #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
  66. # ifndef HAVE_VSNPRINTF
  67. # define HAVE_VSNPRINTF
  68. # endif
  69. #endif
  70. #ifndef HAVE_VSNPRINTF
  71. # ifdef MSDOS
  72. /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
  73. but for now we just assume it doesn't. */
  74. # define NO_vsnprintf
  75. # endif
  76. # ifdef __TURBOC__
  77. # define NO_vsnprintf
  78. # endif
  79. # ifdef WIN32
  80. /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
  81. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  82. # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
  83. # define vsnprintf _vsnprintf
  84. # endif
  85. # endif
  86. # endif
  87. # ifdef __SASC
  88. # define NO_vsnprintf
  89. # endif
  90. # ifdef VMS
  91. # define NO_vsnprintf
  92. # endif
  93. # ifdef __OS400__
  94. # define NO_vsnprintf
  95. # endif
  96. # ifdef __MVS__
  97. # define NO_vsnprintf
  98. # endif
  99. #endif
  100. /* unlike snprintf (which is required in C99), _snprintf does not guarantee
  101. null termination of the result -- however this is only used in gzlib.c where
  102. the result is assured to fit in the space provided */
  103. #if defined(_MSC_VER) && _MSC_VER < 1900
  104. # define snprintf _snprintf
  105. #endif
  106. #ifndef local
  107. # define local static
  108. #endif
  109. /* since "static" is used to mean two completely different things in C, we
  110. define "local" for the non-static meaning of "static", for readability
  111. (compile with -Dlocal if your debugger can't find static symbols) */
  112. /* gz* functions always use library allocation functions */
  113. #ifndef STDC
  114. extern voidp malloc OF((uInt size));
  115. extern void free OF((voidpf ptr));
  116. #endif
  117. /* get errno and strerror definition */
  118. #if defined UNDER_CE
  119. # include <windows.h>
  120. # define zstrerror() gz_strwinerror((DWORD)GetLastError())
  121. #else
  122. # ifndef NO_STRERROR
  123. # include <errno.h>
  124. # define zstrerror() strerror(errno)
  125. # else
  126. # define zstrerror() "stdio error (consult errno)"
  127. # endif
  128. #endif
  129. /* provide prototypes for these when building zlib without LFS */
  130. #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
  131. ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
  132. ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
  133. ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
  134. ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
  135. #endif
  136. /* default memLevel */
  137. #if MAX_MEM_LEVEL >= 8
  138. # define DEF_MEM_LEVEL 8
  139. #else
  140. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  141. #endif
  142. /* default i/o buffer size -- double this for output when reading (this and
  143. twice this must be able to fit in an unsigned type) */
  144. #define GZBUFSIZE 8192
  145. /* gzip modes, also provide a little integrity check on the passed structure */
  146. #define GZ_NONE 0
  147. #define GZ_READ 7247
  148. #define GZ_WRITE 31153
  149. #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
  150. /* values for gz_state how */
  151. #define LOOK 0 /* look for a gzip header */
  152. #define COPY 1 /* copy input directly */
  153. #define GZIP 2 /* decompress a gzip stream */
  154. /* internal gzip file state data structure */
  155. typedef struct {
  156. /* exposed contents for gzgetc() macro */
  157. struct gzFile_s x; /* "x" for exposed */
  158. /* x.have: number of bytes available at x.next */
  159. /* x.next: next output data to deliver or write */
  160. /* x.pos: current position in uncompressed data */
  161. /* used for both reading and writing */
  162. int mode; /* see gzip modes above */
  163. int fd; /* file descriptor */
  164. char *path; /* path or fd for error messages */
  165. unsigned size; /* buffer size, zero if not allocated yet */
  166. unsigned want; /* requested buffer size, default is GZBUFSIZE */
  167. unsigned char *in; /* input buffer (double-sized when writing) */
  168. unsigned char *out; /* output buffer (double-sized when reading) */
  169. int direct; /* 0 if processing gzip, 1 if transparent */
  170. /* just for reading */
  171. int how; /* 0: get header, 1: copy, 2: decompress */
  172. z_off64_t start; /* where the gzip data started, for rewinding */
  173. int eof; /* true if end of input file reached */
  174. int past; /* true if read requested past end */
  175. /* just for writing */
  176. int level; /* compression level */
  177. int strategy; /* compression strategy */
  178. int reset; /* true if a reset is pending after a Z_FINISH */
  179. /* seek request */
  180. z_off64_t skip; /* amount to skip (already rewound if backwards) */
  181. int seek; /* true if seek request pending */
  182. /* error information */
  183. int err; /* error code */
  184. char *msg; /* error message */
  185. /* zlib inflate or deflate stream */
  186. z_stream strm; /* stream structure in-place (not a pointer) */
  187. } gz_state;
  188. typedef gz_state FAR *gz_statep;
  189. /* shared functions */
  190. void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
  191. #if defined UNDER_CE
  192. char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
  193. #endif
  194. /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
  195. value -- needed when comparing unsigned to z_off64_t, which is signed
  196. (possible z_off64_t types off_t, off64_t, and long are all signed) */
  197. #ifdef INT_MAX
  198. # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
  199. #else
  200. unsigned ZLIB_INTERNAL gz_intmax OF((void));
  201. # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
  202. #endif