ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zip.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "zlib.h"
#include "zip.h"
#include <errno.h>
#include "crypt.h"
+ Include dependency graph for zip.c:

Go to the source code of this file.

Data Structures

struct  linkedlist_datablock_internal_s
 
struct  linkedlist_data_s
 
struct  curfile64_info
 
struct  zip64_internal
 

Macros

#define local   static
 
#define VERSIONMADEBY   (0x031e) /* best for standard pkware crypt */
 
#define Z_BUFSIZE   (64*1024) /* (16384) */
 
#define Z_MAXFILENAMEINZIP   (256)
 
#define ALLOC(size)   (malloc(size))
 
#define TRYFREE(p)   {if (p) free(p);}
 
#define MAKEULONG64(a, b)   ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
 
#define SEEK_CUR   1
 
#define SEEK_END   2
 
#define SEEK_SET   0
 
#define SIZEDATA_INDATABLOCK   (4096-(4*4))
 
#define LOCALHEADERMAGIC   (0x04034b50)
 
#define DESCRIPTORHEADERMAGIC   (0x08074b50)
 
#define CENTRALHEADERMAGIC   (0x02014b50)
 
#define ENDHEADERMAGIC   (0x06054b50)
 
#define ZIP64ENDHEADERMAGIC   (0x6064b50)
 
#define ZIP64ENDLOCHEADERMAGIC   (0x7064b50)
 
#define FLAG_LOCALHEADER_OFFSET   (0x06)
 
#define CRC_LOCALHEADER_OFFSET   (0x0e)
 
#define SIZECENTRALHEADER   (0x2e) /* 46 */
 
#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
 
#define BUFREADCOMMENT   (0x400)
 

Typedefs

typedef uLongf z_crc_t
 
typedef struct
linkedlist_datablock_internal_s 
linkedlist_datablock_internal
 
typedef struct linkedlist_data_s linkedlist_data
 

Functions

static
linkedlist_datablock_internal
allocate_new_datablock ()
 
static void free_datablock (linkedlist_datablock_internal *ldi)
 
static void init_linkedlist (linkedlist_data *ll)
 
static void free_linkedlist (linkedlist_data *ll)
 
static int add_data_in_datablock (linkedlist_data *ll, const void *buf, uLong len)
 
static int zip64local_putValue _Z_OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte))
 
static int zip64local_putValue (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
 
static void
zip64local_putValue_inmemory 
_Z_OF ((void *dest, ZPOS64_T x, int nbByte))
 
static void zip64local_putValue_inmemory (void *dest, ZPOS64_T x, int nbByte)
 
static uLong zip64local_TmzDateToDosDate (const tm_zip *ptm)
 
static int zip64local_getByte _Z_OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi))
 
static int zip64local_getByte (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
 
static int zip64local_getShort _Z_OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX))
 
static int zip64local_getShort (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
 
static int zip64local_getLong (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
 
static int zip64local_getLong64 _Z_OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX))
 
static int zip64local_getLong64 (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
 
static ZPOS64_T
zip64local_SearchCentralDir 
_Z_OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream))
 
static ZPOS64_T zip64local_SearchCentralDir (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
 
static ZPOS64_T zip64local_SearchCentralDir64 (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
 
int LoadCentralDirectoryRecord (zip64_internal *pziinit)
 
zipFile ZEXPORT zipOpen3 (voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
 
zipFile ZEXPORT zipOpen2 (voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc32_def)
 
zipFile ZEXPORT zipOpen2_64 (voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
 
zipFile ZEXPORT zipOpen (voidpf file, int append)
 
zipFile ZEXPORT zipOpen64 (voidpf file, int append)
 
int Write_LocalFileHeader (zip64_internal *zi, const char *filename, uInt size_extrafield_local, const void *extrafield_local, uLong version_to_extract)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
static int zip64FlushWriteBuffer (zip64_internal *zi)
 
int ZEXPORT zipWriteInFileInZip (zipFile file, const void *buf, unsigned int len)
 
int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
 
int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
 
int ZEXPORT zipCloseFileInZip (zipFile file)
 
int Write_Zip64EndOfCentralDirectoryLocator (zip64_internal *zi, ZPOS64_T zip64eocd_pos_inzip)
 
int Write_Zip64EndOfCentralDirectoryRecord (zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
 
int Write_EndOfCentralDirectoryRecord (zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
 
int Write_GlobalComment (zip64_internal *zi, const char *global_comment)
 
int ZEXPORT zipClose (zipFile file, const char *global_comment)
 
int ZEXPORT zipRemoveExtraInfoBlock (char *pData, int *dataLen, short sHeader)
 
int ZEXPORT zipSetFlags (zipFile file, unsigned flags)
 
int ZEXPORT zipClearFlags (zipFile file, unsigned flags)
 

Variables

const char zip_copyright [] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"
 

Data Structure Documentation

struct linkedlist_datablock_internal_s

Definition at line 121 of file zip.c.

+ Collaboration diagram for linkedlist_datablock_internal_s:
Data Fields
uLong avail_in_this_block
unsigned char data[(4096-(4 *4))]
uLong filled_in_this_block
struct
linkedlist_datablock_internal_s *
next_datablock
uLong unused
struct linkedlist_data_s

Definition at line 130 of file zip.c.

+ Collaboration diagram for linkedlist_data_s:
Data Fields
linkedlist_datablock_internal * first_block
linkedlist_datablock_internal * last_block
struct curfile64_info

Definition at line 137 of file zip.c.

+ Collaboration diagram for curfile64_info:
Data Fields
Byte buffered_data[(64 *1024)]
char * central_header
uLong crc32
int crypt_header_size
uLong dosDate
int encrypt
uLong flag
unsigned long keys[3]
int method
const z_crc_t FAR * pcrc_32_tab
uInt pos_in_buffered_data
ZPOS64_T pos_local_header
ZPOS64_T pos_zip64extrainfo
int raw
uLong size_centralExtra
uLong size_centralExtraFree
uLong size_centralheader
z_stream stream
int stream_initialised
ZPOS64_T totalCompressedData
ZPOS64_T totalUncompressedData
int zip64
struct zip64_internal

Definition at line 172 of file zip.c.

+ Collaboration diagram for zip64_internal:
Data Fields
ZPOS64_T add_position_when_writting_offset
ZPOS64_T begin_pos
linkedlist_data central_dir
curfile64_info ci
voidpf filestream
unsigned flags
char * globalcomment
int in_opened_file_inzip
ZPOS64_T number_entry
zlib_filefunc64_32_def z_filefunc

Macro Definition Documentation

#define BUFREADCOMMENT   (0x400)

Definition at line 481 of file zip.c.

Referenced by zip64local_SearchCentralDir(), and zip64local_SearchCentralDir64().

#define CENTRALHEADERMAGIC   (0x02014b50)

Definition at line 111 of file zip.c.

Referenced by zipOpenNewFileInZip4_64().

#define CRC_LOCALHEADER_OFFSET   (0x0e)

Definition at line 117 of file zip.c.

#define DESCRIPTORHEADERMAGIC   (0x08074b50)

Definition at line 110 of file zip.c.

Referenced by zipCloseFileInZipRaw64().

#define ENDHEADERMAGIC   (0x06054b50)

Definition at line 112 of file zip.c.

Referenced by Write_EndOfCentralDirectoryRecord().

#define FLAG_LOCALHEADER_OFFSET   (0x06)

Definition at line 116 of file zip.c.

#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED

Definition at line 194 of file zip.c.

#define local   static

Definition at line 51 of file zip.c.

#define LOCALHEADERMAGIC   (0x04034b50)

Definition at line 109 of file zip.c.

Referenced by Write_LocalFileHeader().

#define MAKEULONG64 (   a,
 
)    ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))

Definition at line 83 of file zip.c.

#define SEEK_CUR   1

Definition at line 86 of file zip.c.

#define SEEK_END   2

Definition at line 90 of file zip.c.

Referenced by zipOpen3().

#define SEEK_SET   0

Definition at line 94 of file zip.c.

#define SIZECENTRALHEADER   (0x2e) /* 46 */

Definition at line 119 of file zip.c.

Referenced by zipOpenNewFileInZip4_64().

#define SIZEDATA_INDATABLOCK   (4096-(4*4))

Definition at line 107 of file zip.c.

Referenced by allocate_new_datablock(), and LoadCentralDirectoryRecord().

#define TRYFREE (   p)    {if (p) free(p);}
#define VERSIONMADEBY   (0x031e) /* best for standard pkware crypt */
#define Z_BUFSIZE   (64*1024) /* (16384) */

Definition at line 60 of file zip.c.

Referenced by zipCloseFileInZipRaw64(), zipOpenNewFileInZip4_64(), and zipWriteInFileInZip().

#define Z_MAXFILENAMEINZIP   (256)

Definition at line 64 of file zip.c.

#define ZIP64ENDHEADERMAGIC   (0x6064b50)

Definition at line 113 of file zip.c.

Referenced by Write_Zip64EndOfCentralDirectoryRecord().

#define ZIP64ENDLOCHEADERMAGIC   (0x7064b50)

Definition at line 114 of file zip.c.

Referenced by Write_Zip64EndOfCentralDirectoryLocator().

Typedef Documentation

typedef uLongf z_crc_t

Definition at line 34 of file zip.c.

Function Documentation

static int zip64local_putValue _Z_OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)  )
static
static void zip64local_putValue_inmemory _Z_OF ( (void *dest, ZPOS64_T x, int nbByte)  )
static
static int zip64local_getByte _Z_OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)  )
static
static int zip64local_getShort _Z_OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)  )
static
static int zip64local_getLong64 _Z_OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)  )
static
static ZPOS64_T zip64local_SearchCentralDir _Z_OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)  )
static
static int add_data_in_datablock ( linkedlist_data ll,
const void *  buf,
uLong  len 
)
static

Definition at line 234 of file zip.c.

References allocate_new_datablock(), linkedlist_datablock_internal_s::avail_in_this_block, linkedlist_datablock_internal_s::data, linkedlist_datablock_internal_s::filled_in_this_block, linkedlist_data_s::first_block, linkedlist_data_s::last_block, linkedlist_datablock_internal_s::next_datablock, ZIP_INTERNALERROR, and ZIP_OK.

Referenced by LoadCentralDirectoryRecord(), and zipCloseFileInZipRaw64().

235 {
237  const unsigned char* from_copy;
238 
239  if (ll==NULL)
240  return ZIP_INTERNALERROR;
241 
242  if (ll->last_block == NULL)
243  {
245  if (ll->first_block == NULL)
246  return ZIP_INTERNALERROR;
247  }
248 
249  ldi = ll->last_block;
250  from_copy = (unsigned char*)buf;
251 
252  while (len>0)
253  {
254  uInt copy_this;
255  uInt i;
256  unsigned char* to_copy;
257 
258  if (ldi->avail_in_this_block==0)
259  {
261  if (ldi->next_datablock == NULL)
262  return ZIP_INTERNALERROR;
263  ldi = ldi->next_datablock ;
264  ll->last_block = ldi;
265  }
266 
267  if (ldi->avail_in_this_block < len)
268  copy_this = (uInt)ldi->avail_in_this_block;
269  else
270  copy_this = (uInt)len;
271 
272  to_copy = &(ldi->data[ldi->filled_in_this_block]);
273 
274  for (i=0;i<copy_this;i++)
275  *(to_copy+i)=*(from_copy+i);
276 
277  ldi->filled_in_this_block += copy_this;
278  ldi->avail_in_this_block -= copy_this;
279  from_copy += copy_this ;
280  len -= copy_this;
281  }
282  return ZIP_OK;
283 }
#define ZIP_OK
Definition: zip.h:78
unsigned char data[(4096-(4 *4))]
Definition: zip.c:127
linkedlist_datablock_internal * last_block
Definition: zip.c:133
#define ZIP_INTERNALERROR
Definition: zip.h:83
static linkedlist_datablock_internal * allocate_new_datablock()
Definition: zip.c:198
struct linkedlist_datablock_internal_s * next_datablock
Definition: zip.c:123
linkedlist_datablock_internal * first_block
Definition: zip.c:132

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static linkedlist_datablock_internal* allocate_new_datablock ( )
static

