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