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(_MSC_VER) || defined(__MINGW__) |
42 | # include <unistd.h> /* for lseek(), read(), close(), write(), unlink() */ |
43 | #endif |
44 | |
45 | #if defined(_WIN32) |
46 | # include <io.h> |
47 | # define WIDECHAR |
48 | #endif |
49 | |
50 | #ifdef WINAPI_FAMILY |
51 | # define open _open |
52 | # define read _read |
53 | # define write _write |
54 | # define close _close |
55 | #endif |
56 | |
57 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ |
58 | #if !defined(STDC99) && !defined(__CYGWIN__) && !defined(__MINGW__) && defined(_WIN32) |
59 | # if !defined(vsnprintf) |
60 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) |
61 | # define vsnprintf _vsnprintf |
62 | # endif |
63 | # endif |
64 | #endif |
65 | |
66 | /* unlike snprintf (which is required in C99), _snprintf does not guarantee |
67 | null termination of the result -- however this is only used in gzlib.c |
68 | where the result is assured to fit in the space provided */ |
69 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
70 | # define snprintf _snprintf |
71 | #endif |
72 | |
73 | /* get errno and strerror definition */ |
74 | #ifndef NO_STRERROR |
75 | # include <errno.h> |
76 | # define zstrerror() strerror(errno) |
77 | #else |
78 | # define zstrerror() "stdio error (consult errno)" |
79 | #endif |
80 | |
81 | /* default memLevel */ |
82 | #if MAX_MEM_LEVEL >= 8 |
83 | # define DEF_MEM_LEVEL 8 |
84 | #else |
85 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
86 | #endif |
87 | |
88 | /* default i/o buffer size -- double this for output when reading (this and |
89 | twice this must be able to fit in an unsigned type) */ |
90 | #ifndef GZBUFSIZE |
91 | # define GZBUFSIZE 8192 |
92 | #endif |
93 | |
94 | /* gzip modes, also provide a little integrity check on the passed structure */ |
95 | #define GZ_NONE 0 |
96 | #define GZ_READ 7247 |
97 | #define GZ_WRITE 31153 |
98 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ |
99 | |
100 | /* values for gz_state how */ |
101 | #define LOOK 0 /* look for a gzip header */ |
102 | #define COPY 1 /* copy input directly */ |
103 | #define GZIP 2 /* decompress a gzip stream */ |
104 | |
105 | /* internal gzip file state data structure */ |
106 | typedef struct { |
107 | /* exposed contents for gzgetc() macro */ |
108 | struct gzFile_s x; /* "x" for exposed */ |
109 | /* x.have: number of bytes available at x.next */ |
110 | /* x.next: next output data to deliver or write */ |
111 | /* x.pos: current position in uncompressed data */ |
112 | /* used for both reading and writing */ |
113 | int mode; /* see gzip modes above */ |
114 | int fd; /* file descriptor */ |
115 | char *path; /* path or fd for error messages */ |
116 | unsigned size; /* buffer size, zero if not allocated yet */ |
117 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ |
118 | unsigned char *in; /* input buffer (double-sized when writing) */ |
119 | unsigned char *out; /* output buffer (double-sized when reading) */ |
120 | int direct; /* 0 if processing gzip, 1 if transparent */ |
121 | /* just for reading */ |
122 | int how; /* 0: get header, 1: copy, 2: decompress */ |
123 | z_off64_t start; /* where the gzip data started, for rewinding */ |
124 | int eof; /* true if end of input file reached */ |
125 | int past; /* true if read requested past end */ |
126 | /* just for writing */ |
127 | int level; /* compression level */ |
128 | int strategy; /* compression strategy */ |
129 | int reset; /* true if a reset is pending after a Z_FINISH */ |
130 | /* seek request */ |
131 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ |
132 | int seek; /* true if seek request pending */ |
133 | /* error information */ |
134 | int err; /* error code */ |
135 | char *msg; /* error message */ |
136 | /* zlib inflate or deflate stream */ |
137 | PREFIX3(stream) strm; /* stream structure in-place (not a pointer) */ |
138 | } gz_state; |
139 | typedef gz_state *gz_statep; |
140 | |
141 | /* shared functions */ |
142 | void Z_INTERNAL gz_error(gz_state *, int, const char *); |
143 | |
144 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t |
145 | value -- needed when comparing unsigned to z_off64_t, which is signed |
146 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ |
147 | #ifdef INT_MAX |
148 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) |
149 | #else |
150 | unsigned Z_INTERNAL gz_intmax(void); |
151 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) |
152 | #endif |
153 | |
154 | #endif /* GZGUTS_H_ */ |
155 | |