Definition at line 198 of file zip.c.

References ALLOC, linkedlist_datablock_internal_s::avail_in_this_block, linkedlist_datablock_internal_s::filled_in_this_block, linkedlist_datablock_internal_s::next_datablock, and SIZEDATA_INDATABLOCK.

Referenced by add_data_in_datablock().

199 {
203  if (ldi!=NULL)
204  {
205  ldi->next_datablock = NULL ;
206  ldi->filled_in_this_block = 0 ;
208  }
209  return ldi;
210 }
#define SIZEDATA_INDATABLOCK
Definition: zip.c:107
#define ALLOC(size)
Definition: zip.c:68
struct linkedlist_datablock_internal_s * next_datablock
Definition: zip.c:123

+ Here is the caller graph for this function:

static void free_datablock ( linkedlist_datablock_internal ldi)
static

Definition at line 212 of file zip.c.

References linkedlist_datablock_internal_s::next_datablock, and TRYFREE.

Referenced by free_linkedlist().

213 {
214  while (ldi!=NULL)
215  {
217  TRYFREE(ldi);
218  ldi = ldinext;
219  }
220 }
#define TRYFREE(p)
Definition: zip.c:71
struct linkedlist_datablock_internal_s * next_datablock
Definition: zip.c:123

+ Here is the caller graph for this function:

static void free_linkedlist ( linkedlist_data ll)
static

Definition at line 227 of file zip.c.

References linkedlist_data_s::first_block, free_datablock(), and linkedlist_data_s::last_block.

Referenced by zipClose().

228 {
230  ll->first_block = ll->last_block = NULL;
231 }
linkedlist_datablock_internal * last_block
Definition: zip.c:133
static void free_datablock(linkedlist_datablock_internal *ldi)
Definition: zip.c:212
linkedlist_datablock_internal * first_block
Definition: zip.c:132

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void init_linkedlist ( linkedlist_data ll)
static

Definition at line 222 of file zip.c.

References linkedlist_data_s::first_block, and linkedlist_data_s::last_block.

Referenced by zipOpen3().

223 {
224  ll->first_block = ll->last_block = NULL;
225 }
linkedlist_datablock_internal * last_block
Definition: zip.c:133
linkedlist_datablock_internal * first_block
Definition: zip.c:132

+ Here is the caller graph for this function:

int LoadCentralDirectoryRecord ( zip64_internal pziinit)

Definition at line 649 of file zip.c.

References add_data_in_datablock(), zip64_internal::add_position_when_writting_offset, ALLOC, zip64_internal::begin_pos, zip64_internal::central_dir, zip64_internal::filestream, zip64_internal::flags, zip64_internal::globalcomment, zip64_internal::number_entry, SIZEDATA_INDATABLOCK, TRYFREE, zip64_internal::z_filefunc, ZCLOSE64, ZFAKECLOSE64, zip64local_getLong(), zip64local_getLong64(), zip64local_getShort(), zip64local_SearchCentralDir(), zip64local_SearchCentralDir64(), ZIP_AUTO_CLOSE, ZIP_BADZIPFILE, ZIP_ERRNO, ZIP_OK, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, and ZSEEK64.

Referenced by zipOpen3().

650 {
651  int err=ZIP_OK;
652  ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
653 
654  ZPOS64_T size_central_dir; /* size of the central directory */
655  ZPOS64_T offset_central_dir; /* offset of start of central directory */
656  ZPOS64_T central_pos;
657  uLong uL;
658 
659  uLong number_disk; /* number of the current dist, used for
660  spaning ZIP, unsupported, always 0*/
661  uLong number_disk_with_CD; /* number the the disk with central dir, used
662  for spaning ZIP, unsupported, always 0*/
663  ZPOS64_T number_entry;
664  ZPOS64_T number_entry_CD; /* total number of entries in
665  the central dir
666  (same than number_entry on nospan) */
667  uLong VersionMadeBy;
668  uLong VersionNeeded;
669  uLong size_comment;
670 
671  int hasZIP64Record = 0;
672 
673  /* check first if we find a ZIP64 record */
674  central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
675  if(central_pos > 0)
676  {
677  hasZIP64Record = 1;
678  }
679  else if(central_pos == 0)
680  {
681  central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
682  }
683 
684 /* disable to allow appending to empty ZIP archive
685  if (central_pos==0)
686  err=ZIP_ERRNO;
687 */
688 
689  if(hasZIP64Record)
690  {
691  ZPOS64_T sizeEndOfCentralDirectory;
692  if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
693  err=ZIP_ERRNO;
694 
695  /* the signature, already checked */
696  if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
697  err=ZIP_ERRNO;
698 
699  /* size of zip64 end of central directory record */
700  if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
701  err=ZIP_ERRNO;
702 
703  /* version made by */
704  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
705  err=ZIP_ERRNO;
706 
707  /* version needed to extract */
708  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
709  err=ZIP_ERRNO;
710 
711  /* number of this disk */
712  if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
713  err=ZIP_ERRNO;
714 
715  /* number of the disk with the start of the central directory */
716  if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
717  err=ZIP_ERRNO;
718 
719  /* total number of entries in the central directory on this disk */
720  if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
721  err=ZIP_ERRNO;
722 
723  /* total number of entries in the central directory */
724  if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
725  err=ZIP_ERRNO;
726 
727  if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
728  err=ZIP_BADZIPFILE;
729 
730  /* size of the central directory */
731  if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
732  err=ZIP_ERRNO;
733 
734  /* offset of start of central directory with respect to the
735  starting disk number */
736  if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
737  err=ZIP_ERRNO;
738 
739  /* TODO.. */
740  /* read the comment from the standard central header. */
741  size_comment = 0;
742  }
743  else
744  {
745  /* Read End of central Directory info */
746  if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
747  err=ZIP_ERRNO;
748 
749  /* the signature, already checked */
750  if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
751  err=ZIP_ERRNO;
752 
753  /* number of this disk */
754  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
755  err=ZIP_ERRNO;
756 
757  /* number of the disk with the start of the central directory */
758  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
759  err=ZIP_ERRNO;
760 
761  /* total number of entries in the central dir on this disk */
762  number_entry = 0;
763  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
764  err=ZIP_ERRNO;
765  else
766  number_entry = uL;
767 
768  /* total number of entries in the central dir */
769  number_entry_CD = 0;
770  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
771  err=ZIP_ERRNO;
772  else
773  number_entry_CD = uL;
774 
775  if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
776  err=ZIP_BADZIPFILE;
777 
778  /* size of the central directory */
779  size_central_dir = 0;
780  if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
781  err=ZIP_ERRNO;
782  else
783  size_central_dir = uL;
784 
785  /* offset of start of central directory with respect to the starting disk number */
786  offset_central_dir = 0;
787  if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
788  err=ZIP_ERRNO;
789  else
790  offset_central_dir = uL;
791 
792 
793  /* zipfile global comment length */
794  if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
795  err=ZIP_ERRNO;
796  }
797 
798  if ((central_pos<offset_central_dir+size_central_dir) &&
799  (err==ZIP_OK))
800  err=ZIP_BADZIPFILE;
801 
802  if (err!=ZIP_OK)
803  {
804  if ((pziinit->flags & ZIP_AUTO_CLOSE) != 0) {
805  ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
806  } else {
807  ZFAKECLOSE64(pziinit->z_filefunc, pziinit->filestream);
808  }
809  return ZIP_ERRNO;
810  }
811 
812  if (size_comment>0)
813  {
814  pziinit->globalcomment = (char*)ALLOC(size_comment+1);
815  if (pziinit->globalcomment)
816  {
817  size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
818  pziinit->globalcomment[size_comment]=0;
819  }
820  }
821 
822  byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
823  pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
824 
825  {
826  ZPOS64_T size_central_dir_to_read = size_central_dir;
827  size_t buf_size = SIZEDATA_INDATABLOCK;
828  void* buf_read = (void*)ALLOC(buf_size);
829  if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
830  err=ZIP_ERRNO;
831 
832  while ((size_central_dir_to_read>0) && (err==ZIP_OK))
833  {
834  ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
835  if (read_this > size_central_dir_to_read)
836  read_this = size_central_dir_to_read;
837 
838  if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
839  err=ZIP_ERRNO;
840 
841  if (err==ZIP_OK)
842  err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
843 
844  size_central_dir_to_read-=read_this;
845  }
846  TRYFREE(buf_read);
847  }
848  pziinit->begin_pos = byte_before_the_zipfile;
849  pziinit->number_entry = number_entry_CD;
850 
851  if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
852  err=ZIP_ERRNO;
853 
854  return err;
855 }
#define ZIP_OK
Definition: zip.h:78
static int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
Definition: zip.c:435
char * globalcomment
Definition: zip.c:185
static int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: zip.c:382
#define SIZEDATA_INDATABLOCK
Definition: zip.c:107
#define ZIP_BADZIPFILE
Definition: zip.h:82
voidpf filestream
Definition: zip.c:175
unsigned flags
Definition: zip.c:188
static ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
Definition: zip.c:551
static int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: zip.c:404
#define ZCLOSE64(filefunc, filestream)
Definition: ioapi.h:189
#define ZFAKECLOSE64(filefunc, filestream)
Definition: ioapi.h:190
#define ZREAD64(filefunc, filestream, buf, size)
Definition: ioapi.h:185
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
linkedlist_data central_dir
Definition: zip.c:176
#define TRYFREE(p)
Definition: zip.c:71
#define ZIP_AUTO_CLOSE
Definition: zip.h:86
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZIP_ERRNO
Definition: zip.h:80
ZPOS64_T number_entry
Definition: zip.c:182
#define ALLOC(size)
Definition: zip.c:68
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:201
ZPOS64_T begin_pos
Definition: zip.c:180
static ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
Definition: zip.c:489
static int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
Definition: zip.c:234
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:111

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Write_EndOfCentralDirectoryRecord ( zip64_internal zi,
uLong  size_centraldir,
ZPOS64_T  centraldir_pos_inzip 
)

Definition at line 1876 of file zip.c.

References zip64_internal::add_position_when_writting_offset, ENDHEADERMAGIC, zip64_internal::filestream, zip64_internal::number_entry, zip64_internal::z_filefunc, zip64local_putValue(), and ZIP_OK.

Referenced by zipClose().

1877 {
1878  int err = ZIP_OK;
1879 
1880  /*signature*/
1881  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1882 
1883  if (err==ZIP_OK) /* number of this disk */
1884  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1885 
1886  if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1887  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1888 
1889  if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1890  {
1891  {
1892  if(zi->number_entry >= 0xFFFF)
1893  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
1894  else
1895  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1896  }
1897  }
1898 
1899  if (err==ZIP_OK) /* total number of entries in the central dir */
1900  {
1901  if(zi->number_entry >= 0xFFFF)
1902  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
1903  else
1904  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1905  }
1906 
1907  if (err==ZIP_OK) /* size of the central directory */
1908  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1909 
1910  if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1911  {
1912  ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1913  if(pos >= 0xffffffff)
1914  {
1915  err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
1916  }
1917  else
1918  err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
1919  }
1920 
1921  return err;
1922 }
#define ZIP_OK
Definition: zip.h:78
#define ENDHEADERMAGIC
Definition: zip.c:112
voidpf filestream
Definition: zip.c:175
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
ZPOS64_T number_entry
Definition: zip.c:182
static int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Write_GlobalComment ( zip64_internal zi,
const char *  global_comment 
)

