]>
Commit | Line | Data |
---|---|---|
3ec97ca4 | 1 | /* gzguts.h -- zlib internal header definitions for gz* operations\r |
d11973f1 | 2 | * Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>\r |
3ec97ca4 DM |
3 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler\r |
4 | * For conditions of distribution and use, see copyright notice in zlib.h\r | |
5 | */\r | |
6 | \r | |
7 | #ifdef _LARGEFILE64_SOURCE\r | |
8 | # ifndef _LARGEFILE_SOURCE\r | |
9 | # define _LARGEFILE_SOURCE 1\r | |
10 | # endif\r | |
11 | # ifdef _FILE_OFFSET_BITS\r | |
12 | # undef _FILE_OFFSET_BITS\r | |
13 | # endif\r | |
14 | #endif\r | |
15 | \r | |
16 | #ifdef HAVE_HIDDEN\r | |
17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))\r | |
18 | #else\r | |
19 | # define ZLIB_INTERNAL\r | |
20 | #endif\r | |
21 | \r | |
22 | #include <stdio.h>\r | |
23 | #include "zlib.h"\r | |
24 | #ifdef STDC\r | |
25 | # include <string.h>\r | |
26 | # include <stdlib.h>\r | |
27 | # include <limits.h>\r | |
28 | #endif\r | |
29 | #include <fcntl.h>\r | |
30 | \r | |
31 | #ifdef _WIN32\r | |
32 | # include <stddef.h>\r | |
33 | #endif\r | |
34 | \r | |
d11973f1 | 35 | #if (defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)) && !defined(UEFI_C_SOURCE)\r |
3ec97ca4 DM |
36 | # include <io.h>\r |
37 | #endif\r | |
38 | \r | |
39 | #ifdef WINAPI_FAMILY\r | |
40 | # define open _open\r | |
41 | # define read _read\r | |
42 | # define write _write\r | |
43 | # define close _close\r | |
44 | #endif\r | |
45 | \r | |
d11973f1 DM |
46 | // Needed to get the declarations for open, read, write, close\r |
47 | #ifdef UEFI_C_SOURCE\r | |
48 | # include <unistd.h>\r | |
49 | #endif\r | |
50 | \r | |
3ec97ca4 DM |
51 | #ifdef NO_DEFLATE /* for compatibility with old definition */\r |
52 | # define NO_GZCOMPRESS\r | |
53 | #endif\r | |
54 | \r | |
55 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)\r | |
56 | # ifndef HAVE_VSNPRINTF\r | |
57 | # define HAVE_VSNPRINTF\r | |
58 | # endif\r | |
59 | #endif\r | |
60 | \r | |
61 | #if defined(__CYGWIN__)\r | |
62 | # ifndef HAVE_VSNPRINTF\r | |
63 | # define HAVE_VSNPRINTF\r | |
64 | # endif\r | |
65 | #endif\r | |
66 | \r | |
67 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)\r | |
68 | # ifndef HAVE_VSNPRINTF\r | |
69 | # define HAVE_VSNPRINTF\r | |
70 | # endif\r | |
71 | #endif\r | |
72 | \r | |
73 | #ifndef HAVE_VSNPRINTF\r | |
74 | # ifdef MSDOS\r | |
75 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),\r | |
76 | but for now we just assume it doesn't. */\r | |
77 | # define NO_vsnprintf\r | |
78 | # endif\r | |
79 | # ifdef __TURBOC__\r | |
80 | # define NO_vsnprintf\r | |
81 | # endif\r | |
82 | # ifdef WIN32\r | |
83 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */\r | |
84 | # if !defined(vsnprintf) && !defined(NO_vsnprintf)\r | |
85 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )\r | |
86 | # define vsnprintf _vsnprintf\r | |
87 | # endif\r | |
88 | # endif\r | |
89 | # endif\r | |
90 | # ifdef __SASC\r | |
91 | # define NO_vsnprintf\r | |
92 | # endif\r | |
93 | # ifdef VMS\r | |
94 | # define NO_vsnprintf\r | |
95 | # endif\r | |
96 | # ifdef __OS400__\r | |
97 | # define NO_vsnprintf\r | |
98 | # endif\r | |
99 | # ifdef __MVS__\r | |
100 | # define NO_vsnprintf\r | |
101 | # endif\r | |
102 | #endif\r | |
103 | \r | |
104 | /* unlike snprintf (which is required in C99, yet still not supported by\r | |
105 | Microsoft more than a decade later!), _snprintf does not guarantee null\r | |
106 | termination of the result -- however this is only used in gzlib.c where\r | |
107 | the result is assured to fit in the space provided */\r | |
d11973f1 | 108 | #if defined(_MSC_VER) && !defined(UEFI_C_SOURCE)\r |
3ec97ca4 DM |
109 | # define snprintf _snprintf\r |
110 | #endif\r | |
111 | \r | |
112 | #ifndef local\r | |
113 | # define local static\r | |
114 | #endif\r | |
115 | /* compile with -Dlocal if your debugger can't find static symbols */\r | |
116 | \r | |
117 | /* gz* functions always use library allocation functions */\r | |
118 | #ifndef STDC\r | |
119 | extern voidp malloc OF((uInt size));\r | |
120 | extern void free OF((voidpf ptr));\r | |
121 | #endif\r | |
122 | \r | |
123 | /* get errno and strerror definition */\r | |
124 | #if defined UNDER_CE\r | |
125 | # include <windows.h>\r | |
126 | # define zstrerror() gz_strwinerror((DWORD)GetLastError())\r | |
127 | #else\r | |
128 | # ifndef NO_STRERROR\r | |
129 | # include <errno.h>\r | |
130 | # define zstrerror() strerror(errno)\r | |
131 | # else\r | |
132 | # define zstrerror() "stdio error (consult errno)"\r | |
133 | # endif\r | |
134 | #endif\r | |
135 | \r | |
136 | /* provide prototypes for these when building zlib without LFS */\r | |
137 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0\r | |
138 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));\r | |
139 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));\r | |
140 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));\r | |
141 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));\r | |
142 | #endif\r | |
143 | \r | |
144 | /* default memLevel */\r | |
145 | #if MAX_MEM_LEVEL >= 8\r | |
146 | # define DEF_MEM_LEVEL 8\r | |
147 | #else\r | |
148 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL\r | |
149 | #endif\r | |
150 | \r | |
151 | /* default i/o buffer size -- double this for output when reading (this and\r | |
152 | twice this must be able to fit in an unsigned type) */\r | |
153 | #define GZBUFSIZE 8192\r | |
154 | \r | |
155 | /* gzip modes, also provide a little integrity check on the passed structure */\r | |
156 | #define GZ_NONE 0\r | |
157 | #define GZ_READ 7247\r | |
158 | #define GZ_WRITE 31153\r | |
159 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */\r | |
160 | \r | |
161 | /* values for gz_state how */\r | |
162 | #define LOOK 0 /* look for a gzip header */\r | |
163 | #define COPY 1 /* copy input directly */\r | |
164 | #define GZIP 2 /* decompress a gzip stream */\r | |
165 | \r | |
166 | /* internal gzip file state data structure */\r | |
167 | typedef struct {\r | |
168 | /* exposed contents for gzgetc() macro */\r | |
169 | struct gzFile_s x; /* "x" for exposed */\r | |
170 | /* x.have: number of bytes available at x.next */\r | |
171 | /* x.next: next output data to deliver or write */\r | |
172 | /* x.pos: current position in uncompressed data */\r | |
173 | /* used for both reading and writing */\r | |
174 | int mode; /* see gzip modes above */\r | |
175 | int fd; /* file descriptor */\r | |
176 | char *path; /* path or fd for error messages */\r | |
177 | unsigned size; /* buffer size, zero if not allocated yet */\r | |
178 | unsigned want; /* requested buffer size, default is GZBUFSIZE */\r | |
179 | unsigned char *in; /* input buffer */\r | |
180 | unsigned char *out; /* output buffer (double-sized when reading) */\r | |
181 | int direct; /* 0 if processing gzip, 1 if transparent */\r | |
182 | /* just for reading */\r | |
183 | int how; /* 0: get header, 1: copy, 2: decompress */\r | |
184 | z_off64_t start; /* where the gzip data started, for rewinding */\r | |
185 | int eof; /* true if end of input file reached */\r | |
186 | int past; /* true if read requested past end */\r | |
187 | /* just for writing */\r | |
188 | int level; /* compression level */\r | |
189 | int strategy; /* compression strategy */\r | |
190 | /* seek request */\r | |
191 | z_off64_t skip; /* amount to skip (already rewound if backwards) */\r | |
192 | int seek; /* true if seek request pending */\r | |
193 | /* error information */\r | |
194 | int err; /* error code */\r | |
195 | char *msg; /* error message */\r | |
196 | /* zlib inflate or deflate stream */\r | |
197 | z_stream strm; /* stream structure in-place (not a pointer) */\r | |
198 | } gz_state;\r | |
199 | typedef gz_state FAR *gz_statep;\r | |
200 | \r | |
201 | /* shared functions */\r | |
202 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));\r | |
203 | #if defined UNDER_CE\r | |
204 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));\r | |
205 | #endif\r | |
206 | \r | |
207 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t\r | |
208 | value -- needed when comparing unsigned to z_off64_t, which is signed\r | |
209 | (possible z_off64_t types off_t, off64_t, and long are all signed) */\r | |
210 | #ifdef INT_MAX\r | |
211 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)\r | |
212 | #else\r | |
213 | unsigned ZLIB_INTERNAL gz_intmax OF((void));\r | |
214 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())\r | |
215 | #endif\r |