gzguts.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef GZGUTS_H_
  2. #define GZGUTS_H_
  3. /* gzguts.h -- zlib internal header definitions for gz* operations
  4. * Copyright (C) 2004-2024 Mark Adler
  5. * For conditions of distribution and use, see copyright notice in zlib.h
  6. */
  7. #ifdef _LARGEFILE64_SOURCE
  8. # ifndef _LARGEFILE_SOURCE
  9. # define _LARGEFILE_SOURCE 1
  10. # endif
  11. # undef _FILE_OFFSET_BITS
  12. # undef _TIME_BITS
  13. #endif
  14. #if defined(HAVE_VISIBILITY_INTERNAL)
  15. # define Z_INTERNAL __attribute__((visibility ("internal")))
  16. #elif defined(HAVE_VISIBILITY_HIDDEN)
  17. # define Z_INTERNAL __attribute__((visibility ("hidden")))
  18. #else
  19. # define Z_INTERNAL
  20. #endif
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <limits.h>
  25. #include <fcntl.h>
  26. #if defined(ZLIB_COMPAT)
  27. # include "zlib.h"
  28. #else
  29. # include "zlib-ng.h"
  30. #endif
  31. #ifdef _WIN32
  32. # include <stddef.h>
  33. #endif
  34. #if defined(_WIN32)
  35. # include <io.h>
  36. # define WIDECHAR
  37. #endif
  38. #ifdef WINAPI_FAMILY
  39. # define open _open
  40. # define read _read
  41. # define write _write
  42. # define close _close
  43. #endif
  44. /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
  45. #if !defined(STDC99) && !defined(__CYGWIN__) && !defined(__MINGW__) && defined(_WIN32)
  46. # if !defined(vsnprintf)
  47. # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
  48. # define vsnprintf _vsnprintf
  49. # endif
  50. # endif
  51. #endif
  52. /* unlike snprintf (which is required in C99), _snprintf does not guarantee
  53. null termination of the result -- however this is only used in gzlib.c
  54. where the result is assured to fit in the space provided */
  55. #if defined(_MSC_VER) && _MSC_VER < 1900
  56. # define snprintf _snprintf
  57. #endif
  58. /* get errno and strerror definition */
  59. #ifndef NO_STRERROR
  60. # include <errno.h>
  61. # define zstrerror() strerror(errno)
  62. #else
  63. # define zstrerror() "stdio error (consult errno)"
  64. #endif
  65. /* default memLevel */
  66. #if MAX_MEM_LEVEL >= 8
  67. # define DEF_MEM_LEVEL 8
  68. #else
  69. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  70. #endif
  71. /* default i/o buffer size -- double this for output when reading (this and
  72. twice this must be able to fit in an unsigned type) */
  73. #ifndef GZBUFSIZE
  74. # define GZBUFSIZE 131072
  75. #endif
  76. /* gzip modes, also provide a little integrity check on the passed structure */
  77. #define GZ_NONE 0
  78. #define GZ_READ 7247
  79. #define GZ_WRITE 31153
  80. #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
  81. /* values for gz_state how */
  82. #define LOOK 0 /* look for a gzip header */
  83. #define COPY 1 /* copy input directly */
  84. #define GZIP 2 /* decompress a gzip stream */
  85. /* internal gzip file state data structure */
  86. typedef struct {
  87. /* exposed contents for gzgetc() macro */
  88. struct gzFile_s x; /* "x" for exposed */
  89. /* x.have: number of bytes available at x.next */
  90. /* x.next: next output data to deliver or write */
  91. /* x.pos: current position in uncompressed data */
  92. /* used for both reading and writing */
  93. int mode; /* see gzip modes above */
  94. int fd; /* file descriptor */
  95. char *path; /* path or fd for error messages */
  96. unsigned size; /* buffer size, zero if not allocated yet */
  97. unsigned want; /* requested buffer size, default is GZBUFSIZE */
  98. unsigned char *in; /* input buffer (double-sized when writing) */
  99. unsigned char *out; /* output buffer (double-sized when reading) */
  100. int direct; /* 0 if processing gzip, 1 if transparent */
  101. /* just for reading */
  102. int how; /* 0: get header, 1: copy, 2: decompress */
  103. z_off64_t start; /* where the gzip data started, for rewinding */
  104. int eof; /* true if end of input file reached */
  105. int past; /* true if read requested past end */
  106. /* just for writing */
  107. int level; /* compression level */
  108. int strategy; /* compression strategy */
  109. int reset; /* true if a reset is pending after a Z_FINISH */
  110. /* seek request */
  111. z_off64_t skip; /* amount to skip (already rewound if backwards) */
  112. int seek; /* true if seek request pending */
  113. /* error information */
  114. int err; /* error code */
  115. char *msg; /* error message */
  116. /* zlib inflate or deflate stream */
  117. PREFIX3(stream) strm; /* stream structure in-place (not a pointer) */
  118. } gz_state;
  119. typedef gz_state *gz_statep;
  120. /* shared functions */
  121. void Z_INTERNAL gz_error(gz_state *, int, const char *);
  122. #ifdef ZLIB_COMPAT
  123. unsigned Z_INTERNAL gz_intmax(void);
  124. #endif
  125. /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
  126. value -- needed when comparing unsigned to z_off64_t, which is signed
  127. (possible z_off64_t types off_t, off64_t, and long are all signed) */
  128. #define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
  129. #endif /* GZGUTS_H_ */