Definition at line 1924 of file zip.c.

References zip64_internal::filestream, zip64_internal::z_filefunc, zip64local_putValue(), ZIP_ERRNO, ZIP_OK, and ZWRITE64.

Referenced by zipClose().

1925 {
1926  int err = ZIP_OK;
1927  uInt size_global_comment = 0;
1928 
1929  if(global_comment != NULL)
1930  size_global_comment = (uInt)strlen(global_comment);
1931 
1932  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
1933 
1934  if (err == ZIP_OK && size_global_comment > 0)
1935  {
1936  if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
1937  err = ZIP_ERRNO;
1938  }
1939  return err;
1940 }
#define ZIP_OK
Definition: zip.h:78
voidpf filestream
Definition: zip.c:175
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZIP_ERRNO
Definition: zip.h:80
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:186
static int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Write_LocalFileHeader ( zip64_internal zi,
const char *  filename,
uInt  size_extrafield_local,
const void *  extrafield_local,
uLong  version_to_extract 
)

Definition at line 977 of file zip.c.

References zip64_internal::ci, curfile64_info::dosDate, zip64_internal::filestream, curfile64_info::flag, LOCALHEADERMAGIC, curfile64_info::method, curfile64_info::pos_zip64extrainfo, zip64_internal::z_filefunc, curfile64_info::zip64, zip64local_putValue(), ZIP_ERRNO, ZIP_OK, ZTELL64, and ZWRITE64.

Referenced by zipOpenNewFileInZip4_64().

981 {
982  /* write the local header */
983  int err;
984  uInt size_filename = (uInt)strlen(filename);
985  uInt size_extrafield = size_extrafield_local;
986 
987  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
988 
989  if (err==ZIP_OK)
990  {
991  if(zi->ci.zip64)
992  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
993  else
994  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)version_to_extract,2);
995  }
996 
997  if (err==ZIP_OK)
998  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
999 
1000  if (err==ZIP_OK)
1001  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
1002 
1003  if (err==ZIP_OK)
1004  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
1005 
1006  /* CRC / Compressed size / Uncompressed size will be filled in later and rewritten later */
1007  if (err==ZIP_OK)
1008  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
1009  if (err==ZIP_OK)
1010  {
1011  if(zi->ci.zip64)
1012  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
1013  else
1014  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
1015  }
1016  if (err==ZIP_OK)
1017  {
1018  if(zi->ci.zip64)
1019  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
1020  else
1021  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
1022  }
1023 
1024  if (err==ZIP_OK)
1025  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
1026 
1027  if(zi->ci.zip64)
1028  {
1029  size_extrafield += 20;
1030  }
1031 
1032  if (err==ZIP_OK)
1033  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
1034 
1035  if ((err==ZIP_OK) && (size_filename > 0))
1036  {
1037  if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
1038  err = ZIP_ERRNO;
1039  }
1040 
1041  if ((err==ZIP_OK) && (size_extrafield_local > 0))
1042  {
1043  if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
1044  err = ZIP_ERRNO;
1045  }
1046 
1047 
1048  if ((err==ZIP_OK) && (zi->ci.zip64))
1049  {
1050  /* write the Zip64 extended info */
1051  short HeaderID = 1;
1052  short DataSize = 16;
1053  ZPOS64_T CompressedSize = 0;
1054  ZPOS64_T UncompressedSize = 0;
1055 
1056  /* Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) */
1058 
1059  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
1060  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
1061 
1062  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
1063  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
1064  }
1065 
1066  return err;
1067 }
#define ZIP_OK
Definition: zip.h:78
#define LOCALHEADERMAGIC
Definition: zip.c:109
ZPOS64_T pos_zip64extrainfo
Definition: zip.c:162
voidpf filestream
Definition: zip.c:175
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
#define ZIP_ERRNO
Definition: zip.h:80
uLong dosDate
Definition: zip.c:158
uLong flag
Definition: zip.c:153
curfile64_info ci
Definition: zip.c:178
int zip64
Definition: zip.c:161
int method
Definition: zip.c:155
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:186
static int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Write_Zip64EndOfCentralDirectoryLocator ( zip64_internal zi,
ZPOS64_T  zip64eocd_pos_inzip 
)

Definition at line 1815 of file zip.c.

References zip64_internal::add_position_when_writting_offset, zip64_internal::filestream, zip64_internal::z_filefunc, ZIP64ENDLOCHEADERMAGIC, zip64local_putValue(), and ZIP_OK.

Referenced by zipClose().

1816 {
1817  int err = ZIP_OK;
1818  ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
1819 
1821 
1822  /*num disks*/
1823  if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1824  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1825 
1826  /*relative offset*/
1827  if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
1828  err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
1829 
1830  /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
1831  if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1832  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
1833 
1834  return err;
1835 }
#define ZIP_OK
Definition: zip.h:78
#define ZIP64ENDLOCHEADERMAGIC
Definition: zip.c:114
voidpf filestream
Definition: zip.c:175
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
static int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Write_Zip64EndOfCentralDirectoryRecord ( zip64_internal zi,
uLong  size_centraldir,
ZPOS64_T  centraldir_pos_inzip 
)

Definition at line 1837 of file zip.c.

References zip64_internal::add_position_when_writting_offset, zip64_internal::filestream, zip64_internal::number_entry, zip64_internal::z_filefunc, ZIP64ENDHEADERMAGIC, zip64local_putValue(), and ZIP_OK.

Referenced by zipClose().

1838 {
1839  int err = ZIP_OK;
1840 
1841  uLong Zip64DataSize = 44;
1842 
1844 
1845  if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
1846  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); /* why ZPOS64_T of this ? */
1847 
1848  if (err==ZIP_OK) /* version made by */
1849  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1850 
1851  if (err==ZIP_OK) /* version needed */
1852  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1853 
1854  if (err==ZIP_OK) /* number of this disk */
1855  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1856 
1857  if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1858  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1859 
1860  if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1861  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1862 
1863  if (err==ZIP_OK) /* total number of entries in the central dir */
1864  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1865 
1866  if (err==ZIP_OK) /* size of the central directory */
1867  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
1868 
1869  if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1870  {
1871  ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1872  err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
1873  }
1874  return err;
1875 }
#define ZIP_OK
Definition: zip.h:78
voidpf filestream
Definition: zip.c:175
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
#define ZIP64ENDHEADERMAGIC
Definition: zip.c:113
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
ZPOS64_T number_entry
Definition: zip.c:182
static int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int zip64FlushWriteBuffer ( zip64_internal zi)
static

Definition at line 1403 of file zip.c.

References curfile64_info::buffered_data, zip64_internal::ci, curfile64_info::encrypt, zip64_internal::filestream, curfile64_info::keys, curfile64_info::method, curfile64_info::pcrc_32_tab, curfile64_info::pos_in_buffered_data, curfile64_info::stream, curfile64_info::totalCompressedData, curfile64_info::totalUncompressedData, Z_BZIP2ED, zip64_internal::z_filefunc, zencode, ZIP_ERRNO, ZIP_OK, and ZWRITE64.

Referenced by zipCloseFileInZipRaw64(), and zipWriteInFileInZip().

1404 {
1405  int err=ZIP_OK;
1406 
1407  if (zi->ci.encrypt != 0)
1408  {
1409 #ifndef NOCRYPT
1410  uInt i;
1411  int t;
1412  for (i=0;i<zi->ci.pos_in_buffered_data;i++)
1413  zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
1414 #endif
1415  }
1416 
1418  err = ZIP_ERRNO;
1419 
1421 
1422 #ifdef HAVE_BZIP2
1423  if(zi->ci.method == Z_BZIP2ED)
1424  {
1425  zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
1426  zi->ci.bstream.total_in_lo32 = 0;
1427  zi->ci.bstream.total_in_hi32 = 0;
1428  }
1429  else
1430 #endif
1431  {
1432  zi->ci.totalUncompressedData += zi->ci.stream.total_in;
1433  zi->ci.stream.total_in = 0;
1434  }
1435 
1436 
1437  zi->ci.pos_in_buffered_data = 0;
1438 
1439  return err;
1440 }
#define ZIP_OK
Definition: zip.h:78
Byte buffered_data[(64 *1024)]
Definition: zip.c:157
unsigned long keys[3]
Definition: zip.c:166
ZPOS64_T totalCompressedData
Definition: zip.c:163
uInt pos_in_buffered_data
Definition: zip.c:145
voidpf filestream
Definition: zip.c:175
#define Z_BZIP2ED
Definition: unzip.h:67
const z_crc_t FAR * pcrc_32_tab
Definition: zip.c:167
int encrypt
Definition: zip.c:160
#define zencode(pkeys, pcrc_32_tab, c, t)
Definition: crypt.h:82
z_stream stream
Definition: zip.c:139
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZIP_ERRNO
Definition: zip.h:80
curfile64_info ci
Definition: zip.c:178
ZPOS64_T totalUncompressedData
Definition: zip.c:164
int method
Definition: zip.c:155
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:186

+ Here is the caller graph for this function:

static int zip64local_getByte ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
int *  pi 
)
static

Definition at line 358 of file zip.c.

References ZERROR64, ZIP_EOF, ZIP_ERRNO, ZIP_OK, and ZREAD64.

Referenced by zip64local_getLong(), zip64local_getLong64(), and zip64local_getShort().

359 {
360  unsigned char c;
361  int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
362  if (err==1)
363  {
364  *pi = (int)c;
365  return ZIP_OK;
366  }
367  else
368  {
369  if (ZERROR64(*pzlib_filefunc_def,filestream))
370  return ZIP_ERRNO;
371  else
372  return ZIP_EOF;
373  }
374 }
#define ZIP_OK
Definition: zip.h:78
#define ZERROR64(filefunc, filestream)
Definition: ioapi.h:191
#define ZREAD64(filefunc, filestream, buf, size)
Definition: ioapi.h:185
#define ZIP_EOF
Definition: zip.h:79
#define ZIP_ERRNO
Definition: zip.h:80

+ Here is the caller graph for this function:

static int zip64local_getLong ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
uLong *  pX 
)
static

Definition at line 404 of file zip.c.

References x, zip64local_getByte(), and ZIP_OK.

Referenced by LoadCentralDirectoryRecord(), and zip64local_SearchCentralDir64().

405 {
406  uLong x ;
407  int i = 0;
408  int err;
409 
410  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
411  x = (uLong)i;
412 
413  if (err==ZIP_OK)
414  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
415  x += ((uLong)i)<<8;
416 
417  if (err==ZIP_OK)
418  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
419  x += ((uLong)i)<<16;
420 
421  if (err==ZIP_OK)
422  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
423  x += ((uLong)i)<<24;
424 
425  if (err==ZIP_OK)
426  *pX = x;
427  else
428  *pX = 0;
429  return err;
430 }
#define ZIP_OK
Definition: zip.h:78
static int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
Definition: zip.c:358
float x
Definition: main.c:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int zip64local_getLong64 ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
ZPOS64_T pX 
)
static

Definition at line 435 of file zip.c.

References x, zip64local_getByte(), and ZIP_OK.

Referenced by LoadCentralDirectoryRecord(), and zip64local_SearchCentralDir64().

