ReactOS 0.4.15-dev-7906-g1b85a5f
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.

Classes

struct  linkedlist_datablock_internal_s
 
struct  linkedlist_data_s
 
struct  curfile64_info
 
struct  zip64_internal
 

Macros

#define local   static
 
#define VERSIONMADEBY   (0x0) /* platform depedent */
 
#define Z_BUFSIZE   (64*1024)
 
#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 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 struct linkedlist_datablock_internal_s linkedlist_datablock_internal
 
typedef struct linkedlist_data_s linkedlist_data
 

Functions

linkedlist_datablock_internalallocate_new_datablock ()
 
void free_datablock (linkedlist_datablock_internal *ldi)
 
void init_linkedlist (linkedlist_data *ll)
 
void free_linkedlist (linkedlist_data *ll)
 
int add_data_in_datablock (linkedlist_data *ll, const void *buf, uLong len)
 
int zip64local_putValue OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte))
 
int zip64local_putValue (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
 
void zip64local_putValue_inmemory OF ((void *dest, ZPOS64_T x, int nbByte))
 
void zip64local_putValue_inmemory (void *dest, ZPOS64_T x, int nbByte)
 
uLong zip64local_TmzDateToDosDate (const tm_zip *ptm)
 
int zip64local_getByte OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi))
 
int zip64local_getByte (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
 
int zip64local_getShort OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX))
 
int zip64local_getShort (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
 
int zip64local_getLong (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
 
int zip64local_getLong64 OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX))
 
int zip64local_getLong64 (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
 
ZPOS64_T zip64local_SearchCentralDir OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream))
 
ZPOS64_T zip64local_SearchCentralDir (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
 
ZPOS64_T zip64local_SearchCentralDir64 (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
 
int LoadCentralDirectoryRecord (zip64_internal *pziinit)
 
zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def)
 
zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc32_def)
 
zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
 
zipFile ZEXPORT zipOpen (const char *pathname, int append)
 
zipFile ZEXPORT zipOpen64 (const void *pathname, int append)
 
int Write_LocalFileHeader (zip64_internal *zi, const char *filename, uInt size_extrafield_local, const void *extrafield_local)
 
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)
 
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)
 

Variables

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

Macro Definition Documentation

◆ ALLOC

#define ALLOC (   size)    (malloc(size))

Definition at line 62 of file zip.c.

◆ BUFREADCOMMENT

#define BUFREADCOMMENT   (0x400)

Definition at line 472 of file zip.c.

◆ CENTRALHEADERMAGIC

#define CENTRALHEADERMAGIC   (0x02014b50)

Definition at line 104 of file zip.c.

◆ CRC_LOCALHEADER_OFFSET

#define CRC_LOCALHEADER_OFFSET   (0x0e)

Definition at line 110 of file zip.c.

◆ ENDHEADERMAGIC

#define ENDHEADERMAGIC   (0x06054b50)

Definition at line 105 of file zip.c.

◆ FLAG_LOCALHEADER_OFFSET

#define FLAG_LOCALHEADER_OFFSET   (0x06)

Definition at line 109 of file zip.c.

◆ INCLUDECRYPTINGCODE_IFCRYPTALLOWED

#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED

Definition at line 185 of file zip.c.

◆ local

#define local   static

Definition at line 45 of file zip.c.

◆ LOCALHEADERMAGIC

#define LOCALHEADERMAGIC   (0x04034b50)

Definition at line 103 of file zip.c.

◆ MAKEULONG64

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

Definition at line 77 of file zip.c.

◆ SEEK_CUR

#define SEEK_CUR   1

Definition at line 80 of file zip.c.

◆ SEEK_END

#define SEEK_END   2

Definition at line 84 of file zip.c.

◆ SEEK_SET

#define SEEK_SET   0

Definition at line 88 of file zip.c.

◆ SIZECENTRALHEADER

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

Definition at line 112 of file zip.c.

◆ SIZEDATA_INDATABLOCK

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

Definition at line 101 of file zip.c.

◆ TRYFREE

#define TRYFREE (   p)    {if (p) free(p);}

Definition at line 65 of file zip.c.

◆ VERSIONMADEBY

#define VERSIONMADEBY   (0x0) /* platform depedent */

Definition at line 50 of file zip.c.

◆ Z_BUFSIZE

#define Z_BUFSIZE   (64*1024)

Definition at line 54 of file zip.c.

◆ Z_MAXFILENAMEINZIP

#define Z_MAXFILENAMEINZIP   (256)

Definition at line 58 of file zip.c.

◆ ZIP64ENDHEADERMAGIC

#define ZIP64ENDHEADERMAGIC   (0x6064b50)

Definition at line 106 of file zip.c.

◆ ZIP64ENDLOCHEADERMAGIC

#define ZIP64ENDLOCHEADERMAGIC   (0x7064b50)

Definition at line 107 of file zip.c.

Typedef Documentation

◆ linkedlist_data

◆ linkedlist_datablock_internal

Function Documentation

◆ add_data_in_datablock()

int add_data_in_datablock ( linkedlist_data ll,
const void buf,
uLong  len 
)

Definition at line 225 of file zip.c.

226{
228 const unsigned char* from_copy;
229
230 if (ll==NULL)
231 return ZIP_INTERNALERROR;
232
233 if (ll->last_block == NULL)
234 {
235 ll->first_block = ll->last_block = allocate_new_datablock();
236 if (ll->first_block == NULL)
237 return ZIP_INTERNALERROR;
238 }
239
240 ldi = ll->last_block;
241 from_copy = (unsigned char*)buf;
242
243 while (len>0)
244 {
245 uInt copy_this;
246 uInt i;
247 unsigned char* to_copy;
248
249 if (ldi->avail_in_this_block==0)
250 {
252 if (ldi->next_datablock == NULL)
253 return ZIP_INTERNALERROR;
254 ldi = ldi->next_datablock ;
255 ll->last_block = ldi;
256 }
257
258 if (ldi->avail_in_this_block < len)
259 copy_this = (uInt)ldi->avail_in_this_block;
260 else
261 copy_this = (uInt)len;
262
263 to_copy = &(ldi->data[ldi->filled_in_this_block]);
264
265 for (i=0;i<copy_this;i++)
266 *(to_copy+i)=*(from_copy+i);
267
268 ldi->filled_in_this_block += copy_this;
269 ldi->avail_in_this_block -= copy_this;
270 from_copy += copy_this ;
271 len -= copy_this;
272 }
273 return ZIP_OK;
274}
w ll
Definition: byte_order.h:167
#define NULL
Definition: types.h:112
unsigned int uInt
Definition: zlib.h:38
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char data[SIZEDATA_INDATABLOCK]
Definition: zip.c:120
struct linkedlist_datablock_internal_s * next_datablock
Definition: zip.c:116
linkedlist_datablock_internal * allocate_new_datablock()
Definition: zip.c:189
#define ZIP_OK
Definition: zip.h:72
#define ZIP_INTERNALERROR
Definition: zip.h:77

Referenced by LoadCentralDirectoryRecord(), and zipCloseFileInZipRaw64().

◆ allocate_new_datablock()

linkedlist_datablock_internal * allocate_new_datablock ( )

Definition at line 189 of file zip.c.

