38 # define VERSIONMADEBY (0x0) 42 #define Z_BUFSIZE (16384) 45 #ifndef Z_MAXFILENAMEINZIP 46 #define Z_MAXFILENAMEINZIP (256) 50 # define ALLOC(size) (malloc(size)) 53 # define TRYFREE(p) {if (p) free(p);} 76 #if MAX_MEM_LEVEL >= 8 77 # define DEF_MEM_LEVEL 8 79 # define DEF_MEM_LEVEL MAX_MEM_LEVEL 83 " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
86 #define SIZEDATA_INDATABLOCK (4096-(4*4)) 88 #define LOCALHEADERMAGIC (0x04034b50) 89 #define CENTRALHEADERMAGIC (0x02014b50) 90 #define ENDHEADERMAGIC (0x06054b50) 92 #define FLAG_LOCALHEADER_OFFSET (0x06) 93 #define CRC_LOCALHEADER_OFFSET (0x0e) 95 #define SIZECENTRALHEADER (0x2e) 132 unsigned long keys[3];
149 #ifndef NO_ADDFILEINEXISTINGZIP 157 #define INCLUDECRYPTINGCODE_IFCRYPTALLOWED 192 static inline void free_linkedlist(ll)
196 ll->first_block = ll->last_block = NULL;
205 const unsigned char* from_copy;
210 if (ll->last_block == NULL)
213 if (ll->first_block == NULL)
217 ldi = ll->last_block;
218 from_copy = (
unsigned char*)buf;
224 unsigned char* to_copy;
232 ll->last_block = ldi;
238 copy_this = (uInt)len;
242 for (i=0;i<copy_this;i++)
243 *(to_copy+i)=*(from_copy+i);
247 from_copy += copy_this ;
257 #ifndef NO_ADDFILEINEXISTINGZIP 271 unsigned char buf[4];
273 for (n = 0; n < nbByte; n++)
275 buf[n] = (
unsigned char)(x & 0xff);
280 for (n = 0; n < nbByte; n++)
286 if (
ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(
uLong)nbByte)
298 unsigned char*
buf=(
unsigned char*)dest;
300 for (n = 0; n < nbByte; n++) {
301 buf[n] = (
unsigned char)(x & 0xff);
307 for (n = 0; n < nbByte; n++)
328 (
uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
329 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (
uLong)ptm->tm_hour));
346 int err = (
int)
ZREAD(*pzlib_filefunc_def,filestream,&c,1);
354 if (
ZERROR(*pzlib_filefunc_def,filestream))
429 #ifndef BUFREADCOMMENT 430 #define BUFREADCOMMENT (0x400) 447 uLong uMaxBack=0xffff;
454 uSizeFile =
ZTELL(*pzlib_filefunc_def,filestream);
456 if (uMaxBack>uSizeFile)
457 uMaxBack = uSizeFile;
464 while (uBackRead<uMaxBack)
466 uLong uReadSize,uReadPos ;
469 uBackRead = uMaxBack;
472 uReadPos = uSizeFile-uBackRead ;
479 if (
ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
482 for (i=(
int)uReadSize-3; (i--)>0;)
483 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
484 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
486 uPosFound = uReadPos+i;
500 const
char *pathname;
510 if (pzlib_filefunc_def==NULL)
540 # ifndef NO_ADDFILEINEXISTINGZIP 544 uLong byte_before_the_zipfile;
546 uLong size_central_dir;
547 uLong offset_central_dir;
548 uLong central_pos,uL;
552 uLong number_disk_with_CD;
555 uLong number_entry_CD;
588 if ((number_entry_CD!=number_entry) ||
589 (number_disk_with_CD!=0) ||
606 if ((central_pos<offset_central_dir+size_central_dir) &&
626 byte_before_the_zipfile = central_pos -
627 (offset_central_dir+size_central_dir);
631 uLong size_central_dir_to_read = size_central_dir;
633 void* buf_read = (
void*)
ALLOC(buf_size);
635 offset_central_dir + byte_before_the_zipfile,
639 while ((size_central_dir_to_read>0) && (err==
ZIP_OK))
642 if (read_this > size_central_dir_to_read)
643 read_this = size_central_dir_to_read;
650 size_central_dir_to_read-=read_this;
654 ziinit.
begin_pos = byte_before_the_zipfile;
670 # ifndef NO_ADDFILEINEXISTINGZIP 684 const
char *pathname;
687 return zipOpen2(pathname,append,NULL,NULL);
691 extrafield_local, size_extrafield_local,
692 extrafield_global, size_extrafield_global,
693 comment, method, level, raw,
694 windowBits, memLevel, strategy,
695 password, crcForCrypting)
699 const
void* extrafield_local;
700 uInt size_extrafield_local;
701 const
void* extrafield_global;
702 uInt size_extrafield_global;
710 const
char* password;
711 uLong crcForCrypting;
720 if (password != NULL)
726 if ((method!=0) && (method!=Z_DEFLATED))
745 size_comment = (uInt)strlen(comment);
747 size_filename = (uInt)strlen(filename);
759 if (level==8 || level==9)
765 if (password != NULL)
776 size_extrafield_global + size_comment;
806 for (i=0;i<size_filename;i++)
809 for (i=0;i<size_extrafield_global;i++)
811 *(((
const char*)extrafield_global)+i);
813 for (i=0;i<size_comment;i++)
815 size_extrafield_global+i) = *(comment+i);
846 if ((err==
ZIP_OK) && (size_filename>0))
850 if ((err==
ZIP_OK) && (size_extrafield_local>0))
852 !=size_extrafield_local)
863 zi->
ci.
stream.zalloc = (alloc_func)0;
868 windowBits = -windowBits;
870 err = deflateInit2(&zi->
ci.
stream, level,
871 Z_DEFLATED, windowBits, memLevel, strategy);
878 if ((err==Z_OK) && (password != NULL))
880 unsigned char bufHead[RAND_HEAD_LEN];
881 unsigned int sizeHead;
883 zi->
ci.
pcrc_32_tab = (
const long unsigned int*)get_crc_table();
886 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->
ci.
keys,zi->
ci.
pcrc_32_tab,crcForCrypting);
900 extrafield_local, size_extrafield_local,
901 extrafield_global, size_extrafield_global,
902 comment, method, level, raw)
906 const
void* extrafield_local;
907 uInt size_extrafield_local;
908 const
void* extrafield_global;
909 uInt size_extrafield_global;
916 extrafield_local, size_extrafield_local,
917 extrafield_global, size_extrafield_global,
918 comment, method, level, raw,
924 extrafield_local, size_extrafield_local,
925 extrafield_global, size_extrafield_global,
926 comment, method, level)
930 const
void* extrafield_local;
931 uInt size_extrafield_local;
932 const
void* extrafield_global;
933 uInt size_extrafield_global;
939 extrafield_local, size_extrafield_local,
940 extrafield_global, size_extrafield_global,
941 comment, method, level, 0);
949 if (zi->ci.encrypt != 0)
954 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
955 zi->ci.buffered_data[i] =
zencode(zi->ci.keys, zi->ci.pcrc_32_tab,
956 zi->ci.buffered_data[i],t);
959 if (
ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)
960 !=zi->ci.pos_in_buffered_data)
962 zi->ci.pos_in_buffered_data = 0;
1002 err=deflate(&zi->
ci.
stream, Z_NO_FLUSH);
1010 copy_this = zi->
ci.
stream.avail_in;
1012 copy_this = zi->
ci.
stream.avail_out;
1013 for (i=0;i<copy_this;i++)
1014 *(((
char*)zi->
ci.
stream.next_out)+i) =
1015 *(((
const char*)zi->
ci.
stream.next_in)+i);
1017 zi->
ci.
stream.avail_in -= copy_this;
1018 zi->
ci.
stream.avail_out-= copy_this;
1020 zi->
ci.
stream.next_out+= copy_this;
1021 zi->
ci.
stream.total_in+= copy_this;
1022 zi->
ci.
stream.total_out+= copy_this;
1033 uLong uncompressed_size;
1037 uLong compressed_size;
1051 uLong uTotalOutBefore;
1059 uTotalOutBefore = zi->
ci.
stream.total_out;
1060 err=deflate(&zi->
ci.
stream, Z_FINISH);
1064 if (err==Z_STREAM_END)
1090 if (zi->
ci.
stream.data_type == Z_ASCII)
1093 uncompressed_size,4);
1135 const
char* global_comment;
1139 uLong size_centraldir = 0;
1140 uLong centraldir_pos_inzip;
1141 uInt size_global_comment;
1151 #ifndef NO_ADDFILEINEXISTINGZIP 1152 if (global_comment==NULL)
1155 if (global_comment==NULL)
1156 size_global_comment = 0;
1158 size_global_comment = (uInt)strlen(global_comment);
1204 if ((err==
ZIP_OK) && (size_global_comment>0))
1206 global_comment,size_global_comment) != size_global_comment)
1213 #ifndef NO_ADDFILEINEXISTINGZIP
struct linkedlist_datablock_internal_s linkedlist_datablock_internal
#define ZTELL(filefunc, filestream)
#define ZREAD(filefunc, filestream, buf, size)
#define ZIP_INTERNALERROR
local int ziplocal_getByte(zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, int *pi) const
#define SIZEDATA_INDATABLOCK
unsigned char data[SIZEDATA_INDATABLOCK]
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)
#define SIZECENTRALHEADER
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)
uLong filled_in_this_block
local int zipFlushWriteBuffer(zip_internal *zi)
struct linkedlist_datablock_internal_s * next_datablock
#define ZLIB_FILEFUNC_MODE_READ
local linkedlist_datablock_internal * allocate_new_datablock()
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
struct linkedlist_data_s linkedlist_data
local void init_linkedlist(linkedlist_data *ll)
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32)
zlib_filefunc_def z_filefunc
Byte buffered_data[Z_BUFSIZE]
#define ZERROR(filefunc, filestream)
#define ZSEEK(filefunc, filestream, pos, mode)
local int ziplocal_getShort(zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX) const
linkedlist_datablock_internal * first_block
typedef voidpf(ZCALLBACK *open_file_func) OF((voidpf opaque
uInt pos_in_buffered_data
const unsigned long * pcrc_32_tab
local uLong ziplocal_SearchCentralDir(zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream) const
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned len)
#define zencode(pkeys, pcrc_32_tab, c, t)
zipFile ZEXPORT zipOpen(char *pathname, int append) const
#define ZLIB_FILEFUNC_MODE_CREATE
local int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
#define ZLIB_FILEFUNC_MODE_EXISTING
uLong avail_in_this_block
local void ziplocal_putValue_inmemory(void *dest, uLong x, int nbByte)
uLong add_position_when_writting_offset
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)
#define ZCLOSE(filefunc, filestream)
open_file_func zopen_file
local int ziplocal_getLong(zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX) const
local int ziplocal_putValue(zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong x, int nbByte) const
linkedlist_data central_dir
local void free_datablock(linkedlist_datablock_internal *ldi)
#define ZLIB_FILEFUNC_MODE_WRITE
int ZEXPORT zipCloseFileInZip(zipFile file)
zipFile ZEXPORT zipOpen2(char *pathname, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc_def) const
#define ZLIB_FILEFUNC_SEEK_END
#define ZWRITE(filefunc, filestream, buf, size)
#define APPEND_STATUS_ADDINZIP
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
const char zip_copyright[]
local int ziplocal_putValue OF((const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong x, int nbByte))
#define ZLIB_FILEFUNC_SEEK_SET
#define APPEND_STATUS_CREATE
typedef uLong(ZCALLBACK *read_file_func) OF((voidpf opaque
int ZEXPORT zipClose(zipFile file, const char *global_comment)
linkedlist_datablock_internal * last_block
#define CENTRALHEADERMAGIC
local uLong ziplocal_TmzDateToDosDate(tm_zip *ptm, uLong dosDate) const