Debian Codegraph @

external/zlib/gzlib.c

raw symbols SCIP
1 /* gzlib.c -- zlib functions common to reading and writing gzip files
2 * Copyright (C) 2004-2026 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "gzguts.h"cxx . . $ `<file>/external/zlib/gzguts.h`/
7
8 #if defined(__DJGPP__)
9 # define LSEEK llseek
10 #elif defined(_WIN32) && !defined(__BORLANDC__) && !defined(UNDER_CE)
11 # define LSEEK _lseeki64
12 #elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILEcxx . . $ `<external>/4533468968537266721/posix_opt.h:121:9`!-0
13 # define LSEEK lseek64
14 #else
15 # define LSEEKcxx . . $ `external/zlib/gzlib.c:15:11`! lseek
16 #endif
17
18 #if defined UNDER_CE
19
20 /* Map the Windows error number in ERROR to a locale-dependent error message
21 string and return a pointer to it. Typically, the values for ERROR come
22 from GetLastError.
23
24 The string pointed to shall not be modified by the application, but may be
25 overwritten by a subsequent call to gz_strwinerror
26
27 The gz_strwinerror function does not change the current setting of
28 GetLastError. */
29 char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
30 static char buf[1024];
31
32 wchar_t *msgbuf;
33 DWORD lasterr = GetLastError();
34 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
35 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
36 NULL,
37 error,
38 0, /* Default language */
39 (LPVOID)&msgbuf,
40 0,
41 NULL);
42 if (chars != 0) {
43 /* If there is an \r\n appended, zap it. */
44 if (chars >= 2
45 && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
46 chars -= 2;
47 msgbuf[chars] = 0;
48 }
49
50 if (chars > sizeof (buf) - 1) {
51 chars = sizeof (buf) - 1;
52 msgbuf[chars] = 0;
53 }
54
55 wcstombs(buf, msgbuf, chars + 1); /* assumes buf is big enough */
56 LocalFree(msgbuf);
57 }
58 else {
59 sprintf(buf, "unknown win32 error (%ld)", error);
60 }
61
62 SetLastError(lasterr);
63 return buf;
64 }
65
66 #endif /* UNDER_CE */
67
68 /* Reset gzip file state */
69 localcxx . . $ `external/zlib/gzguts.h:114:11`! void gz_resetcxx . . $ gz_reset(fa781aa02c61891d).(gz_statepcxx . . $ gz_statep# state) {
70 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have. = 0; /* no output data available */
71 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) { /* for reading ... */
72 state->eofcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#eof. = 0; /* not at end of file */
73 state->pastcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#past. = 0; /* have not read past end yet */
74 state->howcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#how. = LOOKcxx . . $ `external/zlib/gzguts.h:165:9`!; /* look for gzip header */
75 state->junkcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#junk. = -1; /* mark first member */
76 }
77 else /* for writing ... */
78 state->resetcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#reset. = 0; /* no deflateReset pending */
79 state->againcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#again. = 0; /* no stalled i/o yet */
80 state->skipcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#skip. = 0; /* no seek request pending */
81 gz_errorcxx . . $ gz_error(b3e12012326d2820).(state, Z_OKcxx . . $ `external/zlib/zlib.h:182:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); /* clear error */
82 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos. = 0; /* no uncompressed data yet */
83 state->strmcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strm..avail_incxx . . $ z_stream_s#avail_in. = 0; /* no input data yet */
84 }
85
86 /* Open a gzip file either by name or file descriptor. */
87 localcxx . . $ `external/zlib/gzguts.h:114:11`! gzFilecxx . . $ gzFile# gz_opencxx . . $ gz_open(731d016a20827edc).(const void *path, int fd, const char *mode) {
88 gz_statepcxx . . $ gz_statep# state;
89 z_size_tcxx . . $ z_size_t# len;
90 int oflag = 0;
91 #ifdef O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`!
92 int exclusive = 0;
93 #endif
94
95 /* check input */
96 if (path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || mode == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
97 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
98
99 /* allocate gzFile structure to return */
100 state = (gz_statepcxx . . $ gz_statep#)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(gz_statecxx . . $ gz_state#));
101 if (state == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
102 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
103 state->sizecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#size. = 0; /* no buffers allocated yet */
104 state->wantcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#want. = GZBUFSIZEcxx . . $ `external/zlib/gzguts.h:156:9`!; /* requested buffer size */
105 state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. = Z_OKcxx . . $ `external/zlib/zlib.h:182:9`!; /* no error yet */
106 state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; /* no error message yet */
107
108 /* interpret mode */
109 state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. = GZ_NONEcxx . . $ `external/zlib/gzguts.h:159:9`!;
110 state->levelcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#level. = Z_DEFAULT_COMPRESSIONcxx . . $ `external/zlib/zlib.h:198:9`!;
111 state->strategycxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strategy. = Z_DEFAULT_STRATEGYcxx . . $ `external/zlib/zlib.h:205:9`!;
112 state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. = 0;
113 while (*mode) {
114 if (*mode >= '0' && *mode <= '9')
115 state->levelcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#level. = *mode - '0';
116 else
117 switch (*mode) {
118 case 'r':
119 state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. = GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!;
120 break;
121 #ifndef NO_GZCOMPRESScxx . . $ `external/zlib/zlib.h:1:9`!
122 case 'w':
123 state->mode = GZ_WRITE;
124 break;
125 case 'a':
126 state->mode = GZ_APPEND;
127 break;
128 #endif
129 case '+': /* can't read and write at the same time */
130 freecxx . . $ free(5d22bdacc48458e8).(state);
131 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
132 case 'b': /* ignore -- will request binary anyway */
133 break;
134 #ifdef O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!
135 case 'e':
136 oflag |= O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!;
137 break;
138 #endif
139 #ifdef O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`!
140 case 'x':
141 exclusive = 1;
142 break;
143 #endif
144 case 'f':
145 state->strategycxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strategy. = Z_FILTEREDcxx . . $ `external/zlib/zlib.h:201:9`!;
146 break;
147 case 'h':
148 state->strategycxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strategy. = Z_HUFFMAN_ONLYcxx . . $ `external/zlib/zlib.h:202:9`!;
149 break;
150 case 'R':
151 state->strategycxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strategy. = Z_RLEcxx . . $ `external/zlib/zlib.h:203:9`!;
152 break;
153 case 'F':
154 state->strategycxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strategy. = Z_FIXEDcxx . . $ `external/zlib/zlib.h:204:9`!;
155 break;
156 case 'G':
157 state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. = -1;
158 break;
159 #ifdef O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!
160 case 'N':
161 oflag |= O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!;
162 break;
163 #endif
164 case 'T':
165 state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. = 1;
166 break;
167 default: /* could consider as an error, but just ignore */
168 ;
169 }
170 mode++;
171 }
172
173 /* must provide an "r", "w", or "a" */
174 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_NONEcxx . . $ `external/zlib/gzguts.h:159:9`!) {
175 freecxx . . $ free(5d22bdacc48458e8).(state);
176 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
177 }
178
179 /* direct is 0, 1 if "T", or -1 if "G" (last "G" or "T" wins) */
180 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) {
181 if (state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. == 1) {
182 /* can't force a transparent read */
183 freecxx . . $ free(5d22bdacc48458e8).(state);
184 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
185 }
186 if (state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. == 0)
187 /* default when reading is auto-detect of gzip vs. transparent --
188 start with a transparent assumption in case of an empty file */
189 state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. = 1;
190 }
191 else if (state->directcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#direct. == -1) {
192 /* "G" has no meaning when writing -- disallow it */
193 freecxx . . $ free(5d22bdacc48458e8).(state);
194 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
195 }
196 /* if reading, direct == 1 for auto-detect, -1 for gzip only; if writing or
197 appending, direct == 0 for gzip, 1 for transparent (copy in to out) */
198
199 /* save the path name for error messages */
200 #ifdef WIDECHAR
201 if (fd == -2)
202 len = wcstombs(NULL, path, 0);
203 else
204 #endif
205 len = strlencxx . . $ strlen(751346f8406fd082).((const char *)path);
206 state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path. = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(len + 1);
207 if (state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
208 freecxx . . $ free(5d22bdacc48458e8).(state);
209 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
210 }
211 #ifdef WIDECHAR
212 if (fd == -2) {
213 if (len)
214 wcstombs(state->path, path, len + 1);
215 else
216 *(state->path) = 0;
217 }
218 else
219 #endif
220 {
221 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
222 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path., len + 1, "%s", (const char *)path);
223 #else
224 strcpy(state->path, path);
225 #endif
226 }
227
228 /* compute the flags for open() */
229 oflag |=
230 #ifdef O_LARGEFILE
231 O_LARGEFILE |
232 #endif
233 #ifdef O_BINARY
234 O_BINARY |
235 #endif
236 (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! ?
237 O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! :
238 (O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`! | O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! |
239 #ifdef O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`!
240 (exclusive ? O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`! : 0) |
241 #endif
242 (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`! ?
243 O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`! :
244 O_APPENDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:59:10`!)));
245
246 /* open the file with the appropriate flags (or just use fd) */
247 if (fd == -1)
248 state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd. = opencxx . . $ open(e156e3aa1e5c4ad1).((const char *)path, oflag, 0666);
249 #ifdef WIDECHAR
250 else if (fd == -2)
251 state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE);
252 #endif
253 else {
254 #ifdef O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!
255 if (oflag & O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!)
256 fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!) | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!);
257 #endif
258 #ifdef O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!
259 if (oflag & O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!)
260 fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_SETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:167:9`!, fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_GETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:166:9`!) | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!);
261 #endif
262 state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd. = fd;
263 }
264 if (state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd. == -1) {
265 freecxx . . $ free(5d22bdacc48458e8).(state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path.);
266 freecxx . . $ free(5d22bdacc48458e8).(state);
267 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
268 }
269 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_APPENDcxx . . $ `external/zlib/gzguts.h:162:9`!) {
270 LSEEKcxx . . $ `external/zlib/gzlib.c:15:11`!(state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd., 0, SEEK_ENDcxx . . $ `<external>/14710646456994434043/fcntl.h:139:10`!); /* so gzoffset() is correct */
271 state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. = GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!; /* simplify later checks */
272 }
273
274 /* save the current position for rewinding (only if reading) */
275 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) {
276 state->startcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#start. = LSEEKcxx . . $ `external/zlib/gzlib.c:15:11`!(state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd., 0, SEEK_CURcxx . . $ `<external>/14710646456994434043/fcntl.h:138:10`!);
277 if (state->startcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#start. == -1) state->startcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#start. = 0;
278 }
279
280 /* initialize stream */
281 gz_resetcxx . . $ gz_reset(fa781aa02c61891d).(state);
282
283 /* return stream */
284 return (gzFilecxx . . $ gzFile#)state;
285 }
286
287 /* -- see zlib.h -- */
288 gzFilecxx . . $ gzFile# ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzopencxx . . $ gzopen(e549dd1a5168a7e3).(const char *path, const char *mode) {
289 return gz_opencxx . . $ gz_open(731d016a20827edc).(path, -1, mode);
290 }
291
292 /* -- see zlib.h -- */
293 gzFilecxx . . $ gzFile# ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzopen64cxx . . $ gzopen64(e549dd1a5168a7e3).(const char *path, const char *mode) {
294 return gz_opencxx . . $ gz_open(731d016a20827edc).(path, -1, mode);
295 }
296
297 /* -- see zlib.h -- */
298 gzFilecxx . . $ gzFile# ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzdopencxx . . $ gzdopen(22355c0c2644e5c0).(int fd, const char *mode) {
299 char *path; /* identifier for error messages */
300 gzFilecxx . . $ gzFile# gz;
301
302 if (fd == -1 || (path = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(7 + 3 * sizeof(int))) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
303 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
304 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
305 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
306 #else
307 sprintf(path, "<fd:%d>", fd); /* for debugging */
308 #endif
309 gz = gz_opencxx . . $ gz_open(731d016a20827edc).(path, fd, mode);
310 freecxx . . $ free(5d22bdacc48458e8).(path);
311 return gz;
312 }
313
314 /* -- see zlib.h -- */
315 #ifdef WIDECHAR
316 gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
317 return gz_open(path, -2, mode);
318 }
319 #endif
320
321 /* -- see zlib.h -- */
322 int ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzbuffercxx . . $ gzbuffer(6f9d918e95eeb730).(gzFilecxx . . $ gzFile# file, unsigned size) {
323 gz_statepcxx . . $ gz_statep# state;
324
325 /* get internal structure and check integrity */
326 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
327 return -1;
328 state = (gz_statepcxx . . $ gz_statep#)file;
329 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
330 return -1;
331
332 /* make sure we haven't already allocated memory */
333 if (state->sizecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#size. != 0)
334 return -1;
335
336 /* check and set requested size */
337 if ((size << 1) < size)
338 return -1; /* need to be able to double it */
339 if (size < 8)
340 size = 8; /* needed to behave well with flushing */
341 state->wantcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#want. = size;
342 return 0;
343 }
344
345 /* -- see zlib.h -- */
346 int ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzrewindcxx . . $ gzrewind(4d4947b8d23ad0c4).(gzFilecxx . . $ gzFile# file) {
347 gz_statepcxx . . $ gz_statep# state;
348
349 /* get internal structure */
350 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
351 return -1;
352 state = (gz_statepcxx . . $ gz_statep#)file;
353
354 /* check that we're reading and that there's no error */
355 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! ||
356 (state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. != Z_OKcxx . . $ `external/zlib/zlib.h:182:9`! && state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. != Z_BUF_ERRORcxx . . $ `external/zlib/zlib.h:189:9`!))
357 return -1;
358
359 /* back up and start over */
360 if (LSEEKcxx . . $ `external/zlib/gzlib.c:15:11`!(state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd., state->startcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#start., SEEK_SETcxx . . $ `<external>/14710646456994434043/fcntl.h:137:10`!) == -1)
361 return -1;
362 gz_resetcxx . . $ gz_reset(fa781aa02c61891d).(state);
363 return 0;
364 }
365
366 /* -- see zlib.h -- */
367 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzseek64cxx . . $ gzseek64(e8cdc07dcf9f3ac2).(gzFilecxx . . $ gzFile# file, z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! offset, int whence) {
368 unsigned n;
369 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ret;
370 gz_statepcxx . . $ gz_statep# state;
371
372 /* get internal structure and check integrity */
373 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
374 return -1;
375 state = (gz_statepcxx . . $ gz_statep#)file;
376 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
377 return -1;
378
379 /* check that there's no error */
380 if (state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. != Z_OKcxx . . $ `external/zlib/zlib.h:182:9`! && state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. != Z_BUF_ERRORcxx . . $ `external/zlib/zlib.h:189:9`!)
381 return -1;
382
383 /* can only seek from start or relative to current position */
384 if (whence != SEEK_SETcxx . . $ `<external>/14710646456994434043/fcntl.h:137:10`! && whence != SEEK_CURcxx . . $ `<external>/14710646456994434043/fcntl.h:138:10`!)
385 return -1;
386
387 /* normalize offset to a SEEK_CUR specification */
388 if (whence == SEEK_SETcxx . . $ `<external>/14710646456994434043/fcntl.h:137:10`!)
389 offset -= state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos.;
390 else {
391 offset += state->pastcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#past. ? 0 : state->skipcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#skip.;
392 state->skipcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#skip. = 0;
393 }
394
395 /* if within raw area while reading, just go there */
396 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->howcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#how. == COPYcxx . . $ `external/zlib/gzguts.h:166:9`! &&
397 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos. + offset >= 0) {
398 ret = LSEEKcxx . . $ `external/zlib/gzlib.c:15:11`!(state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd., offset - (z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`!)state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have., SEEK_CURcxx . . $ `<external>/14710646456994434043/fcntl.h:138:10`!);
399 if (ret == -1)
400 return -1;
401 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have. = 0;
402 state->eofcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#eof. = 0;
403 state->pastcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#past. = 0;
404 state->skipcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#skip. = 0;
405 gz_errorcxx . . $ gz_error(b3e12012326d2820).(state, Z_OKcxx . . $ `external/zlib/zlib.h:182:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
406 state->strmcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strm..avail_incxx . . $ z_stream_s#avail_in. = 0;
407 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos. += offset;
408 return state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos.;
409 }
410
411 /* calculate skip amount, rewinding if needed for back seek when reading */
412 if (offset < 0) {
413 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) /* writing -- can't go backwards */
414 return -1;
415 offset += state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos.;
416 if (offset < 0) /* before start of file! */
417 return -1;
418 if (gzrewindcxx . . $ gzrewind(4d4947b8d23ad0c4).(file) == -1) /* rewind, then skip to offset */
419 return -1;
420 }
421
422 /* if reading, skip what's in output buffer (one less gzgetc() check) */
423 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) {
424 n = GT_OFFcxx . . $ `external/zlib/gzguts.h:216:9`!(state->x.have) || (z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`!)state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have. > offset ?
425 (unsigned)offset : state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have.;
426 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have. -= n;
427 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..nextcxx . . $ gzFile_s#next. += n;
428 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos. += n;
429 offset -= n;
430 }
431
432 /* request skip (if not zero) */
433 state->skipcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#skip. = offset;
434 return state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos. + offset;
435 }
436
437 /* -- see zlib.h -- */
438 z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`! ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzseekcxx . . $ gzseek(e8cdc07dcf9f3ac2).(gzFilecxx . . $ gzFile# file, z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`! offset, int whence) {
439 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ret;
440
441 ret = gzseek64cxx . . $ gzseek64(e8cdc07dcf9f3ac2).(file, (z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`!)offset, whence);
442 return ret == (z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`!)ret ? (z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`!)ret : -1;
443 }
444
445 /* -- see zlib.h -- */
446 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gztell64cxx . . $ gztell64(84882b272d5a8a2f).(gzFilecxx . . $ gzFile# file) {
447 gz_statepcxx . . $ gz_statep# state;
448
449 /* get internal structure and check integrity */
450 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
451 return -1;
452 state = (gz_statepcxx . . $ gz_statep#)file;
453 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
454 return -1;
455
456 /* return position */
457 return state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..poscxx . . $ gzFile_s#pos. + (state->pastcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#past. ? 0 : state->skipcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#skip.);
458 }
459
460 /* -- see zlib.h -- */
461 z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`! ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gztellcxx . . $ gztell(84882b272d5a8a2f).(gzFilecxx . . $ gzFile# file) {
462 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ret;
463
464 ret = gztell64cxx . . $ gztell64(84882b272d5a8a2f).(file);
465 return ret == (z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`!)ret ? (z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`!)ret : -1;
466 }
467
468 /* -- see zlib.h -- */
469 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzoffset64cxx . . $ gzoffset64(84882b272d5a8a2f).(gzFilecxx . . $ gzFile# file) {
470 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! offset;
471 gz_statepcxx . . $ gz_statep# state;
472
473 /* get internal structure and check integrity */
474 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
475 return -1;
476 state = (gz_statepcxx . . $ gz_statep#)file;
477 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
478 return -1;
479
480 /* compute and return effective offset in file */
481 offset = LSEEKcxx . . $ `external/zlib/gzlib.c:15:11`!(state->fdcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#fd., 0, SEEK_CURcxx . . $ `<external>/14710646456994434043/fcntl.h:138:10`!);
482 if (offset == -1)
483 return -1;
484 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) /* reading */
485 offset -= state->strmcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#strm..avail_incxx . . $ z_stream_s#avail_in.; /* don't count buffered input */
486 return offset;
487 }
488
489 /* -- see zlib.h -- */
490 z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`! ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzoffsetcxx . . $ gzoffset(84882b272d5a8a2f).(gzFilecxx . . $ gzFile# file) {
491 z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`! ret;
492
493 ret = gzoffset64cxx . . $ gzoffset64(84882b272d5a8a2f).(file);
494 return ret == (z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`!)ret ? (z_off_tcxx . . $ `<external>/116306602880328527/zconf.h:495:15`!)ret : -1;
495 }
496
497 /* -- see zlib.h -- */
498 int ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzeofcxx . . $ gzeof(4d4947b8d23ad0c4).(gzFilecxx . . $ gzFile# file) {
499 gz_statepcxx . . $ gz_statep# state;
500
501 /* get internal structure and check integrity */
502 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
503 return 0;
504 state = (gz_statepcxx . . $ gz_statep#)file;
505 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
506 return 0;
507
508 /* return end-of-file state */
509 return state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! ? state->pastcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#past. : 0;
510 }
511
512 /* -- see zlib.h -- */
513 const char * ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzerrorcxx . . $ gzerror(57e2cfef56dee254).(gzFilecxx . . $ gzFile# file, int *errnum) {
514 gz_statepcxx . . $ gz_statep# state;
515
516 /* get internal structure and check integrity */
517 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
518 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
519 state = (gz_statepcxx . . $ gz_statep#)file;
520 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
521 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
522
523 /* return error information */
524 if (errnum != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
525 *errnum = state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err.;
526 return state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. == Z_MEM_ERRORcxx . . $ `external/zlib/zlib.h:188:9`! ? "out of memory" :
527 (state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? "" : state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg.);
528 }
529
530 /* -- see zlib.h -- */
531 void ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! gzclearerrcxx . . $ gzclearerr(97c5c64d4d242386).(gzFilecxx . . $ gzFile# file) {
532 gz_statepcxx . . $ gz_statep# state;
533
534 /* get internal structure and check integrity */
535 if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
536 return;
537 state = (gz_statepcxx . . $ gz_statep#)file;
538 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`! && state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. != GZ_WRITEcxx . . $ `external/zlib/gzguts.h:161:9`!)
539 return;
540
541 /* clear error and end-of-file */
542 if (state->modecxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#mode. == GZ_READcxx . . $ `external/zlib/gzguts.h:160:9`!) {
543 state->eofcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#eof. = 0;
544 state->pastcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#past. = 0;
545 }
546 gz_errorcxx . . $ gz_error(b3e12012326d2820).(state, Z_OKcxx . . $ `external/zlib/zlib.h:182:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
547 }
548
549 /* Create an error message in allocated memory and set state->err and
550 state->msg accordingly. Free any previous error message already there. Do
551 not try to free or allocate space if the error is Z_MEM_ERROR (out of
552 memory). Simply save the error message as a static string. If there is an
553 allocation failure constructing the error message, then convert the error to
554 out of memory. */
555 void ZLIB_INTERNALcxx . . $ `external/zlib/gzguts.h:17:11`! gz_errorcxx . . $ gz_error(b3e12012326d2820).(gz_statepcxx . . $ gz_statep# state, int err, const char *msg) {
556 /* free previously allocated message and clear */
557 if (state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
558 if (state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. != Z_MEM_ERRORcxx . . $ `external/zlib/zlib.h:188:9`!)
559 freecxx . . $ free(5d22bdacc48458e8).(state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg.);
560 state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
561 }
562
563 /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
564 if (err != Z_OKcxx . . $ `external/zlib/zlib.h:182:9`! && err != Z_BUF_ERRORcxx . . $ `external/zlib/zlib.h:189:9`! && !state->againcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#again.)
565 state->xcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#x..havecxx . . $ gzFile_s#have. = 0;
566
567 /* set error code, and if no message, then done */
568 state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. = err;
569 if (msg == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
570 return;
571
572 /* for an out of memory error, return literal string when requested */
573 if (err == Z_MEM_ERRORcxx . . $ `external/zlib/zlib.h:188:9`!)
574 return;
575
576 /* construct error message with path */
577 if ((state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg. = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path.) + strlencxx . . $ strlen(751346f8406fd082).(msg) + 3)) ==
578 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
579 state->errcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#err. = Z_MEM_ERRORcxx . . $ `external/zlib/zlib.h:188:9`!;
580 return;
581 }
582 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
583 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(state->msgcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#msg., strlencxx . . $ strlen(751346f8406fd082).(state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path.) + strlencxx . . $ strlen(751346f8406fd082).(msg) + 3,
584 "%s%s%s", state->pathcxx . . $ $anonymous_type_bcfb4b0c61b213ca_0#path., ": ", msg);
585 #else
586 strcpy(state->msg, state->path);
587 strcat(state->msg, ": ");
588 strcat(state->msg, msg);
589 #endif
590 }
591
592 /* portably return maximum value for an int (when limits.h presumed not
593 available) -- we need to do this to cover cases where 2's complement not
594 used, since C standard permits 1's complement and sign-bit representations,
595 otherwise we could just use ((unsigned)-1) >> 1 */
596 unsigned ZLIB_INTERNALcxx . . $ `external/zlib/gzguts.h:17:11`! gz_intmaxcxx . . $ gz_intmax(db52760e79bf9054).(void) {
597 #ifdef INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!
598 return INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
599 #else
600 unsigned p = 1, q;
601
602 do {
603 q = p;
604 p <<= 1;
605 p++;
606 } while (p > q);
607 return q >> 1;
608 #endif
609 }