diff --git a/SSZipArchive/SSZipArchive.m b/SSZipArchive/SSZipArchive.m index c7a8f45..35d1f59 100644 --- a/SSZipArchive/SSZipArchive.m +++ b/SSZipArchive/SSZipArchive.m @@ -5,7 +5,6 @@ // Created by Sam Soffes on 7/21/10. // Copyright (c) Sam Soffes 2010-2015. All rights reserved. // - #import "SSZipArchive.h" #include "unzip.h" #include "zip.h" @@ -15,7 +14,6 @@ #include #define CHUNK 16384 -#define HAVE_AES @interface SSZipArchive () + (NSDate *)_dateWithMSDOSFormat:(UInt32)msdosDateTime; @@ -120,6 +118,7 @@ BOOL success = YES; BOOL canceled = NO; int ret = 0; + int crc_ret =0; unsigned char buffer[4096] = {0}; NSFileManager *fileManager = [NSFileManager defaultManager]; NSMutableSet *directoriesModificationDates = [[NSMutableSet alloc] init]; @@ -232,6 +231,7 @@ [directoriesModificationDates addObject: @{@"path": fullPath, @"modDate": modDate}]; if ([fileManager fileExistsAtPath:fullPath] && !isDirectory && !overwrite) { + //FIXME: couldBe CRC Check? unzCloseCurrentFile(zip); ret = unzGoToNextFile(zip); continue; @@ -317,7 +317,11 @@ } } - unzCloseCurrentFile( zip ); + crc_ret = unzCloseCurrentFile( zip ); + if (crc_ret == UNZ_CRCERROR) { + //CRC ERROR + return NO; + } ret = unzGoToNextFile( zip ); // Message delegate diff --git a/SSZipArchive/minizip/aes/entropy.c b/SSZipArchive/minizip/aes/entropy.c index e00d65f..5840a97 100755 --- a/SSZipArchive/minizip/aes/entropy.c +++ b/SSZipArchive/minizip/aes/entropy.c @@ -3,12 +3,13 @@ #else #include #include +#include +#endif + +#if defined(__cplusplus) +extern "C" +{ #endif - -#if defined(__cplusplus) -extern "C" -{ -#endif #ifdef _WIN32 int entropy_fun(unsigned char buf[], unsigned int len) @@ -37,17 +38,17 @@ int entropy_fun(unsigned char buf[], unsigned int len) #else int entropy_fun(unsigned char buf[], unsigned int len) { - int frand = open("/dev/random", O_RDONLY); - int rlen = 0; - if (frand != -1) - { - rlen = read(frand, buf, len); + int frand = open("/dev/random", O_RDONLY); + int rlen = 0; + if (frand != -1) + { + rlen = (int)read(frand, buf, len); close(frand); } return rlen; } -#endif - -#if defined(__cplusplus) -} -#endif +#endif + +#if defined(__cplusplus) +} +#endif diff --git a/SSZipArchive/minizip/unzip.c b/SSZipArchive/minizip/unzip.c index 7c8d913..76a8892 100755 --- a/SSZipArchive/minizip/unzip.c +++ b/SSZipArchive/minizip/unzip.c @@ -853,16 +853,16 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p if (uL != 1 && uL != 2) err = UNZ_ERRNO; file_info_internal.aes_version = uL; - if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK) + if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, (int *)&uL) != UNZ_OK) err = UNZ_ERRNO; if ((char)uL != 'A') err = UNZ_ERRNO; - if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK) + if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, (int *)&uL) != UNZ_OK) err = UNZ_ERRNO; if ((char)uL != 'E') err = UNZ_ERRNO; /* Get AES encryption strength and actual compression method */ - if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK) + if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, (int *)&uL) != UNZ_OK) err = UNZ_ERRNO; file_info_internal.aes_encryption_mode = uL; if (unz64local_getShort(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK) @@ -1202,7 +1202,7 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in if (ZREAD64(s->z_filefunc, s->filestream, passverify, AES_PWVERIFYSIZE) != AES_PWVERIFYSIZE) return UNZ_INTERNALERROR; - fcrypt_init(s->cur_file_info_internal.aes_encryption_mode, password, strlen(password), saltvalue, + fcrypt_init((int)s->cur_file_info_internal.aes_encryption_mode, (unsigned char *)password, (unsigned int)strlen(password), saltvalue, passverify, &s->pfile_in_zip_read->aes_ctx); pfile_in_zip_read_info->rest_read_compressed -= saltlength + AES_PWVERIFYSIZE; @@ -1293,7 +1293,7 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) if (pfile_in_zip_read_info->stream.next_in != NULL) bytes_not_read = (uInt)(pfile_in_zip_read_info->read_buffer + UNZ_BUFSIZE - - pfile_in_zip_read_info->stream.next_in); + pfile_in_zip_read_info->stream.next_in); bytes_to_read -= bytes_not_read; if (bytes_not_read > 0) memcpy(pfile_in_zip_read_info->read_buffer, pfile_in_zip_read_info->stream.next_in, bytes_not_read); diff --git a/SSZipArchive/minizip/unzip.h b/SSZipArchive/minizip/unzip.h index 22c830f..449615b 100755 --- a/SSZipArchive/minizip/unzip.h +++ b/SSZipArchive/minizip/unzip.h @@ -17,6 +17,8 @@ #ifndef _UNZ_H #define _UNZ_H +#define HAVE_AES + #ifdef __cplusplus extern "C" { #endif diff --git a/SSZipArchive/minizip/zip.c b/SSZipArchive/minizip/zip.c index fec002f..47d70f7 100755 --- a/SSZipArchive/minizip/zip.c +++ b/SSZipArchive/minizip/zip.c @@ -12,7 +12,7 @@ This program is distributed under the terms of the same license as zlib. See the accompanying LICENSE file for the full text of the license. -*/ + */ #include #include @@ -27,7 +27,7 @@ # include #endif #ifdef NO_ERRNO_H - extern int errno; +extern int errno; #else # include #endif @@ -56,7 +56,7 @@ #endif /* compile with -Dlocal if your debugger can't find static symbols */ -#define SIZEDATA_INDATABLOCK (4096-(4*4)) +#define SIZEDATA_INDATABLOCK (4096 - (4 * 4)) #define DISKHEADERMAGIC (0x08074b50) #define LOCALHEADERMAGIC (0x04034b50) @@ -81,7 +81,7 @@ #endif #ifndef Z_BUFSIZE -# define Z_BUFSIZE (64*1024) +# define Z_BUFSIZE (64 * 1024) #endif #ifndef Z_MAXFILENAMEINZIP # define Z_MAXFILENAMEINZIP (256) @@ -91,7 +91,7 @@ # define ALLOC(size) (malloc(size)) #endif #ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} +# define TRYFREE(p) {if (p) free(p); } #endif /* NOT sure that this work on ALL platform */ @@ -107,23 +107,20 @@ const char zip_copyright[] = " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; -typedef struct linkedlist_datablock_internal_s -{ - struct linkedlist_datablock_internal_s* next_datablock; - uLong avail_in_this_block; - uLong filled_in_this_block; - uLong unused; /* for future use and alignment */ +typedef struct linkedlist_datablock_internal_s { + struct linkedlist_datablock_internal_s *next_datablock; + uLong avail_in_this_block; + uLong filled_in_this_block; + uLong unused; /* for future use and alignment */ unsigned char data[SIZEDATA_INDATABLOCK]; } linkedlist_datablock_internal; -typedef struct linkedlist_data_s -{ - linkedlist_datablock_internal* first_block; - linkedlist_datablock_internal* last_block; +typedef struct linkedlist_data_s { + linkedlist_datablock_internal *first_block; + linkedlist_datablock_internal *last_block; } linkedlist_data; -typedef struct -{ +typedef struct { z_stream stream; /* zLib stream structure for inflate */ #ifdef HAVE_BZIP2 bz_stream bstream; /* bzLib stream structure for bziped */ @@ -132,37 +129,36 @@ typedef struct fcrypt_ctx aes_ctx; prng_ctx aes_rng[1]; #endif - int stream_initialised; /* 1 is stream is initialized */ + int stream_initialised; /* 1 is stream is initialized */ uInt pos_in_buffered_data; /* last written byte in buffered_data */ ZPOS64_T pos_local_header; /* offset of the local header of the file currently writing */ - char* central_header; /* central header data for the current file */ + char *central_header; /* central header data for the current file */ uLong size_centralextra; uLong size_centralheader; /* size of the central header for cur file */ uLong size_centralextrafree; /* Extra bytes allocated to the central header but that are not used */ uLong size_comment; uLong flag; /* flag of the file currently writing */ - int method; /* compression method written to file.*/ - int compression_method; /* compression method to use */ - int raw; /* 1 for directly writing raw data */ + int method; /* compression method written to file.*/ + int compression_method; /* compression method to use */ + int raw; /* 1 for directly writing raw data */ Byte buffered_data[Z_BUFSIZE]; /* buffer contain compressed data to be writ*/ uLong dosDate; uLong crc32; - int zip64; /* Add ZIP64 extended information in the extra field */ + int zip64; /* Add ZIP64 extended information in the extra field */ uLong number_disk; /* number of current disk used for spanning ZIP */ ZPOS64_T pos_zip64extrainfo; ZPOS64_T total_compressed; ZPOS64_T total_uncompressed; #ifndef NOCRYPT unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const unsigned long* pcrc_32_tab; + const unsigned long *pcrc_32_tab; int crypt_header_size; #endif } curfile64_info; -typedef struct -{ +typedef struct { zlib_filefunc64_32_def z_filefunc; voidpf filestream; /* io structure of the zipfile */ voidpf filestream_with_CD; /* io structure of the zipfile with the central dir */ @@ -183,15 +179,14 @@ typedef struct } zip64_internal; /* Allocate a new data block */ -local linkedlist_datablock_internal* allocate_new_datablock OF(()); -local linkedlist_datablock_internal* allocate_new_datablock() +local linkedlist_datablock_internal *allocate_new_datablock OF(()); +local linkedlist_datablock_internal *allocate_new_datablock() { - linkedlist_datablock_internal* ldi; + linkedlist_datablock_internal *ldi; - ldi = (linkedlist_datablock_internal*)ALLOC(sizeof(linkedlist_datablock_internal)); + ldi = (linkedlist_datablock_internal *)ALLOC(sizeof(linkedlist_datablock_internal)); - if (ldi != NULL) - { + if (ldi != NULL) { ldi->next_datablock = NULL; ldi->filled_in_this_block = 0; ldi->avail_in_this_block = SIZEDATA_INDATABLOCK; @@ -200,64 +195,60 @@ local linkedlist_datablock_internal* allocate_new_datablock() } /* Free data block in linked list */ -local void free_datablock OF((linkedlist_datablock_internal* ldi)); -local void free_datablock(linkedlist_datablock_internal* ldi) +local void free_datablock OF((linkedlist_datablock_internal * ldi)); +local void free_datablock(linkedlist_datablock_internal *ldi) { - while (ldi != NULL) - { - linkedlist_datablock_internal* ldinext = ldi->next_datablock; + while (ldi != NULL) { + linkedlist_datablock_internal *ldinext = ldi->next_datablock; TRYFREE(ldi); ldi = ldinext; } } /* Initialize linked list */ -local void init_linkedlist OF((linkedlist_data* ll)); -local void init_linkedlist(linkedlist_data* ll) +local void init_linkedlist OF((linkedlist_data * ll)); +local void init_linkedlist(linkedlist_data *ll) { ll->first_block = ll->last_block = NULL; } /* Free entire linked list and all data blocks */ -local void free_linkedlist OF((linkedlist_data* ll)); -local void free_linkedlist(linkedlist_data* ll) +local void free_linkedlist OF((linkedlist_data * ll)); +local void free_linkedlist(linkedlist_data *ll) { free_datablock(ll->first_block); ll->first_block = ll->last_block = NULL; } /* Add data to linked list data block */ -local int add_data_in_datablock OF((linkedlist_data* ll, const void* buf, uLong len)); -local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) +local int add_data_in_datablock OF((linkedlist_data * ll, const void *buf, uLong len)); +local int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len) { - linkedlist_datablock_internal* ldi; - const unsigned char* from_copy; + linkedlist_datablock_internal *ldi; + const unsigned char *from_copy; if (ll == NULL) return ZIP_INTERNALERROR; - if (ll->last_block == NULL) - { + if (ll->last_block == NULL) { ll->first_block = ll->last_block = allocate_new_datablock(); if (ll->first_block == NULL) return ZIP_INTERNALERROR; } ldi = ll->last_block; - from_copy = (unsigned char*)buf; + from_copy = (unsigned char *)buf; - while (len>0) - { + while (len > 0) { uInt copy_this; uInt i; - unsigned char* to_copy; + unsigned char *to_copy; - if (ldi->avail_in_this_block == 0) - { + if (ldi->avail_in_this_block == 0) { ldi->next_datablock = allocate_new_datablock(); if (ldi->next_datablock == NULL) return ZIP_INTERNALERROR; - ldi = ldi->next_datablock ; + ldi = ldi->next_datablock; ll->last_block = ldi; } @@ -268,36 +259,36 @@ local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) to_copy = &(ldi->data[ldi->filled_in_this_block]); - for (i=0;ifilled_in_this_block += copy_this; ldi->avail_in_this_block -= copy_this; - from_copy += copy_this ; + from_copy += copy_this; len -= copy_this; } return ZIP_OK; } -local uLong zip64local_TmzDateToDosDate OF((const tm_zip* ptm)); -local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) +local uLong zip64local_TmzDateToDosDate OF((const tm_zip * ptm)); +local uLong zip64local_TmzDateToDosDate(const tm_zip *ptm) { uLong year; #define zip64local_in_range(min, max, value) ((min) <= (value) && (value) <= (max)) /* Years supported: - * [00, 79] (assumed to be between 2000 and 2079) - * [80, 207] (assumed to be between 1980 and 2107, typical output of old + * [00, 79] (assumed to be between 2000 and 2079) + * [80, 207] (assumed to be between 1980 and 2107, typical output of old software that does 'year-1900' to get a double digit year) - * [1980, 2107] + * [1980, 2107] Due to the date format limitations, only years between 1980 and 2107 can be stored. - */ + */ if (!(zip64local_in_range(1980, 2107, ptm->tm_year) || zip64local_in_range(0, 207, ptm->tm_year)) || !zip64local_in_range(0, 11, ptm->tm_mon) || !zip64local_in_range(1, 31, ptm->tm_mday) || !zip64local_in_range(0, 23, ptm->tm_hour) || !zip64local_in_range(0, 59, ptm->tm_min) || !zip64local_in_range(0, 59, ptm->tm_sec)) - return 0; + return 0; #undef zip64local_in_range year = (uLong)ptm->tm_year; @@ -309,65 +300,59 @@ local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) year += 20; return - (uLong)(((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | - ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); + (uLong)(((ptm->tm_mday) + (32 * (ptm->tm_mon + 1)) + (512 * year)) << 16) | + ((ptm->tm_sec / 2) + (32 * ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); } /* Inputs a long in LSB order to the given file: nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) */ -local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, - ZPOS64_T x, int nbByte)); -local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, - ZPOS64_T x, int nbByte) +local int zip64local_putValue OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, + ZPOS64_T x, int nbByte)); +local int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, + ZPOS64_T x, int nbByte) { unsigned char buf[8]; int n; - for (n = 0; n < nbByte; n++) - { + for (n = 0; n < nbByte; n++) { buf[n] = (unsigned char)(x & 0xff); x >>= 8; } - if (x != 0) - { + if (x != 0) { /* data overflow - hack for ZIP64 (X Roche) */ - for (n = 0; n < nbByte; n++) - { + for (n = 0; n < nbByte; n++) { buf[n] = 0xff; } } - if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) + if (ZWRITE64(*pzlib_filefunc_def, filestream, buf, nbByte) != (uLong)nbByte) return ZIP_ERRNO; return ZIP_OK; } -local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); -local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) +local void zip64local_putValue_inmemory OF((void *dest, ZPOS64_T x, int nbByte)); +local void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte) { - unsigned char* buf =(unsigned char*)dest; + unsigned char *buf = (unsigned char *)dest; int n; for (n = 0; n < nbByte; n++) { buf[n] = (unsigned char)(x & 0xff); x >>= 8; } - if (x != 0) - { - /* data overflow - hack for ZIP64 */ - for (n = 0; n < nbByte; n++) - { - buf[n] = 0xff; - } + if (x != 0) { + /* data overflow - hack for ZIP64 */ + for (n = 0; n < nbByte; n++) { + buf[n] = 0xff; + } } } -local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); -local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) +local int zip64local_getByte OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, int *pi)); +local int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi) { unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def, filestream, &c,1); - if (err == 1) - { + int err = (int)ZREAD64(*pzlib_filefunc_def, filestream, &c, 1); + if (err == 1) { *pi = (int)c; return ZIP_OK; } @@ -376,8 +361,8 @@ local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,vo return ZIP_EOF; } -local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); -local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) +local int zip64local_getShort OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX)); +local int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX) { uLong x; int i = 0; @@ -396,8 +381,8 @@ local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, return err; } -local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); -local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) +local int zip64local_getLong OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX)); +local int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX) { uLong x; int i = 0; @@ -407,13 +392,13 @@ local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, x = (uLong)i; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((uLong)i)<<8; + x += ((uLong)i) << 8; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((uLong)i)<<16; + x += ((uLong)i) << 16; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((uLong)i)<<24; + x += ((uLong)i) << 24; if (err == ZIP_OK) *pX = x; @@ -422,8 +407,8 @@ local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, return err; } -local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); -local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) +local int zip64local_getLong64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, ZPOS64_T * pX)); +local int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) { ZPOS64_T x; int i = 0; @@ -433,25 +418,25 @@ local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def x = (ZPOS64_T)i; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<8; + x += ((ZPOS64_T)i) << 8; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<16; + x += ((ZPOS64_T)i) << 16; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<24; + x += ((ZPOS64_T)i) << 24; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<32; + x += ((ZPOS64_T)i) << 32; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<40; + x += ((ZPOS64_T)i) << 40; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<48; + x += ((ZPOS64_T)i) << 48; if (err == ZIP_OK) err = zip64local_getByte(pzlib_filefunc_def, filestream, &i); - x += ((ZPOS64_T)i)<<56; + x += ((ZPOS64_T)i) << 56; if (err == ZIP_OK) *pX = x; @@ -462,13 +447,13 @@ local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def } /* Gets the amount of bytes left to write to the current disk for spanning archives */ -local int zipGetDiskSizeAvailable OF((zipFile file, ZPOS64_T *size_available)); +local int zipGetDiskSizeAvailable OF((zipFile file, ZPOS64_T * size_available)); local int zipGetDiskSizeAvailable(zipFile file, ZPOS64_T *size_available) { - zip64_internal* zi; + zip64_internal *zi; ZPOS64_T current_disk_size; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; ZSEEK64(zi->z_filefunc, zi->filestream, 0, ZLIB_FILEFUNC_SEEK_END); current_disk_size = ZTELL64(zi->z_filefunc, zi->filestream); *size_available = zi->disk_size - current_disk_size; @@ -479,10 +464,10 @@ local int zipGetDiskSizeAvailable(zipFile file, ZPOS64_T *size_available) local int zipGoToSpecificDisk OF((zipFile file, int number_disk, int open_existing)); local int zipGoToSpecificDisk(zipFile file, int number_disk, int open_existing) { - zip64_internal* zi; + zip64_internal *zi; int err = ZIP_OK; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; if (zi->disk_size == 0) return err; @@ -490,8 +475,8 @@ local int zipGoToSpecificDisk(zipFile file, int number_disk, int open_existing) ZCLOSE64(zi->z_filefunc, zi->filestream); zi->filestream = ZOPENDISK64(zi->z_filefunc, zi->filestream_with_CD, number_disk, (open_existing == 1) ? - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING) : - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE)); + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING) : + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE)); if (zi->filestream == NULL) err = ZIP_ERRNO; @@ -503,11 +488,11 @@ local int zipGoToSpecificDisk(zipFile file, int number_disk, int open_existing) local int zipGoToFirstDisk OF((zipFile file)); local int zipGoToFirstDisk(zipFile file) { - zip64_internal* zi; + zip64_internal *zi; int number_disk_next; int err = ZIP_OK; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; if (zi->disk_size == 0) return err; @@ -527,20 +512,19 @@ local int zipGoToFirstDisk(zipFile file) local int zipGoToNextDisk OF((zipFile file)); local int zipGoToNextDisk(zipFile file) { - zip64_internal* zi; + zip64_internal *zi; ZPOS64_T size_available_in_disk; int err = ZIP_OK; int number_disk_next; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; if (zi->disk_size == 0) return err; number_disk_next = (int)zi->number_disk + 1; - do - { + do { err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP)); if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP)) err = zipGoToSpecificDisk(file, number_disk_next, 0); @@ -553,31 +537,29 @@ local int zipGoToNextDisk(zipFile file) zi->number_disk_with_CD = zi->number_disk + 1; number_disk_next += 1; - } - while (size_available_in_disk <= 0); + } while (size_available_in_disk <= 0); return err; } /* Locate the Central directory of a zipfile (at the end, just before the global comment) */ -local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); -local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream)); +local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream) { - unsigned char* buf; + unsigned char *buf; ZPOS64_T file_size; ZPOS64_T back_read = 4; - ZPOS64_T max_back=0xffff; /* maximum size of global comment */ - ZPOS64_T pos_found=0; + ZPOS64_T max_back = 0xffff; /* maximum size of global comment */ + ZPOS64_T pos_found = 0; uLong read_size; ZPOS64_T read_pos; int i; - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + buf = (unsigned char *)ALLOC(BUFREADCOMMENT + 4); if (buf == NULL) return 0; - if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) - { + if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) { TRYFREE(buf); return 0; } @@ -587,29 +569,27 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f if (max_back > file_size) max_back = file_size; - while (back_read < max_back) - { + while (back_read < max_back) { if (back_read + BUFREADCOMMENT > max_back) back_read = max_back; else back_read += BUFREADCOMMENT; - read_pos = file_size-back_read; - read_size = ((BUFREADCOMMENT+4) < (file_size-read_pos)) ? - (BUFREADCOMMENT+4) : (uLong)(file_size-read_pos); + read_pos = file_size - back_read; + read_size = ((BUFREADCOMMENT + 4) < (file_size - read_pos)) ? + (BUFREADCOMMENT + 4) : (uLong)(file_size - read_pos); if (ZSEEK64(*pzlib_filefunc_def, filestream, read_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) break; if (ZREAD64(*pzlib_filefunc_def, filestream, buf, read_size) != read_size) break; - for (i = (int)read_size-3; (i--) > 0;) - if ((*(buf+i)) == (ENDHEADERMAGIC & 0xff) && - (*(buf+i+1)) == (ENDHEADERMAGIC >> 8 & 0xff) && - (*(buf+i+2)) == (ENDHEADERMAGIC >> 16 & 0xff) && - (*(buf+i+3)) == (ENDHEADERMAGIC >> 24 & 0xff)) - { - pos_found = read_pos+i; + for (i = (int)read_size - 3; (i--) > 0; ) + if ((*(buf + i)) == (ENDHEADERMAGIC & 0xff) && + (*(buf + i + 1)) == (ENDHEADERMAGIC >> 8 & 0xff) && + (*(buf + i + 2)) == (ENDHEADERMAGIC >> 16 & 0xff) && + (*(buf + i + 3)) == (ENDHEADERMAGIC >> 24 & 0xff)) { + pos_found = read_pos + i; break; } @@ -621,10 +601,10 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f } /* Locate the Central directory 64 of a zipfile (at the end, just before the global comment) */ -local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, - const ZPOS64_T endcentraloffset)); -local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, - const ZPOS64_T endcentraloffset) +local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, + const ZPOS64_T endcentraloffset)); +local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, + const ZPOS64_T endcentraloffset) { ZPOS64_T offset; uLong uL; @@ -648,9 +628,9 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK) return 0; /* Goto end of central directory record */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, offset, ZLIB_FILEFUNC_SEEK_SET) != 0) + if (ZSEEK64(*pzlib_filefunc_def, filestream, offset, ZLIB_FILEFUNC_SEEK_SET) != 0) return 0; - /* the signature */ + /* the signature */ if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK) return 0; if (uL != ZIP64ENDHEADERMAGIC) @@ -659,11 +639,11 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib return offset; } -extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc* globalcomment, - zlib_filefunc64_32_def* pzlib_filefunc64_32_def) +extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment, + zlib_filefunc64_32_def *pzlib_filefunc64_32_def) { zip64_internal ziinit; - zip64_internal* zi; + zip64_internal *zi; #ifndef NO_ADDFILEINEXISTINGZIP ZPOS64_T byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx)*/ ZPOS64_T size_central_dir = 0; /* size of the central directory */ @@ -675,7 +655,7 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ uLong uL; uLong size_comment = 0; size_t buf_size = SIZEDATA_INDATABLOCK; - void* buf_read; + void *buf_read; #endif int err = ZIP_OK; int mode; @@ -696,13 +676,12 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ if (ziinit.filestream == NULL) return NULL; - if (append == APPEND_STATUS_CREATEAFTER) - { + if (append == APPEND_STATUS_CREATEAFTER) { /* Don't support spanning ZIP with APPEND_STATUS_CREATEAFTER */ if (disk_size > 0) return NULL; - ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); + ZSEEK64(ziinit.z_filefunc, ziinit.filestream, 0, SEEK_END); } ziinit.filestream_with_CD = ziinit.filestream; @@ -710,36 +689,33 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ ziinit.number_disk = 0; ziinit.number_disk_with_CD = 0; ziinit.disk_size = disk_size; - ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); + ziinit.begin_pos = ZTELL64(ziinit.z_filefunc, ziinit.filestream); ziinit.in_opened_file_inzip = 0; ziinit.ci.stream_initialised = 0; ziinit.number_entry = 0; ziinit.add_position_when_writting_offset = 0; init_linkedlist(&(ziinit.central_dir)); - zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); - if (zi == NULL) - { - ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); + zi = (zip64_internal *)ALLOC(sizeof(zip64_internal)); + if (zi == NULL) { + ZCLOSE64(ziinit.z_filefunc, ziinit.filestream); return NULL; } #ifndef NO_ADDFILEINEXISTINGZIP /* Add file in a zipfile */ ziinit.globalcomment = NULL; - if (append == APPEND_STATUS_ADDINZIP) - { + if (append == APPEND_STATUS_ADDINZIP) { /* Read and Cache Central Directory Records */ - central_pos = zip64local_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); + central_pos = zip64local_SearchCentralDir(&ziinit.z_filefunc, ziinit.filestream); /* disable to allow appending to empty ZIP archive (must be standard zip, not zip64) if (central_pos == 0) err = ZIP_ERRNO; - */ + */ - if (err == ZIP_OK) - { + if (err == ZIP_OK) { /* read end of central directory info */ - if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET) != 0) + if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) err = ZIP_ERRNO; /* the signature, already checked */ @@ -763,7 +739,7 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ err = ZIP_ERRNO; else number_entry_CD = uL; - if (number_entry_CD!=number_entry) + if (number_entry_CD != number_entry) err = ZIP_BADZIPFILE; /* size of the central directory */ size_central_dir = 0; @@ -781,13 +757,11 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &size_comment) != ZIP_OK) err = ZIP_ERRNO; - if ((err == ZIP_OK) && ((number_entry_CD == 0xffff) || (offset_central_dir == 0xffffffff))) - { + if ((err == ZIP_OK) && ((number_entry_CD == 0xffff) || (offset_central_dir == 0xffffffff))) { /* Format should be Zip64, as the central directory or file size is too large */ central_pos = zip64local_SearchCentralDir64(&ziinit.z_filefunc, ziinit.filestream, central_pos); - if (central_pos) - { + if (central_pos) { ZPOS64_T sizeEndOfCentralDirectory; if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) @@ -817,7 +791,7 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ /* total number of entries in the central directory */ if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &number_entry_CD) != ZIP_OK) err = ZIP_ERRNO; - if (number_entry_CD!=number_entry) + if (number_entry_CD != number_entry) err = ZIP_BADZIPFILE; /* size of the central directory */ if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &size_central_dir) != ZIP_OK) @@ -825,46 +799,41 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ /* offset of start of central directory with respect to the starting disk number */ if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &offset_central_dir) != ZIP_OK) err = ZIP_ERRNO; - } - else + } else err = ZIP_BADZIPFILE; - } + } } - if ((err == ZIP_OK) && (central_pos 0) - { - ziinit.globalcomment = (char*)ALLOC(size_comment+1); - if (ziinit.globalcomment) - { + if (size_comment > 0) { + ziinit.globalcomment = (char *)ALLOC(size_comment + 1); + if (ziinit.globalcomment) { size_comment = ZREAD64(ziinit.z_filefunc, ziinit.filestream, ziinit.globalcomment, size_comment); ziinit.globalcomment[size_comment] = 0; } } - byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); + byte_before_the_zipfile = central_pos - (offset_central_dir + size_central_dir); ziinit.add_position_when_writting_offset = byte_before_the_zipfile; /* Store central directory in memory */ size_central_dir_to_read = size_central_dir; buf_size = SIZEDATA_INDATABLOCK; - buf_read = (void*)ALLOC(buf_size); + buf_read = (void *)ALLOC(buf_size); if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) + offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) err = ZIP_ERRNO; - while ((size_central_dir_to_read > 0) && (err == ZIP_OK)) - { + while ((size_central_dir_to_read > 0) && (err == ZIP_OK)) { ZPOS64_T read_this = SIZEDATA_INDATABLOCK; if (read_this > size_central_dir_to_read) read_this = size_central_dir_to_read; @@ -883,7 +852,7 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ ziinit.number_entry = number_entry_CD; if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir+byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) + offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) err = ZIP_ERRNO; } @@ -891,8 +860,7 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ *globalcomment = ziinit.globalcomment; #endif - if (err != ZIP_OK) - { + if (err != ZIP_OK) { #ifndef NO_ADDFILEINEXISTINGZIP TRYFREE(ziinit.globalcomment); #endif @@ -902,26 +870,24 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_ *zi = ziinit; zipGoToFirstDisk((zipFile)zi); - return(zipFile)zi; + return (zipFile)zi; } -extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc* globalcomment, - zlib_filefunc_def* pzlib_filefunc32_def) +extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc *globalcomment, + zlib_filefunc_def *pzlib_filefunc32_def) { - if (pzlib_filefunc32_def != NULL) - { + if (pzlib_filefunc32_def != NULL) { zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); + fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def); return zipOpen4(pathname, append, 0, globalcomment, &zlib_filefunc64_32_def_fill); } return zipOpen4(pathname, append, 0, globalcomment, NULL); } -extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc* globalcomment, - zlib_filefunc64_def* pzlib_filefunc_def) +extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment, + zlib_filefunc64_def *pzlib_filefunc_def) { - if (pzlib_filefunc_def != NULL) - { + if (pzlib_filefunc_def != NULL) { zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; zlib_filefunc64_32_def_fill.ztell32_file = NULL; @@ -931,23 +897,21 @@ extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc* return zipOpen4(pathname, append, 0, globalcomment, NULL); } -extern zipFile ZEXPORT zipOpen3(const char *pathname, int append, ZPOS64_T disk_size, zipcharpc* globalcomment, - zlib_filefunc_def* pzlib_filefunc32_def) +extern zipFile ZEXPORT zipOpen3(const char *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment, + zlib_filefunc_def *pzlib_filefunc32_def) { - if (pzlib_filefunc32_def != NULL) - { + if (pzlib_filefunc32_def != NULL) { zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); + fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def); return zipOpen4(pathname, append, disk_size, globalcomment, &zlib_filefunc64_32_def_fill); } return zipOpen4(pathname, append, disk_size, globalcomment, NULL); } -extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc* globalcomment, - zlib_filefunc64_def* pzlib_filefunc_def) +extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment, + zlib_filefunc64_def *pzlib_filefunc_def) { - if (pzlib_filefunc_def != NULL) - { + if (pzlib_filefunc_def != NULL) { zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; zlib_filefunc64_32_def_fill.ztell32_file = NULL; @@ -957,22 +921,22 @@ extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T di return zipOpen4(pathname, append, disk_size, globalcomment, NULL); } -extern zipFile ZEXPORT zipOpen(const char* pathname, int append) +extern zipFile ZEXPORT zipOpen(const char *pathname, int append) { - return zipOpen3((const void*)pathname,append,0,NULL,NULL); + return zipOpen3((const void *)pathname, append, 0, NULL, NULL); } -extern zipFile ZEXPORT zipOpen64(const void* pathname, int append) +extern zipFile ZEXPORT zipOpen64(const void *pathname, int append) { - return zipOpen3(pathname,append,0,NULL,NULL); + return zipOpen3(pathname, append, 0, NULL, NULL); } -extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, - int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64) +extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, + int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64) { - zip64_internal* zi; + zip64_internal *zi; uInt size_filename; uInt size_comment = 0; uInt i; @@ -996,11 +960,10 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c (method != Z_DEFLATED)) return ZIP_PARAMERROR; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); + if (zi->in_opened_file_inzip == 1) { + err = zipCloseFileInZip(file); if (err != ZIP_OK) return err; } @@ -1014,8 +977,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c if (zipfi == NULL) zi->ci.dosDate = 0; - else - { + else { if (zipfi->dosDate != 0) zi->ci.dosDate = zipfi->dosDate; else @@ -1035,16 +997,14 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c zi->ci.flag |= 4; if (level == 1) zi->ci.flag |= 6; - if (password != NULL) - { + if (password != NULL) { zi->ci.flag |= 1; #ifdef HAVE_AES zi->ci.method = AES_METHOD; #endif } - if (zi->disk_size > 0) - { + if (zi->disk_size > 0) { if ((zi->number_disk == 0) && (zi->number_entry == 0)) err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)DISKHEADERMAGIC, 4); @@ -1070,47 +1030,47 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c if (zi->ci.method == AES_METHOD) zi->ci.size_centralextrafree += 11; /* Extra space reserved for AES extra info */ #endif - zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralextrafree + size_comment); + zi->ci.central_header = (char *)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralextrafree + size_comment); zi->ci.number_disk = zi->number_disk; /* Write central directory header */ zip64local_putValue_inmemory(zi->ci.central_header, (uLong)CENTRALHEADERMAGIC, 4); - zip64local_putValue_inmemory(zi->ci.central_header+4, (uLong)versionMadeBy, 2); - zip64local_putValue_inmemory(zi->ci.central_header+6, (uLong)20, 2); - zip64local_putValue_inmemory(zi->ci.central_header+8, (uLong)zi->ci.flag, 2); - zip64local_putValue_inmemory(zi->ci.central_header+10, (uLong)zi->ci.method, 2); - zip64local_putValue_inmemory(zi->ci.central_header+12, (uLong)zi->ci.dosDate, 4); - zip64local_putValue_inmemory(zi->ci.central_header+16, (uLong)0, 4); /*crc*/ - zip64local_putValue_inmemory(zi->ci.central_header+20, (uLong)0, 4); /*compr size*/ - zip64local_putValue_inmemory(zi->ci.central_header+24, (uLong)0, 4); /*uncompr size*/ - zip64local_putValue_inmemory(zi->ci.central_header+28, (uLong)size_filename, 2); - zip64local_putValue_inmemory(zi->ci.central_header+30, (uLong)size_extrafield_global, 2); - zip64local_putValue_inmemory(zi->ci.central_header+32, (uLong)size_comment, 2); - zip64local_putValue_inmemory(zi->ci.central_header+34, (uLong)zi->ci.number_disk, 2); /*disk nm start*/ + zip64local_putValue_inmemory(zi->ci.central_header + 4, (uLong)versionMadeBy, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 6, (uLong)20, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 8, (uLong)zi->ci.flag, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 10, (uLong)zi->ci.method, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 12, (uLong)zi->ci.dosDate, 4); + zip64local_putValue_inmemory(zi->ci.central_header + 16, (uLong)0, 4); /*crc*/ + zip64local_putValue_inmemory(zi->ci.central_header + 20, (uLong)0, 4); /*compr size*/ + zip64local_putValue_inmemory(zi->ci.central_header + 24, (uLong)0, 4); /*uncompr size*/ + zip64local_putValue_inmemory(zi->ci.central_header + 28, (uLong)size_filename, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)size_extrafield_global, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 32, (uLong)size_comment, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 34, (uLong)zi->ci.number_disk, 2); /*disk nm start*/ if (zipfi == NULL) - zip64local_putValue_inmemory(zi->ci.central_header+36, (uLong)0, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)0, 2); else - zip64local_putValue_inmemory(zi->ci.central_header+36, (uLong)zipfi->internal_fa, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)zipfi->internal_fa, 2); if (zipfi == NULL) - zip64local_putValue_inmemory(zi->ci.central_header+38, (uLong)0, 4); + zip64local_putValue_inmemory(zi->ci.central_header + 38, (uLong)0, 4); else - zip64local_putValue_inmemory(zi->ci.central_header+38, (uLong)zipfi->external_fa, 4); + zip64local_putValue_inmemory(zi->ci.central_header + 38, (uLong)zipfi->external_fa, 4); if (zi->ci.pos_local_header >= 0xffffffff) - zip64local_putValue_inmemory(zi->ci.central_header+42, (uLong)0xffffffff, 4); + zip64local_putValue_inmemory(zi->ci.central_header + 42, (uLong)0xffffffff, 4); else - zip64local_putValue_inmemory(zi->ci.central_header+42, - (uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset, 4); + zip64local_putValue_inmemory(zi->ci.central_header + 42, + (uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset, 4); for (i = 0; i < size_filename; i++) - zi->ci.central_header[SIZECENTRALHEADER+i] = filename[i]; + zi->ci.central_header[SIZECENTRALHEADER + i] = filename[i]; for (i = 0; i < size_extrafield_global; i++) - zi->ci.central_header[SIZECENTRALHEADER+size_filename+i] = - ((const char*)extrafield_global)[i]; + zi->ci.central_header[SIZECENTRALHEADER + size_filename + i] = + ((const char *)extrafield_global)[i]; /* Store comment at the end for later repositioning */ for (i = 0; i < size_comment; i++) - zi->ci.central_header[zi->ci.size_centralheader+ - zi->ci.size_centralextrafree+i] = comment[i]; + zi->ci.central_header[zi->ci.size_centralheader + + zi->ci.size_centralextrafree + i] = comment[i]; if (zi->ci.central_header == NULL) return ZIP_INTERNALERROR; @@ -1123,8 +1083,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c /* Write the local header */ err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)LOCALHEADERMAGIC, 4); - if (err == ZIP_OK) - { + if (err == ZIP_OK) { if (zi->ci.zip64) err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2); /* version needed to extract */ else @@ -1141,15 +1100,13 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c if (err == ZIP_OK) err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4); /* crc 32, unknown */ - if (err == ZIP_OK) - { + if (err == ZIP_OK) { if (zi->ci.zip64) err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xFFFFFFFF, 4); /* compressed size, unknown */ else err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4); /* compressed size, unknown */ } - if (err == ZIP_OK) - { + if (err == ZIP_OK) { if (zi->ci.zip64) /* uncompressed size, unknown */ err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xFFFFFFFF, 4); else /* uncompressed size, unknown */ @@ -1157,8 +1114,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c } if (err == ZIP_OK) err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_filename, 2); - if (err == ZIP_OK) - { + if (err == ZIP_OK) { ZPOS64_T size_extrafield = size_extrafield_local; if (zi->ci.zip64) size_extrafield += 20; @@ -1166,22 +1122,19 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c if (zi->ci.method == AES_METHOD) size_extrafield += 11; #endif - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_extrafield,2); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_extrafield, 2); } - if ((err == ZIP_OK) && (size_filename > 0)) - { + if ((err == ZIP_OK) && (size_filename > 0)) { if (ZWRITE64(zi->z_filefunc, zi->filestream, filename, size_filename) != size_filename) err = ZIP_ERRNO; } - if ((err == ZIP_OK) && (size_extrafield_local > 0)) - { + if ((err == ZIP_OK) && (size_extrafield_local > 0)) { if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) err = ZIP_ERRNO; } /* Write the Zip64 extended info */ - if ((err == ZIP_OK) && (zi->ci.zip64)) - { + if ((err == ZIP_OK) && (zi->ci.zip64)) { short headerid = 1; short datasize = 16; ZPOS64_T compressed_size = 0; @@ -1199,8 +1152,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c } #ifdef HAVE_AES /* Write the AES extended info */ - if ((err == ZIP_OK) && (zi->ci.method == AES_METHOD)) - { + if ((err == ZIP_OK) && (zi->ci.method == AES_METHOD)) { int headerid = 0x9901; short datasize = 7; @@ -1218,7 +1170,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c #ifdef HAVE_BZIP2 zi->ci.bstream.avail_in = (uInt)0; zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + zi->ci.bstream.next_out = (char *)zi->ci.buffered_data; zi->ci.bstream.total_in_hi32 = 0; zi->ci.bstream.total_in_lo32 = 0; zi->ci.bstream.total_out_hi32 = 0; @@ -1232,10 +1184,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c zi->ci.stream.total_out = 0; zi->ci.stream.data_type = Z_BINARY; - if ((err == ZIP_OK) && (!zi->ci.raw)) - { - if (method == Z_DEFLATED) - { + if ((err == ZIP_OK) && (!zi->ci.raw)) { + if (method == Z_DEFLATED) { zi->ci.stream.zalloc = (alloc_func)0; zi->ci.stream.zfree = (free_func)0; zi->ci.stream.opaque = (voidpf)zi; @@ -1247,9 +1197,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c if (err == Z_OK) zi->ci.stream_initialised = Z_DEFLATED; - } - else if (method == Z_BZIP2ED) - { + } else if (method == Z_BZIP2ED) { #ifdef HAVE_BZIP2 zi->ci.bstream.bzalloc = 0; zi->ci.bstream.bzfree = 0; @@ -1264,11 +1212,9 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c #ifndef NOCRYPT zi->ci.crypt_header_size = 0; - if ((err == Z_OK) && ((zi->ci.flag & 1) != 0)) - { + if ((err == Z_OK) && ((zi->ci.flag & 1) != 0)) { #ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - { + if (zi->ci.method == AES_METHOD) { unsigned char passverify[AES_PWVERIFYSIZE]; unsigned char saltvalue[AES_MAXSALTLENGTH]; uInt saltlength; @@ -1282,7 +1228,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c prng_rand(saltvalue, saltlength, zi->ci.aes_rng); prng_end(zi->ci.aes_rng); - fcrypt_init(AES_ENCRYPTIONMODE, password, strlen(password), saltvalue, passverify, &zi->ci.aes_ctx); + fcrypt_init(AES_ENCRYPTIONMODE, (unsigned char *)password, (unsigned int)strlen(password), saltvalue, passverify, &zi->ci.aes_ctx); if (ZWRITE64(zi->z_filefunc, zi->filestream, saltvalue, saltlength) != saltlength) err = ZIP_ERRNO; @@ -1290,8 +1236,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c err = ZIP_ERRNO; zi->ci.crypt_header_size = saltlength + AES_PWVERIFYSIZE + AES_AUTHCODESIZE; - } - else + } else #endif { unsigned char bufHead[RAND_HEAD_LEN]; @@ -1314,75 +1259,75 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c return err; } -extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, - int memLevel, int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase) +extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, + int memLevel, int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, - strategy, password, crcForCrypting, versionMadeBy, flagBase, 0); + extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, + strategy, password, crcForCrypting, versionMadeBy, flagBase, 0); } -extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, - int memLevel, int strategy, const char* password, uLong crcForCrypting) +extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, + int memLevel, int strategy, const char *password, uLong crcForCrypting) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, - strategy, password, crcForCrypting, VERSIONMADEBY, 0, 0); + extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, + strategy, password, crcForCrypting, VERSIONMADEBY, 0, 0); } -extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, - int memLevel, int strategy, const char* password, uLong crcForCrypting, int zip64) +extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, + int memLevel, int strategy, const char *password, uLong crcForCrypting, int zip64) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, strategy, - password, crcForCrypting, VERSIONMADEBY, 0, zip64); + extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, zip64); } -extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int raw) +extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int raw) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0); + extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0); } -extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int raw, int zip64) +extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int raw, int zip64) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64); + extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64); } -extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void*extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level, int zip64) +extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level, int zip64) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64); + extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64); } -extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, const void*extrafield_global, - uInt size_extrafield_global, const char* comment, int method, int level) +extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, + const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, + uInt size_extrafield_global, const char *comment, int method, int level) { return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0); + extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0); } /* Flushes the write buffer to disk */ -local int zip64FlushWriteBuffer OF((zip64_internal* zi)); -local int zip64FlushWriteBuffer(zip64_internal* zi) +local int zip64FlushWriteBuffer OF((zip64_internal * zi)); +local int zip64FlushWriteBuffer(zip64_internal *zi) { int err = ZIP_OK; uInt written = 0; @@ -1391,39 +1336,33 @@ local int zip64FlushWriteBuffer(zip64_internal* zi) uInt max_write = 0; ZPOS64_T size_available = 0; - if ((zi->ci.flag & 1) != 0) - { + if ((zi->ci.flag & 1) != 0) { #ifndef NOCRYPT #ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - { + if (zi->ci.method == AES_METHOD) { fcrypt_encrypt(zi->ci.buffered_data, zi->ci.pos_in_buffered_data, &zi->ci.aes_ctx); - } - else + } else #endif { uInt i; int t; - for (i = 0;i < zi->ci.pos_in_buffered_data; i++) - zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t); + for (i = 0; i < zi->ci.pos_in_buffered_data; i++) + zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i], t); } #endif } write = zi->ci.pos_in_buffered_data; - do - { + do { max_write = write; - if (zi->disk_size > 0) - { + if (zi->disk_size > 0) { err = zipGetDiskSizeAvailable((zipFile)zi, &size_available); if (err != ZIP_OK) return err; - if (size_available == 0) - { + if (size_available == 0) { err = zipGoToNextDisk((zipFile)zi); if (err != ZIP_OK) return err; @@ -1435,27 +1374,23 @@ local int zip64FlushWriteBuffer(zip64_internal* zi) written = (unsigned int)ZWRITE64(zi->z_filefunc, zi->filestream, zi->ci.buffered_data + total_written, max_write); - if (ZERROR64(zi->z_filefunc, zi->filestream)) - { + if (ZERROR64(zi->z_filefunc, zi->filestream)) { err = ZIP_ERRNO; break; } total_written += written; write -= written; - } - while (write > 0); + } while (write > 0); zi->ci.total_compressed += zi->ci.pos_in_buffered_data; #ifdef HAVE_BZIP2 - if (zi->ci.compression_method == Z_BZIP2ED) - { + if (zi->ci.compression_method == Z_BZIP2ED) { zi->ci.total_uncompressed += zi->ci.bstream.total_in_lo32; zi->ci.bstream.total_in_lo32 = 0; zi->ci.bstream.total_in_hi32 = 0; - } - else + } else #endif { zi->ci.total_uncompressed += zi->ci.stream.total_in; @@ -1467,14 +1402,14 @@ local int zip64FlushWriteBuffer(zip64_internal* zi) return err; } -extern int ZEXPORT zipWriteInFileInZip(zipFile file,const void* buf,unsigned int len) +extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len) { - zip64_internal* zi; + zip64_internal *zi; int err = ZIP_OK; if (file == NULL) return ZIP_PARAMERROR; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; if (zi->in_opened_file_inzip == 0) return ZIP_PARAMERROR; @@ -1482,23 +1417,18 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file,const void* buf,unsigned int zi->ci.crc32 = crc32(zi->ci.crc32, buf, (uInt)len); #ifdef HAVE_BZIP2 - if ((zi->ci.compression_method == Z_BZIP2ED) && (!zi->ci.raw)) - { - zi->ci.bstream.next_in = (void*)buf; + if ((zi->ci.compression_method == Z_BZIP2ED) && (!zi->ci.raw)) { + zi->ci.bstream.next_in = (void *)buf; zi->ci.bstream.avail_in = len; err = BZ_RUN_OK; - while ((err == BZ_RUN_OK) && (zi->ci.bstream.avail_in > 0)) - { - if (zi->ci.bstream.avail_out == 0) - { + while ((err == BZ_RUN_OK) && (zi->ci.bstream.avail_in > 0)) { + if (zi->ci.bstream.avail_out == 0) { if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) err = ZIP_ERRNO; zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - } - else - { + zi->ci.bstream.next_out = (char *)zi->ci.buffered_data; + } else { uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; @@ -1510,17 +1440,14 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file,const void* buf,unsigned int if (err == BZ_RUN_OK) err = ZIP_OK; - } - else + } else #endif { - zi->ci.stream.next_in = (Bytef*)buf; + zi->ci.stream.next_in = (Bytef *)buf; zi->ci.stream.avail_in = len; - while ((err == ZIP_OK) && (zi->ci.stream.avail_in > 0)) - { - if (zi->ci.stream.avail_out == 0) - { + while ((err == ZIP_OK) && (zi->ci.stream.avail_in > 0)) { + if (zi->ci.stream.avail_out == 0) { if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) err = ZIP_ERRNO; zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; @@ -1530,25 +1457,22 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file,const void* buf,unsigned int if (err != ZIP_OK) break; - if ((zi->ci.compression_method == Z_DEFLATED) && (!zi->ci.raw)) - { + if ((zi->ci.compression_method == Z_DEFLATED) && (!zi->ci.raw)) { uLong total_out_before = zi->ci.stream.total_out; err = deflate(&zi->ci.stream, Z_NO_FLUSH); zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - total_out_before); - } - else - { - uInt copy_this,i; + } else { + uInt copy_this, i; if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) copy_this = zi->ci.stream.avail_in; else copy_this = zi->ci.stream.avail_out; for (i = 0; i < copy_this; i++) - *(((char*)zi->ci.stream.next_out)+i) = - *(((const char*)zi->ci.stream.next_in)+i); + *(((char *)zi->ci.stream.next_out) + i) = + *(((const char *)zi->ci.stream.next_in) + i); - zi->ci.stream.avail_in -= copy_this; + zi->ci.stream.avail_in -= copy_this; zi->ci.stream.avail_out -= copy_this; zi->ci.stream.next_in += copy_this; zi->ci.stream.next_out += copy_this; @@ -1564,12 +1488,12 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file,const void* buf,unsigned int extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32) { - return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); + return zipCloseFileInZipRaw64(file, uncompressed_size, crc32); } extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32) { - zip64_internal* zi; + zip64_internal *zi; ZPOS64_T compressed_size; uLong invalidValue = 0xffffffff; uLong i = 0; @@ -1578,21 +1502,17 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si if (file == NULL) return ZIP_PARAMERROR; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; if (zi->in_opened_file_inzip == 0) return ZIP_PARAMERROR; zi->ci.stream.avail_in = 0; - if (!zi->ci.raw) - { - if (zi->ci.compression_method == Z_DEFLATED) - { - while (err == ZIP_OK) - { + if (!zi->ci.raw) { + if (zi->ci.compression_method == Z_DEFLATED) { + while (err == ZIP_OK) { uLong total_out_before; - if (zi->ci.stream.avail_out == 0) - { + if (zi->ci.stream.avail_out == 0) { if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) err = ZIP_ERRNO; zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; @@ -1602,20 +1522,16 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si err = deflate(&zi->ci.stream, Z_FINISH); zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - total_out_before); } - } - else if (zi->ci.compression_method == Z_BZIP2ED) - { + } else if (zi->ci.compression_method == Z_BZIP2ED) { #ifdef HAVE_BZIP2 err = BZ_FINISH_OK; - while (err == BZ_FINISH_OK) - { + while (err == BZ_FINISH_OK) { uLong total_out_before; - if (zi->ci.bstream.avail_out == 0) - { + if (zi->ci.bstream.avail_out == 0) { if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) err = ZIP_ERRNO; zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + zi->ci.bstream.next_out = (char *)zi->ci.buffered_data; } total_out_before = zi->ci.bstream.total_out_lo32; err = BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); @@ -1633,15 +1549,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si if (err == Z_STREAM_END) err = ZIP_OK; /* this is normal */ - if ((zi->ci.pos_in_buffered_data>0) && (err == ZIP_OK)) - { + if ((zi->ci.pos_in_buffered_data > 0) && (err == ZIP_OK)) { if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) err = ZIP_ERRNO; } #ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - { + if (zi->ci.method == AES_METHOD) { unsigned char authcode[AES_AUTHCODESIZE]; fcrypt_end(authcode, &zi->ci.aes_ctx); @@ -1651,18 +1565,15 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si } #endif - if (!zi->ci.raw) - { - if (zi->ci.compression_method == Z_DEFLATED) - { + if (!zi->ci.raw) { + if (zi->ci.compression_method == Z_DEFLATED) { int tmp_err = deflateEnd(&zi->ci.stream); if (err == ZIP_OK) err = tmp_err; zi->ci.stream_initialised = 0; } #ifdef HAVE_BZIP2 - else if (zi->ci.compression_method == Z_BZIP2ED) - { + else if (zi->ci.compression_method == Z_BZIP2ED) { int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); if (err == ZIP_OK) err = tmperr; @@ -1680,22 +1591,21 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si #endif /* Update current item crc and sizes */ - if (compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) - { - zip64local_putValue_inmemory(zi->ci.central_header+4, (uLong)45, 2); /* version made by */ - zip64local_putValue_inmemory(zi->ci.central_header+6, (uLong)45, 2); /* version needed */ + if (compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) { + zip64local_putValue_inmemory(zi->ci.central_header + 4, (uLong)45, 2); /* version made by */ + zip64local_putValue_inmemory(zi->ci.central_header + 6, (uLong)45, 2); /* version needed */ } - zip64local_putValue_inmemory(zi->ci.central_header+16, crc32, 4); /* crc */ + zip64local_putValue_inmemory(zi->ci.central_header + 16, crc32, 4); /* crc */ if (compressed_size >= 0xffffffff) - zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue, 4); /* compr size */ + zip64local_putValue_inmemory(zi->ci.central_header + 20, invalidValue, 4); /* compr size */ else - zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size, 4); /* compr size */ + zip64local_putValue_inmemory(zi->ci.central_header + 20, compressed_size, 4); /* compr size */ if (zi->ci.stream.data_type == Z_ASCII) - zip64local_putValue_inmemory(zi->ci.central_header+36, (uLong)Z_ASCII, 2); /* internal file attrib */ + zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)Z_ASCII, 2); /* internal file attrib */ if (uncompressed_size >= 0xffffffff) - zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue, 4); /* uncompr size */ + zip64local_putValue_inmemory(zi->ci.central_header + 24, invalidValue, 4); /* uncompr size */ else - zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size, 4); /* uncompr size */ + zip64local_putValue_inmemory(zi->ci.central_header + 24, uncompressed_size, 4); /* uncompr size */ /* Add ZIP64 extra info field for uncompressed size */ if (uncompressed_size >= 0xffffffff) @@ -1708,9 +1618,8 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si datasize += 8; /* Add Extra Information Header for 'ZIP64 information' */ - if (datasize > 0) - { - char* p = zi->ci.central_header + zi->ci.size_centralheader; + if (datasize > 0) { + char *p = zi->ci.central_header + zi->ci.size_centralheader; if ((uLong)(datasize + 4) > zi->ci.size_centralextrafree) return ZIP_BADZIPFILE; @@ -1720,18 +1629,15 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si zip64local_putValue_inmemory(p, datasize, 2); p += 2; - if (uncompressed_size >= 0xffffffff) - { + if (uncompressed_size >= 0xffffffff) { zip64local_putValue_inmemory(p, uncompressed_size, 8); p += 8; } - if (compressed_size >= 0xffffffff) - { + if (compressed_size >= 0xffffffff) { zip64local_putValue_inmemory(p, compressed_size, 8); p += 8; } - if (zi->ci.pos_local_header >= 0xffffffff) - { + if (zi->ci.pos_local_header >= 0xffffffff) { zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); p += 8; } @@ -1740,14 +1646,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si zi->ci.size_centralheader += datasize + 4; zi->ci.size_centralextra += datasize + 4; - zip64local_putValue_inmemory(zi->ci.central_header+30, (uLong)zi->ci.size_centralextra, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)zi->ci.size_centralextra, 2); } #ifdef HAVE_AES /* Write the AES extended info */ - if (zi->ci.method == AES_METHOD) - { - char* p = zi->ci.central_header + zi->ci.size_centralheader; + if (zi->ci.method == AES_METHOD) { + char *p = zi->ci.central_header + zi->ci.size_centralheader; datasize = 7; @@ -1773,13 +1678,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si zi->ci.size_centralheader += datasize + 4; zi->ci.size_centralextra += datasize + 4; - zip64local_putValue_inmemory(zi->ci.central_header+30, (uLong)zi->ci.size_centralextra, 2); + zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)zi->ci.size_centralextra, 2); } #endif /* Restore comment to correct position */ for (i = 0; i < zi->ci.size_comment; i++) - zi->ci.central_header[zi->ci.size_centralheader+i] = - zi->ci.central_header[zi->ci.size_centralheader+zi->ci.size_centralextrafree+i]; + zi->ci.central_header[zi->ci.size_centralheader + i] = + zi->ci.central_header[zi->ci.size_centralheader + zi->ci.size_centralextrafree + i]; zi->ci.size_centralheader += zi->ci.size_comment; if (err == ZIP_OK) @@ -1787,8 +1692,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si free(zi->ci.central_header); - if (err == ZIP_OK) - { + if (err == ZIP_OK) { /* Update the LocalFileHeader with the new values. */ ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream); uLong cur_number_disk = zi->number_disk; @@ -1800,12 +1704,10 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si if (ZSEEK64(zi->z_filefunc, zi->filestream, zi->ci.pos_local_header + 14, ZLIB_FILEFUNC_SEEK_SET) != 0) err = ZIP_ERRNO; if (err == ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc, zi->filestream,crc32,4); /* crc 32, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, crc32, 4); /* crc 32, unknown */ - if (uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff) - { - if (zi->ci.pos_zip64extrainfo > 0) - { + if (uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff) { + if (zi->ci.pos_zip64extrainfo > 0) { /* Update the size in the ZIP64 extended field. */ if (ZSEEK64(zi->z_filefunc, zi->filestream, zi->ci.pos_zip64extrainfo + 4, ZLIB_FILEFUNC_SEEK_SET) != 0) err = ZIP_ERRNO; @@ -1814,16 +1716,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); if (err == ZIP_OK) /* uncompressed size, unknown */ err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); - } - else + } else err = ZIP_BADZIPFILE; /* Caller passed zip64 = 0, so no room for zip64 info -> fatal */ - } - else - { - if (err == ZIP_OK) /* compressed size, unknown */ - err = zip64local_putValue(&zi->z_filefunc, zi->filestream,compressed_size, 4); - if (err == ZIP_OK) /* uncompressed size, unknown */ - err = zip64local_putValue(&zi->z_filefunc, zi->filestream,uncompressed_size, 4); + } else { + if (err == ZIP_OK) /* compressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 4); + if (err == ZIP_OK) /* uncompressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 4); } /* Now switch back again to the disk we were on before */ @@ -1845,9 +1744,9 @@ extern int ZEXPORT zipCloseFileInZip(zipFile file) return zipCloseFileInZipRaw(file, 0, 0); } -extern int ZEXPORT zipClose(zipFile file, const char* global_comment) +extern int ZEXPORT zipClose(zipFile file, const char *global_comment) { - zip64_internal* zi; + zip64_internal *zi; int err = 0; uLong size_centraldir = 0; uInt size_global_comment = 0; @@ -1858,7 +1757,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) if (file == NULL) return ZIP_PARAMERROR; - zi = (zip64_internal*)file; + zi = (zip64_internal *)file; if (zi->in_opened_file_inzip == 1) err = zipCloseFileInZip(file); @@ -1868,8 +1767,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) global_comment = zi->globalcomment; #endif - if (zi->filestream != zi->filestream_with_CD) - { + if (zi->filestream != zi->filestream_with_CD) { if (ZCLOSE64(zi->z_filefunc, zi->filestream) != 0) if (err == ZIP_OK) err = ZIP_ERRNO; @@ -1880,13 +1778,10 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) 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)) - { + 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; @@ -1902,8 +1797,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; /* Write the ZIP64 central directory header */ - if (pos >= 0xffffffff || zi->number_entry > 0xffff) - { + if (pos >= 0xffffffff || zi->number_entry > 0xffff) { ZPOS64_T zip64eocd_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream); uLong zip64datasize = 44; @@ -1934,8 +1828,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) if (err == ZIP_OK) err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)size_centraldir, 8); - if (err == ZIP_OK) - { + 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); @@ -1947,14 +1840,13 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) 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) - { + 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); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD + 1, 4); } /* Write the central directory header */ @@ -1969,16 +1861,14 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) 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 (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 (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 @@ -1986,10 +1876,9 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) } /* size of the central directory */ if (err == ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_centraldir,4); + 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) - { + 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); @@ -2003,8 +1892,7 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) 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 (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; } @@ -2019,3 +1907,4 @@ extern int ZEXPORT zipClose(zipFile file, const char* global_comment) return err; } + diff --git a/SSZipArchive/minizip/zip.h b/SSZipArchive/minizip/zip.h index 3f3a30b..10bbf26 100755 --- a/SSZipArchive/minizip/zip.h +++ b/SSZipArchive/minizip/zip.h @@ -15,6 +15,8 @@ #ifndef _ZIP_H #define _ZIP_H +#define HAVE_AES + #ifdef __cplusplus extern "C" { #endif