96#ifndef CASESENSITIVITYDEFAULT_NO
97# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
98# define CASESENSITIVITYDEFAULT_NO
104#define UNZ_BUFSIZE (16384)
107#ifndef UNZ_MAXFILENAMEINZIP
108#define UNZ_MAXFILENAMEINZIP (256)
112# define ALLOC(size) (malloc(size))
115# define TRYFREE(p) {if (p) free(p);}
118#define SIZECENTRALDIRITEM (0x2e)
119#define SIZEZIPLOCALHEADER (0x1e)
126 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
193 unsigned long keys[3];
194 const unsigned long* pcrc_32_tab;
218 int err = (
int)
ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
226 if (
ZERROR64(*pzlib_filefunc_def,filestream))
356 char c1=*(fileName1++);
357 char c2=*(fileName2++);
358 if ((c1>=
'a') && (c1<=
'z'))
360 if ((c2>=
'a') && (c2<=
'z'))
363 return ((c2==
'\0') ? 0 : -1);
374#ifdef CASESENSITIVITYDEFAULT_NO
375#define CASESENSITIVITYDEFAULTVALUE 2
377#define CASESENSITIVITYDEFAULTVALUE 1
380#ifndef STRCMPCASENOSENTIVEFUNCTION
381#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
394 const char* fileName2,
395 int iCaseSensitivity)
398 if (iCaseSensitivity==0)
401 if (iCaseSensitivity==1)
402 return strcmp(fileName1,fileName2);
407#ifndef BUFREADCOMMENT
408#define BUFREADCOMMENT (0x400)
428 uSizeFile =
ZTELL64(*pzlib_filefunc_def,filestream);
430 if (uMaxBack>uSizeFile)
431 uMaxBack = uSizeFile;
438 while (uBackRead<uMaxBack)
444 uBackRead = uMaxBack;
447 uReadPos = uSizeFile-uBackRead ;
454 if (
ZREAD64(*pzlib_filefunc_def,filestream,
buf,uReadSize)!=uReadSize)
457 for (i=(
int)uReadSize-3; (i--)>0;)
458 if (((*(
buf+i))==0x50) && ((*(
buf+i+1))==0x4b) &&
459 ((*(
buf+i+2))==0x05) && ((*(
buf+i+3))==0x06))
461 uPosFound = uReadPos+i;
496 uSizeFile =
ZTELL64(*pzlib_filefunc_def,filestream);
498 if (uMaxBack>uSizeFile)
499 uMaxBack = uSizeFile;
506 while (uBackRead<uMaxBack)
512 uBackRead = uMaxBack;
515 uReadPos = uSizeFile-uBackRead ;
522 if (
ZREAD64(*pzlib_filefunc_def,filestream,
buf,uReadSize)!=uReadSize)
525 for (i=(
int)uReadSize-3; (i--)>0;)
526 if (((*(
buf+i))==0x50) && ((*(
buf+i+1))==0x4b) &&
527 ((*(
buf+i+2))==0x06) && ((*(
buf+i+3))==0x07))
529 uPosFound = uReadPos+i;
572 if (uL != 0x06064b50)
575 return relativeOffset;
589 int is64bitOpenFunction)
598 uLong number_disk_with_CD;
611 if (pzlib_filefunc64_32_def==NULL)
671 (number_disk_with_CD!=0) ||
718 number_entry_CD = uL;
721 (number_disk_with_CD!=0) ||
771 if (pzlib_filefunc32_def != NULL)
784 if (pzlib_filefunc_def != NULL)
787 zlib_filefunc64_32_def_fill.
zfile_func64 = *pzlib_filefunc_def;
860 ptm->
tm_mon = (
uInt)((((uDate)&0x1E0)/0x20)-1) ;
861 ptm->
tm_year = (
uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
864 ptm->
tm_min = (
uInt) ((ulDosDate&0x7E0)/0x20) ;
874 *pfile_info_internal,
876 uLong fileNameBufferSize,
878 uLong extraFieldBufferSize,
880 uLong commentBufferSize));
885 *pfile_info_internal,
887 uLong fileNameBufferSize,
889 uLong extraFieldBufferSize,
891 uLong commentBufferSize)
915 else if (uMagic!=0x02014b50)
971 if ((err==
UNZ_OK) && (szFileName!=NULL))
980 uSizeRead = fileNameBufferSize;
989 if ((err==
UNZ_OK) && (extraField!=NULL))
995 uSizeRead = extraFieldBufferSize;
1042 if (headerId == 0x0001)
1079 acc += 2 + 2 + dataSize;
1083 if ((err==
UNZ_OK) && (szComment!=NULL))
1092 uSizeRead = commentBufferSize;
1114 if ((err==
UNZ_OK) && (pfile_info!=NULL))
1115 *pfile_info=file_info;
1117 if ((err==
UNZ_OK) && (pfile_info_internal!=NULL))
1118 *pfile_info_internal=file_info_internal;
1132 char * szFileName,
uLong fileNameBufferSize,
1133 void *extraField,
uLong extraFieldBufferSize,
1134 char* szComment,
uLong commentBufferSize)
1137 szFileName,fileNameBufferSize,
1138 extraField,extraFieldBufferSize,
1139 szComment,commentBufferSize);
1144 char * szFileName,
uLong fileNameBufferSize,
1145 void *extraField,
uLong extraFieldBufferSize,
1146 char* szComment,
uLong commentBufferSize)
1151 szFileName,fileNameBufferSize,
1152 extraField,extraFieldBufferSize,
1153 szComment,commentBufferSize);
1158 pfile_info->
flag = file_info64.
flag;
1161 pfile_info->
crc = file_info64.
crc;
1195 NULL,0,NULL,0,NULL,0);
1224 NULL,0,NULL,0,NULL,0);
1274 szCurrentFileName,
sizeof(szCurrentFileName)-1,
1279 szFileName,iCaseSensitivity)==0)
1298// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
1299// I need random access
1301// Further optimization could be realized by adding an ability
1302// to cache the directory in memory. The goal being a single
1303// comprehensive file read to put the file I need in a memory.
1318 if (file==NULL || file_pos==NULL)
1349 if (file==NULL || file_pos==NULL)
1360 NULL,0,NULL,0,NULL,0);
1371 if (file_pos == NULL)
1392 ZPOS64_T * poffset_local_extrafield,
1393 uInt * psize_local_extrafield)
1395 uLong uMagic,uData,uFlags;
1396 uLong size_filename;
1397 uLong size_extra_field;
1401 *poffset_local_extrafield = 0;
1402 *psize_local_extrafield = 0;
1413 else if (uMagic!=0x04034b50)
1461 *piSizeVar += (
uInt)size_filename;
1467 *psize_local_extrafield = (
uInt)size_extra_field;
1469 *piSizeVar += (
uInt)size_extra_field;
1479 int* level,
int raw,
const char* password)
1486 uInt size_local_extrafield;
1490 if (password != NULL)
1507 if (pfile_in_zip_read_info==NULL)
1514 pfile_in_zip_read_info->
raw=raw;
1518 TRYFREE(pfile_in_zip_read_info);
1532 case 6 : *level = 1;
break;
1533 case 4 : *level = 2;
break;
1534 case 2 : *level = 9;
break;
1548 TRYFREE(pfile_in_zip_read_info);
1553 pfile_in_zip_read_info->
crc32=0;
1560 pfile_in_zip_read_info->
stream.total_out = 0;
1565 pfile_in_zip_read_info->bstream.bzalloc = (
void *(*) (
void *,
int,
int))0;
1566 pfile_in_zip_read_info->bstream.bzfree = (
free_func)0;
1567 pfile_in_zip_read_info->bstream.opaque = (
voidpf)0;
1568 pfile_in_zip_read_info->bstream.state = (
voidpf)0;
1574 pfile_in_zip_read_info->
stream.avail_in = 0;
1576 err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1581 TRYFREE(pfile_in_zip_read_info);
1585 pfile_in_zip_read_info->
raw=1;
1593 pfile_in_zip_read_info->
stream.next_in = 0;
1594 pfile_in_zip_read_info->
stream.avail_in = 0;
1601 TRYFREE(pfile_in_zip_read_info);
1622 pfile_in_zip_read_info->
stream.avail_in = (
uInt)0;
1628 if (password != NULL)
1631 s->pcrc_32_tab = get_crc_table();
1632 init_keys(password,s->keys,s->pcrc_32_tab);
1641 for (i = 0; i<12; i++)
1642 zdecode(s->keys,s->pcrc_32_tab,source[i]);
1678 if (pfile_in_zip_read_info==NULL)
1707 if (pfile_in_zip_read_info==NULL)
1718 pfile_in_zip_read_info->
stream.avail_out = (
uInt)len;
1721 (!(pfile_in_zip_read_info->
raw)))
1722 pfile_in_zip_read_info->
stream.avail_out =
1726 pfile_in_zip_read_info->
stream.avail_in) &&
1727 (pfile_in_zip_read_info->
raw))
1728 pfile_in_zip_read_info->
stream.avail_out =
1730 pfile_in_zip_read_info->
stream.avail_in;
1732 while (pfile_in_zip_read_info->
stream.avail_out>0)
1734 if ((pfile_in_zip_read_info->
stream.avail_in==0) &&
1751 uReadThis)!=uReadThis)
1759 for(i=0;i<uReadThis;i++)
1761 zdecode(s->keys,s->pcrc_32_tab,
1771 pfile_in_zip_read_info->
stream.next_in =
1773 pfile_in_zip_read_info->
stream.avail_in = (
uInt)uReadThis;
1780 if ((pfile_in_zip_read_info->
stream.avail_in == 0) &&
1782 return (iRead==0) ?
UNZ_EOF : iRead;
1784 if (pfile_in_zip_read_info->
stream.avail_out <
1785 pfile_in_zip_read_info->
stream.avail_in)
1786 uDoCopy = pfile_in_zip_read_info->
stream.avail_out ;
1788 uDoCopy = pfile_in_zip_read_info->
stream.avail_in ;
1790 for (i=0;i<uDoCopy;i++)
1791 *(pfile_in_zip_read_info->
stream.next_out+i) =
1792 *(pfile_in_zip_read_info->
stream.next_in+i);
1797 pfile_in_zip_read_info->
stream.next_out,
1800 pfile_in_zip_read_info->
stream.avail_in -= uDoCopy;
1801 pfile_in_zip_read_info->
stream.avail_out -= uDoCopy;
1802 pfile_in_zip_read_info->
stream.next_out += uDoCopy;
1803 pfile_in_zip_read_info->
stream.next_in += uDoCopy;
1804 pfile_in_zip_read_info->
stream.total_out += uDoCopy;
1810 uLong uTotalOutBefore,uTotalOutAfter;
1811 const Bytef *bufBefore;
1814 pfile_in_zip_read_info->bstream.next_in = (
char*)pfile_in_zip_read_info->
stream.next_in;
1815 pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->
stream.avail_in;
1816 pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->
stream.total_in;
1817 pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
1818 pfile_in_zip_read_info->bstream.next_out = (
char*)pfile_in_zip_read_info->
stream.next_out;
1819 pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->
stream.avail_out;
1820 pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->
stream.total_out;
1821 pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
1823 uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
1824 bufBefore = (
const Bytef *)pfile_in_zip_read_info->bstream.next_out;
1826 err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
1828 uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
1829 uOutThis = uTotalOutAfter-uTotalOutBefore;
1833 pfile_in_zip_read_info->
crc32 =
crc32(pfile_in_zip_read_info->
crc32,bufBefore, (
uInt)(uOutThis));
1835 iRead += (
uInt)(uTotalOutAfter - uTotalOutBefore);
1837 pfile_in_zip_read_info->
stream.next_in = (
Bytef*)pfile_in_zip_read_info->bstream.next_in;
1838 pfile_in_zip_read_info->
stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
1839 pfile_in_zip_read_info->
stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
1840 pfile_in_zip_read_info->
stream.next_out = (
Bytef*)pfile_in_zip_read_info->bstream.next_out;
1841 pfile_in_zip_read_info->
stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
1842 pfile_in_zip_read_info->
stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
1844 if (err==BZ_STREAM_END)
1845 return (iRead==0) ?
UNZ_EOF : iRead;
1852 ZPOS64_T uTotalOutBefore,uTotalOutAfter;
1853 const Bytef *bufBefore;
1857 uTotalOutBefore = pfile_in_zip_read_info->
stream.total_out;
1858 bufBefore = pfile_in_zip_read_info->
stream.next_out;
1868 if ((err>=0) && (pfile_in_zip_read_info->
stream.msg!=NULL))
1871 uTotalOutAfter = pfile_in_zip_read_info->
stream.total_out;
1872 uOutThis = uTotalOutAfter-uTotalOutBefore;
1876 pfile_in_zip_read_info->
crc32 =
1877 crc32(pfile_in_zip_read_info->
crc32,bufBefore,
1883 iRead += (
uInt)(uTotalOutAfter - uTotalOutBefore);
1886 return (iRead==0) ?
UNZ_EOF : iRead;
1910 if (pfile_in_zip_read_info==NULL)
1913 return (z_off_t)pfile_in_zip_read_info->
stream.total_out;
1926 if (pfile_in_zip_read_info==NULL)
1945 if (pfile_in_zip_read_info==NULL)
1980 if (pfile_in_zip_read_info==NULL)
1987 return (
int)size_to_read;
1989 if (len>size_to_read)
1990 read_now = (
uInt)size_to_read;
1992 read_now = (
uInt)len ;
2006 buf,read_now)!=read_now)
2009 return (
int)read_now;
2027 if (pfile_in_zip_read_info==NULL)
2032 (!pfile_in_zip_read_info->
raw))
2034 if (pfile_in_zip_read_info->
crc32 != pfile_in_zip_read_info->
crc32_wait)
2045 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2050 TRYFREE(pfile_in_zip_read_info);
2071 uReadThis = uSizeBuf;
2087 return (
int)uReadThis;
2113 return (
uLong)offset64;
2129 NULL,0,NULL,0,NULL,0);
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
#define ZERROR64(filefunc, filestream)
#define ZLIB_FILEFUNC_MODE_EXISTING
#define ZOPEN64(filefunc, filename, mode)
#define ZLIB_FILEFUNC_SEEK_CUR
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define ZSEEK64(filefunc, filestream, pos, mode)
#define ZLIB_FILEFUNC_SEEK_SET
#define ZREAD64(filefunc, filestream, buf, size)
#define ZCLOSE64(filefunc, filestream)
#define ZTELL64(filefunc, filestream)
#define ZLIB_FILEFUNC_SEEK_END
#define ZLIB_FILEFUNC_MODE_READ
unsigned long long int ZPOS64_T
__attribute__((visibility("default")))
ZPOS64_T byte_before_the_zipfile
ZPOS64_T rest_read_uncompressed
ZPOS64_T offset_local_extrafield
ZPOS64_T rest_read_compressed
zlib_filefunc64_32_def z_filefunc
uInt size_local_extrafield
ZPOS64_T pos_local_extrafield
ZPOS64_T pos_in_zip_directory
zlib_filefunc64_32_def z_filefunc
unz_file_info64 cur_file_info
ZPOS64_T pos_in_central_dir
unz_file_info64_internal cur_file_info_internal
file_in_zip64_read_info_s * pfile_in_zip_read
ZPOS64_T offset_central_dir
ZPOS64_T size_central_dir
ZPOS64_T byte_before_the_zipfile
ZPOS64_T uncompressed_size
uLong pos_in_zip_directory
seek_file_func zseek32_file
zlib_filefunc64_def zfile_func64
tell_file_func ztell32_file
int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len)
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
int ZEXPORT unzSetOffset(unzFile file, uLong pos)
z_off_t ZEXPORT unztell(unzFile file)
local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
uLong ZEXPORT unzGetOffset(unzFile file)
#define CASESENSITIVITYDEFAULTVALUE
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos)
#define STRCMPCASENOSENTIVEFUNCTION
int ZEXPORT unzStringFileNameCompare(const char *fileName1, const char *fileName2, int iCaseSensitivity)
ZPOS64_T ZEXPORT unztell64(unzFile file)
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
#define SIZEZIPLOCALHEADER
int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz *ptm)
unzFile ZEXPORT unzOpen(const char *path)
local int unz64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
int ZEXPORT unzGoToFirstFile(unzFile file)
int ZEXPORT unzeof(unzFile file)
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *pfile_info, unz_file_info64_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
local int unz64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
int ZEXPORT unzOpenCurrentFile(unzFile file)
int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos)
int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
local int strcmpcasenosensitive_internal(const char *fileName1, const char *fileName2)
local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s *s, uInt *piSizeVar, ZPOS64_T *poffset_local_extrafield, uInt *psize_local_extrafield)
unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc32_def)
#define UNZ_MAXFILENAMEINZIP
int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info32)
ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file)
unzFile ZEXPORT unzOpen64(const void *path)
local int unz64local_getByte OF((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi))
local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, int is64bitOpenFunction)
int ZEXPORT unzCloseCurrentFile(unzFile file)
int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
local int unz64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
int ZEXPORT unzGoToNextFile(unzFile file)
local int unz64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
#define SIZECENTRALDIRITEM
int ZEXPORT unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf)
static const char unz_copyright[]
struct unz_file_info64_internal_s unz_file_info64_internal
int ZEXPORT unzClose(unzFile file)
#define UNZ_INTERNALERROR
#define UNZ_END_OF_LIST_OF_FILE