436 {
437  ZPOS64_T x;
438  int i = 0;
439  int err;
440 
441  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
442  x = (ZPOS64_T)i;
443 
444  if (err==ZIP_OK)
445  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
446  x += ((ZPOS64_T)i)<<8;
447 
448  if (err==ZIP_OK)
449  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
450  x += ((ZPOS64_T)i)<<16;
451 
452  if (err==ZIP_OK)
453  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
454  x += ((ZPOS64_T)i)<<24;
455 
456  if (err==ZIP_OK)
457  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
458  x += ((ZPOS64_T)i)<<32;
459 
460  if (err==ZIP_OK)
461  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
462  x += ((ZPOS64_T)i)<<40;
463 
464  if (err==ZIP_OK)
465  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
466  x += ((ZPOS64_T)i)<<48;
467 
468  if (err==ZIP_OK)
469  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
470  x += ((ZPOS64_T)i)<<56;
471 
472  if (err==ZIP_OK)
473  *pX = x;
474  else
475  *pX = 0;
476 
477  return err;
478 }
#define ZIP_OK
Definition: zip.h:78
static int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
Definition: zip.c:358
float x
Definition: main.c:66
unsigned long long int ZPOS64_T
Definition: ioapi.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int zip64local_getShort ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
uLong *  pX 
)
static

Definition at line 382 of file zip.c.

References x, zip64local_getByte(), and ZIP_OK.

Referenced by LoadCentralDirectoryRecord().

383 {
384  uLong x ;
385  int i = 0;
386  int err;
387 
388  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
389  x = (uLong)i;
390 
391  if (err==ZIP_OK)
392  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
393  x += ((uLong)i)<<8;
394 
395  if (err==ZIP_OK)
396  *pX = x;
397  else
398  *pX = 0;
399  return err;
400 }
#define ZIP_OK
Definition: zip.h:78
static int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
Definition: zip.c:358
float x
Definition: main.c:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int zip64local_putValue ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
ZPOS64_T  x,
int  nbByte 
)
static

Definition at line 296 of file zip.c.

References ZIP_ERRNO, ZIP_OK, and ZWRITE64.

Referenced by Write_EndOfCentralDirectoryRecord(), Write_GlobalComment(), Write_LocalFileHeader(), Write_Zip64EndOfCentralDirectoryLocator(), Write_Zip64EndOfCentralDirectoryRecord(), and zipCloseFileInZipRaw64().

297 {
298  unsigned char buf[8];
299  int n;
300  for (n = 0; n < nbByte; n++)
301  {
302  buf[n] = (unsigned char)(x & 0xff);
303  x >>= 8;
304  }
305  if (x != 0)
306  { /* data overflow - hack for ZIP64 (X Roche) */
307  for (n = 0; n < nbByte; n++)
308  {
309  buf[n] = 0xff;
310  }
311  }
312 
313  if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
314  return ZIP_ERRNO;
315  else
316  return ZIP_OK;
317 }
#define ZIP_OK
Definition: zip.h:78
float x
Definition: main.c:66
#define ZIP_ERRNO
Definition: zip.h:80
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:186

+ Here is the caller graph for this function:

static void zip64local_putValue_inmemory ( void *  dest,
ZPOS64_T  x,
int  nbByte 
)
static

Definition at line 320 of file zip.c.

Referenced by zipCloseFileInZipRaw64(), and zipOpenNewFileInZip4_64().

321 {
322  unsigned char* buf=(unsigned char*)dest;
323  int n;
324  for (n = 0; n < nbByte; n++) {
325  buf[n] = (unsigned char)(x & 0xff);
326  x >>= 8;
327  }
328 
329  if (x != 0)
330  { /* data overflow - hack for ZIP64 */
331  for (n = 0; n < nbByte; n++)
332  {
333  buf[n] = 0xff;
334  }
335  }
336 }
float x
Definition: main.c:66

+ Here is the caller graph for this function:

static ZPOS64_T zip64local_SearchCentralDir ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream 
)
static

Definition at line 489 of file zip.c.

References ALLOC, BUFREADCOMMENT, TRYFREE, ZLIB_FILEFUNC_SEEK_END, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, ZSEEK64, and ZTELL64.

Referenced by LoadCentralDirectoryRecord().

490 {
491  unsigned char* buf;
492  ZPOS64_T uSizeFile;
493  ZPOS64_T uBackRead;
494  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
495  ZPOS64_T uPosFound=0;
496 
497  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
498  return 0;
499 
500 
501  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
502 
503  if (uMaxBack>uSizeFile)
504  uMaxBack = uSizeFile;
505 
506  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
507  if (buf==NULL)
508  return 0;
509 
510  uBackRead = 4;
511  while (uBackRead<uMaxBack)
512  {
513  uLong uReadSize;
514  ZPOS64_T uReadPos ;
515  int i;
516  if (uBackRead+BUFREADCOMMENT>uMaxBack)
517  uBackRead = uMaxBack;
518  else
519  uBackRead+=BUFREADCOMMENT;
520  uReadPos = uSizeFile-uBackRead ;
521 
522  uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
523  (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
524  if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
525  break;
526 
527  if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
528  break;
529 
530  for (i=(int)uReadSize-3; (i--)>0;)
531  if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
532  ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
533  {
534  uPosFound = uReadPos+i;
535  break;
536  }
537 
538  if (uPosFound!=0)
539  break;
540  }
541  TRYFREE(buf);
542  return uPosFound;
543 }
#define ZREAD64(filefunc, filestream, buf, size)
Definition: ioapi.h:185
#define TRYFREE(p)
Definition: zip.c:71
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
#define ALLOC(size)
Definition: zip.c:68
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:201
#define ZLIB_FILEFUNC_SEEK_END
Definition: ioapi.h:110
#define BUFREADCOMMENT
Definition: zip.c:481
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:111

+ Here is the caller graph for this function:

static ZPOS64_T zip64local_SearchCentralDir64 ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream 
)
static

Definition at line 551 of file zip.c.

References ALLOC, BUFREADCOMMENT, TRYFREE, zip64local_getLong(), zip64local_getLong64(), ZIP_OK, ZLIB_FILEFUNC_SEEK_END, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, ZSEEK64, and ZTELL64.

Referenced by LoadCentralDirectoryRecord().

552 {
553  unsigned char* buf;
554  ZPOS64_T uSizeFile;
555  ZPOS64_T uBackRead;
556  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
557  ZPOS64_T uPosFound=0;
558  uLong uL;
559  ZPOS64_T relativeOffset;
560 
561  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
562  return 0;
563 
564  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
565 
566  if (uMaxBack>uSizeFile)
567  uMaxBack = uSizeFile;
568 
569  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
570  if (buf==NULL)
571  return 0;
572 
573  uBackRead = 4;
574  while (uBackRead<uMaxBack)
575  {
576  uLong uReadSize;
577  ZPOS64_T uReadPos;
578  int i;
579  if (uBackRead+BUFREADCOMMENT>uMaxBack)
580  uBackRead = uMaxBack;
581  else
582  uBackRead+=BUFREADCOMMENT;
583  uReadPos = uSizeFile-uBackRead ;
584 
585  uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
586  (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
587  if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
588  break;
589 
590  if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
591  break;
592 
593  for (i=(int)uReadSize-3; (i--)>0;)
594  {
595  /* Signature "0x07064b50" Zip64 end of central directory locater */
596  if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
597  {
598  uPosFound = uReadPos+i;
599  break;
600  }
601  }
602 
603  if (uPosFound!=0)
604  break;
605  }
606 
607  TRYFREE(buf);
608  if (uPosFound == 0)
609  return 0;
610 
611  /* Zip64 end of central directory locator */
612  if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
613  return 0;
614 
615  /* the signature, already checked */
616  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
617  return 0;
618 
619  /* number of the disk with the start of the zip64 end of central directory */
620  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
621  return 0;
622  if (uL != 0)
623  return 0;
624 
625  /* relative offset of the zip64 end of central directory record */
626  if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
627  return 0;
628 
629  /* total number of disks */
630  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
631  return 0;
632  if (uL != 1)
633  return 0;
634 
635  /* Goto Zip64 end of central directory record */
636  if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
637  return 0;
638 
639  /* the signature */
640  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
641  return 0;
642 
643  if (uL != 0x06064b50) /* signature of 'Zip64 end of central directory' */
644  return 0;
645 
646  return relativeOffset;
647 }
#define ZIP_OK
Definition: zip.h:78
static int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
Definition: zip.c:435
static int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: zip.c:404
#define ZREAD64(filefunc, filestream, buf, size)
Definition: ioapi.h:185
#define TRYFREE(p)
Definition: zip.c:71
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
#define ALLOC(size)
Definition: zip.c:68
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:201
#define ZLIB_FILEFUNC_SEEK_END
Definition: ioapi.h:110
#define BUFREADCOMMENT
Definition: zip.c:481
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:111

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static uLong zip64local_TmzDateToDosDate ( const tm_zip ptm)
static

Definition at line 341 of file zip.c.

References tm_zip_s::tm_hour, tm_zip_s::tm_mday, tm_zip_s::tm_min, tm_zip_s::tm_mon, tm_zip_s::tm_sec, and tm_zip_s::tm_year.

Referenced by zipOpenNewFileInZip4_64().

342 {
343  uLong year = (uLong)ptm->tm_year;
344  if (year>=1980)
345  year-=1980;
346  else if (year>=80)
347  year-=80;
348  return
349  (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
350  ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
351 }
uInt tm_min
Definition: zip.h:103
uInt tm_hour
Definition: zip.h:104
uInt tm_sec
Definition: zip.h:102
uInt tm_mday
Definition: zip.h:105
uInt tm_mon
Definition: zip.h:106
uInt tm_year
Definition: zip.h:107

+ Here is the caller graph for this function:

int ZEXPORT zipClearFlags ( zipFile  file,
unsigned  flags 
)

Definition at line 2091 of file zip.c.

References zip64_internal::flags, ZIP_OK, ZIP_PARAMERROR, ZIP_SEQUENTIAL, and ZIP_WRITE_DATA_DESCRIPTOR.

Referenced by QuaZipFile::open().

2092 {
2093  zip64_internal* zi;
2094  if (file == NULL)
2095  return ZIP_PARAMERROR;
2096  zi = (zip64_internal*)file;
2097  zi->flags &= ~flags;
2098  // If the data descriptor is not written, we can't use a non-seekable output.
2099  if ((zi->flags & ZIP_WRITE_DATA_DESCRIPTOR) == 0) {
2100  zi->flags &= ~ZIP_SEQUENTIAL;
2101  }
2102  return ZIP_OK;
2103 }
#define ZIP_OK
Definition: zip.h:78
#define ZIP_WRITE_DATA_DESCRIPTOR
Definition: zip.h:85
unsigned flags
Definition: zip.c:188
#define ZIP_PARAMERROR
Definition: zip.h:81
#define ZIP_SEQUENTIAL
Definition: zip.h:87

+ Here is the caller graph for this function:

int ZEXPORT zipClose ( zipFile  file,
const char *  global_comment 
)

Definition at line 1942 of file zip.c.

References zip64_internal::add_position_when_writting_offset, zip64_internal::central_dir, linkedlist_datablock_internal_s::data, zip64_internal::filestream, linkedlist_datablock_internal_s::filled_in_this_block, linkedlist_data_s::first_block, zip64_internal::flags, free_linkedlist(), zip64_internal::globalcomment, zip64_internal::in_opened_file_inzip, linkedlist_datablock_internal_s::next_datablock, zip64_internal::number_entry, TRYFREE, Write_EndOfCentralDirectoryRecord(), Write_GlobalComment(), Write_Zip64EndOfCentralDirectoryLocator(), Write_Zip64EndOfCentralDirectoryRecord(), zip64_internal::z_filefunc, ZCLOSE64, ZFAKECLOSE64, ZIP_AUTO_CLOSE, ZIP_ERRNO, ZIP_OK, ZIP_PARAMERROR, zipCloseFileInZip(), ZTELL64, and ZWRITE64.

Referenced by QuaZip::close(), and QuaZip::open().

1943 {
1944  zip64_internal* zi;
1945  int err = 0;
1946  uLong size_centraldir = 0;
1947  ZPOS64_T centraldir_pos_inzip;
1948  ZPOS64_T pos;
1949 
1950  if (file == NULL)
1951  return ZIP_PARAMERROR;
1952 
1953  zi = (zip64_internal*)file;
1954 
1955  if (zi->in_opened_file_inzip == 1)
1956  {
1957  err = zipCloseFileInZip (file);
1958  }
1959 
1960 #ifndef NO_ADDFILEINEXISTINGZIP
1961  if (global_comment==NULL)
1962  global_comment = zi->globalcomment;
1963 #endif
1964 
1965  centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1966 
1967  if (err==ZIP_OK)
1968  {
1970  while (ldi!=NULL)
1971  {
1972  if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
1973  {
1975  err = ZIP_ERRNO;
1976  }
1977 
1978  size_centraldir += ldi->filled_in_this_block;
1979  ldi = ldi->next_datablock;
1980  }
1981  }
1982  free_linkedlist(&(zi->central_dir));
1983 
1984  pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1985  if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
1986  {
1987  ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
1988  Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1989 
1990  Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
1991  }
1992 
1993  if (err==ZIP_OK)
1994  err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1995 
1996  if(err == ZIP_OK)
1997  err = Write_GlobalComment(zi, global_comment);
1998 
1999  if ((zi->flags & ZIP_AUTO_CLOSE) != 0) {
2000  if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) {
2001  if (err == ZIP_OK)
2002  err = ZIP_ERRNO;
2003  }
2004  } else {
2005  if (ZFAKECLOSE64(zi->z_filefunc,zi->filestream) != 0) {
2006  if (err == ZIP_OK)
2007  err = ZIP_ERRNO;
2008  }
2009  }
2010 
2011 #ifndef NO_ADDFILEINEXISTINGZIP
2012  TRYFREE(zi->globalcomment);
2013 #endif
2014  TRYFREE(zi);
2015 
2016  return err;
2017 }
#define ZIP_OK
Definition: zip.h:78
unsigned char data[(4096-(4 *4))]
Definition: zip.c:127
char * globalcomment
Definition: zip.c:185
int Write_EndOfCentralDirectoryRecord(zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
Definition: zip.c:1876
int in_opened_file_inzip
Definition: zip.c:177
static void free_linkedlist(linkedlist_data *ll)
Definition: zip.c:227
voidpf filestream
Definition: zip.c:175
unsigned flags
Definition: zip.c:188
#define ZCLOSE64(filefunc, filestream)
Definition: ioapi.h:189
#define ZFAKECLOSE64(filefunc, filestream)
Definition: ioapi.h:190
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
linkedlist_data central_dir
Definition: zip.c:176
#define TRYFREE(p)
Definition: zip.c:71
#define ZIP_AUTO_CLOSE
Definition: zip.h:86
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
#define ZIP_ERRNO
Definition: zip.h:80
int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
Definition: zip.c:1837
ZPOS64_T number_entry
Definition: zip.c:182
int Write_GlobalComment(zip64_internal *zi, const char *global_comment)
Definition: zip.c:1924
#define ZIP_PARAMERROR
Definition: zip.h:81
int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal *zi, ZPOS64_T zip64eocd_pos_inzip)
Definition: zip.c:1815
int ZEXPORT zipCloseFileInZip(zipFile file)
Definition: zip.c:1810
struct linkedlist_datablock_internal_s * next_datablock
Definition: zip.c:123
linkedlist_datablock_internal * first_block
Definition: zip.c:132
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:186

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int ZEXPORT zipCloseFileInZip ( zipFile  file)

Definition at line 1810 of file zip.c.

References zipCloseFileInZipRaw().

Referenced by QuaZipFile::close(), zipClose(), and zipOpenNewFileInZip4_64().

1811 {
1812  return zipCloseFileInZipRaw (file,0,0);
1813 }
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32)
Definition: zip.c:1549

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int ZEXPORT zipCloseFileInZipRaw ( zipFile  file,
uLong  uncompressed_size,
uLong  crc32 
)

