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