aboutsummaryrefslogtreecommitdiff
path: root/contrib/minizip/zip.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/minizip/zip.c')
-rw-r--r--contrib/minizip/zip.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 93d2612..103f325 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -52,7 +52,7 @@
52#endif 52#endif
53 53
54#ifndef Z_BUFSIZE 54#ifndef Z_BUFSIZE
55#define Z_BUFSIZE (64*1024) //(16384) 55#define Z_BUFSIZE (64*1024) /* (16384) */
56#endif 56#endif
57 57
58#ifndef Z_MAXFILENAMEINZIP 58#ifndef Z_MAXFILENAMEINZIP
@@ -71,7 +71,7 @@
71/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 71/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
72 72
73 73
74// NOT sure that this work on ALL platform 74/* NOT sure that this work on ALL platform */
75#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) 75#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
76 76
77#ifndef SEEK_CUR 77#ifndef SEEK_CUR
@@ -125,16 +125,16 @@ typedef struct linkedlist_data_s
125} linkedlist_data; 125} linkedlist_data;
126 126
127 127
128// zipAlreadyThere() set functions for a set of zero-terminated strings, and 128/* zipAlreadyThere() set functions for a set of zero-terminated strings, and
129// a block_t type for reading the central directory datablocks. 129// a block_t type for reading the central directory datablocks. */
130typedef char *set_key_t; 130typedef char *set_key_t;
131#define set_cmp(a, b) strcmp(a, b) 131#define set_cmp(a, b) strcmp(a, b)
132#define set_drop(s, k) set_free(s, k) 132#define set_drop(s, k) set_free(s, k)
133#include "skipset.h" 133#include "skipset.h"
134typedef struct { 134typedef struct {
135 unsigned char *next; // next byte in datablock data 135 unsigned char *next; /* next byte in datablock data */
136 size_t left; // number of bytes left in data (at least) 136 size_t left; /* number of bytes left in data (at least) */
137 linkedlist_datablock_internal *node; // current datablock 137 linkedlist_datablock_internal *node; /* current datablock */
138} block_t; 138} block_t;
139 139
140 140
@@ -189,9 +189,9 @@ typedef struct
189 char *globalcomment; 189 char *globalcomment;
190#endif 190#endif
191 191
192 // Support for zipAlreadyThere(). 192 /* Support for zipAlreadyThere(). */
193 set_t set; // set for detecting name collisions 193 set_t set; /* set for detecting name collisions */
194 block_t block; // block for reading the central directory 194 block_t block; /* block for reading the central directory */
195 195
196} zip64_internal; 196} zip64_internal;
197 197
@@ -283,7 +283,7 @@ local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
283 return ZIP_OK; 283 return ZIP_OK;
284} 284}
285 285
286// zipAlreadyThere() operations. "set" in the zip internal structure keeps the 286/* zipAlreadyThere() operations. "set" in the zip internal structure keeps the
287// set of names that are in the under-construction central directory so far. A 287// set of names that are in the under-construction central directory so far. A
288// skipset provides ~O(log n) time insertion and searching. Central directory 288// skipset provides ~O(log n) time insertion and searching. Central directory
289// records, stored in a linked list of allocated memory datablocks, is read 289// records, stored in a linked list of allocated memory datablocks, is read
@@ -295,81 +295,81 @@ local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
295// datablocks. 295// datablocks.
296 296
297// Initialize *block to the head of list. This should only be called once the 297// Initialize *block to the head of list. This should only be called once the
298// list has at least some data in it, i.e. list->first_block is not NULL. 298// list has at least some data in it, i.e. list->first_block is not NULL. */
299local void block_init(block_t *block, linkedlist_data *list) { 299local void block_init(block_t *block, linkedlist_data *list) {
300 block->node = list->first_block; 300 block->node = list->first_block;
301 block->next = block->node->data; 301 block->next = block->node->data;
302 block->left = block->node->filled_in_this_block; 302 block->left = block->node->filled_in_this_block;
303} 303}
304 304
305// Mark *block as bad, with all subsequent reads returning end, even if more 305/* Mark *block as bad, with all subsequent reads returning end, even if more
306// data is added to the datablocks. This is invoked if the central directory is 306// data is added to the datablocks. This is invoked if the central directory is
307// invalid, so there is no longer any point in attempting to interpret it. 307// invalid, so there is no longer any point in attempting to interpret it. */
308local void block_stop(block_t *block) { 308local void block_stop(block_t *block) {
309 block->left = 0; 309 block->left = 0;
310 block->next = NULL; 310 block->next = NULL;
311} 311}
312 312
313// Return true if *block has reached the end of the data in the datablocks. 313/* Return true if *block has reached the end of the data in the datablocks. */
314local int block_end(block_t *block) { 314local int block_end(block_t *block) {
315 linkedlist_datablock_internal *node = block->node; 315 linkedlist_datablock_internal *node = block->node;
316 if (node == NULL) 316 if (node == NULL)
317 // This block was previously terminated with extreme prejudice. 317 /* This block was previously terminated with extreme prejudice. */
318 return 1; 318 return 1;
319 if (block->next < node->data + node->filled_in_this_block) 319 if (block->next < node->data + node->filled_in_this_block)
320 // There are more bytes to read in the current datablock. 320 /* There are more bytes to read in the current datablock. */
321 return 0; 321 return 0;
322 while (node->next_datablock != NULL) { 322 while (node->next_datablock != NULL) {
323 if (node->filled_in_this_block != 0) 323 if (node->filled_in_this_block != 0)
324 // There are some bytes in a later datablock. 324 /* There are some bytes in a later datablock. */
325 return 0; 325 return 0;
326 node = node->next_datablock; 326 node = node->next_datablock;
327 } 327 }
328 // Reached the end of the list of datablocks. There's nothing. 328 /* Reached the end of the list of datablocks. There's nothing. */
329 return 1; 329 return 1;
330} 330}
331 331
332// Return one byte from *block, or -1 if the end is reached. 332/* Return one byte from *block, or -1 if the end is reached. */
333local int block_get(block_t *block) { 333local int block_get(block_t *block) {
334 while (block->left == 0) { 334 while (block->left == 0) {
335 if (block->node == NULL) 335 if (block->node == NULL)
336 // We've been marked bad. Return end. 336 /* We've been marked bad. Return end. */
337 return -1; 337 return -1;
338 // Update left in case more was filled in since we were last here. 338 /* Update left in case more was filled in since we were last here. */
339 block->left = block->node->filled_in_this_block - 339 block->left = block->node->filled_in_this_block -
340 (block->next - block->node->data); 340 (block->next - block->node->data);
341 if (block->left != 0) 341 if (block->left != 0)
342 // There was indeed more data appended in the current datablock. 342 /* There was indeed more data appended in the current datablock. */
343 break; 343 break;
344 if (block->node->next_datablock == NULL) 344 if (block->node->next_datablock == NULL)
345 // No more data here, and there is no next datablock. At the end. 345 /* No more data here, and there is no next datablock. At the end. */
346 return -1; 346 return -1;
347 // Try the next datablock for more data. 347 /* Try the next datablock for more data. */
348 block->node = block->node->next_datablock; 348 block->node = block->node->next_datablock;
349 block->next = block->node->data; 349 block->next = block->node->data;
350 block->left = block->node->filled_in_this_block; 350 block->left = block->node->filled_in_this_block;
351 } 351 }
352 // We have a byte to return. 352 /* We have a byte to return. */
353 block->left--; 353 block->left--;
354 return *block->next++; 354 return *block->next++;
355} 355}
356 356
357// Return a 16-bit unsigned little-endian value from block, or a negative value 357/* Return a 16-bit unsigned little-endian value from block, or a negative value
358// if the end is reached. 358// if the end is reached. */
359local long block_get2(block_t *block) { 359local long block_get2(block_t *block) {
360 long got = block_get(block); 360 long got = block_get(block);
361 return got | ((unsigned long)block_get(block) << 8); 361 return got | ((unsigned long)block_get(block) << 8);
362} 362}
363 363
364// Read up to len bytes from block into buf. Return the number of bytes read. 364/* Read up to len bytes from block into buf. Return the number of bytes read. */
365local size_t block_read(block_t *block, unsigned char *buf, size_t len) { 365local size_t block_read(block_t *block, unsigned char *buf, size_t len) {
366 size_t need = len; 366 size_t need = len;
367 while (need) { 367 while (need) {
368 if (block->left == 0) { 368 if (block->left == 0) {
369 // Get a byte to update and step through the linked list as needed. 369 /* Get a byte to update and step through the linked list as needed. */
370 int got = block_get(block); 370 int got = block_get(block);
371 if (got == -1) 371 if (got == -1)
372 // Reached the end. 372 /* Reached the end. */
373 break; 373 break;
374 *buf++ = (unsigned char)got; 374 *buf++ = (unsigned char)got;
375 need--; 375 need--;
@@ -382,11 +382,11 @@ local size_t block_read(block_t *block, unsigned char *buf, size_t len) {
382 buf += take; 382 buf += take;
383 need -= take; 383 need -= take;
384 } 384 }
385 return len - need; // return the number of bytes copied 385 return len - need; /* return the number of bytes copied */
386} 386}
387 387
388// Skip n bytes in block. Return 0 on success or -1 if there are less than n 388/* Skip n bytes in block. Return 0 on success or -1 if there are less than n
389// bytes to the end. 389// bytes to the end. */
390local int block_skip(block_t *block, size_t n) { 390local int block_skip(block_t *block, size_t n) {
391 while (n > block->left) { 391 while (n > block->left) {
392 n -= block->left; 392 n -= block->left;
@@ -401,103 +401,103 @@ local int block_skip(block_t *block, size_t n) {
401 return 0; 401 return 0;
402} 402}
403 403
404// Process the next central directory record at *block. Return the allocated, 404/* Process the next central directory record at *block. Return the allocated,
405// zero-terminated file name, or NULL for end of input or invalid data. If 405// zero-terminated file name, or NULL for end of input or invalid data. If
406// invalid, *block is marked bad. This uses *set for the allocation of memory. 406// invalid, *block is marked bad. This uses *set for the allocation of memory. */
407local char *block_central_name(block_t *block, set_t *set) { 407local char *block_central_name(block_t *block, set_t *set) {
408 char *name = NULL; 408 char *name = NULL;
409 for (;;) { 409 for (;;) {
410 if (block_end(block)) 410 if (block_end(block))
411 // At the end of the central directory (so far). 411 /* At the end of the central directory (so far). */
412 return NULL; 412 return NULL;
413 413
414 // Check for a central directory record signature. 414 /* Check for a central directory record signature. */
415 if (block_get2(block) != (CENTRALHEADERMAGIC & 0xffff) || 415 if (block_get2(block) != (CENTRALHEADERMAGIC & 0xffff) ||
416 block_get2(block) != (CENTRALHEADERMAGIC >> 16)) 416 block_get2(block) != (CENTRALHEADERMAGIC >> 16))
417 // Incorrect signature. 417 /* Incorrect signature. */
418 break; 418 break;
419 419
420 // Go through the remaining fixed-length portion of the record, 420 /* Go through the remaining fixed-length portion of the record,
421 // extracting the lengths of the three variable-length fields. 421 // extracting the lengths of the three variable-length fields. */
422 block_skip(block, 24); 422 block_skip(block, 24);
423 unsigned flen = block_get2(block); // file name length 423 unsigned flen = block_get2(block); /* file name length */
424 unsigned xlen = block_get2(block); // extra field length 424 unsigned xlen = block_get2(block); /* extra field length */
425 unsigned clen = block_get2(block); // comment field length 425 unsigned clen = block_get2(block); /* comment field length */
426 if (block_skip(block, 12) == -1) 426 if (block_skip(block, 12) == -1)
427 // Premature end of the record. 427 /* Premature end of the record. */
428 break; 428 break;
429 429
430 // Extract the name and skip over the extra and comment fields. 430 /* Extract the name and skip over the extra and comment fields. */
431 name = set_alloc(set, NULL, flen + 1); 431 name = set_alloc(set, NULL, flen + 1);
432 if (block_read(block, (unsigned char *)name, flen) < flen || 432 if (block_read(block, (unsigned char *)name, flen) < flen ||
433 block_skip(block, xlen + clen) == -1) 433 block_skip(block, xlen + clen) == -1)
434 // Premature end of the record. 434 /* Premature end of the record. */
435 break; 435 break;
436 436
437 // Check for embedded nuls in the name. 437 /* Check for embedded nuls in the name. */
438 if (memchr(name, 0, flen) != NULL) { 438 if (memchr(name, 0, flen) != NULL) {
439 // This name can never match the zero-terminated name provided to 439 /* This name can never match the zero-terminated name provided to
440 // zipAlreadyThere(), so we discard it and go back to get another 440 // zipAlreadyThere(), so we discard it and go back to get another
441 // name. (Who the heck is putting nuls inside their zip file entry 441 // name. (Who the heck is putting nuls inside their zip file entry
442 // names anyway?) 442 // names anyway?) */
443 set_free(set, name); 443 set_free(set, name);
444 continue; 444 continue;
445 } 445 }
446 446
447 // All good. Return the zero-terminated file name. 447 /* All good. Return the zero-terminated file name. */
448 name[flen] = 0; 448 name[flen] = 0;
449 return name; 449 return name;
450 } 450 }
451 451
452 // Invalid signature or premature end of the central directory record. 452 /* Invalid signature or premature end of the central directory record.
453 // Abandon trying to process the central directory. 453 // Abandon trying to process the central directory. */
454 set_free(set, name); 454 set_free(set, name);
455 block_stop(block); 455 block_stop(block);
456 return NULL; 456 return NULL;
457} 457}
458 458
459// Return 0 if name is not in the central directory so far, 1 if it is, -1 if 459/* Return 0 if name is not in the central directory so far, 1 if it is, -1 if
460// the central directory is invalid, -2 if out of memory, or ZIP_PARAMERROR if 460// the central directory is invalid, -2 if out of memory, or ZIP_PARAMERROR if
461// file is NULL. 461// file is NULL. */
462extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) { 462extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) {
463 zip64_internal *zip = file; 463 zip64_internal *zip = file;
464 if (zip == NULL) 464 if (zip == NULL)
465 return ZIP_PARAMERROR; 465 return ZIP_PARAMERROR;
466 if (zip->central_dir.first_block == NULL) 466 if (zip->central_dir.first_block == NULL)
467 // No central directory yet, so no, name isn't there. 467 /* No central directory yet, so no, name isn't there. */
468 return 0; 468 return 0;
469 if (setjmp(zip->set.env)) { 469 if (setjmp(zip->set.env)) {
470 // Memory allocation failure. 470 /* Memory allocation failure. */
471 set_end(&zip->set); 471 set_end(&zip->set);
472 return -2; 472 return -2;
473 } 473 }
474 if (!set_ok(&zip->set)) { 474 if (!set_ok(&zip->set)) {
475 // This is the first time here with some central directory content. We 475 /* This is the first time here with some central directory content. We
476 // construct this set of names only on demand. Prepare set and block. 476 // construct this set of names only on demand. Prepare set and block. */
477 set_start(&zip->set); 477 set_start(&zip->set);
478 block_init(&zip->block, &zip->central_dir); 478 block_init(&zip->block, &zip->central_dir);
479 } 479 }
480 480
481 // Update the set of names from the current central directory contents. 481 /* Update the set of names from the current central directory contents.
482 // This reads any new central directory records since the last time we were 482 // This reads any new central directory records since the last time we were
483 // here. 483 // here. */
484 for (;;) { 484 for (;;) {
485 char *there = block_central_name(&zip->block, &zip->set); 485 char *there = block_central_name(&zip->block, &zip->set);
486 if (there == NULL) { 486 if (there == NULL) {
487 if (zip->block.next == NULL) 487 if (zip->block.next == NULL)
488 // The central directory is invalid. 488 /* The central directory is invalid. */
489 return -1; 489 return -1;
490 break; 490 break;
491 } 491 }
492 492
493 // Add there to the set. 493 /* Add there to the set. */
494 if (set_insert(&zip->set, there)) 494 if (set_insert(&zip->set, there))
495 // There's already a duplicate in the central directory! We'll just 495 /* There's already a duplicate in the central directory! We'll just
496 // let this be and carry on. 496 // let this be and carry on. */
497 set_free(&zip->set, there); 497 set_free(&zip->set, there);
498 } 498 }
499 499
500 // Return true if name is in the central directory. 500 /* Return true if name is in the central directory. */
501 size_t len = strlen(name); 501 size_t len = strlen(name);
502 char *copy = set_alloc(&zip->set, NULL, len + 1); 502 char *copy = set_alloc(&zip->set, NULL, len + 1);
503 strcpy(copy, name); 503 strcpy(copy, name);
@@ -792,7 +792,7 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
792 792
793 for (i=(int)uReadSize-3; (i--)>0;) 793 for (i=(int)uReadSize-3; (i--)>0;)
794 { 794 {
795 // Signature "0x07064b50" Zip64 end of central directory locator 795 /* Signature "0x07064b50" Zip64 end of central directory locator */
796 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) 796 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
797 { 797 {
798 uPosFound = uReadPos+(unsigned)i; 798 uPosFound = uReadPos+(unsigned)i;
@@ -840,7 +840,7 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
840 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) 840 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
841 return 0; 841 return 0;
842 842
843 if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' 843 if (uL != 0x06064b50) /* signature of 'Zip64 end of central directory' */
844 return 0; 844 return 0;
845 845
846 return relativeOffset; 846 return relativeOffset;
@@ -869,7 +869,7 @@ local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
869 869
870 int hasZIP64Record = 0; 870 int hasZIP64Record = 0;
871 871
872 // check first if we find a ZIP64 record 872 /* check first if we find a ZIP64 record */
873 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); 873 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
874 if(central_pos > 0) 874 if(central_pos > 0)
875 { 875 {
@@ -935,13 +935,13 @@ local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
935 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) 935 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
936 err=ZIP_ERRNO; 936 err=ZIP_ERRNO;
937 937
938 // TODO.. 938 /* TODO..
939 // read the comment from the standard central header. 939 // read the comment from the standard central header. */
940 size_comment = 0; 940 size_comment = 0;
941 } 941 }
942 else 942 else
943 { 943 {
944 // Read End of central Directory info 944 /* Read End of central Directory info */
945 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 945 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
946 err=ZIP_ERRNO; 946 err=ZIP_ERRNO;
947 947
@@ -1084,7 +1084,7 @@ extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* glo
1084 ziinit.number_entry = 0; 1084 ziinit.number_entry = 0;
1085 ziinit.add_position_when_writing_offset = 0; 1085 ziinit.add_position_when_writing_offset = 0;
1086 init_linkedlist(&(ziinit.central_dir)); 1086 init_linkedlist(&(ziinit.central_dir));
1087 memset(&ziinit.set, 0, sizeof(set_t)); // make sure set appears dormant 1087 memset(&ziinit.set, 0, sizeof(set_t)); /* make sure set appears dormant */
1088 1088
1089 1089
1090 1090
@@ -1100,7 +1100,7 @@ extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* glo
1100 ziinit.globalcomment = NULL; 1100 ziinit.globalcomment = NULL;
1101 if (append == APPEND_STATUS_ADDINZIP) 1101 if (append == APPEND_STATUS_ADDINZIP)
1102 { 1102 {
1103 // Read and Cache Central Directory Records 1103 /* Read and Cache Central Directory Records */
1104 err = LoadCentralDirectoryRecord(&ziinit); 1104 err = LoadCentralDirectoryRecord(&ziinit);
1105 } 1105 }
1106 1106
@@ -1184,7 +1184,7 @@ local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt s
1184 if (err==ZIP_OK) 1184 if (err==ZIP_OK)
1185 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); 1185 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
1186 1186
1187 // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later 1187 /* CRC / Compressed size / Uncompressed size will be filled in later and rewritten later */
1188 if (err==ZIP_OK) 1188 if (err==ZIP_OK)
1189 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ 1189 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
1190 if (err==ZIP_OK) 1190 if (err==ZIP_OK)
@@ -1228,13 +1228,13 @@ local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt s
1228 1228
1229 if ((err==ZIP_OK) && (zi->ci.zip64)) 1229 if ((err==ZIP_OK) && (zi->ci.zip64))
1230 { 1230 {
1231 // write the Zip64 extended info 1231 /* write the Zip64 extended info */
1232 short HeaderID = 1; 1232 short HeaderID = 1;
1233 short DataSize = 16; 1233 short DataSize = 16;
1234 ZPOS64_T CompressedSize = 0; 1234 ZPOS64_T CompressedSize = 0;
1235 ZPOS64_T UncompressedSize = 0; 1235 ZPOS64_T UncompressedSize = 0;
1236 1236
1237 // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) 1237 /* Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) */
1238 zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); 1238 zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
1239 1239
1240 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)HeaderID,2); 1240 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)HeaderID,2);
@@ -1284,14 +1284,14 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
1284 return ZIP_PARAMERROR; 1284 return ZIP_PARAMERROR;
1285#endif 1285#endif
1286 1286
1287 // The filename and comment length must fit in 16 bits. 1287 /* The filename and comment length must fit in 16 bits. */
1288 if ((filename!=NULL) && (strlen(filename)>0xffff)) 1288 if ((filename!=NULL) && (strlen(filename)>0xffff))
1289 return ZIP_PARAMERROR; 1289 return ZIP_PARAMERROR;
1290 if ((comment!=NULL) && (strlen(comment)>0xffff)) 1290 if ((comment!=NULL) && (strlen(comment)>0xffff))
1291 return ZIP_PARAMERROR; 1291 return ZIP_PARAMERROR;
1292 // The extra field length must fit in 16 bits. If the member also requires 1292 /* The extra field length must fit in 16 bits. If the member also requires
1293 // a Zip64 extra block, that will also need to fit within that 16-bit 1293 // a Zip64 extra block, that will also need to fit within that 16-bit
1294 // length, but that will be checked for later. 1294 // length, but that will be checked for later. */
1295 if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff)) 1295 if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff))
1296 return ZIP_PARAMERROR; 1296 return ZIP_PARAMERROR;
1297 1297
@@ -1343,7 +1343,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
1343 zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); 1343 zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
1344 1344
1345 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; 1345 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
1346 zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data 1346 zi->ci.size_centralExtraFree = 32; /* Extra space we have reserved in case we need to add ZIP64 extra info data */
1347 1347
1348 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); 1348 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
1349 1349
@@ -1438,7 +1438,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
1438 else if(zi->ci.method == Z_BZIP2ED) 1438 else if(zi->ci.method == Z_BZIP2ED)
1439 { 1439 {
1440#ifdef HAVE_BZIP2 1440#ifdef HAVE_BZIP2
1441 // Init BZip stuff here 1441 /* Init BZip stuff here */
1442 zi->ci.bstream.bzalloc = 0; 1442 zi->ci.bstream.bzalloc = 0;
1443 zi->ci.bstream.bzfree = 0; 1443 zi->ci.bstream.bzfree = 0;
1444 zi->ci.bstream.opaque = (voidpf)0; 1444 zi->ci.bstream.opaque = (voidpf)0;
@@ -1640,7 +1640,7 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned i
1640 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) 1640 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1641 { 1641 {
1642 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; 1642 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1643// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; 1643/* uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; */
1644 err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); 1644 err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1645 1645
1646 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; 1646 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
@@ -1698,7 +1698,7 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned i
1698 zi->ci.pos_in_buffered_data += copy_this; 1698 zi->ci.pos_in_buffered_data += copy_this;
1699 } 1699 }
1700 } 1700 }
1701 }// while(...) 1701 }/* while(...) */
1702 } 1702 }
1703 1703
1704 return err; 1704 return err;
@@ -1804,7 +1804,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1804 compressed_size += zi->ci.crypt_header_size; 1804 compressed_size += zi->ci.crypt_header_size;
1805# endif 1805# endif
1806 1806
1807 // update Current Item crc and sizes, 1807 /* update Current Item crc and sizes, */
1808 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) 1808 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
1809 { 1809 {
1810 /*version Made by*/ 1810 /*version Made by*/
@@ -1822,7 +1822,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1822 else 1822 else
1823 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ 1823 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
1824 1824
1825 /// set internal file attributes field 1825 /* set internal file attributes field */
1826 if (zi->ci.stream.data_type == Z_ASCII) 1826 if (zi->ci.stream.data_type == Z_ASCII)
1827 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); 1827 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1828 1828
@@ -1831,15 +1831,15 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1831 else 1831 else
1832 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/ 1832 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
1833 1833
1834 // Add ZIP64 extra info field for uncompressed size 1834 /* Add ZIP64 extra info field for uncompressed size */
1835 if(uncompressed_size >= 0xffffffff) 1835 if(uncompressed_size >= 0xffffffff)
1836 datasize += 8; 1836 datasize += 8;
1837 1837
1838 // Add ZIP64 extra info field for compressed size 1838 /* Add ZIP64 extra info field for compressed size */
1839 if(compressed_size >= 0xffffffff) 1839 if(compressed_size >= 0xffffffff)
1840 datasize += 8; 1840 datasize += 8;
1841 1841
1842 // Add ZIP64 extra info field for relative offset to local file header of current file 1842 /* Add ZIP64 extra info field for relative offset to local file header of current file */
1843 if(zi->ci.pos_local_header >= 0xffffffff) 1843 if(zi->ci.pos_local_header >= 0xffffffff)
1844 datasize += 8; 1844 datasize += 8;
1845 1845
@@ -1849,16 +1849,16 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1849 1849
1850 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) 1850 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
1851 { 1851 {
1852 // we cannot write more data to the buffer that we have room for. 1852 /* we cannot write more data to the buffer that we have room for. */
1853 return ZIP_BADZIPFILE; 1853 return ZIP_BADZIPFILE;
1854 } 1854 }
1855 1855
1856 p = zi->ci.central_header + zi->ci.size_centralheader; 1856 p = zi->ci.central_header + zi->ci.size_centralheader;
1857 1857
1858 // Add Extra Information Header for 'ZIP64 information' 1858 /* Add Extra Information Header for 'ZIP64 information' */
1859 zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID 1859 zip64local_putValue_inmemory(p, 0x0001, 2); /* HeaderID */
1860 p += 2; 1860 p += 2;
1861 zip64local_putValue_inmemory(p, datasize, 2); // DataSize 1861 zip64local_putValue_inmemory(p, datasize, 2); /* DataSize */
1862 p += 2; 1862 p += 2;
1863 1863
1864 if(uncompressed_size >= 0xffffffff) 1864 if(uncompressed_size >= 0xffffffff)
@@ -1879,13 +1879,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1879 p += 8; 1879 p += 8;
1880 } 1880 }
1881 1881
1882 // Update how much extra free space we got in the memory buffer 1882 /* Update how much extra free space we got in the memory buffer
1883 // and increase the centralheader size so the new ZIP64 fields are included 1883 // and increase the centralheader size so the new ZIP64 fields are included
1884 // ( 4 below is the size of HeaderID and DataSize field ) 1884 // ( 4 below is the size of HeaderID and DataSize field ) */
1885 zi->ci.size_centralExtraFree -= datasize + 4; 1885 zi->ci.size_centralExtraFree -= datasize + 4;
1886 zi->ci.size_centralheader += datasize + 4; 1886 zi->ci.size_centralheader += datasize + 4;
1887 1887
1888 // Update the extra info size field 1888 /* Update the extra info size field */
1889 zi->ci.size_centralExtra += datasize + 4; 1889 zi->ci.size_centralExtra += datasize + 4;
1890 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); 1890 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
1891 } 1891 }
@@ -1897,7 +1897,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1897 1897
1898 if (err==ZIP_OK) 1898 if (err==ZIP_OK)
1899 { 1899 {
1900 // Update the LocalFileHeader with the new values. 1900 /* Update the LocalFileHeader with the new values. */
1901 1901
1902 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); 1902 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1903 1903
@@ -1911,7 +1911,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1911 { 1911 {
1912 if(zi->ci.pos_zip64extrainfo > 0) 1912 if(zi->ci.pos_zip64extrainfo > 0)
1913 { 1913 {
1914 // Update the size in the ZIP64 extended field. 1914 /* Update the size in the ZIP64 extended field. */
1915 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0) 1915 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
1916 err = ZIP_ERRNO; 1916 err = ZIP_ERRNO;
1917 1917
@@ -1922,7 +1922,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
1922 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); 1922 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
1923 } 1923 }
1924 else 1924 else
1925 err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal 1925 err = ZIP_BADZIPFILE; /* Caller passed zip64 = 0, so no room for zip64 info -> fatal */
1926 } 1926 }
1927 else 1927 else
1928 { 1928 {
@@ -1976,7 +1976,7 @@ local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_
1976 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); 1976 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
1977 1977
1978 if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ 1978 if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
1979 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? 1979 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); /* why ZPOS64_T of this ? */
1980 1980
1981 if (err==ZIP_OK) /* version made by */ 1981 if (err==ZIP_OK) /* version made by */
1982 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); 1982 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
@@ -2023,7 +2023,7 @@ local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centr
2023 { 2023 {
2024 { 2024 {
2025 if(zi->number_entry >= 0xFFFF) 2025 if(zi->number_entry >= 0xFFFF)
2026 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record 2026 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
2027 else 2027 else
2028 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); 2028 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
2029 } 2029 }
@@ -2032,7 +2032,7 @@ local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centr
2032 if (err==ZIP_OK) /* total number of entries in the central dir */ 2032 if (err==ZIP_OK) /* total number of entries in the central dir */
2033 { 2033 {
2034 if(zi->number_entry >= 0xFFFF) 2034 if(zi->number_entry >= 0xFFFF)
2035 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record 2035 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
2036 else 2036 else
2037 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); 2037 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
2038 } 2038 }
@@ -2112,7 +2112,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) {
2112 } 2112 }
2113 free_linkedlist(&(zi->central_dir)); 2113 free_linkedlist(&(zi->central_dir));
2114 2114
2115 set_end(&zi->set); // set was zeroed, so this is safe 2115 set_end(&zi->set); /* set was zeroed, so this is safe */
2116 2116
2117 pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; 2117 pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
2118 if(pos >= 0xffffffff || zi->number_entry >= 0xFFFF) 2118 if(pos >= 0xffffffff || zi->number_entry >= 0xFFFF)
@@ -2162,13 +2162,13 @@ extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHea
2162 header = *(short*)p; 2162 header = *(short*)p;
2163 dataSize = *(((short*)p)+1); 2163 dataSize = *(((short*)p)+1);
2164 2164
2165 if( header == sHeader ) // Header found. 2165 if( header == sHeader ) /* Header found. */
2166 { 2166 {
2167 p += dataSize + 4; // skip it. do not copy to temp buffer 2167 p += dataSize + 4; /* skip it. do not copy to temp buffer */
2168 } 2168 }
2169 else 2169 else
2170 { 2170 {
2171 // Extra Info block should not be removed, So copy it to the temp buffer. 2171 /* Extra Info block should not be removed, So copy it to the temp buffer. */
2172 memcpy(pTmp, p, dataSize + 4); 2172 memcpy(pTmp, p, dataSize + 4);
2173 p += dataSize + 4; 2173 p += dataSize + 4;
2174 size += dataSize + 4; 2174 size += dataSize + 4;
@@ -2178,14 +2178,14 @@ extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHea
2178 2178
2179 if(size < *dataLen) 2179 if(size < *dataLen)
2180 { 2180 {
2181 // clean old extra info block. 2181 /* clean old extra info block. */
2182 memset(pData,0, *dataLen); 2182 memset(pData,0, *dataLen);
2183 2183
2184 // copy the new extra info block over the old 2184 /* copy the new extra info block over the old */
2185 if(size > 0) 2185 if(size > 0)
2186 memcpy(pData, pNewHeader, size); 2186 memcpy(pData, pNewHeader, size);
2187 2187
2188 // set the new extra info size 2188 /* set the new extra info size */
2189 *dataLen = size; 2189 *dataLen = size;
2190 2190
2191 retVal = ZIP_OK; 2191 retVal = ZIP_OK;