190{
194 if (ldi!=NULL)
195 {
196 ldi->next_datablock = NULL ;
197 ldi->filled_in_this_block = 0 ;
199 }
200 return ldi;
201}
#define SIZEDATA_INDATABLOCK
Definition: zip.c:101
#define ALLOC(size)
Definition: zip.c:62

Referenced by add_data_in_datablock().

◆ free_datablock()

void free_datablock ( linkedlist_datablock_internal ldi)

Definition at line 203 of file zip.c.

204{
205 while (ldi!=NULL)
206 {
208 TRYFREE(ldi);
209 ldi = ldinext;
210 }
211}
#define TRYFREE(p)
Definition: zip.c:65

Referenced by free_linkedlist().

◆ free_linkedlist()

void free_linkedlist ( linkedlist_data ll)

Definition at line 218 of file zip.c.

219{
220 free_datablock(ll->first_block);
221 ll->first_block = ll->last_block = NULL;
222}
void free_datablock(linkedlist_datablock_internal *ldi)
Definition: zip.c:203

Referenced by zipClose().

◆ init_linkedlist()

void init_linkedlist ( linkedlist_data ll)

Definition at line 213 of file zip.c.

214{
215 ll->first_block = ll->last_block = NULL;
216}

Referenced by zipOpen3().

◆ LoadCentralDirectoryRecord()

int LoadCentralDirectoryRecord ( zip64_internal pziinit)

Definition at line 642 of file zip.c.

643{
644 int err=ZIP_OK;
645 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
646
647 ZPOS64_T size_central_dir; /* size of the central directory */
648 ZPOS64_T offset_central_dir; /* offset of start of central directory */
649 ZPOS64_T central_pos;
650 uLong uL;
651
652 uLong number_disk; /* number of the current dist, used for
653 spaning ZIP, unsupported, always 0*/
654 uLong number_disk_with_CD; /* number the the disk with central dir, used
655 for spaning ZIP, unsupported, always 0*/
656 ZPOS64_T number_entry;
657 ZPOS64_T number_entry_CD; /* total number of entries in
658 the central dir
659 (same than number_entry on nospan) */
660 uLong VersionMadeBy;
661 uLong VersionNeeded;
662 uLong size_comment;
663
664 int hasZIP64Record = 0;
665
666 // check first if we find a ZIP64 record
667 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
668 if(central_pos > 0)
669 {
670 hasZIP64Record = 1;
671 }
672 else if(central_pos == 0)
673 {
674 central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
675 }
676
677/* disable to allow appending to empty ZIP archive
678 if (central_pos==0)
679 err=ZIP_ERRNO;
680*/
681
682 if(hasZIP64Record)
683 {
684 ZPOS64_T sizeEndOfCentralDirectory;
685 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
687
688 /* the signature, already checked */
689 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
691
692 /* size of zip64 end of central directory record */
693 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
695
696 /* version made by */
697 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
699
700 /* version needed to extract */
701 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
703
704 /* number of this disk */
705 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
707
708 /* number of the disk with the start of the central directory */
709 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
711
712 /* total number of entries in the central directory on this disk */
713 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
715
716 /* total number of entries in the central directory */
717 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
719
720 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
722
723 /* size of the central directory */
724 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
726
727 /* offset of start of central directory with respect to the
728 starting disk number */
729 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
731
732 // TODO..
733 // read the comment from the standard central header.
734 size_comment = 0;
735 }
736 else
737 {
738 // Read End of central Directory info
739 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
741
742 /* the signature, already checked */
743 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
745
746 /* number of this disk */
747 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
749
750 /* number of the disk with the start of the central directory */
751 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
753
754 /* total number of entries in the central dir on this disk */
755 number_entry = 0;
756 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
758 else
759 number_entry = uL;
760
761 /* total number of entries in the central dir */
762 number_entry_CD = 0;
763 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
765 else
766 number_entry_CD = uL;
767
768 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
770
771 /* size of the central directory */
772 size_central_dir = 0;
773 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
775 else
776 size_central_dir = uL;
777
778 /* offset of start of central directory with respect to the starting disk number */
779 offset_central_dir = 0;
780 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
782 else
783 offset_central_dir = uL;
784
785
786 /* zipfile global comment length */
787 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
789 }
790
791 if ((central_pos<offset_central_dir+size_central_dir) &&
792 (err==ZIP_OK))
794
795 if (err!=ZIP_OK)
796 {
797 ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
798 return ZIP_ERRNO;
799 }
800
801 if (size_comment>0)
802 {
803 pziinit->globalcomment = (char*)ALLOC(size_comment+1);
804 if (pziinit->globalcomment)
805 {
806 size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
807 pziinit->globalcomment[size_comment]=0;
808 }
809 }
810
811 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
812 pziinit->add_position_when_writing_offset = byte_before_the_zipfile;
813
814 {
815 ZPOS64_T size_central_dir_to_read = size_central_dir;
816 size_t buf_size = SIZEDATA_INDATABLOCK;
817 void* buf_read = (void*)ALLOC(buf_size);
818 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
820
821 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
822 {
823 ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
824 if (read_this > size_central_dir_to_read)
825 read_this = size_central_dir_to_read;
826
827 if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
829
830 if (err==ZIP_OK)
831 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
832
833 size_central_dir_to_read-=read_this;
834 }
836 }
837 pziinit->begin_pos = byte_before_the_zipfile;
838 pziinit->number_entry = number_entry_CD;
839
840 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
842
843 return err;
844}
ssize_t buf_read(int, void *, size_t)
unsigned long uLong
Definition: zlib.h:39
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:204
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:116
#define ZREAD64(filefunc, filestream, buf, size)
Definition: ioapi.h:189
#define ZCLOSE64(filefunc, filestream)
Definition: ioapi.h:193
unsigned long long int ZPOS64_T
Definition: ioapi.h:99
#define err(...)
ZPOS64_T add_position_when_writing_offset
Definition: zip.c:174
ZPOS64_T number_entry
Definition: zip.c:175
voidpf filestream
Definition: zip.c:168
linkedlist_data central_dir
Definition: zip.c:169
char * globalcomment
Definition: zip.c:178
zlib_filefunc64_32_def z_filefunc
Definition: zip.c:167
ZPOS64_T begin_pos
Definition: zip.c:173
int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
Definition: zip.c:225
ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
Definition: zip.c:544
ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
Definition: zip.c:480
int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: zip.c:373
int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: zip.c:395
int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
Definition: zip.c:426
#define ZIP_ERRNO
Definition: zip.h:74
#define ZIP_BADZIPFILE
Definition: zip.h:76

Referenced by zipOpen3().

◆ OF() [1/6]

ZPOS64_T zip64local_SearchCentralDir OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)  )

◆ OF() [2/6]

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

◆ OF() [3/6]

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

◆ OF() [4/6]

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

◆ OF() [5/6]

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

◆ OF() [6/6]

◆ Write_EndOfCentralDirectoryRecord()

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

Definition at line 1817 of file zip.c.

