diff options
Diffstat (limited to 'src/common/unzip.c')
-rw-r--r-- | src/common/unzip.c | 328 |
1 files changed, 164 insertions, 164 deletions
diff --git a/src/common/unzip.c b/src/common/unzip.c index 749d783..0de7778 100644 --- a/src/common/unzip.c +++ b/src/common/unzip.c | |||
@@ -21,7 +21,7 @@ | |||
21 | * @file common/unzip.c | 21 | * @file common/unzip.c |
22 | * @brief API to access ZIP archives | 22 | * @brief API to access ZIP archives |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * | 24 | * |
25 | * This code is based in part on | 25 | * This code is based in part on |
26 | * unzip 1.00 Copyright 1998-2003 Gilles Vollant | 26 | * unzip 1.00 Copyright 1998-2003 Gilles Vollant |
27 | * http://www.winimage.com/zLibDll" | 27 | * http://www.winimage.com/zLibDll" |
@@ -39,7 +39,7 @@ | |||
39 | * | 39 | * |
40 | * This assumes that the zip file is considered to be non-corrupt/non-truncated. | 40 | * This assumes that the zip file is considered to be non-corrupt/non-truncated. |
41 | * If it is truncated then it's not considered to be a zip and skipped. | 41 | * If it is truncated then it's not considered to be a zip and skipped. |
42 | * | 42 | * |
43 | * ZIP format description from appnote.iz and appnote.txt (more or less): | 43 | * ZIP format description from appnote.iz and appnote.txt (more or less): |
44 | * | 44 | * |
45 | * (this is why you always need to put in the last floppy if you span disks) | 45 | * (this is why you always need to put in the last floppy if you span disks) |
@@ -137,21 +137,21 @@ struct FileFuncDefs | |||
137 | 137 | ||
138 | /** | 138 | /** |
139 | * Global data about the ZIPfile | 139 | * Global data about the ZIPfile |
140 | * These data comes from the end of central dir | 140 | * These data comes from the end of central dir |
141 | */ | 141 | */ |
142 | struct GlobalInfo | 142 | struct GlobalInfo |
143 | { | 143 | { |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * total number of entries in | 146 | * total number of entries in |
147 | * the central dir on this disk | 147 | * the central dir on this disk |
148 | */ | 148 | */ |
149 | uLong number_entry; | 149 | uLong number_entry; |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * size of the global comment of the zipfile | 152 | * size of the global comment of the zipfile |
153 | */ | 153 | */ |
154 | uLong size_comment; | 154 | uLong size_comment; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * offset of the global comment in the zipfile | 157 | * offset of the global comment in the zipfile |
@@ -167,7 +167,7 @@ struct UnzipFileInfoInternal | |||
167 | { | 167 | { |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * relative offset of local header 4 bytes | 170 | * relative offset of local header 4 bytes |
171 | */ | 171 | */ |
172 | uLong offset_curfile; | 172 | uLong offset_curfile; |
173 | 173 | ||
@@ -181,69 +181,69 @@ struct UnzipFileInfoInternal | |||
181 | struct FileInZipReadInfo | 181 | struct FileInZipReadInfo |
182 | { | 182 | { |
183 | /** | 183 | /** |
184 | * internal buffer for compressed data | 184 | * internal buffer for compressed data |
185 | */ | 185 | */ |
186 | char *read_buffer; | 186 | char *read_buffer; |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * zLib stream structure for inflate | 189 | * zLib stream structure for inflate |
190 | */ | 190 | */ |
191 | z_stream stream; | 191 | z_stream stream; |
192 | 192 | ||
193 | /** | 193 | /** |
194 | * position in byte on the zipfile, for fseek | 194 | * position in byte on the zipfile, for fseek |
195 | */ | 195 | */ |
196 | uLong pos_in_zipfile; | 196 | uLong pos_in_zipfile; |
197 | 197 | ||
198 | /** | 198 | /** |
199 | * flag set if stream structure is initialised | 199 | * flag set if stream structure is initialised |
200 | */ | 200 | */ |
201 | uLong stream_initialised; | 201 | uLong stream_initialised; |
202 | 202 | ||
203 | /** | 203 | /** |
204 | * offset of the local extra field | 204 | * offset of the local extra field |
205 | */ | 205 | */ |
206 | uLong offset_local_extrafield; | 206 | uLong offset_local_extrafield; |
207 | 207 | ||
208 | /** | 208 | /** |
209 | * size of the local extra field | 209 | * size of the local extra field |
210 | */ | 210 | */ |
211 | uInt size_local_extrafield; | 211 | uInt size_local_extrafield; |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * position in the local extra field in read | 214 | * position in the local extra field in read |
215 | */ | 215 | */ |
216 | uLong pos_local_extrafield; | 216 | uLong pos_local_extrafield; |
217 | 217 | ||
218 | /** | 218 | /** |
219 | * crc32 of all data uncompressed so far | 219 | * crc32 of all data uncompressed so far |
220 | */ | 220 | */ |
221 | uLong crc32; | 221 | uLong crc32; |
222 | 222 | ||
223 | /** | 223 | /** |
224 | * crc32 we must obtain after decompress all | 224 | * crc32 we must obtain after decompress all |
225 | */ | 225 | */ |
226 | uLong crc32_wait; | 226 | uLong crc32_wait; |
227 | 227 | ||
228 | /** | 228 | /** |
229 | * number of bytes to be decompressed | 229 | * number of bytes to be decompressed |
230 | */ | 230 | */ |
231 | uLong rest_read_compressed; | 231 | uLong rest_read_compressed; |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * number of bytes to be obtained after decomp | 234 | * number of bytes to be obtained after decomp |
235 | */ | 235 | */ |
236 | uLong rest_read_uncompressed; | 236 | uLong rest_read_uncompressed; |
237 | 237 | ||
238 | /** | 238 | /** |
239 | * IO functions. | 239 | * IO functions. |
240 | */ | 240 | */ |
241 | struct FileFuncDefs z_filefunc; | 241 | struct FileFuncDefs z_filefunc; |
242 | 242 | ||
243 | /** | 243 | /** |
244 | * compression method (0==store) | 244 | * compression method (0==store) |
245 | */ | 245 | */ |
246 | uLong compression_method; | 246 | uLong compression_method; |
247 | 247 | ||
248 | /** | 248 | /** |
249 | * byte before the zipfile, (>0 for sfx) | 249 | * byte before the zipfile, (>0 for sfx) |
@@ -259,65 +259,65 @@ struct FileInZipReadInfo | |||
259 | struct EXTRACTOR_UnzipFile | 259 | struct EXTRACTOR_UnzipFile |
260 | { | 260 | { |
261 | /** | 261 | /** |
262 | * io structore of the zipfile | 262 | * io structore of the zipfile |
263 | */ | 263 | */ |
264 | struct FileFuncDefs z_filefunc; | 264 | struct FileFuncDefs z_filefunc; |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * public global information | 267 | * public global information |
268 | */ | 268 | */ |
269 | struct GlobalInfo gi; | 269 | struct GlobalInfo gi; |
270 | 270 | ||
271 | /** | 271 | /** |
272 | * byte before the zipfile, (>0 for sfx) | 272 | * byte before the zipfile, (>0 for sfx) |
273 | */ | 273 | */ |
274 | uLong byte_before_the_zipfile; | 274 | uLong byte_before_the_zipfile; |
275 | 275 | ||
276 | /** | 276 | /** |
277 | * number of the current file in the zipfile | 277 | * number of the current file in the zipfile |
278 | */ | 278 | */ |
279 | uLong num_file; | 279 | uLong num_file; |
280 | 280 | ||
281 | /** | 281 | /** |
282 | * pos of the current file in the central dir | 282 | * pos of the current file in the central dir |
283 | */ | 283 | */ |
284 | uLong pos_in_central_dir; | 284 | uLong pos_in_central_dir; |
285 | 285 | ||
286 | /** | 286 | /** |
287 | * flag about the usability of the current file | 287 | * flag about the usability of the current file |
288 | */ | 288 | */ |
289 | uLong current_file_ok; | 289 | uLong current_file_ok; |
290 | 290 | ||
291 | /** | 291 | /** |
292 | * position of the beginning of the central dir | 292 | * position of the beginning of the central dir |
293 | */ | 293 | */ |
294 | uLong central_pos; | 294 | uLong central_pos; |
295 | 295 | ||
296 | /** | 296 | /** |
297 | * size of the central directory | 297 | * size of the central directory |
298 | */ | 298 | */ |
299 | uLong size_central_dir; | 299 | uLong size_central_dir; |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * offset of start of central directory with respect to the starting | 302 | * offset of start of central directory with respect to the starting |
303 | * disk number | 303 | * disk number |
304 | */ | 304 | */ |
305 | uLong offset_central_dir; | 305 | uLong offset_central_dir; |
306 | 306 | ||
307 | /** | 307 | /** |
308 | * public info about the current file in zip | 308 | * public info about the current file in zip |
309 | */ | 309 | */ |
310 | struct EXTRACTOR_UnzipFileInfo cur_file_info; | 310 | struct EXTRACTOR_UnzipFileInfo cur_file_info; |
311 | 311 | ||
312 | /** | 312 | /** |
313 | * private info about it | 313 | * private info about it |
314 | */ | 314 | */ |
315 | struct UnzipFileInfoInternal cur_file_info_internal; | 315 | struct UnzipFileInfoInternal cur_file_info_internal; |
316 | 316 | ||
317 | /** | 317 | /** |
318 | * structure about the current file if we are decompressing it | 318 | * structure about the current file if we are decompressing it |
319 | */ | 319 | */ |
320 | struct FileInZipReadInfo *pfile_in_zip_read; | 320 | struct FileInZipReadInfo *pfile_in_zip_read; |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Is the file encrypted? | 323 | * Is the file encrypted? |
@@ -333,9 +333,9 @@ struct EXTRACTOR_UnzipFile | |||
333 | * | 333 | * |
334 | * @param ffd functions for performing IO operations | 334 | * @param ffd functions for performing IO operations |
335 | * @param pi where to store the byte that was read | 335 | * @param pi where to store the byte that was read |
336 | * @return EXTRACTOR_UNZIP_OK on success, or EXTRACTOR_UNZIP_EOF | 336 | * @return #EXTRACTOR_UNZIP_OK on success, or #EXTRACTOR_UNZIP_EOF |
337 | */ | 337 | */ |
338 | static int | 338 | static int |
339 | read_byte_from_ffd (const struct FileFuncDefs *ffd, | 339 | read_byte_from_ffd (const struct FileFuncDefs *ffd, |
340 | int *pi) | 340 | int *pi) |
341 | { | 341 | { |
@@ -355,23 +355,23 @@ read_byte_from_ffd (const struct FileFuncDefs *ffd, | |||
355 | * | 355 | * |
356 | * @param ffd functions for performing IO operations | 356 | * @param ffd functions for performing IO operations |
357 | * @param pi where to store the short that was read | 357 | * @param pi where to store the short that was read |
358 | * @return EXTRACTOR_UNZIP_OK on success, or EXTRACTOR_UNZIP_EOF | 358 | * @return #EXTRACTOR_UNZIP_OK on success, or #EXTRACTOR_UNZIP_EOF |
359 | */ | 359 | */ |
360 | static int | 360 | static int |
361 | read_short_from_ffd (const struct FileFuncDefs *ffd, | 361 | read_short_from_ffd (const struct FileFuncDefs *ffd, |
362 | uLong *pX) | 362 | uLong *pX) |
363 | { | 363 | { |
364 | uLong x; | 364 | uLong x; |
365 | int i; | 365 | int i; |
366 | int err; | 366 | int err; |
367 | 367 | ||
368 | *pX = 0; | 368 | *pX = 0; |
369 | if (EXTRACTOR_UNZIP_OK != (err = read_byte_from_ffd (ffd, &i))) | 369 | if (EXTRACTOR_UNZIP_OK != (err = read_byte_from_ffd (ffd, &i))) |
370 | return err; | 370 | return err; |
371 | x = (uLong) i; | 371 | x = (uLong) i; |
372 | if (EXTRACTOR_UNZIP_OK != (err = read_byte_from_ffd (ffd, &i))) | 372 | if (EXTRACTOR_UNZIP_OK != (err = read_byte_from_ffd (ffd, &i))) |
373 | return err; | 373 | return err; |
374 | x += ((uLong) i) << 8; | 374 | x += ((uLong) i) << 8; |
375 | *pX = x; | 375 | *pX = x; |
376 | return err; | 376 | return err; |
377 | } | 377 | } |
@@ -384,16 +384,16 @@ read_short_from_ffd (const struct FileFuncDefs *ffd, | |||
384 | * | 384 | * |
385 | * @param ffd functions for performing IO operations | 385 | * @param ffd functions for performing IO operations |
386 | * @param pi where to store the long that was read | 386 | * @param pi where to store the long that was read |
387 | * @return EXTRACTOR_UNZIP_OK on success, or EXTRACTOR_UNZIP_EOF | 387 | * @return #EXTRACTOR_UNZIP_OK on success, or #EXTRACTOR_UNZIP_EOF |
388 | */ | 388 | */ |
389 | static int | 389 | static int |
390 | read_long_from_ffd (const struct FileFuncDefs *ffd, | 390 | read_long_from_ffd (const struct FileFuncDefs *ffd, |
391 | uLong *pX) | 391 | uLong *pX) |
392 | { | 392 | { |
393 | uLong x; | 393 | uLong x; |
394 | int i; | 394 | int i; |
395 | int err; | 395 | int err; |
396 | 396 | ||
397 | *pX = 0; | 397 | *pX = 0; |
398 | if (EXTRACTOR_UNZIP_OK != (err = read_byte_from_ffd (ffd, &i))) | 398 | if (EXTRACTOR_UNZIP_OK != (err = read_byte_from_ffd (ffd, &i))) |
399 | return err; | 399 | return err; |
@@ -435,7 +435,7 @@ read_long_from_ffd (const struct FileFuncDefs *ffd, | |||
435 | * 0 for defaut of your operating system (like 1 on Unix, 2 on Windows) | 435 | * 0 for defaut of your operating system (like 1 on Unix, 2 on Windows) |
436 | * @return 0 if names are equal | 436 | * @return 0 if names are equal |
437 | */ | 437 | */ |
438 | static int | 438 | static int |
439 | EXTRACTOR_common_unzip_string_file_name_compare (const char* fileName1, | 439 | EXTRACTOR_common_unzip_string_file_name_compare (const char* fileName1, |
440 | const char* fileName2, | 440 | const char* fileName2, |
441 | int iCaseSensitivity) | 441 | int iCaseSensitivity) |
@@ -459,14 +459,14 @@ EXTRACTOR_common_unzip_string_file_name_compare (const char* fileName1, | |||
459 | * @param ffd IO functions | 459 | * @param ffd IO functions |
460 | * @return offset of central directory, 0 on error | 460 | * @return offset of central directory, 0 on error |
461 | */ | 461 | */ |
462 | static uLong | 462 | static uLong |
463 | locate_central_directory (const struct FileFuncDefs *ffd) | 463 | locate_central_directory (const struct FileFuncDefs *ffd) |
464 | { | 464 | { |
465 | unsigned char buf[BUFREADCOMMENT + 4]; | 465 | unsigned char buf[BUFREADCOMMENT + 4]; |
466 | uLong uSizeFile; | 466 | uLong uSizeFile; |
467 | uLong uBackRead; | 467 | uLong uBackRead; |
468 | uLong uMaxBack = 0xffff; /* maximum size of global comment */ | 468 | uLong uMaxBack = 0xffff; /* maximum size of global comment */ |
469 | 469 | ||
470 | if (0 != ZSEEK (*ffd, 0, SEEK_END)) | 470 | if (0 != ZSEEK (*ffd, 0, SEEK_END)) |
471 | return 0; | 471 | return 0; |
472 | uSizeFile = ZTELL (*ffd); | 472 | uSizeFile = ZTELL (*ffd); |
@@ -484,18 +484,18 @@ locate_central_directory (const struct FileFuncDefs *ffd) | |||
484 | else | 484 | else |
485 | uBackRead += BUFREADCOMMENT; | 485 | uBackRead += BUFREADCOMMENT; |
486 | uReadPos = uSizeFile - uBackRead; | 486 | uReadPos = uSizeFile - uBackRead; |
487 | uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) | 487 | uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) |
488 | ? (BUFREADCOMMENT + 4) | 488 | ? (BUFREADCOMMENT + 4) |
489 | : (uSizeFile - uReadPos); | 489 | : (uSizeFile - uReadPos); |
490 | if (0 != ZSEEK (*ffd, uReadPos, SEEK_SET)) | 490 | if (0 != ZSEEK (*ffd, uReadPos, SEEK_SET)) |
491 | break; | 491 | break; |
492 | if (ZREAD (*ffd, buf, uReadSize) != uReadSize) | 492 | if (ZREAD (*ffd, buf, uReadSize) != uReadSize) |
493 | break; | 493 | break; |
494 | i = (int) uReadSize - 3; | 494 | i = (int) uReadSize - 3; |
495 | while (i-- > 0) | 495 | while (i-- > 0) |
496 | if ( (0x50 == (*(buf+i))) && | 496 | if ( (0x50 == (*(buf+i))) && |
497 | (0x4b == (*(buf+i+1))) && | 497 | (0x4b == (*(buf+i+1))) && |
498 | (0x05 == (*(buf+i+2))) && | 498 | (0x05 == (*(buf+i+2))) && |
499 | (0x06 == (*(buf+i+3))) ) | 499 | (0x06 == (*(buf+i+3))) ) |
500 | return uReadPos + i; | 500 | return uReadPos + i; |
501 | } | 501 | } |
@@ -504,13 +504,13 @@ locate_central_directory (const struct FileFuncDefs *ffd) | |||
504 | 504 | ||
505 | 505 | ||
506 | /** | 506 | /** |
507 | * Translate date/time from Dos format to struct | 507 | * Translate date/time from Dos format to `struct |
508 | * EXTRACTOR_UnzipDateTimeInfo (readable more easilty) | 508 | * EXTRACTOR_UnzipDateTimeInfo` (readable more easilty) |
509 | * | 509 | * |
510 | * @param ulDosDate time in DOS format (input) | 510 | * @param ulDosDate time in DOS format (input) |
511 | * @param ptm where to write time in readable format | 511 | * @param ptm where to write time in readable format |
512 | */ | 512 | */ |
513 | static void | 513 | static void |
514 | dos_date_to_tmu_date (uLong ulDosDate, | 514 | dos_date_to_tmu_date (uLong ulDosDate, |
515 | struct EXTRACTOR_UnzipDateTimeInfo* ptm) | 515 | struct EXTRACTOR_UnzipDateTimeInfo* ptm) |
516 | { | 516 | { |
@@ -536,12 +536,12 @@ dos_date_to_tmu_date (uLong ulDosDate, | |||
536 | * @param szFileName where to write the name of the current file | 536 | * @param szFileName where to write the name of the current file |
537 | * @param fileNameBufferSize number of bytes available in szFileName | 537 | * @param fileNameBufferSize number of bytes available in szFileName |
538 | * @param extraField where to write extra data | 538 | * @param extraField where to write extra data |
539 | * @param extraFieldBufferSize number of bytes available in extraField | 539 | * @param extraFieldBufferSize number of bytes available in extraField |
540 | * @param szComment where to write the comment on the current file | 540 | * @param szComment where to write the comment on the current file |
541 | * @param commentBufferSize number of bytes available in szComment | 541 | * @param commentBufferSize number of bytes available in szComment |
542 | * @return EXTRACTOR_UNZIP_OK if there is no problem. | 542 | * @return #EXTRACTOR_UNZIP_OK if there is no problem. |
543 | */ | 543 | */ |
544 | static int | 544 | static int |
545 | get_current_file_info (struct EXTRACTOR_UnzipFile *file, | 545 | get_current_file_info (struct EXTRACTOR_UnzipFile *file, |
546 | struct EXTRACTOR_UnzipFileInfo *pfile_info, | 546 | struct EXTRACTOR_UnzipFileInfo *pfile_info, |
547 | struct UnzipFileInfoInternal *pfile_info_internal, | 547 | struct UnzipFileInfoInternal *pfile_info_internal, |
@@ -556,7 +556,7 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
556 | struct UnzipFileInfoInternal file_info_internal; | 556 | struct UnzipFileInfoInternal file_info_internal; |
557 | uLong uMagic; | 557 | uLong uMagic; |
558 | long lSeek = 0; | 558 | long lSeek = 0; |
559 | 559 | ||
560 | if (NULL == file) | 560 | if (NULL == file) |
561 | return EXTRACTOR_UNZIP_PARAMERROR; | 561 | return EXTRACTOR_UNZIP_PARAMERROR; |
562 | if (0 != ZSEEK (file->z_filefunc, | 562 | if (0 != ZSEEK (file->z_filefunc, |
@@ -619,14 +619,14 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
619 | } | 619 | } |
620 | else | 620 | else |
621 | uSizeRead = fileNameBufferSize; | 621 | uSizeRead = fileNameBufferSize; |
622 | 622 | ||
623 | if ( (file_info.size_filename > 0) && | 623 | if ( (file_info.size_filename > 0) && |
624 | (fileNameBufferSize > 0) ) | 624 | (fileNameBufferSize > 0) ) |
625 | if (ZREAD(file->z_filefunc, szFileName, uSizeRead) != uSizeRead) | 625 | if (ZREAD(file->z_filefunc, szFileName, uSizeRead) != uSizeRead) |
626 | return EXTRACTOR_UNZIP_ERRNO; | 626 | return EXTRACTOR_UNZIP_ERRNO; |
627 | lSeek -= uSizeRead; | 627 | lSeek -= uSizeRead; |
628 | } | 628 | } |
629 | 629 | ||
630 | if (NULL != extraField) | 630 | if (NULL != extraField) |
631 | { | 631 | { |
632 | uLong uSizeRead; | 632 | uLong uSizeRead; |
@@ -635,8 +635,8 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
635 | uSizeRead = file_info.size_file_extra; | 635 | uSizeRead = file_info.size_file_extra; |
636 | else | 636 | else |
637 | uSizeRead = extraFieldBufferSize; | 637 | uSizeRead = extraFieldBufferSize; |
638 | 638 | ||
639 | if (0 != lSeek) | 639 | if (0 != lSeek) |
640 | { | 640 | { |
641 | if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR)) | 641 | if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR)) |
642 | lSeek = 0; | 642 | lSeek = 0; |
@@ -644,8 +644,8 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
644 | return EXTRACTOR_UNZIP_ERRNO; | 644 | return EXTRACTOR_UNZIP_ERRNO; |
645 | } | 645 | } |
646 | if ( (file_info.size_file_extra > 0) && | 646 | if ( (file_info.size_file_extra > 0) && |
647 | (extraFieldBufferSize > 0) && | 647 | (extraFieldBufferSize > 0) && |
648 | (ZREAD (file->z_filefunc, | 648 | (ZREAD (file->z_filefunc, |
649 | extraField, | 649 | extraField, |
650 | uSizeRead) != uSizeRead) ) | 650 | uSizeRead) != uSizeRead) ) |
651 | return EXTRACTOR_UNZIP_ERRNO; | 651 | return EXTRACTOR_UNZIP_ERRNO; |
@@ -653,7 +653,7 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
653 | } | 653 | } |
654 | else | 654 | else |
655 | lSeek += file_info.size_file_extra; | 655 | lSeek += file_info.size_file_extra; |
656 | 656 | ||
657 | if (NULL != szComment) | 657 | if (NULL != szComment) |
658 | { | 658 | { |
659 | uLong uSizeRead; | 659 | uLong uSizeRead; |
@@ -665,8 +665,8 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
665 | } | 665 | } |
666 | else | 666 | else |
667 | uSizeRead = commentBufferSize; | 667 | uSizeRead = commentBufferSize; |
668 | 668 | ||
669 | if (0 != lSeek) | 669 | if (0 != lSeek) |
670 | { | 670 | { |
671 | if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR)) | 671 | if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR)) |
672 | lSeek = 0; | 672 | lSeek = 0; |
@@ -681,7 +681,7 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
681 | } | 681 | } |
682 | else | 682 | else |
683 | lSeek += file_info.size_file_comment; | 683 | lSeek += file_info.size_file_comment; |
684 | 684 | ||
685 | if (NULL != pfile_info) | 685 | if (NULL != pfile_info) |
686 | *pfile_info = file_info; | 686 | *pfile_info = file_info; |
687 | if (NULL != pfile_info_internal) | 687 | if (NULL != pfile_info_internal) |
@@ -696,7 +696,7 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file, | |||
696 | * @param file zipfile to manipulate | 696 | * @param file zipfile to manipulate |
697 | * @return UNZ_OK if there is no problem | 697 | * @return UNZ_OK if there is no problem |
698 | */ | 698 | */ |
699 | int | 699 | int |
700 | EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file) | 700 | EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file) |
701 | { | 701 | { |
702 | int err; | 702 | int err; |
@@ -720,7 +720,7 @@ EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file) | |||
720 | * @param ffd IO functions | 720 | * @param ffd IO functions |
721 | * @return NULL on error | 721 | * @return NULL on error |
722 | */ | 722 | */ |
723 | static struct EXTRACTOR_UnzipFile * | 723 | static struct EXTRACTOR_UnzipFile * |
724 | unzip_open_using_ffd (struct FileFuncDefs *ffd) | 724 | unzip_open_using_ffd (struct FileFuncDefs *ffd) |
725 | { | 725 | { |
726 | struct EXTRACTOR_UnzipFile us; | 726 | struct EXTRACTOR_UnzipFile us; |
@@ -735,56 +735,56 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd) | |||
735 | the central dir | 735 | the central dir |
736 | (same than number_entry on nospan) */ | 736 | (same than number_entry on nospan) */ |
737 | 737 | ||
738 | memset (&us, 0, sizeof(us)); | 738 | memset (&us, 0, sizeof(us)); |
739 | us.z_filefunc = *ffd; | 739 | us.z_filefunc = *ffd; |
740 | central_pos = locate_central_directory (&us.z_filefunc); | 740 | central_pos = locate_central_directory (&us.z_filefunc); |
741 | if (0 == central_pos) | 741 | if (0 == central_pos) |
742 | return NULL; | 742 | return NULL; |
743 | if (0 != ZSEEK (us.z_filefunc, | 743 | if (0 != ZSEEK (us.z_filefunc, |
744 | central_pos, SEEK_SET)) | 744 | central_pos, SEEK_SET)) |
745 | return NULL; | 745 | return NULL; |
746 | 746 | ||
747 | /* the signature, already checked */ | 747 | /* the signature, already checked */ |
748 | if (EXTRACTOR_UNZIP_OK != | 748 | if (EXTRACTOR_UNZIP_OK != |
749 | read_long_from_ffd (&us.z_filefunc, &uL)) | 749 | read_long_from_ffd (&us.z_filefunc, &uL)) |
750 | return NULL; | 750 | return NULL; |
751 | 751 | ||
752 | /* number of this disk */ | 752 | /* number of this disk */ |
753 | if (EXTRACTOR_UNZIP_OK != | 753 | if (EXTRACTOR_UNZIP_OK != |
754 | read_short_from_ffd (&us.z_filefunc, &number_disk)) | 754 | read_short_from_ffd (&us.z_filefunc, &number_disk)) |
755 | return NULL; | 755 | return NULL; |
756 | 756 | ||
757 | /* number of the disk with the start of the central directory */ | 757 | /* number of the disk with the start of the central directory */ |
758 | if (EXTRACTOR_UNZIP_OK != | 758 | if (EXTRACTOR_UNZIP_OK != |
759 | read_short_from_ffd (&us.z_filefunc, &number_disk_with_CD)) | 759 | read_short_from_ffd (&us.z_filefunc, &number_disk_with_CD)) |
760 | return NULL; | 760 | return NULL; |
761 | 761 | ||
762 | /* total number of entries in the central dir on this disk */ | 762 | /* total number of entries in the central dir on this disk */ |
763 | if (EXTRACTOR_UNZIP_OK != | 763 | if (EXTRACTOR_UNZIP_OK != |
764 | read_short_from_ffd (&us.z_filefunc, &us.gi.number_entry)) | 764 | read_short_from_ffd (&us.z_filefunc, &us.gi.number_entry)) |
765 | return NULL; | 765 | return NULL; |
766 | 766 | ||
767 | /* total number of entries in the central dir */ | 767 | /* total number of entries in the central dir */ |
768 | if (EXTRACTOR_UNZIP_OK != | 768 | if (EXTRACTOR_UNZIP_OK != |
769 | read_short_from_ffd (&us.z_filefunc, &number_entry_CD)) | 769 | read_short_from_ffd (&us.z_filefunc, &number_entry_CD)) |
770 | return NULL; | 770 | return NULL; |
771 | 771 | ||
772 | if ( (number_entry_CD != us.gi.number_entry) || | 772 | if ( (number_entry_CD != us.gi.number_entry) || |
773 | (0 != number_disk_with_CD) || | 773 | (0 != number_disk_with_CD) || |
774 | (0 != number_disk) ) | 774 | (0 != number_disk) ) |
775 | return NULL; | 775 | return NULL; |
776 | 776 | ||
777 | /* size of the central directory */ | 777 | /* size of the central directory */ |
778 | if (EXTRACTOR_UNZIP_OK != | 778 | if (EXTRACTOR_UNZIP_OK != |
779 | read_long_from_ffd (&us.z_filefunc, &us.size_central_dir)) | 779 | read_long_from_ffd (&us.z_filefunc, &us.size_central_dir)) |
780 | return NULL; | 780 | return NULL; |
781 | 781 | ||
782 | /* offset of start of central directory with respect to the | 782 | /* offset of start of central directory with respect to the |
783 | starting disk number */ | 783 | starting disk number */ |
784 | if (EXTRACTOR_UNZIP_OK != | 784 | if (EXTRACTOR_UNZIP_OK != |
785 | read_long_from_ffd (&us.z_filefunc, &us.offset_central_dir)) | 785 | read_long_from_ffd (&us.z_filefunc, &us.offset_central_dir)) |
786 | return NULL; | 786 | return NULL; |
787 | 787 | ||
788 | /* zipfile comment length */ | 788 | /* zipfile comment length */ |
789 | if (EXTRACTOR_UNZIP_OK != | 789 | if (EXTRACTOR_UNZIP_OK != |
790 | read_short_from_ffd (&us.z_filefunc, &us.gi.size_comment)) | 790 | read_short_from_ffd (&us.z_filefunc, &us.gi.size_comment)) |
@@ -792,13 +792,13 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd) | |||
792 | us.gi.offset_comment = ZTELL (us.z_filefunc); | 792 | us.gi.offset_comment = ZTELL (us.z_filefunc); |
793 | if ((central_pos < us.offset_central_dir + us.size_central_dir)) | 793 | if ((central_pos < us.offset_central_dir + us.size_central_dir)) |
794 | return NULL; | 794 | return NULL; |
795 | 795 | ||
796 | us.byte_before_the_zipfile = central_pos - | 796 | us.byte_before_the_zipfile = central_pos - |
797 | (us.offset_central_dir + us.size_central_dir); | 797 | (us.offset_central_dir + us.size_central_dir); |
798 | us.central_pos = central_pos; | 798 | us.central_pos = central_pos; |
799 | us.pfile_in_zip_read = NULL; | 799 | us.pfile_in_zip_read = NULL; |
800 | us.encrypted = 0; | 800 | us.encrypted = 0; |
801 | 801 | ||
802 | if (NULL == (file = malloc (sizeof(struct EXTRACTOR_UnzipFile)))) | 802 | if (NULL == (file = malloc (sizeof(struct EXTRACTOR_UnzipFile)))) |
803 | return NULL; | 803 | return NULL; |
804 | *file = us; | 804 | *file = us; |
@@ -808,16 +808,16 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd) | |||
808 | 808 | ||
809 | 809 | ||
810 | /** | 810 | /** |
811 | * Close the file in zip opened with EXTRACTOR_common_unzip_open_current_file. | 811 | * Close the file in zip opened with #EXTRACTOR_common_unzip_open_current_file(). |
812 | * | 812 | * |
813 | * @return EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good | 813 | * @return #EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good |
814 | */ | 814 | */ |
815 | int | 815 | int |
816 | EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file) | 816 | EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file) |
817 | { | 817 | { |
818 | struct FileInZipReadInfo* pfile_in_zip_read_info; | 818 | struct FileInZipReadInfo* pfile_in_zip_read_info; |
819 | int err = EXTRACTOR_UNZIP_OK; | 819 | int err = EXTRACTOR_UNZIP_OK; |
820 | 820 | ||
821 | if (NULL == file) | 821 | if (NULL == file) |
822 | return EXTRACTOR_UNZIP_PARAMERROR; | 822 | return EXTRACTOR_UNZIP_PARAMERROR; |
823 | if (NULL == (pfile_in_zip_read_info = file->pfile_in_zip_read)) | 823 | if (NULL == (pfile_in_zip_read_info = file->pfile_in_zip_read)) |
@@ -841,9 +841,9 @@ EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file) | |||
841 | * Close a ZipFile. | 841 | * Close a ZipFile. |
842 | * | 842 | * |
843 | * @param file zip file to close | 843 | * @param file zip file to close |
844 | * @return EXTRACTOR_UNZIP_OK if there is no problem. | 844 | * @return #EXTRACTOR_UNZIP_OK if there is no problem. |
845 | */ | 845 | */ |
846 | int | 846 | int |
847 | EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file) | 847 | EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file) |
848 | { | 848 | { |
849 | if (NULL == file) | 849 | if (NULL == file) |
@@ -861,7 +861,7 @@ EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file) | |||
861 | * @param file unzip file to inspect | 861 | * @param file unzip file to inspect |
862 | * @param comment where to copy the comment | 862 | * @param comment where to copy the comment |
863 | * @param comment_len maximum number of bytes available in comment | 863 | * @param comment_len maximum number of bytes available in comment |
864 | * @return EXTRACTOR_UNZIP_OK on success | 864 | * @return #EXTRACTOR_UNZIP_OK on success |
865 | */ | 865 | */ |
866 | int | 866 | int |
867 | EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file, | 867 | EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file, |
@@ -892,10 +892,10 @@ EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file, | |||
892 | * @param szFileName where to write the name of the current file | 892 | * @param szFileName where to write the name of the current file |
893 | * @param fileNameBufferSize number of bytes available in szFileName | 893 | * @param fileNameBufferSize number of bytes available in szFileName |
894 | * @param extraField where to write extra data | 894 | * @param extraField where to write extra data |
895 | * @param extraFieldBufferSize number of bytes available in extraField | 895 | * @param extraFieldBufferSize number of bytes available in extraField |
896 | * @param szComment where to write the comment on the current file | 896 | * @param szComment where to write the comment on the current file |
897 | * @param commentBufferSize number of bytes available in szComment | 897 | * @param commentBufferSize number of bytes available in szComment |
898 | * @return EXTRACTOR_UNZIP_OK if there is no problem. | 898 | * @return #EXTRACTOR_UNZIP_OK if there is no problem. |
899 | */ | 899 | */ |
900 | int | 900 | int |
901 | EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile * file, | 901 | EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile * file, |
@@ -918,14 +918,14 @@ EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile * file, | |||
918 | * Set the current file of the zipfile to the next file. | 918 | * Set the current file of the zipfile to the next file. |
919 | * | 919 | * |
920 | * @param file zipfile to manipulate | 920 | * @param file zipfile to manipulate |
921 | * @return EXTRACTOR_UNZIP_OK if there is no problem, | 921 | * @return #EXTRACTOR_UNZIP_OK if there is no problem, |
922 | * EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the actual file was the latest. | 922 | * #EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the actual file was the latest. |
923 | */ | 923 | */ |
924 | int | 924 | int |
925 | EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file) | 925 | EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file) |
926 | { | 926 | { |
927 | int err; | 927 | int err; |
928 | 928 | ||
929 | if (NULL == file) | 929 | if (NULL == file) |
930 | return EXTRACTOR_UNZIP_PARAMERROR; | 930 | return EXTRACTOR_UNZIP_PARAMERROR; |
931 | if (! file->current_file_ok) | 931 | if (! file->current_file_ok) |
@@ -935,7 +935,7 @@ EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file) | |||
935 | file->pos_in_central_dir += SIZECENTRALDIRITEM + file->cur_file_info.size_filename + | 935 | file->pos_in_central_dir += SIZECENTRALDIRITEM + file->cur_file_info.size_filename + |
936 | file->cur_file_info.size_file_extra + file->cur_file_info.size_file_comment; | 936 | file->cur_file_info.size_file_extra + file->cur_file_info.size_file_comment; |
937 | file->num_file++; | 937 | file->num_file++; |
938 | err = get_current_file_info (file, | 938 | err = get_current_file_info (file, |
939 | &file->cur_file_info, | 939 | &file->cur_file_info, |
940 | &file->cur_file_info_internal, | 940 | &file->cur_file_info_internal, |
941 | NULL, 0, NULL, 0, NULL, 0); | 941 | NULL, 0, NULL, 0, NULL, 0); |
@@ -946,17 +946,17 @@ EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file) | |||
946 | 946 | ||
947 | /** | 947 | /** |
948 | * Try locate the file szFileName in the zipfile. | 948 | * Try locate the file szFileName in the zipfile. |
949 | * | 949 | * |
950 | * @param file zipfile to manipulate | 950 | * @param file zipfile to manipulate |
951 | * @param szFileName name to find | 951 | * @param szFileName name to find |
952 | * @param iCaseSensitivity, use 1 for case sensitivity (like strcmp); | 952 | * @param iCaseSensitivity, use 1 for case sensitivity (like strcmp); |
953 | * 2 for no case sensitivity (like strcmpi or strcasecmp); or | 953 | * 2 for no case sensitivity (like strcmpi or strcasecmp); or |
954 | * 0 for defaut of your operating system (like 1 on Unix, 2 on Windows) | 954 | * 0 for defaut of your operating system (like 1 on Unix, 2 on Windows) |
955 | * @return EXTRACTOR_UNZIP_OK if the file is found. It becomes the current file. | 955 | * @return #EXTRACTOR_UNZIP_OK if the file is found. It becomes the current file. |
956 | * EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the file is not found | 956 | * #EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the file is not found |
957 | */ | 957 | */ |
958 | int | 958 | int |
959 | EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, | 959 | EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, |
960 | const char *szFileName, | 960 | const char *szFileName, |
961 | int iCaseSensitivity) | 961 | int iCaseSensitivity) |
962 | { | 962 | { |
@@ -968,28 +968,28 @@ EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, | |||
968 | struct UnzipFileInfoInternal cur_file_info_internalSaved; | 968 | struct UnzipFileInfoInternal cur_file_info_internalSaved; |
969 | uLong num_fileSaved; | 969 | uLong num_fileSaved; |
970 | uLong pos_in_central_dirSaved; | 970 | uLong pos_in_central_dirSaved; |
971 | 971 | ||
972 | if (NULL == file) | 972 | if (NULL == file) |
973 | return EXTRACTOR_UNZIP_PARAMERROR; | 973 | return EXTRACTOR_UNZIP_PARAMERROR; |
974 | if (strlen (szFileName) >= UNZ_MAXFILENAMEINZIP) | 974 | if (strlen (szFileName) >= UNZ_MAXFILENAMEINZIP) |
975 | return EXTRACTOR_UNZIP_PARAMERROR; | 975 | return EXTRACTOR_UNZIP_PARAMERROR; |
976 | if (! file->current_file_ok) | 976 | if (! file->current_file_ok) |
977 | return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE; | 977 | return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE; |
978 | 978 | ||
979 | /* Save the current state */ | 979 | /* Save the current state */ |
980 | num_fileSaved = file->num_file; | 980 | num_fileSaved = file->num_file; |
981 | pos_in_central_dirSaved = file->pos_in_central_dir; | 981 | pos_in_central_dirSaved = file->pos_in_central_dir; |
982 | cur_file_infoSaved = file->cur_file_info; | 982 | cur_file_infoSaved = file->cur_file_info; |
983 | cur_file_info_internalSaved = file->cur_file_info_internal; | 983 | cur_file_info_internalSaved = file->cur_file_info_internal; |
984 | err = EXTRACTOR_common_unzip_go_to_first_file (file); | 984 | err = EXTRACTOR_common_unzip_go_to_first_file (file); |
985 | 985 | ||
986 | while (EXTRACTOR_UNZIP_OK == err) | 986 | while (EXTRACTOR_UNZIP_OK == err) |
987 | { | 987 | { |
988 | char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1]; | 988 | char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1]; |
989 | 989 | ||
990 | if (EXTRACTOR_UNZIP_OK != | 990 | if (EXTRACTOR_UNZIP_OK != |
991 | (err = EXTRACTOR_common_unzip_get_current_file_info (file, NULL, | 991 | (err = EXTRACTOR_common_unzip_get_current_file_info (file, NULL, |
992 | szCurrentFileName, | 992 | szCurrentFileName, |
993 | sizeof (szCurrentFileName) - 1, | 993 | sizeof (szCurrentFileName) - 1, |
994 | NULL, 0, NULL, 0))) | 994 | NULL, 0, NULL, 0))) |
995 | break; | 995 | break; |
@@ -1000,7 +1000,7 @@ EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, | |||
1000 | return EXTRACTOR_UNZIP_OK; | 1000 | return EXTRACTOR_UNZIP_OK; |
1001 | err = EXTRACTOR_common_unzip_go_to_next_file (file); | 1001 | err = EXTRACTOR_common_unzip_go_to_next_file (file); |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | /* We failed, so restore the state of the 'current file' to where we | 1004 | /* We failed, so restore the state of the 'current file' to where we |
1005 | * were. | 1005 | * were. |
1006 | */ | 1006 | */ |
@@ -1020,9 +1020,9 @@ EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, | |||
1020 | * @return the number of byte copied if somes bytes are copied | 1020 | * @return the number of byte copied if somes bytes are copied |
1021 | * 0 if the end of file was reached | 1021 | * 0 if the end of file was reached |
1022 | * <0 with error code if there is an error | 1022 | * <0 with error code if there is an error |
1023 | * (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error) | 1023 | * (#EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error) |
1024 | */ | 1024 | */ |
1025 | ssize_t | 1025 | ssize_t |
1026 | EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | 1026 | EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, |
1027 | void *buf, | 1027 | void *buf, |
1028 | size_t len) | 1028 | size_t len) |
@@ -1045,7 +1045,7 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | |||
1045 | if (len > pfile_in_zip_read_info->rest_read_uncompressed) | 1045 | if (len > pfile_in_zip_read_info->rest_read_uncompressed) |
1046 | pfile_in_zip_read_info->stream.avail_out = | 1046 | pfile_in_zip_read_info->stream.avail_out = |
1047 | (uInt) pfile_in_zip_read_info->rest_read_uncompressed; | 1047 | (uInt) pfile_in_zip_read_info->rest_read_uncompressed; |
1048 | 1048 | ||
1049 | while (pfile_in_zip_read_info->stream.avail_out > 0) | 1049 | while (pfile_in_zip_read_info->stream.avail_out > 0) |
1050 | { | 1050 | { |
1051 | if ( (0 == pfile_in_zip_read_info->stream.avail_in) && | 1051 | if ( (0 == pfile_in_zip_read_info->stream.avail_in) && |
@@ -1056,7 +1056,7 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | |||
1056 | uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed; | 1056 | uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed; |
1057 | if (0 == uReadThis) | 1057 | if (0 == uReadThis) |
1058 | return EXTRACTOR_UNZIP_EOF; | 1058 | return EXTRACTOR_UNZIP_EOF; |
1059 | if (0 != | 1059 | if (0 != |
1060 | ZSEEK (pfile_in_zip_read_info->z_filefunc, | 1060 | ZSEEK (pfile_in_zip_read_info->z_filefunc, |
1061 | pfile_in_zip_read_info->pos_in_zipfile + | 1061 | pfile_in_zip_read_info->pos_in_zipfile + |
1062 | pfile_in_zip_read_info->byte_before_the_zipfile, | 1062 | pfile_in_zip_read_info->byte_before_the_zipfile, |
@@ -1066,22 +1066,22 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | |||
1066 | pfile_in_zip_read_info->read_buffer, | 1066 | pfile_in_zip_read_info->read_buffer, |
1067 | uReadThis) != uReadThis) | 1067 | uReadThis) != uReadThis) |
1068 | return EXTRACTOR_UNZIP_ERRNO; | 1068 | return EXTRACTOR_UNZIP_ERRNO; |
1069 | 1069 | ||
1070 | pfile_in_zip_read_info->pos_in_zipfile += uReadThis; | 1070 | pfile_in_zip_read_info->pos_in_zipfile += uReadThis; |
1071 | pfile_in_zip_read_info->rest_read_compressed -= uReadThis; | 1071 | pfile_in_zip_read_info->rest_read_compressed -= uReadThis; |
1072 | pfile_in_zip_read_info->stream.next_in = | 1072 | pfile_in_zip_read_info->stream.next_in = |
1073 | (Bytef *) pfile_in_zip_read_info->read_buffer; | 1073 | (Bytef *) pfile_in_zip_read_info->read_buffer; |
1074 | pfile_in_zip_read_info->stream.avail_in = (uInt) uReadThis; | 1074 | pfile_in_zip_read_info->stream.avail_in = (uInt) uReadThis; |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | if (0 == pfile_in_zip_read_info->compression_method) | 1077 | if (0 == pfile_in_zip_read_info->compression_method) |
1078 | { | 1078 | { |
1079 | uInt uDoCopy; | 1079 | uInt uDoCopy; |
1080 | 1080 | ||
1081 | if ( (0 == pfile_in_zip_read_info->stream.avail_in) && | 1081 | if ( (0 == pfile_in_zip_read_info->stream.avail_in) && |
1082 | (0 == pfile_in_zip_read_info->rest_read_compressed) ) | 1082 | (0 == pfile_in_zip_read_info->rest_read_compressed) ) |
1083 | return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead; | 1083 | return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead; |
1084 | 1084 | ||
1085 | if (pfile_in_zip_read_info->stream.avail_out < | 1085 | if (pfile_in_zip_read_info->stream.avail_out < |
1086 | pfile_in_zip_read_info->stream.avail_in) | 1086 | pfile_in_zip_read_info->stream.avail_in) |
1087 | uDoCopy = pfile_in_zip_read_info->stream.avail_out; | 1087 | uDoCopy = pfile_in_zip_read_info->stream.avail_out; |
@@ -1108,10 +1108,10 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | |||
1108 | const Bytef *bufBefore; | 1108 | const Bytef *bufBefore; |
1109 | uLong uOutThis; | 1109 | uLong uOutThis; |
1110 | int flush = Z_SYNC_FLUSH; | 1110 | int flush = Z_SYNC_FLUSH; |
1111 | 1111 | ||
1112 | uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; | 1112 | uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; |
1113 | bufBefore = pfile_in_zip_read_info->stream.next_out; | 1113 | bufBefore = pfile_in_zip_read_info->stream.next_out; |
1114 | 1114 | ||
1115 | /* | 1115 | /* |
1116 | if ((pfile_in_zip_read_info->rest_read_uncompressed == | 1116 | if ((pfile_in_zip_read_info->rest_read_uncompressed == |
1117 | pfile_in_zip_read_info->stream.avail_out) && | 1117 | pfile_in_zip_read_info->stream.avail_out) && |
@@ -1119,26 +1119,26 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | |||
1119 | flush = Z_FINISH; | 1119 | flush = Z_FINISH; |
1120 | */ | 1120 | */ |
1121 | err = inflate (&pfile_in_zip_read_info->stream, flush); | 1121 | err = inflate (&pfile_in_zip_read_info->stream, flush); |
1122 | 1122 | ||
1123 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; | 1123 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; |
1124 | uOutThis = uTotalOutAfter-uTotalOutBefore; | 1124 | uOutThis = uTotalOutAfter-uTotalOutBefore; |
1125 | 1125 | ||
1126 | pfile_in_zip_read_info->crc32 = | 1126 | pfile_in_zip_read_info->crc32 = |
1127 | crc32 (pfile_in_zip_read_info->crc32, bufBefore, | 1127 | crc32 (pfile_in_zip_read_info->crc32, bufBefore, |
1128 | (uInt) (uOutThis)); | 1128 | (uInt) (uOutThis)); |
1129 | 1129 | ||
1130 | pfile_in_zip_read_info->rest_read_uncompressed -= | 1130 | pfile_in_zip_read_info->rest_read_uncompressed -= |
1131 | uOutThis; | 1131 | uOutThis; |
1132 | 1132 | ||
1133 | iRead += (uInt) (uTotalOutAfter - uTotalOutBefore); | 1133 | iRead += (uInt) (uTotalOutAfter - uTotalOutBefore); |
1134 | 1134 | ||
1135 | if (Z_STREAM_END == err) | 1135 | if (Z_STREAM_END == err) |
1136 | return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead; | 1136 | return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead; |
1137 | if (Z_OK != err) | 1137 | if (Z_OK != err) |
1138 | break; | 1138 | break; |
1139 | } | 1139 | } |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | if (Z_OK == err) | 1142 | if (Z_OK == err) |
1143 | return iRead; | 1143 | return iRead; |
1144 | return err; | 1144 | return err; |
@@ -1155,9 +1155,9 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, | |||
1155 | * @param piSizeVar where to store the size of the extra info | 1155 | * @param piSizeVar where to store the size of the extra info |
1156 | * @param poffset_local_extrafield where to store the offset of the local extrafield | 1156 | * @param poffset_local_extrafield where to store the offset of the local extrafield |
1157 | * @param psoze_local_extrafield where to store the size of the local extrafield | 1157 | * @param psoze_local_extrafield where to store the size of the local extrafield |
1158 | * @return EXTRACTOR_UNZIP_OK on success | 1158 | * @return #EXTRACTOR_UNZIP_OK on success |
1159 | */ | 1159 | */ |
1160 | static int | 1160 | static int |
1161 | parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | 1161 | parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, |
1162 | uInt *piSizeVar, | 1162 | uInt *piSizeVar, |
1163 | uLong *poffset_local_extrafield, | 1163 | uLong *poffset_local_extrafield, |
@@ -1172,10 +1172,10 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | |||
1172 | *piSizeVar = 0; | 1172 | *piSizeVar = 0; |
1173 | *poffset_local_extrafield = 0; | 1173 | *poffset_local_extrafield = 0; |
1174 | *psize_local_extrafield = 0; | 1174 | *psize_local_extrafield = 0; |
1175 | 1175 | ||
1176 | if (0 != ZSEEK (file->z_filefunc, | 1176 | if (0 != ZSEEK (file->z_filefunc, |
1177 | file->cur_file_info_internal.offset_curfile + | 1177 | file->cur_file_info_internal.offset_curfile + |
1178 | file->byte_before_the_zipfile, | 1178 | file->byte_before_the_zipfile, |
1179 | SEEK_SET)) | 1179 | SEEK_SET)) |
1180 | return EXTRACTOR_UNZIP_ERRNO; | 1180 | return EXTRACTOR_UNZIP_ERRNO; |
1181 | if (EXTRACTOR_UNZIP_OK != | 1181 | if (EXTRACTOR_UNZIP_OK != |
@@ -1183,7 +1183,7 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | |||
1183 | &uMagic)) | 1183 | &uMagic)) |
1184 | return EXTRACTOR_UNZIP_ERRNO; | 1184 | return EXTRACTOR_UNZIP_ERRNO; |
1185 | if (0x04034b50 != uMagic) | 1185 | if (0x04034b50 != uMagic) |
1186 | return EXTRACTOR_UNZIP_BADZIPFILE; | 1186 | return EXTRACTOR_UNZIP_BADZIPFILE; |
1187 | if ( (EXTRACTOR_UNZIP_OK != | 1187 | if ( (EXTRACTOR_UNZIP_OK != |
1188 | read_short_from_ffd (&file->z_filefunc, &uData)) || | 1188 | read_short_from_ffd (&file->z_filefunc, &uData)) || |
1189 | (EXTRACTOR_UNZIP_OK != | 1189 | (EXTRACTOR_UNZIP_OK != |
@@ -1195,7 +1195,7 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | |||
1195 | return EXTRACTOR_UNZIP_BADZIPFILE; | 1195 | return EXTRACTOR_UNZIP_BADZIPFILE; |
1196 | if ( (0 != file->cur_file_info.compression_method) && | 1196 | if ( (0 != file->cur_file_info.compression_method) && |
1197 | (Z_DEFLATED != file->cur_file_info.compression_method) ) | 1197 | (Z_DEFLATED != file->cur_file_info.compression_method) ) |
1198 | return EXTRACTOR_UNZIP_BADZIPFILE; | 1198 | return EXTRACTOR_UNZIP_BADZIPFILE; |
1199 | if (EXTRACTOR_UNZIP_OK != | 1199 | if (EXTRACTOR_UNZIP_OK != |
1200 | read_long_from_ffd (&file->z_filefunc, &uData)) /* date/time */ | 1200 | read_long_from_ffd (&file->z_filefunc, &uData)) /* date/time */ |
1201 | return EXTRACTOR_UNZIP_ERRNO; | 1201 | return EXTRACTOR_UNZIP_ERRNO; |
@@ -1222,7 +1222,7 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | |||
1222 | read_short_from_ffd (&file->z_filefunc, &size_filename)) | 1222 | read_short_from_ffd (&file->z_filefunc, &size_filename)) |
1223 | return EXTRACTOR_UNZIP_ERRNO; | 1223 | return EXTRACTOR_UNZIP_ERRNO; |
1224 | if (size_filename != file->cur_file_info.size_filename) | 1224 | if (size_filename != file->cur_file_info.size_filename) |
1225 | return EXTRACTOR_UNZIP_BADZIPFILE; | 1225 | return EXTRACTOR_UNZIP_BADZIPFILE; |
1226 | *piSizeVar += (uInt) size_filename; | 1226 | *piSizeVar += (uInt) size_filename; |
1227 | if (EXTRACTOR_UNZIP_OK != | 1227 | if (EXTRACTOR_UNZIP_OK != |
1228 | read_short_from_ffd (&file->z_filefunc, | 1228 | read_short_from_ffd (&file->z_filefunc, |
@@ -1232,7 +1232,7 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | |||
1232 | SIZEZIPLOCALHEADER + size_filename; | 1232 | SIZEZIPLOCALHEADER + size_filename; |
1233 | *psize_local_extrafield = (uInt) size_extra_field; | 1233 | *psize_local_extrafield = (uInt) size_extra_field; |
1234 | *piSizeVar += (uInt)size_extra_field; | 1234 | *piSizeVar += (uInt)size_extra_field; |
1235 | 1235 | ||
1236 | return EXTRACTOR_UNZIP_OK; | 1236 | return EXTRACTOR_UNZIP_OK; |
1237 | } | 1237 | } |
1238 | 1238 | ||
@@ -1241,9 +1241,9 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, | |||
1241 | * Open for reading data the current file in the zipfile. | 1241 | * Open for reading data the current file in the zipfile. |
1242 | * | 1242 | * |
1243 | * @param file zipfile to manipulate | 1243 | * @param file zipfile to manipulate |
1244 | * @return EXTRACTOR_UNZIP_OK on success | 1244 | * @return #EXTRACTOR_UNZIP_OK on success |
1245 | */ | 1245 | */ |
1246 | int | 1246 | int |
1247 | EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file) | 1247 | EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file) |
1248 | { | 1248 | { |
1249 | int err; | 1249 | int err; |
@@ -1251,7 +1251,7 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file) | |||
1251 | struct FileInZipReadInfo *pfile_in_zip_read_info; | 1251 | struct FileInZipReadInfo *pfile_in_zip_read_info; |
1252 | uLong offset_local_extrafield; /* offset of the local extra field */ | 1252 | uLong offset_local_extrafield; /* offset of the local extra field */ |
1253 | uInt size_local_extrafield; /* size of the local extra field */ | 1253 | uInt size_local_extrafield; /* size of the local extra field */ |
1254 | 1254 | ||
1255 | if (NULL == file) | 1255 | if (NULL == file) |
1256 | return EXTRACTOR_UNZIP_PARAMERROR; | 1256 | return EXTRACTOR_UNZIP_PARAMERROR; |
1257 | if (! file->current_file_ok) | 1257 | if (! file->current_file_ok) |
@@ -1259,7 +1259,7 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file) | |||
1259 | if (NULL != file->pfile_in_zip_read) | 1259 | if (NULL != file->pfile_in_zip_read) |
1260 | EXTRACTOR_common_unzip_close_current_file (file); | 1260 | EXTRACTOR_common_unzip_close_current_file (file); |
1261 | if (EXTRACTOR_UNZIP_OK != | 1261 | if (EXTRACTOR_UNZIP_OK != |
1262 | parse_current_file_coherency_header (file, | 1262 | parse_current_file_coherency_header (file, |
1263 | &iSizeVar, | 1263 | &iSizeVar, |
1264 | &offset_local_extrafield, | 1264 | &offset_local_extrafield, |
1265 | &size_local_extrafield)) | 1265 | &size_local_extrafield)) |
@@ -1283,7 +1283,7 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file) | |||
1283 | // FIXME: we don't do anything with this 'err' code. | 1283 | // FIXME: we don't do anything with this 'err' code. |
1284 | // Can this happen? Should we abort in this case? | 1284 | // Can this happen? Should we abort in this case? |
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | pfile_in_zip_read_info->crc32_wait = file->cur_file_info.crc; | 1287 | pfile_in_zip_read_info->crc32_wait = file->cur_file_info.crc; |
1288 | pfile_in_zip_read_info->crc32 = 0; | 1288 | pfile_in_zip_read_info->crc32 = 0; |
1289 | pfile_in_zip_read_info->compression_method = file->cur_file_info.compression_method; | 1289 | pfile_in_zip_read_info->compression_method = file->cur_file_info.compression_method; |
@@ -1332,16 +1332,16 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file) | |||
1332 | * @param size number of bytes desired | 1332 | * @param size number of bytes desired |
1333 | * @return number of bytes copied to buf | 1333 | * @return number of bytes copied to buf |
1334 | */ | 1334 | */ |
1335 | static uLong | 1335 | static uLong |
1336 | ec_read_file_func (voidpf opaque, | 1336 | ec_read_file_func (voidpf opaque, |
1337 | void* buf, | 1337 | void* buf, |
1338 | uLong size) | 1338 | uLong size) |
1339 | { | 1339 | { |
1340 | struct EXTRACTOR_ExtractContext *ec = opaque; | 1340 | struct EXTRACTOR_ExtractContext *ec = opaque; |
1341 | void *ptr; | 1341 | void *ptr; |
1342 | ssize_t ret; | 1342 | ssize_t ret; |
1343 | uLong done; | 1343 | uLong done; |
1344 | 1344 | ||
1345 | done = 0; | 1345 | done = 0; |
1346 | while (done < size) | 1346 | while (done < size) |
1347 | { | 1347 | { |
@@ -1363,7 +1363,7 @@ ec_read_file_func (voidpf opaque, | |||
1363 | * @param opaque the 'struct EXTRACTOR_ExtractContext' | 1363 | * @param opaque the 'struct EXTRACTOR_ExtractContext' |
1364 | * @return current offset in file, -1 on error | 1364 | * @return current offset in file, -1 on error |
1365 | */ | 1365 | */ |
1366 | static long | 1366 | static long |
1367 | ec_tell_file_func (voidpf opaque) | 1367 | ec_tell_file_func (voidpf opaque) |
1368 | { | 1368 | { |
1369 | struct EXTRACTOR_ExtractContext *ec = opaque; | 1369 | struct EXTRACTOR_ExtractContext *ec = opaque; |
@@ -1378,15 +1378,15 @@ ec_tell_file_func (voidpf opaque) | |||
1378 | * @param opaque the 'struct EXTRACTOR_ExtractContext' | 1378 | * @param opaque the 'struct EXTRACTOR_ExtractContext' |
1379 | * @param offset where to seek | 1379 | * @param offset where to seek |
1380 | * @param origin relative to where should we seek | 1380 | * @param origin relative to where should we seek |
1381 | * @return EXTRACTOR_UNZIP_OK on success | 1381 | * @return #EXTRACTOR_UNZIP_OK on success |
1382 | */ | 1382 | */ |
1383 | static long | 1383 | static long |
1384 | ec_seek_file_func (voidpf opaque, | 1384 | ec_seek_file_func (voidpf opaque, |
1385 | uLong offset, | 1385 | uLong offset, |
1386 | int origin) | 1386 | int origin) |
1387 | { | 1387 | { |
1388 | struct EXTRACTOR_ExtractContext *ec = opaque; | 1388 | struct EXTRACTOR_ExtractContext *ec = opaque; |
1389 | 1389 | ||
1390 | if (-1 == ec->seek (ec->cls, offset, origin)) | 1390 | if (-1 == ec->seek (ec->cls, offset, origin)) |
1391 | return EXTRACTOR_UNZIP_INTERNALERROR; | 1391 | return EXTRACTOR_UNZIP_INTERNALERROR; |
1392 | return EXTRACTOR_UNZIP_OK; | 1392 | return EXTRACTOR_UNZIP_OK; |
@@ -1400,7 +1400,7 @@ ec_seek_file_func (voidpf opaque, | |||
1400 | * @param ec extract context to use | 1400 | * @param ec extract context to use |
1401 | * @return handle to zip data, NULL on error | 1401 | * @return handle to zip data, NULL on error |
1402 | */ | 1402 | */ |
1403 | struct EXTRACTOR_UnzipFile * | 1403 | struct EXTRACTOR_UnzipFile * |
1404 | EXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec) | 1404 | EXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec) |
1405 | { | 1405 | { |
1406 | struct FileFuncDefs ffd; | 1406 | struct FileFuncDefs ffd; |