UFO: Alien Invasion
Loading...
Searching...
No Matches
unzip.cpp
Go to the documentation of this file.
1/* unzip.c -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005
3
4 Copyright (C) 1998-2005 Gilles Vollant
5
6 Read unzip.h for more info
7*/
8
9/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
10compatibility with older software. The following is from the original crypt.c. Code
11woven in by Terry Thorsen 1/2003.
12*/
13/*
14 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15
16 See the accompanying file LICENSE, version 2000-Apr-09 or later
17 (the contents of which are also included in zip.h) for terms of use.
18 If, for some reason, all these files are missing, the Info-ZIP license
19 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/
21/*
22 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
23
24 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA.
27 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */
29
30/*
31 This encryption code is a direct transcription of the algorithm from
32 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
33 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities).
35 */
36
37#include "unzip.h"
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41
42#ifdef STDC
43# include <stddef.h>
44# include <string.h>
45# include <stdlib.h>
46#endif
47#include <errno.h>
48
49
50#ifndef local
51# define local static
52#endif
53/* compile with -Dlocal if your debugger can't find static symbols */
54
55
56#ifndef CASESENSITIVITYDEFAULT_NO
57# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
58# define CASESENSITIVITYDEFAULT_NO
59# endif
60#endif
61
62
63#ifndef UNZ_BUFSIZE
64#define UNZ_BUFSIZE (16384)
65#endif
66
67#ifndef UNZ_MAXFILENAMEINZIP
68#define UNZ_MAXFILENAMEINZIP (256)
69#endif
70
71#ifndef ALLOC
72# define ALLOC(size) (malloc(size))
73#endif
74#ifndef TRYFREE
75# define TRYFREE(p) (free(p))
76#endif
77
78#define SIZECENTRALDIRITEM (0x2e)
79#define SIZEZIPLOCALHEADER (0x1e)
80
81
82
83
84const char unz_copyright[] =
85 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
86
87/* unz_file_info_interntal contain internal info about a file in zipfile*/
88typedef struct unz_file_info_internal_s
89{
90 uLong offset_curfile;/* relative offset of local header 4 bytes */
92
93
94/* file_in_zip_read_info_s contain internal information about a file in zipfile,
95 when reading and decompress it */
96typedef struct
97{
98 char *read_buffer; /* internal buffer for compressed data */
99 z_stream stream; /* zLib stream structure for inflate */
100
101 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
102 uLong stream_initialised; /* flag set if stream structure is initialised*/
103
104 uLong offset_local_extrafield;/* offset of the local extra field */
105 uInt size_local_extrafield;/* size of the local extra field */
106 uLong pos_local_extrafield; /* position in the local extra field in read*/
107
108 uLong crc32; /* crc32 of all data uncompressed */
109 uLong crc32_wait; /* crc32 we must obtain after decompress all */
110 uLong rest_read_compressed; /* number of byte to be decompressed */
111 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
113 voidpf filestream; /* io structore of the zipfile */
114 uLong compression_method; /* compression method (0==store) */
115 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sample)*/
116 int raw;
118
119
120/* unz_s contain internal information about the zipfile
121*/
122typedef struct
123{
125 voidpf filestream; /* io structore of the zipfile */
126 unz_global_info gi; /* public global information */
127 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sample)*/
128 uLong num_file; /* number of the current file in the zipfile*/
129 uLong pos_in_central_dir; /* pos of the current file in the central dir*/
130 uLong current_file_ok; /* flag about the usability of the current file*/
131 uLong central_pos; /* position of the beginning of the central dir*/
132
133 uLong size_central_dir; /* size of the central directory */
134 uLong offset_central_dir; /* offset of start of central directory with
135 respect to the starting disk number */
136
137 unz_file_info cur_file_info; /* public info about the current file in zip*/
139 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
140 file if we are decompressing it */
142# ifndef NOUNCRYPT
143 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
144 const unsigned long* pcrc_32_tab;
145# endif
146} unz_s;
147
148
149#ifndef NOUNCRYPT
150#include "crypt.h"
151#endif
152
153/* ===========================================================================
154 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
155 for end of file.
156 IN assertion: the stream s has been successfully opened for reading.
157*/
158
159
160local int unzlocal_getByte (const zlib_filefunc_def* pzlib_filefunc_def, voidpf filestream, int* pi)
161{
162 unsigned char c;
163 const int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
164 if (err==1)
165 {
166 *pi = (int)c;
167 return UNZ_OK;
168 }
169 else
170 {
171 if (ZERROR(*pzlib_filefunc_def,filestream))
172 return UNZ_ERRNO;
173 else
174 return UNZ_EOF;
175 }
176}
177
178
179/* ===========================================================================
180 Reads a long in LSB order from the given gz_stream. Sets
181*/
182local int unzlocal_getShort (const zlib_filefunc_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)
183{
184 int i = 0;
185
186 int err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
187 uLong x = (uLong)i;
188
189 if (err==UNZ_OK)
190 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
191 x += ((uLong)i)<<8;
192
193 if (err==UNZ_OK)
194 *pX = x;
195 else
196 *pX = 0;
197 return err;
198}
199
200local int unzlocal_getLong (const zlib_filefunc_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)
201{
202 int i = 0;
203
204 int err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
205 uLong x = (uLong)i;
206
207 if (err==UNZ_OK)
208 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
209 x += ((uLong)i)<<8;
210
211 if (err==UNZ_OK)
212 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
213 x += ((uLong)i)<<16;
214
215 if (err==UNZ_OK)
216 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
217 x += ((uLong)i)<<24;
218
219 if (err==UNZ_OK)
220 *pX = x;
221 else
222 *pX = 0;
223 return err;
224}
225
226
227/* My own strcmpi / strcasecmp */
228local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
229{
230 for (;;)
231 {
232 char c1=*(fileName1++);
233 char c2=*(fileName2++);
234 if ((c1>='a') && (c1<='z'))
235 c1 -= 0x20;
236 if ((c2>='a') && (c2<='z'))
237 c2 -= 0x20;
238 if (c1=='\0')
239 return ((c2=='\0') ? 0 : -1);
240 if (c2=='\0')
241 return 1;
242 if (c1<c2)
243 return -1;
244 if (c1>c2)
245 return 1;
246 }
247}
248
249
250#ifdef CASESENSITIVITYDEFAULT_NO
251#define CASESENSITIVITYDEFAULTVALUE 2
252#else
253#define CASESENSITIVITYDEFAULTVALUE 1
254#endif
255
256#ifndef STRCMPCASENOSENTIVEFUNCTION
257#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
258#endif
259
260/*
261 Compare two filename (fileName1,fileName2).
262 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
263 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
264 or strcasecmp)
265 If iCaseSenisivity = 0, case sensitivity is default of your operating system
266 (like 1 on Unix, 2 on Windows)
267
268*/
269int ZEXPORT unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity)
270{
271 if (iCaseSensitivity==0)
272 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
273
274 if (iCaseSensitivity==1)
275 return strcmp(fileName1,fileName2);
276
277 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
278}
279
280#ifndef BUFREADCOMMENT
281#define BUFREADCOMMENT (0x400)
282#endif
283
284/*
285 Locate the Central directory of a zipfile (at the end, just before
286 the global comment)
287*/
288local uLong unzlocal_SearchCentralDir (const zlib_filefunc_def* pzlib_filefunc_def, voidpf filestream)
289{
290 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
291 return 0;
292
293
294 const uLong uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
295
296 uLong uMaxBack = 0xffff; /* maximum size of global comment */
297 if (uMaxBack>uSizeFile)
298 uMaxBack = uSizeFile;
299
300 unsigned char* buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
301 if (buf==NULL)
302 return 0;
303
304 uLong uPosFound = 0;
305 uLong uBackRead = 4;
306 while (uBackRead<uMaxBack)
307 {
308 if (uBackRead+BUFREADCOMMENT>uMaxBack)
309 uBackRead = uMaxBack;
310 else
311 uBackRead+=BUFREADCOMMENT;
312 const uLong uReadPos = uSizeFile-uBackRead;
313
314 const uLong uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
315 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
316 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
317 break;
318
319 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
320 break;
321
322 for (int i=(int)uReadSize-3; (i--)>0;)
323 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
324 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
325 {
326 uPosFound = uReadPos+i;
327 break;
328 }
329
330 if (uPosFound!=0)
331 break;
332 }
333 TRYFREE(buf);
334 return uPosFound;
335}
336
337/*
338 Open a Zip file. path contain the full pathname (by example,
339 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
340 "zlib/zlib114.zip".
341 If the zipfile cannot be opened (file doesn't exist or in not valid), the
342 return value is NULL.
343 Else, the return value is a unzFile Handle, usable with other function
344 of this unzip package.
345*/
346unzFile ZEXPORT unzOpen2 (const char* path, zlib_filefunc_def* pzlib_filefunc_def)
347{
348 unz_s us;
349 uLong uL;
350
351 uLong number_disk; /* number of the current dist, used for
352 spaning ZIP, unsupported, always 0*/
353 uLong number_disk_with_CD; /* number the the disk with central dir, used
354 for spaning ZIP, unsupported, always 0*/
355 uLong number_entry_CD; /* total number of entries in
356 the central dir
357 (same than number_entry on nospan) */
358
359 int err=UNZ_OK;
360
361 if (unz_copyright[0]!=' ')
362 return NULL;
363
364 if (pzlib_filefunc_def==NULL)
366 else
367 us.z_filefunc = *pzlib_filefunc_def;
368
370 path,
373 if (us.filestream==NULL)
374 return NULL;
375
376 const uLong central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
377 if (central_pos==0)
378 err=UNZ_ERRNO;
379
380 if (ZSEEK(us.z_filefunc, us.filestream,
381 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
382 err=UNZ_ERRNO;
383
384 /* the signature, already checked */
386 err=UNZ_ERRNO;
387
388 /* number of this disk */
389 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
390 err=UNZ_ERRNO;
391
392 /* number of the disk with the start of the central directory */
393 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
394 err=UNZ_ERRNO;
395
396 /* total number of entries in the central dir on this disk */
398 err=UNZ_ERRNO;
399
400 /* total number of entries in the central dir */
401 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
402 err=UNZ_ERRNO;
403
404 if ((number_entry_CD!=us.gi.number_entry) ||
405 (number_disk_with_CD!=0) ||
406 (number_disk!=0))
407 err=UNZ_BADZIPFILE;
408
409 /* size of the central directory */
411 err=UNZ_ERRNO;
412
413 /* offset of start of central directory with respect to the
414 starting disk number */
416 err=UNZ_ERRNO;
417
418 /* zipfile comment length */
420 err=UNZ_ERRNO;
421
422 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
423 (err==UNZ_OK))
424 err=UNZ_BADZIPFILE;
425
426 if (err!=UNZ_OK)
427 {
429 return NULL;
430 }
431
432 us.byte_before_the_zipfile = central_pos -
434 us.central_pos = central_pos;
435 us.pfile_in_zip_read = NULL;
436 us.encrypted = 0;
437
438
439 unz_s* s=(unz_s*)ALLOC(sizeof(unz_s));
440 *s=us;
442 return (unzFile)s;
443}
444
445
446unzFile ZEXPORT unzOpen (const char* path)
447{
448 return unzOpen2(path, NULL);
449}
450
451/*
452 Close a ZipFile opened with unzipOpen.
453 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
454 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
455 return UNZ_OK if there is no problem. */
456int ZEXPORT unzClose (unzFile file)
457{
458 if (file==NULL)
459 return UNZ_PARAMERROR;
460 unz_s* s=(unz_s*)file;
461
462 if (s->pfile_in_zip_read!=NULL)
464
466 TRYFREE(s);
467 return UNZ_OK;
468}
469
470
471/*
472 Write info about the ZipFile in the *pglobal_info structure.
473 No preparation of the structure is needed
474 return UNZ_OK if there is no problem. */
475int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info)
476{
477 if (file==NULL)
478 return UNZ_PARAMERROR;
479 const unz_s* s=(unz_s*)file;
480 *pglobal_info=s->gi;
481 return UNZ_OK;
482}
483
484
485/*
486 Translate date/time from Dos format to tm_unz (readable more easilty)
487*/
489{
490 const uLong uDate = (uLong)(ulDosDate>>16);
491 ptm->tm_mday = (uInt)(uDate&0x1f) ;
492 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
493 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
494
495 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
496 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
497 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
498}
499
505 unzFile file,
506 unz_file_info *pfile_info,
508 *pfile_info_internal,
509 char* szFileName,
510 uLong fileNameBufferSize,
511 void* extraField,
512 uLong extraFieldBufferSize,
513 char* szComment,
514 uLong commentBufferSize));
515
516local int unzlocal_GetCurrentFileInfoInternal (unzFile file, unz_file_info *pfile_info, unz_file_info_internal *pfile_info_internal, char* szFileName, uLong fileNameBufferSize, void* extraField, uLong extraFieldBufferSize, char* szComment, uLong commentBufferSize)
517{
518 unz_file_info file_info;
519 unz_file_info_internal file_info_internal;
520 int err=UNZ_OK;
521 uLong uMagic;
522 long lSeek=0;
523
524 if (file==NULL)
525 return UNZ_PARAMERROR;
526 const unz_s* s=(unz_s*)file;
527 if (ZSEEK(s->z_filefunc, s->filestream,
530 err=UNZ_ERRNO;
531
532
533 /* we check the magic */
534 if (err==UNZ_OK) {
535 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) {
536 err=UNZ_ERRNO;
537 } else if (uMagic!=0x02014b50) {
538 err=UNZ_BADZIPFILE;
539 }
540 }
541
542 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
543 err=UNZ_ERRNO;
544
546 err=UNZ_ERRNO;
547
548 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
549 err=UNZ_ERRNO;
550
552 err=UNZ_ERRNO;
553
554 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
555 err=UNZ_ERRNO;
556
557 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
558
559 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
560 err=UNZ_ERRNO;
561
563 err=UNZ_ERRNO;
564
566 err=UNZ_ERRNO;
567
569 err=UNZ_ERRNO;
570
572 err=UNZ_ERRNO;
573
575 err=UNZ_ERRNO;
576
578 err=UNZ_ERRNO;
579
580 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
581 err=UNZ_ERRNO;
582
583 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
584 err=UNZ_ERRNO;
585
586 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
587 err=UNZ_ERRNO;
588
589 lSeek+=file_info.size_filename;
590 if ((err==UNZ_OK) && (szFileName!=NULL))
591 {
592 uLong uSizeRead;
593 if (file_info.size_filename<fileNameBufferSize) {
594 *(szFileName+file_info.size_filename)='\0';
595 uSizeRead = file_info.size_filename;
596 } else {
597 uSizeRead = fileNameBufferSize;
598 }
599 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
600 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
601 err=UNZ_ERRNO;
602 lSeek -= uSizeRead;
603 }
604
605 if ((err==UNZ_OK) && (extraField!=NULL))
606 {
607 uLong uSizeRead;
608 if (file_info.size_file_extra<extraFieldBufferSize)
609 uSizeRead = file_info.size_file_extra;
610 else
611 uSizeRead = extraFieldBufferSize;
612
613 if (lSeek!=0) {
615 lSeek=0;
616 } else {
617 err=UNZ_ERRNO;
618 }
619
620 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
621 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
622 err=UNZ_ERRNO;
623 lSeek += file_info.size_file_extra - uSizeRead;
624 } else {
625 lSeek+=file_info.size_file_extra;
626 }
627
628 if ((err==UNZ_OK) && (szComment!=NULL))
629 {
630 uLong uSizeRead;
631 if (file_info.size_file_comment<commentBufferSize) {
632 *(szComment+file_info.size_file_comment)='\0';
633 uSizeRead = file_info.size_file_comment;
634 } else {
635 uSizeRead = commentBufferSize;
636 }
637
638 if (lSeek!=0) {
640 lSeek=0;
641 } else {
642 err=UNZ_ERRNO;
643 }
644
645 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
646 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
647 err=UNZ_ERRNO;
648 lSeek+=file_info.size_file_comment - uSizeRead;
649 } else {
650 lSeek+=file_info.size_file_comment;
651 }
652
653 if ((err==UNZ_OK) && (pfile_info!=NULL))
654 *pfile_info=file_info;
655
656 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
657 *pfile_info_internal=file_info_internal;
658
659 return err;
660}
661
662
663
664/*
665 Write info about the ZipFile in the *pglobal_info structure.
666 No preparation of the structure is needed
667 return UNZ_OK if there is no problem.
668*/
669int ZEXPORT unzGetCurrentFileInfo (unzFile file, unz_file_info *pfile_info, char* szFileName, uLong fileNameBufferSize, void* extraField, uLong extraFieldBufferSize, char* szComment, uLong commentBufferSize)
670{
671 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
672 szFileName,fileNameBufferSize,
673 extraField,extraFieldBufferSize,
674 szComment,commentBufferSize);
675}
676
677/*
678 Set the current file of the zipfile to the first file.
679 return UNZ_OK if there is no problem
680*/
681int ZEXPORT unzGoToFirstFile (unzFile file)
682{
683 int err=UNZ_OK;
684 if (file==NULL)
685 return UNZ_PARAMERROR;
686 unz_s* s=(unz_s*)file;
688 s->num_file=0;
691 NULL,0,NULL,0,NULL,0);
692 s->current_file_ok = (err == UNZ_OK);
693 return err;
694}
695
696/*
697 Set the current file of the zipfile to the next file.
698 return UNZ_OK if there is no problem
699 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
700*/
701int ZEXPORT unzGoToNextFile (unzFile file)
702{
703 if (file==NULL)
704 return UNZ_PARAMERROR;
705 unz_s* s=(unz_s*)file;
706 if (!s->current_file_ok)
708 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
709 if (s->num_file+1==s->gi.number_entry)
711
714 s->num_file++;
717 NULL,0,NULL,0,NULL,0);
718 s->current_file_ok = (err == UNZ_OK);
719 return err;
720}
721
722
723/*
724 Try locate the file szFileName in the zipfile.
725 For the iCaseSensitivity signification, see unzipStringFileNameCompare
726
727 return value :
728 UNZ_OK if the file is found. It becomes the current file.
729 UNZ_END_OF_LIST_OF_FILE if the file is not found
730*/
731int ZEXPORT unzLocateFile (unzFile file, const char* szFileName, int iCaseSensitivity)
732{
733 if (file==NULL)
734 return UNZ_PARAMERROR;
735
736 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
737 return UNZ_PARAMERROR;
738
739 unz_s* s=(unz_s*)file;
740 if (!s->current_file_ok)
742
743 /* We remember the 'current' position in the file so that we can jump
744 * back there if we fail.
745 */
746 const uLong num_fileSaved = s->num_file;
747 const uLong pos_in_central_dirSaved = s->pos_in_central_dir;
748 const unz_file_info cur_file_infoSaved = s->cur_file_info;
749 const unz_file_info_internal cur_file_info_internalSaved = s->cur_file_info_internal;
750
751 int err = unzGoToFirstFile(file);
752
753 while (err == UNZ_OK)
754 {
755 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
756 err = unzGetCurrentFileInfo(file,NULL,
757 szCurrentFileName,sizeof(szCurrentFileName)-1,
758 NULL,0,NULL,0);
759 if (err == UNZ_OK)
760 {
761 if (unzStringFileNameCompare(szCurrentFileName,
762 szFileName,iCaseSensitivity)==0)
763 return UNZ_OK;
764 err = unzGoToNextFile(file);
765 }
766 }
767
768 /* We failed, so restore the state of the 'current file' to where we
769 * were.
770 */
771 s->num_file = num_fileSaved ;
772 s->pos_in_central_dir = pos_in_central_dirSaved ;
773 s->cur_file_info = cur_file_infoSaved;
774 s->cur_file_info_internal = cur_file_info_internalSaved;
775 return err;
776}
777
778
779/*
781// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
782// I need random access
783//
784// Further optimization could be realized by adding an ability
785// to cache the directory in memory. The goal being a single
786// comprehensive file read to put the file I need in a memory.
787*/
788
789/*
790typedef struct unz_file_pos_s
791{
792 uLong pos_in_zip_directory; // offset in file
793 uLong num_of_file; // # of file
794} unz_file_pos;
795*/
796
797int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos)
798{
799 if (file==NULL || file_pos==NULL)
800 return UNZ_PARAMERROR;
801 const unz_s* s=(unz_s*)file;
802 if (!s->current_file_ok)
804
806 file_pos->num_of_file = s->num_file;
807
808 return UNZ_OK;
809}
810
811int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos)
812{
813 if (file==NULL || file_pos==NULL)
814 return UNZ_PARAMERROR;
815 unz_s* s=(unz_s*)file;
816
817 /* jump to the right spot */
819 s->num_file = file_pos->num_of_file;
820
821 /* set the current file */
824 NULL,0,NULL,0,NULL,0);
825 /* return results */
826 s->current_file_ok = (err == UNZ_OK);
827 return err;
828}
829
830/*
831// Unzip Helper Functions - should be here?
833*/
834
835/*
836 Read the local header of the current zipfile
837 Check the coherency of the local header and info in the end of central
838 directory about this file
839 store in *piSizeVar the size of extra info in local header
840 (filename and size of extra field data)
841*/
842local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar, uLong *poffset_local_extrafield, uInt *psize_local_extrafield)
843{
844 uLong uMagic,uData,uFlags;
845 uLong size_filename;
846 uLong size_extra_field;
847 int err=UNZ_OK;
848
849 *piSizeVar = 0;
850 *poffset_local_extrafield = 0;
851 *psize_local_extrafield = 0;
852
855 return UNZ_ERRNO;
856
857
858 if (err==UNZ_OK) {
859 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
860 err=UNZ_ERRNO;
861 else if (uMagic!=0x04034b50)
862 err=UNZ_BADZIPFILE;
863 }
864
865 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
866 err=UNZ_ERRNO;
867/*
868 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
869 err=UNZ_BADZIPFILE;
870*/
871 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
872 err=UNZ_ERRNO;
873
874 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
875 err=UNZ_ERRNO;
876 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
877 err=UNZ_BADZIPFILE;
878
879 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
880 (s->cur_file_info.compression_method!=Z_DEFLATED))
881 err=UNZ_BADZIPFILE;
882
883 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
884 err=UNZ_ERRNO;
885
886 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
887 err=UNZ_ERRNO;
888 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
889 ((uFlags & 8)==0))
890 err=UNZ_BADZIPFILE;
891
892 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
893 err=UNZ_ERRNO;
894 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
895 ((uFlags & 8)==0))
896 err=UNZ_BADZIPFILE;
897
898 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
899 err=UNZ_ERRNO;
900 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
901 ((uFlags & 8)==0))
902 err=UNZ_BADZIPFILE;
903
904
905 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
906 err=UNZ_ERRNO;
907 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
908 err=UNZ_BADZIPFILE;
909
910 *piSizeVar += (uInt)size_filename;
911
912 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
913 err=UNZ_ERRNO;
914 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
915 SIZEZIPLOCALHEADER + size_filename;
916 *psize_local_extrafield = (uInt)size_extra_field;
917
918 *piSizeVar += (uInt)size_extra_field;
919
920 return err;
921}
922
923/*
924 Open for reading data the current file in the zipfile.
925 If there is no error and the file is opened, the return value is UNZ_OK.
926*/
927int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, int* level, int raw, const char* password)
928{
929 int err=UNZ_OK;
930 uInt iSizeVar;
931 uLong offset_local_extrafield; /* offset of the local extra field */
932 uInt size_local_extrafield; /* size of the local extra field */
933# ifndef NOUNCRYPT
934 char source[12];
935# else
936 if (password != NULL)
937 return UNZ_PARAMERROR;
938# endif
939
940 if (file==NULL)
941 return UNZ_PARAMERROR;
942 unz_s* s=(unz_s*)file;
943 if (!s->current_file_ok)
944 return UNZ_PARAMERROR;
945
946 if (s->pfile_in_zip_read != NULL)
948
950 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
951 return UNZ_BADZIPFILE;
952
953 file_in_zip_read_info_s* pfile_in_zip_read_info = (file_in_zip_read_info_s*)
955 if (pfile_in_zip_read_info==NULL)
956 return UNZ_INTERNALERROR;
957
958 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
959 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
960 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
961 pfile_in_zip_read_info->pos_local_extrafield=0;
962 pfile_in_zip_read_info->raw=raw;
963
964 if (pfile_in_zip_read_info->read_buffer==NULL)
965 {
966 TRYFREE(pfile_in_zip_read_info);
967 return UNZ_INTERNALERROR;
968 }
969
970 pfile_in_zip_read_info->stream_initialised=0;
971
972 if (method!=NULL)
974
975 if (level!=NULL)
976 {
977 *level = 6;
978 switch (s->cur_file_info.flag & 0x06)
979 {
980 case 6 : *level = 1; break;
981 case 4 : *level = 2; break;
982 case 2 : *level = 9; break;
983 }
984 }
985
986 if ((s->cur_file_info.compression_method!=0) &&
987 (s->cur_file_info.compression_method!=Z_DEFLATED))
988 err=UNZ_BADZIPFILE;
989
990 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
991 pfile_in_zip_read_info->crc32=0;
992 pfile_in_zip_read_info->compression_method =
994 pfile_in_zip_read_info->filestream=s->filestream;
995 pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
996 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
997
998 pfile_in_zip_read_info->stream.total_out = 0;
999
1000 if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1001 (!raw))
1002 {
1003 pfile_in_zip_read_info->stream.zalloc = 0;
1004 pfile_in_zip_read_info->stream.zfree = 0;
1005 pfile_in_zip_read_info->stream.opaque = 0;
1006 pfile_in_zip_read_info->stream.next_in = 0;
1007 pfile_in_zip_read_info->stream.avail_in = 0;
1008
1009 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1010 if (err == Z_OK)
1011 pfile_in_zip_read_info->stream_initialised=1;
1012 else
1013 {
1014 TRYFREE(pfile_in_zip_read_info);
1015 return err;
1016 }
1017 /* windowBits is passed < 0 to tell that there is no zlib header.
1018 * Note that in this case inflate *requires* an extra "dummy" byte
1019 * after the compressed stream in order to complete decompression and
1020 * return Z_STREAM_END.
1021 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1022 * size of both compressed and uncompressed data
1023 */
1024 }
1025 pfile_in_zip_read_info->rest_read_compressed =
1027 pfile_in_zip_read_info->rest_read_uncompressed =
1029
1030
1031 pfile_in_zip_read_info->pos_in_zipfile =
1033 iSizeVar;
1034
1035 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1036
1037 s->pfile_in_zip_read = pfile_in_zip_read_info;
1038
1039# ifndef NOUNCRYPT
1040 if (password != NULL)
1041 {
1042 s->pcrc_32_tab = get_crc_table();
1043 init_keys(password,s->keys,s->pcrc_32_tab);
1044 if (ZSEEK(s->z_filefunc, s->filestream,
1047 SEEK_SET)!=0)
1048 return UNZ_INTERNALERROR;
1049 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1050 return UNZ_INTERNALERROR;
1051
1052 for (int i = 0; i<12; i++)
1053 zdecode(s->keys,s->pcrc_32_tab,source[i]);
1054
1056 s->encrypted=1;
1057 }
1058# endif
1059
1060
1061 return UNZ_OK;
1062}
1063
1064int ZEXPORT unzOpenCurrentFile (unzFile file)
1065{
1066 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1067}
1068
1069int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
1070{
1071 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1072}
1073
1074int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
1075{
1076 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1077}
1078
1079/*
1080 Read bytes from the current file.
1081 buf contain buffer where data must be copied
1082 len the size of buf.
1083
1084 return the number of byte copied if somes bytes are copied
1085 return 0 if the end of file was reached
1086 return <0 with error code if there is an error
1087 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1088*/
1089int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1090{
1091 int err=UNZ_OK;
1092 uInt iRead = 0;
1093 if (file==NULL)
1094 return UNZ_PARAMERROR;
1095 const unz_s* s=(unz_s*)file;
1096 file_in_zip_read_info_s* pfile_in_zip_read_info=s->pfile_in_zip_read;
1097
1098 if (pfile_in_zip_read_info==NULL)
1099 return UNZ_PARAMERROR;
1100
1101
1102 if (pfile_in_zip_read_info->read_buffer == NULL)
1104 if (len==0)
1105 return 0;
1106
1107 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1108
1109 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1110
1111 if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1112 (!(pfile_in_zip_read_info->raw)))
1113 pfile_in_zip_read_info->stream.avail_out =
1114 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1115
1116 if ((len>pfile_in_zip_read_info->rest_read_compressed+
1117 pfile_in_zip_read_info->stream.avail_in) &&
1118 (pfile_in_zip_read_info->raw))
1119 pfile_in_zip_read_info->stream.avail_out =
1120 (uInt)pfile_in_zip_read_info->rest_read_compressed+
1121 pfile_in_zip_read_info->stream.avail_in;
1122
1123 while (pfile_in_zip_read_info->stream.avail_out>0)
1124 {
1125 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1126 (pfile_in_zip_read_info->rest_read_compressed>0))
1127 {
1128 uInt uReadThis = UNZ_BUFSIZE;
1129 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1130 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1131 if (uReadThis == 0)
1132 return UNZ_EOF;
1133 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1134 pfile_in_zip_read_info->filestream,
1135 pfile_in_zip_read_info->pos_in_zipfile +
1136 pfile_in_zip_read_info->byte_before_the_zipfile,
1138 return UNZ_ERRNO;
1139 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1140 pfile_in_zip_read_info->filestream,
1141 pfile_in_zip_read_info->read_buffer,
1142 uReadThis)!=uReadThis)
1143 return UNZ_ERRNO;
1144
1145
1146# ifndef NOUNCRYPT
1147 if(s->encrypted)
1148 {
1149 for(uInti=0;i<uReadThis;i++)
1150 pfile_in_zip_read_info->read_buffer[i] =
1151 zdecode(s->keys,s->pcrc_32_tab,
1152 pfile_in_zip_read_info->read_buffer[i]);
1153 }
1154# endif
1155
1156
1157 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1158
1159 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1160
1161 pfile_in_zip_read_info->stream.next_in =
1162 (Bytef*)pfile_in_zip_read_info->read_buffer;
1163 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1164 }
1165
1166 if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1167 {
1168 uInt uDoCopy ;
1169
1170 if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1171 (pfile_in_zip_read_info->rest_read_compressed == 0))
1172 return (iRead==0) ? UNZ_EOF : iRead;
1173
1174 if (pfile_in_zip_read_info->stream.avail_out <
1175 pfile_in_zip_read_info->stream.avail_in)
1176 uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1177 else
1178 uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1179
1180 for (uInt i=0;i<uDoCopy;i++)
1181 *(pfile_in_zip_read_info->stream.next_out+i) =
1182 *(pfile_in_zip_read_info->stream.next_in+i);
1183
1184 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1185 pfile_in_zip_read_info->stream.next_out,
1186 uDoCopy);
1187 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1188 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1189 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1190 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1191 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1192 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1193 iRead += uDoCopy;
1194 }
1195 else
1196 {
1197 int flush=Z_SYNC_FLUSH;
1198
1199 const uLong uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1200 const Bytef *bufBefore = pfile_in_zip_read_info->stream.next_out;
1201
1202 /*
1203 if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1204 pfile_in_zip_read_info->stream.avail_out) &&
1205 (pfile_in_zip_read_info->rest_read_compressed == 0))
1206 flush = Z_FINISH;
1207 */
1208 err=inflate(&pfile_in_zip_read_info->stream,flush);
1209
1210 if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
1211 err = Z_DATA_ERROR;
1212
1213 const uLong uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1214 const uLong uOutThis = uTotalOutAfter-uTotalOutBefore;
1215
1216 pfile_in_zip_read_info->crc32 =
1217 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1218 (uInt)(uOutThis));
1219
1220 pfile_in_zip_read_info->rest_read_uncompressed -=
1221 uOutThis;
1222
1223 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1224
1225 if (err==Z_STREAM_END)
1226 return (iRead==0) ? UNZ_EOF : iRead;
1227 if (err!=Z_OK)
1228 break;
1229 }
1230 }
1231
1232 if (err==Z_OK)
1233 return iRead;
1234 return err;
1235}
1236
1237
1238/*
1239 Give the current position in uncompressed data
1240*/
1241z_off_t ZEXPORT unztell (unzFile file)
1242{
1243 if (file==NULL)
1244 return UNZ_PARAMERROR;
1245 const unz_s* s=(unz_s*)file;
1246 const file_in_zip_read_info_s* pfile_in_zip_read_info=s->pfile_in_zip_read;
1247
1248 if (pfile_in_zip_read_info==NULL)
1249 return UNZ_PARAMERROR;
1250
1251 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1252}
1253
1254
1255/*
1256 return 1 if the end of file was reached, 0 elsewhere
1257*/
1258int ZEXPORT unzeof (unzFile file)
1259{
1260 if (file==NULL)
1261 return UNZ_PARAMERROR;
1262 const unz_s* s=(unz_s*)file;
1263 const file_in_zip_read_info_s* pfile_in_zip_read_info=s->pfile_in_zip_read;
1264
1265 if (pfile_in_zip_read_info==NULL)
1266 return UNZ_PARAMERROR;
1267
1268 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1269 return 1;
1270 else
1271 return 0;
1272}
1273
1274
1275
1276/*
1277 Read extra field from the current file (opened by unzOpenCurrentFile)
1278 This is the local-header version of the extra field (sometimes, there is
1279 more info in the local-header version than in the central-header)
1280
1281 if buf==NULL, it return the size of the local extra field that can be read
1282
1283 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1284 buf.
1285 the return value is the number of bytes copied in buf, or (if <0)
1286 the error code
1287*/
1288int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
1289{
1290 uInt read_now;
1291
1292 if (file==NULL)
1293 return UNZ_PARAMERROR;
1294 const unz_s* s=(unz_s*)file;
1295 const file_in_zip_read_info_s* pfile_in_zip_read_info=s->pfile_in_zip_read;
1296
1297 if (pfile_in_zip_read_info==NULL)
1298 return UNZ_PARAMERROR;
1299
1300 const uLong size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1301 pfile_in_zip_read_info->pos_local_extrafield);
1302
1303 if (buf==NULL)
1304 return (int)size_to_read;
1305
1306 if (len>size_to_read)
1307 read_now = (uInt)size_to_read;
1308 else
1309 read_now = (uInt)len ;
1310
1311 if (read_now==0)
1312 return 0;
1313
1314 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1315 pfile_in_zip_read_info->filestream,
1316 pfile_in_zip_read_info->offset_local_extrafield +
1317 pfile_in_zip_read_info->pos_local_extrafield,
1319 return UNZ_ERRNO;
1320
1321 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1322 pfile_in_zip_read_info->filestream,
1323 buf,read_now)!=read_now)
1324 return UNZ_ERRNO;
1325
1326 return (int)read_now;
1327}
1328
1329/*
1330 Close the file in zip opened with unzipOpenCurrentFile
1331 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1332*/
1334{
1335 int err=UNZ_OK;
1336
1337 if (file==NULL)
1338 return UNZ_PARAMERROR;
1339 unz_s* s=(unz_s*)file;
1340 file_in_zip_read_info_s* pfile_in_zip_read_info=s->pfile_in_zip_read;
1341
1342 if (pfile_in_zip_read_info==NULL)
1343 return UNZ_PARAMERROR;
1344
1345
1346 if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
1347 (!pfile_in_zip_read_info->raw))
1348 {
1349 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1350 err=UNZ_CRCERROR;
1351 }
1352
1353
1354 TRYFREE(pfile_in_zip_read_info->read_buffer);
1355 pfile_in_zip_read_info->read_buffer = NULL;
1356 if (pfile_in_zip_read_info->stream_initialised)
1357 inflateEnd(&pfile_in_zip_read_info->stream);
1358
1359 pfile_in_zip_read_info->stream_initialised = 0;
1360 TRYFREE(pfile_in_zip_read_info);
1361
1362 s->pfile_in_zip_read=NULL;
1363
1364 return err;
1365}
1366
1367
1368/*
1369 Get the global comment string of the ZipFile, in the szComment buffer.
1370 uSizeBuf is the size of the szComment buffer.
1371 return the number of byte copied or an error code <0
1372*/
1373int ZEXPORT unzGetGlobalComment ( unzFile file, char* szComment, uLong uSizeBuf)
1374{
1375 if (file==NULL)
1376 return UNZ_PARAMERROR;
1377 const unz_s* s=(unz_s*)file;
1378
1379 uLong uReadThis = uSizeBuf;
1380 if (uReadThis>s->gi.size_comment)
1381 uReadThis = s->gi.size_comment;
1382
1384 return UNZ_ERRNO;
1385
1386 if (uReadThis>0)
1387 {
1388 *szComment='\0';
1389 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1390 return UNZ_ERRNO;
1391 }
1392
1393 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
1394 *(szComment+s->gi.size_comment)='\0';
1395 return (int)uReadThis;
1396}
1397
1398/* Additions by RX '2004 */
1400{
1401 if (file==NULL)
1402 return UNZ_PARAMERROR;
1403 const unz_s* s=(unz_s*)file;
1404 if (!s->current_file_ok)
1405 return 0;
1406 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
1407 if (s->num_file==s->gi.number_entry)
1408 return 0;
1409 return s->pos_in_central_dir;
1410}
1411
1412int ZEXPORT unzSetOffset (unzFile file, uLong pos)
1413{
1414 if (file==NULL)
1415 return UNZ_PARAMERROR;
1416 unz_s* s=(unz_s*)file;
1417
1418 s->pos_in_central_dir = pos;
1419 s->num_file = s->gi.number_entry; /* hack */
1420 const int err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1422 NULL,0,NULL,0,NULL,0);
1423 s->current_file_ok = (err == UNZ_OK);
1424 return err;
1425}
1426
1427
1428/*
1429 Set the position of the info of the current file in the zip.
1430 return UNZ_OK if there is no problem
1431*/
1432extern int ZEXPORT unzSetCurrentFileInfoPosition (unzFile file, unsigned long pos )
1433{
1434 if (file==NULL)
1435 return UNZ_PARAMERROR;
1436 unz_s* s=(unz_s*)file;
1437
1438 s->pos_in_central_dir = pos;
1439 const int err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1441 NULL,0,NULL,0,NULL,0);
1442 s->current_file_ok = (err == UNZ_OK);
1443 return UNZ_OK;
1444}
1445
1446/*
1447 Get the position of the info of the current file in the zip.
1448 return UNZ_OK if there is no problem
1449*/
1450extern int ZEXPORT unzGetCurrentFileInfoPosition (unzFile file, unsigned long *pos )
1451{
1452 if (file==NULL)
1453 return UNZ_PARAMERROR;
1454 const unz_s* s=(unz_s*)file;
1455
1456 *pos = s->pos_in_central_dir;
1457 return UNZ_OK;
1458}
level_locals_t level
Definition g_main.cpp:38
cvar_t * password
Definition g_main.cpp:67
#define SEEK_SET
Definition ioapi.cpp:30
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
Definition ioapi.cpp:95
#define ZSEEK(filefunc, filestream, pos, mode)
Definition ioapi.h:68
typedef voidpf(ZCALLBACK *open_file_func) OF((voidpf opaque
typedef uLong(ZCALLBACK *read_file_func) OF((voidpf opaque
#define ZTELL(filefunc, filestream)
Definition ioapi.h:67
#define ZCLOSE(filefunc, filestream)
Definition ioapi.h:69
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition ioapi.h:20
#define ZLIB_FILEFUNC_SEEK_CUR
Definition ioapi.h:12
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
voidpf void * buf
Definition ioapi.h:42
#define ZLIB_FILEFUNC_SEEK_SET
Definition ioapi.h:14
#define OF(args)
Definition ioapi.h:34
#define ZERROR(filefunc, filestream)
Definition ioapi.h:70
#define ZLIB_FILEFUNC_SEEK_END
Definition ioapi.h:13
#define ZREAD(filefunc, filestream, buf, size)
Definition ioapi.h:65
#define ZLIB_FILEFUNC_MODE_READ
Definition ioapi.h:16
QGL_EXTERN GLuint GLchar GLuint * len
Definition r_gl.h:99
QGL_EXTERN GLint i
Definition r_gl.h:113
zlib_filefunc_def z_filefunc
Definition unzip.cpp:112
Definition unzip.h:85
uInt tm_mday
Definition unzip.h:89
uInt tm_min
Definition unzip.h:87
uInt tm_sec
Definition unzip.h:86
uInt tm_mon
Definition unzip.h:90
uInt tm_year
Definition unzip.h:91
uInt tm_hour
Definition unzip.h:88
uLong compressed_size
Definition unzip.h:113
uLong dosDate
Definition unzip.h:111
uLong size_file_comment
Definition unzip.h:117
uLong size_file_extra
Definition unzip.h:116
uLong crc
Definition unzip.h:112
uLong version
Definition unzip.h:107
uLong disk_num_start
Definition unzip.h:119
uLong flag
Definition unzip.h:109
uLong size_filename
Definition unzip.h:115
tm_unz tmu_date
Definition unzip.h:123
uLong compression_method
Definition unzip.h:110
uLong internal_fa
Definition unzip.h:120
uLong external_fa
Definition unzip.h:121
uLong version_needed
Definition unzip.h:108
uLong uncompressed_size
Definition unzip.h:114
uLong pos_in_zip_directory
Definition unzip.h:216
uLong num_of_file
Definition unzip.h:217
uLong number_entry
Definition unzip.h:98
uLong size_comment
Definition unzip.h:100
unz_global_info gi
Definition unzip.cpp:126
uLong central_pos
Definition unzip.cpp:131
unz_file_info_internal cur_file_info_internal
Definition unzip.cpp:138
voidpf filestream
Definition unzip.cpp:125
uLong size_central_dir
Definition unzip.cpp:133
uLong pos_in_central_dir
Definition unzip.cpp:129
uLong num_file
Definition unzip.cpp:128
uLong byte_before_the_zipfile
Definition unzip.cpp:127
file_in_zip_read_info_s * pfile_in_zip_read
Definition unzip.cpp:139
zlib_filefunc_def z_filefunc
Definition unzip.cpp:124
unz_file_info cur_file_info
Definition unzip.cpp:137
uLong current_file_ok
Definition unzip.cpp:130
uLong offset_central_dir
Definition unzip.cpp:134
int encrypted
Definition unzip.cpp:141
open_file_func zopen_file
Definition ioapi.h:51
voidpf opaque
Definition ioapi.h:58
int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len)
Definition unzip.cpp:1288
#define local
Definition unzip.cpp:51
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
Definition unzip.cpp:1069
#define BUFREADCOMMENT
Definition unzip.cpp:281
int ZEXPORT unzSetOffset(unzFile file, uLong pos)
Definition unzip.cpp:1412
z_off_t ZEXPORT unztell(unzFile file)
Definition unzip.cpp:1241
uLong ZEXPORT unzGetOffset(unzFile file)
Definition unzip.cpp:1399
#define CASESENSITIVITYDEFAULTVALUE
Definition unzip.cpp:251
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
Definition unzip.cpp:731
int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos)
Definition unzip.cpp:797
#define STRCMPCASENOSENTIVEFUNCTION
Definition unzip.cpp:257
int ZEXPORT unzStringFileNameCompare(const char *fileName1, const char *fileName2, int iCaseSensitivity)
Definition unzip.cpp:269
#define SIZEZIPLOCALHEADER
Definition unzip.cpp:79
unzFile ZEXPORT unzOpen(const char *path)
Definition unzip.cpp:446
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition unzip.cpp:681
int ZEXPORT unzeof(unzFile file)
Definition unzip.cpp:1258
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
Definition unzip.cpp:1074
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
Definition unzip.cpp:927
#define TRYFREE(p)
Definition unzip.cpp:75
int ZEXPORT unzSetCurrentFileInfoPosition(unzFile file, unsigned long pos)
Definition unzip.cpp:1432
local int unzlocal_GetCurrentFileInfoInternal(unzFile file, unz_file_info *pfile_info, unz_file_info_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition unzip.cpp:516
int ZEXPORT unzOpenCurrentFile(unzFile file)
Definition unzip.cpp:1064
int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
Definition unzip.cpp:811
int ZEXPORT unzGetCurrentFileInfoPosition(unzFile file, unsigned long *pos)
Definition unzip.cpp:1450
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Definition unzip.cpp:1089
local int strcmpcasenosensitive_internal(const char *fileName1, const char *fileName2)
Definition unzip.cpp:228
local uLong unzlocal_SearchCentralDir(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream)
Definition unzip.cpp:288
#define UNZ_MAXFILENAMEINZIP
Definition unzip.cpp:68
unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def)
Definition unzip.cpp:346
local int unzlocal_getLong(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition unzip.cpp:200
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition unzip.cpp:1333
#define ALLOC(size)
Definition unzip.cpp:72
#define UNZ_BUFSIZE
Definition unzip.cpp:64
int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition unzip.cpp:669
int ZEXPORT unzGoToNextFile(unzFile file)
Definition unzip.cpp:701
#define SIZECENTRALDIRITEM
Definition unzip.cpp:78
local int unzlocal_getByte(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, int *pi)
Definition unzip.cpp:160
int ZEXPORT unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf)
Definition unzip.cpp:1373
local int unzlocal_CheckCurrentFileCoherencyHeader(unz_s *s, uInt *piSizeVar, uLong *poffset_local_extrafield, uInt *psize_local_extrafield)
Definition unzip.cpp:842
const char unz_copyright[]
Definition unzip.cpp:84
local void unzlocal_DosDateToTmuDate(uLong ulDosDate, tm_unz *ptm)
Definition unzip.cpp:488
int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info)
Definition unzip.cpp:475
local int unzlocal_getShort(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition unzip.cpp:182
int ZEXPORT unzClose(unzFile file)
Definition unzip.cpp:456
#define UNZ_EOF
Definition unzip.h:77
#define UNZ_BADZIPFILE
Definition unzip.h:79
#define UNZ_INTERNALERROR
Definition unzip.h:80
#define UNZ_ERRNO
Definition unzip.h:76
#define UNZ_END_OF_LIST_OF_FILE
Definition unzip.h:75
#define UNZ_PARAMERROR
Definition unzip.h:78
voidp unzFile
Definition unzip.h:70
#define UNZ_OK
Definition unzip.h:74
#define UNZ_CRCERROR
Definition unzip.h:81