gzguts.h 5.9 KB

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