82 #include "minizip/unzip.h" 102 #ifndef CASESENSITIVITYDEFAULT_NO 103 # if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) 104 # define CASESENSITIVITYDEFAULT_NO 110 #define UNZ_BUFSIZE (16384) 113 #ifndef UNZ_MAXFILENAMEINZIP 114 #define UNZ_MAXFILENAMEINZIP (256) 118 # define ALLOC(size) (malloc(size)) 121 # define TRYFREE(p) {if (p) {free(p); }} 124 #define SIZECENTRALDIRITEM (0x2e) 125 #define SIZEZIPLOCALHEADER (0x1e) 128 const char unz_copyright[] =
129 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
134 ZPOS64_T offset_curfile;
149 ZPOS64_T pos_in_zipfile;
150 uLong stream_initialised;
152 ZPOS64_T offset_local_extrafield;
153 uInt size_local_extrafield;
154 ZPOS64_T pos_local_extrafield;
155 ZPOS64_T total_out_64;
159 ZPOS64_T rest_read_compressed;
160 ZPOS64_T rest_read_uncompressed;
163 uLong compression_method;
164 ZPOS64_T byte_before_the_zipfile;
174 int is64bitOpenFunction;
177 ZPOS64_T byte_before_the_zipfile;
179 ZPOS64_T pos_in_central_dir;
180 ZPOS64_T current_file_ok;
181 ZPOS64_T central_pos;
183 ZPOS64_T size_central_dir;
184 ZPOS64_T offset_central_dir;
196 unsigned long keys[3];
197 const unsigned long* pcrc_32_tab;
203 #include "minizip/crypt.h" 213 local
int unz64local_getByte OF((
218 local
int unz64local_getByte(
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
int *pi)
221 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
229 if (ZERROR64(*pzlib_filefunc_def,filestream))
244 local
int unz64local_getShort OF((
257 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
262 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
277 local
int unz64local_getLong OF((
290 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
295 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
301 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
307 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
322 local
int unz64local_getLong64 OF((
336 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
341 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
343 x |= ((ZPOS64_T)i)<<8;
347 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
349 x |= ((ZPOS64_T)i)<<16;
353 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
355 x |= ((ZPOS64_T)i)<<24;
359 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
361 x |= ((ZPOS64_T)i)<<32;
365 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
367 x |= ((ZPOS64_T)i)<<40;
371 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
373 x |= ((ZPOS64_T)i)<<48;
377 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
379 x |= ((ZPOS64_T)i)<<56;
393 local
int strcmpcasenosensitive_internal (
const char* fileName1,
const char* fileName2)
397 char c1 = *(fileName1++);
398 char c2 = *(fileName2++);
399 if ((c1>=
'a') && (c1<=
'z'))
403 if ((c2>=
'a') && (c2<=
'z'))
409 return ((c2==
'\0') ? 0 : -1);
427 #ifdef CASESENSITIVITYDEFAULT_NO 428 #define CASESENSITIVITYDEFAULTVALUE 2 430 #define CASESENSITIVITYDEFAULTVALUE 1 433 #ifndef STRCMPCASENOSENTIVEFUNCTION 434 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal 446 extern MINIZIP_API
int unzStringFileNameCompare (
const char* fileName1,
447 const char* fileName2,
448 int iCaseSensitivity)
451 if (iCaseSensitivity==0)
453 iCaseSensitivity = CASESENSITIVITYDEFAULTVALUE;
456 if (iCaseSensitivity==1)
458 return strcmp(fileName1,fileName2);
461 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
464 #ifndef BUFREADCOMMENT 465 #define BUFREADCOMMENT (0x400) 472 local ZPOS64_T unz64local_SearchCentralDir OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
473 local ZPOS64_T unz64local_SearchCentralDir(
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
478 ZPOS64_T uMaxBack = 0xffff;
479 ZPOS64_T uPosFound = 0;
481 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
487 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
489 if (uMaxBack>uSizeFile)
491 uMaxBack = uSizeFile;
494 buf = (
unsigned char*)ALLOC(BUFREADCOMMENT+4);
501 while (uBackRead<uMaxBack)
506 if (uBackRead+BUFREADCOMMENT>uMaxBack)
508 uBackRead = uMaxBack;
512 uBackRead += BUFREADCOMMENT;
514 uReadPos = uSizeFile-uBackRead;
516 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
517 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
518 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
523 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
528 for (i = (
int)uReadSize-3; (i--)>0; )
530 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
531 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
533 uPosFound = uReadPos+i;
552 local ZPOS64_T unz64local_SearchCentralDir64 OF((
562 ZPOS64_T uMaxBack = 0xffff;
563 ZPOS64_T uPosFound = 0;
565 ZPOS64_T relativeOffset;
567 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
573 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
575 if (uMaxBack>uSizeFile)
577 uMaxBack = uSizeFile;
580 buf = (
unsigned char*)ALLOC(BUFREADCOMMENT+4);
587 while (uBackRead<uMaxBack)
592 if (uBackRead+BUFREADCOMMENT>uMaxBack)
594 uBackRead = uMaxBack;
598 uBackRead += BUFREADCOMMENT;
600 uReadPos = uSizeFile-uBackRead;
602 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
603 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
604 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
609 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
614 for (i = (
int)uReadSize-3; (i--)>0; )
616 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
617 ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
619 uPosFound = uReadPos+i;
636 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
642 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
648 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
658 if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
664 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
674 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
680 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
685 if (uL != 0x06064b50)
690 return relativeOffset;
702 local unzFile unzOpenInternal (
const void *path,
704 int is64bitOpenFunction)
708 ZPOS64_T central_pos;
713 uLong number_disk_with_CD;
715 ZPOS64_T number_entry_CD;
721 if (unz_copyright[0]!=
' ')
726 us.z_filefunc.zseek32_file = NULL;
727 us.z_filefunc.ztell32_file = NULL;
728 if (pzlib_filefunc64_32_def==NULL)
730 fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
734 us.z_filefunc = *pzlib_filefunc64_32_def;
736 us.is64bitOpenFunction = is64bitOpenFunction;
740 us.filestream = ZOPEN64(us.z_filefunc,
742 ZLIB_FILEFUNC_MODE_READ |
743 ZLIB_FILEFUNC_MODE_EXISTING);
744 if (us.filestream==NULL)
749 central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
757 if (ZSEEK64(us.z_filefunc, us.filestream,
758 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
764 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
770 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
776 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
782 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
788 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
794 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
800 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
806 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
811 if ((number_entry_CD!=us.gi.number_entry) ||
812 (number_disk_with_CD!=0) ||
815 err = UNZ_BADZIPFILE;
819 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
826 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
831 us.gi.size_comment = 0;
835 central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
843 if (ZSEEK64(us.z_filefunc, us.filestream,
844 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
850 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
856 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
862 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
868 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
872 us.gi.number_entry = uL;
875 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
879 number_entry_CD = uL;
881 if ((number_entry_CD!=us.gi.number_entry) ||
882 (number_disk_with_CD!=0) ||
885 err = UNZ_BADZIPFILE;
889 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
893 us.size_central_dir = uL;
897 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
901 us.offset_central_dir = uL;
904 if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
910 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
913 err = UNZ_BADZIPFILE;
918 ZCLOSE64(us.z_filefunc, us.filestream);
922 us.byte_before_the_zipfile = central_pos -
923 (us.offset_central_dir+us.size_central_dir);
924 us.central_pos = central_pos;
925 us.pfile_in_zip_read = NULL;
933 unzGoToFirstFile((unzFile)s);
939 extern unzFile MINIZIP_API unzOpen2 (
const char *path,
942 if (pzlib_filefunc32_def != NULL)
945 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
946 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
950 return unzOpenInternal(path, NULL, 0);
954 extern unzFile MINIZIP_API unzOpen2_64 (
const void *path,
957 if (pzlib_filefunc_def != NULL)
960 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
961 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
962 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
963 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
967 return unzOpenInternal(path, NULL, 1);
971 extern unzFile MINIZIP_API unzOpen (
const char *path)
973 return unzOpenInternal(path, NULL, 0);
976 extern unzFile MINIZIP_API unzOpen64 (
const void *path)
978 return unzOpenInternal(path, NULL, 1);
986 extern MINIZIP_API
int unzClose (unzFile file)
991 return UNZ_PARAMERROR;
995 if (s->pfile_in_zip_read!=NULL)
997 unzCloseCurrentFile(file);
1000 ZCLOSE64(s->z_filefunc, s->filestream);
1010 extern MINIZIP_API
int unzGetGlobalInfo64 (unzFile file,
unz_global_info64* pglobal_info)
1015 return UNZ_PARAMERROR;
1018 *pglobal_info = s->gi;
1022 extern MINIZIP_API
int unzGetGlobalInfo (unzFile file,
unz_global_info* pglobal_info32)
1027 return UNZ_PARAMERROR;
1031 pglobal_info32->number_entry = (uLong)s->gi.number_entry;
1032 pglobal_info32->size_comment = s->gi.size_comment;
1038 local
void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate,
tm_unz* ptm)
1041 uDate = (ZPOS64_T)(ulDosDate>>16);
1042 ptm->tm_mday = (uInt)(uDate&0x1f);
1043 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1);
1044 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980);
1046 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
1047 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20);
1048 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f));
1054 local
int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
1057 *pfile_info_internal,
1059 uLong fileNameBufferSize,
1061 uLong extraFieldBufferSize,
1063 uLong commentBufferSize));
1065 local
int unz64local_GetCurrentFileInfoInternal (unzFile file,
1068 *pfile_info_internal,
1070 uLong fileNameBufferSize,
1072 uLong extraFieldBufferSize,
1074 uLong commentBufferSize)
1086 return UNZ_PARAMERROR;
1089 if (ZSEEK64(s->z_filefunc, s->filestream,
1090 s->pos_in_central_dir+s->byte_before_the_zipfile,
1091 ZLIB_FILEFUNC_SEEK_SET)!=0)
1100 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1104 else if (uMagic!=0x02014b50)
1106 err = UNZ_BADZIPFILE;
1110 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
1115 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
1120 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
1125 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
1130 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
1135 unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
1137 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
1142 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1146 file_info.compressed_size = uL;
1148 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1152 file_info.uncompressed_size = uL;
1154 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
1159 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
1164 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
1169 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
1174 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
1179 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
1185 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1189 file_info_internal.offset_curfile = uL;
1191 lSeek += file_info.size_filename;
1192 if ((err==UNZ_OK) && (szFileName!=NULL))
1195 if (file_info.size_filename<fileNameBufferSize)
1197 *(szFileName+file_info.size_filename) =
'\0';
1198 uSizeRead = file_info.size_filename;
1202 uSizeRead = fileNameBufferSize;
1205 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
1207 if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
1216 if ((err==UNZ_OK) && (extraField!=NULL))
1219 if (file_info.size_file_extra<extraFieldBufferSize)
1221 uSizeRead = file_info.size_file_extra;
1225 uSizeRead = extraFieldBufferSize;
1230 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1240 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
1242 if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
1248 lSeek += file_info.size_file_extra - (uLong)uSizeRead;
1252 lSeek += file_info.size_file_extra;
1256 if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
1261 lSeek -= file_info.size_file_extra;
1265 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1275 while(acc < file_info.size_file_extra)
1280 if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
1285 if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
1291 if (headerId == 0x0001)
1295 if(file_info.uncompressed_size == (ZPOS64_T)(
unsigned long)-1)
1297 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1303 if(file_info.compressed_size == (ZPOS64_T)(
unsigned long)-1)
1305 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1311 if(file_info_internal.offset_curfile == (ZPOS64_T)(
unsigned long)-1)
1314 if (unz64local_getLong64(&s->z_filefunc, s->filestream,
1315 &file_info_internal.offset_curfile) != UNZ_OK)
1321 if(file_info.disk_num_start == (
unsigned long)-1)
1324 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1333 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
1339 acc += 2 + 2 + dataSize;
1343 if ((err==UNZ_OK) && (szComment!=NULL))
1346 if (file_info.size_file_comment<commentBufferSize)
1348 *(szComment+file_info.size_file_comment) =
'\0';
1349 uSizeRead = file_info.size_file_comment;
1353 uSizeRead = commentBufferSize;
1358 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1368 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
1370 if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
1375 lSeek += file_info.size_file_comment - uSizeRead;
1379 lSeek += file_info.size_file_comment;
1383 if ((err==UNZ_OK) && (pfile_info!=NULL))
1385 *pfile_info = file_info;
1388 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
1390 *pfile_info_internal = file_info_internal;
1403 extern MINIZIP_API
int unzGetCurrentFileInfo64 (unzFile file,
1405 char * szFileName, uLong fileNameBufferSize,
1406 void *extraField, uLong extraFieldBufferSize,
1407 char* szComment, uLong commentBufferSize)
1409 return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1410 szFileName,fileNameBufferSize,
1411 extraField,extraFieldBufferSize,
1412 szComment,commentBufferSize);
1415 extern MINIZIP_API
int unzGetCurrentFileInfo (unzFile file,
1417 char * szFileName, uLong fileNameBufferSize,
1418 void *extraField, uLong extraFieldBufferSize,
1419 char* szComment, uLong commentBufferSize)
1423 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
1424 szFileName,fileNameBufferSize,
1425 extraField,extraFieldBufferSize,
1426 szComment,commentBufferSize);
1429 pfile_info->version = file_info64.version;
1430 pfile_info->version_needed = file_info64.version_needed;
1431 pfile_info->flag = file_info64.flag;
1432 pfile_info->compression_method = file_info64.compression_method;
1433 pfile_info->dosDate = file_info64.dosDate;
1434 pfile_info->crc = file_info64.crc;
1436 pfile_info->size_filename = file_info64.size_filename;
1437 pfile_info->size_file_extra = file_info64.size_file_extra;
1438 pfile_info->size_file_comment = file_info64.size_file_comment;
1440 pfile_info->disk_num_start = file_info64.disk_num_start;
1441 pfile_info->internal_fa = file_info64.internal_fa;
1442 pfile_info->external_fa = file_info64.external_fa;
1444 pfile_info->tmu_date = file_info64.tmu_date,
1447 pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1448 pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1457 extern MINIZIP_API
int unzGoToFirstFile (unzFile file)
1463 return UNZ_PARAMERROR;
1466 s->pos_in_central_dir = s->offset_central_dir;
1468 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1469 &s->cur_file_info_internal,
1470 NULL,0,NULL,0,NULL,0);
1471 s->current_file_ok = (err == UNZ_OK);
1480 extern MINIZIP_API
int unzGoToNextFile (unzFile file)
1487 return UNZ_PARAMERROR;
1490 if (!s->current_file_ok)
1492 return UNZ_END_OF_LIST_OF_FILE;
1494 if (s->gi.number_entry != 0xffff)
1496 if (s->num_file+1==s->gi.number_entry)
1498 return UNZ_END_OF_LIST_OF_FILE;
1502 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
1503 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment;
1505 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1506 &s->cur_file_info_internal,
1507 NULL,0,NULL,0,NULL,0);
1508 s->current_file_ok = (err == UNZ_OK);
1521 extern MINIZIP_API
int unzLocateFile (unzFile file,
const char *szFileName,
int iCaseSensitivity)
1531 ZPOS64_T num_fileSaved;
1532 ZPOS64_T pos_in_central_dirSaved;
1537 return UNZ_PARAMERROR;
1540 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
1542 return UNZ_PARAMERROR;
1546 if (!s->current_file_ok)
1548 return UNZ_END_OF_LIST_OF_FILE;
1552 num_fileSaved = s->num_file;
1553 pos_in_central_dirSaved = s->pos_in_central_dir;
1554 cur_file_infoSaved = s->cur_file_info;
1555 cur_file_info_internalSaved = s->cur_file_info_internal;
1557 err = unzGoToFirstFile(file);
1559 while (err == UNZ_OK)
1561 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
1562 err = unzGetCurrentFileInfo64(file,NULL,
1563 szCurrentFileName,
sizeof(szCurrentFileName)-1,
1567 if (unzStringFileNameCompare(szCurrentFileName,
1568 szFileName,iCaseSensitivity)==0)
1572 err = unzGoToNextFile(file);
1579 s->num_file = num_fileSaved;
1580 s->pos_in_central_dir = pos_in_central_dirSaved;
1581 s->cur_file_info = cur_file_infoSaved;
1582 s->cur_file_info_internal = cur_file_info_internalSaved;
1605 extern MINIZIP_API
int unzGetFilePos64(unzFile file,
unz64_file_pos* file_pos)
1609 if (file==NULL || file_pos==NULL)
1611 return UNZ_PARAMERROR;
1614 if (!s->current_file_ok)
1616 return UNZ_END_OF_LIST_OF_FILE;
1619 file_pos->pos_in_zip_directory = s->pos_in_central_dir;
1620 file_pos->num_of_file = s->num_file;
1625 extern MINIZIP_API
int unzGetFilePos(
1630 int err = unzGetFilePos64(file,&file_pos64);
1633 file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
1634 file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1639 extern MINIZIP_API
int unzGoToFilePos64(unzFile file,
const unz64_file_pos* file_pos)
1644 if (file==NULL || file_pos==NULL)
1646 return UNZ_PARAMERROR;
1651 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
1652 s->num_file = file_pos->num_of_file;
1655 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1656 &s->cur_file_info_internal,
1657 NULL,0,NULL,0,NULL,0);
1659 s->current_file_ok = (err == UNZ_OK);
1663 extern MINIZIP_API
int unzGoToFilePos(
1668 if (file_pos == NULL)
1670 return UNZ_PARAMERROR;
1673 file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
1674 file_pos64.num_of_file = file_pos->num_of_file;
1675 return unzGoToFilePos64(file,&file_pos64);
1690 local
int unz64local_CheckCurrentFileCoherencyHeader (
unz64_s* s, uInt* piSizeVar,
1691 ZPOS64_T * poffset_local_extrafield,
1692 uInt * psize_local_extrafield)
1694 uLong uMagic,uData,uFlags;
1695 uLong size_filename;
1696 uLong size_extra_field;
1700 *poffset_local_extrafield = 0;
1701 *psize_local_extrafield = 0;
1703 if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
1704 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
1712 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1716 else if (uMagic!=0x04034b50)
1718 err = UNZ_BADZIPFILE;
1722 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1730 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
1735 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1739 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1741 err = UNZ_BADZIPFILE;
1744 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1746 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1748 (s->cur_file_info.compression_method!=Z_DEFLATED))
1750 err = UNZ_BADZIPFILE;
1753 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1758 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1762 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
1764 err = UNZ_BADZIPFILE;
1767 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1771 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
1773 err = UNZ_BADZIPFILE;
1776 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1780 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
1782 err = UNZ_BADZIPFILE;
1785 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1789 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1791 err = UNZ_BADZIPFILE;
1794 *piSizeVar += (uInt)size_filename;
1796 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1800 *poffset_local_extrafield = s->cur_file_info_internal.offset_curfile +
1801 SIZEZIPLOCALHEADER + size_filename;
1802 *psize_local_extrafield = (uInt)size_extra_field;
1804 *piSizeVar += (uInt)size_extra_field;
1813 extern MINIZIP_API
int unzOpenCurrentFile3 (unzFile file,
int* method,
1814 int* level,
int raw,
const char* password)
1820 ZPOS64_T offset_local_extrafield;
1821 uInt size_local_extrafield;
1825 if (password != NULL)
1827 return UNZ_PARAMERROR;
1833 return UNZ_PARAMERROR;
1836 if (!s->current_file_ok)
1838 return UNZ_PARAMERROR;
1841 if (s->pfile_in_zip_read != NULL)
1843 unzCloseCurrentFile(file);
1846 if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,
1847 &size_local_extrafield)!=UNZ_OK)
1849 return UNZ_BADZIPFILE;
1853 if (pfile_in_zip_read_info==NULL)
1855 return UNZ_INTERNALERROR;
1858 pfile_in_zip_read_info->read_buffer = (
char*)ALLOC(UNZ_BUFSIZE);
1859 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1860 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1861 pfile_in_zip_read_info->pos_local_extrafield = 0;
1862 pfile_in_zip_read_info->raw = raw;
1864 if (pfile_in_zip_read_info->read_buffer==NULL)
1866 TRYFREE(pfile_in_zip_read_info);
1867 return UNZ_INTERNALERROR;
1870 pfile_in_zip_read_info->stream_initialised = 0;
1874 *method = (int)s->cur_file_info.compression_method;
1880 switch (s->cur_file_info.flag & 0x06)
1882 case 6: *level = 1;
break;
1883 case 4: *level = 2;
break;
1884 case 2: *level = 9;
break;
1888 if ((s->cur_file_info.compression_method!=0) &&
1890 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1892 (s->cur_file_info.compression_method!=Z_DEFLATED))
1895 err = UNZ_BADZIPFILE;
1898 pfile_in_zip_read_info->crc32_wait = s->cur_file_info.crc;
1899 pfile_in_zip_read_info->crc32 = 0;
1900 pfile_in_zip_read_info->total_out_64 = 0;
1901 pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
1902 pfile_in_zip_read_info->filestream = s->filestream;
1903 pfile_in_zip_read_info->z_filefunc = s->z_filefunc;
1904 pfile_in_zip_read_info->byte_before_the_zipfile = s->byte_before_the_zipfile;
1906 pfile_in_zip_read_info->stream.total_out = 0;
1908 if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
1911 pfile_in_zip_read_info->bstream.bzalloc = (
void *(*)(
void *, int, int)) 0;
1912 pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
1913 pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
1914 pfile_in_zip_read_info->bstream.state = (voidpf)0;
1916 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1917 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1918 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1919 pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1920 pfile_in_zip_read_info->stream.avail_in = 0;
1922 err = BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1925 pfile_in_zip_read_info->stream_initialised = Z_BZIP2ED;
1929 TRYFREE(pfile_in_zip_read_info);
1933 pfile_in_zip_read_info->raw = 1;
1936 else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
1938 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1939 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1940 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1941 pfile_in_zip_read_info->stream.next_in = 0;
1942 pfile_in_zip_read_info->stream.avail_in = 0;
1944 err = inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1947 pfile_in_zip_read_info->stream_initialised = Z_DEFLATED;
1951 TRYFREE(pfile_in_zip_read_info);
1962 pfile_in_zip_read_info->rest_read_compressed =
1963 s->cur_file_info.compressed_size;
1964 pfile_in_zip_read_info->rest_read_uncompressed =
1965 s->cur_file_info.uncompressed_size;
1968 pfile_in_zip_read_info->pos_in_zipfile =
1969 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1972 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1974 s->pfile_in_zip_read = pfile_in_zip_read_info;
1978 if (password != NULL)
1981 s->pcrc_32_tab = get_crc_table();
1982 init_keys(password,s->keys,s->pcrc_32_tab);
1983 if (ZSEEK64(s->z_filefunc, s->filestream,
1984 s->pfile_in_zip_read->pos_in_zipfile +
1985 s->pfile_in_zip_read->byte_before_the_zipfile,
1988 return UNZ_INTERNALERROR;
1990 if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
1992 return UNZ_INTERNALERROR;
1995 for (i = 0; i<12; i++)
1997 zdecode(s->keys,s->pcrc_32_tab,source[i]);
2000 s->pfile_in_zip_read->pos_in_zipfile += 12;
2009 extern MINIZIP_API
int unzOpenCurrentFile (unzFile file)
2011 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
2014 extern MINIZIP_API
int unzOpenCurrentFilePassword (unzFile file,
const char* password)
2016 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
2019 extern MINIZIP_API
int unzOpenCurrentFile2 (unzFile file,
int* method,
int* level,
int raw)
2021 return unzOpenCurrentFile3(file, method, level, raw, NULL);
2026 extern ZPOS64_T MINIZIP_API unzGetCurrentFileZStreamPos64( unzFile file)
2035 pfile_in_zip_read_info = s->pfile_in_zip_read;
2036 if (pfile_in_zip_read_info==NULL)
2040 return pfile_in_zip_read_info->pos_in_zipfile +
2041 pfile_in_zip_read_info->byte_before_the_zipfile;
2056 extern MINIZIP_API
int unzReadCurrentFile (unzFile file, voidp buf,
unsigned len)
2064 return UNZ_PARAMERROR;
2067 pfile_in_zip_read_info = s->pfile_in_zip_read;
2069 if (pfile_in_zip_read_info==NULL)
2071 return UNZ_PARAMERROR;
2075 if ((pfile_in_zip_read_info->read_buffer == NULL))
2077 return UNZ_END_OF_LIST_OF_FILE;
2084 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
2086 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
2088 if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
2089 (!(pfile_in_zip_read_info->raw)))
2091 pfile_in_zip_read_info->stream.avail_out =
2092 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
2095 if ((len>pfile_in_zip_read_info->rest_read_compressed+
2096 pfile_in_zip_read_info->stream.avail_in) &&
2097 (pfile_in_zip_read_info->raw))
2099 pfile_in_zip_read_info->stream.avail_out =
2100 (uInt)pfile_in_zip_read_info->rest_read_compressed+
2101 pfile_in_zip_read_info->stream.avail_in;
2104 while (pfile_in_zip_read_info->stream.avail_out>0)
2106 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
2107 (pfile_in_zip_read_info->rest_read_compressed>0))
2109 uInt uReadThis = UNZ_BUFSIZE;
2110 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
2112 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
2118 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
2119 pfile_in_zip_read_info->filestream,
2120 pfile_in_zip_read_info->pos_in_zipfile +
2121 pfile_in_zip_read_info->byte_before_the_zipfile,
2122 ZLIB_FILEFUNC_SEEK_SET)!=0)
2126 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
2127 pfile_in_zip_read_info->filestream,
2128 pfile_in_zip_read_info->read_buffer,
2129 uReadThis)!=uReadThis)
2139 for(i = 0; i<uReadThis; i++)
2141 pfile_in_zip_read_info->read_buffer[i] =
2142 zdecode(s->keys,s->pcrc_32_tab,
2143 pfile_in_zip_read_info->read_buffer[i]);
2149 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
2151 pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
2153 pfile_in_zip_read_info->stream.next_in =
2154 (Bytef*)pfile_in_zip_read_info->read_buffer;
2155 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
2158 if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
2162 if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
2163 (pfile_in_zip_read_info->rest_read_compressed == 0))
2165 return (iRead==0) ? UNZ_EOF : iRead;
2168 if (pfile_in_zip_read_info->stream.avail_out <
2169 pfile_in_zip_read_info->stream.avail_in)
2171 uDoCopy = pfile_in_zip_read_info->stream.avail_out;
2175 uDoCopy = pfile_in_zip_read_info->stream.avail_in;
2178 for (i = 0; i<uDoCopy; i++)
2180 *(pfile_in_zip_read_info->stream.next_out+i) =
2181 *(pfile_in_zip_read_info->stream.next_in+i);
2184 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
2186 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
2187 pfile_in_zip_read_info->stream.next_out,
2189 pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
2190 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
2191 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
2192 pfile_in_zip_read_info->stream.next_out += uDoCopy;
2193 pfile_in_zip_read_info->stream.next_in += uDoCopy;
2194 pfile_in_zip_read_info->stream.total_out += uDoCopy;
2197 else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
2200 uLong uTotalOutBefore,uTotalOutAfter;
2201 const Bytef *bufBefore;
2204 pfile_in_zip_read_info->bstream.next_in = (
char*)pfile_in_zip_read_info->stream.next_in;
2205 pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
2206 pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
2207 pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
2208 pfile_in_zip_read_info->bstream.next_out = (
char*)pfile_in_zip_read_info->stream.next_out;
2209 pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
2210 pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
2211 pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
2213 uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
2214 bufBefore = (
const Bytef *)pfile_in_zip_read_info->bstream.next_out;
2216 err = BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
2218 uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
2219 uOutThis = uTotalOutAfter-uTotalOutBefore;
2221 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
2223 pfile_in_zip_read_info->crc32 =
2224 crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
2225 pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
2226 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
2228 pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
2229 pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
2230 pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
2231 pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
2232 pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
2233 pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
2235 if (err==BZ_STREAM_END)
2237 return (iRead==0) ? UNZ_EOF : iRead;
2247 ZPOS64_T uTotalOutBefore,uTotalOutAfter;
2248 const Bytef *bufBefore;
2250 int flush = Z_SYNC_FLUSH;
2252 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
2253 bufBefore = pfile_in_zip_read_info->stream.next_out;
2261 err = inflate(&pfile_in_zip_read_info->stream,flush);
2263 if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
2268 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
2269 uOutThis = uTotalOutAfter-uTotalOutBefore;
2271 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
2273 pfile_in_zip_read_info->crc32 =
2274 crc32(pfile_in_zip_read_info->crc32,bufBefore,
2277 pfile_in_zip_read_info->rest_read_uncompressed -=
2280 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
2282 if (err==Z_STREAM_END)
2284 return (iRead==0) ? UNZ_EOF : iRead;
2304 extern z_off_t MINIZIP_API unztell (unzFile file)
2310 return UNZ_PARAMERROR;
2313 pfile_in_zip_read_info = s->pfile_in_zip_read;
2315 if (pfile_in_zip_read_info==NULL)
2317 return UNZ_PARAMERROR;
2320 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
2323 extern ZPOS64_T MINIZIP_API unztell64 (unzFile file)
2330 return (ZPOS64_T)-1;
2333 pfile_in_zip_read_info = s->pfile_in_zip_read;
2335 if (pfile_in_zip_read_info==NULL)
2337 return (ZPOS64_T)-1;
2340 return pfile_in_zip_read_info->total_out_64;
2347 extern MINIZIP_API
int unzeof (unzFile file)
2353 return UNZ_PARAMERROR;
2356 pfile_in_zip_read_info = s->pfile_in_zip_read;
2358 if (pfile_in_zip_read_info==NULL)
2360 return UNZ_PARAMERROR;
2363 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2387 extern MINIZIP_API
int unzGetLocalExtrafield (unzFile file, voidp buf,
unsigned len)
2392 ZPOS64_T size_to_read;
2396 return UNZ_PARAMERROR;
2399 pfile_in_zip_read_info = s->pfile_in_zip_read;
2401 if (pfile_in_zip_read_info==NULL)
2403 return UNZ_PARAMERROR;
2406 size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
2407 pfile_in_zip_read_info->pos_local_extrafield);
2411 return (
int)size_to_read;
2414 if (len>size_to_read)
2416 read_now = (uInt)size_to_read;
2420 read_now = (uInt)len;
2428 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
2429 pfile_in_zip_read_info->filestream,
2430 pfile_in_zip_read_info->offset_local_extrafield +
2431 pfile_in_zip_read_info->pos_local_extrafield,
2432 ZLIB_FILEFUNC_SEEK_SET)!=0)
2437 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
2438 pfile_in_zip_read_info->filestream,
2439 buf,read_now)!=read_now)
2444 return (
int)read_now;
2451 extern MINIZIP_API
int unzCloseCurrentFile (unzFile file)
2459 return UNZ_PARAMERROR;
2462 pfile_in_zip_read_info = s->pfile_in_zip_read;
2464 if (pfile_in_zip_read_info==NULL)
2466 return UNZ_PARAMERROR;
2470 if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
2471 (!pfile_in_zip_read_info->raw))
2473 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2480 TRYFREE(pfile_in_zip_read_info->read_buffer);
2481 pfile_in_zip_read_info->read_buffer = NULL;
2482 if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
2484 inflateEnd(&pfile_in_zip_read_info->stream);
2487 else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
2489 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2494 pfile_in_zip_read_info->stream_initialised = 0;
2495 TRYFREE(pfile_in_zip_read_info);
2497 s->pfile_in_zip_read = NULL;
2508 extern MINIZIP_API
int unzGetGlobalComment (unzFile file,
char * szComment, uLong uSizeBuf)
2514 return (
int)UNZ_PARAMERROR;
2518 uReadThis = uSizeBuf;
2519 if (uReadThis>s->gi.size_comment)
2521 uReadThis = s->gi.size_comment;
2524 if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
2532 if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
2538 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
2540 *(szComment+s->gi.size_comment) =
'\0';
2542 return (
int)uReadThis;
2546 extern ZPOS64_T MINIZIP_API unzGetOffset64(unzFile file)
2555 if (!s->current_file_ok)
2559 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
2561 if (s->num_file==s->gi.number_entry)
2566 return s->pos_in_central_dir;
2569 extern uLong MINIZIP_API unzGetOffset (unzFile file)
2577 offset64 = unzGetOffset64(file);
2578 return (uLong)offset64;
2581 extern MINIZIP_API
int unzSetOffset64(unzFile file, ZPOS64_T pos)
2588 return UNZ_PARAMERROR;
2592 s->pos_in_central_dir = pos;
2593 s->num_file = s->gi.number_entry;
2594 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
2595 &s->cur_file_info_internal,
2596 NULL,0,NULL,0,NULL,0);
2597 s->current_file_ok = (err == UNZ_OK);
2601 extern MINIZIP_API
int unzSetOffset (unzFile file, uLong pos)
2603 return unzSetOffset64(file,pos);