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