gzguts.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* gzguts.h -- zlib internal header definitions for gz* operations
  2. * Copyright (C) 2004, 2005, 2010 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. #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
  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 NO_DEFLATE /* for compatibility with old definition */
  27. # define NO_GZCOMPRESS
  28. #endif
  29. #ifdef _MSC_VER
  30. # include <io.h>
  31. # define vsnprintf _vsnprintf
  32. #endif
  33. #ifndef local
  34. # define local static
  35. #endif
  36. /* compile with -Dlocal if your debugger can't find static symbols */
  37. /* gz* functions always use library allocation functions */
  38. #ifndef STDC
  39. extern voidp malloc OF((uInt size));
  40. extern void free OF((voidpf ptr));
  41. #endif
  42. /* get errno and strerror definition */
  43. #if defined UNDER_CE
  44. # include <windows.h>
  45. # define zstrerror() gz_strwinerror((DWORD)GetLastError())
  46. #else
  47. # ifdef STDC
  48. # include <errno.h>
  49. # define zstrerror() strerror(errno)
  50. # else
  51. # define zstrerror() "stdio error (consult errno)"
  52. # endif
  53. #endif
  54. /* provide prototypes for these when building zlib without LFS */
  55. #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
  56. ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
  57. ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
  58. ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
  59. ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
  60. #endif
  61. /* default i/o buffer size -- double this for output when reading */
  62. #define GZBUFSIZE 8192
  63. /* gzip modes, also provide a little integrity check on the passed structure */
  64. #define GZ_NONE 0
  65. #define GZ_READ 7247
  66. #define GZ_WRITE 31153
  67. #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
  68. /* values for gz_state how */
  69. #define LOOK 0 /* look for a gzip header */
  70. #define COPY 1 /* copy input directly */
  71. #define GZIP 2 /* decompress a gzip stream */
  72. /* internal gzip file state data structure */
  73. typedef struct {
  74. /* used for both reading and writing */
  75. int mode; /* see gzip modes above */
  76. int fd; /* file descriptor */
  77. char *path; /* path or fd for error messages */
  78. z_off64_t pos; /* current position in uncompressed data */
  79. unsigned size; /* buffer size, zero if not allocated yet */
  80. unsigned want; /* requested buffer size, default is GZBUFSIZE */
  81. unsigned char *in; /* input buffer */
  82. unsigned char *out; /* output buffer (double-sized when reading) */
  83. unsigned char *next; /* next output data to deliver or write */
  84. /* just for reading */
  85. unsigned have; /* amount of output data unused at next */
  86. int eof; /* true if end of input file reached */
  87. z_off64_t start; /* where the gzip data started, for rewinding */
  88. z_off64_t raw; /* where the raw data started, for seeking */
  89. int how; /* 0: get header, 1: copy, 2: decompress */
  90. int direct; /* true if last read direct, false if gzip */
  91. /* just for writing */
  92. int level; /* compression level */
  93. int strategy; /* compression strategy */
  94. /* seek request */
  95. z_off64_t skip; /* amount to skip (already rewound if backwards) */
  96. int seek; /* true if seek request pending */
  97. /* error information */
  98. int err; /* error code */
  99. char *msg; /* error message */
  100. /* zlib inflate or deflate stream */
  101. z_stream strm; /* stream structure in-place (not a pointer) */
  102. } gz_state;
  103. typedef gz_state FAR *gz_statep;
  104. /* shared functions */
  105. void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
  106. #if defined UNDER_CE
  107. char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
  108. #endif
  109. /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
  110. value -- needed when comparing unsigned to z_off64_t, which is signed
  111. (possible z_off64_t types off_t, off64_t, and long are all signed) */
  112. #ifdef INT_MAX
  113. # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
  114. #else
  115. unsigned ZLIB_INTERNAL gz_intmax OF((void));
  116. # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
  117. #endif