1818{
1819 int err = ZIP_OK;
1820
1821 /*signature*/
1823
1824 if (err==ZIP_OK) /* number of this disk */
1826
1827 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1829
1830 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1831 {
1832 {
1833 if(zi->number_entry >= 0xFFFF)
1834 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
1835 else
1837 }
1838 }
1839
1840 if (err==ZIP_OK) /* total number of entries in the central dir */
1841 {
1842 if(zi->number_entry >= 0xFFFF)
1843 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
1844 else
1846 }
1847
1848 if (err==ZIP_OK) /* size of the central directory */
1849 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1850
1851 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1852 {
1853 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
1854 if(pos >= 0xffffffff)
1855 {
1856 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
1857 }
1858 else
1859 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writing_offset),4);
1860 }
1861
1862 return err;
1863}
int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
Definition: zip.c:287
#define ENDHEADERMAGIC
Definition: zip.c:105

Referenced by zipClose().

◆ Write_GlobalComment()

int Write_GlobalComment ( zip64_internal zi,
const char global_comment 
)

Definition at line 1865 of file zip.c.

1866{
1867 int err = ZIP_OK;
1868 uInt size_global_comment = 0;
1869
1870 if(global_comment != NULL)
1871 size_global_comment = (uInt)strlen(global_comment);
1872
1873 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
1874
1875 if (err == ZIP_OK && size_global_comment > 0)
1876 {
1877 if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
1878 err = ZIP_ERRNO;
1879 }
1880 return err;
1881}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ZWRITE64(filefunc, filestream, buf, size)
Definition: ioapi.h:190

Referenced by zipClose().

◆ Write_LocalFileHeader()

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

Definition at line 964 of file zip.c.

965{
966 /* write the local header */
967 int err;
968 uInt size_filename = (uInt)strlen(filename);
969 uInt size_extrafield = size_extrafield_local;
970
972
973 if (err==ZIP_OK)
974 {
975 if(zi->ci.zip64)
976 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
977 else
978 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
979 }
980
981 if (err==ZIP_OK)
983
984 if (err==ZIP_OK)
986
987 if (err==ZIP_OK)
989
990 // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
991 if (err==ZIP_OK)
992 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
993 if (err==ZIP_OK)
994 {
995 if(zi->ci.zip64)
996 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
997 else
998 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
999 }
1000 if (err==ZIP_OK)
1001 {
1002 if(zi->ci.zip64)
1003 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
1004 else
1005 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
1006 }
1007
1008 if (err==ZIP_OK)
1009 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
1010
1011 if(zi->ci.zip64)
1012 {
1013 size_extrafield += 20;
1014 }
1015
1016 if (err==ZIP_OK)
1017 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
1018
1019 if ((err==ZIP_OK) && (size_filename > 0))
1020 {
1021 if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
1022 err = ZIP_ERRNO;
1023 }
1024
1025 if ((err==ZIP_OK) && (size_extrafield_local > 0))
1026 {
1027 if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
1028 err = ZIP_ERRNO;
1029 }
1030
1031
1032 if ((err==ZIP_OK) && (zi->ci.zip64))
1033 {
1034 // write the Zip64 extended info
1035 short HeaderID = 1;
1036 short DataSize = 16;
1037 ZPOS64_T CompressedSize = 0;
1038 ZPOS64_T UncompressedSize = 0;
1039
1040 // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
1042
1043 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)HeaderID,2);
1045
1046 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
1047 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
1048 }
1049
1050 return err;
1051}
const char * filename
Definition: ioapi.h:137
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:203
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
ZPOS64_T pos_zip64extrainfo
Definition: zip.c:155
uLong flag
Definition: zip.c:146
uLong dosDate
Definition: zip.c:151
int zip64
Definition: zip.c:154
int method
Definition: zip.c:148
curfile64_info ci
Definition: zip.c:171
#define LOCALHEADERMAGIC
Definition: zip.c:103

Referenced by zipOpenNewFileInZip4_64().

◆ Write_Zip64EndOfCentralDirectoryLocator()

int Write_Zip64EndOfCentralDirectoryLocator ( zip64_internal zi,
ZPOS64_T  zip64eocd_pos_inzip 
)

Definition at line 1756 of file zip.c.

1757{
1758 int err = ZIP_OK;
1759 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset;
1760
1762
1763 /*num disks*/
1764 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1766
1767 /*relative offset*/
1768 if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
1770
1771 /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
1772 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1774
1775 return err;
1776}
#define ZIP64ENDLOCHEADERMAGIC
Definition: zip.c:107

Referenced by zipClose().

◆ Write_Zip64EndOfCentralDirectoryRecord()

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

Definition at line 1778 of file zip.c.

1779{
1780 int err = ZIP_OK;
1781
1782 uLong Zip64DataSize = 44;
1783
1785
1786 if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
1787 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
1788
1789 if (err==ZIP_OK) /* version made by */
1791
1792 if (err==ZIP_OK) /* version needed */
1794
1795 if (err==ZIP_OK) /* number of this disk */
1797
1798 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1800
1801 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1803
1804 if (err==ZIP_OK) /* total number of entries in the central dir */
1806
1807 if (err==ZIP_OK) /* size of the central directory */
1808 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
1809
1810 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1811 {
1812 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
1814 }
1815 return err;
1816}
#define ZIP64ENDHEADERMAGIC
Definition: zip.c:106

Referenced by zipClose().

◆ zip64FlushWriteBuffer()

int zip64FlushWriteBuffer ( zip64_internal zi)

Definition at line 1369 of file zip.c.

1370{
1371 int err=ZIP_OK;
1372
1373 if (zi->ci.encrypt != 0)
1374 {
1375#ifndef NOCRYPT
1376 uInt i;
1377 int t;
1378 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
1379 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
1380#endif
1381 }
1382
1384 err = ZIP_ERRNO;
1385
1387
1388#ifdef HAVE_BZIP2
1389 if(zi->ci.method == Z_BZIP2ED)
1390 {
1391 zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
1392 zi->ci.bstream.total_in_lo32 = 0;
1393 zi->ci.bstream.total_in_hi32 = 0;
1394 }
1395 else
1396#endif
1397 {
1399 zi->ci.stream.total_in = 0;
1400 }
1401
1402
1403 zi->ci.pos_in_buffered_data = 0;
1404
1405 return err;
1406}
GLdouble GLdouble t
Definition: gl.h:2047
#define zencode(pkeys, pcrc_32_tab, c, t)
Definition: crypt.h:80
unsigned long keys[3]
Definition: zip.c:159
Byte buffered_data[Z_BUFSIZE]
Definition: zip.c:150
uInt pos_in_buffered_data
Definition: zip.c:138
z_stream stream
Definition: zip.c:132
ZPOS64_T totalCompressedData
Definition: zip.c:156
const z_crc_t * pcrc_32_tab
Definition: zip.c:160
int encrypt
Definition: zip.c:153
ZPOS64_T totalUncompressedData
Definition: zip.c:157
uLong total_in
Definition: zlib.h:61
#define Z_BZIP2ED
Definition: unzip.h:62

Referenced by zipCloseFileInZipRaw64(), and zipWriteInFileInZip().

◆ zip64local_getByte()

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

Definition at line 349 of file zip.c.

350{
351 unsigned char c;
352 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
353 if (err==1)
354 {
355 *pi = (int)c;
356 return ZIP_OK;
357 }
358 else
359 {
360 if (ZERROR64(*pzlib_filefunc_def,filestream))
361 return ZIP_ERRNO;
362 else
363 return ZIP_EOF;
364 }
365}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
const GLubyte * c
Definition: glext.h:8905
#define ZERROR64(filefunc, filestream)
Definition: ioapi.h:194
#define c
Definition: ke_i.h:80
static refpint_t pi[]
Definition: server.c:96
#define ZIP_EOF
Definition: zip.h:73

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