Definition at line 1549 of file zip.c.

References zipCloseFileInZipRaw64().

Referenced by zipCloseFileInZip().

1550 {
1551  return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1552 }
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
Definition: zip.c:1554

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int ZEXPORT zipCloseFileInZipRaw64 ( zipFile  file,
ZPOS64_T  uncompressed_size,
uLong  crc32 
)

Definition at line 1554 of file zip.c.

References add_data_in_datablock(), curfile64_info::buffered_data, zip64_internal::central_dir, curfile64_info::central_header, zip64_internal::ci, curfile64_info::crc32, curfile64_info::crypt_header_size, DESCRIPTORHEADERMAGIC, zip64_internal::filestream, curfile64_info::flag, zip64_internal::flags, zip64_internal::in_opened_file_inzip, curfile64_info::method, zip64_internal::number_entry, curfile64_info::pos_in_buffered_data, curfile64_info::pos_local_header, curfile64_info::pos_zip64extrainfo, curfile64_info::raw, curfile64_info::size_centralExtra, curfile64_info::size_centralExtraFree, curfile64_info::size_centralheader, curfile64_info::stream, curfile64_info::stream_initialised, curfile64_info::totalCompressedData, curfile64_info::totalUncompressedData, Z_BUFSIZE, Z_BZIP2ED, zip64_internal::z_filefunc, curfile64_info::zip64, zip64FlushWriteBuffer(), zip64local_putValue(), zip64local_putValue_inmemory(), ZIP_BADZIPFILE, ZIP_ERRNO, ZIP_OK, ZIP_PARAMERROR, ZIP_SEQUENTIAL, ZLIB_FILEFUNC_SEEK_SET, ZSEEK64, and ZTELL64.

Referenced by QuaZipFile::close(), and zipCloseFileInZipRaw().

1555 {
1556  zip64_internal* zi;
1557  ZPOS64_T compressed_size;
1558  uLong invalidValue = 0xffffffff;
1559  short datasize = 0;
1560  int err=ZIP_OK;
1561 
1562  if (file == NULL)
1563  return ZIP_PARAMERROR;
1564  zi = (zip64_internal*)file;
1565 
1566  if (zi->in_opened_file_inzip == 0)
1567  return ZIP_PARAMERROR;
1568  zi->ci.stream.avail_in = 0;
1569 
1570  if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1571  {
1572  while (err==ZIP_OK)
1573  {
1574  uLong uTotalOutBefore;
1575  if (zi->ci.stream.avail_out == 0)
1576  {
1577  if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1578  err = ZIP_ERRNO;
1579  zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1580  zi->ci.stream.next_out = zi->ci.buffered_data;
1581  }
1582  uTotalOutBefore = zi->ci.stream.total_out;
1583  err=deflate(&zi->ci.stream, Z_FINISH);
1584  zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1585  }
1586  }
1587  else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1588  {
1589 #ifdef HAVE_BZIP2
1590  err = BZ_FINISH_OK;
1591  while (err==BZ_FINISH_OK)
1592  {
1593  uLong uTotalOutBefore;
1594  if (zi->ci.bstream.avail_out == 0)
1595  {
1596  if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1597  err = ZIP_ERRNO;
1598  zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1599  zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1600  }
1601  uTotalOutBefore = zi->ci.bstream.total_out_lo32;
1602  err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
1603  if(err == BZ_STREAM_END)
1604  err = Z_STREAM_END;
1605 
1606  zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
1607  }
1608 
1609  if(err == BZ_FINISH_OK)
1610  err = ZIP_OK;
1611 #endif
1612  }
1613 
1614  if (err==Z_STREAM_END)
1615  err=ZIP_OK; /* this is normal */
1616 
1617  if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1618  {
1620  err = ZIP_ERRNO;
1621  }
1622 
1623  if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1624  {
1625  int tmp_err = deflateEnd(&zi->ci.stream);
1626  if (err == ZIP_OK)
1627  err = tmp_err;
1628  zi->ci.stream_initialised = 0;
1629  }
1630 #ifdef HAVE_BZIP2
1631  else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1632  {
1633  int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
1634  if (err==ZIP_OK)
1635  err = tmperr;
1636  zi->ci.stream_initialised = 0;
1637  }
1638 #endif
1639 
1640  if (!zi->ci.raw)
1641  {
1642  crc32 = (uLong)zi->ci.crc32;
1643  uncompressed_size = zi->ci.totalUncompressedData;
1644  }
1645  compressed_size = zi->ci.totalCompressedData;
1646 
1647 # ifndef NOCRYPT
1648  compressed_size += zi->ci.crypt_header_size;
1649 # endif
1650 
1651  /* update Current Item crc and sizes, */
1652  if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
1653  {
1654  /*version Made by*/
1655  zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
1656  /*version needed*/
1657  zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
1658 
1659  }
1660 
1661  zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
1662 
1663 
1664  if(compressed_size >= 0xffffffff)
1665  zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
1666  else
1667  zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
1668 
1669  /* set internal file attributes field */
1670  if (zi->ci.stream.data_type == Z_ASCII)
1671  zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1672 
1673  if(uncompressed_size >= 0xffffffff)
1674  zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
1675  else
1676  zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
1677 
1678  /* Add ZIP64 extra info field for uncompressed size */
1679  if(uncompressed_size >= 0xffffffff)
1680  datasize += 8;
1681 
1682  /* Add ZIP64 extra info field for compressed size */
1683  if(compressed_size >= 0xffffffff)
1684  datasize += 8;
1685 
1686  /* Add ZIP64 extra info field for relative offset to local file header of current file */
1687  if(zi->ci.pos_local_header >= 0xffffffff)
1688  datasize += 8;
1689 
1690  if(datasize > 0)
1691  {
1692  char* p = NULL;
1693 
1694  if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
1695  {
1696  /* we can not write more data to the buffer that we have room for. */
1697  return ZIP_BADZIPFILE;
1698  }
1699 
1700  p = zi->ci.central_header + zi->ci.size_centralheader;
1701 
1702  /* Add Extra Information Header for 'ZIP64 information' */
1703  zip64local_putValue_inmemory(p, 0x0001, 2); /* HeaderID */
1704  p += 2;
1705  zip64local_putValue_inmemory(p, datasize, 2); /* DataSize */
1706  p += 2;
1707 
1708  if(uncompressed_size >= 0xffffffff)
1709  {
1710  zip64local_putValue_inmemory(p, uncompressed_size, 8);
1711  p += 8;
1712  }
1713 
1714  if(compressed_size >= 0xffffffff)
1715  {
1716  zip64local_putValue_inmemory(p, compressed_size, 8);
1717  p += 8;
1718  }
1719 
1720  if(zi->ci.pos_local_header >= 0xffffffff)
1721  {
1723  p += 8;
1724  }
1725 
1726  /* Update how much extra free space we got in the memory buffer */
1727  /* and increase the centralheader size so the new ZIP64 fields are included */
1728  /* ( 4 below is the size of HeaderID and DataSize field ) */
1729  zi->ci.size_centralExtraFree -= datasize + 4;
1730  zi->ci.size_centralheader += datasize + 4;
1731 
1732  /* Update the extra info size field */
1733  zi->ci.size_centralExtra += datasize + 4;
1735  }
1736 
1737  if (err==ZIP_OK)
1739 
1740  free(zi->ci.central_header);
1741 
1742  if (err==ZIP_OK)
1743  {
1744  if ((zi->flags & ZIP_SEQUENTIAL) == 0) {
1745  /* Update the LocalFileHeader with the new values. */
1746 
1747  ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1748 
1750  err = ZIP_ERRNO;
1751 
1752  if (err==ZIP_OK)
1753  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1754 
1755  if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff)
1756  {
1757  if(zi->ci.pos_zip64extrainfo > 0)
1758  {
1759  /* Update the size in the ZIP64 extended field. */
1761  err = ZIP_ERRNO;
1762 
1763  if (err==ZIP_OK) /* compressed size, unknown */
1764  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
1765 
1766  if (err==ZIP_OK) /* uncompressed size, unknown */
1767  err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
1768  }
1769  }
1770  else
1771  {
1772  if (err==ZIP_OK) /* compressed size, unknown */
1773  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1774 
1775  if (err==ZIP_OK) /* uncompressed size, unknown */
1776  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1777  }
1778 
1779  if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1780  err = ZIP_ERRNO;
1781  }
1782 
1783  if ((zi->ci.flag & 8) != 0) {
1784  /* Write local Descriptor after file data */
1785  if (err==ZIP_OK)
1787  if (err==ZIP_OK)
1788  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1789  if (zi->ci.zip64) {
1790  if (err==ZIP_OK) /* compressed size, unknown */
1791  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,8);
1792 
1793  if (err==ZIP_OK) /* uncompressed size, unknown */
1794  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,8);
1795  } else {
1796  if (err==ZIP_OK) /* compressed size, unknown */
1797  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1798  if (err==ZIP_OK) /* uncompressed size, unknown */
1799  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1800  }
1801  }
1802  }
1803 
1804  zi->number_entry ++;
1805  zi->in_opened_file_inzip = 0;
1806 
1807  return err;
1808 }
#define ZIP_OK
Definition: zip.h:78
static void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte)
Definition: zip.c:320
Byte buffered_data[(64 *1024)]
Definition: zip.c:157
int raw
Definition: zip.c:156
ZPOS64_T pos_zip64extrainfo
Definition: zip.c:162
ZPOS64_T totalCompressedData
Definition: zip.c:163
int stream_initialised
Definition: zip.c:144
int crypt_header_size
Definition: zip.c:168
uLong size_centralExtraFree
Definition: zip.c:152
int in_opened_file_inzip
Definition: zip.c:177
#define ZIP_BADZIPFILE
Definition: zip.h:82
uInt pos_in_buffered_data
Definition: zip.c:145
#define DESCRIPTORHEADERMAGIC
Definition: zip.c:110
voidpf filestream
Definition: zip.c:175
#define Z_BZIP2ED
Definition: unzip.h:67
unsigned flags
Definition: zip.c:188
uLong crc32
Definition: zip.c:159
#define Z_BUFSIZE
Definition: zip.c:60
linkedlist_data central_dir
Definition: zip.c:176
uLong size_centralExtra
Definition: zip.c:150
z_stream stream
Definition: zip.c:139
unsigned long long int ZPOS64_T
Definition: ioapi.h:94
char * central_header
Definition: zip.c:149
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
#define ZIP_ERRNO
Definition: zip.h:80
ZPOS64_T number_entry
Definition: zip.c:182
static int zip64FlushWriteBuffer(zip64_internal *zi)
Definition: zip.c:1403
#define ZIP_PARAMERROR
Definition: zip.h:81
uLong flag
Definition: zip.c:153
curfile64_info ci
Definition: zip.c:178
#define ZIP_SEQUENTIAL
Definition: zip.h:87
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:201
uLong size_centralheader
Definition: zip.c:151
static int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
Definition: zip.c:234
ZPOS64_T totalUncompressedData
Definition: zip.c:164
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:111
int zip64
Definition: zip.c:161
int method
Definition: zip.c:155
static int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:296
ZPOS64_T pos_local_header
Definition: zip.c:147

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

