gzguts.h 6.4 KB

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