◆ zip64local_getLong()

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

Definition at line 395 of file zip.c.

396{
397 uLong x ;
398 int i = 0;
399 int err;
400
401 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
402 x = (uLong)i;
403
404 if (err==ZIP_OK)
405 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
406 x += ((uLong)i)<<8;
407
408 if (err==ZIP_OK)
409 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
410 x += ((uLong)i)<<16;
411
412 if (err==ZIP_OK)
413 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
414 x += ((uLong)i)<<24;
415
416 if (err==ZIP_OK)
417 *pX = x;
418 else
419 *pX = 0;
420 return err;
421}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
Definition: zip.c:349

Referenced by LoadCentralDirectoryRecord(), and zip64local_SearchCentralDir64().

◆ zip64local_getLong64()

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

Definition at line 426 of file zip.c.

427{
428 ZPOS64_T x;
429 int i = 0;
430 int err;
431
432 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
433 x = (ZPOS64_T)i;
434
435 if (err==ZIP_OK)
436 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
437 x += ((ZPOS64_T)i)<<8;
438
439 if (err==ZIP_OK)
440 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
441 x += ((ZPOS64_T)i)<<16;
442
443 if (err==ZIP_OK)
444 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
445 x += ((ZPOS64_T)i)<<24;
446
447 if (err==ZIP_OK)
448 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
449 x += ((ZPOS64_T)i)<<32;
450
451 if (err==ZIP_OK)
452 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
453 x += ((ZPOS64_T)i)<<40;
454
455 if (err==ZIP_OK)
456 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
457 x += ((ZPOS64_T)i)<<48;
458
459 if (err==ZIP_OK)
460 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
461 x += ((ZPOS64_T)i)<<56;
462
463 if (err==ZIP_OK)
464 *pX = x;
465 else
466 *pX = 0;
467
468 return err;
469}

Referenced by LoadCentralDirectoryRecord(), and zip64local_SearchCentralDir64().

◆ zip64local_getShort()

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

Definition at line 373 of file zip.c.

374{
375 uLong x ;
376 int i = 0;
377 int err;
378
379 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
380 x = (uLong)i;
381
382 if (err==ZIP_OK)
383 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
384 x += ((uLong)i)<<8;
385
386 if (err==ZIP_OK)
387 *pX = x;
388 else
389 *pX = 0;
390 return err;
391}

Referenced by LoadCentralDirectoryRecord().

◆ zip64local_putValue()

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

Definition at line 287 of file zip.c.

288{
289 unsigned char buf[8];
290 int n;
291 for (n = 0; n < nbByte; n++)
292 {
293 buf[n] = (unsigned char)(x & 0xff);
294 x >>= 8;
295 }
296 if (x != 0)
297 { /* data overflow - hack for ZIP64 (X Roche) */
298 for (n = 0; n < nbByte; n++)
299 {
300 buf[n] = 0xff;
301 }
302 }
303
304 if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,(uLong)nbByte)!=(uLong)nbByte)
305 return ZIP_ERRNO;
306 else
307 return ZIP_OK;
308}
unsigned char
Definition: typeof.h:29
GLdouble n
Definition: glext.h:7729

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

◆ zip64local_putValue_inmemory()

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

Definition at line 311 of file zip.c.

312{
313 unsigned char* buf=(unsigned char*)dest;
314 int n;
315 for (n = 0; n < nbByte; n++) {
316 buf[n] = (unsigned char)(x & 0xff);
317 x >>= 8;
318 }
319
320 if (x != 0)
321 { /* data overflow - hack for ZIP64 */
322 for (n = 0; n < nbByte; n++)
323 {
324 buf[n] = 0xff;
325 }
326 }
327}
static char * dest
Definition: rtl.c:135

Referenced by zipCloseFileInZipRaw64(), and zipOpenNewFileInZip4_64().

◆ zip64local_SearchCentralDir()

ZPOS64_T zip64local_SearchCentralDir ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream 
)

Definition at line 480 of file zip.c.

481{
482 unsigned char* buf;
483 ZPOS64_T uSizeFile;
484 ZPOS64_T uBackRead;
485 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
486 ZPOS64_T uPosFound=0;
487
488 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
489 return 0;
490
491
492 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
493
494 if (uMaxBack>uSizeFile)
495 uMaxBack = uSizeFile;
496
497 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
498 if (buf==NULL)
499 return 0;
500
501 uBackRead = 4;
502 while (uBackRead<uMaxBack)
503 {
504 uLong uReadSize;
505 ZPOS64_T uReadPos ;
506 int i;
507 if (uBackRead+BUFREADCOMMENT>uMaxBack)
508 uBackRead = uMaxBack;
509 else
510 uBackRead+=BUFREADCOMMENT;
511 uReadPos = uSizeFile-uBackRead ;
512
513 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
514 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
515 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
516 break;
517
518 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
519 break;
520
521 for (i=(int)uReadSize-3; (i--)>0;)
522 {
523 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
524 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
525 {
526 uPosFound = uReadPos+(unsigned)i;
527 break;
528 }
529 }
530
531 if (uPosFound!=0)
532 break;
533 }
534 TRYFREE(buf);
535 return uPosFound;
536}
#define ZLIB_FILEFUNC_SEEK_END
Definition: ioapi.h:115
static unsigned(__cdecl *hash_bstr)(bstr_t s)
#define BUFREADCOMMENT
Definition: zip.c:472

Referenced by LoadCentralDirectoryRecord().

◆ zip64local_SearchCentralDir64()

ZPOS64_T zip64local_SearchCentralDir64 ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream 
)

Definition at line 544 of file zip.c.

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

Referenced by LoadCentralDirectoryRecord().

◆ zip64local_TmzDateToDosDate()

uLong zip64local_TmzDateToDosDate ( const tm_zip ptm)

Definition at line 332 of file zip.c.

