in ios/CodePush/SSZipArchive/minizip/zip.c [1747:1909]
extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
{
zip64_internal *zi;
int err = 0;
uLong size_centraldir = 0;
uInt size_global_comment = 0;
ZPOS64_T centraldir_pos_inzip;
ZPOS64_T pos = 0;
uLong write = 0;
if (file == NULL)
return ZIP_PARAMERROR;
zi = (zip64_internal *)file;
if (zi->in_opened_file_inzip == 1)
err = zipCloseFileInZip(file);
#ifndef NO_ADDFILEINEXISTINGZIP
if (global_comment == NULL)
global_comment = zi->globalcomment;
#endif
if (zi->filestream != zi->filestream_with_CD) {
if (ZCLOSE64(zi->z_filefunc, zi->filestream) != 0)
if (err == ZIP_OK)
err = ZIP_ERRNO;
if (zi->disk_size > 0)
zi->number_disk_with_CD = zi->number_disk + 1;
zi->filestream = zi->filestream_with_CD;
}
centraldir_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
if (err == ZIP_OK) {
linkedlist_datablock_internal *ldi = zi->central_dir.first_block;
while (ldi != NULL) {
if ((err == ZIP_OK) && (ldi->filled_in_this_block > 0)) {
write = ZWRITE64(zi->z_filefunc, zi->filestream, ldi->data, ldi->filled_in_this_block);
if (write != ldi->filled_in_this_block)
err = ZIP_ERRNO;
}
size_centraldir += ldi->filled_in_this_block;
ldi = ldi->next_datablock;
}
}
free_linkedlist(&(zi->central_dir));
pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
/* Write the ZIP64 central directory header */
if (pos >= 0xffffffff || zi->number_entry > 0xffff) {
ZPOS64_T zip64eocd_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
uLong zip64datasize = 44;
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ZIP64ENDHEADERMAGIC, 4);
/* size of this 'zip64 end of central directory' */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)zip64datasize, 8);
/* version made by */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2);
/* version needed */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2);
/* number of this disk */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
/* number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
/* total number of entries in the central dir on this disk */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
/* total number of entries in the central dir */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
/* size of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)size_centraldir, 8);
if (err == ZIP_OK) {
/* offset of start of central directory with respect to the starting disk number */
ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)pos, 8);
}
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ZIP64ENDLOCHEADERMAGIC, 4);
/* number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
/*relative offset to the Zip64EndOfCentralDirectory */
if (err == ZIP_OK) {
ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, pos, 8);
}
/* number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD + 1, 4);
}
/* Write the central directory header */
/* signature */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ENDHEADERMAGIC, 4);
/* number of this disk */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 2);
/* number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 2);
/* total number of entries in the central dir on this disk */
if (err == ZIP_OK) {
if (zi->number_entry >= 0xffff)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffff, 2); /* use value in ZIP64 record */
else
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_entry, 2);
}
/* total number of entries in the central dir */
if (err == ZIP_OK) {
if (zi->number_entry >= 0xffff)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffff, 2); /* use value in ZIP64 record */
else
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_entry, 2);
}
/* size of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_centraldir, 4);
/* offset of start of central directory with respect to the starting disk number */
if (err == ZIP_OK) {
ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
if (pos >= 0xffffffff)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffffffff, 4);
else
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)pos, 4);
}
/* Write global comment */
if (global_comment != NULL)
size_global_comment = (uInt)strlen(global_comment);
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_global_comment, 2);
if (err == ZIP_OK && size_global_comment > 0) {
if (ZWRITE64(zi->z_filefunc, zi->filestream, global_comment, size_global_comment) != size_global_comment)
err = ZIP_ERRNO;
}
if ((ZCLOSE64(zi->z_filefunc, zi->filestream) != 0) && (err == ZIP_OK))
err = ZIP_ERRNO;
#ifndef NO_ADDFILEINEXISTINGZIP
TRYFREE(zi->globalcomment);
#endif
TRYFREE(zi);
return err;
}