zipFile ZEXPORT zipOpen ( voidpf  file,
int  append 
)

Definition at line 967 of file zip.c.

References ZIP_DEFAULT_FLAGS, and zipOpen3().

968 {
969  return zipOpen3(file,append,NULL,NULL, ZIP_DEFAULT_FLAGS);
970 }
#define ZIP_DEFAULT_FLAGS
Definition: zip.h:88
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862

+ Here is the call graph for this function:

zipFile ZEXPORT zipOpen2 ( voidpf  file,
int  append,
zipcharpc globalcomment,
zlib_filefunc_def pzlib_filefunc32_def 
)

Definition at line 939 of file zip.c.

References fill_zlib_filefunc64_32_def_from_filefunc32(), ZIP_DEFAULT_FLAGS, and zipOpen3().

Referenced by QuaZip::open().

940 {
941  if (pzlib_filefunc32_def != NULL)
942  {
943  zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
944  fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
945  return zipOpen3(file, append, globalcomment, &zlib_filefunc64_32_def_fill, ZIP_DEFAULT_FLAGS);
946  }
947  else
948  return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
949 }
#define ZIP_DEFAULT_FLAGS
Definition: zip.h:88
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
Definition: qioapi.cpp:346
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

zipFile ZEXPORT zipOpen2_64 ( voidpf  file,
int  append,
zipcharpc globalcomment,
zlib_filefunc64_def pzlib_filefunc_def 
)

Definition at line 951 of file zip.c.

References zlib_filefunc64_32_def_s::zfile_func64, ZIP_DEFAULT_FLAGS, zipOpen3(), zlib_filefunc64_32_def_s::zseek32_file, and zlib_filefunc64_32_def_s::ztell32_file.

952 {
953  if (pzlib_filefunc_def != NULL)
954  {
955  zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
956  zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
957  zlib_filefunc64_32_def_fill.ztell32_file = NULL;
958  zlib_filefunc64_32_def_fill.zseek32_file = NULL;
959  return zipOpen3(file, append, globalcomment, &zlib_filefunc64_32_def_fill, ZIP_DEFAULT_FLAGS);
960  }
961  else
962  return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
963 }
#define ZIP_DEFAULT_FLAGS
Definition: zip.h:88
zlib_filefunc64_def zfile_func64
Definition: ioapi.h:178
tell_file_func ztell32_file
Definition: ioapi.h:180
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862
seek_file_func zseek32_file
Definition: ioapi.h:181

+ Here is the call graph for this function:

zipFile ZEXPORT zipOpen3 ( voidpf  file,
int  append,
zipcharpc globalcomment,
zlib_filefunc64_32_def pzlib_filefunc64_32_def,
unsigned  flags 
)

Definition at line 862 of file zip.c.

References zip64_internal::add_position_when_writting_offset, ALLOC, APPEND_STATUS_ADDINZIP, APPEND_STATUS_CREATE, APPEND_STATUS_CREATEAFTER, zip64_internal::begin_pos, zip64_internal::central_dir, zip64_internal::ci, zip64_internal::filestream, fill_qiodevice64_filefunc(), zip64_internal::flags, zip64_internal::globalcomment, zip64_internal::in_opened_file_inzip, init_linkedlist(), LoadCentralDirectoryRecord(), zip64_internal::number_entry, SEEK_END, curfile64_info::stream_initialised, TRYFREE, zip64_internal::z_filefunc, ZCLOSE64, ZFAKECLOSE64, zlib_filefunc64_32_def_s::zfile_func64, ZIP_AUTO_CLOSE, ZIP_OK, ZLIB_FILEFUNC_MODE_CREATE, ZLIB_FILEFUNC_MODE_EXISTING, ZLIB_FILEFUNC_MODE_READ, ZLIB_FILEFUNC_MODE_WRITE, ZOPEN64, zlib_filefunc64_32_def_s::zseek32_file, ZSEEK64, zlib_filefunc64_32_def_s::ztell32_file, and ZTELL64.

Referenced by QuaZip::open(), zipOpen(), zipOpen2(), zipOpen2_64(), and zipOpen64().

864 {
865  zip64_internal ziinit;
866  zip64_internal* zi;
867  int err=ZIP_OK;
868 
869  ziinit.flags = flags;
870  ziinit.z_filefunc.zseek32_file = NULL;
871  ziinit.z_filefunc.ztell32_file = NULL;
872  if (pzlib_filefunc64_32_def==NULL)
874  else
875  ziinit.z_filefunc = *pzlib_filefunc64_32_def;
876 
877  ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
878  file,
879  (append == APPEND_STATUS_CREATE) ?
882 
883  if (ziinit.filestream == NULL)
884  return NULL;
885 
886  if (append == APPEND_STATUS_CREATEAFTER)
887  ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
888 
889  ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
890  ziinit.in_opened_file_inzip = 0;
891  ziinit.ci.stream_initialised = 0;
892  ziinit.number_entry = 0;
894  init_linkedlist(&(ziinit.central_dir));
895 
896 
897 
898  zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
899  if (zi==NULL)
900  {
901  if ((ziinit.flags & ZIP_AUTO_CLOSE) != 0) {
902  ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
903  } else {
904  ZFAKECLOSE64(ziinit.z_filefunc,ziinit.filestream);
905  }
906  return NULL;
907  }
908 
909  /* now we add file in a zipfile */
910 # ifndef NO_ADDFILEINEXISTINGZIP
911  ziinit.globalcomment = NULL;
912  if (append == APPEND_STATUS_ADDINZIP)
913  {
914  /* Read and Cache Central Directory Records */
915  err = LoadCentralDirectoryRecord(&ziinit);
916  }
917 
918  if (globalcomment)
919  {
920  *globalcomment = ziinit.globalcomment;
921  }
922 # endif /* !NO_ADDFILEINEXISTINGZIP*/
923 
924  if (err != ZIP_OK)
925  {
926 # ifndef NO_ADDFILEINEXISTINGZIP
927  TRYFREE(ziinit.globalcomment);
928 # endif /* !NO_ADDFILEINEXISTINGZIP*/
929  TRYFREE(zi);
930  return NULL;
931  }
932  else
933  {
934  *zi = ziinit;
935  return (zipFile)zi;
936  }
937 }
#define ZIP_OK
Definition: zip.h:78
char * globalcomment
Definition: zip.c:185
void fill_qiodevice64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: qioapi.cpp:331
#define APPEND_STATUS_CREATEAFTER
Definition: zip.h:124
#define ZLIB_FILEFUNC_MODE_READ
Definition: ioapi.h:113
int stream_initialised
Definition: zip.c:144
zlib_filefunc64_def zfile_func64
Definition: ioapi.h:178
tell_file_func ztell32_file
Definition: ioapi.h:180
int in_opened_file_inzip
Definition: zip.c:177
voidp zipFile
Definition: zip.h:75
voidpf filestream
Definition: zip.c:175
unsigned flags
Definition: zip.c:188
#define ZCLOSE64(filefunc, filestream)
Definition: ioapi.h:189
#define ZFAKECLOSE64(filefunc, filestream)
Definition: ioapi.h:190
#define SEEK_END
Definition: zip.c:90
#define ZOPEN64(filefunc, filename, mode)
Definition: ioapi.h:199
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
int LoadCentralDirectoryRecord(zip64_internal *pziinit)
Definition: zip.c:649
linkedlist_data central_dir
Definition: zip.c:176
#define TRYFREE(p)
Definition: zip.c:71
#define ZIP_AUTO_CLOSE
Definition: zip.h:86
#define ZLIB_FILEFUNC_MODE_CREATE
Definition: ioapi.h:118
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition: ioapi.h:117
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
static void init_linkedlist(linkedlist_data *ll)
Definition: zip.c:222
ZPOS64_T number_entry
Definition: zip.c:182
seek_file_func zseek32_file
Definition: ioapi.h:181
#define ALLOC(size)
Definition: zip.c:68
curfile64_info ci
Definition: zip.c:178
#define ZLIB_FILEFUNC_MODE_WRITE
Definition: ioapi.h:114
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:201
ZPOS64_T begin_pos
Definition: zip.c:180
#define APPEND_STATUS_ADDINZIP
Definition: zip.h:125
#define APPEND_STATUS_CREATE
Definition: zip.h:123

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

