199
202
voidpf filestream,
202
local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
203
const zlib_filefunc_def* pzlib_filefunc_def;
206
local int unzlocal_getShort (
207
const zlib_filefunc_def* pzlib_filefunc_def,
211
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
215
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
215
err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
219
err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
221
x += ((uLong) i) << 8;
225
local int unzlocal_getLong OF((
226
const zlib_filefunc_def* pzlib_filefunc_def,
230
local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
231
const zlib_filefunc_def* pzlib_filefunc_def;
232
local int unzlocal_getLong OF ((
233
const zlib_filefunc_def* pzlib_filefunc_def,
238
local int unzlocal_getLong (const zlib_filefunc_def* pzlib_filefunc_def,
239
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
243
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
247
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
251
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
246
err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
250
err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
252
x += ((uLong)i) << 8;
255
err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
257
x += ((uLong)i) << 16;
260
err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
262
x += ((uLong)i) << 24;
262
273
/* My own strcmpi / strcasecmp */
263
local int strcmpcasenosensitive_internal (fileName1,fileName2)
264
const char* fileName1;
265
const char* fileName2;
274
local int strcmpcasenosensitive_internal (
275
const char* fileName1,
276
const char* fileName2)
269
char c1=*(fileName1++);
270
char c2=*(fileName2++);
271
if ((c1>='a') && (c1<='z'))
273
if ((c2>='a') && (c2<='z'))
276
return ((c2=='\0') ? 0 : -1);
280
char c1 = *(fileName1++);
281
char c2 = *(fileName2++);
283
if ((c1 >= 'a') && (c1 <= 'z'))
286
if ((c2 >= 'a') && (c2 <= 'z'))
290
return ((c2 == '\0') ? 0 : -1);
329
346
const zlib_filefunc_def* pzlib_filefunc_def,
330
347
voidpf filestream));
332
local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
333
const zlib_filefunc_def* pzlib_filefunc_def;
349
local uLong unzlocal_SearchCentralDir (const zlib_filefunc_def* pzlib_filefunc_def,
339
uLong uMaxBack=0xffff; /* maximum size of global comment */
342
if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
346
uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
348
if (uMaxBack>uSizeFile)
349
uMaxBack = uSizeFile;
351
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
356
while (uBackRead<uMaxBack)
355
uLong uMaxBack = 0xffff; // maximum size of global comment
358
if (ZSEEK (*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0)
362
uSizeFile = ZTELL (*pzlib_filefunc_def, filestream);
364
if (uMaxBack > uSizeFile)
365
uMaxBack = uSizeFile;
367
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
374
while (uBackRead < uMaxBack)
358
376
uLong uReadSize,uReadPos ;
360
if (uBackRead+BUFREADCOMMENT>uMaxBack)
378
if (uBackRead + BUFREADCOMMENT > uMaxBack)
361
379
uBackRead = uMaxBack;
363
uBackRead+=BUFREADCOMMENT;
364
uReadPos = uSizeFile-uBackRead ;
366
uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
367
(BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
368
if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
371
if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
374
for (i=(int)uReadSize-3; (i--)>0;)
375
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
376
((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
381
uBackRead += BUFREADCOMMENT;
382
uReadPos = uSizeFile - uBackRead ;
384
uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) ?
385
(BUFREADCOMMENT + 4) : (uSizeFile - uReadPos);
386
if (ZSEEK(*pzlib_filefunc_def, filestream, uReadPos, ZLIB_FILEFUNC_SEEK_SET) != 0)
389
if (ZREAD(*pzlib_filefunc_def, filestream, buf, uReadSize) != uReadSize)
392
for (i = (int)uReadSize - 3; (i--) > 0;)
393
if (((*(buf + i)) == 0x50) && ((*(buf + i + 1)) == 0x4b) &&
394
((*(buf + i + 2)) == 0x05) && ((*(buf + i + 3)) == 0x06))
378
uPosFound = uReadPos+i;
396
uPosFound = uReadPos+i;
395
415
Else, the return value is a unzFile Handle, usable with other function
396
416
of this unzip package.
398
extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
400
zlib_filefunc_def* pzlib_filefunc_def;
418
extern unzFile ZEXPORT unzOpen2 (const char *path,
419
zlib_filefunc_def* pzlib_filefunc_def)
404
uLong central_pos,uL;
423
uLong central_pos,uL;
406
uLong number_disk; /* number of the current dist, used for
425
uLong number_disk; /* number of the current dist, used for
407
426
spaning ZIP, unsupported, always 0*/
408
uLong number_disk_with_CD; /* number the the disk with central dir, used
427
uLong number_disk_with_CD; /* number the the disk with central dir, used
409
428
for spaning ZIP, unsupported, always 0*/
410
uLong number_entry_CD; /* total number of entries in
429
uLong number_entry_CD; /* total number of entries in
412
431
(same than number_entry on nospan) */
416
if (unz_copyright[0]!=' ')
419
if (pzlib_filefunc_def==NULL)
420
fill_fopen_filefunc(&us.z_filefunc);
435
if (unz_copyright[0] != ' ')
438
if (! pzlib_filefunc_def)
439
fill_fopen_filefunc (&us.z_filefunc);
422
441
us.z_filefunc = *pzlib_filefunc_def;
424
us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
426
ZLIB_FILEFUNC_MODE_READ |
427
ZLIB_FILEFUNC_MODE_EXISTING);
428
if (us.filestream==NULL)
431
central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
435
if (ZSEEK(us.z_filefunc, us.filestream,
436
central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
439
/* the signature, already checked */
440
if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
443
/* number of this disk */
444
if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
447
/* number of the disk with the start of the central directory */
448
if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
451
/* total number of entries in the central dir on this disk */
452
if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
455
/* total number of entries in the central dir */
456
if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
459
if ((number_entry_CD!=us.gi.number_entry) ||
460
(number_disk_with_CD!=0) ||
464
/* size of the central directory */
465
if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
443
us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
445
ZLIB_FILEFUNC_MODE_READ |
446
ZLIB_FILEFUNC_MODE_EXISTING);
450
central_pos = unzlocal_SearchCentralDir (&us.z_filefunc, us.filestream);
451
if (central_pos == 0)
454
if (ZSEEK(us.z_filefunc,
457
ZLIB_FILEFUNC_SEEK_SET) != 0)
460
// the signature, already checked
461
if (unzlocal_getLong (&us.z_filefunc, us.filestream, &uL) != UNZ_OK)
464
// number of this disk
465
if (unzlocal_getShort (&us.z_filefunc, us.filestream, &number_disk) != UNZ_OK)
468
// number of the disk with the start of the central directory
469
if (unzlocal_getShort (&us.z_filefunc, us.filestream, &number_disk_with_CD) != UNZ_OK)
472
// total number of entries in the central dir on this disk
473
if (unzlocal_getShort (&us.z_filefunc, us.filestream, &us.gi.number_entry) != UNZ_OK)
476
// total number of entries in the central dir
477
if (unzlocal_getShort (&us.z_filefunc, us.filestream, &number_entry_CD) != UNZ_OK)
480
if ((number_entry_CD != us.gi.number_entry) ||
481
(number_disk_with_CD != 0) ||
483
err = UNZ_BADZIPFILE;
485
// size of the central directory
486
if (unzlocal_getLong (&us.z_filefunc, us.filestream, &us.size_central_dir) != UNZ_OK)
468
489
/* offset of start of central directory with respect to the
469
490
starting disk number */
470
if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
473
/* zipfile comment length */
474
if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
477
if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
483
ZCLOSE(us.z_filefunc, us.filestream);
487
us.byte_before_the_zipfile = central_pos -
488
(us.offset_central_dir+us.size_central_dir);
491
if (unzlocal_getLong (&us.z_filefunc, us.filestream, &us.offset_central_dir) != UNZ_OK)
494
//zipfile comment length
495
if (unzlocal_getShort (&us.z_filefunc, us.filestream, &us.gi.size_comment) != UNZ_OK)
498
if ((central_pos < us.offset_central_dir+us.size_central_dir) && (err == UNZ_OK))
499
err = UNZ_BADZIPFILE;
503
ZCLOSE (us.z_filefunc, us.filestream);
507
us.byte_before_the_zipfile = central_pos - (us.offset_central_dir + us.size_central_dir);
489
508
us.central_pos = central_pos;
490
509
us.pfile_in_zip_read = NULL;
491
510
us.encrypted = 0;
494
s=(unz_s*)ALLOC(sizeof(unz_s));
496
unzGoToFirstFile((unzFile)s);
512
s = (unz_s*)ALLOC (sizeof (unz_s));
514
unzGoToFirstFile ((unzFile)s);
497
515
return (unzFile)s;
501
extern unzFile ZEXPORT unzOpen (path)
519
extern unzFile ZEXPORT unzOpen (const char *path)
504
return unzOpen2(path, NULL);
521
return unzOpen2(path, NULL);
576
590
uLong commentBufferSize));
578
local int unzlocal_GetCurrentFileInfoInternal (file,
581
szFileName, fileNameBufferSize,
582
extraField, extraFieldBufferSize,
583
szComment, commentBufferSize)
585
unz_file_info *pfile_info;
586
unz_file_info_internal *pfile_info_internal;
588
uLong fileNameBufferSize;
590
uLong extraFieldBufferSize;
592
uLong commentBufferSize;
592
local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
593
unz_file_info *pfile_info,
594
unz_file_info_internal *pfile_info_internal,
596
uLong fileNameBufferSize,
598
uLong extraFieldBufferSize,
600
uLong commentBufferSize)
595
unz_file_info file_info;
596
unz_file_info_internal file_info_internal;
602
return UNZ_PARAMERROR;
604
if (ZSEEK(s->z_filefunc, s->filestream,
605
s->pos_in_central_dir+s->byte_before_the_zipfile,
606
ZLIB_FILEFUNC_SEEK_SET)!=0)
610
/* we check the magic */
612
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
614
else if (uMagic!=0x02014b50)
618
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
621
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
624
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
627
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
630
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
633
unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
635
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
638
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
641
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
644
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
647
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
650
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
653
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
656
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
659
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
662
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
665
lSeek+=file_info.size_filename;
666
if ((err==UNZ_OK) && (szFileName!=NULL))
669
if (file_info.size_filename<fileNameBufferSize)
671
*(szFileName+file_info.size_filename)='\0';
672
uSizeRead = file_info.size_filename;
675
uSizeRead = fileNameBufferSize;
677
if ((file_info.size_filename>0) && (fileNameBufferSize>0))
678
if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
684
if ((err==UNZ_OK) && (extraField!=NULL))
687
if (file_info.size_file_extra<extraFieldBufferSize)
688
uSizeRead = file_info.size_file_extra;
690
uSizeRead = extraFieldBufferSize;
693
if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
698
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
699
if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
603
return UNZ_PARAMERROR;
606
unz_file_info file_info;
607
unz_file_info_internal file_info_internal;
614
if (ZSEEK(s->z_filefunc, s->filestream,
615
s->pos_in_central_dir + s->byte_before_the_zipfile,
616
ZLIB_FILEFUNC_SEEK_SET) != 0)
620
// we check the magic
623
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK)
626
if (uMagic != 0x02014b50)
627
err = UNZ_BADZIPFILE;
630
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.version) != UNZ_OK)
633
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.version_needed) != UNZ_OK)
636
if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.flag) != UNZ_OK)
639
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.compression_method) != UNZ_OK)
642
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.dosDate) != UNZ_OK)
645
unzlocal_DosDateToTmuDate (file_info.dosDate, &file_info.tmu_date);
647
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.crc) != UNZ_OK)
650
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.compressed_size) != UNZ_OK)
653
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.uncompressed_size) != UNZ_OK)
656
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.size_filename) != UNZ_OK)
659
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.size_file_extra) != UNZ_OK)
662
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.size_file_comment) != UNZ_OK)
665
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.disk_num_start) != UNZ_OK)
668
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.internal_fa) != UNZ_OK)
671
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.external_fa) != UNZ_OK)
674
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info_internal.offset_curfile) != UNZ_OK)
677
lSeek += file_info.size_filename;
679
if ((err == UNZ_OK) && szFileName)
683
if (file_info.size_filename < fileNameBufferSize)
685
*(szFileName + file_info.size_filename) = '\0';
686
uSizeRead = file_info.size_filename;
689
uSizeRead = fileNameBufferSize;
691
if ((file_info.size_filename > 0) && (fileNameBufferSize > 0))
692
if (ZREAD(s->z_filefunc, s->filestream, szFileName, uSizeRead) != uSizeRead)
699
if ((err == UNZ_OK) && extraField)
703
if (file_info.size_file_extra < extraFieldBufferSize)
704
uSizeRead = file_info.size_file_extra;
706
uSizeRead = extraFieldBufferSize;
710
if (ZSEEK (s->z_filefunc, s->filestream, lSeek, ZLIB_FILEFUNC_SEEK_CUR) == 0)
716
if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0))
717
if (ZREAD (s->z_filefunc, s->filestream, extraField, uSizeRead) != uSizeRead)
701
719
lSeek += file_info.size_file_extra - uSizeRead;
704
lSeek+=file_info.size_file_extra;
707
if ((err==UNZ_OK) && (szComment!=NULL))
710
if (file_info.size_file_comment<commentBufferSize)
712
*(szComment+file_info.size_file_comment)='\0';
713
uSizeRead = file_info.size_file_comment;
716
uSizeRead = commentBufferSize;
719
if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
724
if ((file_info.size_file_comment>0) && (commentBufferSize>0))
725
if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
727
lSeek+=file_info.size_file_comment - uSizeRead;
730
lSeek+=file_info.size_file_comment;
732
if ((err==UNZ_OK) && (pfile_info!=NULL))
733
*pfile_info=file_info;
735
if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
736
*pfile_info_internal=file_info_internal;
722
lSeek += file_info.size_file_extra;
725
if ((err == UNZ_OK) && szComment)
728
if (file_info.size_file_comment < commentBufferSize)
730
*(szComment + file_info.size_file_comment) = '\0';
731
uSizeRead = file_info.size_file_comment;
734
uSizeRead = commentBufferSize;
738
if (ZSEEK(s->z_filefunc, s->filestream, lSeek, ZLIB_FILEFUNC_SEEK_CUR) == 0)
744
if ((file_info.size_file_comment > 0) && (commentBufferSize > 0))
745
if (ZREAD(s->z_filefunc, s->filestream, szComment, uSizeRead) != uSizeRead)
748
lSeek += file_info.size_file_comment - uSizeRead;
751
lSeek += file_info.size_file_comment;
753
if ((err == UNZ_OK) && pfile_info)
754
*pfile_info = file_info;
756
if ((err == UNZ_OK) && pfile_info_internal)
757
*pfile_info_internal = file_info_internal;
745
766
No preparation of the structure is needed
746
767
return UNZ_OK if there is no problem.
748
extern int ZEXPORT unzGetCurrentFileInfo (file,
750
szFileName, fileNameBufferSize,
751
extraField, extraFieldBufferSize,
752
szComment, commentBufferSize)
754
unz_file_info *pfile_info;
756
uLong fileNameBufferSize;
758
uLong extraFieldBufferSize;
760
uLong commentBufferSize;
769
extern int ZEXPORT unzGetCurrentFileInfo (
771
unz_file_info *pfile_info,
773
uLong fileNameBufferSize,
775
uLong extraFieldBufferSize,
777
uLong commentBufferSize)
762
return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
763
szFileName,fileNameBufferSize,
764
extraField,extraFieldBufferSize,
765
szComment,commentBufferSize);
779
return unzlocal_GetCurrentFileInfoInternal (file,
785
extraFieldBufferSize,
769
792
Set the current file of the zipfile to the first file.
770
793
return UNZ_OK if there is no problem
772
extern int ZEXPORT unzGoToFirstFile (file)
795
extern int ZEXPORT unzGoToFirstFile (unzFile file)
778
return UNZ_PARAMERROR;
780
s->pos_in_central_dir=s->offset_central_dir;
782
err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
798
return UNZ_PARAMERROR;
803
s->pos_in_central_dir = s->offset_central_dir;
805
err = unzlocal_GetCurrentFileInfoInternal (file, &s->cur_file_info,
783
806
&s->cur_file_info_internal,
784
NULL,0,NULL,0,NULL,0);
807
NULL, 0, NULL, 0, NULL, 0);
785
808
s->current_file_ok = (err == UNZ_OK);
825
853
UNZ_OK if the file is found. It becomes the current file.
826
854
UNZ_END_OF_LIST_OF_FILE if the file is not found
828
extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
830
const char *szFileName;
831
int iCaseSensitivity;
856
extern int ZEXPORT unzLocateFile (unzFile file,
857
const char *szFileName,
858
int iCaseSensitivity)
861
return UNZ_PARAMERROR;
836
866
/* We remember the 'current' position in the file so that we can jump
837
867
* back there if we fail.
839
unz_file_info cur_file_infoSaved;
840
unz_file_info_internal cur_file_info_internalSaved;
842
uLong pos_in_central_dirSaved;
846
return UNZ_PARAMERROR;
848
if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
849
return UNZ_PARAMERROR;
852
if (!s->current_file_ok)
853
return UNZ_END_OF_LIST_OF_FILE;
869
unz_file_info cur_file_infoSaved;
870
unz_file_info_internal cur_file_info_internalSaved;
872
uLong pos_in_central_dirSaved;
874
if (strlen (szFileName) >= UNZ_MAXFILENAMEINZIP)
875
return UNZ_PARAMERROR;
879
if (! s->current_file_ok)
880
return UNZ_END_OF_LIST_OF_FILE;
855
882
/* Save the current state */
856
num_fileSaved = s->num_file;
857
pos_in_central_dirSaved = s->pos_in_central_dir;
858
cur_file_infoSaved = s->cur_file_info;
859
cur_file_info_internalSaved = s->cur_file_info_internal;
861
err = unzGoToFirstFile(file);
863
while (err == UNZ_OK)
865
char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
866
err = unzGetCurrentFileInfo(file,NULL,
867
szCurrentFileName,sizeof(szCurrentFileName)-1,
883
num_fileSaved = s->num_file;
884
pos_in_central_dirSaved = s->pos_in_central_dir;
885
cur_file_infoSaved = s->cur_file_info;
886
cur_file_info_internalSaved = s->cur_file_info_internal;
888
err = unzGoToFirstFile(file);
890
while (err == UNZ_OK)
871
if (unzStringFileNameCompare(szCurrentFileName,
872
szFileName,iCaseSensitivity)==0)
892
char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1];
893
err = unzGetCurrentFileInfo (file,
895
szCurrentFileName, sizeof( szCurrentFileName) - 1,
900
if (unzStringFileNameCompare (szCurrentFileName,
901
szFileName, iCaseSensitivity) == 0)
874
904
err = unzGoToNextFile(file);
878
908
/* We failed, so restore the state of the 'current file' to where we
881
s->num_file = num_fileSaved ;
882
s->pos_in_central_dir = pos_in_central_dirSaved ;
883
s->cur_file_info = cur_file_infoSaved;
884
s->cur_file_info_internal = cur_file_info_internalSaved;
911
s->num_file = num_fileSaved ;
912
s->pos_in_central_dir = pos_in_central_dirSaved ;
913
s->cur_file_info = cur_file_infoSaved;
914
s->cur_file_info_internal = cur_file_info_internalSaved;
907
extern int ZEXPORT unzGetFilePos(file, file_pos)
909
unz_file_pos* file_pos;
937
extern int ZEXPORT unzGetFilePos (unzFile file,
938
unz_file_pos *file_pos)
913
if (file==NULL || file_pos==NULL)
914
return UNZ_PARAMERROR;
916
if (!s->current_file_ok)
917
return UNZ_END_OF_LIST_OF_FILE;
919
file_pos->pos_in_zip_directory = s->pos_in_central_dir;
920
file_pos->num_of_file = s->num_file;
940
if (! file || ! file_pos)
941
return UNZ_PARAMERROR;
943
unz_s* s = (unz_s*) file;
945
if (! s->current_file_ok)
946
return UNZ_END_OF_LIST_OF_FILE;
948
file_pos->pos_in_zip_directory = s->pos_in_central_dir;
949
file_pos->num_of_file = s->num_file;
925
extern int ZEXPORT unzGoToFilePos(file, file_pos)
927
unz_file_pos* file_pos;
955
extern int ZEXPORT unzGoToFilePos (unzFile file,
956
unz_file_pos *file_pos)
932
if (file==NULL || file_pos==NULL)
933
return UNZ_PARAMERROR;
936
/* jump to the right spot */
937
s->pos_in_central_dir = file_pos->pos_in_zip_directory;
938
s->num_file = file_pos->num_of_file;
940
/* set the current file */
941
err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
942
&s->cur_file_info_internal,
943
NULL,0,NULL,0,NULL,0);
945
s->current_file_ok = (err == UNZ_OK);
959
if (! file || ! file_pos)
960
return UNZ_PARAMERROR;
962
unz_s *s=(unz_s*)file;
966
// jump to the right spot
967
s->pos_in_central_dir = file_pos->pos_in_zip_directory;
968
s->num_file = file_pos->num_of_file;
970
// set the current file
971
err = unzlocal_GetCurrentFileInfoInternal (file, &s->cur_file_info,
972
&s->cur_file_info_internal,
973
NULL, 0, NULL, 0, NULL, 0);
974
s->current_file_ok = (err == UNZ_OK);
958
987
store in *piSizeVar the size of extra info in local header
959
988
(filename and size of extra field data)
961
local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
962
poffset_local_extrafield,
963
psize_local_extrafield)
966
uLong *poffset_local_extrafield;
967
uInt *psize_local_extrafield;
990
local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s *s,
992
uLong *poffset_local_extrafield,
993
uInt *psize_local_extrafield)
969
uLong uMagic,uData,uFlags;
971
uLong size_extra_field;
975
*poffset_local_extrafield = 0;
976
*psize_local_extrafield = 0;
978
if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
979
s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
984
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
986
else if (uMagic!=0x04034b50)
990
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
995
uLong uMagic,uData,uFlags;
997
uLong size_extra_field;
1001
*poffset_local_extrafield = 0;
1002
*psize_local_extrafield = 0;
1004
if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
1005
s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
1011
if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1014
if (uMagic != 0x04034b50)
1015
err = UNZ_BADZIPFILE;
1018
if (unzlocal_getShort (&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
993
1021
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
994
1022
err=UNZ_BADZIPFILE;
996
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
999
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1001
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1004
if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1005
(s->cur_file_info.compression_method!=Z_DEFLATED))
1008
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1011
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1013
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1017
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1019
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1023
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1025
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1030
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1032
else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1035
*piSizeVar += (uInt)size_filename;
1037
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1039
*poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1040
SIZEZIPLOCALHEADER + size_filename;
1041
*psize_local_extrafield = (uInt)size_extra_field;
1043
*piSizeVar += (uInt)size_extra_field;
1024
if (unzlocal_getShort (&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
1027
if (unzlocal_getShort (&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1030
if ((err == UNZ_OK) && (uData != s->cur_file_info.compression_method))
1031
err = UNZ_BADZIPFILE;
1033
if ((err == UNZ_OK) && (s->cur_file_info.compression_method != 0) &&
1034
(s->cur_file_info.compression_method != Z_DEFLATED))
1035
err = UNZ_BADZIPFILE;
1037
if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1040
if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1043
if ((err == UNZ_OK) && (uData != s->cur_file_info.crc) &&
1044
((uFlags & 8) == 0))
1045
err = UNZ_BADZIPFILE;
1047
if (unzlocal_getLong (&s->z_filefunc, s->filestream, &uData) != UNZ_OK) // size compr
1050
if ((err == UNZ_OK) && (uData != s->cur_file_info.compressed_size) &&
1051
((uFlags & 8) == 0))
1052
err = UNZ_BADZIPFILE;
1054
if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uData) != UNZ_OK) // size uncompr
1057
if ((err == UNZ_OK) && (uData != s->cur_file_info.uncompressed_size) &&
1058
((uFlags & 8) == 0))
1059
err = UNZ_BADZIPFILE;
1062
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &size_filename) != UNZ_OK)
1065
if ((err == UNZ_OK) && (size_filename != s->cur_file_info.size_filename))
1066
err = UNZ_BADZIPFILE;
1068
*piSizeVar += (uInt)size_filename;
1070
if (unzlocal_getShort (&s->z_filefunc, s->filestream, &size_extra_field) != UNZ_OK)
1073
*poffset_local_extrafield = s->cur_file_info_internal.offset_curfile +
1074
SIZEZIPLOCALHEADER + size_filename;
1075
*psize_local_extrafield = (uInt)size_extra_field;
1077
*piSizeVar += (uInt)size_extra_field;
1049
1083
Open for reading data the current file in the zipfile.
1050
1084
If there is no error and the file is opened, the return value is UNZ_OK.
1052
extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1057
const char* password;
1086
extern int ZEXPORT unzOpenCurrentFile3 (unzFile file,
1090
const char *password)
1062
file_in_zip_read_info_s* pfile_in_zip_read_info;
1063
uLong offset_local_extrafield; /* offset of the local extra field */
1064
uInt size_local_extrafield; /* size of the local extra field */
1068
if (password != NULL)
1069
return UNZ_PARAMERROR;
1073
return UNZ_PARAMERROR;
1075
if (!s->current_file_ok)
1076
return UNZ_PARAMERROR;
1078
if (s->pfile_in_zip_read != NULL)
1079
unzCloseCurrentFile(file);
1081
if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1082
&offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1083
return UNZ_BADZIPFILE;
1085
pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1086
ALLOC(sizeof(file_in_zip_read_info_s));
1087
if (pfile_in_zip_read_info==NULL)
1088
return UNZ_INTERNALERROR;
1090
pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1091
pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1092
pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1093
pfile_in_zip_read_info->pos_local_extrafield=0;
1094
pfile_in_zip_read_info->raw=raw;
1096
if (pfile_in_zip_read_info->read_buffer==NULL)
1098
TRYFREE(pfile_in_zip_read_info);
1099
return UNZ_INTERNALERROR;
1102
pfile_in_zip_read_info->stream_initialised=0;
1105
*method = (int)s->cur_file_info.compression_method;
1110
switch (s->cur_file_info.flag & 0x06)
1112
case 6 : *level = 1; break;
1113
case 4 : *level = 2; break;
1114
case 2 : *level = 9; break;
1118
if ((s->cur_file_info.compression_method!=0) &&
1119
(s->cur_file_info.compression_method!=Z_DEFLATED))
1122
pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1123
pfile_in_zip_read_info->crc32=0;
1124
pfile_in_zip_read_info->compression_method =
1125
s->cur_file_info.compression_method;
1126
pfile_in_zip_read_info->filestream=s->filestream;
1127
pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1128
pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1130
pfile_in_zip_read_info->stream.total_out = 0;
1132
if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1093
return UNZ_PARAMERROR;
1098
file_in_zip_read_info_s *pfile_in_zip_read_info;
1099
uLong offset_local_extrafield; /* offset of the local extra field */
1100
uInt size_local_extrafield; /* size of the local extra field */
1106
return UNZ_PARAMERROR;
1110
if (! s->current_file_ok)
1111
return UNZ_PARAMERROR;
1113
if (s->pfile_in_zip_read)
1114
unzCloseCurrentFile(file);
1116
if (unzlocal_CheckCurrentFileCoherencyHeader (s, &iSizeVar,
1117
&offset_local_extrafield, &size_local_extrafield) != UNZ_OK)
1118
return UNZ_BADZIPFILE;
1120
pfile_in_zip_read_info = (file_in_zip_read_info_s*) ALLOC(sizeof (file_in_zip_read_info_s));
1122
if (! pfile_in_zip_read_info)
1123
return UNZ_INTERNALERROR;
1125
pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1126
pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1127
pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1128
pfile_in_zip_read_info->pos_local_extrafield = 0;
1129
pfile_in_zip_read_info->raw = raw;
1131
if (! pfile_in_zip_read_info->read_buffer)
1133
TRYFREE (pfile_in_zip_read_info);
1134
return UNZ_INTERNALERROR;
1137
pfile_in_zip_read_info->stream_initialised=0;
1140
*method = (int)s->cur_file_info.compression_method;
1145
switch (s->cur_file_info.flag & 0x06)
1147
case 6: *level = 1; break;
1148
case 4: *level = 2; break;
1149
case 2: *level = 9; break;
1153
if ((s->cur_file_info.compression_method != 0) &&
1154
(s->cur_file_info.compression_method != Z_DEFLATED))
1157
pfile_in_zip_read_info->crc32_wait = s->cur_file_info.crc;
1158
pfile_in_zip_read_info->crc32 = 0;
1159
pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
1160
pfile_in_zip_read_info->filestream = s->filestream;
1161
pfile_in_zip_read_info->z_filefunc = s->z_filefunc;
1162
pfile_in_zip_read_info->byte_before_the_zipfile = s->byte_before_the_zipfile;
1164
pfile_in_zip_read_info->stream.total_out = 0;
1166
if ((s->cur_file_info.compression_method == Z_DEFLATED) &&
1135
1169
pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1136
1170
pfile_in_zip_read_info->stream.zfree = (free_func)0;
1137
1171
pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1138
1172
pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1139
1173
pfile_in_zip_read_info->stream.avail_in = 0;
1141
err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1175
err = inflateInit2 (&pfile_in_zip_read_info->stream, -MAX_WBITS);
1142
1177
if (err == Z_OK)
1143
pfile_in_zip_read_info->stream_initialised=1;
1178
pfile_in_zip_read_info->stream_initialised = 1;
1146
TRYFREE(pfile_in_zip_read_info);
1181
TRYFREE (pfile_in_zip_read_info);
1149
1184
/* windowBits is passed < 0 to tell that there is no zlib header.
1150
1185
* Note that in this case inflate *requires* an extra "dummy" byte
1151
1186
* after the compressed stream in order to complete decompression and
1153
1188
* In unzip, i don't wait absolutely Z_STREAM_END because I known the
1154
1189
* size of both compressed and uncompressed data
1157
pfile_in_zip_read_info->rest_read_compressed =
1158
s->cur_file_info.compressed_size ;
1159
pfile_in_zip_read_info->rest_read_uncompressed =
1160
s->cur_file_info.uncompressed_size ;
1163
pfile_in_zip_read_info->pos_in_zipfile =
1164
s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1167
pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1169
s->pfile_in_zip_read = pfile_in_zip_read_info;
1172
if (password != NULL)
1175
s->pcrc_32_tab = get_crc_table();
1176
init_keys(password,s->keys,s->pcrc_32_tab);
1177
if (ZSEEK(s->z_filefunc, s->filestream,
1178
s->pfile_in_zip_read->pos_in_zipfile +
1179
s->pfile_in_zip_read->byte_before_the_zipfile,
1181
return UNZ_INTERNALERROR;
1182
if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1183
return UNZ_INTERNALERROR;
1185
for (i = 0; i<12; i++)
1186
zdecode(s->keys,s->pcrc_32_tab,source[i]);
1188
s->pfile_in_zip_read->pos_in_zipfile+=12;
1197
extern int ZEXPORT unzOpenCurrentFile (file)
1200
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1203
extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1205
const char* password;
1207
return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1210
extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1216
return unzOpenCurrentFile3(file, method, level, raw, NULL);
1193
pfile_in_zip_read_info->rest_read_compressed = s->cur_file_info.compressed_size;
1194
pfile_in_zip_read_info->rest_read_uncompressed = s->cur_file_info.uncompressed_size;
1196
pfile_in_zip_read_info->pos_in_zipfile = s->cur_file_info_internal.offset_curfile +
1197
SIZEZIPLOCALHEADER +
1200
pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1202
s->pfile_in_zip_read = pfile_in_zip_read_info;
1209
s->pcrc_32_tab = get_crc_table();
1210
init_keys (password, s->keys, s->pcrc_32_tab);
1212
if (ZSEEK(s->z_filefunc, s->filestream,
1213
s->pfile_in_zip_read->pos_in_zipfile +
1214
s->pfile_in_zip_read->byte_before_the_zipfile,
1216
return UNZ_INTERNALERROR;
1218
if (ZREAD(s->z_filefunc, s->filestream,source, 12) < 12)
1219
return UNZ_INTERNALERROR;
1221
for (i = 0; i < 12; i++)
1222
zdecode (s->keys, s->pcrc_32_tab, source[i]);
1224
s->pfile_in_zip_read->pos_in_zipfile += 12;
1235
extern int ZEXPORT unzOpenCurrentFile (unzFile file)
1237
return unzOpenCurrentFile3 (file, NULL, NULL, 0, NULL);
1241
extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file,
1242
const char *password)
1244
return unzOpenCurrentFile3 (file, NULL, NULL, 0, password);
1248
extern int ZEXPORT unzOpenCurrentFile2 (unzFile file,
1253
return unzOpenCurrentFile3 (file, method, level, raw, NULL);
1226
1263
return <0 with error code if there is an error
1227
1264
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
1229
extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1266
extern int ZEXPORT unzReadCurrentFile (unzFile file,
1237
file_in_zip_read_info_s* pfile_in_zip_read_info;
1239
return UNZ_PARAMERROR;
1241
pfile_in_zip_read_info=s->pfile_in_zip_read;
1243
if (pfile_in_zip_read_info==NULL)
1244
return UNZ_PARAMERROR;
1247
if ((pfile_in_zip_read_info->read_buffer == NULL))
1248
return UNZ_END_OF_LIST_OF_FILE;
1252
pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1254
pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1256
if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1257
(!(pfile_in_zip_read_info->raw)))
1258
pfile_in_zip_read_info->stream.avail_out =
1259
(uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1261
if ((len>pfile_in_zip_read_info->rest_read_compressed+
1262
pfile_in_zip_read_info->stream.avail_in) &&
1263
(pfile_in_zip_read_info->raw))
1264
pfile_in_zip_read_info->stream.avail_out =
1265
(uInt)pfile_in_zip_read_info->rest_read_compressed+
1266
pfile_in_zip_read_info->stream.avail_in;
1268
while (pfile_in_zip_read_info->stream.avail_out>0)
1270
if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1271
(pfile_in_zip_read_info->rest_read_compressed>0))
1273
uInt uReadThis = UNZ_BUFSIZE;
1274
if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1275
uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1278
if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1279
pfile_in_zip_read_info->filestream,
1280
pfile_in_zip_read_info->pos_in_zipfile +
1281
pfile_in_zip_read_info->byte_before_the_zipfile,
1282
ZLIB_FILEFUNC_SEEK_SET)!=0)
1284
if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1285
pfile_in_zip_read_info->filestream,
1286
pfile_in_zip_read_info->read_buffer,
1287
uReadThis)!=uReadThis)
1271
return UNZ_PARAMERROR;
1276
file_in_zip_read_info_s *pfile_in_zip_read_info;
1278
unz_s *s = (unz_s*)file;
1279
pfile_in_zip_read_info = s->pfile_in_zip_read;
1281
if (! pfile_in_zip_read_info)
1282
return UNZ_PARAMERROR;
1284
if (! pfile_in_zip_read_info->read_buffer)
1285
return UNZ_END_OF_LIST_OF_FILE;
1290
pfile_in_zip_read_info->stream.next_out = (Bytef*) buf;
1291
pfile_in_zip_read_info->stream.avail_out = (uInt) len;
1293
if ((len > pfile_in_zip_read_info->rest_read_uncompressed) && ! pfile_in_zip_read_info->raw)
1294
pfile_in_zip_read_info->stream.avail_out = (uInt) pfile_in_zip_read_info->rest_read_uncompressed;
1296
if ((len > pfile_in_zip_read_info->rest_read_compressed +
1297
pfile_in_zip_read_info->stream.avail_in) && pfile_in_zip_read_info->raw)
1298
pfile_in_zip_read_info->stream.avail_out = (uInt) pfile_in_zip_read_info->rest_read_compressed +
1299
pfile_in_zip_read_info->stream.avail_in;
1301
while (pfile_in_zip_read_info->stream.avail_out > 0)
1303
if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1304
(pfile_in_zip_read_info->rest_read_compressed > 0))
1295
for(i=0;i<uReadThis;i++)
1296
pfile_in_zip_read_info->read_buffer[i] =
1297
zdecode(s->keys,s->pcrc_32_tab,
1298
pfile_in_zip_read_info->read_buffer[i]);
1306
uInt uReadThis = UNZ_BUFSIZE;
1308
if (pfile_in_zip_read_info->rest_read_compressed < uReadThis)
1309
uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed;
1314
if (ZSEEK (pfile_in_zip_read_info->z_filefunc,
1315
pfile_in_zip_read_info->filestream,
1316
pfile_in_zip_read_info->pos_in_zipfile +
1317
pfile_in_zip_read_info->byte_before_the_zipfile,
1318
ZLIB_FILEFUNC_SEEK_SET) != 0)
1321
if (ZREAD (pfile_in_zip_read_info->z_filefunc,
1322
pfile_in_zip_read_info->filestream,
1323
pfile_in_zip_read_info->read_buffer,
1324
uReadThis) != uReadThis)
1333
for (i = 0; i < uReadThis; i++)
1334
pfile_in_zip_read_info->read_buffer[i] = zdecode (s->keys,
1336
pfile_in_zip_read_info->read_buffer[i]);
1341
pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1342
pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
1343
pfile_in_zip_read_info->stream.next_in = (Bytef*) pfile_in_zip_read_info->read_buffer;
1344
pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1303
pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1305
pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1307
pfile_in_zip_read_info->stream.next_in =
1308
(Bytef*)pfile_in_zip_read_info->read_buffer;
1309
pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1312
if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1347
if ((pfile_in_zip_read_info->compression_method == 0) || (pfile_in_zip_read_info->raw))
1316
1351
if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1317
(pfile_in_zip_read_info->rest_read_compressed == 0))
1318
return (iRead==0) ? UNZ_EOF : iRead;
1352
(pfile_in_zip_read_info->rest_read_compressed == 0))
1353
return (iRead==0) ? UNZ_EOF : iRead;
1320
if (pfile_in_zip_read_info->stream.avail_out <
1321
pfile_in_zip_read_info->stream.avail_in)
1322
uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1355
if (pfile_in_zip_read_info->stream.avail_out < pfile_in_zip_read_info->stream.avail_in)
1356
uDoCopy = pfile_in_zip_read_info->stream.avail_out;
1324
uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1326
for (i=0;i<uDoCopy;i++)
1327
*(pfile_in_zip_read_info->stream.next_out+i) =
1328
*(pfile_in_zip_read_info->stream.next_in+i);
1330
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1331
pfile_in_zip_read_info->stream.next_out,
1333
pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1334
pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1335
pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1336
pfile_in_zip_read_info->stream.next_out += uDoCopy;
1337
pfile_in_zip_read_info->stream.next_in += uDoCopy;
1338
pfile_in_zip_read_info->stream.total_out += uDoCopy;
1358
uDoCopy = pfile_in_zip_read_info->stream.avail_in;
1360
for (i = 0; i < uDoCopy; i++)
1362
*(pfile_in_zip_read_info->stream.next_out+i) = *(pfile_in_zip_read_info->stream.next_in + i);
1365
pfile_in_zip_read_info->crc32 = crc32 (pfile_in_zip_read_info->crc32,
1366
pfile_in_zip_read_info->stream.next_out,
1368
pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
1369
pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1370
pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1371
pfile_in_zip_read_info->stream.next_out += uDoCopy;
1372
pfile_in_zip_read_info->stream.next_in += uDoCopy;
1373
pfile_in_zip_read_info->stream.total_out += uDoCopy;
1343
uLong uTotalOutBefore,uTotalOutAfter;
1344
const Bytef *bufBefore;
1346
int flush=Z_SYNC_FLUSH;
1348
uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1349
bufBefore = pfile_in_zip_read_info->stream.next_out;
1352
if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1353
pfile_in_zip_read_info->stream.avail_out) &&
1354
(pfile_in_zip_read_info->rest_read_compressed == 0))
1357
err=inflate(&pfile_in_zip_read_info->stream,flush);
1359
if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
1362
uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1363
uOutThis = uTotalOutAfter-uTotalOutBefore;
1365
pfile_in_zip_read_info->crc32 =
1366
crc32(pfile_in_zip_read_info->crc32,bufBefore,
1369
pfile_in_zip_read_info->rest_read_uncompressed -=
1372
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1374
if (err==Z_STREAM_END)
1378
uLong uTotalOutBefore, uTotalOutAfter;
1379
const Bytef *bufBefore;
1381
int flush = Z_SYNC_FLUSH;
1383
uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1384
bufBefore = pfile_in_zip_read_info->stream.next_out;
1387
if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1388
pfile_in_zip_read_info->stream.avail_out) &&
1389
(pfile_in_zip_read_info->rest_read_compressed == 0))
1392
err = inflate (&pfile_in_zip_read_info->stream,flush);
1394
if ((err >= 0) && pfile_in_zip_read_info->stream.msg)
1397
uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1398
uOutThis = uTotalOutAfter - uTotalOutBefore;
1400
pfile_in_zip_read_info->crc32 = crc32 (pfile_in_zip_read_info->crc32, bufBefore,
1403
pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
1405
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1407
if (err == Z_STREAM_END)
1375
1408
return (iRead==0) ? UNZ_EOF : iRead;
1388
Give the current position in uncompressed data
1390
extern z_off_t ZEXPORT unztell (file)
1422
// Give the current position in uncompressed data
1424
extern z_off_t ZEXPORT unztell (unzFile file)
1394
file_in_zip_read_info_s* pfile_in_zip_read_info;
1396
return UNZ_PARAMERROR;
1398
pfile_in_zip_read_info=s->pfile_in_zip_read;
1400
if (pfile_in_zip_read_info==NULL)
1401
return UNZ_PARAMERROR;
1403
return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1427
return UNZ_PARAMERROR;
1429
file_in_zip_read_info_s *pfile_in_zip_read_info;
1431
unz_s *s = (unz_s*)file;
1432
pfile_in_zip_read_info = s->pfile_in_zip_read;
1434
if (! pfile_in_zip_read_info)
1435
return UNZ_PARAMERROR;
1437
return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1408
return 1 if the end of file was reached, 0 elsewhere
1410
extern int ZEXPORT unzeof (file)
1441
//return 1 if the end of file was reached, 0 elsewhere
1443
extern int ZEXPORT unzeof (unzFile file)
1414
file_in_zip_read_info_s* pfile_in_zip_read_info;
1416
return UNZ_PARAMERROR;
1418
pfile_in_zip_read_info=s->pfile_in_zip_read;
1420
if (pfile_in_zip_read_info==NULL)
1421
return UNZ_PARAMERROR;
1423
if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1446
return UNZ_PARAMERROR;
1448
file_in_zip_read_info_s* pfile_in_zip_read_info;
1449
unz_s *s = (unz_s*)file;
1450
pfile_in_zip_read_info = s->pfile_in_zip_read;
1452
if (! pfile_in_zip_read_info)
1453
return UNZ_PARAMERROR;
1455
if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1440
1472
the return value is the number of bytes copied in buf, or (if <0)
1443
extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1475
extern int ZEXPORT unzGetLocalExtrafield (unzFile file,
1449
file_in_zip_read_info_s* pfile_in_zip_read_info;
1454
return UNZ_PARAMERROR;
1456
pfile_in_zip_read_info=s->pfile_in_zip_read;
1458
if (pfile_in_zip_read_info==NULL)
1459
return UNZ_PARAMERROR;
1461
size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1462
pfile_in_zip_read_info->pos_local_extrafield);
1465
return (int)size_to_read;
1467
if (len>size_to_read)
1468
read_now = (uInt)size_to_read;
1470
read_now = (uInt)len ;
1475
if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1476
pfile_in_zip_read_info->filestream,
1477
pfile_in_zip_read_info->offset_local_extrafield +
1478
pfile_in_zip_read_info->pos_local_extrafield,
1479
ZLIB_FILEFUNC_SEEK_SET)!=0)
1482
if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1483
pfile_in_zip_read_info->filestream,
1484
buf,read_now)!=read_now)
1487
return (int)read_now;
1480
return UNZ_PARAMERROR;
1482
file_in_zip_read_info_s* pfile_in_zip_read_info;
1486
unz_s* s = (unz_s*)file;
1487
pfile_in_zip_read_info = s->pfile_in_zip_read;
1489
if (! pfile_in_zip_read_info)
1490
return UNZ_PARAMERROR;
1492
size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1493
pfile_in_zip_read_info->pos_local_extrafield);
1496
return (int) size_to_read;
1498
if (len > size_to_read)
1499
read_now = (uInt) size_to_read;
1501
read_now = (uInt) len ;
1506
if (ZSEEK (pfile_in_zip_read_info->z_filefunc,
1507
pfile_in_zip_read_info->filestream,
1508
pfile_in_zip_read_info->offset_local_extrafield +
1509
pfile_in_zip_read_info->pos_local_extrafield,
1510
ZLIB_FILEFUNC_SEEK_SET) != 0)
1513
if (ZREAD (pfile_in_zip_read_info->z_filefunc,
1514
pfile_in_zip_read_info->filestream,
1516
read_now) != read_now)
1519
return (int)read_now;
1491
1523
Close the file in zip opened with unzipOpenCurrentFile
1492
1524
Return UNZ_CRCERROR if all the file was read but the CRC is not good
1494
extern int ZEXPORT unzCloseCurrentFile (file)
1526
extern int ZEXPORT unzCloseCurrentFile (unzFile file)
1500
file_in_zip_read_info_s* pfile_in_zip_read_info;
1502
return UNZ_PARAMERROR;
1504
pfile_in_zip_read_info=s->pfile_in_zip_read;
1506
if (pfile_in_zip_read_info==NULL)
1507
return UNZ_PARAMERROR;
1510
if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
1511
(!pfile_in_zip_read_info->raw))
1513
if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1518
TRYFREE(pfile_in_zip_read_info->read_buffer);
1519
pfile_in_zip_read_info->read_buffer = NULL;
1520
if (pfile_in_zip_read_info->stream_initialised)
1521
inflateEnd(&pfile_in_zip_read_info->stream);
1523
pfile_in_zip_read_info->stream_initialised = 0;
1524
TRYFREE(pfile_in_zip_read_info);
1526
s->pfile_in_zip_read=NULL;
1529
return UNZ_PARAMERROR;
1533
file_in_zip_read_info_s *pfile_in_zip_read_info;
1534
unz_s *s = (unz_s*) file;
1535
pfile_in_zip_read_info = s->pfile_in_zip_read;
1537
if (! pfile_in_zip_read_info)
1538
return UNZ_PARAMERROR;
1541
if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && ! pfile_in_zip_read_info->raw)
1542
if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1546
TRYFREE (pfile_in_zip_read_info->read_buffer);
1547
pfile_in_zip_read_info->read_buffer = NULL;
1549
if (pfile_in_zip_read_info->stream_initialised)
1550
inflateEnd (&pfile_in_zip_read_info->stream);
1552
pfile_in_zip_read_info->stream_initialised = 0;
1553
TRYFREE (pfile_in_zip_read_info);
1555
s->pfile_in_zip_read = NULL;