|
7ef7284…
|
drh
|
1 |
/* unzip.c -- IO for uncompress .zip files using zlib |
|
6ea30fb…
|
florian
|
2 |
part of the MiniZip project - ( https://www.winimage.com/zLibDll/minizip.html ) |
|
7ef7284…
|
drh
|
3 |
|
|
6ea30fb…
|
florian
|
4 |
Copyright (C) 1998-2026 Gilles Vollant (minizip) ( https://www.winimage.com/zLibDll/minizip.html ) |
|
7ef7284…
|
drh
|
5 |
|
|
7ef7284…
|
drh
|
6 |
Modifications of Unzip for Zip64 |
|
7ef7284…
|
drh
|
7 |
Copyright (C) 2007-2008 Even Rouault |
|
7ef7284…
|
drh
|
8 |
|
|
7ef7284…
|
drh
|
9 |
Modifications for Zip64 support on both zip and unzip |
|
6ea30fb…
|
florian
|
10 |
Copyright (C) 2009-2010 Mathias Svensson ( https://result42.com ) |
|
7ef7284…
|
drh
|
11 |
|
|
7ef7284…
|
drh
|
12 |
For more info read MiniZip_info.txt |
|
7ef7284…
|
drh
|
13 |
|
|
7ef7284…
|
drh
|
14 |
|
|
7ef7284…
|
drh
|
15 |
------------------------------------------------------------------------------------ |
|
7ef7284…
|
drh
|
16 |
Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of |
|
7ef7284…
|
drh
|
17 |
compatibility with older software. The following is from the original crypt.c. |
|
7ef7284…
|
drh
|
18 |
Code woven in by Terry Thorsen 1/2003. |
|
7ef7284…
|
drh
|
19 |
|
|
7ef7284…
|
drh
|
20 |
Copyright (c) 1990-2000 Info-ZIP. All rights reserved. |
|
7ef7284…
|
drh
|
21 |
|
|
7ef7284…
|
drh
|
22 |
See the accompanying file LICENSE, version 2000-Apr-09 or later |
|
7ef7284…
|
drh
|
23 |
(the contents of which are also included in zip.h) for terms of use. |
|
7ef7284…
|
drh
|
24 |
If, for some reason, all these files are missing, the Info-ZIP license |
|
7ef7284…
|
drh
|
25 |
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
|
7ef7284…
|
drh
|
26 |
|
|
7ef7284…
|
drh
|
27 |
crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] |
|
7ef7284…
|
drh
|
28 |
|
|
7ef7284…
|
drh
|
29 |
The encryption/decryption parts of this source code (as opposed to the |
|
7ef7284…
|
drh
|
30 |
non-echoing password parts) were originally written in Europe. The |
|
7ef7284…
|
drh
|
31 |
whole source package can be freely distributed, including from the USA. |
|
7ef7284…
|
drh
|
32 |
(Prior to January 2000, re-export from the US was a violation of US law.) |
|
7ef7284…
|
drh
|
33 |
|
|
7ef7284…
|
drh
|
34 |
This encryption code is a direct transcription of the algorithm from |
|
7ef7284…
|
drh
|
35 |
Roger Schlafly, described by Phil Katz in the file appnote.txt. This |
|
7ef7284…
|
drh
|
36 |
file (appnote.txt) is distributed with the PKZIP program (even in the |
|
7ef7284…
|
drh
|
37 |
version without encryption capabilities). |
|
7ef7284…
|
drh
|
38 |
|
|
7ef7284…
|
drh
|
39 |
------------------------------------------------------------------------------------ |
|
7ef7284…
|
drh
|
40 |
|
|
7ef7284…
|
drh
|
41 |
Changes in unzip.c |
|
7ef7284…
|
drh
|
42 |
|
|
7ef7284…
|
drh
|
43 |
2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos |
|
7ef7284…
|
drh
|
44 |
2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* |
|
7ef7284…
|
drh
|
45 |
2007-2008 - Even Rouault - Remove old C style function prototypes |
|
7ef7284…
|
drh
|
46 |
2007-2008 - Even Rouault - Add unzip support for ZIP64 |
|
7ef7284…
|
drh
|
47 |
|
|
7ef7284…
|
drh
|
48 |
Copyright (C) 2007-2008 Even Rouault |
|
7ef7284…
|
drh
|
49 |
|
|
7ef7284…
|
drh
|
50 |
|
|
f1f1d6c…
|
drh
|
51 |
Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). |
|
7ef7284…
|
drh
|
52 |
Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G |
|
7ef7284…
|
drh
|
53 |
should only read the compressed/uncompressed size from the Zip64 format if |
|
7ef7284…
|
drh
|
54 |
the size from normal header was 0xFFFFFFFF |
|
f1f1d6c…
|
drh
|
55 |
Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant |
|
f1f1d6c…
|
drh
|
56 |
Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required) |
|
7ef7284…
|
drh
|
57 |
Patch created by Daniel Borca |
|
7ef7284…
|
drh
|
58 |
|
|
7ef7284…
|
drh
|
59 |
Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer |
|
7ef7284…
|
drh
|
60 |
|
|
7ef7284…
|
drh
|
61 |
Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson |
|
7ef7284…
|
drh
|
62 |
|
|
7ef7284…
|
drh
|
63 |
*/ |
|
7ef7284…
|
drh
|
64 |
|
|
7ef7284…
|
drh
|
65 |
|
|
7ef7284…
|
drh
|
66 |
#include <stdio.h> |
|
7ef7284…
|
drh
|
67 |
#include <stdlib.h> |
|
7ef7284…
|
drh
|
68 |
#include <string.h> |
|
7ef7284…
|
drh
|
69 |
|
|
6ea30fb…
|
florian
|
70 |
#ifdef ZLIB_DLL |
|
6ea30fb…
|
florian
|
71 |
# undef ZLIB_DLL |
|
7ef7284…
|
drh
|
72 |
#endif |
|
7ef7284…
|
drh
|
73 |
#include "zlib.h" |
|
7ef7284…
|
drh
|
74 |
#include "unzip.h" |
|
7ef7284…
|
drh
|
75 |
|
|
7ef7284…
|
drh
|
76 |
#ifdef STDC |
|
7ef7284…
|
drh
|
77 |
# include <stddef.h> |
|
7ef7284…
|
drh
|
78 |
#endif |
|
7ef7284…
|
drh
|
79 |
#ifdef NO_ERRNO_H |
|
7ef7284…
|
drh
|
80 |
extern int errno; |
|
7ef7284…
|
drh
|
81 |
#else |
|
7ef7284…
|
drh
|
82 |
# include <errno.h> |
|
7ef7284…
|
drh
|
83 |
#endif |
|
7ef7284…
|
drh
|
84 |
|
|
7ef7284…
|
drh
|
85 |
|
|
7ef7284…
|
drh
|
86 |
#ifndef local |
|
7ef7284…
|
drh
|
87 |
# define local static |
|
7ef7284…
|
drh
|
88 |
#endif |
|
7ef7284…
|
drh
|
89 |
/* compile with -Dlocal if your debugger can't find static symbols */ |
|
7ef7284…
|
drh
|
90 |
|
|
7ef7284…
|
drh
|
91 |
|
|
7ef7284…
|
drh
|
92 |
#ifndef CASESENSITIVITYDEFAULT_NO |
|
6ea30fb…
|
florian
|
93 |
# if (!defined(__unix__) && !defined(__unix) || defined(__CYGWIN__)) && !defined(CASESENSITIVITYDEFAULT_YES) |
|
7ef7284…
|
drh
|
94 |
# define CASESENSITIVITYDEFAULT_NO |
|
7ef7284…
|
drh
|
95 |
# endif |
|
7ef7284…
|
drh
|
96 |
#endif |
|
7ef7284…
|
drh
|
97 |
|
|
7ef7284…
|
drh
|
98 |
|
|
7ef7284…
|
drh
|
99 |
#ifndef UNZ_BUFSIZE |
|
7ef7284…
|
drh
|
100 |
#define UNZ_BUFSIZE (16384) |
|
7ef7284…
|
drh
|
101 |
#endif |
|
7ef7284…
|
drh
|
102 |
|
|
7ef7284…
|
drh
|
103 |
#ifndef UNZ_MAXFILENAMEINZIP |
|
7ef7284…
|
drh
|
104 |
#define UNZ_MAXFILENAMEINZIP (256) |
|
7ef7284…
|
drh
|
105 |
#endif |
|
7ef7284…
|
drh
|
106 |
|
|
7ef7284…
|
drh
|
107 |
#ifndef ALLOC |
|
7ef7284…
|
drh
|
108 |
# define ALLOC(size) (malloc(size)) |
|
7ef7284…
|
drh
|
109 |
#endif |
|
7ef7284…
|
drh
|
110 |
|
|
7ef7284…
|
drh
|
111 |
#define SIZECENTRALDIRITEM (0x2e) |
|
7ef7284…
|
drh
|
112 |
#define SIZEZIPLOCALHEADER (0x1e) |
|
7ef7284…
|
drh
|
113 |
|
|
7ef7284…
|
drh
|
114 |
|
|
7ef7284…
|
drh
|
115 |
const char unz_copyright[] = |
|
6ea30fb…
|
florian
|
116 |
" unzip 1.01 Copyright 1998-2004 Gilles Vollant - https://www.winimage.com/zLibDll/minizip.html"; |
|
7ef7284…
|
drh
|
117 |
|
|
64ce68d…
|
drh
|
118 |
/* unz_file_info64_internal contain internal info about a file in zipfile*/ |
|
7ef7284…
|
drh
|
119 |
typedef struct unz_file_info64_internal_s |
|
7ef7284…
|
drh
|
120 |
{ |
|
7ef7284…
|
drh
|
121 |
ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ |
|
7ef7284…
|
drh
|
122 |
} unz_file_info64_internal; |
|
7ef7284…
|
drh
|
123 |
|
|
7ef7284…
|
drh
|
124 |
|
|
7ef7284…
|
drh
|
125 |
/* file_in_zip_read_info_s contain internal information about a file in zipfile, |
|
7ef7284…
|
drh
|
126 |
when reading and decompress it */ |
|
7ef7284…
|
drh
|
127 |
typedef struct |
|
7ef7284…
|
drh
|
128 |
{ |
|
7ef7284…
|
drh
|
129 |
char *read_buffer; /* internal buffer for compressed data */ |
|
7ef7284…
|
drh
|
130 |
z_stream stream; /* zLib stream structure for inflate */ |
|
7ef7284…
|
drh
|
131 |
|
|
7ef7284…
|
drh
|
132 |
#ifdef HAVE_BZIP2 |
|
7ef7284…
|
drh
|
133 |
bz_stream bstream; /* bzLib stream structure for bziped */ |
|
7ef7284…
|
drh
|
134 |
#endif |
|
7ef7284…
|
drh
|
135 |
|
|
7ef7284…
|
drh
|
136 |
ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ |
|
7ef7284…
|
drh
|
137 |
uLong stream_initialised; /* flag set if stream structure is initialised*/ |
|
7ef7284…
|
drh
|
138 |
|
|
7ef7284…
|
drh
|
139 |
ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ |
|
7ef7284…
|
drh
|
140 |
uInt size_local_extrafield;/* size of the local extra field */ |
|
7ef7284…
|
drh
|
141 |
ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ |
|
7ef7284…
|
drh
|
142 |
ZPOS64_T total_out_64; |
|
7ef7284…
|
drh
|
143 |
|
|
7ef7284…
|
drh
|
144 |
uLong crc32; /* crc32 of all data uncompressed */ |
|
7ef7284…
|
drh
|
145 |
uLong crc32_wait; /* crc32 we must obtain after decompress all */ |
|
7ef7284…
|
drh
|
146 |
ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ |
|
7ef7284…
|
drh
|
147 |
ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ |
|
7ef7284…
|
drh
|
148 |
zlib_filefunc64_32_def z_filefunc; |
|
f1f1d6c…
|
drh
|
149 |
voidpf filestream; /* io structure of the zipfile */ |
|
7ef7284…
|
drh
|
150 |
uLong compression_method; /* compression method (0==store) */ |
|
7ef7284…
|
drh
|
151 |
ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ |
|
7ef7284…
|
drh
|
152 |
int raw; |
|
7ef7284…
|
drh
|
153 |
} file_in_zip64_read_info_s; |
|
7ef7284…
|
drh
|
154 |
|
|
7ef7284…
|
drh
|
155 |
|
|
7ef7284…
|
drh
|
156 |
/* unz64_s contain internal information about the zipfile |
|
7ef7284…
|
drh
|
157 |
*/ |
|
7ef7284…
|
drh
|
158 |
typedef struct |
|
7ef7284…
|
drh
|
159 |
{ |
|
7ef7284…
|
drh
|
160 |
zlib_filefunc64_32_def z_filefunc; |
|
7ef7284…
|
drh
|
161 |
int is64bitOpenFunction; |
|
f1f1d6c…
|
drh
|
162 |
voidpf filestream; /* io structure of the zipfile */ |
|
7ef7284…
|
drh
|
163 |
unz_global_info64 gi; /* public global information */ |
|
7ef7284…
|
drh
|
164 |
ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ |
|
7ef7284…
|
drh
|
165 |
ZPOS64_T num_file; /* number of the current file in the zipfile*/ |
|
7ef7284…
|
drh
|
166 |
ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ |
|
7ef7284…
|
drh
|
167 |
ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ |
|
7ef7284…
|
drh
|
168 |
ZPOS64_T central_pos; /* position of the beginning of the central dir*/ |
|
7ef7284…
|
drh
|
169 |
|
|
7ef7284…
|
drh
|
170 |
ZPOS64_T size_central_dir; /* size of the central directory */ |
|
7ef7284…
|
drh
|
171 |
ZPOS64_T offset_central_dir; /* offset of start of central directory with |
|
7ef7284…
|
drh
|
172 |
respect to the starting disk number */ |
|
7ef7284…
|
drh
|
173 |
|
|
7ef7284…
|
drh
|
174 |
unz_file_info64 cur_file_info; /* public info about the current file in zip*/ |
|
7ef7284…
|
drh
|
175 |
unz_file_info64_internal cur_file_info_internal; /* private info about it*/ |
|
7ef7284…
|
drh
|
176 |
file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current |
|
7ef7284…
|
drh
|
177 |
file if we are decompressing it */ |
|
7ef7284…
|
drh
|
178 |
int encrypted; |
|
7ef7284…
|
drh
|
179 |
|
|
7ef7284…
|
drh
|
180 |
int isZip64; |
|
7ef7284…
|
drh
|
181 |
|
|
7ef7284…
|
drh
|
182 |
# ifndef NOUNCRYPT |
|
7ef7284…
|
drh
|
183 |
unsigned long keys[3]; /* keys defining the pseudo-random sequence */ |
|
bb4776e…
|
jan.nijtmans
|
184 |
const z_crc_t* pcrc_32_tab; |
|
7ef7284…
|
drh
|
185 |
# endif |
|
7ef7284…
|
drh
|
186 |
} unz64_s; |
|
7ef7284…
|
drh
|
187 |
|
|
7ef7284…
|
drh
|
188 |
|
|
7ef7284…
|
drh
|
189 |
#ifndef NOUNCRYPT |
|
7ef7284…
|
drh
|
190 |
#include "crypt.h" |
|
7ef7284…
|
drh
|
191 |
#endif |
|
7ef7284…
|
drh
|
192 |
|
|
f1f1d6c…
|
drh
|
193 |
|
|
7ef7284…
|
drh
|
194 |
/* =========================================================================== |
|
f1f1d6c…
|
drh
|
195 |
Reads a long in LSB order from the given gz_stream. Sets |
|
7ef7284…
|
drh
|
196 |
*/ |
|
7ef7284…
|
drh
|
197 |
|
|
f1f1d6c…
|
drh
|
198 |
local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, |
|
f1f1d6c…
|
drh
|
199 |
voidpf filestream, |
|
f1f1d6c…
|
drh
|
200 |
uLong *pX) { |
|
f1f1d6c…
|
drh
|
201 |
unsigned char c[2]; |
|
f1f1d6c…
|
drh
|
202 |
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2); |
|
f1f1d6c…
|
drh
|
203 |
if (err==2) |
|
f1f1d6c…
|
drh
|
204 |
{ |
|
f1f1d6c…
|
drh
|
205 |
*pX = c[0] | ((uLong)c[1] << 8); |
|
f1f1d6c…
|
drh
|
206 |
return UNZ_OK; |
|
f1f1d6c…
|
drh
|
207 |
} |
|
f1f1d6c…
|
drh
|
208 |
else |
|
f1f1d6c…
|
drh
|
209 |
{ |
|
f1f1d6c…
|
drh
|
210 |
*pX = 0; |
|
f1f1d6c…
|
drh
|
211 |
if (ZERROR64(*pzlib_filefunc_def,filestream)) |
|
f1f1d6c…
|
drh
|
212 |
return UNZ_ERRNO; |
|
f1f1d6c…
|
drh
|
213 |
else |
|
f1f1d6c…
|
drh
|
214 |
return UNZ_EOF; |
|
f1f1d6c…
|
drh
|
215 |
} |
|
f1f1d6c…
|
drh
|
216 |
} |
|
f1f1d6c…
|
drh
|
217 |
|
|
f1f1d6c…
|
drh
|
218 |
local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, |
|
f1f1d6c…
|
drh
|
219 |
voidpf filestream, |
|
f1f1d6c…
|
drh
|
220 |
uLong *pX) { |
|
f1f1d6c…
|
drh
|
221 |
unsigned char c[4]; |
|
f1f1d6c…
|
drh
|
222 |
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4); |
|
f1f1d6c…
|
drh
|
223 |
if (err==4) |
|
f1f1d6c…
|
drh
|
224 |
{ |
|
f1f1d6c…
|
drh
|
225 |
*pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24); |
|
f1f1d6c…
|
drh
|
226 |
return UNZ_OK; |
|
f1f1d6c…
|
drh
|
227 |
} |
|
f1f1d6c…
|
drh
|
228 |
else |
|
f1f1d6c…
|
drh
|
229 |
{ |
|
f1f1d6c…
|
drh
|
230 |
*pX = 0; |
|
f1f1d6c…
|
drh
|
231 |
if (ZERROR64(*pzlib_filefunc_def,filestream)) |
|
f1f1d6c…
|
drh
|
232 |
return UNZ_ERRNO; |
|
f1f1d6c…
|
drh
|
233 |
else |
|
f1f1d6c…
|
drh
|
234 |
return UNZ_EOF; |
|
f1f1d6c…
|
drh
|
235 |
} |
|
f1f1d6c…
|
drh
|
236 |
} |
|
f1f1d6c…
|
drh
|
237 |
|
|
f1f1d6c…
|
drh
|
238 |
|
|
f1f1d6c…
|
drh
|
239 |
local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, |
|
f1f1d6c…
|
drh
|
240 |
voidpf filestream, |
|
f1f1d6c…
|
drh
|
241 |
ZPOS64_T *pX) { |
|
f1f1d6c…
|
drh
|
242 |
unsigned char c[8]; |
|
f1f1d6c…
|
drh
|
243 |
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8); |
|
f1f1d6c…
|
drh
|
244 |
if (err==8) |
|
f1f1d6c…
|
drh
|
245 |
{ |
|
f1f1d6c…
|
drh
|
246 |
*pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24) |
|
f1f1d6c…
|
drh
|
247 |
| ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56); |
|
7ef7284…
|
drh
|
248 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
249 |
} |
|
7ef7284…
|
drh
|
250 |
else |
|
7ef7284…
|
drh
|
251 |
{ |
|
f1f1d6c…
|
drh
|
252 |
*pX = 0; |
|
7ef7284…
|
drh
|
253 |
if (ZERROR64(*pzlib_filefunc_def,filestream)) |
|
7ef7284…
|
drh
|
254 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
255 |
else |
|
7ef7284…
|
drh
|
256 |
return UNZ_EOF; |
|
7ef7284…
|
drh
|
257 |
} |
|
7ef7284…
|
drh
|
258 |
} |
|
7ef7284…
|
drh
|
259 |
|
|
7ef7284…
|
drh
|
260 |
/* My own strcmpi / strcasecmp */ |
|
f1f1d6c…
|
drh
|
261 |
local int strcmpcasenosensitive_internal(const char* fileName1, const char* fileName2) { |
|
7ef7284…
|
drh
|
262 |
for (;;) |
|
7ef7284…
|
drh
|
263 |
{ |
|
7ef7284…
|
drh
|
264 |
char c1=*(fileName1++); |
|
7ef7284…
|
drh
|
265 |
char c2=*(fileName2++); |
|
7ef7284…
|
drh
|
266 |
if ((c1>='a') && (c1<='z')) |
|
7ef7284…
|
drh
|
267 |
c1 -= 0x20; |
|
7ef7284…
|
drh
|
268 |
if ((c2>='a') && (c2<='z')) |
|
7ef7284…
|
drh
|
269 |
c2 -= 0x20; |
|
7ef7284…
|
drh
|
270 |
if (c1=='\0') |
|
7ef7284…
|
drh
|
271 |
return ((c2=='\0') ? 0 : -1); |
|
7ef7284…
|
drh
|
272 |
if (c2=='\0') |
|
7ef7284…
|
drh
|
273 |
return 1; |
|
7ef7284…
|
drh
|
274 |
if (c1<c2) |
|
7ef7284…
|
drh
|
275 |
return -1; |
|
7ef7284…
|
drh
|
276 |
if (c1>c2) |
|
7ef7284…
|
drh
|
277 |
return 1; |
|
7ef7284…
|
drh
|
278 |
} |
|
7ef7284…
|
drh
|
279 |
} |
|
7ef7284…
|
drh
|
280 |
|
|
7ef7284…
|
drh
|
281 |
|
|
7ef7284…
|
drh
|
282 |
#ifdef CASESENSITIVITYDEFAULT_NO |
|
7ef7284…
|
drh
|
283 |
#define CASESENSITIVITYDEFAULTVALUE 2 |
|
7ef7284…
|
drh
|
284 |
#else |
|
7ef7284…
|
drh
|
285 |
#define CASESENSITIVITYDEFAULTVALUE 1 |
|
7ef7284…
|
drh
|
286 |
#endif |
|
7ef7284…
|
drh
|
287 |
|
|
7ef7284…
|
drh
|
288 |
#ifndef STRCMPCASENOSENTIVEFUNCTION |
|
7ef7284…
|
drh
|
289 |
#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal |
|
7ef7284…
|
drh
|
290 |
#endif |
|
7ef7284…
|
drh
|
291 |
|
|
7ef7284…
|
drh
|
292 |
/* |
|
f1f1d6c…
|
drh
|
293 |
Compare two filenames (fileName1,fileName2). |
|
f1f1d6c…
|
drh
|
294 |
If iCaseSensitivity = 1, comparison is case sensitive (like strcmp) |
|
f1f1d6c…
|
drh
|
295 |
If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi |
|
7ef7284…
|
drh
|
296 |
or strcasecmp) |
|
f1f1d6c…
|
drh
|
297 |
If iCaseSensitivity = 0, case sensitivity is default of your operating system |
|
7ef7284…
|
drh
|
298 |
(like 1 on Unix, 2 on Windows) |
|
7ef7284…
|
drh
|
299 |
|
|
7ef7284…
|
drh
|
300 |
*/ |
|
7ef7284…
|
drh
|
301 |
extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, |
|
f1f1d6c…
|
drh
|
302 |
const char* fileName2, |
|
f1f1d6c…
|
drh
|
303 |
int iCaseSensitivity) { |
|
7ef7284…
|
drh
|
304 |
if (iCaseSensitivity==0) |
|
7ef7284…
|
drh
|
305 |
iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; |
|
7ef7284…
|
drh
|
306 |
|
|
7ef7284…
|
drh
|
307 |
if (iCaseSensitivity==1) |
|
7ef7284…
|
drh
|
308 |
return strcmp(fileName1,fileName2); |
|
7ef7284…
|
drh
|
309 |
|
|
7ef7284…
|
drh
|
310 |
return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); |
|
7ef7284…
|
drh
|
311 |
} |
|
7ef7284…
|
drh
|
312 |
|
|
7ef7284…
|
drh
|
313 |
#ifndef BUFREADCOMMENT |
|
7ef7284…
|
drh
|
314 |
#define BUFREADCOMMENT (0x400) |
|
7ef7284…
|
drh
|
315 |
#endif |
|
7ef7284…
|
drh
|
316 |
|
|
f1f1d6c…
|
drh
|
317 |
#ifndef CENTRALDIRINVALID |
|
f1f1d6c…
|
drh
|
318 |
#define CENTRALDIRINVALID ((ZPOS64_T)(-1)) |
|
f1f1d6c…
|
drh
|
319 |
#endif |
|
f1f1d6c…
|
drh
|
320 |
|
|
7ef7284…
|
drh
|
321 |
/* |
|
7ef7284…
|
drh
|
322 |
Locate the Central directory of a zipfile (at the end, just before |
|
7ef7284…
|
drh
|
323 |
the global comment) |
|
7ef7284…
|
drh
|
324 |
*/ |
|
f1f1d6c…
|
drh
|
325 |
local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) { |
|
7ef7284…
|
drh
|
326 |
unsigned char* buf; |
|
7ef7284…
|
drh
|
327 |
ZPOS64_T uSizeFile; |
|
7ef7284…
|
drh
|
328 |
ZPOS64_T uBackRead; |
|
7ef7284…
|
drh
|
329 |
ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ |
|
f1f1d6c…
|
drh
|
330 |
ZPOS64_T uPosFound=CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
331 |
|
|
7ef7284…
|
drh
|
332 |
if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) |
|
f1f1d6c…
|
drh
|
333 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
334 |
|
|
7ef7284…
|
drh
|
335 |
|
|
7ef7284…
|
drh
|
336 |
uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); |
|
7ef7284…
|
drh
|
337 |
|
|
7ef7284…
|
drh
|
338 |
if (uMaxBack>uSizeFile) |
|
7ef7284…
|
drh
|
339 |
uMaxBack = uSizeFile; |
|
7ef7284…
|
drh
|
340 |
|
|
7ef7284…
|
drh
|
341 |
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); |
|
7ef7284…
|
drh
|
342 |
if (buf==NULL) |
|
f1f1d6c…
|
drh
|
343 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
344 |
|
|
7ef7284…
|
drh
|
345 |
uBackRead = 4; |
|
7ef7284…
|
drh
|
346 |
while (uBackRead<uMaxBack) |
|
7ef7284…
|
drh
|
347 |
{ |
|
7ef7284…
|
drh
|
348 |
uLong uReadSize; |
|
7ef7284…
|
drh
|
349 |
ZPOS64_T uReadPos ; |
|
7ef7284…
|
drh
|
350 |
int i; |
|
7ef7284…
|
drh
|
351 |
if (uBackRead+BUFREADCOMMENT>uMaxBack) |
|
7ef7284…
|
drh
|
352 |
uBackRead = uMaxBack; |
|
7ef7284…
|
drh
|
353 |
else |
|
7ef7284…
|
drh
|
354 |
uBackRead+=BUFREADCOMMENT; |
|
7ef7284…
|
drh
|
355 |
uReadPos = uSizeFile-uBackRead ; |
|
7ef7284…
|
drh
|
356 |
|
|
7ef7284…
|
drh
|
357 |
uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? |
|
7ef7284…
|
drh
|
358 |
(BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); |
|
7ef7284…
|
drh
|
359 |
if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
360 |
break; |
|
7ef7284…
|
drh
|
361 |
|
|
7ef7284…
|
drh
|
362 |
if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) |
|
7ef7284…
|
drh
|
363 |
break; |
|
7ef7284…
|
drh
|
364 |
|
|
7ef7284…
|
drh
|
365 |
for (i=(int)uReadSize-3; (i--)>0;) |
|
7ef7284…
|
drh
|
366 |
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && |
|
7ef7284…
|
drh
|
367 |
((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) |
|
7ef7284…
|
drh
|
368 |
{ |
|
adb9e8e…
|
drh
|
369 |
uPosFound = uReadPos+(unsigned)i; |
|
7ef7284…
|
drh
|
370 |
break; |
|
7ef7284…
|
drh
|
371 |
} |
|
7ef7284…
|
drh
|
372 |
|
|
f1f1d6c…
|
drh
|
373 |
if (uPosFound!=CENTRALDIRINVALID) |
|
7ef7284…
|
drh
|
374 |
break; |
|
7ef7284…
|
drh
|
375 |
} |
|
f1f1d6c…
|
drh
|
376 |
free(buf); |
|
7ef7284…
|
drh
|
377 |
return uPosFound; |
|
7ef7284…
|
drh
|
378 |
} |
|
7ef7284…
|
drh
|
379 |
|
|
7ef7284…
|
drh
|
380 |
|
|
7ef7284…
|
drh
|
381 |
/* |
|
7ef7284…
|
drh
|
382 |
Locate the Central directory 64 of a zipfile (at the end, just before |
|
7ef7284…
|
drh
|
383 |
the global comment) |
|
7ef7284…
|
drh
|
384 |
*/ |
|
7ef7284…
|
drh
|
385 |
local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, |
|
f1f1d6c…
|
drh
|
386 |
voidpf filestream) { |
|
7ef7284…
|
drh
|
387 |
unsigned char* buf; |
|
7ef7284…
|
drh
|
388 |
ZPOS64_T uSizeFile; |
|
7ef7284…
|
drh
|
389 |
ZPOS64_T uBackRead; |
|
7ef7284…
|
drh
|
390 |
ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ |
|
f1f1d6c…
|
drh
|
391 |
ZPOS64_T uPosFound=CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
392 |
uLong uL; |
|
7ef7284…
|
drh
|
393 |
ZPOS64_T relativeOffset; |
|
7ef7284…
|
drh
|
394 |
|
|
7ef7284…
|
drh
|
395 |
if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) |
|
f1f1d6c…
|
drh
|
396 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
397 |
|
|
7ef7284…
|
drh
|
398 |
|
|
7ef7284…
|
drh
|
399 |
uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); |
|
7ef7284…
|
drh
|
400 |
|
|
7ef7284…
|
drh
|
401 |
if (uMaxBack>uSizeFile) |
|
7ef7284…
|
drh
|
402 |
uMaxBack = uSizeFile; |
|
7ef7284…
|
drh
|
403 |
|
|
7ef7284…
|
drh
|
404 |
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); |
|
7ef7284…
|
drh
|
405 |
if (buf==NULL) |
|
f1f1d6c…
|
drh
|
406 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
407 |
|
|
7ef7284…
|
drh
|
408 |
uBackRead = 4; |
|
7ef7284…
|
drh
|
409 |
while (uBackRead<uMaxBack) |
|
7ef7284…
|
drh
|
410 |
{ |
|
7ef7284…
|
drh
|
411 |
uLong uReadSize; |
|
7ef7284…
|
drh
|
412 |
ZPOS64_T uReadPos; |
|
7ef7284…
|
drh
|
413 |
int i; |
|
7ef7284…
|
drh
|
414 |
if (uBackRead+BUFREADCOMMENT>uMaxBack) |
|
7ef7284…
|
drh
|
415 |
uBackRead = uMaxBack; |
|
7ef7284…
|
drh
|
416 |
else |
|
7ef7284…
|
drh
|
417 |
uBackRead+=BUFREADCOMMENT; |
|
7ef7284…
|
drh
|
418 |
uReadPos = uSizeFile-uBackRead ; |
|
7ef7284…
|
drh
|
419 |
|
|
7ef7284…
|
drh
|
420 |
uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? |
|
7ef7284…
|
drh
|
421 |
(BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); |
|
7ef7284…
|
drh
|
422 |
if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
423 |
break; |
|
7ef7284…
|
drh
|
424 |
|
|
7ef7284…
|
drh
|
425 |
if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) |
|
7ef7284…
|
drh
|
426 |
break; |
|
7ef7284…
|
drh
|
427 |
|
|
7ef7284…
|
drh
|
428 |
for (i=(int)uReadSize-3; (i--)>0;) |
|
7ef7284…
|
drh
|
429 |
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && |
|
7ef7284…
|
drh
|
430 |
((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) |
|
7ef7284…
|
drh
|
431 |
{ |
|
adb9e8e…
|
drh
|
432 |
uPosFound = uReadPos+(unsigned)i; |
|
7ef7284…
|
drh
|
433 |
break; |
|
7ef7284…
|
drh
|
434 |
} |
|
7ef7284…
|
drh
|
435 |
|
|
f1f1d6c…
|
drh
|
436 |
if (uPosFound!=CENTRALDIRINVALID) |
|
7ef7284…
|
drh
|
437 |
break; |
|
7ef7284…
|
drh
|
438 |
} |
|
f1f1d6c…
|
drh
|
439 |
free(buf); |
|
f1f1d6c…
|
drh
|
440 |
if (uPosFound == CENTRALDIRINVALID) |
|
f1f1d6c…
|
drh
|
441 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
442 |
|
|
7ef7284…
|
drh
|
443 |
/* Zip64 end of central directory locator */ |
|
7ef7284…
|
drh
|
444 |
if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
f1f1d6c…
|
drh
|
445 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
446 |
|
|
7ef7284…
|
drh
|
447 |
/* the signature, already checked */ |
|
7ef7284…
|
drh
|
448 |
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) |
|
f1f1d6c…
|
drh
|
449 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
450 |
|
|
64ce68d…
|
drh
|
451 |
/* number of the disk with the start of the zip64 end of central directory */ |
|
7ef7284…
|
drh
|
452 |
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) |
|
f1f1d6c…
|
drh
|
453 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
454 |
if (uL != 0) |
|
f1f1d6c…
|
drh
|
455 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
456 |
|
|
7ef7284…
|
drh
|
457 |
/* relative offset of the zip64 end of central directory record */ |
|
7ef7284…
|
drh
|
458 |
if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) |
|
f1f1d6c…
|
drh
|
459 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
460 |
|
|
7ef7284…
|
drh
|
461 |
/* total number of disks */ |
|
7ef7284…
|
drh
|
462 |
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) |
|
f1f1d6c…
|
drh
|
463 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
464 |
if (uL != 1) |
|
f1f1d6c…
|
drh
|
465 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
466 |
|
|
7ef7284…
|
drh
|
467 |
/* Goto end of central directory record */ |
|
7ef7284…
|
drh
|
468 |
if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
f1f1d6c…
|
drh
|
469 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
470 |
|
|
7ef7284…
|
drh
|
471 |
/* the signature */ |
|
7ef7284…
|
drh
|
472 |
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) |
|
f1f1d6c…
|
drh
|
473 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
474 |
|
|
7ef7284…
|
drh
|
475 |
if (uL != 0x06064b50) |
|
f1f1d6c…
|
drh
|
476 |
return CENTRALDIRINVALID; |
|
7ef7284…
|
drh
|
477 |
|
|
7ef7284…
|
drh
|
478 |
return relativeOffset; |
|
7ef7284…
|
drh
|
479 |
} |
|
7ef7284…
|
drh
|
480 |
|
|
7ef7284…
|
drh
|
481 |
/* |
|
7ef7284…
|
drh
|
482 |
Open a Zip file. path contain the full pathname (by example, |
|
7ef7284…
|
drh
|
483 |
on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer |
|
7ef7284…
|
drh
|
484 |
"zlib/zlib114.zip". |
|
7ef7284…
|
drh
|
485 |
If the zipfile cannot be opened (file doesn't exist or in not valid), the |
|
7ef7284…
|
drh
|
486 |
return value is NULL. |
|
7ef7284…
|
drh
|
487 |
Else, the return value is a unzFile Handle, usable with other function |
|
7ef7284…
|
drh
|
488 |
of this unzip package. |
|
7ef7284…
|
drh
|
489 |
*/ |
|
f1f1d6c…
|
drh
|
490 |
local unzFile unzOpenInternal(const void *path, |
|
f1f1d6c…
|
drh
|
491 |
zlib_filefunc64_32_def* pzlib_filefunc64_32_def, |
|
f1f1d6c…
|
drh
|
492 |
int is64bitOpenFunction) { |
|
7ef7284…
|
drh
|
493 |
unz64_s us; |
|
7ef7284…
|
drh
|
494 |
unz64_s *s; |
|
7ef7284…
|
drh
|
495 |
ZPOS64_T central_pos; |
|
7ef7284…
|
drh
|
496 |
uLong uL; |
|
7ef7284…
|
drh
|
497 |
|
|
64ce68d…
|
drh
|
498 |
uLong number_disk; /* number of the current disk, used for |
|
f1f1d6c…
|
drh
|
499 |
spanning ZIP, unsupported, always 0*/ |
|
64ce68d…
|
drh
|
500 |
uLong number_disk_with_CD; /* number the disk with central dir, used |
|
f1f1d6c…
|
drh
|
501 |
for spanning ZIP, unsupported, always 0*/ |
|
7ef7284…
|
drh
|
502 |
ZPOS64_T number_entry_CD; /* total number of entries in |
|
7ef7284…
|
drh
|
503 |
the central dir |
|
7ef7284…
|
drh
|
504 |
(same than number_entry on nospan) */ |
|
7ef7284…
|
drh
|
505 |
|
|
7ef7284…
|
drh
|
506 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
507 |
|
|
7ef7284…
|
drh
|
508 |
if (unz_copyright[0]!=' ') |
|
7ef7284…
|
drh
|
509 |
return NULL; |
|
7ef7284…
|
drh
|
510 |
|
|
7ef7284…
|
drh
|
511 |
us.z_filefunc.zseek32_file = NULL; |
|
7ef7284…
|
drh
|
512 |
us.z_filefunc.ztell32_file = NULL; |
|
7ef7284…
|
drh
|
513 |
if (pzlib_filefunc64_32_def==NULL) |
|
7ef7284…
|
drh
|
514 |
fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); |
|
7ef7284…
|
drh
|
515 |
else |
|
7ef7284…
|
drh
|
516 |
us.z_filefunc = *pzlib_filefunc64_32_def; |
|
7ef7284…
|
drh
|
517 |
us.is64bitOpenFunction = is64bitOpenFunction; |
|
7ef7284…
|
drh
|
518 |
|
|
7ef7284…
|
drh
|
519 |
|
|
7ef7284…
|
drh
|
520 |
|
|
7ef7284…
|
drh
|
521 |
us.filestream = ZOPEN64(us.z_filefunc, |
|
7ef7284…
|
drh
|
522 |
path, |
|
7ef7284…
|
drh
|
523 |
ZLIB_FILEFUNC_MODE_READ | |
|
7ef7284…
|
drh
|
524 |
ZLIB_FILEFUNC_MODE_EXISTING); |
|
7ef7284…
|
drh
|
525 |
if (us.filestream==NULL) |
|
7ef7284…
|
drh
|
526 |
return NULL; |
|
7ef7284…
|
drh
|
527 |
|
|
7ef7284…
|
drh
|
528 |
central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); |
|
f1f1d6c…
|
drh
|
529 |
if (central_pos!=CENTRALDIRINVALID) |
|
7ef7284…
|
drh
|
530 |
{ |
|
7ef7284…
|
drh
|
531 |
uLong uS; |
|
7ef7284…
|
drh
|
532 |
ZPOS64_T uL64; |
|
7ef7284…
|
drh
|
533 |
|
|
7ef7284…
|
drh
|
534 |
us.isZip64 = 1; |
|
7ef7284…
|
drh
|
535 |
|
|
7ef7284…
|
drh
|
536 |
if (ZSEEK64(us.z_filefunc, us.filestream, |
|
7ef7284…
|
drh
|
537 |
central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
538 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
539 |
|
|
7ef7284…
|
drh
|
540 |
/* the signature, already checked */ |
|
7ef7284…
|
drh
|
541 |
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
|
7ef7284…
|
drh
|
542 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
543 |
|
|
7ef7284…
|
drh
|
544 |
/* size of zip64 end of central directory record */ |
|
7ef7284…
|
drh
|
545 |
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) |
|
7ef7284…
|
drh
|
546 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
547 |
|
|
7ef7284…
|
drh
|
548 |
/* version made by */ |
|
7ef7284…
|
drh
|
549 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) |
|
7ef7284…
|
drh
|
550 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
551 |
|
|
7ef7284…
|
drh
|
552 |
/* version needed to extract */ |
|
7ef7284…
|
drh
|
553 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) |
|
7ef7284…
|
drh
|
554 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
555 |
|
|
7ef7284…
|
drh
|
556 |
/* number of this disk */ |
|
7ef7284…
|
drh
|
557 |
if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) |
|
7ef7284…
|
drh
|
558 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
559 |
|
|
7ef7284…
|
drh
|
560 |
/* number of the disk with the start of the central directory */ |
|
7ef7284…
|
drh
|
561 |
if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) |
|
7ef7284…
|
drh
|
562 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
563 |
|
|
7ef7284…
|
drh
|
564 |
/* total number of entries in the central directory on this disk */ |
|
7ef7284…
|
drh
|
565 |
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) |
|
7ef7284…
|
drh
|
566 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
567 |
|
|
7ef7284…
|
drh
|
568 |
/* total number of entries in the central directory */ |
|
7ef7284…
|
drh
|
569 |
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) |
|
7ef7284…
|
drh
|
570 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
571 |
|
|
7ef7284…
|
drh
|
572 |
if ((number_entry_CD!=us.gi.number_entry) || |
|
7ef7284…
|
drh
|
573 |
(number_disk_with_CD!=0) || |
|
7ef7284…
|
drh
|
574 |
(number_disk!=0)) |
|
7ef7284…
|
drh
|
575 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
576 |
|
|
7ef7284…
|
drh
|
577 |
/* size of the central directory */ |
|
7ef7284…
|
drh
|
578 |
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) |
|
7ef7284…
|
drh
|
579 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
580 |
|
|
7ef7284…
|
drh
|
581 |
/* offset of start of central directory with respect to the |
|
7ef7284…
|
drh
|
582 |
starting disk number */ |
|
7ef7284…
|
drh
|
583 |
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) |
|
7ef7284…
|
drh
|
584 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
585 |
|
|
7ef7284…
|
drh
|
586 |
us.gi.size_comment = 0; |
|
7ef7284…
|
drh
|
587 |
} |
|
7ef7284…
|
drh
|
588 |
else |
|
7ef7284…
|
drh
|
589 |
{ |
|
7ef7284…
|
drh
|
590 |
central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); |
|
f1f1d6c…
|
drh
|
591 |
if (central_pos==CENTRALDIRINVALID) |
|
7ef7284…
|
drh
|
592 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
593 |
|
|
7ef7284…
|
drh
|
594 |
us.isZip64 = 0; |
|
7ef7284…
|
drh
|
595 |
|
|
7ef7284…
|
drh
|
596 |
if (ZSEEK64(us.z_filefunc, us.filestream, |
|
7ef7284…
|
drh
|
597 |
central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
598 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
599 |
|
|
7ef7284…
|
drh
|
600 |
/* the signature, already checked */ |
|
7ef7284…
|
drh
|
601 |
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
|
7ef7284…
|
drh
|
602 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
603 |
|
|
7ef7284…
|
drh
|
604 |
/* number of this disk */ |
|
7ef7284…
|
drh
|
605 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) |
|
7ef7284…
|
drh
|
606 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
607 |
|
|
7ef7284…
|
drh
|
608 |
/* number of the disk with the start of the central directory */ |
|
7ef7284…
|
drh
|
609 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) |
|
7ef7284…
|
drh
|
610 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
611 |
|
|
7ef7284…
|
drh
|
612 |
/* total number of entries in the central dir on this disk */ |
|
7ef7284…
|
drh
|
613 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
|
7ef7284…
|
drh
|
614 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
615 |
us.gi.number_entry = uL; |
|
7ef7284…
|
drh
|
616 |
|
|
7ef7284…
|
drh
|
617 |
/* total number of entries in the central dir */ |
|
7ef7284…
|
drh
|
618 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
|
7ef7284…
|
drh
|
619 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
620 |
number_entry_CD = uL; |
|
7ef7284…
|
drh
|
621 |
|
|
7ef7284…
|
drh
|
622 |
if ((number_entry_CD!=us.gi.number_entry) || |
|
7ef7284…
|
drh
|
623 |
(number_disk_with_CD!=0) || |
|
7ef7284…
|
drh
|
624 |
(number_disk!=0)) |
|
7ef7284…
|
drh
|
625 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
626 |
|
|
7ef7284…
|
drh
|
627 |
/* size of the central directory */ |
|
7ef7284…
|
drh
|
628 |
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
|
7ef7284…
|
drh
|
629 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
630 |
us.size_central_dir = uL; |
|
7ef7284…
|
drh
|
631 |
|
|
7ef7284…
|
drh
|
632 |
/* offset of start of central directory with respect to the |
|
7ef7284…
|
drh
|
633 |
starting disk number */ |
|
7ef7284…
|
drh
|
634 |
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
|
7ef7284…
|
drh
|
635 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
636 |
us.offset_central_dir = uL; |
|
7ef7284…
|
drh
|
637 |
|
|
7ef7284…
|
drh
|
638 |
/* zipfile comment length */ |
|
7ef7284…
|
drh
|
639 |
if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) |
|
7ef7284…
|
drh
|
640 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
641 |
} |
|
7ef7284…
|
drh
|
642 |
|
|
7ef7284…
|
drh
|
643 |
if ((central_pos<us.offset_central_dir+us.size_central_dir) && |
|
7ef7284…
|
drh
|
644 |
(err==UNZ_OK)) |
|
7ef7284…
|
drh
|
645 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
646 |
|
|
7ef7284…
|
drh
|
647 |
if (err!=UNZ_OK) |
|
7ef7284…
|
drh
|
648 |
{ |
|
7ef7284…
|
drh
|
649 |
ZCLOSE64(us.z_filefunc, us.filestream); |
|
7ef7284…
|
drh
|
650 |
return NULL; |
|
7ef7284…
|
drh
|
651 |
} |
|
7ef7284…
|
drh
|
652 |
|
|
7ef7284…
|
drh
|
653 |
us.byte_before_the_zipfile = central_pos - |
|
7ef7284…
|
drh
|
654 |
(us.offset_central_dir+us.size_central_dir); |
|
7ef7284…
|
drh
|
655 |
us.central_pos = central_pos; |
|
7ef7284…
|
drh
|
656 |
us.pfile_in_zip_read = NULL; |
|
7ef7284…
|
drh
|
657 |
us.encrypted = 0; |
|
7ef7284…
|
drh
|
658 |
|
|
7ef7284…
|
drh
|
659 |
|
|
7ef7284…
|
drh
|
660 |
s=(unz64_s*)ALLOC(sizeof(unz64_s)); |
|
7ef7284…
|
drh
|
661 |
if( s != NULL) |
|
7ef7284…
|
drh
|
662 |
{ |
|
7ef7284…
|
drh
|
663 |
*s=us; |
|
7ef7284…
|
drh
|
664 |
unzGoToFirstFile((unzFile)s); |
|
7ef7284…
|
drh
|
665 |
} |
|
7ef7284…
|
drh
|
666 |
return (unzFile)s; |
|
7ef7284…
|
drh
|
667 |
} |
|
7ef7284…
|
drh
|
668 |
|
|
7ef7284…
|
drh
|
669 |
|
|
f1f1d6c…
|
drh
|
670 |
extern unzFile ZEXPORT unzOpen2(const char *path, |
|
f1f1d6c…
|
drh
|
671 |
zlib_filefunc_def* pzlib_filefunc32_def) { |
|
7ef7284…
|
drh
|
672 |
if (pzlib_filefunc32_def != NULL) |
|
7ef7284…
|
drh
|
673 |
{ |
|
7ef7284…
|
drh
|
674 |
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; |
|
7ef7284…
|
drh
|
675 |
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); |
|
7ef7284…
|
drh
|
676 |
return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0); |
|
7ef7284…
|
drh
|
677 |
} |
|
7ef7284…
|
drh
|
678 |
else |
|
7ef7284…
|
drh
|
679 |
return unzOpenInternal(path, NULL, 0); |
|
7ef7284…
|
drh
|
680 |
} |
|
7ef7284…
|
drh
|
681 |
|
|
f1f1d6c…
|
drh
|
682 |
extern unzFile ZEXPORT unzOpen2_64(const void *path, |
|
f1f1d6c…
|
drh
|
683 |
zlib_filefunc64_def* pzlib_filefunc_def) { |
|
7ef7284…
|
drh
|
684 |
if (pzlib_filefunc_def != NULL) |
|
7ef7284…
|
drh
|
685 |
{ |
|
7ef7284…
|
drh
|
686 |
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; |
|
7ef7284…
|
drh
|
687 |
zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; |
|
6ea30fb…
|
florian
|
688 |
zlib_filefunc64_32_def_fill.zopen32_file = NULL; |
|
7ef7284…
|
drh
|
689 |
zlib_filefunc64_32_def_fill.ztell32_file = NULL; |
|
7ef7284…
|
drh
|
690 |
zlib_filefunc64_32_def_fill.zseek32_file = NULL; |
|
7ef7284…
|
drh
|
691 |
return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1); |
|
7ef7284…
|
drh
|
692 |
} |
|
7ef7284…
|
drh
|
693 |
else |
|
7ef7284…
|
drh
|
694 |
return unzOpenInternal(path, NULL, 1); |
|
7ef7284…
|
drh
|
695 |
} |
|
7ef7284…
|
drh
|
696 |
|
|
f1f1d6c…
|
drh
|
697 |
extern unzFile ZEXPORT unzOpen(const char *path) { |
|
7ef7284…
|
drh
|
698 |
return unzOpenInternal(path, NULL, 0); |
|
7ef7284…
|
drh
|
699 |
} |
|
7ef7284…
|
drh
|
700 |
|
|
f1f1d6c…
|
drh
|
701 |
extern unzFile ZEXPORT unzOpen64(const void *path) { |
|
7ef7284…
|
drh
|
702 |
return unzOpenInternal(path, NULL, 1); |
|
7ef7284…
|
drh
|
703 |
} |
|
7ef7284…
|
drh
|
704 |
|
|
7ef7284…
|
drh
|
705 |
/* |
|
bb4776e…
|
jan.nijtmans
|
706 |
Close a ZipFile opened with unzOpen. |
|
bb4776e…
|
jan.nijtmans
|
707 |
If there is files inside the .Zip opened with unzOpenCurrentFile (see later), |
|
bb4776e…
|
jan.nijtmans
|
708 |
these files MUST be closed with unzCloseCurrentFile before call unzClose. |
|
7ef7284…
|
drh
|
709 |
return UNZ_OK if there is no problem. */ |
|
f1f1d6c…
|
drh
|
710 |
extern int ZEXPORT unzClose(unzFile file) { |
|
7ef7284…
|
drh
|
711 |
unz64_s* s; |
|
7ef7284…
|
drh
|
712 |
if (file==NULL) |
|
7ef7284…
|
drh
|
713 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
714 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
715 |
|
|
7ef7284…
|
drh
|
716 |
if (s->pfile_in_zip_read!=NULL) |
|
7ef7284…
|
drh
|
717 |
unzCloseCurrentFile(file); |
|
7ef7284…
|
drh
|
718 |
|
|
7ef7284…
|
drh
|
719 |
ZCLOSE64(s->z_filefunc, s->filestream); |
|
f1f1d6c…
|
drh
|
720 |
free(s); |
|
7ef7284…
|
drh
|
721 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
722 |
} |
|
7ef7284…
|
drh
|
723 |
|
|
7ef7284…
|
drh
|
724 |
|
|
7ef7284…
|
drh
|
725 |
/* |
|
7ef7284…
|
drh
|
726 |
Write info about the ZipFile in the *pglobal_info structure. |
|
7ef7284…
|
drh
|
727 |
No preparation of the structure is needed |
|
7ef7284…
|
drh
|
728 |
return UNZ_OK if there is no problem. */ |
|
f1f1d6c…
|
drh
|
729 |
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64* pglobal_info) { |
|
7ef7284…
|
drh
|
730 |
unz64_s* s; |
|
7ef7284…
|
drh
|
731 |
if (file==NULL) |
|
7ef7284…
|
drh
|
732 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
733 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
734 |
*pglobal_info=s->gi; |
|
7ef7284…
|
drh
|
735 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
736 |
} |
|
7ef7284…
|
drh
|
737 |
|
|
f1f1d6c…
|
drh
|
738 |
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32) { |
|
7ef7284…
|
drh
|
739 |
unz64_s* s; |
|
7ef7284…
|
drh
|
740 |
if (file==NULL) |
|
7ef7284…
|
drh
|
741 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
742 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
743 |
/* to do : check if number_entry is not truncated */ |
|
7ef7284…
|
drh
|
744 |
pglobal_info32->number_entry = (uLong)s->gi.number_entry; |
|
7ef7284…
|
drh
|
745 |
pglobal_info32->size_comment = s->gi.size_comment; |
|
7ef7284…
|
drh
|
746 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
747 |
} |
|
7ef7284…
|
drh
|
748 |
/* |
|
f1f1d6c…
|
drh
|
749 |
Translate date/time from Dos format to tm_unz (readable more easily) |
|
7ef7284…
|
drh
|
750 |
*/ |
|
f1f1d6c…
|
drh
|
751 |
local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz* ptm) { |
|
7ef7284…
|
drh
|
752 |
ZPOS64_T uDate; |
|
7ef7284…
|
drh
|
753 |
uDate = (ZPOS64_T)(ulDosDate>>16); |
|
adb9e8e…
|
drh
|
754 |
ptm->tm_mday = (int)(uDate&0x1f) ; |
|
adb9e8e…
|
drh
|
755 |
ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ; |
|
adb9e8e…
|
drh
|
756 |
ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ; |
|
7ef7284…
|
drh
|
757 |
|
|
adb9e8e…
|
drh
|
758 |
ptm->tm_hour = (int) ((ulDosDate &0xF800)/0x800); |
|
adb9e8e…
|
drh
|
759 |
ptm->tm_min = (int) ((ulDosDate&0x7E0)/0x20) ; |
|
adb9e8e…
|
drh
|
760 |
ptm->tm_sec = (int) (2*(ulDosDate&0x1f)) ; |
|
7ef7284…
|
drh
|
761 |
} |
|
7ef7284…
|
drh
|
762 |
|
|
7ef7284…
|
drh
|
763 |
/* |
|
7ef7284…
|
drh
|
764 |
Get Info about the current file in the zipfile, with internal only info |
|
7ef7284…
|
drh
|
765 |
*/ |
|
f1f1d6c…
|
drh
|
766 |
local int unz64local_GetCurrentFileInfoInternal(unzFile file, |
|
f1f1d6c…
|
drh
|
767 |
unz_file_info64 *pfile_info, |
|
f1f1d6c…
|
drh
|
768 |
unz_file_info64_internal |
|
f1f1d6c…
|
drh
|
769 |
*pfile_info_internal, |
|
f1f1d6c…
|
drh
|
770 |
char *szFileName, |
|
f1f1d6c…
|
drh
|
771 |
uLong fileNameBufferSize, |
|
f1f1d6c…
|
drh
|
772 |
void *extraField, |
|
f1f1d6c…
|
drh
|
773 |
uLong extraFieldBufferSize, |
|
f1f1d6c…
|
drh
|
774 |
char *szComment, |
|
f1f1d6c…
|
drh
|
775 |
uLong commentBufferSize) { |
|
7ef7284…
|
drh
|
776 |
unz64_s* s; |
|
7ef7284…
|
drh
|
777 |
unz_file_info64 file_info; |
|
7ef7284…
|
drh
|
778 |
unz_file_info64_internal file_info_internal; |
|
7ef7284…
|
drh
|
779 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
780 |
uLong uMagic; |
|
7ef7284…
|
drh
|
781 |
long lSeek=0; |
|
7ef7284…
|
drh
|
782 |
uLong uL; |
|
7ef7284…
|
drh
|
783 |
|
|
7ef7284…
|
drh
|
784 |
if (file==NULL) |
|
7ef7284…
|
drh
|
785 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
786 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
787 |
if (ZSEEK64(s->z_filefunc, s->filestream, |
|
7ef7284…
|
drh
|
788 |
s->pos_in_central_dir+s->byte_before_the_zipfile, |
|
7ef7284…
|
drh
|
789 |
ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
790 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
791 |
|
|
7ef7284…
|
drh
|
792 |
|
|
7ef7284…
|
drh
|
793 |
/* we check the magic */ |
|
7ef7284…
|
drh
|
794 |
if (err==UNZ_OK) |
|
7ef7284…
|
drh
|
795 |
{ |
|
7ef7284…
|
drh
|
796 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) |
|
7ef7284…
|
drh
|
797 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
798 |
else if (uMagic!=0x02014b50) |
|
7ef7284…
|
drh
|
799 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
800 |
} |
|
7ef7284…
|
drh
|
801 |
|
|
7ef7284…
|
drh
|
802 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) |
|
7ef7284…
|
drh
|
803 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
804 |
|
|
7ef7284…
|
drh
|
805 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) |
|
7ef7284…
|
drh
|
806 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
807 |
|
|
7ef7284…
|
drh
|
808 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) |
|
7ef7284…
|
drh
|
809 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
810 |
|
|
7ef7284…
|
drh
|
811 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) |
|
7ef7284…
|
drh
|
812 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
813 |
|
|
7ef7284…
|
drh
|
814 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) |
|
7ef7284…
|
drh
|
815 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
816 |
|
|
7ef7284…
|
drh
|
817 |
unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); |
|
7ef7284…
|
drh
|
818 |
|
|
7ef7284…
|
drh
|
819 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) |
|
7ef7284…
|
drh
|
820 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
821 |
|
|
7ef7284…
|
drh
|
822 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) |
|
7ef7284…
|
drh
|
823 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
824 |
file_info.compressed_size = uL; |
|
7ef7284…
|
drh
|
825 |
|
|
7ef7284…
|
drh
|
826 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) |
|
7ef7284…
|
drh
|
827 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
828 |
file_info.uncompressed_size = uL; |
|
7ef7284…
|
drh
|
829 |
|
|
7ef7284…
|
drh
|
830 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) |
|
7ef7284…
|
drh
|
831 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
832 |
|
|
7ef7284…
|
drh
|
833 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) |
|
7ef7284…
|
drh
|
834 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
835 |
|
|
7ef7284…
|
drh
|
836 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) |
|
7ef7284…
|
drh
|
837 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
838 |
|
|
7ef7284…
|
drh
|
839 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) |
|
7ef7284…
|
drh
|
840 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
841 |
|
|
7ef7284…
|
drh
|
842 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) |
|
7ef7284…
|
drh
|
843 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
844 |
|
|
7ef7284…
|
drh
|
845 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) |
|
7ef7284…
|
drh
|
846 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
847 |
|
|
6ea30fb…
|
florian
|
848 |
/* relative offset of local header */ |
|
7ef7284…
|
drh
|
849 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) |
|
7ef7284…
|
drh
|
850 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
851 |
file_info_internal.offset_curfile = uL; |
|
7ef7284…
|
drh
|
852 |
|
|
7ef7284…
|
drh
|
853 |
lSeek+=file_info.size_filename; |
|
7ef7284…
|
drh
|
854 |
if ((err==UNZ_OK) && (szFileName!=NULL)) |
|
7ef7284…
|
drh
|
855 |
{ |
|
7ef7284…
|
drh
|
856 |
uLong uSizeRead ; |
|
7ef7284…
|
drh
|
857 |
if (file_info.size_filename<fileNameBufferSize) |
|
7ef7284…
|
drh
|
858 |
{ |
|
7ef7284…
|
drh
|
859 |
*(szFileName+file_info.size_filename)='\0'; |
|
7ef7284…
|
drh
|
860 |
uSizeRead = file_info.size_filename; |
|
7ef7284…
|
drh
|
861 |
} |
|
7ef7284…
|
drh
|
862 |
else |
|
7ef7284…
|
drh
|
863 |
uSizeRead = fileNameBufferSize; |
|
7ef7284…
|
drh
|
864 |
|
|
7ef7284…
|
drh
|
865 |
if ((file_info.size_filename>0) && (fileNameBufferSize>0)) |
|
7ef7284…
|
drh
|
866 |
if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) |
|
7ef7284…
|
drh
|
867 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
868 |
lSeek -= uSizeRead; |
|
7ef7284…
|
drh
|
869 |
} |
|
7ef7284…
|
drh
|
870 |
|
|
6ea30fb…
|
florian
|
871 |
/* Read extrafield */ |
|
7ef7284…
|
drh
|
872 |
if ((err==UNZ_OK) && (extraField!=NULL)) |
|
7ef7284…
|
drh
|
873 |
{ |
|
7ef7284…
|
drh
|
874 |
ZPOS64_T uSizeRead ; |
|
7ef7284…
|
drh
|
875 |
if (file_info.size_file_extra<extraFieldBufferSize) |
|
7ef7284…
|
drh
|
876 |
uSizeRead = file_info.size_file_extra; |
|
7ef7284…
|
drh
|
877 |
else |
|
7ef7284…
|
drh
|
878 |
uSizeRead = extraFieldBufferSize; |
|
7ef7284…
|
drh
|
879 |
|
|
7ef7284…
|
drh
|
880 |
if (lSeek!=0) |
|
7ef7284…
|
drh
|
881 |
{ |
|
adb9e8e…
|
drh
|
882 |
if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) |
|
7ef7284…
|
drh
|
883 |
lSeek=0; |
|
7ef7284…
|
drh
|
884 |
else |
|
7ef7284…
|
drh
|
885 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
886 |
} |
|
7ef7284…
|
drh
|
887 |
|
|
7ef7284…
|
drh
|
888 |
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) |
|
7ef7284…
|
drh
|
889 |
if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) |
|
7ef7284…
|
drh
|
890 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
891 |
|
|
7ef7284…
|
drh
|
892 |
lSeek += file_info.size_file_extra - (uLong)uSizeRead; |
|
7ef7284…
|
drh
|
893 |
} |
|
7ef7284…
|
drh
|
894 |
else |
|
7ef7284…
|
drh
|
895 |
lSeek += file_info.size_file_extra; |
|
7ef7284…
|
drh
|
896 |
|
|
7ef7284…
|
drh
|
897 |
|
|
7ef7284…
|
drh
|
898 |
if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) |
|
7ef7284…
|
drh
|
899 |
{ |
|
7ef7284…
|
drh
|
900 |
uLong acc = 0; |
|
7ef7284…
|
drh
|
901 |
|
|
6ea30fb…
|
florian
|
902 |
/* since lSeek now points to after the extra field we need to move back */ |
|
7ef7284…
|
drh
|
903 |
lSeek -= file_info.size_file_extra; |
|
7ef7284…
|
drh
|
904 |
|
|
7ef7284…
|
drh
|
905 |
if (lSeek!=0) |
|
7ef7284…
|
drh
|
906 |
{ |
|
adb9e8e…
|
drh
|
907 |
if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) |
|
7ef7284…
|
drh
|
908 |
lSeek=0; |
|
7ef7284…
|
drh
|
909 |
else |
|
7ef7284…
|
drh
|
910 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
911 |
} |
|
7ef7284…
|
drh
|
912 |
|
|
7ef7284…
|
drh
|
913 |
while(acc < file_info.size_file_extra) |
|
7ef7284…
|
drh
|
914 |
{ |
|
7ef7284…
|
drh
|
915 |
uLong headerId; |
|
7ef7284…
|
drh
|
916 |
uLong dataSize; |
|
7ef7284…
|
drh
|
917 |
|
|
7ef7284…
|
drh
|
918 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) |
|
7ef7284…
|
drh
|
919 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
920 |
|
|
7ef7284…
|
drh
|
921 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) |
|
7ef7284…
|
drh
|
922 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
923 |
|
|
7ef7284…
|
drh
|
924 |
/* ZIP64 extra fields */ |
|
7ef7284…
|
drh
|
925 |
if (headerId == 0x0001) |
|
7ef7284…
|
drh
|
926 |
{ |
|
f1f1d6c…
|
drh
|
927 |
if(file_info.uncompressed_size == MAXU32) |
|
f1f1d6c…
|
drh
|
928 |
{ |
|
f1f1d6c…
|
drh
|
929 |
if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) |
|
f1f1d6c…
|
drh
|
930 |
err=UNZ_ERRNO; |
|
f1f1d6c…
|
drh
|
931 |
} |
|
f1f1d6c…
|
drh
|
932 |
|
|
f1f1d6c…
|
drh
|
933 |
if(file_info.compressed_size == MAXU32) |
|
f1f1d6c…
|
drh
|
934 |
{ |
|
f1f1d6c…
|
drh
|
935 |
if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) |
|
f1f1d6c…
|
drh
|
936 |
err=UNZ_ERRNO; |
|
f1f1d6c…
|
drh
|
937 |
} |
|
f1f1d6c…
|
drh
|
938 |
|
|
f1f1d6c…
|
drh
|
939 |
if(file_info_internal.offset_curfile == MAXU32) |
|
f1f1d6c…
|
drh
|
940 |
{ |
|
f1f1d6c…
|
drh
|
941 |
/* Relative Header offset */ |
|
f1f1d6c…
|
drh
|
942 |
if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) |
|
f1f1d6c…
|
drh
|
943 |
err=UNZ_ERRNO; |
|
f1f1d6c…
|
drh
|
944 |
} |
|
f1f1d6c…
|
drh
|
945 |
|
|
f1f1d6c…
|
drh
|
946 |
if(file_info.disk_num_start == 0xffff) |
|
f1f1d6c…
|
drh
|
947 |
{ |
|
f1f1d6c…
|
drh
|
948 |
/* Disk Start Number */ |
|
f1f1d6c…
|
drh
|
949 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) |
|
f1f1d6c…
|
drh
|
950 |
err=UNZ_ERRNO; |
|
f1f1d6c…
|
drh
|
951 |
} |
|
7ef7284…
|
drh
|
952 |
|
|
7ef7284…
|
drh
|
953 |
} |
|
7ef7284…
|
drh
|
954 |
else |
|
7ef7284…
|
drh
|
955 |
{ |
|
7ef7284…
|
drh
|
956 |
if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) |
|
7ef7284…
|
drh
|
957 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
958 |
} |
|
7ef7284…
|
drh
|
959 |
|
|
7ef7284…
|
drh
|
960 |
acc += 2 + 2 + dataSize; |
|
7ef7284…
|
drh
|
961 |
} |
|
7ef7284…
|
drh
|
962 |
} |
|
7ef7284…
|
drh
|
963 |
|
|
7ef7284…
|
drh
|
964 |
if ((err==UNZ_OK) && (szComment!=NULL)) |
|
7ef7284…
|
drh
|
965 |
{ |
|
7ef7284…
|
drh
|
966 |
uLong uSizeRead ; |
|
7ef7284…
|
drh
|
967 |
if (file_info.size_file_comment<commentBufferSize) |
|
7ef7284…
|
drh
|
968 |
{ |
|
7ef7284…
|
drh
|
969 |
*(szComment+file_info.size_file_comment)='\0'; |
|
7ef7284…
|
drh
|
970 |
uSizeRead = file_info.size_file_comment; |
|
7ef7284…
|
drh
|
971 |
} |
|
7ef7284…
|
drh
|
972 |
else |
|
7ef7284…
|
drh
|
973 |
uSizeRead = commentBufferSize; |
|
7ef7284…
|
drh
|
974 |
|
|
7ef7284…
|
drh
|
975 |
if (lSeek!=0) |
|
7ef7284…
|
drh
|
976 |
{ |
|
adb9e8e…
|
drh
|
977 |
if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) |
|
7ef7284…
|
drh
|
978 |
lSeek=0; |
|
7ef7284…
|
drh
|
979 |
else |
|
7ef7284…
|
drh
|
980 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
981 |
} |
|
7ef7284…
|
drh
|
982 |
|
|
7ef7284…
|
drh
|
983 |
if ((file_info.size_file_comment>0) && (commentBufferSize>0)) |
|
7ef7284…
|
drh
|
984 |
if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) |
|
7ef7284…
|
drh
|
985 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
986 |
lSeek+=file_info.size_file_comment - uSizeRead; |
|
7ef7284…
|
drh
|
987 |
} |
|
7ef7284…
|
drh
|
988 |
else |
|
7ef7284…
|
drh
|
989 |
lSeek+=file_info.size_file_comment; |
|
7ef7284…
|
drh
|
990 |
|
|
7ef7284…
|
drh
|
991 |
|
|
7ef7284…
|
drh
|
992 |
if ((err==UNZ_OK) && (pfile_info!=NULL)) |
|
7ef7284…
|
drh
|
993 |
*pfile_info=file_info; |
|
7ef7284…
|
drh
|
994 |
|
|
7ef7284…
|
drh
|
995 |
if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) |
|
7ef7284…
|
drh
|
996 |
*pfile_info_internal=file_info_internal; |
|
7ef7284…
|
drh
|
997 |
|
|
7ef7284…
|
drh
|
998 |
return err; |
|
7ef7284…
|
drh
|
999 |
} |
|
7ef7284…
|
drh
|
1000 |
|
|
7ef7284…
|
drh
|
1001 |
|
|
7ef7284…
|
drh
|
1002 |
|
|
7ef7284…
|
drh
|
1003 |
/* |
|
7ef7284…
|
drh
|
1004 |
Write info about the ZipFile in the *pglobal_info structure. |
|
7ef7284…
|
drh
|
1005 |
No preparation of the structure is needed |
|
7ef7284…
|
drh
|
1006 |
return UNZ_OK if there is no problem. |
|
7ef7284…
|
drh
|
1007 |
*/ |
|
f1f1d6c…
|
drh
|
1008 |
extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, |
|
f1f1d6c…
|
drh
|
1009 |
unz_file_info64 * pfile_info, |
|
f1f1d6c…
|
drh
|
1010 |
char * szFileName, uLong fileNameBufferSize, |
|
f1f1d6c…
|
drh
|
1011 |
void *extraField, uLong extraFieldBufferSize, |
|
f1f1d6c…
|
drh
|
1012 |
char* szComment, uLong commentBufferSize) { |
|
7ef7284…
|
drh
|
1013 |
return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, |
|
f1f1d6c…
|
drh
|
1014 |
szFileName,fileNameBufferSize, |
|
f1f1d6c…
|
drh
|
1015 |
extraField,extraFieldBufferSize, |
|
f1f1d6c…
|
drh
|
1016 |
szComment,commentBufferSize); |
|
7ef7284…
|
drh
|
1017 |
} |
|
7ef7284…
|
drh
|
1018 |
|
|
f1f1d6c…
|
drh
|
1019 |
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, |
|
f1f1d6c…
|
drh
|
1020 |
unz_file_info * pfile_info, |
|
f1f1d6c…
|
drh
|
1021 |
char * szFileName, uLong fileNameBufferSize, |
|
f1f1d6c…
|
drh
|
1022 |
void *extraField, uLong extraFieldBufferSize, |
|
f1f1d6c…
|
drh
|
1023 |
char* szComment, uLong commentBufferSize) { |
|
7ef7284…
|
drh
|
1024 |
int err; |
|
7ef7284…
|
drh
|
1025 |
unz_file_info64 file_info64; |
|
7ef7284…
|
drh
|
1026 |
err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, |
|
7ef7284…
|
drh
|
1027 |
szFileName,fileNameBufferSize, |
|
7ef7284…
|
drh
|
1028 |
extraField,extraFieldBufferSize, |
|
7ef7284…
|
drh
|
1029 |
szComment,commentBufferSize); |
|
7ef7284…
|
drh
|
1030 |
if ((err==UNZ_OK) && (pfile_info != NULL)) |
|
7ef7284…
|
drh
|
1031 |
{ |
|
7ef7284…
|
drh
|
1032 |
pfile_info->version = file_info64.version; |
|
7ef7284…
|
drh
|
1033 |
pfile_info->version_needed = file_info64.version_needed; |
|
7ef7284…
|
drh
|
1034 |
pfile_info->flag = file_info64.flag; |
|
7ef7284…
|
drh
|
1035 |
pfile_info->compression_method = file_info64.compression_method; |
|
7ef7284…
|
drh
|
1036 |
pfile_info->dosDate = file_info64.dosDate; |
|
7ef7284…
|
drh
|
1037 |
pfile_info->crc = file_info64.crc; |
|
7ef7284…
|
drh
|
1038 |
|
|
7ef7284…
|
drh
|
1039 |
pfile_info->size_filename = file_info64.size_filename; |
|
7ef7284…
|
drh
|
1040 |
pfile_info->size_file_extra = file_info64.size_file_extra; |
|
7ef7284…
|
drh
|
1041 |
pfile_info->size_file_comment = file_info64.size_file_comment; |
|
7ef7284…
|
drh
|
1042 |
|
|
7ef7284…
|
drh
|
1043 |
pfile_info->disk_num_start = file_info64.disk_num_start; |
|
7ef7284…
|
drh
|
1044 |
pfile_info->internal_fa = file_info64.internal_fa; |
|
7ef7284…
|
drh
|
1045 |
pfile_info->external_fa = file_info64.external_fa; |
|
7ef7284…
|
drh
|
1046 |
|
|
f1f1d6c…
|
drh
|
1047 |
pfile_info->tmu_date = file_info64.tmu_date; |
|
7ef7284…
|
drh
|
1048 |
|
|
7ef7284…
|
drh
|
1049 |
|
|
7ef7284…
|
drh
|
1050 |
pfile_info->compressed_size = (uLong)file_info64.compressed_size; |
|
7ef7284…
|
drh
|
1051 |
pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; |
|
7ef7284…
|
drh
|
1052 |
|
|
7ef7284…
|
drh
|
1053 |
} |
|
7ef7284…
|
drh
|
1054 |
return err; |
|
7ef7284…
|
drh
|
1055 |
} |
|
7ef7284…
|
drh
|
1056 |
/* |
|
7ef7284…
|
drh
|
1057 |
Set the current file of the zipfile to the first file. |
|
7ef7284…
|
drh
|
1058 |
return UNZ_OK if there is no problem |
|
7ef7284…
|
drh
|
1059 |
*/ |
|
f1f1d6c…
|
drh
|
1060 |
extern int ZEXPORT unzGoToFirstFile(unzFile file) { |
|
7ef7284…
|
drh
|
1061 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
1062 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1063 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1064 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1065 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1066 |
s->pos_in_central_dir=s->offset_central_dir; |
|
7ef7284…
|
drh
|
1067 |
s->num_file=0; |
|
7ef7284…
|
drh
|
1068 |
err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
|
7ef7284…
|
drh
|
1069 |
&s->cur_file_info_internal, |
|
7ef7284…
|
drh
|
1070 |
NULL,0,NULL,0,NULL,0); |
|
7ef7284…
|
drh
|
1071 |
s->current_file_ok = (err == UNZ_OK); |
|
7ef7284…
|
drh
|
1072 |
return err; |
|
7ef7284…
|
drh
|
1073 |
} |
|
7ef7284…
|
drh
|
1074 |
|
|
7ef7284…
|
drh
|
1075 |
/* |
|
7ef7284…
|
drh
|
1076 |
Set the current file of the zipfile to the next file. |
|
7ef7284…
|
drh
|
1077 |
return UNZ_OK if there is no problem |
|
7ef7284…
|
drh
|
1078 |
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. |
|
7ef7284…
|
drh
|
1079 |
*/ |
|
f1f1d6c…
|
drh
|
1080 |
extern int ZEXPORT unzGoToNextFile(unzFile file) { |
|
7ef7284…
|
drh
|
1081 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1082 |
int err; |
|
7ef7284…
|
drh
|
1083 |
|
|
7ef7284…
|
drh
|
1084 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1085 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1086 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1087 |
if (!s->current_file_ok) |
|
7ef7284…
|
drh
|
1088 |
return UNZ_END_OF_LIST_OF_FILE; |
|
7ef7284…
|
drh
|
1089 |
if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ |
|
7ef7284…
|
drh
|
1090 |
if (s->num_file+1==s->gi.number_entry) |
|
7ef7284…
|
drh
|
1091 |
return UNZ_END_OF_LIST_OF_FILE; |
|
7ef7284…
|
drh
|
1092 |
|
|
7ef7284…
|
drh
|
1093 |
s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + |
|
7ef7284…
|
drh
|
1094 |
s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; |
|
7ef7284…
|
drh
|
1095 |
s->num_file++; |
|
7ef7284…
|
drh
|
1096 |
err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
|
7ef7284…
|
drh
|
1097 |
&s->cur_file_info_internal, |
|
7ef7284…
|
drh
|
1098 |
NULL,0,NULL,0,NULL,0); |
|
7ef7284…
|
drh
|
1099 |
s->current_file_ok = (err == UNZ_OK); |
|
7ef7284…
|
drh
|
1100 |
return err; |
|
7ef7284…
|
drh
|
1101 |
} |
|
7ef7284…
|
drh
|
1102 |
|
|
7ef7284…
|
drh
|
1103 |
|
|
7ef7284…
|
drh
|
1104 |
/* |
|
7ef7284…
|
drh
|
1105 |
Try locate the file szFileName in the zipfile. |
|
bb4776e…
|
jan.nijtmans
|
1106 |
For the iCaseSensitivity signification, see unzStringFileNameCompare |
|
7ef7284…
|
drh
|
1107 |
|
|
7ef7284…
|
drh
|
1108 |
return value : |
|
7ef7284…
|
drh
|
1109 |
UNZ_OK if the file is found. It becomes the current file. |
|
7ef7284…
|
drh
|
1110 |
UNZ_END_OF_LIST_OF_FILE if the file is not found |
|
7ef7284…
|
drh
|
1111 |
*/ |
|
f1f1d6c…
|
drh
|
1112 |
extern int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) { |
|
7ef7284…
|
drh
|
1113 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1114 |
int err; |
|
7ef7284…
|
drh
|
1115 |
|
|
7ef7284…
|
drh
|
1116 |
/* We remember the 'current' position in the file so that we can jump |
|
7ef7284…
|
drh
|
1117 |
* back there if we fail. |
|
7ef7284…
|
drh
|
1118 |
*/ |
|
7ef7284…
|
drh
|
1119 |
unz_file_info64 cur_file_infoSaved; |
|
7ef7284…
|
drh
|
1120 |
unz_file_info64_internal cur_file_info_internalSaved; |
|
7ef7284…
|
drh
|
1121 |
ZPOS64_T num_fileSaved; |
|
7ef7284…
|
drh
|
1122 |
ZPOS64_T pos_in_central_dirSaved; |
|
7ef7284…
|
drh
|
1123 |
|
|
7ef7284…
|
drh
|
1124 |
|
|
7ef7284…
|
drh
|
1125 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1126 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1127 |
|
|
7ef7284…
|
drh
|
1128 |
if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) |
|
7ef7284…
|
drh
|
1129 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1130 |
|
|
7ef7284…
|
drh
|
1131 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1132 |
if (!s->current_file_ok) |
|
7ef7284…
|
drh
|
1133 |
return UNZ_END_OF_LIST_OF_FILE; |
|
7ef7284…
|
drh
|
1134 |
|
|
7ef7284…
|
drh
|
1135 |
/* Save the current state */ |
|
7ef7284…
|
drh
|
1136 |
num_fileSaved = s->num_file; |
|
7ef7284…
|
drh
|
1137 |
pos_in_central_dirSaved = s->pos_in_central_dir; |
|
7ef7284…
|
drh
|
1138 |
cur_file_infoSaved = s->cur_file_info; |
|
7ef7284…
|
drh
|
1139 |
cur_file_info_internalSaved = s->cur_file_info_internal; |
|
7ef7284…
|
drh
|
1140 |
|
|
7ef7284…
|
drh
|
1141 |
err = unzGoToFirstFile(file); |
|
7ef7284…
|
drh
|
1142 |
|
|
7ef7284…
|
drh
|
1143 |
while (err == UNZ_OK) |
|
7ef7284…
|
drh
|
1144 |
{ |
|
7ef7284…
|
drh
|
1145 |
char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; |
|
7ef7284…
|
drh
|
1146 |
err = unzGetCurrentFileInfo64(file,NULL, |
|
7ef7284…
|
drh
|
1147 |
szCurrentFileName,sizeof(szCurrentFileName)-1, |
|
7ef7284…
|
drh
|
1148 |
NULL,0,NULL,0); |
|
7ef7284…
|
drh
|
1149 |
if (err == UNZ_OK) |
|
7ef7284…
|
drh
|
1150 |
{ |
|
7ef7284…
|
drh
|
1151 |
if (unzStringFileNameCompare(szCurrentFileName, |
|
7ef7284…
|
drh
|
1152 |
szFileName,iCaseSensitivity)==0) |
|
7ef7284…
|
drh
|
1153 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
1154 |
err = unzGoToNextFile(file); |
|
7ef7284…
|
drh
|
1155 |
} |
|
7ef7284…
|
drh
|
1156 |
} |
|
7ef7284…
|
drh
|
1157 |
|
|
7ef7284…
|
drh
|
1158 |
/* We failed, so restore the state of the 'current file' to where we |
|
7ef7284…
|
drh
|
1159 |
* were. |
|
7ef7284…
|
drh
|
1160 |
*/ |
|
7ef7284…
|
drh
|
1161 |
s->num_file = num_fileSaved ; |
|
7ef7284…
|
drh
|
1162 |
s->pos_in_central_dir = pos_in_central_dirSaved ; |
|
7ef7284…
|
drh
|
1163 |
s->cur_file_info = cur_file_infoSaved; |
|
7ef7284…
|
drh
|
1164 |
s->cur_file_info_internal = cur_file_info_internalSaved; |
|
7ef7284…
|
drh
|
1165 |
return err; |
|
7ef7284…
|
drh
|
1166 |
} |
|
7ef7284…
|
drh
|
1167 |
|
|
7ef7284…
|
drh
|
1168 |
|
|
7ef7284…
|
drh
|
1169 |
/* |
|
7ef7284…
|
drh
|
1170 |
/////////////////////////////////////////// |
|
7ef7284…
|
drh
|
1171 |
// Contributed by Ryan Haksi (mailto://[email protected]) |
|
7ef7284…
|
drh
|
1172 |
// I need random access |
|
7ef7284…
|
drh
|
1173 |
// |
|
7ef7284…
|
drh
|
1174 |
// Further optimization could be realized by adding an ability |
|
7ef7284…
|
drh
|
1175 |
// to cache the directory in memory. The goal being a single |
|
7ef7284…
|
drh
|
1176 |
// comprehensive file read to put the file I need in a memory. |
|
7ef7284…
|
drh
|
1177 |
*/ |
|
7ef7284…
|
drh
|
1178 |
|
|
7ef7284…
|
drh
|
1179 |
/* |
|
7ef7284…
|
drh
|
1180 |
typedef struct unz_file_pos_s |
|
7ef7284…
|
drh
|
1181 |
{ |
|
7ef7284…
|
drh
|
1182 |
ZPOS64_T pos_in_zip_directory; // offset in file |
|
7ef7284…
|
drh
|
1183 |
ZPOS64_T num_of_file; // # of file |
|
7ef7284…
|
drh
|
1184 |
} unz_file_pos; |
|
7ef7284…
|
drh
|
1185 |
*/ |
|
7ef7284…
|
drh
|
1186 |
|
|
f1f1d6c…
|
drh
|
1187 |
extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) { |
|
7ef7284…
|
drh
|
1188 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1189 |
|
|
7ef7284…
|
drh
|
1190 |
if (file==NULL || file_pos==NULL) |
|
7ef7284…
|
drh
|
1191 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1192 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1193 |
if (!s->current_file_ok) |
|
7ef7284…
|
drh
|
1194 |
return UNZ_END_OF_LIST_OF_FILE; |
|
7ef7284…
|
drh
|
1195 |
|
|
7ef7284…
|
drh
|
1196 |
file_pos->pos_in_zip_directory = s->pos_in_central_dir; |
|
7ef7284…
|
drh
|
1197 |
file_pos->num_of_file = s->num_file; |
|
7ef7284…
|
drh
|
1198 |
|
|
7ef7284…
|
drh
|
1199 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
1200 |
} |
|
7ef7284…
|
drh
|
1201 |
|
|
f1f1d6c…
|
drh
|
1202 |
extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos) { |
|
7ef7284…
|
drh
|
1203 |
unz64_file_pos file_pos64; |
|
7ef7284…
|
drh
|
1204 |
int err = unzGetFilePos64(file,&file_pos64); |
|
7ef7284…
|
drh
|
1205 |
if (err==UNZ_OK) |
|
7ef7284…
|
drh
|
1206 |
{ |
|
7ef7284…
|
drh
|
1207 |
file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; |
|
7ef7284…
|
drh
|
1208 |
file_pos->num_of_file = (uLong)file_pos64.num_of_file; |
|
7ef7284…
|
drh
|
1209 |
} |
|
7ef7284…
|
drh
|
1210 |
return err; |
|
7ef7284…
|
drh
|
1211 |
} |
|
7ef7284…
|
drh
|
1212 |
|
|
f1f1d6c…
|
drh
|
1213 |
extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) { |
|
7ef7284…
|
drh
|
1214 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1215 |
int err; |
|
7ef7284…
|
drh
|
1216 |
|
|
7ef7284…
|
drh
|
1217 |
if (file==NULL || file_pos==NULL) |
|
7ef7284…
|
drh
|
1218 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1219 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1220 |
|
|
7ef7284…
|
drh
|
1221 |
/* jump to the right spot */ |
|
7ef7284…
|
drh
|
1222 |
s->pos_in_central_dir = file_pos->pos_in_zip_directory; |
|
7ef7284…
|
drh
|
1223 |
s->num_file = file_pos->num_of_file; |
|
7ef7284…
|
drh
|
1224 |
|
|
7ef7284…
|
drh
|
1225 |
/* set the current file */ |
|
7ef7284…
|
drh
|
1226 |
err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
|
7ef7284…
|
drh
|
1227 |
&s->cur_file_info_internal, |
|
7ef7284…
|
drh
|
1228 |
NULL,0,NULL,0,NULL,0); |
|
7ef7284…
|
drh
|
1229 |
/* return results */ |
|
7ef7284…
|
drh
|
1230 |
s->current_file_ok = (err == UNZ_OK); |
|
7ef7284…
|
drh
|
1231 |
return err; |
|
7ef7284…
|
drh
|
1232 |
} |
|
7ef7284…
|
drh
|
1233 |
|
|
f1f1d6c…
|
drh
|
1234 |
extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos) { |
|
7ef7284…
|
drh
|
1235 |
unz64_file_pos file_pos64; |
|
7ef7284…
|
drh
|
1236 |
if (file_pos == NULL) |
|
7ef7284…
|
drh
|
1237 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1238 |
|
|
7ef7284…
|
drh
|
1239 |
file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; |
|
7ef7284…
|
drh
|
1240 |
file_pos64.num_of_file = file_pos->num_of_file; |
|
7ef7284…
|
drh
|
1241 |
return unzGoToFilePos64(file,&file_pos64); |
|
7ef7284…
|
drh
|
1242 |
} |
|
7ef7284…
|
drh
|
1243 |
|
|
7ef7284…
|
drh
|
1244 |
/* |
|
7ef7284…
|
drh
|
1245 |
// Unzip Helper Functions - should be here? |
|
7ef7284…
|
drh
|
1246 |
/////////////////////////////////////////// |
|
7ef7284…
|
drh
|
1247 |
*/ |
|
7ef7284…
|
drh
|
1248 |
|
|
7ef7284…
|
drh
|
1249 |
/* |
|
7ef7284…
|
drh
|
1250 |
Read the local header of the current zipfile |
|
7ef7284…
|
drh
|
1251 |
Check the coherency of the local header and info in the end of central |
|
7ef7284…
|
drh
|
1252 |
directory about this file |
|
7ef7284…
|
drh
|
1253 |
store in *piSizeVar the size of extra info in local header |
|
7ef7284…
|
drh
|
1254 |
(filename and size of extra field data) |
|
7ef7284…
|
drh
|
1255 |
*/ |
|
f1f1d6c…
|
drh
|
1256 |
local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar, |
|
f1f1d6c…
|
drh
|
1257 |
ZPOS64_T * poffset_local_extrafield, |
|
f1f1d6c…
|
drh
|
1258 |
uInt * psize_local_extrafield) { |
|
7ef7284…
|
drh
|
1259 |
uLong uMagic,uData,uFlags; |
|
7ef7284…
|
drh
|
1260 |
uLong size_filename; |
|
7ef7284…
|
drh
|
1261 |
uLong size_extra_field; |
|
7ef7284…
|
drh
|
1262 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
1263 |
|
|
7ef7284…
|
drh
|
1264 |
*piSizeVar = 0; |
|
7ef7284…
|
drh
|
1265 |
*poffset_local_extrafield = 0; |
|
7ef7284…
|
drh
|
1266 |
*psize_local_extrafield = 0; |
|
7ef7284…
|
drh
|
1267 |
|
|
7ef7284…
|
drh
|
1268 |
if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + |
|
7ef7284…
|
drh
|
1269 |
s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
1270 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1271 |
|
|
7ef7284…
|
drh
|
1272 |
|
|
7ef7284…
|
drh
|
1273 |
if (err==UNZ_OK) |
|
7ef7284…
|
drh
|
1274 |
{ |
|
7ef7284…
|
drh
|
1275 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) |
|
7ef7284…
|
drh
|
1276 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1277 |
else if (uMagic!=0x04034b50) |
|
7ef7284…
|
drh
|
1278 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1279 |
} |
|
7ef7284…
|
drh
|
1280 |
|
|
7ef7284…
|
drh
|
1281 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) |
|
7ef7284…
|
drh
|
1282 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1283 |
/* |
|
7ef7284…
|
drh
|
1284 |
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) |
|
7ef7284…
|
drh
|
1285 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1286 |
*/ |
|
7ef7284…
|
drh
|
1287 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) |
|
7ef7284…
|
drh
|
1288 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1289 |
|
|
7ef7284…
|
drh
|
1290 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) |
|
7ef7284…
|
drh
|
1291 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1292 |
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) |
|
7ef7284…
|
drh
|
1293 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1294 |
|
|
7ef7284…
|
drh
|
1295 |
if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && |
|
7ef7284…
|
drh
|
1296 |
/* #ifdef HAVE_BZIP2 */ |
|
7ef7284…
|
drh
|
1297 |
(s->cur_file_info.compression_method!=Z_BZIP2ED) && |
|
7ef7284…
|
drh
|
1298 |
/* #endif */ |
|
7ef7284…
|
drh
|
1299 |
(s->cur_file_info.compression_method!=Z_DEFLATED)) |
|
7ef7284…
|
drh
|
1300 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1301 |
|
|
7ef7284…
|
drh
|
1302 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ |
|
7ef7284…
|
drh
|
1303 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1304 |
|
|
7ef7284…
|
drh
|
1305 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ |
|
7ef7284…
|
drh
|
1306 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1307 |
else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) |
|
7ef7284…
|
drh
|
1308 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1309 |
|
|
7ef7284…
|
drh
|
1310 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ |
|
7ef7284…
|
drh
|
1311 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1312 |
else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) |
|
7ef7284…
|
drh
|
1313 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1314 |
|
|
7ef7284…
|
drh
|
1315 |
if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ |
|
7ef7284…
|
drh
|
1316 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1317 |
else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) |
|
7ef7284…
|
drh
|
1318 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1319 |
|
|
7ef7284…
|
drh
|
1320 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) |
|
7ef7284…
|
drh
|
1321 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1322 |
else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) |
|
7ef7284…
|
drh
|
1323 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1324 |
|
|
7ef7284…
|
drh
|
1325 |
*piSizeVar += (uInt)size_filename; |
|
7ef7284…
|
drh
|
1326 |
|
|
7ef7284…
|
drh
|
1327 |
if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) |
|
7ef7284…
|
drh
|
1328 |
err=UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1329 |
*poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + |
|
7ef7284…
|
drh
|
1330 |
SIZEZIPLOCALHEADER + size_filename; |
|
7ef7284…
|
drh
|
1331 |
*psize_local_extrafield = (uInt)size_extra_field; |
|
7ef7284…
|
drh
|
1332 |
|
|
7ef7284…
|
drh
|
1333 |
*piSizeVar += (uInt)size_extra_field; |
|
7ef7284…
|
drh
|
1334 |
|
|
7ef7284…
|
drh
|
1335 |
return err; |
|
7ef7284…
|
drh
|
1336 |
} |
|
7ef7284…
|
drh
|
1337 |
|
|
7ef7284…
|
drh
|
1338 |
/* |
|
7ef7284…
|
drh
|
1339 |
Open for reading data the current file in the zipfile. |
|
7ef7284…
|
drh
|
1340 |
If there is no error and the file is opened, the return value is UNZ_OK. |
|
7ef7284…
|
drh
|
1341 |
*/ |
|
f1f1d6c…
|
drh
|
1342 |
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, |
|
f1f1d6c…
|
drh
|
1343 |
int* level, int raw, const char* password) { |
|
7ef7284…
|
drh
|
1344 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
1345 |
uInt iSizeVar; |
|
7ef7284…
|
drh
|
1346 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1347 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1348 |
ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ |
|
7ef7284…
|
drh
|
1349 |
uInt size_local_extrafield; /* size of the local extra field */ |
|
7ef7284…
|
drh
|
1350 |
# ifndef NOUNCRYPT |
|
7ef7284…
|
drh
|
1351 |
char source[12]; |
|
7ef7284…
|
drh
|
1352 |
# else |
|
7ef7284…
|
drh
|
1353 |
if (password != NULL) |
|
7ef7284…
|
drh
|
1354 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1355 |
# endif |
|
7ef7284…
|
drh
|
1356 |
|
|
7ef7284…
|
drh
|
1357 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1358 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1359 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1360 |
if (!s->current_file_ok) |
|
7ef7284…
|
drh
|
1361 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1362 |
|
|
7ef7284…
|
drh
|
1363 |
if (s->pfile_in_zip_read != NULL) |
|
7ef7284…
|
drh
|
1364 |
unzCloseCurrentFile(file); |
|
7ef7284…
|
drh
|
1365 |
|
|
7ef7284…
|
drh
|
1366 |
if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) |
|
7ef7284…
|
drh
|
1367 |
return UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1368 |
|
|
7ef7284…
|
drh
|
1369 |
pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); |
|
7ef7284…
|
drh
|
1370 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1371 |
return UNZ_INTERNALERROR; |
|
7ef7284…
|
drh
|
1372 |
|
|
7ef7284…
|
drh
|
1373 |
pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); |
|
7ef7284…
|
drh
|
1374 |
pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; |
|
7ef7284…
|
drh
|
1375 |
pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; |
|
7ef7284…
|
drh
|
1376 |
pfile_in_zip_read_info->pos_local_extrafield=0; |
|
7ef7284…
|
drh
|
1377 |
pfile_in_zip_read_info->raw=raw; |
|
7ef7284…
|
drh
|
1378 |
|
|
7ef7284…
|
drh
|
1379 |
if (pfile_in_zip_read_info->read_buffer==NULL) |
|
7ef7284…
|
drh
|
1380 |
{ |
|
f1f1d6c…
|
drh
|
1381 |
free(pfile_in_zip_read_info); |
|
7ef7284…
|
drh
|
1382 |
return UNZ_INTERNALERROR; |
|
7ef7284…
|
drh
|
1383 |
} |
|
7ef7284…
|
drh
|
1384 |
|
|
7ef7284…
|
drh
|
1385 |
pfile_in_zip_read_info->stream_initialised=0; |
|
7ef7284…
|
drh
|
1386 |
|
|
7ef7284…
|
drh
|
1387 |
if (method!=NULL) |
|
7ef7284…
|
drh
|
1388 |
*method = (int)s->cur_file_info.compression_method; |
|
7ef7284…
|
drh
|
1389 |
|
|
7ef7284…
|
drh
|
1390 |
if (level!=NULL) |
|
7ef7284…
|
drh
|
1391 |
{ |
|
7ef7284…
|
drh
|
1392 |
*level = 6; |
|
7ef7284…
|
drh
|
1393 |
switch (s->cur_file_info.flag & 0x06) |
|
7ef7284…
|
drh
|
1394 |
{ |
|
7ef7284…
|
drh
|
1395 |
case 6 : *level = 1; break; |
|
7ef7284…
|
drh
|
1396 |
case 4 : *level = 2; break; |
|
7ef7284…
|
drh
|
1397 |
case 2 : *level = 9; break; |
|
7ef7284…
|
drh
|
1398 |
} |
|
7ef7284…
|
drh
|
1399 |
} |
|
7ef7284…
|
drh
|
1400 |
|
|
7ef7284…
|
drh
|
1401 |
if ((s->cur_file_info.compression_method!=0) && |
|
7ef7284…
|
drh
|
1402 |
/* #ifdef HAVE_BZIP2 */ |
|
7ef7284…
|
drh
|
1403 |
(s->cur_file_info.compression_method!=Z_BZIP2ED) && |
|
7ef7284…
|
drh
|
1404 |
/* #endif */ |
|
7ef7284…
|
drh
|
1405 |
(s->cur_file_info.compression_method!=Z_DEFLATED)) |
|
7ef7284…
|
drh
|
1406 |
|
|
7ef7284…
|
drh
|
1407 |
err=UNZ_BADZIPFILE; |
|
7ef7284…
|
drh
|
1408 |
|
|
7ef7284…
|
drh
|
1409 |
pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; |
|
7ef7284…
|
drh
|
1410 |
pfile_in_zip_read_info->crc32=0; |
|
7ef7284…
|
drh
|
1411 |
pfile_in_zip_read_info->total_out_64=0; |
|
7ef7284…
|
drh
|
1412 |
pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; |
|
7ef7284…
|
drh
|
1413 |
pfile_in_zip_read_info->filestream=s->filestream; |
|
7ef7284…
|
drh
|
1414 |
pfile_in_zip_read_info->z_filefunc=s->z_filefunc; |
|
7ef7284…
|
drh
|
1415 |
pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; |
|
7ef7284…
|
drh
|
1416 |
|
|
7ef7284…
|
drh
|
1417 |
pfile_in_zip_read_info->stream.total_out = 0; |
|
7ef7284…
|
drh
|
1418 |
|
|
7ef7284…
|
drh
|
1419 |
if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) |
|
7ef7284…
|
drh
|
1420 |
{ |
|
7ef7284…
|
drh
|
1421 |
#ifdef HAVE_BZIP2 |
|
7ef7284…
|
drh
|
1422 |
pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; |
|
7ef7284…
|
drh
|
1423 |
pfile_in_zip_read_info->bstream.bzfree = (free_func)0; |
|
7ef7284…
|
drh
|
1424 |
pfile_in_zip_read_info->bstream.opaque = (voidpf)0; |
|
7ef7284…
|
drh
|
1425 |
pfile_in_zip_read_info->bstream.state = (voidpf)0; |
|
7ef7284…
|
drh
|
1426 |
|
|
7ef7284…
|
drh
|
1427 |
pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; |
|
7ef7284…
|
drh
|
1428 |
pfile_in_zip_read_info->stream.zfree = (free_func)0; |
|
7ef7284…
|
drh
|
1429 |
pfile_in_zip_read_info->stream.opaque = (voidpf)0; |
|
7ef7284…
|
drh
|
1430 |
pfile_in_zip_read_info->stream.next_in = (voidpf)0; |
|
7ef7284…
|
drh
|
1431 |
pfile_in_zip_read_info->stream.avail_in = 0; |
|
7ef7284…
|
drh
|
1432 |
|
|
7ef7284…
|
drh
|
1433 |
err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); |
|
7ef7284…
|
drh
|
1434 |
if (err == Z_OK) |
|
7ef7284…
|
drh
|
1435 |
pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; |
|
7ef7284…
|
drh
|
1436 |
else |
|
7ef7284…
|
drh
|
1437 |
{ |
|
f1f1d6c…
|
drh
|
1438 |
free(pfile_in_zip_read_info->read_buffer); |
|
f1f1d6c…
|
drh
|
1439 |
free(pfile_in_zip_read_info); |
|
7ef7284…
|
drh
|
1440 |
return err; |
|
7ef7284…
|
drh
|
1441 |
} |
|
7ef7284…
|
drh
|
1442 |
#else |
|
7ef7284…
|
drh
|
1443 |
pfile_in_zip_read_info->raw=1; |
|
7ef7284…
|
drh
|
1444 |
#endif |
|
7ef7284…
|
drh
|
1445 |
} |
|
7ef7284…
|
drh
|
1446 |
else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) |
|
7ef7284…
|
drh
|
1447 |
{ |
|
7ef7284…
|
drh
|
1448 |
pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; |
|
7ef7284…
|
drh
|
1449 |
pfile_in_zip_read_info->stream.zfree = (free_func)0; |
|
7ef7284…
|
drh
|
1450 |
pfile_in_zip_read_info->stream.opaque = (voidpf)0; |
|
7ef7284…
|
drh
|
1451 |
pfile_in_zip_read_info->stream.next_in = 0; |
|
7ef7284…
|
drh
|
1452 |
pfile_in_zip_read_info->stream.avail_in = 0; |
|
7ef7284…
|
drh
|
1453 |
|
|
7ef7284…
|
drh
|
1454 |
err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); |
|
7ef7284…
|
drh
|
1455 |
if (err == Z_OK) |
|
7ef7284…
|
drh
|
1456 |
pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; |
|
7ef7284…
|
drh
|
1457 |
else |
|
7ef7284…
|
drh
|
1458 |
{ |
|
f1f1d6c…
|
drh
|
1459 |
free(pfile_in_zip_read_info->read_buffer); |
|
f1f1d6c…
|
drh
|
1460 |
free(pfile_in_zip_read_info); |
|
7ef7284…
|
drh
|
1461 |
return err; |
|
7ef7284…
|
drh
|
1462 |
} |
|
7ef7284…
|
drh
|
1463 |
/* windowBits is passed < 0 to tell that there is no zlib header. |
|
7ef7284…
|
drh
|
1464 |
* Note that in this case inflate *requires* an extra "dummy" byte |
|
7ef7284…
|
drh
|
1465 |
* after the compressed stream in order to complete decompression and |
|
7ef7284…
|
drh
|
1466 |
* return Z_STREAM_END. |
|
7ef7284…
|
drh
|
1467 |
* In unzip, i don't wait absolutely Z_STREAM_END because I known the |
|
7ef7284…
|
drh
|
1468 |
* size of both compressed and uncompressed data |
|
7ef7284…
|
drh
|
1469 |
*/ |
|
7ef7284…
|
drh
|
1470 |
} |
|
7ef7284…
|
drh
|
1471 |
pfile_in_zip_read_info->rest_read_compressed = |
|
7ef7284…
|
drh
|
1472 |
s->cur_file_info.compressed_size ; |
|
7ef7284…
|
drh
|
1473 |
pfile_in_zip_read_info->rest_read_uncompressed = |
|
7ef7284…
|
drh
|
1474 |
s->cur_file_info.uncompressed_size ; |
|
7ef7284…
|
drh
|
1475 |
|
|
7ef7284…
|
drh
|
1476 |
|
|
7ef7284…
|
drh
|
1477 |
pfile_in_zip_read_info->pos_in_zipfile = |
|
7ef7284…
|
drh
|
1478 |
s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + |
|
7ef7284…
|
drh
|
1479 |
iSizeVar; |
|
7ef7284…
|
drh
|
1480 |
|
|
7ef7284…
|
drh
|
1481 |
pfile_in_zip_read_info->stream.avail_in = (uInt)0; |
|
7ef7284…
|
drh
|
1482 |
|
|
7ef7284…
|
drh
|
1483 |
s->pfile_in_zip_read = pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1484 |
s->encrypted = 0; |
|
7ef7284…
|
drh
|
1485 |
|
|
7ef7284…
|
drh
|
1486 |
# ifndef NOUNCRYPT |
|
7ef7284…
|
drh
|
1487 |
if (password != NULL) |
|
7ef7284…
|
drh
|
1488 |
{ |
|
7ef7284…
|
drh
|
1489 |
int i; |
|
7ef7284…
|
drh
|
1490 |
s->pcrc_32_tab = get_crc_table(); |
|
7ef7284…
|
drh
|
1491 |
init_keys(password,s->keys,s->pcrc_32_tab); |
|
7ef7284…
|
drh
|
1492 |
if (ZSEEK64(s->z_filefunc, s->filestream, |
|
7ef7284…
|
drh
|
1493 |
s->pfile_in_zip_read->pos_in_zipfile + |
|
7ef7284…
|
drh
|
1494 |
s->pfile_in_zip_read->byte_before_the_zipfile, |
|
7ef7284…
|
drh
|
1495 |
SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
1496 |
return UNZ_INTERNALERROR; |
|
7ef7284…
|
drh
|
1497 |
if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) |
|
7ef7284…
|
drh
|
1498 |
return UNZ_INTERNALERROR; |
|
7ef7284…
|
drh
|
1499 |
|
|
7ef7284…
|
drh
|
1500 |
for (i = 0; i<12; i++) |
|
7ef7284…
|
drh
|
1501 |
zdecode(s->keys,s->pcrc_32_tab,source[i]); |
|
7ef7284…
|
drh
|
1502 |
|
|
7ef7284…
|
drh
|
1503 |
s->pfile_in_zip_read->pos_in_zipfile+=12; |
|
7ef7284…
|
drh
|
1504 |
s->encrypted=1; |
|
7ef7284…
|
drh
|
1505 |
} |
|
7ef7284…
|
drh
|
1506 |
# endif |
|
7ef7284…
|
drh
|
1507 |
|
|
7ef7284…
|
drh
|
1508 |
|
|
7ef7284…
|
drh
|
1509 |
return UNZ_OK; |
|
7ef7284…
|
drh
|
1510 |
} |
|
7ef7284…
|
drh
|
1511 |
|
|
f1f1d6c…
|
drh
|
1512 |
extern int ZEXPORT unzOpenCurrentFile(unzFile file) { |
|
7ef7284…
|
drh
|
1513 |
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); |
|
7ef7284…
|
drh
|
1514 |
} |
|
7ef7284…
|
drh
|
1515 |
|
|
f1f1d6c…
|
drh
|
1516 |
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char* password) { |
|
7ef7284…
|
drh
|
1517 |
return unzOpenCurrentFile3(file, NULL, NULL, 0, password); |
|
7ef7284…
|
drh
|
1518 |
} |
|
7ef7284…
|
drh
|
1519 |
|
|
f1f1d6c…
|
drh
|
1520 |
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int* method, int* level, int raw) { |
|
7ef7284…
|
drh
|
1521 |
return unzOpenCurrentFile3(file, method, level, raw, NULL); |
|
7ef7284…
|
drh
|
1522 |
} |
|
7ef7284…
|
drh
|
1523 |
|
|
7ef7284…
|
drh
|
1524 |
/** Addition for GDAL : START */ |
|
7ef7284…
|
drh
|
1525 |
|
|
f1f1d6c…
|
drh
|
1526 |
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file) { |
|
7ef7284…
|
drh
|
1527 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1528 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1529 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1530 |
if (file==NULL) |
|
6ea30fb…
|
florian
|
1531 |
return 0; /* UNZ_PARAMERROR; */ |
|
7ef7284…
|
drh
|
1532 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1533 |
if (pfile_in_zip_read_info==NULL) |
|
6ea30fb…
|
florian
|
1534 |
return 0; /* UNZ_PARAMERROR; */ |
|
7ef7284…
|
drh
|
1535 |
return pfile_in_zip_read_info->pos_in_zipfile + |
|
7ef7284…
|
drh
|
1536 |
pfile_in_zip_read_info->byte_before_the_zipfile; |
|
7ef7284…
|
drh
|
1537 |
} |
|
7ef7284…
|
drh
|
1538 |
|
|
7ef7284…
|
drh
|
1539 |
/** Addition for GDAL : END */ |
|
7ef7284…
|
drh
|
1540 |
|
|
7ef7284…
|
drh
|
1541 |
/* |
|
7ef7284…
|
drh
|
1542 |
Read bytes from the current file. |
|
7ef7284…
|
drh
|
1543 |
buf contain buffer where data must be copied |
|
7ef7284…
|
drh
|
1544 |
len the size of buf. |
|
7ef7284…
|
drh
|
1545 |
|
|
f1f1d6c…
|
drh
|
1546 |
return the number of byte copied if some bytes are copied |
|
7ef7284…
|
drh
|
1547 |
return 0 if the end of file was reached |
|
7ef7284…
|
drh
|
1548 |
return <0 with error code if there is an error |
|
7ef7284…
|
drh
|
1549 |
(UNZ_ERRNO for IO error, or zLib error for uncompress error) |
|
7ef7284…
|
drh
|
1550 |
*/ |
|
f1f1d6c…
|
drh
|
1551 |
extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { |
|
7ef7284…
|
drh
|
1552 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
1553 |
uInt iRead = 0; |
|
7ef7284…
|
drh
|
1554 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1555 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1556 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1557 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1558 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1559 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1560 |
|
|
7ef7284…
|
drh
|
1561 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1562 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1563 |
|
|
7ef7284…
|
drh
|
1564 |
|
|
7ef7284…
|
drh
|
1565 |
if (pfile_in_zip_read_info->read_buffer == NULL) |
|
7ef7284…
|
drh
|
1566 |
return UNZ_END_OF_LIST_OF_FILE; |
|
7ef7284…
|
drh
|
1567 |
if (len==0) |
|
7ef7284…
|
drh
|
1568 |
return 0; |
|
7ef7284…
|
drh
|
1569 |
|
|
7ef7284…
|
drh
|
1570 |
pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; |
|
7ef7284…
|
drh
|
1571 |
|
|
7ef7284…
|
drh
|
1572 |
pfile_in_zip_read_info->stream.avail_out = (uInt)len; |
|
7ef7284…
|
drh
|
1573 |
|
|
7ef7284…
|
drh
|
1574 |
if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && |
|
7ef7284…
|
drh
|
1575 |
(!(pfile_in_zip_read_info->raw))) |
|
7ef7284…
|
drh
|
1576 |
pfile_in_zip_read_info->stream.avail_out = |
|
7ef7284…
|
drh
|
1577 |
(uInt)pfile_in_zip_read_info->rest_read_uncompressed; |
|
7ef7284…
|
drh
|
1578 |
|
|
7ef7284…
|
drh
|
1579 |
if ((len>pfile_in_zip_read_info->rest_read_compressed+ |
|
7ef7284…
|
drh
|
1580 |
pfile_in_zip_read_info->stream.avail_in) && |
|
7ef7284…
|
drh
|
1581 |
(pfile_in_zip_read_info->raw)) |
|
7ef7284…
|
drh
|
1582 |
pfile_in_zip_read_info->stream.avail_out = |
|
7ef7284…
|
drh
|
1583 |
(uInt)pfile_in_zip_read_info->rest_read_compressed+ |
|
7ef7284…
|
drh
|
1584 |
pfile_in_zip_read_info->stream.avail_in; |
|
7ef7284…
|
drh
|
1585 |
|
|
7ef7284…
|
drh
|
1586 |
while (pfile_in_zip_read_info->stream.avail_out>0) |
|
7ef7284…
|
drh
|
1587 |
{ |
|
7ef7284…
|
drh
|
1588 |
if ((pfile_in_zip_read_info->stream.avail_in==0) && |
|
7ef7284…
|
drh
|
1589 |
(pfile_in_zip_read_info->rest_read_compressed>0)) |
|
7ef7284…
|
drh
|
1590 |
{ |
|
7ef7284…
|
drh
|
1591 |
uInt uReadThis = UNZ_BUFSIZE; |
|
7ef7284…
|
drh
|
1592 |
if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) |
|
7ef7284…
|
drh
|
1593 |
uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; |
|
7ef7284…
|
drh
|
1594 |
if (uReadThis == 0) |
|
7ef7284…
|
drh
|
1595 |
return UNZ_EOF; |
|
7ef7284…
|
drh
|
1596 |
if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, |
|
7ef7284…
|
drh
|
1597 |
pfile_in_zip_read_info->filestream, |
|
7ef7284…
|
drh
|
1598 |
pfile_in_zip_read_info->pos_in_zipfile + |
|
7ef7284…
|
drh
|
1599 |
pfile_in_zip_read_info->byte_before_the_zipfile, |
|
7ef7284…
|
drh
|
1600 |
ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
1601 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1602 |
if (ZREAD64(pfile_in_zip_read_info->z_filefunc, |
|
7ef7284…
|
drh
|
1603 |
pfile_in_zip_read_info->filestream, |
|
7ef7284…
|
drh
|
1604 |
pfile_in_zip_read_info->read_buffer, |
|
7ef7284…
|
drh
|
1605 |
uReadThis)!=uReadThis) |
|
7ef7284…
|
drh
|
1606 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1607 |
|
|
7ef7284…
|
drh
|
1608 |
|
|
7ef7284…
|
drh
|
1609 |
# ifndef NOUNCRYPT |
|
7ef7284…
|
drh
|
1610 |
if(s->encrypted) |
|
7ef7284…
|
drh
|
1611 |
{ |
|
7ef7284…
|
drh
|
1612 |
uInt i; |
|
7ef7284…
|
drh
|
1613 |
for(i=0;i<uReadThis;i++) |
|
7ef7284…
|
drh
|
1614 |
pfile_in_zip_read_info->read_buffer[i] = |
|
6ea30fb…
|
florian
|
1615 |
(char)zdecode(s->keys,s->pcrc_32_tab, |
|
7ef7284…
|
drh
|
1616 |
pfile_in_zip_read_info->read_buffer[i]); |
|
7ef7284…
|
drh
|
1617 |
} |
|
7ef7284…
|
drh
|
1618 |
# endif |
|
7ef7284…
|
drh
|
1619 |
|
|
7ef7284…
|
drh
|
1620 |
|
|
7ef7284…
|
drh
|
1621 |
pfile_in_zip_read_info->pos_in_zipfile += uReadThis; |
|
7ef7284…
|
drh
|
1622 |
|
|
7ef7284…
|
drh
|
1623 |
pfile_in_zip_read_info->rest_read_compressed-=uReadThis; |
|
7ef7284…
|
drh
|
1624 |
|
|
7ef7284…
|
drh
|
1625 |
pfile_in_zip_read_info->stream.next_in = |
|
7ef7284…
|
drh
|
1626 |
(Bytef*)pfile_in_zip_read_info->read_buffer; |
|
7ef7284…
|
drh
|
1627 |
pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; |
|
7ef7284…
|
drh
|
1628 |
} |
|
7ef7284…
|
drh
|
1629 |
|
|
7ef7284…
|
drh
|
1630 |
if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) |
|
7ef7284…
|
drh
|
1631 |
{ |
|
7ef7284…
|
drh
|
1632 |
uInt uDoCopy,i ; |
|
7ef7284…
|
drh
|
1633 |
|
|
7ef7284…
|
drh
|
1634 |
if ((pfile_in_zip_read_info->stream.avail_in == 0) && |
|
7ef7284…
|
drh
|
1635 |
(pfile_in_zip_read_info->rest_read_compressed == 0)) |
|
adb9e8e…
|
drh
|
1636 |
return (iRead==0) ? UNZ_EOF : (int)iRead; |
|
7ef7284…
|
drh
|
1637 |
|
|
7ef7284…
|
drh
|
1638 |
if (pfile_in_zip_read_info->stream.avail_out < |
|
7ef7284…
|
drh
|
1639 |
pfile_in_zip_read_info->stream.avail_in) |
|
7ef7284…
|
drh
|
1640 |
uDoCopy = pfile_in_zip_read_info->stream.avail_out ; |
|
7ef7284…
|
drh
|
1641 |
else |
|
7ef7284…
|
drh
|
1642 |
uDoCopy = pfile_in_zip_read_info->stream.avail_in ; |
|
7ef7284…
|
drh
|
1643 |
|
|
7ef7284…
|
drh
|
1644 |
for (i=0;i<uDoCopy;i++) |
|
7ef7284…
|
drh
|
1645 |
*(pfile_in_zip_read_info->stream.next_out+i) = |
|
7ef7284…
|
drh
|
1646 |
*(pfile_in_zip_read_info->stream.next_in+i); |
|
7ef7284…
|
drh
|
1647 |
|
|
7ef7284…
|
drh
|
1648 |
pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; |
|
7ef7284…
|
drh
|
1649 |
|
|
7ef7284…
|
drh
|
1650 |
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, |
|
7ef7284…
|
drh
|
1651 |
pfile_in_zip_read_info->stream.next_out, |
|
7ef7284…
|
drh
|
1652 |
uDoCopy); |
|
7ef7284…
|
drh
|
1653 |
pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; |
|
7ef7284…
|
drh
|
1654 |
pfile_in_zip_read_info->stream.avail_in -= uDoCopy; |
|
7ef7284…
|
drh
|
1655 |
pfile_in_zip_read_info->stream.avail_out -= uDoCopy; |
|
7ef7284…
|
drh
|
1656 |
pfile_in_zip_read_info->stream.next_out += uDoCopy; |
|
7ef7284…
|
drh
|
1657 |
pfile_in_zip_read_info->stream.next_in += uDoCopy; |
|
7ef7284…
|
drh
|
1658 |
pfile_in_zip_read_info->stream.total_out += uDoCopy; |
|
7ef7284…
|
drh
|
1659 |
iRead += uDoCopy; |
|
7ef7284…
|
drh
|
1660 |
} |
|
7ef7284…
|
drh
|
1661 |
else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) |
|
7ef7284…
|
drh
|
1662 |
{ |
|
7ef7284…
|
drh
|
1663 |
#ifdef HAVE_BZIP2 |
|
7ef7284…
|
drh
|
1664 |
uLong uTotalOutBefore,uTotalOutAfter; |
|
7ef7284…
|
drh
|
1665 |
const Bytef *bufBefore; |
|
7ef7284…
|
drh
|
1666 |
uLong uOutThis; |
|
7ef7284…
|
drh
|
1667 |
|
|
7ef7284…
|
drh
|
1668 |
pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; |
|
7ef7284…
|
drh
|
1669 |
pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; |
|
7ef7284…
|
drh
|
1670 |
pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; |
|
7ef7284…
|
drh
|
1671 |
pfile_in_zip_read_info->bstream.total_in_hi32 = 0; |
|
7ef7284…
|
drh
|
1672 |
pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; |
|
7ef7284…
|
drh
|
1673 |
pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; |
|
7ef7284…
|
drh
|
1674 |
pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; |
|
7ef7284…
|
drh
|
1675 |
pfile_in_zip_read_info->bstream.total_out_hi32 = 0; |
|
7ef7284…
|
drh
|
1676 |
|
|
7ef7284…
|
drh
|
1677 |
uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; |
|
7ef7284…
|
drh
|
1678 |
bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; |
|
7ef7284…
|
drh
|
1679 |
|
|
7ef7284…
|
drh
|
1680 |
err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); |
|
7ef7284…
|
drh
|
1681 |
|
|
7ef7284…
|
drh
|
1682 |
uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; |
|
7ef7284…
|
drh
|
1683 |
uOutThis = uTotalOutAfter-uTotalOutBefore; |
|
7ef7284…
|
drh
|
1684 |
|
|
7ef7284…
|
drh
|
1685 |
pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; |
|
7ef7284…
|
drh
|
1686 |
|
|
7ef7284…
|
drh
|
1687 |
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); |
|
7ef7284…
|
drh
|
1688 |
pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; |
|
7ef7284…
|
drh
|
1689 |
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); |
|
7ef7284…
|
drh
|
1690 |
|
|
7ef7284…
|
drh
|
1691 |
pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; |
|
7ef7284…
|
drh
|
1692 |
pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; |
|
7ef7284…
|
drh
|
1693 |
pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; |
|
7ef7284…
|
drh
|
1694 |
pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; |
|
7ef7284…
|
drh
|
1695 |
pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; |
|
7ef7284…
|
drh
|
1696 |
pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; |
|
7ef7284…
|
drh
|
1697 |
|
|
7ef7284…
|
drh
|
1698 |
if (err==BZ_STREAM_END) |
|
7ef7284…
|
drh
|
1699 |
return (iRead==0) ? UNZ_EOF : iRead; |
|
7ef7284…
|
drh
|
1700 |
if (err!=BZ_OK) |
|
7ef7284…
|
drh
|
1701 |
break; |
|
7ef7284…
|
drh
|
1702 |
#endif |
|
6ea30fb…
|
florian
|
1703 |
} /* end Z_BZIP2ED */ |
|
7ef7284…
|
drh
|
1704 |
else |
|
7ef7284…
|
drh
|
1705 |
{ |
|
7ef7284…
|
drh
|
1706 |
ZPOS64_T uTotalOutBefore,uTotalOutAfter; |
|
7ef7284…
|
drh
|
1707 |
const Bytef *bufBefore; |
|
7ef7284…
|
drh
|
1708 |
ZPOS64_T uOutThis; |
|
7ef7284…
|
drh
|
1709 |
int flush=Z_SYNC_FLUSH; |
|
7ef7284…
|
drh
|
1710 |
|
|
7ef7284…
|
drh
|
1711 |
uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; |
|
7ef7284…
|
drh
|
1712 |
bufBefore = pfile_in_zip_read_info->stream.next_out; |
|
7ef7284…
|
drh
|
1713 |
|
|
7ef7284…
|
drh
|
1714 |
/* |
|
7ef7284…
|
drh
|
1715 |
if ((pfile_in_zip_read_info->rest_read_uncompressed == |
|
7ef7284…
|
drh
|
1716 |
pfile_in_zip_read_info->stream.avail_out) && |
|
7ef7284…
|
drh
|
1717 |
(pfile_in_zip_read_info->rest_read_compressed == 0)) |
|
7ef7284…
|
drh
|
1718 |
flush = Z_FINISH; |
|
7ef7284…
|
drh
|
1719 |
*/ |
|
7ef7284…
|
drh
|
1720 |
err=inflate(&pfile_in_zip_read_info->stream,flush); |
|
7ef7284…
|
drh
|
1721 |
|
|
7ef7284…
|
drh
|
1722 |
if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) |
|
7ef7284…
|
drh
|
1723 |
err = Z_DATA_ERROR; |
|
7ef7284…
|
drh
|
1724 |
|
|
7ef7284…
|
drh
|
1725 |
uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; |
|
adb9e8e…
|
drh
|
1726 |
/* Detect overflow, because z_stream.total_out is uLong (32 bits) */ |
|
adb9e8e…
|
drh
|
1727 |
if (uTotalOutAfter<uTotalOutBefore) |
|
adb9e8e…
|
drh
|
1728 |
uTotalOutAfter += 1LL << 32; /* Add maximum value of uLong + 1 */ |
|
7ef7284…
|
drh
|
1729 |
uOutThis = uTotalOutAfter-uTotalOutBefore; |
|
7ef7284…
|
drh
|
1730 |
|
|
7ef7284…
|
drh
|
1731 |
pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; |
|
7ef7284…
|
drh
|
1732 |
|
|
7ef7284…
|
drh
|
1733 |
pfile_in_zip_read_info->crc32 = |
|
7ef7284…
|
drh
|
1734 |
crc32(pfile_in_zip_read_info->crc32,bufBefore, |
|
7ef7284…
|
drh
|
1735 |
(uInt)(uOutThis)); |
|
7ef7284…
|
drh
|
1736 |
|
|
7ef7284…
|
drh
|
1737 |
pfile_in_zip_read_info->rest_read_uncompressed -= |
|
7ef7284…
|
drh
|
1738 |
uOutThis; |
|
7ef7284…
|
drh
|
1739 |
|
|
7ef7284…
|
drh
|
1740 |
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); |
|
7ef7284…
|
drh
|
1741 |
|
|
7ef7284…
|
drh
|
1742 |
if (err==Z_STREAM_END) |
|
adb9e8e…
|
drh
|
1743 |
return (iRead==0) ? UNZ_EOF : (int)iRead; |
|
7ef7284…
|
drh
|
1744 |
if (err!=Z_OK) |
|
7ef7284…
|
drh
|
1745 |
break; |
|
7ef7284…
|
drh
|
1746 |
} |
|
7ef7284…
|
drh
|
1747 |
} |
|
7ef7284…
|
drh
|
1748 |
|
|
7ef7284…
|
drh
|
1749 |
if (err==Z_OK) |
|
adb9e8e…
|
drh
|
1750 |
return (int)iRead; |
|
7ef7284…
|
drh
|
1751 |
return err; |
|
7ef7284…
|
drh
|
1752 |
} |
|
7ef7284…
|
drh
|
1753 |
|
|
7ef7284…
|
drh
|
1754 |
|
|
7ef7284…
|
drh
|
1755 |
/* |
|
7ef7284…
|
drh
|
1756 |
Give the current position in uncompressed data |
|
7ef7284…
|
drh
|
1757 |
*/ |
|
f1f1d6c…
|
drh
|
1758 |
extern z_off_t ZEXPORT unztell(unzFile file) { |
|
7ef7284…
|
drh
|
1759 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1760 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1761 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1762 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1763 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1764 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1765 |
|
|
7ef7284…
|
drh
|
1766 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1767 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1768 |
|
|
7ef7284…
|
drh
|
1769 |
return (z_off_t)pfile_in_zip_read_info->stream.total_out; |
|
7ef7284…
|
drh
|
1770 |
} |
|
7ef7284…
|
drh
|
1771 |
|
|
f1f1d6c…
|
drh
|
1772 |
extern ZPOS64_T ZEXPORT unztell64(unzFile file) { |
|
7ef7284…
|
drh
|
1773 |
|
|
7ef7284…
|
drh
|
1774 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1775 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1776 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1777 |
return (ZPOS64_T)-1; |
|
7ef7284…
|
drh
|
1778 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1779 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1780 |
|
|
7ef7284…
|
drh
|
1781 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1782 |
return (ZPOS64_T)-1; |
|
7ef7284…
|
drh
|
1783 |
|
|
7ef7284…
|
drh
|
1784 |
return pfile_in_zip_read_info->total_out_64; |
|
7ef7284…
|
drh
|
1785 |
} |
|
7ef7284…
|
drh
|
1786 |
|
|
7ef7284…
|
drh
|
1787 |
|
|
7ef7284…
|
drh
|
1788 |
/* |
|
7ef7284…
|
drh
|
1789 |
return 1 if the end of file was reached, 0 elsewhere |
|
7ef7284…
|
drh
|
1790 |
*/ |
|
f1f1d6c…
|
drh
|
1791 |
extern int ZEXPORT unzeof(unzFile file) { |
|
7ef7284…
|
drh
|
1792 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1793 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1794 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1795 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1796 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1797 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1798 |
|
|
7ef7284…
|
drh
|
1799 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1800 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1801 |
|
|
7ef7284…
|
drh
|
1802 |
if (pfile_in_zip_read_info->rest_read_uncompressed == 0) |
|
7ef7284…
|
drh
|
1803 |
return 1; |
|
7ef7284…
|
drh
|
1804 |
else |
|
7ef7284…
|
drh
|
1805 |
return 0; |
|
7ef7284…
|
drh
|
1806 |
} |
|
7ef7284…
|
drh
|
1807 |
|
|
7ef7284…
|
drh
|
1808 |
|
|
7ef7284…
|
drh
|
1809 |
|
|
7ef7284…
|
drh
|
1810 |
/* |
|
7ef7284…
|
drh
|
1811 |
Read extra field from the current file (opened by unzOpenCurrentFile) |
|
7ef7284…
|
drh
|
1812 |
This is the local-header version of the extra field (sometimes, there is |
|
7ef7284…
|
drh
|
1813 |
more info in the local-header version than in the central-header) |
|
7ef7284…
|
drh
|
1814 |
|
|
7ef7284…
|
drh
|
1815 |
if buf==NULL, it return the size of the local extra field that can be read |
|
7ef7284…
|
drh
|
1816 |
|
|
7ef7284…
|
drh
|
1817 |
if buf!=NULL, len is the size of the buffer, the extra header is copied in |
|
7ef7284…
|
drh
|
1818 |
buf. |
|
7ef7284…
|
drh
|
1819 |
the return value is the number of bytes copied in buf, or (if <0) |
|
7ef7284…
|
drh
|
1820 |
the error code |
|
7ef7284…
|
drh
|
1821 |
*/ |
|
f1f1d6c…
|
drh
|
1822 |
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) { |
|
7ef7284…
|
drh
|
1823 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1824 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1825 |
uInt read_now; |
|
7ef7284…
|
drh
|
1826 |
ZPOS64_T size_to_read; |
|
7ef7284…
|
drh
|
1827 |
|
|
7ef7284…
|
drh
|
1828 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1829 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1830 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1831 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1832 |
|
|
7ef7284…
|
drh
|
1833 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1834 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1835 |
|
|
7ef7284…
|
drh
|
1836 |
size_to_read = (pfile_in_zip_read_info->size_local_extrafield - |
|
7ef7284…
|
drh
|
1837 |
pfile_in_zip_read_info->pos_local_extrafield); |
|
7ef7284…
|
drh
|
1838 |
|
|
7ef7284…
|
drh
|
1839 |
if (buf==NULL) |
|
7ef7284…
|
drh
|
1840 |
return (int)size_to_read; |
|
7ef7284…
|
drh
|
1841 |
|
|
7ef7284…
|
drh
|
1842 |
if (len>size_to_read) |
|
7ef7284…
|
drh
|
1843 |
read_now = (uInt)size_to_read; |
|
7ef7284…
|
drh
|
1844 |
else |
|
7ef7284…
|
drh
|
1845 |
read_now = (uInt)len ; |
|
7ef7284…
|
drh
|
1846 |
|
|
7ef7284…
|
drh
|
1847 |
if (read_now==0) |
|
7ef7284…
|
drh
|
1848 |
return 0; |
|
7ef7284…
|
drh
|
1849 |
|
|
7ef7284…
|
drh
|
1850 |
if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, |
|
7ef7284…
|
drh
|
1851 |
pfile_in_zip_read_info->filestream, |
|
7ef7284…
|
drh
|
1852 |
pfile_in_zip_read_info->offset_local_extrafield + |
|
7ef7284…
|
drh
|
1853 |
pfile_in_zip_read_info->pos_local_extrafield, |
|
7ef7284…
|
drh
|
1854 |
ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
1855 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1856 |
|
|
7ef7284…
|
drh
|
1857 |
if (ZREAD64(pfile_in_zip_read_info->z_filefunc, |
|
7ef7284…
|
drh
|
1858 |
pfile_in_zip_read_info->filestream, |
|
7ef7284…
|
drh
|
1859 |
buf,read_now)!=read_now) |
|
7ef7284…
|
drh
|
1860 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1861 |
|
|
7ef7284…
|
drh
|
1862 |
return (int)read_now; |
|
7ef7284…
|
drh
|
1863 |
} |
|
7ef7284…
|
drh
|
1864 |
|
|
7ef7284…
|
drh
|
1865 |
/* |
|
bb4776e…
|
jan.nijtmans
|
1866 |
Close the file in zip opened with unzOpenCurrentFile |
|
7ef7284…
|
drh
|
1867 |
Return UNZ_CRCERROR if all the file was read but the CRC is not good |
|
7ef7284…
|
drh
|
1868 |
*/ |
|
f1f1d6c…
|
drh
|
1869 |
extern int ZEXPORT unzCloseCurrentFile(unzFile file) { |
|
7ef7284…
|
drh
|
1870 |
int err=UNZ_OK; |
|
7ef7284…
|
drh
|
1871 |
|
|
7ef7284…
|
drh
|
1872 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1873 |
file_in_zip64_read_info_s* pfile_in_zip_read_info; |
|
7ef7284…
|
drh
|
1874 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1875 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1876 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1877 |
pfile_in_zip_read_info=s->pfile_in_zip_read; |
|
7ef7284…
|
drh
|
1878 |
|
|
7ef7284…
|
drh
|
1879 |
if (pfile_in_zip_read_info==NULL) |
|
7ef7284…
|
drh
|
1880 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1881 |
|
|
7ef7284…
|
drh
|
1882 |
|
|
7ef7284…
|
drh
|
1883 |
if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && |
|
7ef7284…
|
drh
|
1884 |
(!pfile_in_zip_read_info->raw)) |
|
7ef7284…
|
drh
|
1885 |
{ |
|
7ef7284…
|
drh
|
1886 |
if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) |
|
7ef7284…
|
drh
|
1887 |
err=UNZ_CRCERROR; |
|
7ef7284…
|
drh
|
1888 |
} |
|
7ef7284…
|
drh
|
1889 |
|
|
7ef7284…
|
drh
|
1890 |
|
|
f1f1d6c…
|
drh
|
1891 |
free(pfile_in_zip_read_info->read_buffer); |
|
7ef7284…
|
drh
|
1892 |
pfile_in_zip_read_info->read_buffer = NULL; |
|
7ef7284…
|
drh
|
1893 |
if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) |
|
7ef7284…
|
drh
|
1894 |
inflateEnd(&pfile_in_zip_read_info->stream); |
|
7ef7284…
|
drh
|
1895 |
#ifdef HAVE_BZIP2 |
|
7ef7284…
|
drh
|
1896 |
else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) |
|
7ef7284…
|
drh
|
1897 |
BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); |
|
7ef7284…
|
drh
|
1898 |
#endif |
|
7ef7284…
|
drh
|
1899 |
|
|
7ef7284…
|
drh
|
1900 |
|
|
7ef7284…
|
drh
|
1901 |
pfile_in_zip_read_info->stream_initialised = 0; |
|
f1f1d6c…
|
drh
|
1902 |
free(pfile_in_zip_read_info); |
|
7ef7284…
|
drh
|
1903 |
|
|
7ef7284…
|
drh
|
1904 |
s->pfile_in_zip_read=NULL; |
|
7ef7284…
|
drh
|
1905 |
|
|
7ef7284…
|
drh
|
1906 |
return err; |
|
7ef7284…
|
drh
|
1907 |
} |
|
7ef7284…
|
drh
|
1908 |
|
|
7ef7284…
|
drh
|
1909 |
|
|
7ef7284…
|
drh
|
1910 |
/* |
|
7ef7284…
|
drh
|
1911 |
Get the global comment string of the ZipFile, in the szComment buffer. |
|
7ef7284…
|
drh
|
1912 |
uSizeBuf is the size of the szComment buffer. |
|
7ef7284…
|
drh
|
1913 |
return the number of byte copied or an error code <0 |
|
7ef7284…
|
drh
|
1914 |
*/ |
|
f1f1d6c…
|
drh
|
1915 |
extern int ZEXPORT unzGetGlobalComment(unzFile file, char * szComment, uLong uSizeBuf) { |
|
7ef7284…
|
drh
|
1916 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1917 |
uLong uReadThis ; |
|
7ef7284…
|
drh
|
1918 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1919 |
return (int)UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1920 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1921 |
|
|
7ef7284…
|
drh
|
1922 |
uReadThis = uSizeBuf; |
|
7ef7284…
|
drh
|
1923 |
if (uReadThis>s->gi.size_comment) |
|
7ef7284…
|
drh
|
1924 |
uReadThis = s->gi.size_comment; |
|
7ef7284…
|
drh
|
1925 |
|
|
7ef7284…
|
drh
|
1926 |
if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) |
|
7ef7284…
|
drh
|
1927 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1928 |
|
|
7ef7284…
|
drh
|
1929 |
if (uReadThis>0) |
|
7ef7284…
|
drh
|
1930 |
{ |
|
7ef7284…
|
drh
|
1931 |
*szComment='\0'; |
|
7ef7284…
|
drh
|
1932 |
if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) |
|
7ef7284…
|
drh
|
1933 |
return UNZ_ERRNO; |
|
7ef7284…
|
drh
|
1934 |
} |
|
7ef7284…
|
drh
|
1935 |
|
|
7ef7284…
|
drh
|
1936 |
if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) |
|
7ef7284…
|
drh
|
1937 |
*(szComment+s->gi.size_comment)='\0'; |
|
7ef7284…
|
drh
|
1938 |
return (int)uReadThis; |
|
7ef7284…
|
drh
|
1939 |
} |
|
7ef7284…
|
drh
|
1940 |
|
|
7ef7284…
|
drh
|
1941 |
/* Additions by RX '2004 */ |
|
f1f1d6c…
|
drh
|
1942 |
extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) { |
|
7ef7284…
|
drh
|
1943 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1944 |
|
|
7ef7284…
|
drh
|
1945 |
if (file==NULL) |
|
6ea30fb…
|
florian
|
1946 |
return 0; /* UNZ_PARAMERROR; */ |
|
7ef7284…
|
drh
|
1947 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1948 |
if (!s->current_file_ok) |
|
7ef7284…
|
drh
|
1949 |
return 0; |
|
7ef7284…
|
drh
|
1950 |
if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) |
|
7ef7284…
|
drh
|
1951 |
if (s->num_file==s->gi.number_entry) |
|
7ef7284…
|
drh
|
1952 |
return 0; |
|
7ef7284…
|
drh
|
1953 |
return s->pos_in_central_dir; |
|
7ef7284…
|
drh
|
1954 |
} |
|
7ef7284…
|
drh
|
1955 |
|
|
f1f1d6c…
|
drh
|
1956 |
extern uLong ZEXPORT unzGetOffset(unzFile file) { |
|
7ef7284…
|
drh
|
1957 |
ZPOS64_T offset64; |
|
7ef7284…
|
drh
|
1958 |
|
|
7ef7284…
|
drh
|
1959 |
if (file==NULL) |
|
6ea30fb…
|
florian
|
1960 |
return 0; /* UNZ_PARAMERROR; */ |
|
7ef7284…
|
drh
|
1961 |
offset64 = unzGetOffset64(file); |
|
7ef7284…
|
drh
|
1962 |
return (uLong)offset64; |
|
7ef7284…
|
drh
|
1963 |
} |
|
7ef7284…
|
drh
|
1964 |
|
|
f1f1d6c…
|
drh
|
1965 |
extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) { |
|
7ef7284…
|
drh
|
1966 |
unz64_s* s; |
|
7ef7284…
|
drh
|
1967 |
int err; |
|
7ef7284…
|
drh
|
1968 |
|
|
7ef7284…
|
drh
|
1969 |
if (file==NULL) |
|
7ef7284…
|
drh
|
1970 |
return UNZ_PARAMERROR; |
|
7ef7284…
|
drh
|
1971 |
s=(unz64_s*)file; |
|
7ef7284…
|
drh
|
1972 |
|
|
7ef7284…
|
drh
|
1973 |
s->pos_in_central_dir = pos; |
|
7ef7284…
|
drh
|
1974 |
s->num_file = s->gi.number_entry; /* hack */ |
|
7ef7284…
|
drh
|
1975 |
err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
|
7ef7284…
|
drh
|
1976 |
&s->cur_file_info_internal, |
|
7ef7284…
|
drh
|
1977 |
NULL,0,NULL,0,NULL,0); |
|
7ef7284…
|
drh
|
1978 |
s->current_file_ok = (err == UNZ_OK); |
|
7ef7284…
|
drh
|
1979 |
return err; |
|
7ef7284…
|
drh
|
1980 |
} |
|
7ef7284…
|
drh
|
1981 |
|
|
f1f1d6c…
|
drh
|
1982 |
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) { |
|
7ef7284…
|
drh
|
1983 |
return unzSetOffset64(file,pos); |
|
7ef7284…
|
drh
|
1984 |
} |