zipFile ZEXPORT zipOpen64 ( voidpf  file,
int  append 
)

Definition at line 972 of file zip.c.

References ZIP_DEFAULT_FLAGS, and zipOpen3().

973 {
974  return zipOpen3(file,append,NULL,NULL, ZIP_DEFAULT_FLAGS);
975 }
#define ZIP_DEFAULT_FLAGS
Definition: zip.h:88
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862

+ Here is the call graph for this function:

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 
)

Definition at line 1390 of file zip.c.

References DEF_MEM_LEVEL, VERSIONMADEBY, and zipOpenNewFileInZip4_64().

1394 {
1395  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1396  extrafield_local, size_extrafield_local,
1397  extrafield_global, size_extrafield_global,
1398  comment, method, level, 0,
1399  -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1400  NULL, 0, VERSIONMADEBY, 0, 0);
1401 }
#define DEF_MEM_LEVEL
Definition: zip.h:94
#define VERSIONMADEBY
Definition: zip.c:56
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

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 
)

Definition at line 1351 of file zip.c.

References DEF_MEM_LEVEL, VERSIONMADEBY, and zipOpenNewFileInZip4_64().

1355 {
1356  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1357  extrafield_local, size_extrafield_local,
1358  extrafield_global, size_extrafield_global,
1359  comment, method, level, raw,
1360  -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1361  NULL, 0, VERSIONMADEBY, 0, 0);
1362 }
#define DEF_MEM_LEVEL
Definition: zip.h:94
#define VERSIONMADEBY
Definition: zip.c:56
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

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 
)

Definition at line 1364 of file zip.c.

References DEF_MEM_LEVEL, VERSIONMADEBY, and zipOpenNewFileInZip4_64().

1368 {
1369  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1370  extrafield_local, size_extrafield_local,
1371  extrafield_global, size_extrafield_global,
1372  comment, method, level, raw,
1373  -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1374  NULL, 0, VERSIONMADEBY, 0, zip64);
1375 }
#define DEF_MEM_LEVEL
Definition: zip.h:94
#define VERSIONMADEBY
Definition: zip.c:56
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

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 
)

Definition at line 1321 of file zip.c.

References VERSIONMADEBY, and zipOpenNewFileInZip4_64().

1327 {
1328  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1329  extrafield_local, size_extrafield_local,
1330  extrafield_global, size_extrafield_global,
1331  comment, method, level, raw,
1332  windowBits, memLevel, strategy,
1333  password, crcForCrypting, VERSIONMADEBY, 0, 0);
1334 }
#define VERSIONMADEBY
Definition: zip.c:56
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

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 
)

Definition at line 1336 of file zip.c.

References VERSIONMADEBY, and zipOpenNewFileInZip4_64().

Referenced by QuaZipFile::open().

1342 {
1343  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1344  extrafield_local, size_extrafield_local,
1345  extrafield_global, size_extrafield_global,
1346  comment, method, level, raw,
1347  windowBits, memLevel, strategy,
1348  password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1349 }
#define VERSIONMADEBY
Definition: zip.c:56
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)

Definition at line 1305 of file zip.c.

References zipOpenNewFileInZip4_64().

1312 {
1313  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1314  extrafield_local, size_extrafield_local,
1315  extrafield_global, size_extrafield_global,
1316  comment, method, level, raw,
1317  windowBits, memLevel, strategy,
1318  password, crcForCrypting, versionMadeBy, flagBase, 0);
1319 }
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

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 
)

Definition at line 1077 of file zip.c.

References zip64_internal::add_position_when_writting_offset, ALLOC, curfile64_info::buffered_data, curfile64_info::central_header, CENTRALHEADERMAGIC, zip64_internal::ci, curfile64_info::crc32, curfile64_info::crypt_header_size, zip_fileinfo::dosDate, curfile64_info::dosDate, curfile64_info::encrypt, zip_fileinfo::external_fa, zip64_internal::filestream, curfile64_info::flag, zip64_internal::flags, zip64_internal::in_opened_file_inzip, zip_fileinfo::internal_fa, curfile64_info::keys, curfile64_info::method, curfile64_info::pcrc_32_tab, curfile64_info::pos_in_buffered_data, curfile64_info::pos_local_header, curfile64_info::pos_zip64extrainfo, curfile64_info::raw, curfile64_info::size_centralExtra, curfile64_info::size_centralExtraFree, curfile64_info::size_centralheader, SIZECENTRALHEADER, curfile64_info::stream, curfile64_info::stream_initialised, zip_fileinfo::tmz_date, curfile64_info::totalCompressedData, curfile64_info::totalUncompressedData, Write_LocalFileHeader(), Z_BUFSIZE, Z_BZIP2ED, zip64_internal::z_filefunc, curfile64_info::zip64, zip64local_putValue_inmemory(), zip64local_TmzDateToDosDate(), ZIP_ERRNO, ZIP_INTERNALERROR, ZIP_OK, ZIP_PARAMERROR, ZIP_SEQUENTIAL, ZIP_WRITE_DATA_DESCRIPTOR, zipCloseFileInZip(), ZTELL64, and ZWRITE64.

Referenced by zipOpenNewFileInZip(), zipOpenNewFileInZip2(), zipOpenNewFileInZip2_64(), zipOpenNewFileInZip3(), zipOpenNewFileInZip3_64(), zipOpenNewFileInZip4(), and zipOpenNewFileInZip64().

1084 {
1085  zip64_internal* zi;
1086  uInt size_filename;
1087  uInt size_comment;
1088  uInt i;
1089  int err = ZIP_OK;
1090  uLong version_to_extract;
1091 
1092 # ifdef NOCRYPT
1093  if (password != NULL)
1094  return ZIP_PARAMERROR;
1095 # endif
1096 
1097  if (file == NULL)
1098  return ZIP_PARAMERROR;
1099 
1100 #ifdef HAVE_BZIP2
1101  if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
1102  return ZIP_PARAMERROR;
1103 #else
1104  if ((method!=0) && (method!=Z_DEFLATED))
1105  return ZIP_PARAMERROR;
1106 #endif
1107 
1108  zi = (zip64_internal*)file;
1109 
1110  if (zi->in_opened_file_inzip == 1)
1111  {
1112  err = zipCloseFileInZip (file);
1113  if (err != ZIP_OK)
1114  return err;
1115  }
1116 
1117  if (method == 0
1118  && (level == 0 || (zi->flags & ZIP_WRITE_DATA_DESCRIPTOR) == 0)
1119  && (zi->flags & ZIP_SEQUENTIAL) == 0)
1120  {
1121  version_to_extract = 10;
1122  }
1123  else
1124  {
1125  version_to_extract = 20;
1126  }
1127 
1128  if (filename==NULL)
1129  filename="-";
1130 
1131  if (comment==NULL)
1132  size_comment = 0;
1133  else
1134  size_comment = (uInt)strlen(comment);
1135 
1136  size_filename = (uInt)strlen(filename);
1137 
1138  if (zipfi == NULL)
1139  zi->ci.dosDate = 0;
1140  else
1141  {
1142  if (zipfi->dosDate != 0)
1143  zi->ci.dosDate = zipfi->dosDate;
1144  else
1146  }
1147 
1148  zi->ci.flag = flagBase;
1149  if ((level==8) || (level==9))
1150  zi->ci.flag |= 2;
1151  if (level==2)
1152  zi->ci.flag |= 4;
1153  if (level==1)
1154  zi->ci.flag |= 6;
1155  if (password != NULL)
1156  zi->ci.flag |= 1;
1157  if (version_to_extract >= 20
1158  && ((zi->flags & ZIP_WRITE_DATA_DESCRIPTOR) != 0
1159  || (zi->flags & ZIP_SEQUENTIAL) != 0))
1160  zi->ci.flag |= 8;
1161 
1162  zi->ci.crc32 = 0;
1163  zi->ci.method = method;
1164  zi->ci.encrypt = 0;
1165  zi->ci.stream_initialised = 0;
1166  zi->ci.pos_in_buffered_data = 0;
1167  zi->ci.raw = raw;
1169 
1170  zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
1171  zi->ci.size_centralExtraFree = 32; /* Extra space we have reserved in case we need to add ZIP64 extra info data */
1172 
1173  zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
1174 
1175  zi->ci.size_centralExtra = size_extrafield_global;
1177  /* version info */
1178  zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
1179  zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)version_to_extract,2);
1183  zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
1184  zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
1185  zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
1186  zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
1187  zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
1188  zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
1189  zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
1190 
1191  if (zipfi==NULL)
1192  zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
1193  else
1195 
1196  if (zipfi==NULL)
1197  zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
1198  else
1200 
1201  if(zi->ci.pos_local_header >= 0xffffffff)
1202  zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
1203  else
1205 
1206  for (i=0;i<size_filename;i++)
1207  *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
1208 
1209  for (i=0;i<size_extrafield_global;i++)
1210  *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
1211  *(((const char*)extrafield_global)+i);
1212 
1213  for (i=0;i<size_comment;i++)
1214  *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
1215  size_extrafield_global+i) = *(comment+i);
1216  if (zi->ci.central_header == NULL)
1217  return ZIP_INTERNALERROR;
1218 
1219  zi->ci.zip64 = zip64;
1220  zi->ci.totalCompressedData = 0;
1221  zi->ci.totalUncompressedData = 0;
1222  zi->ci.pos_zip64extrainfo = 0;
1223 
1224  err = Write_LocalFileHeader(zi, filename, size_extrafield_local,
1225  extrafield_local, version_to_extract);
1226 
1227 #ifdef HAVE_BZIP2
1228  zi->ci.bstream.avail_in = (uInt)0;
1229  zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1230  zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1231  zi->ci.bstream.total_in_hi32 = 0;
1232  zi->ci.bstream.total_in_lo32 = 0;
1233  zi->ci.bstream.total_out_hi32 = 0;
1234  zi->ci.bstream.total_out_lo32 = 0;
1235 #endif
1236 
1237  zi->ci.stream.avail_in = (uInt)0;
1238  zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1239  zi->ci.stream.next_out = zi->ci.buffered_data;
1240  zi->ci.stream.total_in = 0;
1241  zi->ci.stream.total_out = 0;
1242  zi->ci.stream.data_type = Z_BINARY;
1243 
1244 #ifdef HAVE_BZIP2
1245  if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1246 #else
1247  if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1248 #endif
1249  {
1250  if(zi->ci.method == Z_DEFLATED)
1251  {
1252  zi->ci.stream.zalloc = (alloc_func)0;
1253  zi->ci.stream.zfree = (free_func)0;
1254  zi->ci.stream.opaque = (voidpf)0;
1255 
1256  if (windowBits>0)
1257  windowBits = -windowBits;
1258 
1259  err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
1260 
1261  if (err==Z_OK)
1262  zi->ci.stream_initialised = Z_DEFLATED;
1263  }
1264  else if(zi->ci.method == Z_BZIP2ED)
1265  {
1266 #ifdef HAVE_BZIP2
1267  /* Init BZip stuff here */
1268  zi->ci.bstream.bzalloc = 0;
1269  zi->ci.bstream.bzfree = 0;
1270  zi->ci.bstream.opaque = (voidpf)0;
1271 
1272  err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
1273  if(err == BZ_OK)
1275 #endif
1276  }
1277 
1278  }
1279 
1280 # ifndef NOCRYPT
1281  zi->ci.crypt_header_size = 0;
1282  if ((err==Z_OK) && (password != NULL))
1283  {
1284  unsigned char bufHead[RAND_HEAD_LEN];
1285  unsigned int sizeHead;
1286  zi->ci.encrypt = 1;
1287  zi->ci.pcrc_32_tab = get_crc_table();
1288  /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
1289  if (crcForCrypting == 0) {
1290  crcForCrypting = (uLong)zi->ci.dosDate << 16; /* ATTANTION! Without this row, you don't unpack your password protected archive in other app. */
1291  }
1292  sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
1293  zi->ci.crypt_header_size = sizeHead;
1294 
1295  if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
1296  err = ZIP_ERRNO;
1297  }
1298 # endif
1299 
1300  if (err==Z_OK)
1301  zi->in_opened_file_inzip = 1;
1302  return err;
1303 }
#define ZIP_OK
Definition: zip.h:78
static void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte)
Definition: zip.c:320
tm_zip tmz_date
Definition: zip.h:112
Byte buffered_data[(64 *1024)]
Definition: zip.c:157
#define ZIP_WRITE_DATA_DESCRIPTOR
Definition: zip.h:85
#define ZIP_INTERNALERROR
Definition: zip.h:83
uLong external_fa
Definition: zip.h:117
int raw
Definition: zip.c:156
#define SIZECENTRALHEADER
Definition: zip.c:119
unsigned long keys[3]
Definition: zip.c:166
ZPOS64_T pos_zip64extrainfo
Definition: zip.c:162
ZPOS64_T totalCompressedData
Definition: zip.c:163
int stream_initialised
Definition: zip.c:144
int crypt_header_size
Definition: zip.c:168
uLong size_centralExtraFree
Definition: zip.c:152
int in_opened_file_inzip
Definition: zip.c:177
uInt pos_in_buffered_data
Definition: zip.c:145
voidpf filestream
Definition: zip.c:175
#define Z_BZIP2ED
Definition: unzip.h:67
unsigned flags
Definition: zip.c:188
const z_crc_t FAR * pcrc_32_tab
Definition: zip.c:167
int encrypt
Definition: zip.c:160
ZPOS64_T add_position_when_writting_offset
Definition: zip.c:181
uLong dosDate
Definition: zip.h:113
static uLong zip64local_TmzDateToDosDate(const tm_zip *ptm)
Definition: zip.c:341
uLong crc32
Definition: zip.c:159
int Write_LocalFileHeader(zip64_internal *zi, const char *filename, uInt size_extrafield_local, const void *extrafield_local, uLong version_to_extract)
Definition: zip.c:977
#define Z_BUFSIZE
Definition: zip.c:60
uLong size_centralExtra
Definition: zip.c:150
z_stream stream
Definition: zip.c:139
char * central_header
Definition: zip.c:149
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:174
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:200
#define ZIP_ERRNO
Definition: zip.h:80
uLong dosDate
Definition: zip.c:158
#define ZIP_PARAMERROR
Definition: zip.h:81
#define ALLOC(size)
Definition: zip.c:68
uLong flag
Definition: zip.c:153
curfile64_info ci
Definition: zip.c:178
#define ZIP_SEQUENTIAL
Definition: zip.h:87
uLong internal_fa
Definition: zip.h:116
int ZEXPORT zipCloseFileInZip(zipFile file)
Definition: zip.c:1810
uLong size_centralheader
Definition: zip.c:151
ZPOS64_T totalUncompressedData
Definition: zip.c:164
int zip64
Definition: zip.c:161
int method
Definition: zip.c:155
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:186
#define CENTRALHEADERMAGIC
Definition: zip.c:111
ZPOS64_T pos_local_header
Definition: zip.c:147

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)