333{
334 uLong year = (uLong)ptm->tm_year;
335 if (year>=1980)
336 year-=1980;
337 else if (year>=80)
338 year-=80;
339 return
340 (uLong) (((uLong)(ptm->tm_mday) + (32 * (uLong)(ptm->tm_mon+1)) + (512 * year)) << 16) |
341 (((uLong)ptm->tm_sec/2) + (32 * (uLong)ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
342}
if(dx< 0)
Definition: linetemp.h:194
int tm_hour
Definition: zip.h:93
int tm_min
Definition: zip.h:92
int tm_sec
Definition: zip.h:91
int tm_mon
Definition: zip.h:95
int tm_year
Definition: zip.h:96
int tm_mday
Definition: zip.h:94

Referenced by zipOpenNewFileInZip4_64().

◆ zipClose()

int ZEXPORT zipClose ( zipFile  file,
const char global_comment 
)

Definition at line 1883 of file zip.c.

1884{
1885 zip64_internal* zi;
1886 int err = 0;
1887 uLong size_centraldir = 0;
1888 ZPOS64_T centraldir_pos_inzip;
1889 ZPOS64_T pos;
1890
1891 if (file == NULL)
1892 return ZIP_PARAMERROR;
1893
1894 zi = (zip64_internal*)file;
1895
1896 if (zi->in_opened_file_inzip == 1)
1897 {
1899 }
1900
1901#ifndef NO_ADDFILEINEXISTINGZIP
1902 if (global_comment==NULL)
1903 global_comment = zi->globalcomment;
1904#endif
1905
1906 centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1907
1908 if (err==ZIP_OK)
1909 {
1911 while (ldi!=NULL)
1912 {
1913 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
1914 {
1916 err = ZIP_ERRNO;
1917 }
1918
1919 size_centraldir += ldi->filled_in_this_block;
1920 ldi = ldi->next_datablock;
1921 }
1922 }
1924
1925 pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
1926 if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
1927 {
1928 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
1929 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1930
1932 }
1933
1934 if (err==ZIP_OK)
1935 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1936
1937 if(err == ZIP_OK)
1938 err = Write_GlobalComment(zi, global_comment);
1939
1940 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
1941 if (err == ZIP_OK)
1942 err = ZIP_ERRNO;
1943
1944#ifndef NO_ADDFILEINEXISTINGZIP
1946#endif
1947 TRYFREE(zi);
1948
1949 return err;
1950}
Definition: fci.c:127
linkedlist_datablock_internal * first_block
Definition: zip.c:125
int in_opened_file_inzip
Definition: zip.c:170
int Write_EndOfCentralDirectoryRecord(zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
Definition: zip.c:1817
int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
Definition: zip.c:1778
int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal *zi, ZPOS64_T zip64eocd_pos_inzip)
Definition: zip.c:1756
void free_linkedlist(linkedlist_data *ll)
Definition: zip.c:218
int ZEXPORT zipCloseFileInZip(zipFile file)
Definition: zip.c:1751
int Write_GlobalComment(zip64_internal *zi, const char *global_comment)
Definition: zip.c:1865
#define ZIP_PARAMERROR
Definition: zip.h:75

Referenced by CZipCreatorImpl::JustDoIt().

◆ zipCloseFileInZip()

int ZEXPORT zipCloseFileInZip ( zipFile  file)

Definition at line 1751 of file zip.c.

1752{
1753 return zipCloseFileInZipRaw (file,0,0);
1754}
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32)
Definition: zip.c:1510

Referenced by CZipCreatorImpl::JustDoIt(), zipClose(), and zipOpenNewFileInZip4_64().

◆ zipCloseFileInZipRaw()

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

Definition at line 1510 of file zip.c.

1511{
1512 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1513}
#define crc32(crc, buf, len)
Definition: inflate.c:1081
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
Definition: zip.c:1515

Referenced by zipCloseFileInZip().

◆ zipCloseFileInZipRaw64()

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

set internal file attributes field

Definition at line 1515 of file zip.c.

1516{
1517 zip64_internal* zi;
1518 ZPOS64_T compressed_size;
1519 uLong invalidValue = 0xffffffff;
1520 unsigned datasize = 0;
1521 int err=ZIP_OK;
1522
1523 if (file == NULL)
1524 return ZIP_PARAMERROR;
1525 zi = (zip64_internal*)file;
1526
1527 if (zi->in_opened_file_inzip == 0)
1528 return ZIP_PARAMERROR;
1529 zi->ci.stream.avail_in = 0;
1530
1531 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1532 {
1533 while (err==ZIP_OK)
1534 {
1535 uLong uTotalOutBefore;
1536 if (zi->ci.stream.avail_out == 0)
1537 {
1539 err = ZIP_ERRNO;
1541 zi->ci.stream.next_out = zi->ci.buffered_data;
1542 }
1543 uTotalOutBefore = zi->ci.stream.total_out;
1544 err=deflate(&zi->ci.stream, Z_FINISH);
1545 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1546 }
1547 }
1548 else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1549 {
1550#ifdef HAVE_BZIP2
1551 err = BZ_FINISH_OK;
1552 while (err==BZ_FINISH_OK)
1553 {
1554 uLong uTotalOutBefore;
1555 if (zi->ci.bstream.avail_out == 0)
1556 {
1558 err = ZIP_ERRNO;
1559 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1560 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1561 }
1562 uTotalOutBefore = zi->ci.bstream.total_out_lo32;
1563 err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
1564 if(err == BZ_STREAM_END)
1565 err = Z_STREAM_END;
1566
1567 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
1568 }
1569
1570 if(err == BZ_FINISH_OK)
1571 err = ZIP_OK;
1572#endif
1573 }
1574
1575 if (err==Z_STREAM_END)
1576 err=ZIP_OK; /* this is normal */
1577
1578 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1579 {
1581 err = ZIP_ERRNO;
1582 }
1583
1584 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1585 {
1586 int tmp_err = deflateEnd(&zi->ci.stream);
1587 if (err == ZIP_OK)
1588 err = tmp_err;
1589 zi->ci.stream_initialised = 0;
1590 }
1591#ifdef HAVE_BZIP2
1592 else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1593 {
1594 int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
1595 if (err==ZIP_OK)
1596 err = tmperr;
1597 zi->ci.stream_initialised = 0;
1598 }
1599#endif
1600
1601 if (!zi->ci.raw)
1602 {
1603 crc32 = (uLong)zi->ci.crc32;
1604 uncompressed_size = zi->ci.totalUncompressedData;
1605 }
1606 compressed_size = zi->ci.totalCompressedData;
1607
1608# ifndef NOCRYPT
1609 compressed_size += zi->ci.crypt_header_size;
1610# endif
1611
1612 // update Current Item crc and sizes,
1613 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
1614 {
1615 /*version Made by*/
1617 /*version needed*/
1619
1620 }
1621
1623
1624
1625 if(compressed_size >= 0xffffffff)
1626 zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
1627 else
1628 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
1629
1631 if (zi->ci.stream.data_type == Z_ASCII)
1633
1634 if(uncompressed_size >= 0xffffffff)
1635 zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
1636 else
1637 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
1638
1639 // Add ZIP64 extra info field for uncompressed size
1640 if(uncompressed_size >= 0xffffffff)
1641 datasize += 8;
1642
1643 // Add ZIP64 extra info field for compressed size
1644 if(compressed_size >= 0xffffffff)
1645 datasize += 8;
1646
1647 // Add ZIP64 extra info field for relative offset to local file header of current file
1648 if(zi->ci.pos_local_header >= 0xffffffff)
1649 datasize += 8;
1650
1651 if(datasize > 0)
1652 {
1653 char* p = NULL;
1654
1655 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
1656 {
1657 // we can not write more data to the buffer that we have room for.
1658 return ZIP_BADZIPFILE;
1659 }
1660
1662
1663 // Add Extra Information Header for 'ZIP64 information'
1664 zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
1665 p += 2;
1666 zip64local_putValue_inmemory(p, datasize, 2); // DataSize
1667 p += 2;
1668
1669 if(uncompressed_size >= 0xffffffff)
1670 {
1671 zip64local_putValue_inmemory(p, uncompressed_size, 8);
1672 p += 8;
1673 }
1674
1675 if(compressed_size >= 0xffffffff)
1676 {
1677 zip64local_putValue_inmemory(p, compressed_size, 8);
1678 p += 8;
1679 }
1680
1681 if(zi->ci.pos_local_header >= 0xffffffff)
1682 {
1684 p += 8;
1685 }
1686
1687 // Update how much extra free space we got in the memory buffer
1688 // and increase the centralheader size so the new ZIP64 fields are included
1689 // ( 4 below is the size of HeaderID and DataSize field )
1691 zi->ci.size_centralheader += datasize + 4;
1692
1693 // Update the extra info size field
1694 zi->ci.size_centralExtra += datasize + 4;
1696 }
1697
1698 if (err==ZIP_OK)
1700
1701 free(zi->ci.central_header);
1702
1703 if (err==ZIP_OK)
1704 {
1705 // Update the LocalFileHeader with the new values.
1706
1707 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1708
1710 err = ZIP_ERRNO;
1711
1712 if (err==ZIP_OK)
1713 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1714
1715 if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff )
1716 {
1717 if(zi->ci.pos_zip64extrainfo > 0)
1718 {
1719 // Update the size in the ZIP64 extended field.
1721 err = ZIP_ERRNO;
1722
1723 if (err==ZIP_OK) /* compressed size, unknown */
1724 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
1725
1726 if (err==ZIP_OK) /* uncompressed size, unknown */
1727 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
1728 }
1729 else
1730 err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal
1731 }
1732 else
1733 {
1734 if (err==ZIP_OK) /* compressed size, unknown */
1735 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1736
1737 if (err==ZIP_OK) /* uncompressed size, unknown */
1738 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1739 }
1740
1741 if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1742 err = ZIP_ERRNO;
1743 }
1744
1745 zi->number_entry ++;
1746 zi->in_opened_file_inzip = 0;
1747
1748 return err;
1749}
static SIZE_T datasize
Definition: asm.c:30
#define free
Definition: debug_ros.c:5
#define Z_DEFLATED
Definition: zlib.h:146
#define Z_STREAM_END
Definition: zlib.h:115
#define Z_FINISH
Definition: zlib.h:109
int deflate(z_streamp strm, int flush) DECLSPEC_HIDDEN
Definition: deflate.c:815
#define Z_ASCII
Definition: zlib.h:142
int deflateEnd(z_streamp strm) DECLSPEC_HIDDEN
Definition: deflate.c:1130
GLfloat GLfloat p
Definition: glext.h:8902
uLong size_centralheader
Definition: zip.c:144
int stream_initialised
Definition: zip.c:137
unsigned crypt_header_size
Definition: zip.c:161
ZPOS64_T pos_local_header
Definition: zip.c:140
uLong size_centralExtraFree
Definition: zip.c:145
char * central_header
Definition: zip.c:142
uLong crc32
Definition: zip.c:152
uLong size_centralExtra
Definition: zip.c:143
int raw
Definition: zip.c:149
uInt avail_in
Definition: zlib.h:60
uInt avail_out
Definition: zlib.h:64
Bytef * next_out
Definition: zlib.h:63
int data_type
Definition: zlib.h:74
uLong total_out
Definition: zlib.h:65
#define Z_BUFSIZE
Definition: zip.c:54
void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte)
Definition: zip.c:311
int zip64FlushWriteBuffer(zip64_internal *zi)
Definition: zip.c:1369

