Debian Codegraph @

mz_strm.c

raw symbols SCIP
1 /* mz_strm.c -- Stream interface
2 part of the minizip-ng project
3
4 Copyright (C) Nathan Moinvaziri
5 https://github.com/zlib-ng/minizip-ng
6
7 This program is distributed under the terms of the same license as zlib.
8 See the accompanying LICENSE file for the full text of the license.
9 */
10
11 #include "mz.h"cxx . . $ `<file>/mz.h`/
12 #include "mz_strm.h"cxx . . $ `<file>/mz_strm.h`/
13
14 /***************************************************************************/
15
16 #define MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`! (1024)
17
18 /***************************************************************************/
19
20 int32_tcxx . . $ int32_t# mz_stream_opencxx . . $ mz_stream_open(7083a8984c0735e8).(void *stream, const char *path, int32_tcxx . . $ int32_t# mode) {
21 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
22 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->opencxx . . $ mz_stream_vtbl_s#open.)
23 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
24 return strm->vtblcxx . . $ mz_stream_s#vtbl.->opencxx . . $ mz_stream_vtbl_s#open.(strm, path, mode);
25 }
26
27 int32_tcxx . . $ int32_t# mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(void *stream) {
28 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
29 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->is_opencxx . . $ mz_stream_vtbl_s#is_open.)
30 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
31 return strm->vtblcxx . . $ mz_stream_s#vtbl.->is_opencxx . . $ mz_stream_vtbl_s#is_open.(strm);
32 }
33
34 int32_tcxx . . $ int32_t# mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(void *stream, void *buf, int32_tcxx . . $ int32_t# size) {
35 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
36 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->readcxx . . $ mz_stream_vtbl_s#read.)
37 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
38 if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(stream) != MZ_OKcxx . . $ `mz.h:21:9`!)
39 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
40 return strm->vtblcxx . . $ mz_stream_s#vtbl.->readcxx . . $ mz_stream_vtbl_s#read.(strm, buf, size);
41 }
42
43 static int32_tcxx . . $ int32_t# mz_stream_read_valuecxx . . $ mz_stream_read_value(3a20a63c699037e7).(void *stream, uint64_tcxx . . $ uint64_t# *value, int32_tcxx . . $ int32_t# len) {
44 uint8_tcxx . . $ uint8_t# buf[8];
45 int32_tcxx . . $ int32_t# n = 0;
46 int32_tcxx . . $ int32_t# i = 0;
47
48 *value = 0;
49 if (mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(stream, buf, len) == len) {
50 for (n = 0; n < len; n += 1, i += 8)
51 *value += ((uint64_tcxx . . $ uint64_t#)buf[n]) << i;
52 } else if (mz_stream_errorcxx . . $ mz_stream_error(dedf1e9b1c614a07).(stream))
53 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
54 else
55 return MZ_END_OF_STREAMcxx . . $ `mz.h:29:9`!;
56
57 return MZ_OKcxx . . $ `mz.h:21:9`!;
58 }
59
60 int32_tcxx . . $ int32_t# mz_stream_read_uint8cxx . . $ mz_stream_read_uint8(1d53cd22b884299b).(void *stream, uint8_tcxx . . $ uint8_t# *value) {
61 int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!;
62 uint64_tcxx . . $ uint64_t# value64 = 0;
63
64 *value = 0;
65 err = mz_stream_read_valuecxx . . $ mz_stream_read_value(3a20a63c699037e7).(stream, &value64, sizeof(uint8_tcxx . . $ uint8_t#));
66 if (err == MZ_OKcxx . . $ `mz.h:21:9`!)
67 *value = (uint8_tcxx . . $ uint8_t#)value64;
68 return err;
69 }
70
71 int32_tcxx . . $ int32_t# mz_stream_read_uint16cxx . . $ mz_stream_read_uint16(900c00eb402c9863).(void *stream, uint16_tcxx . . $ uint16_t# *value) {
72 int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!;
73 uint64_tcxx . . $ uint64_t# value64 = 0;
74
75 *value = 0;
76 err = mz_stream_read_valuecxx . . $ mz_stream_read_value(3a20a63c699037e7).(stream, &value64, sizeof(uint16_tcxx . . $ uint16_t#));
77 if (err == MZ_OKcxx . . $ `mz.h:21:9`!)
78 *value = (uint16_tcxx . . $ uint16_t#)value64;
79 return err;
80 }
81
82 int32_tcxx . . $ int32_t# mz_stream_read_uint32cxx . . $ mz_stream_read_uint32(3569d74970a1d1f9).(void *stream, uint32_tcxx . . $ uint32_t# *value) {
83 int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!;
84 uint64_tcxx . . $ uint64_t# value64 = 0;
85
86 *value = 0;
87 err = mz_stream_read_valuecxx . . $ mz_stream_read_value(3a20a63c699037e7).(stream, &value64, sizeof(uint32_tcxx . . $ uint32_t#));
88 if (err == MZ_OKcxx . . $ `mz.h:21:9`!)
89 *value = (uint32_tcxx . . $ uint32_t#)value64;
90 return err;
91 }
92
93 int32_tcxx . . $ int32_t# mz_stream_read_int64cxx . . $ mz_stream_read_int64(3c3380c49b0234ac).(void *stream, int64_tcxx . . $ int64_t# *value) {
94 return mz_stream_read_valuecxx . . $ mz_stream_read_value(3a20a63c699037e7).(stream, (uint64_tcxx . . $ uint64_t# *)value, sizeof(uint64_tcxx . . $ uint64_t#));
95 }
96
97 int32_tcxx . . $ int32_t# mz_stream_read_uint64cxx . . $ mz_stream_read_uint64(17c9a57913c314f0).(void *stream, uint64_tcxx . . $ uint64_t# *value) {
98 return mz_stream_read_valuecxx . . $ mz_stream_read_value(3a20a63c699037e7).(stream, value, sizeof(uint64_tcxx . . $ uint64_t#));
99 }
100
101 int32_tcxx . . $ int32_t# mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(void *stream, const void *buf, int32_tcxx . . $ int32_t# size) {
102 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
103 if (size == 0)
104 return size;
105 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->writecxx . . $ mz_stream_vtbl_s#write.)
106 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
107 if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(stream) != MZ_OKcxx . . $ `mz.h:21:9`!)
108 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
109 return strm->vtblcxx . . $ mz_stream_s#vtbl.->writecxx . . $ mz_stream_vtbl_s#write.(strm, buf, size);
110 }
111
112 static int32_tcxx . . $ int32_t# mz_stream_write_valuecxx . . $ mz_stream_write_value(e72f86de37bb8b46).(void *stream, uint64_tcxx . . $ uint64_t# value, int32_tcxx . . $ int32_t# len) {
113 uint8_tcxx . . $ uint8_t# buf[8];
114 int32_tcxx . . $ int32_t# n = 0;
115
116 for (n = 0; n < len; n += 1) {
117 buf[n] = (uint8_tcxx . . $ uint8_t#)(value & 0xff);
118 value >>= 8;
119 }
120
121 if (value != 0) {
122 /* Data overflow - hack for ZIP64 (X Roche) */
123 for (n = 0; n < len; n += 1)
124 buf[n] = 0xff;
125 }
126
127 if (mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(stream, buf, len) != len)
128 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
129
130 return MZ_OKcxx . . $ `mz.h:21:9`!;
131 }
132
133 int32_tcxx . . $ int32_t# mz_stream_write_uint8cxx . . $ mz_stream_write_uint8(5276b51c10b71c09).(void *stream, uint8_tcxx . . $ uint8_t# value) {
134 return mz_stream_write_valuecxx . . $ mz_stream_write_value(e72f86de37bb8b46).(stream, value, sizeof(uint8_tcxx . . $ uint8_t#));
135 }
136
137 int32_tcxx . . $ int32_t# mz_stream_write_uint16cxx . . $ mz_stream_write_uint16(f805ef7ae580f896).(void *stream, uint16_tcxx . . $ uint16_t# value) {
138 return mz_stream_write_valuecxx . . $ mz_stream_write_value(e72f86de37bb8b46).(stream, value, sizeof(uint16_tcxx . . $ uint16_t#));
139 }
140
141 int32_tcxx . . $ int32_t# mz_stream_write_uint32cxx . . $ mz_stream_write_uint32(6fe7d876f9648735).(void *stream, uint32_tcxx . . $ uint32_t# value) {
142 return mz_stream_write_valuecxx . . $ mz_stream_write_value(e72f86de37bb8b46).(stream, value, sizeof(uint32_tcxx . . $ uint32_t#));
143 }
144
145 int32_tcxx . . $ int32_t# mz_stream_write_int64cxx . . $ mz_stream_write_int64(6b20ed9d0f5b4b14).(void *stream, int64_tcxx . . $ int64_t# value) {
146 return mz_stream_write_valuecxx . . $ mz_stream_write_value(e72f86de37bb8b46).(stream, (uint64_tcxx . . $ uint64_t#)value, sizeof(uint64_tcxx . . $ uint64_t#));
147 }
148
149 int32_tcxx . . $ int32_t# mz_stream_write_uint64cxx . . $ mz_stream_write_uint64(c0a5f96701d3f89).(void *stream, uint64_tcxx . . $ uint64_t# value) {
150 return mz_stream_write_valuecxx . . $ mz_stream_write_value(e72f86de37bb8b46).(stream, value, sizeof(uint64_tcxx . . $ uint64_t#));
151 }
152
153 int32_tcxx . . $ int32_t# mz_stream_copycxx . . $ mz_stream_copy(8bc41909eac9e5d8).(void *target, void *source, int32_tcxx . . $ int32_t# len) {
154 return mz_stream_copy_streamcxx . . $ mz_stream_copy_stream(956b84005340d103).(target, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, source, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, len);
155 }
156
157 int32_tcxx . . $ int32_t# mz_stream_copy_to_endcxx . . $ mz_stream_copy_to_end(361d5d7064a2a85d).(void *target, void *source) {
158 return mz_stream_copy_stream_to_endcxx . . $ mz_stream_copy_stream_to_end(1b098803addc636d).(target, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, source, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
159 }
160
161 int32_tcxx . . $ int32_t# mz_stream_copy_streamcxx . . $ mz_stream_copy_stream(956b84005340d103).(void *target, mz_stream_write_cbcxx . . $ mz_stream_write_cb# write_cb, void *source, mz_stream_read_cbcxx . . $ mz_stream_read_cb# read_cb,
162 int32_tcxx . . $ int32_t# len) {
163 uint8_tcxx . . $ uint8_t# buf[16384];
164 int32_tcxx . . $ int32_t# bytes_to_copy = 0;
165 int32_tcxx . . $ int32_t# read = 0;
166 int32_tcxx . . $ int32_t# written = 0;
167
168 if (!write_cb)
169 write_cb = mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).;
170 if (!read_cb)
171 read_cb = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).;
172
173 while (len > 0) {
174 bytes_to_copy = len;
175 if (bytes_to_copy > (int32_tcxx . . $ int32_t#)sizeof(buf))
176 bytes_to_copy = sizeof(buf);
177 read = read_cb(source, buf, bytes_to_copy);
178 if (read <= 0)
179 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
180 written = write_cb(target, buf, read);
181 if (written != read)
182 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
183 len -= read;
184 }
185
186 return MZ_OKcxx . . $ `mz.h:21:9`!;
187 }
188
189 int32_tcxx . . $ int32_t# mz_stream_copy_stream_to_endcxx . . $ mz_stream_copy_stream_to_end(1b098803addc636d).(void *target, mz_stream_write_cbcxx . . $ mz_stream_write_cb# write_cb, void *source,
190 mz_stream_read_cbcxx . . $ mz_stream_read_cb# read_cb) {
191 uint8_tcxx . . $ uint8_t# buf[16384];
192 int32_tcxx . . $ int32_t# read = 0;
193 int32_tcxx . . $ int32_t# written = 0;
194
195 if (!write_cb)
196 write_cb = mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).;
197 if (!read_cb)
198 read_cb = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).;
199
200 read = read_cb(source, buf, sizeof(buf));
201 while (read > 0) {
202 written = write_cb(target, buf, read);
203 if (written != read)
204 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
205 read = read_cb(source, buf, sizeof(buf));
206 }
207
208 if (read < 0)
209 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
210
211 return MZ_OKcxx . . $ `mz.h:21:9`!;
212 }
213
214 int64_tcxx . . $ int64_t# mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(void *stream) {
215 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
216 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->tellcxx . . $ mz_stream_vtbl_s#tell.)
217 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
218 if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(stream) != MZ_OKcxx . . $ `mz.h:21:9`!)
219 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
220 return strm->vtblcxx . . $ mz_stream_s#vtbl.->tellcxx . . $ mz_stream_vtbl_s#tell.(strm);
221 }
222
223 int32_tcxx . . $ int32_t# mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(void *stream, int64_tcxx . . $ int64_t# offset, int32_tcxx . . $ int32_t# origin) {
224 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
225 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->seekcxx . . $ mz_stream_vtbl_s#seek.)
226 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
227 if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(stream) != MZ_OKcxx . . $ `mz.h:21:9`!)
228 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
229 if (origin == MZ_SEEK_SETcxx . . $ `mz.h:58:9`! && offset < 0)
230 return MZ_SEEK_ERRORcxx . . $ `mz.h:42:9`!;
231 return strm->vtblcxx . . $ mz_stream_s#vtbl.->seekcxx . . $ mz_stream_vtbl_s#seek.(strm, offset, origin);
232 }
233
234 int32_tcxx . . $ int32_t# mz_stream_findcxx . . $ mz_stream_find(8aa461340cfae934).(void *stream, const void *find, int32_tcxx . . $ int32_t# find_size, int64_tcxx . . $ int64_t# max_seek, int64_tcxx . . $ int64_t# *position) {
235 uint8_tcxx . . $ uint8_t# buf[MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`!];
236 int32_tcxx . . $ int32_t# buf_pos = 0;
237 int32_tcxx . . $ int32_t# read_size = sizeof(buf);
238 int32_tcxx . . $ int32_t# read = 0;
239 int64_tcxx . . $ int64_t# read_pos = 0;
240 int64_tcxx . . $ int64_t# start_pos = 0;
241 int64_tcxx . . $ int64_t# disk_pos = 0;
242 int32_tcxx . . $ int32_t# i = 0;
243 uint8_tcxx . . $ uint8_t# first = 1;
244 int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!;
245
246 if (!stream || !find || !position)
247 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
248 if (find_size < 0 || find_size >= (int32_tcxx . . $ int32_t#)sizeof(buf))
249 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
250
251 *position = -1;
252
253 start_pos = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(stream);
254
255 while (read_pos < max_seek) {
256 if (read_size > (int32_tcxx . . $ int32_t#)(max_seek - read_pos - buf_pos) &&
257 (max_seek - read_pos - buf_pos) < (int64_tcxx . . $ int64_t#)sizeof(buf)) {
258 read_size = (int32_tcxx . . $ int32_t#)(max_seek - read_pos - buf_pos);
259 }
260
261 read = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(stream, buf + buf_pos, read_size);
262 if ((read <= 0) || (read + buf_pos < find_size))
263 break;
264
265 for (i = 0; i <= read + buf_pos - find_size; i += 1) {
266 if (memcmpcxx . . $ memcmp(36f949851efa3055).(&buf[i], find, find_size) != 0)
267 continue;
268
269 disk_pos = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(stream);
270
271 /* Seek to position on disk where the data was found */
272 err = mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(stream, disk_pos - ((int64_tcxx . . $ int64_t#)read + buf_pos - i), MZ_SEEK_SETcxx . . $ `mz.h:58:9`!);
273 if (err != MZ_OKcxx . . $ `mz.h:21:9`!)
274 return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!;
275
276 *position = start_pos + read_pos + i;
277 return MZ_OKcxx . . $ `mz.h:21:9`!;
278 }
279
280 if (first) {
281 read -= find_size;
282 read_size -= find_size;
283 buf_pos = find_size;
284 first = 0;
285 }
286
287 memmovecxx . . $ memmove(cc817cb175f282d).(buf, buf + read, find_size);
288 read_pos += read;
289 }
290
291 return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!;
292 }
293
294 int32_tcxx . . $ int32_t# mz_stream_find_reversecxx . . $ mz_stream_find_reverse(8aa461340cfae934).(void *stream, const void *find, int32_tcxx . . $ int32_t# find_size, int64_tcxx . . $ int64_t# max_seek, int64_tcxx . . $ int64_t# *position) {
295 uint8_tcxx . . $ uint8_t# buf[MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`!];
296 int32_tcxx . . $ int32_t# buf_pos = 0;
297 int32_tcxx . . $ int32_t# read_size = MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`!;
298 int64_tcxx . . $ int64_t# read_pos = 0;
299 int32_tcxx . . $ int32_t# read = 0;
300 int64_tcxx . . $ int64_t# start_pos = 0;
301 int64_tcxx . . $ int64_t# disk_pos = 0;
302 uint8_tcxx . . $ uint8_t# first = 1;
303 int32_tcxx . . $ int32_t# i = 0;
304 int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!;
305
306 if (!stream || !find || !position)
307 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
308 if (find_size < 0 || find_size >= (int32_tcxx . . $ int32_t#)sizeof(buf))
309 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
310
311 *position = -1;
312
313 start_pos = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(stream);
314
315 while (read_pos < max_seek) {
316 if (read_size > (int32_tcxx . . $ int32_t#)(max_seek - read_pos) && (max_seek - read_pos) < (int64_tcxx . . $ int64_t#)sizeof(buf))
317 read_size = (int32_tcxx . . $ int32_t#)(max_seek - read_pos);
318
319 if (mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(stream, start_pos - (read_pos + read_size), MZ_SEEK_SETcxx . . $ `mz.h:58:9`!) != MZ_OKcxx . . $ `mz.h:21:9`!)
320 break;
321 read = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(stream, buf, read_size);
322 if ((read <= 0) || (read + buf_pos < find_size))
323 break;
324 if (read + buf_pos < MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`!)
325 memmovecxx . . $ memmove(cc817cb175f282d).(buf + MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`! - (read + buf_pos), buf, read);
326
327 for (i = find_size; i <= (read + buf_pos); i += 1) {
328 if (memcmpcxx . . $ memcmp(36f949851efa3055).(&buf[MZ_STREAM_FIND_SIZEcxx . . $ `mz_strm.c:16:9`! - i], find, find_size) != 0)
329 continue;
330
331 disk_pos = mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(stream);
332
333 /* Seek to position on disk where the data was found */
334 err = mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(stream, disk_pos + buf_pos - i, MZ_SEEK_SETcxx . . $ `mz.h:58:9`!);
335 if (err != MZ_OKcxx . . $ `mz.h:21:9`!)
336 return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!;
337
338 *position = start_pos - (read_pos - buf_pos + i);
339 return MZ_OKcxx . . $ `mz.h:21:9`!;
340 }
341
342 if (first) {
343 read -= find_size;
344 read_size -= find_size;
345 buf_pos = find_size;
346 first = 0;
347 }
348
349 if (read == 0)
350 break;
351
352 memmovecxx . . $ memmove(cc817cb175f282d).(buf + read_size, buf, find_size);
353 read_pos += read;
354 }
355
356 return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!;
357 }
358
359 int32_tcxx . . $ int32_t# mz_stream_closecxx . . $ mz_stream_close(dedf1e9b1c614a07).(void *stream) {
360 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
361 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->closecxx . . $ mz_stream_vtbl_s#close.)
362 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
363 if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(stream) != MZ_OKcxx . . $ `mz.h:21:9`!)
364 return MZ_STREAM_ERRORcxx . . $ `mz.h:22:9`!;
365 return strm->vtblcxx . . $ mz_stream_s#vtbl.->closecxx . . $ mz_stream_vtbl_s#close.(strm);
366 }
367
368 int32_tcxx . . $ int32_t# mz_stream_errorcxx . . $ mz_stream_error(dedf1e9b1c614a07).(void *stream) {
369 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
370 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->errorcxx . . $ mz_stream_vtbl_s#error.)
371 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
372 return strm->vtblcxx . . $ mz_stream_s#vtbl.->errorcxx . . $ mz_stream_vtbl_s#error.(strm);
373 }
374
375 int32_tcxx . . $ int32_t# mz_stream_set_basecxx . . $ mz_stream_set_base(361d5d7064a2a85d).(void *stream, void *base) {
376 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
377 strm->basecxx . . $ mz_stream_s#base. = (mz_streamcxx . . $ mz_stream# *)base;
378 return MZ_OKcxx . . $ `mz.h:21:9`!;
379 }
380
381 void *mz_stream_get_interfacecxx . . $ mz_stream_get_interface(9f162e79bfc6c74).(void *stream) {
382 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
383 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl.)
384 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
385 return (void *)strm->vtblcxx . . $ mz_stream_s#vtbl.;
386 }
387
388 int32_tcxx . . $ int32_t# mz_stream_get_prop_int64cxx . . $ mz_stream_get_prop_int64(280df70541557ec8).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# *value) {
389 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
390 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->get_prop_int64cxx . . $ mz_stream_vtbl_s#get_prop_int64.)
391 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
392 return strm->vtblcxx . . $ mz_stream_s#vtbl.->get_prop_int64cxx . . $ mz_stream_vtbl_s#get_prop_int64.(stream, prop, value);
393 }
394
395 int32_tcxx . . $ int32_t# mz_stream_set_prop_int64cxx . . $ mz_stream_set_prop_int64(5f4b2ff0df22ef2b).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# value) {
396 mz_streamcxx . . $ mz_stream# *strm = (mz_streamcxx . . $ mz_stream# *)stream;
397 if (!strm || !strm->vtblcxx . . $ mz_stream_s#vtbl. || !strm->vtblcxx . . $ mz_stream_s#vtbl.->set_prop_int64cxx . . $ mz_stream_vtbl_s#set_prop_int64.)
398 return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!;
399 return strm->vtblcxx . . $ mz_stream_s#vtbl.->set_prop_int64cxx . . $ mz_stream_vtbl_s#set_prop_int64.(stream, prop, value);
400 }
401
402 void *mz_stream_createcxx . . $ mz_stream_create(f660b63577525b91).(mz_stream_vtblcxx . . $ mz_stream_vtbl# *vtbl) {
403 if (!vtbl || !vtbl->createcxx . . $ mz_stream_vtbl_s#create.)
404 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
405 return vtbl->createcxx . . $ mz_stream_vtbl_s#create.();
406 }
407
408 void mz_stream_deletecxx . . $ mz_stream_delete(539e082cf00e1f43).(void **stream) {
409 mz_streamcxx . . $ mz_stream# *strm = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
410 if (!stream)
411 return;
412 strm = (mz_streamcxx . . $ mz_stream# *)*stream;
413 if (strm && strm->vtblcxx . . $ mz_stream_s#vtbl. && strm->vtblcxx . . $ mz_stream_s#vtbl.->destroycxx . . $ mz_stream_vtbl_s#destroy.)
414 strm->vtblcxx . . $ mz_stream_s#vtbl.->destroycxx . . $ mz_stream_vtbl_s#destroy.(stream);
415 *stream = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
416 }
417
418 /***************************************************************************/
419
420 typedef struct mz_stream_raw_scxx . . $ mz_stream_raw_s# {
421 mz_streamcxx . . $ mz_stream# streamcxx . . $ mz_stream_raw_s#stream.;
422 int64_tcxx . . $ int64_t# total_incxx . . $ mz_stream_raw_s#total_in.;
423 int64_tcxx . . $ int64_t# total_outcxx . . $ mz_stream_raw_s#total_out.;
424 int64_tcxx . . $ int64_t# max_total_incxx . . $ mz_stream_raw_s#max_total_in.;
425 } mz_stream_rawcxx . . $ mz_stream_raw#;
426
427 /***************************************************************************/
428
429 int32_tcxx . . $ int32_t# mz_stream_raw_opencxx . . $ mz_stream_raw_open(7083a8984c0735e8).(void *stream, const char *path, int32_tcxx . . $ int32_t# mode) {
430 MZ_UNUSEDcxx . . $ `mz.h:147:9`!(stream);
431 MZ_UNUSEDcxx . . $ `mz.h:147:9`!(path);
432 MZ_UNUSEDcxx . . $ `mz.h:147:9`!(mode);
433
434 return MZ_OKcxx . . $ `mz.h:21:9`!;
435 }
436
437 int32_tcxx . . $ int32_t# mz_stream_raw_is_opencxx . . $ mz_stream_raw_is_open(dedf1e9b1c614a07).(void *stream) {
438 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
439 return mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(raw->streamcxx . . $ mz_stream_raw_s#stream..basecxx . . $ mz_stream_s#base.);
440 }
441
442 int32_tcxx . . $ int32_t# mz_stream_raw_readcxx . . $ mz_stream_raw_read(8bc41909eac9e5d8).(void *stream, void *buf, int32_tcxx . . $ int32_t# size) {
443 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
444 int32_tcxx . . $ int32_t# bytes_to_read = size;
445 int32_tcxx . . $ int32_t# read = 0;
446
447 if (raw->max_total_incxx . . $ mz_stream_raw_s#max_total_in. > 0) {
448 if ((int64_tcxx . . $ int64_t#)bytes_to_read > (raw->max_total_incxx . . $ mz_stream_raw_s#max_total_in. - raw->total_incxx . . $ mz_stream_raw_s#total_in.))
449 bytes_to_read = (int32_tcxx . . $ int32_t#)(raw->max_total_incxx . . $ mz_stream_raw_s#max_total_in. - raw->total_incxx . . $ mz_stream_raw_s#total_in.);
450 }
451
452 read = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(raw->streamcxx . . $ mz_stream_raw_s#stream..basecxx . . $ mz_stream_s#base., buf, bytes_to_read);
453
454 if (read > 0) {
455 raw->total_incxx . . $ mz_stream_raw_s#total_in. += read;
456 raw->total_outcxx . . $ mz_stream_raw_s#total_out. += read;
457 }
458
459 return read;
460 }
461
462 int32_tcxx . . $ int32_t# mz_stream_raw_writecxx . . $ mz_stream_raw_write(91e54fd90adbb21).(void *stream, const void *buf, int32_tcxx . . $ int32_t# size) {
463 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
464 int32_tcxx . . $ int32_t# written = 0;
465
466 written = mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(raw->streamcxx . . $ mz_stream_raw_s#stream..basecxx . . $ mz_stream_s#base., buf, size);
467
468 if (written > 0) {
469 raw->total_outcxx . . $ mz_stream_raw_s#total_out. += written;
470 raw->total_incxx . . $ mz_stream_raw_s#total_in. += written;
471 }
472
473 return written;
474 }
475
476 int64_tcxx . . $ int64_t# mz_stream_raw_tellcxx . . $ mz_stream_raw_tell(72c1818a5177f981).(void *stream) {
477 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
478 return mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(raw->streamcxx . . $ mz_stream_raw_s#stream..basecxx . . $ mz_stream_s#base.);
479 }
480
481 int32_tcxx . . $ int32_t# mz_stream_raw_seekcxx . . $ mz_stream_raw_seek(8bc0ff128761c75d).(void *stream, int64_tcxx . . $ int64_t# offset, int32_tcxx . . $ int32_t# origin) {
482 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
483 return mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(raw->streamcxx . . $ mz_stream_raw_s#stream..basecxx . . $ mz_stream_s#base., offset, origin);
484 }
485
486 int32_tcxx . . $ int32_t# mz_stream_raw_closecxx . . $ mz_stream_raw_close(dedf1e9b1c614a07).(void *stream) {
487 MZ_UNUSEDcxx . . $ `mz.h:147:9`!(stream);
488 return MZ_OKcxx . . $ `mz.h:21:9`!;
489 }
490
491 int32_tcxx . . $ int32_t# mz_stream_raw_errorcxx . . $ mz_stream_raw_error(dedf1e9b1c614a07).(void *stream) {
492 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
493 return mz_stream_errorcxx . . $ mz_stream_error(dedf1e9b1c614a07).(raw->streamcxx . . $ mz_stream_raw_s#stream..basecxx . . $ mz_stream_s#base.);
494 }
495
496 int32_tcxx . . $ int32_t# mz_stream_raw_get_prop_int64cxx . . $ mz_stream_raw_get_prop_int64(280df70541557ec8).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# *value) {
497 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
498 switch (prop) {
499 case MZ_STREAM_PROP_TOTAL_INcxx . . $ `mz_strm.h:20:9`!:
500 *value = raw->total_incxx . . $ mz_stream_raw_s#total_in.;
501 return MZ_OKcxx . . $ `mz.h:21:9`!;
502 case MZ_STREAM_PROP_TOTAL_OUTcxx . . $ `mz_strm.h:22:9`!:
503 *value = raw->total_outcxx . . $ mz_stream_raw_s#total_out.;
504 return MZ_OKcxx . . $ `mz.h:21:9`!;
505 }
506 return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!;
507 }
508
509 int32_tcxx . . $ int32_t# mz_stream_raw_set_prop_int64cxx . . $ mz_stream_raw_set_prop_int64(5f4b2ff0df22ef2b).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# value) {
510 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)stream;
511 switch (prop) {
512 case MZ_STREAM_PROP_TOTAL_IN_MAXcxx . . $ `mz_strm.h:21:9`!:
513 raw->max_total_incxx . . $ mz_stream_raw_s#max_total_in. = value;
514 return MZ_OKcxx . . $ `mz.h:21:9`!;
515 }
516 return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!;
517 }
518
519 /***************************************************************************/
520
521 static mz_stream_vtblcxx . . $ mz_stream_vtbl# mz_stream_raw_vtblcxx . . $ mz_stream_raw_vtbl. = {
522 mz_stream_raw_opencxx . . $ mz_stream_raw_open(7083a8984c0735e8)., mz_stream_raw_is_opencxx . . $ mz_stream_raw_is_open(dedf1e9b1c614a07)., mz_stream_raw_readcxx . . $ mz_stream_raw_read(8bc41909eac9e5d8)., mz_stream_raw_writecxx . . $ mz_stream_raw_write(91e54fd90adbb21).,
523 mz_stream_raw_tellcxx . . $ mz_stream_raw_tell(72c1818a5177f981)., mz_stream_raw_seekcxx . . $ mz_stream_raw_seek(8bc0ff128761c75d)., mz_stream_raw_closecxx . . $ mz_stream_raw_close(dedf1e9b1c614a07)., mz_stream_raw_errorcxx . . $ mz_stream_raw_error(dedf1e9b1c614a07).,
524 mz_stream_raw_createcxx . . $ mz_stream_raw_create(50c7df7de5344ebb)., mz_stream_raw_deletecxx . . $ mz_stream_raw_delete(539e082cf00e1f43)., mz_stream_raw_get_prop_int64cxx . . $ mz_stream_raw_get_prop_int64(280df70541557ec8)., mz_stream_raw_set_prop_int64cxx . . $ mz_stream_raw_set_prop_int64(5f4b2ff0df22ef2b).};
525
526 /***************************************************************************/
527
528 void *mz_stream_raw_createcxx . . $ mz_stream_raw_create(50c7df7de5344ebb).(void) {
529 mz_stream_rawcxx . . $ mz_stream_raw# *raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(mz_stream_rawcxx . . $ mz_stream_raw#));
530 if (raw)
531 raw->streamcxx . . $ mz_stream_raw_s#stream..vtblcxx . . $ mz_stream_s#vtbl. = &mz_stream_raw_vtblcxx . . $ mz_stream_raw_vtbl.;
532 return raw;
533 }
534
535 void mz_stream_raw_deletecxx . . $ mz_stream_raw_delete(539e082cf00e1f43).(void **stream) {
536 mz_stream_rawcxx . . $ mz_stream_raw# *raw = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
537 if (!stream)
538 return;
539 raw = (mz_stream_rawcxx . . $ mz_stream_raw# *)*stream;
540 freecxx . . $ free(5d22bdacc48458e8).(raw);
541 *stream = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
542 }