Definition at line 1377 of file zip.c.

References DEF_MEM_LEVEL, VERSIONMADEBY, and zipOpenNewFileInZip4_64().

1381 {
1382  return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1383  extrafield_local, size_extrafield_local,
1384  extrafield_global, size_extrafield_global,
1385  comment, method, level, 0,
1386  -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1387  NULL, 0, VERSIONMADEBY, 0, zip64);
1388 }
#define DEF_MEM_LEVEL
Definition: zip.h:94
#define VERSIONMADEBY
Definition: zip.c:56
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)
Definition: zip.c:1077

+ Here is the call graph for this function:

int ZEXPORT zipRemoveExtraInfoBlock ( char *  pData,
int *  dataLen,
short  sHeader 
)

Definition at line 2019 of file zip.c.

References ALLOC, TRYFREE, ZIP_ERRNO, ZIP_OK, and ZIP_PARAMERROR.

2020 {
2021  char* p = pData;
2022  int size = 0;
2023  char* pNewHeader;
2024  char* pTmp;
2025  short header;
2026  short dataSize;
2027 
2028  int retVal = ZIP_OK;
2029 
2030  if(pData == NULL || *dataLen < 4)
2031  return ZIP_PARAMERROR;
2032 
2033  pNewHeader = (char*)ALLOC(*dataLen);
2034  pTmp = pNewHeader;
2035 
2036  while(p < (pData + *dataLen))
2037  {
2038  header = *(short*)p;
2039  dataSize = *(((short*)p)+1);
2040 
2041  if( header == sHeader ) /* Header found. */
2042  {
2043  p += dataSize + 4; /* skip it. do not copy to temp buffer */
2044  }
2045  else
2046  {
2047  /* Extra Info block should not be removed, So copy it to the temp buffer. */
2048  memcpy(pTmp, p, dataSize + 4);
2049  p += dataSize + 4;
2050  size += dataSize + 4;
2051  }
2052 
2053  }
2054 
2055  if(size < *dataLen)
2056  {
2057  /* clean old extra info block. */
2058  memset(pData,0, *dataLen);
2059 
2060  /* copy the new extra info block over the old */
2061  if(size > 0)
2062  memcpy(pData, pNewHeader, size);
2063 
2064  /* set the new extra info size */
2065  *dataLen = size;
2066 
2067  retVal = ZIP_OK;
2068  }
2069  else
2070  retVal = ZIP_ERRNO;
2071 
2072  TRYFREE(pNewHeader);
2073 
2074  return retVal;
2075 }
#define ZIP_OK
Definition: zip.h:78
#define TRYFREE(p)
Definition: zip.c:71
#define ZIP_ERRNO
Definition: zip.h:80
#define ZIP_PARAMERROR
Definition: zip.h:81
#define ALLOC(size)
Definition: zip.c:68
int ZEXPORT zipSetFlags ( zipFile  file,
unsigned  flags 
)

Definition at line 2077 of file zip.c.

References zip64_internal::flags, ZIP_OK, ZIP_PARAMERROR, ZIP_SEQUENTIAL, and ZIP_WRITE_DATA_DESCRIPTOR.

Referenced by QuaZip::open(), and QuaZipFile::open().

2078 {
2079  zip64_internal* zi;
2080  if (file == NULL)
2081  return ZIP_PARAMERROR;
2082  zi = (zip64_internal*)file;
2083  zi->flags |= flags;
2084  // If the output is non-seekable, the data descriptor is needed.
2085  if ((zi->flags & ZIP_SEQUENTIAL) != 0) {
2087  }
2088  return ZIP_OK;
2089 }
#define ZIP_OK
Definition: zip.h:78
#define ZIP_WRITE_DATA_DESCRIPTOR
Definition: zip.h:85
unsigned flags
Definition: zip.c:188
#define ZIP_PARAMERROR
Definition: zip.h:81
#define ZIP_SEQUENTIAL
Definition: zip.h:87

+ Here is the caller graph for this function:

int ZEXPORT zipWriteInFileInZip ( zipFile  file,
const void *  buf,
unsigned int  len 
)

Definition at line 1442 of file zip.c.

References curfile64_info::buffered_data, zip64_internal::ci, curfile64_info::crc32, zip64_internal::in_opened_file_inzip, curfile64_info::method, curfile64_info::pos_in_buffered_data, curfile64_info::raw, curfile64_info::stream, Z_BUFSIZE, Z_BZIP2ED, zip64FlushWriteBuffer(), ZIP_ERRNO, ZIP_OK, and ZIP_PARAMERROR.

Referenced by QuaZipFile::writeData().

1443 {
1444  zip64_internal* zi;
1445  int err=ZIP_OK;
1446 
1447  if (file == NULL)
1448  return ZIP_PARAMERROR;
1449  zi = (zip64_internal*)file;
1450 
1451  if (zi->in_opened_file_inzip == 0)
1452  return ZIP_PARAMERROR;
1453 
1454  zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
1455 
1456 #ifdef HAVE_BZIP2
1457  if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
1458  {
1459  zi->ci.bstream.next_in = (void*)buf;
1460  zi->ci.bstream.avail_in = len;
1461  err = BZ_RUN_OK;
1462 
1463  while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
1464  {
1465  if (zi->ci.bstream.avail_out == 0)
1466  {
1467  if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1468  err = ZIP_ERRNO;
1469  zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1470  zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1471  }
1472 
1473 
1474  if(err != BZ_RUN_OK)
1475  break;
1476 
1477  if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1478  {
1479  uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1480 /* uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; */
1481  err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1482 
1483  zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
1484  }
1485  }
1486 
1487  if(err == BZ_RUN_OK)
1488  err = ZIP_OK;
1489  }
1490  else
1491 #endif
1492  {
1493  zi->ci.stream.next_in = (Bytef*)buf;
1494  zi->ci.stream.avail_in = len;
1495 
1496  while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1497  {
1498  if (zi->ci.stream.avail_out == 0)
1499  {
1500  if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1501  err = ZIP_ERRNO;
1502  zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1503  zi->ci.stream.next_out = zi->ci.buffered_data;
1504  }
1505 
1506 
1507  if(err != ZIP_OK)
1508  break;
1509 
1510  if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1511  {
1512  uLong uTotalOutBefore = zi->ci.stream.total_out;
1513  err=deflate(&zi->ci.stream, Z_NO_FLUSH);
1514  if(uTotalOutBefore > zi->ci.stream.total_out)
1515  {
1516  int bBreak = 0;
1517  bBreak++;
1518  }
1519 
1520  zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1521  }
1522  else
1523  {
1524  uInt copy_this,i;
1525  if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1526  copy_this = zi->ci.stream.avail_in;
1527  else
1528  copy_this = zi->ci.stream.avail_out;
1529 
1530  for (i = 0; i < copy_this; i++)
1531  *(((char*)zi->ci.stream.next_out)+i) =
1532  *(((const char*)zi->ci.stream.next_in)+i);
1533  {
1534  zi->ci.stream.avail_in -= copy_this;
1535  zi->ci.stream.avail_out-= copy_this;
1536  zi->ci.stream.next_in+= copy_this;
1537  zi->ci.stream.next_out+= copy_this;
1538  zi->ci.stream.total_in+= copy_this;
1539  zi->ci.stream.total_out+= copy_this;
1540  zi->ci.pos_in_buffered_data += copy_this;
1541  }
1542  }
1543  }/* while(...) */
1544  }
1545 
1546  return err;
1547 }
#define ZIP_OK
Definition: zip.h:78
Byte buffered_data[(64 *1024)]
Definition: zip.c:157
int raw
Definition: zip.c:156
int in_opened_file_inzip
Definition: zip.c:177
uInt pos_in_buffered_data
Definition: zip.c:145
#define Z_BZIP2ED
Definition: unzip.h:67
uLong crc32
Definition: zip.c:159
#define Z_BUFSIZE
Definition: zip.c:60
z_stream stream
Definition: zip.c:139
#define ZIP_ERRNO
Definition: zip.h:80
static int zip64FlushWriteBuffer(zip64_internal *zi)
Definition: zip.c:1403
#define ZIP_PARAMERROR
Definition: zip.h:81
curfile64_info ci
Definition: zip.c:178
int method
Definition: zip.c:155

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"

Definition at line 104 of file zip.c.