Referenced by zipCloseFileInZipRaw().

◆ zipOpen()

zipFile ZEXPORT zipOpen ( const char pathname,
int  append 
)

Definition at line 954 of file zip.c.

955{
956 return zipOpen3((const void*)pathname,append,NULL,NULL);
957}
static void append(struct dump_context *dc, const void *data, unsigned size)
Definition: minidump.c:397
char pathname[512]
Definition: util.h:13
zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def)
Definition: zip.c:851

◆ zipOpen2()

zipFile ZEXPORT zipOpen2 ( const char pathname,
int  append,
zipcharpc globalcomment,
zlib_filefunc_def pzlib_filefunc32_def 
)

Definition at line 925 of file zip.c.

926{
927 if (pzlib_filefunc32_def != NULL)
928 {
929 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
930 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
931 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
932 }
933 else
934 return zipOpen3(pathname, append, globalcomment, NULL);
935}
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
Definition: ioapi.c:70

◆ zipOpen2_64()

zipFile ZEXPORT zipOpen2_64 ( const void pathname,
int  append,
zipcharpc globalcomment,
zlib_filefunc64_def pzlib_filefunc_def 
)

Definition at line 938 of file zip.c.

939{
940 if (pzlib_filefunc_def != NULL)
941 {
942 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
943 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
944 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
945 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
946 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
947 }
948 else
949 return zipOpen3(pathname, append, globalcomment, NULL);
950}
seek_file_func zseek32_file
Definition: ioapi.h:185
zlib_filefunc64_def zfile_func64
Definition: ioapi.h:182
tell_file_func ztell32_file
Definition: ioapi.h:184

Referenced by CZipCreatorImpl::JustDoIt().

◆ zipOpen3()

zipFile ZEXPORT zipOpen3 ( const void pathname,
int  append,
zipcharpc globalcomment,
zlib_filefunc64_32_def pzlib_filefunc64_32_def 
)

Definition at line 851 of file zip.c.

852{
853 zip64_internal ziinit;
854 zip64_internal* zi;
855 int err=ZIP_OK;
856
859#ifndef __REACTOS__
860 if (pzlib_filefunc64_32_def==NULL)
862 else
863#endif
864 ziinit.z_filefunc = *pzlib_filefunc64_32_def;
865
866 ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
867 pathname,
871
872 if (ziinit.filestream == NULL)
873 return NULL;
874
876 ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
877
878 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
879 ziinit.in_opened_file_inzip = 0;
880 ziinit.ci.stream_initialised = 0;
881 ziinit.number_entry = 0;
883 init_linkedlist(&(ziinit.central_dir));
884
885
886
887 zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
888 if (zi==NULL)
889 {
890 ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
891 return NULL;
892 }
893
894 /* now we add file in a zipfile */
895# ifndef NO_ADDFILEINEXISTINGZIP
896 ziinit.globalcomment = NULL;
898 {
899 // Read and Cache Central Directory Records
901 }
902
903 if (globalcomment)
904 {
905 *globalcomment = ziinit.globalcomment;
906 }
907# endif /* !NO_ADDFILEINEXISTINGZIP*/
908
909 if (err != ZIP_OK)
910 {
911# ifndef NO_ADDFILEINEXISTINGZIP
912 TRYFREE(ziinit.globalcomment);
913# endif /* !NO_ADDFILEINEXISTINGZIP*/
914 TRYFREE(zi);
915 return NULL;
916 }
917 else
918 {
919 *zi = ziinit;
920 return (zipFile)zi;
921 }
922}
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: ioapi.c:248
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition: ioapi.h:122
#define ZOPEN64(filefunc, filename, mode)
Definition: ioapi.h:202
#define ZLIB_FILEFUNC_MODE_CREATE
Definition: ioapi.h:123
#define ZLIB_FILEFUNC_MODE_WRITE
Definition: ioapi.h:119
#define ZLIB_FILEFUNC_MODE_READ
Definition: ioapi.h:118
int LoadCentralDirectoryRecord(zip64_internal *pziinit)
Definition: zip.c:642
void init_linkedlist(linkedlist_data *ll)
Definition: zip.c:213
#define SEEK_END
Definition: zip.c:84
#define APPEND_STATUS_ADDINZIP
Definition: zip.h:114
#define APPEND_STATUS_CREATEAFTER
Definition: zip.h:113
#define APPEND_STATUS_CREATE
Definition: zip.h:112
voidp zipFile
Definition: zip.h:69

Referenced by zipOpen(), zipOpen2(), zipOpen2_64(), and zipOpen64().

◆ zipOpen64()

zipFile ZEXPORT zipOpen64 ( const void pathname,
int  append 
)

Definition at line 959 of file zip.c.

960{
962}

◆ zipOpenNewFileInZip()

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 1356 of file zip.c.

1360{
1361 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1362 extrafield_local, size_extrafield_local,
1363 extrafield_global, size_extrafield_global,
1364 comment, method, level, 0,
1366 NULL, 0, VERSIONMADEBY, 0, 0);
1367}
#define Z_DEFAULT_STRATEGY
Definition: zlib.h:137
#define MAX_WBITS
Definition: zlib.h:151
method
Definition: dragdrop.c:54
#define DEF_MEM_LEVEL
Definition: zutil.h:53
GLint level
Definition: gl.h:1546
#define comment(fmt, arg1)
Definition: rebar.c:820
#define VERSIONMADEBY
Definition: zip.c:50
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:1061

◆ zipOpenNewFileInZip2()

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 1317 of file zip.c.

1321{
1322 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1323 extrafield_local, size_extrafield_local,
1324 extrafield_global, size_extrafield_global,
1325 comment, method, level, raw,
1327 NULL, 0, VERSIONMADEBY, 0, 0);
1328}

◆ zipOpenNewFileInZip2_64()

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 1330 of file zip.c.

1334{
1335 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1336 extrafield_local, size_extrafield_local,
1337 extrafield_global, size_extrafield_global,
1338 comment, method, level, raw,
1340 NULL, 0, VERSIONMADEBY, 0, zip64);
1341}

◆ zipOpenNewFileInZip3()

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 1287 of file zip.c.

1293{
1294 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1295 extrafield_local, size_extrafield_local,
1296 extrafield_global, size_extrafield_global,
1297 comment, method, level, raw,
1298 windowBits, memLevel, strategy,
1299 password, crcForCrypting, VERSIONMADEBY, 0, 0);
1300}
static WCHAR password[]
Definition: url.c:33
int windowBits
Definition: zlib.h:813

◆ zipOpenNewFileInZip3_64()

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 1302 of file zip.c.

1308{
1309 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1310 extrafield_local, size_extrafield_local,
1311 extrafield_global, size_extrafield_global,
1312 comment, method, level, raw,
1313 windowBits, memLevel, strategy,
1314 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1315}

◆ zipOpenNewFileInZip4()

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 1271 of file zip.c.

1278{
1279 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1280 extrafield_local, size_extrafield_local,
1281 extrafield_global, size_extrafield_global,
1282 comment, method, level, raw,
1283 windowBits, memLevel, strategy,
1284 password, crcForCrypting, versionMadeBy, flagBase, 0);
1285}

◆ zipOpenNewFileInZip4_64()

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 1061 of file zip.c.

1068{
1069 zip64_internal* zi;
1070 uInt size_filename;
1071 uInt size_comment;
1072 uInt i;
1073 int err = ZIP_OK;
1074
1075# ifdef NOCRYPT
1076 (crcForCrypting);
1077 if (password != NULL)
1078 return ZIP_PARAMERROR;
1079# endif
1080
1081 if (file == NULL)
1082 return ZIP_PARAMERROR;
1083
1084#ifdef HAVE_BZIP2
1085 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
1086 return ZIP_PARAMERROR;
1087#else
1088 if ((method!=0) && (method!=Z_DEFLATED))
1089 return ZIP_PARAMERROR;
1090#endif
1091
1092 zi = (zip64_internal*)file;
1093
1094 if (zi->in_opened_file_inzip == 1)
1095 {
1097 if (err != ZIP_OK)
1098 return err;
1099 }
1100
1101 if (filename==NULL)
1102 filename="-";
1103
1104 if (comment==NULL)
1105 size_comment = 0;
1106 else
1107 size_comment = (uInt)strlen(comment);
1108
1109 size_filename = (uInt)strlen(filename);
1110
1111 if (zipfi == NULL)
1112 zi->ci.dosDate = 0;
1113 else
1114 {
1115 if (zipfi->dosDate != 0)
1116 zi->ci.dosDate = zipfi->dosDate;
1117 else
1119 }
1120
1121 zi->ci.flag = flagBase;
1122 if ((level==8) || (level==9))
1123 zi->ci.flag |= 2;
1124 if (level==2)
1125 zi->ci.flag |= 4;
1126 if (level==1)
1127 zi->ci.flag |= 6;
1128 if (password != NULL)
1129 zi->ci.flag |= 1;
1130
1131 zi->ci.crc32 = 0;
1132 zi->ci.method = method;
1133 zi->ci.encrypt = 0;
1134 zi->ci.stream_initialised = 0;
1135 zi->ci.pos_in_buffered_data = 0;
1136 zi->ci.raw = raw;
1138
1139 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
1140 zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
1141
1143
1144 zi->ci.size_centralExtra = size_extrafield_global;
1146 /* version info */
1147 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
1153 zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
1154 zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
1155 zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
1156 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
1157 zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
1158 zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
1159
1160 if (zipfi==NULL)
1162 else
1164
1165 if (zipfi==NULL)
1167 else
1169
1170 if(zi->ci.pos_local_header >= 0xffffffff)
1172 else
1174
1175 for (i=0;i<size_filename;i++)
1177
1178 for (i=0;i<size_extrafield_global;i++)
1179 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
1180 *(((const char*)extrafield_global)+i);
1181
1182 for (i=0;i<size_comment;i++)
1183 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
1184 size_extrafield_global+i) = *(comment+i);
1185 if (zi->ci.central_header == NULL)
1186 return ZIP_INTERNALERROR;
1187
1188 zi->ci.zip64 = zip64;
1189 zi->ci.totalCompressedData = 0;
1190 zi->ci.totalUncompressedData = 0;
1191 zi->ci.pos_zip64extrainfo = 0;
1192
1193 err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
1194
1195#ifdef HAVE_BZIP2
1196 zi->ci.bstream.avail_in = (uInt)0;
1197 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1198 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1199 zi->ci.bstream.total_in_hi32 = 0;
1200 zi->ci.bstream.total_in_lo32 = 0;
1201 zi->ci.bstream.total_out_hi32 = 0;
1202 zi->ci.bstream.total_out_lo32 = 0;
1203#endif
1204
1205 zi->ci.stream.avail_in = (uInt)0;
1207 zi->ci.stream.next_out = zi->ci.buffered_data;
1208 zi->ci.stream.total_in = 0;
1209 zi->ci.stream.total_out = 0;
1211
1212#ifdef HAVE_BZIP2
1213 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1214#else
1215 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1216#endif
1217 {
1218 if(zi->ci.method == Z_DEFLATED)
1219 {
1220 zi->ci.stream.zalloc = (alloc_func)0;
1221 zi->ci.stream.zfree = (free_func)0;
1222 zi->ci.stream.opaque = (voidpf)0;
1223
1224 if (windowBits>0)
1226
1227 err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
1228
1229 if (err==Z_OK)
1231 }
1232 else if(zi->ci.method == Z_BZIP2ED)
1233 {
1234#ifdef HAVE_BZIP2
1235 // Init BZip stuff here
1236 zi->ci.bstream.bzalloc = 0;
1237 zi->ci.bstream.bzfree = 0;
1238 zi->ci.bstream.opaque = (voidpf)0;
1239
1240 err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
1241 if(err == BZ_OK)
1243#endif
1244 }
1245
1246 }
1247
1248# ifndef NOCRYPT
1249 zi->ci.crypt_header_size = 0;
1250 if ((err==Z_OK) && (password != NULL))
1251 {
1252 unsigned char bufHead[RAND_HEAD_LEN];
1253 unsigned int sizeHead;
1254 zi->ci.encrypt = 1;
1256 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
1257
1258 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
1259 zi->ci.crypt_header_size = sizeHead;
1260
1261 if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
1262 err = ZIP_ERRNO;
1263 }
1264# endif
1265
1266 if (err==Z_OK)
1267 zi->in_opened_file_inzip = 1;
1268 return err;
1269}
const z_crc_t FAR *ZEXPORT get_crc_table()
Definition: crc32.c:595
void(* free_func)(voidpf opaque, voidpf address)
Definition: zlib.h:54
#define Z_BINARY
Definition: zlib.h:140
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
Definition: zlib.h:53
void FAR * voidpf
Definition: zlib.h:42
#define Z_OK
Definition: zlib.h:114
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
Definition: zlib.h:1814
alloc_func zalloc
Definition: zlib.h:70
free_func zfree
Definition: zlib.h:71
voidpf opaque
Definition: zlib.h:72
uLong dosDate
Definition: zip.h:102
uLong internal_fa
Definition: zip.h:105
uLong external_fa
Definition: zip.h:106
tm_zip tmz_date
Definition: zip.h:101
#define SIZECENTRALHEADER
Definition: zip.c:112
uLong zip64local_TmzDateToDosDate(const tm_zip *ptm)
Definition: zip.c:332
#define CENTRALHEADERMAGIC
Definition: zip.c:104
int Write_LocalFileHeader(zip64_internal *zi, const char *filename, uInt size_extrafield_local, const void *extrafield_local)
Definition: zip.c:964

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

◆ zipOpenNewFileInZip64()

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 1343 of file zip.c.

1347{
1348 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1349 extrafield_local, size_extrafield_local,
1350 extrafield_global, size_extrafield_global,
1351 comment, method, level, 0,
1353 NULL, 0, VERSIONMADEBY, 0, zip64);
1354}

◆ zipRemoveExtraInfoBlock()

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

Definition at line 1952 of file zip.c.

1953{
1954 char* p = pData;
1955 int size = 0;
1956 char* pNewHeader;
1957 char* pTmp;
1958 short header;
1959 short dataSize;
1960
1961 int retVal = ZIP_OK;
1962
1963 if(pData == NULL || dataLen == NULL || *dataLen < 4)
1964 return ZIP_PARAMERROR;
1965
1966 pNewHeader = (char*)ALLOC((unsigned)*dataLen);
1967 pTmp = pNewHeader;
1968
1969 while(p < (pData + *dataLen))
1970 {
1971 header = *(short*)p;
1972 dataSize = *(((short*)p)+1);
1973
1974 if( header == sHeader ) // Header found.
1975 {
1976 p += dataSize + 4; // skip it. do not copy to temp buffer
1977 }
1978 else
1979 {
1980 // Extra Info block should not be removed, So copy it to the temp buffer.
1981 memcpy(pTmp, p, dataSize + 4);
1982 p += dataSize + 4;
1983 size += dataSize + 4;
1984 }
1985
1986 }
1987
1988 if(size < *dataLen)
1989 {
1990 // clean old extra info block.
1991 memset(pData,0, *dataLen);
1992
1993 // copy the new extra info block over the old
1994 if(size > 0)
1995 memcpy(pData, pNewHeader, size);
1996
1997 // set the new extra info size
1998 *dataLen = size;
1999
2000 retVal = ZIP_OK;
2001 }
2002 else
2003 retVal = ZIP_ERRNO;
2004
2005 TRYFREE(pNewHeader);
2006
2007 return retVal;
2008}
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei dataSize
Definition: glext.h:11123
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memset(x, y, z)
Definition: compat.h:39
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830

◆ zipWriteInFileInZip()

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

Definition at line 1408 of file zip.c.

1409{
1410 zip64_internal* zi;
1411 int err=ZIP_OK;
1412
1413 if (file == NULL)
1414 return ZIP_PARAMERROR;
1415 zi = (zip64_internal*)file;
1416
1417 if (zi->in_opened_file_inzip == 0)
1418 return ZIP_PARAMERROR;
1419
1420 zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
1421
1422#ifdef HAVE_BZIP2
1423 if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
1424 {
1425 zi->ci.bstream.next_in = (void*)buf;
1426 zi->ci.bstream.avail_in = len;
1427 err = BZ_RUN_OK;
1428
1429 while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
1430 {
1431 if (zi->ci.bstream.avail_out == 0)
1432 {
1434 err = ZIP_ERRNO;
1435 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1436 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1437 }
1438
1439
1440 if(err != BZ_RUN_OK)
1441 break;
1442
1443 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1444 {
1445 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1446// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
1447 err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1448
1449 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
1450 }
1451 }
1452
1453 if(err == BZ_RUN_OK)
1454 err = ZIP_OK;
1455 }
1456 else
1457#endif
1458 {
1459 zi->ci.stream.next_in = (Bytef*)buf;
1460 zi->ci.stream.avail_in = len;
1461
1462 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1463 {
1464 if (zi->ci.stream.avail_out == 0)
1465 {
1467 err = ZIP_ERRNO;
1469 zi->ci.stream.next_out = zi->ci.buffered_data;
1470 }
1471
1472
1473 if(err != ZIP_OK)
1474 break;
1475
1476 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1477 {
1478 uLong uTotalOutBefore = zi->ci.stream.total_out;
1480
1481 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1482 }
1483 else
1484 {
1485 uInt copy_this,i;
1486 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1487 copy_this = zi->ci.stream.avail_in;
1488 else
1489 copy_this = zi->ci.stream.avail_out;
1490
1491 for (i = 0; i < copy_this; i++)
1492 *(((char*)zi->ci.stream.next_out)+i) =
1493 *(((const char*)zi->ci.stream.next_in)+i);
1494 {
1495 zi->ci.stream.avail_in -= copy_this;
1496 zi->ci.stream.avail_out-= copy_this;
1497 zi->ci.stream.next_in+= copy_this;
1498 zi->ci.stream.next_out+= copy_this;
1499 zi->ci.stream.total_in+= copy_this;
1500 zi->ci.stream.total_out+= copy_this;
1501 zi->ci.pos_in_buffered_data += copy_this;
1502 }
1503 }
1504 }// while(...)
1505 }
1506
1507 return err;
1508}
#define Z_NO_FLUSH
Definition: zlib.h:105
Byte FAR Bytef
Definition: zlib.h:41
z_const Bytef * next_in
Definition: zlib.h:59

Referenced by CZipCreatorImpl::JustDoIt().

Variable Documentation

◆ zip_copyright

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

Definition at line 98 of file zip.c.