summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:26:49 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:26:49 -0700
commitd004b047838a7e803818b4973a2e39e0ff8c1fa2 (patch)
tree9e8c804f78d73152c70d4ff24c6a7531a0d46782 /contrib
parentf6194ef39af5864f792412460c354cc339dde7d1 (diff)
downloadzlib-1.2.3.5.tar.gz
zlib-1.2.3.5.tar.bz2
zlib-1.2.3.5.zip
zlib 1.2.3.5v1.2.3.5
Diffstat (limited to '')
-rw-r--r--contrib/README.contrib1
-rw-r--r--contrib/delphi/zlibd32.mak16
-rw-r--r--contrib/infback9/inftree9.c4
-rw-r--r--contrib/minizip/ChangeLogUnzip67
-rw-r--r--contrib/minizip/Makefile50
-rw-r--r--contrib/minizip/MiniZip64_Changes.txt7
-rw-r--r--contrib/minizip/MiniZip64_info.txt79
-rw-r--r--contrib/minizip/crypt.h17
-rw-r--r--contrib/minizip/ioapi.c220
-rw-r--r--contrib/minizip/ioapi.h175
-rw-r--r--contrib/minizip/iowin32.c309
-rw-r--r--contrib/minizip/iowin32.h15
-rw-r--r--contrib/minizip/miniunz.c137
-rw-r--r--contrib/minizip/minizip.c134
-rw-r--r--contrib/minizip/mztools.c562
-rw-r--r--contrib/minizip/mztools.h62
-rw-r--r--contrib/minizip/unzip.c1283
-rw-r--r--contrib/minizip/unzip.h129
-rw-r--r--contrib/minizip/zconf.h332
-rw-r--r--contrib/minizip/zconf.in.h332
-rw-r--r--contrib/minizip/zip.c1830
-rw-r--r--contrib/minizip/zip.h175
-rw-r--r--contrib/pascal/zlibd32.mak16
-rw-r--r--contrib/vstudio/vc7/zlib.rc6
-rw-r--r--contrib/vstudio/vc7/zlibstat.vcproj12
-rw-r--r--contrib/vstudio/vc7/zlibvc.vcproj12
-rw-r--r--contrib/vstudio/vc8/zlibstat.vcproj15
-rw-r--r--contrib/vstudio/vc8/zlibvc.vcproj15
-rw-r--r--nintendods/Makefile (renamed from contrib/nintendods/Makefile)0
-rw-r--r--nintendods/README (renamed from contrib/nintendods/README)0
30 files changed, 4364 insertions, 1648 deletions
diff --git a/contrib/README.contrib b/contrib/README.contrib
index f9c1665..17fc8f6 100644
--- a/contrib/README.contrib
+++ b/contrib/README.contrib
@@ -56,6 +56,7 @@ masmx86/ by Gilles Vollant <info@winimage.com>
56 56
57minizip/ by Gilles Vollant <info@winimage.com> 57minizip/ by Gilles Vollant <info@winimage.com>
58 Mini zip and unzip based on zlib 58 Mini zip and unzip based on zlib
59 Includes Zip64 support by Mathias Svensson <mathias@result42.com>
59 See http://www.winimage.com/zLibDll/unzip.html 60 See http://www.winimage.com/zLibDll/unzip.html
60 61
61pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al. 62pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al.
diff --git a/contrib/delphi/zlibd32.mak b/contrib/delphi/zlibd32.mak
index 88fafa0..203a4c9 100644
--- a/contrib/delphi/zlibd32.mak
+++ b/contrib/delphi/zlibd32.mak
@@ -18,10 +18,10 @@ LDFLAGS =
18# variables 18# variables
19ZLIB_LIB = zlib.lib 19ZLIB_LIB = zlib.lib
20 20
21OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj 21OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
22OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 22OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
23OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj 23OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
24OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 24OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
25 25
26 26
27# targets 27# targets
@@ -38,8 +38,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
38 38
39deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 39deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
40 40
41gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
42
41gzio.obj: gzio.c zutil.h zlib.h zconf.h 43gzio.obj: gzio.c zutil.h zlib.h zconf.h
42 44
45gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
46
47gzread.obj: gzread.c zlib.h zconf.h gzguts.h
48
49gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
50
43infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 51infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
44 inffast.h inffixed.h 52 inffast.h inffixed.h
45 53
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c
index 18353cb..9b0f46c 100644
--- a/contrib/infback9/inftree9.c
+++ b/contrib/infback9/inftree9.c
@@ -9,7 +9,7 @@
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate9_copyright[] = 11const char inflate9_copyright[] =
12 " inflate9 1.2.3.4 Copyright 1995-2008 Mark Adler "; 12 " inflate9 1.2.3.5 Copyright 1995-2009 Mark Adler ";
13/* 13/*
14 If you use the zlib library in a product, an acknowledgment is welcome 14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot 15 in the documentation of your product. If for some reason you cannot
@@ -64,7 +64,7 @@ unsigned short FAR *work;
64 static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 64 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
65 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 65 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
66 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, 66 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
67 133, 133, 133, 133, 144, 72, 200}; 67 133, 133, 133, 133, 144, 69, 199};
68 static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ 68 static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
69 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 69 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
70 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 70 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip
deleted file mode 100644
index 50ca6a9..0000000
--- a/contrib/minizip/ChangeLogUnzip
+++ /dev/null
@@ -1,67 +0,0 @@
1Change in 1.01e (12 feb 05)
2- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
3- Fix possible memory leak in unzip.c (Zoran Stevanovic)
4
5Change in 1.01b (20 may 04)
6- Integrate patch from Debian package (submited by Mark Brown)
7- Add tools mztools from Xavier Roche
8
9Change in 1.01 (8 may 04)
10- fix buffer overrun risk in unzip.c (Xavier Roche)
11- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
12
13Change in 1.00: (10 sept 03)
14- rename to 1.00
15- cosmetic code change
16
17Change in 0.22: (19 May 03)
18- crypting support (unless you define NOCRYPT)
19- append file in existing zipfile
20
21Change in 0.21: (10 Mar 03)
22- bug fixes
23
24Change in 0.17: (27 Jan 02)
25- bug fixes
26
27Change in 0.16: (19 Jan 02)
28- Support of ioapi for virtualize zip file access
29
30Change in 0.15: (19 Mar 98)
31- fix memory leak in minizip.c
32
33Change in 0.14: (10 Mar 98)
34- fix bugs in minizip.c sample for zipping big file
35- fix problem in month in date handling
36- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
37 comment handling
38
39Change in 0.13: (6 Mar 98)
40- fix bugs in zip.c
41- add real minizip sample
42
43Change in 0.12: (4 Mar 98)
44- add zip.c and zip.h for creates .zip file
45- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
46- fix miniunz.c for file without specific record for directory
47
48Change in 0.11: (3 Mar 98)
49- fix bug in unzGetCurrentFileInfo for get extra field and comment
50- enhance miniunz sample, remove the bad unztst.c sample
51
52Change in 0.10: (2 Mar 98)
53- fix bug in unzReadCurrentFile
54- rename unzip* to unz* function and structure
55- remove Windows-like hungary notation variable name
56- modify some structure in unzip.h
57- add somes comment in source
58- remove unzipGetcCurrentFile function
59- replace ZUNZEXPORT by ZEXPORT
60- add unzGetLocalExtrafield for get the local extrafield info
61- add a new sample, miniunz.c
62
63Change in 0.4: (25 Feb 98)
64- suppress the type unzipFileInZip.
65 Only on file in the zipfile can be open at the same time
66- fix somes typo in code
67- added tm_unz structure in unzip_file_info (date/time in readable format)
diff --git a/contrib/minizip/Makefile b/contrib/minizip/Makefile
index 84eaad2..fbba3ac 100644
--- a/contrib/minizip/Makefile
+++ b/contrib/minizip/Makefile
@@ -1,25 +1,25 @@
1CC=cc 1CC=cc
2CFLAGS=-O -I../.. 2CFLAGS=-O -I../..
3 3
4UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a 4UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
5ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a 5ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
6 6
7.c.o: 7.c.o:
8 $(CC) -c $(CFLAGS) $*.c 8 $(CC) -c $(CFLAGS) $*.c
9 9
10all: miniunz minizip 10all: miniunz minizip
11 11
12miniunz: $(UNZ_OBJS) 12miniunz: $(UNZ_OBJS)
13 $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) 13 $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
14 14
15minizip: $(ZIP_OBJS) 15minizip: $(ZIP_OBJS)
16 $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) 16 $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
17 17
18test: miniunz minizip 18test: miniunz minizip
19 ./minizip test readme.txt 19 ./minizip test readme.txt
20 ./miniunz -l test.zip 20 ./miniunz -l test.zip
21 mv readme.txt readme.old 21 mv readme.txt readme.old
22 ./miniunz test.zip 22 ./miniunz test.zip
23 23
24clean: 24clean:
25 /bin/rm -f *.o *~ minizip miniunz 25 /bin/rm -f *.o *~ minizip miniunz
diff --git a/contrib/minizip/MiniZip64_Changes.txt b/contrib/minizip/MiniZip64_Changes.txt
new file mode 100644
index 0000000..9d370df
--- /dev/null
+++ b/contrib/minizip/MiniZip64_Changes.txt
@@ -0,0 +1,7 @@
1
2MiniZip64 was derrived from MiniZip at version 1.01f
3
4Change in 1.0 (Okt 2009)
5 - **TODO - Add history**
6
7 \ No newline at end of file
diff --git a/contrib/minizip/MiniZip64_info.txt b/contrib/minizip/MiniZip64_info.txt
new file mode 100644
index 0000000..f4eef25
--- /dev/null
+++ b/contrib/minizip/MiniZip64_info.txt
@@ -0,0 +1,79 @@
1MiniZip64 - Copyright (c) 2009-2010 - Mathias Svensson - Built from MiniZip by Gilles Vollant
2
3Introduction
4---------------------
5MiniZip64 is built from MiniZip by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html )
6
7When adding ZIP64 support into minizip it would result into breaking compatibility with current minizip.
8And since breaking compatibility in minizip is not wanted. I decided to create a fork of minizip
9and create minizip64.
10
11Even though MiniZip64 is build from MiniZip, all functions and struct's have changed name so that it
12would not collide with each other.
13
14
15Background
16---------------------
17When adding ZIP64 support I found that Even Rouault have added ZIP64 support for unzip.c into minizip
18for a open source project called gdal ( http://www.gdal.org/ )
19
20That was used as a starting point. And after that ZIP64 support was added to zip.c
21some refactoring and code cleanup was also done.
22
23
24Changed from MiniZip to MiniZip64
25-------------------------------------
26* Filenames has got a '64' at the end of them . eg unzip.c is now called unzip64.c
27* Added ZIP64 support for unzip ( by Even Rouault )
28* Added ZIP64 support for zip ( by Mathias Svensson )
29* Reverted some changed that Even Rouault did.
30* Bunch of patches received from Gulles Vollant that he received for MiniZip from various users.
31* Added unzip patch for BZIP Compression method (patch create by Daniel Borca)
32* Added BZIP Compress method for zip
33* Did some refactoring and code cleanup
34
35
36Credits
37
38 Gilles Vollant - Original MiniZip author
39 Even Rouault - ZIP64 unzip Support
40 Daniel Borca - BZip Compression method support in unzip
41 Mathias Svensson - ZIP64 zip support
42 Mathias Svensson - BZip Compression method support in zip
43
44 Resources
45
46 ZipLayout http://result42.com/projects/ZipFileLayout
47 Command line tool for Windows that shows the layout and information of the headers in a zip archive.
48 Used when debugging and validating the creation of zip files using MiniZip64
49
50
51 ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT
52 Zip File specification
53
54
55Notes.
56 * To be able to use BZip compression method in zip64.c or unzip64.c the BZIP2 lib is needed and HAVE_BZIP2 need to be defined.
57
58License
59----------------------------------------------------------
60 Condition of use and distribution are the same than zlib :
61
62 This software is provided 'as-is', without any express or implied
63 warranty. In no event will the authors be held liable for any damages
64 arising from the use of this software.
65
66 Permission is granted to anyone to use this software for any purpose,
67 including commercial applications, and to alter it and redistribute it
68 freely, subject to the following restrictions:
69
70 1. The origin of this software must not be misrepresented; you must not
71 claim that you wrote the original software. If you use this software
72 in a product, an acknowledgment in the product documentation would be
73 appreciated but is not required.
74 2. Altered source versions must be plainly marked as such, and must not be
75 misrepresented as being the original software.
76 3. This notice may not be removed or altered from any source distribution.
77
78----------------------------------------------------------
79
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h
index 622f4bc..679e2a1 100644
--- a/contrib/minizip/crypt.h
+++ b/contrib/minizip/crypt.h
@@ -87,13 +87,12 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned lon
87# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 87# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
88# endif 88# endif
89 89
90static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 90static int crypthead(const char* passwd, /* password string */
91 const char *passwd; /* password string */ 91 unsigned char* buf, /* where to write header */
92 unsigned char *buf; /* where to write header */ 92 int bufSize,
93 int bufSize; 93 unsigned long* pkeys,
94 unsigned long* pkeys; 94 const unsigned long* pcrc_32_tab,
95 const unsigned long* pcrc_32_tab; 95 unsigned long crcForCrypting)
96 unsigned long crcForCrypting;
97{ 96{
98 int n; /* index in random header */ 97 int n; /* index in random header */
99 int t; /* temporary */ 98 int t; /* temporary */
@@ -124,8 +123,8 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
124 { 123 {
125 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 124 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
126 } 125 }
127 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 126 buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
128 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 127 buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
129 return n; 128 return n;
130} 129}
131 130
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
index f1bee23..36ed0e0 100644
--- a/contrib/minizip/ioapi.c
+++ b/contrib/minizip/ioapi.c
@@ -1,74 +1,104 @@
1/* ioapi.c -- IO base function header for compress/uncompress .zip 1/* ioapi.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 3
4 Version 1.01e, February 12th, 2005 4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5
6 Copyright (C) 1998-2005 Gilles Vollant
7*/
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include "zlib.h"
14#include "ioapi.h"
15 5
6 Modifications for Zip64 support
7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
16 8
9 For more info read MiniZip_info.txt
17 10
18/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 11*/
19 12
20#ifndef SEEK_CUR 13#if (defined(_WIN32))
21#define SEEK_CUR 1 14 #define _CRT_SECURE_NO_WARNINGS
22#endif 15#endif
23 16
24#ifndef SEEK_END 17#include "ioapi.h"
25#define SEEK_END 2
26#endif
27 18
28#ifndef SEEK_SET 19voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
29#define SEEK_SET 0 20{
30#endif 21 if (pfilefunc->zfile_func64.zopen64_file != NULL)
22 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
23 else
24 {
25 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
26 }
27}
31 28
32voidpf ZCALLBACK fopen_file_func OF(( 29long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
33 voidpf opaque, 30{
34 const char* filename, 31 if (pfilefunc->zfile_func64.zseek64_file != NULL)
35 int mode)); 32 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
33 else
34 {
35 uLong offsetTruncated = (uLong)offset;
36 if (offsetTruncated != offset)
37 return -1;
38 else
39 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
40 }
41}
36 42
37uLong ZCALLBACK fread_file_func OF(( 43ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
38 voidpf opaque, 44{
39 voidpf stream, 45 if (pfilefunc->zfile_func64.zseek64_file != NULL)
40 void* buf, 46 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
41 uLong size)); 47 else
48 {
49 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
50 if ((tell_uLong) == ((uLong)-1))
51 return (ZPOS64_T)-1;
52 else
53 return tell_uLong;
54 }
55}
42 56
43uLong ZCALLBACK fwrite_file_func OF(( 57void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
44 voidpf opaque, 58{
45 voidpf stream, 59 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
46 const void* buf, 60 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
47 uLong size)); 61 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
62 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
63 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
64 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
65 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
66 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
67 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
68 p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
69 p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
70 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
71}
48 72
49long ZCALLBACK ftell_file_func OF((
50 voidpf opaque,
51 voidpf stream));
52 73
53long ZCALLBACK fseek_file_func OF((
54 voidpf opaque,
55 voidpf stream,
56 uLong offset,
57 int origin));
58 74
59int ZCALLBACK fclose_file_func OF(( 75static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
60 voidpf opaque, 76static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
61 voidpf stream)); 77static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
78static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
79static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
80static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
81static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
62 82
63int ZCALLBACK ferror_file_func OF(( 83static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
64 voidpf opaque, 84{
65 voidpf stream)); 85 FILE* file = NULL;
86 const char* mode_fopen = NULL;
87 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
88 mode_fopen = "rb";
89 else
90 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
91 mode_fopen = "r+b";
92 else
93 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
94 mode_fopen = "wb";
66 95
96 if ((filename!=NULL) && (mode_fopen != NULL))
97 file = fopen(filename, mode_fopen);
98 return file;
99}
67 100
68voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 101static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
69 voidpf opaque;
70 const char* filename;
71 int mode;
72{ 102{
73 FILE* file = NULL; 103 FILE* file = NULL;
74 const char* mode_fopen = NULL; 104 const char* mode_fopen = NULL;
@@ -82,48 +112,41 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
82 mode_fopen = "wb"; 112 mode_fopen = "wb";
83 113
84 if ((filename!=NULL) && (mode_fopen != NULL)) 114 if ((filename!=NULL) && (mode_fopen != NULL))
85 file = fopen(filename, mode_fopen); 115 file = fopen64((const char*)filename, mode_fopen);
86 return file; 116 return file;
87} 117}
88 118
89 119
90uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 120static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
91 voidpf opaque;
92 voidpf stream;
93 void* buf;
94 uLong size;
95{ 121{
96 uLong ret; 122 uLong ret;
97 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 123 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
98 return ret; 124 return ret;
99} 125}
100 126
101 127static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
102uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
103 voidpf opaque;
104 voidpf stream;
105 const void* buf;
106 uLong size;
107{ 128{
108 uLong ret; 129 uLong ret;
109 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 130 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
110 return ret; 131 return ret;
111} 132}
112 133
113long ZCALLBACK ftell_file_func (opaque, stream) 134static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
114 voidpf opaque;
115 voidpf stream;
116{ 135{
117 long ret; 136 long ret;
118 ret = ftell((FILE *)stream); 137 ret = ftell((FILE *)stream);
119 return ret; 138 return ret;
120} 139}
121 140
122long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 141
123 voidpf opaque; 142static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
124 voidpf stream; 143{
125 uLong offset; 144 ZPOS64_T ret;
126 int origin; 145 ret = ftello64((FILE *)stream);
146 return ret;
147}
148
149static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
127{ 150{
128 int fseek_origin=0; 151 int fseek_origin=0;
129 long ret; 152 long ret;
@@ -141,22 +164,45 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
141 default: return -1; 164 default: return -1;
142 } 165 }
143 ret = 0; 166 ret = 0;
144 fseek((FILE *)stream, offset, fseek_origin); 167 if (fseek((FILE *)stream, offset, fseek_origin) != 0)
168 ret = -1;
145 return ret; 169 return ret;
146} 170}
147 171
148int ZCALLBACK fclose_file_func (opaque, stream) 172static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
149 voidpf opaque; 173{
150 voidpf stream; 174 int fseek_origin=0;
175 long ret;
176 switch (origin)
177 {
178 case ZLIB_FILEFUNC_SEEK_CUR :
179 fseek_origin = SEEK_CUR;
180 break;
181 case ZLIB_FILEFUNC_SEEK_END :
182 fseek_origin = SEEK_END;
183 break;
184 case ZLIB_FILEFUNC_SEEK_SET :
185 fseek_origin = SEEK_SET;
186 break;
187 default: return -1;
188 }
189 ret = 0;
190
191 if(fseeko64((FILE *)stream, offset, fseek_origin) != 0)
192 ret = -1;
193
194 return ret;
195}
196
197
198static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
151{ 199{
152 int ret; 200 int ret;
153 ret = fclose((FILE *)stream); 201 ret = fclose((FILE *)stream);
154 return ret; 202 return ret;
155} 203}
156 204
157int ZCALLBACK ferror_file_func (opaque, stream) 205static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
158 voidpf opaque;
159 voidpf stream;
160{ 206{
161 int ret; 207 int ret;
162 ret = ferror((FILE *)stream); 208 ret = ferror((FILE *)stream);
@@ -175,3 +221,15 @@ void fill_fopen_filefunc (pzlib_filefunc_def)
175 pzlib_filefunc_def->zerror_file = ferror_file_func; 221 pzlib_filefunc_def->zerror_file = ferror_file_func;
176 pzlib_filefunc_def->opaque = NULL; 222 pzlib_filefunc_def->opaque = NULL;
177} 223}
224
225void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
226{
227 pzlib_filefunc_def->zopen64_file = fopen64_file_func;
228 pzlib_filefunc_def->zread_file = fread_file_func;
229 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
230 pzlib_filefunc_def->ztell64_file = ftell64_file_func;
231 pzlib_filefunc_def->zseek64_file = fseek64_file_func;
232 pzlib_filefunc_def->zclose_file = fclose_file_func;
233 pzlib_filefunc_def->zerror_file = ferror_file_func;
234 pzlib_filefunc_def->opaque = NULL;
235}
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h
index 7d457ba..f443d82 100644
--- a/contrib/minizip/ioapi.h
+++ b/contrib/minizip/ioapi.h
@@ -1,13 +1,98 @@
1/* ioapi.h -- IO base function header for compress/uncompress .zip 1/* ioapi.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 3
4 Version 1.01e, February 12th, 2005 4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5
6 Modifications for Zip64 support
7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
8
9 For more info read MiniZip_info.txt
10
11 Changes
12
13 Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
14 Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
15 More if/def section may be needed to support other platforms
16 Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
17 (but you should use iowin32.c for windows instead)
5 18
6 Copyright (C) 1998-2005 Gilles Vollant
7*/ 19*/
8 20
9#ifndef _ZLIBIOAPI_H 21#ifndef _ZLIBIOAPI64_H
10#define _ZLIBIOAPI_H 22#define _ZLIBIOAPI64_H
23
24#ifndef _WIN32
25
26 // Linux needs this to support file operation on files larger then 4+GB
27 // But might need better if/def to select just the platforms that needs them.
28
29 #ifndef __USE_FILE_OFFSET64
30 #define __USE_FILE_OFFSET64
31 #endif
32 #ifndef __USE_LARGEFILE64
33 #define __USE_LARGEFILE64
34 #endif
35 #ifndef _LARGEFILE64_SOURCE
36 #define _LARGEFILE64_SOURCE
37 #endif
38 #ifndef _FILE_OFFSET_BIT
39 #define _FILE_OFFSET_BIT 64
40 #endif
41#endif
42
43#include <stdio.h>
44#include <stdlib.h>
45#include "zlib.h"
46
47#ifdef _MSC_VER
48 #define fopen64 fopen
49 #if _MSC_VER >= 1400
50 #define ftello64 _ftelli64
51 #define fseeko64 _fseeki64
52 #else // old MSC
53 #define ftello64 ftell
54 #define fseeko64 fseek
55 #endif
56#endif
57
58/*
59#ifndef ZPOS64_T
60 #ifdef _WIN32
61 #define ZPOS64_T fpos_t
62 #else
63 #include <stdint.h>
64 #define ZPOS64_T uint64_t
65 #endif
66#endif
67*/
68
69#ifdef HAVE_MINIZIP64_CONF_H
70#include "mz64conf.h"
71#endif
72
73/* a type choosen by DEFINE */
74#ifdef HAVE_64BIT_INT_CUSTOM
75typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
76#else
77#ifdef HAS_STDINT_H
78#include "stdint.h"
79typedef uint64_t ZPOS64_T;
80#else
81
82
83#if defined(_MSC_VER) || defined(__BORLANDC__)
84typedef unsigned __int64 ZPOS64_T;
85#else
86typedef unsigned long long int ZPOS64_T;
87#endif
88#endif
89#endif
90
91
92
93#ifdef __cplusplus
94extern "C" {
95#endif
11 96
12 97
13#define ZLIB_FILEFUNC_SEEK_CUR (1) 98#define ZLIB_FILEFUNC_SEEK_CUR (1)
@@ -23,26 +108,27 @@
23 108
24 109
25#ifndef ZCALLBACK 110#ifndef ZCALLBACK
26 111 #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
27#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 112 #define ZCALLBACK CALLBACK
28#define ZCALLBACK CALLBACK 113 #else
29#else 114 #define ZCALLBACK
30#define ZCALLBACK 115 #endif
31#endif
32#endif 116#endif
33 117
34#ifdef __cplusplus
35extern "C" {
36#endif
37 118
38typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
39typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
40typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
41typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
42typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
43typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
44typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
45 119
120
121typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
122typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
123typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
124typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
125typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
126
127typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
128typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
129
130
131/* here is the "old" 32 bits structure structure */
46typedef struct zlib_filefunc_def_s 132typedef struct zlib_filefunc_def_s
47{ 133{
48 open_file_func zopen_file; 134 open_file_func zopen_file;
@@ -55,21 +141,54 @@ typedef struct zlib_filefunc_def_s
55 voidpf opaque; 141 voidpf opaque;
56} zlib_filefunc_def; 142} zlib_filefunc_def;
57 143
144typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
145typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
146typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
58 147
148typedef struct zlib_filefunc64_def_s
149{
150 open64_file_func zopen64_file;
151 read_file_func zread_file;
152 write_file_func zwrite_file;
153 tell64_file_func ztell64_file;
154 seek64_file_func zseek64_file;
155 close_file_func zclose_file;
156 testerror_file_func zerror_file;
157 voidpf opaque;
158} zlib_filefunc64_def;
59 159
160void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
60void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 161void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
61 162
62#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 163/* now internal definition, only for zip.c and unzip.h */
63#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 164typedef struct zlib_filefunc64_32_def_s
64#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 165{
65#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 166 zlib_filefunc64_def zfile_func64;
66#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 167 open_file_func zopen32_file;
67#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 168 tell_file_func ztell32_file;
169 seek_file_func zseek32_file;
170} zlib_filefunc64_32_def;
171
172
173#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
174#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
175//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
176//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
177#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
178#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
68 179
180voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
181long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
182ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
183
184void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
185
186#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
187#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
188#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
69 189
70#ifdef __cplusplus 190#ifdef __cplusplus
71} 191}
72#endif 192#endif
73 193
74#endif 194#endif
75
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
index a9b5f78..92b9352 100644
--- a/contrib/minizip/iowin32.c
+++ b/contrib/minizip/iowin32.c
@@ -1,10 +1,14 @@
1/* iowin32.c -- IO base function header for compress/uncompress .zip 1/* iowin32.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 Version 1.1, January 7th, 2010
3 This IO API version uses the Win32 API (for Microsoft Windows) 3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4 4
5 Version 1.01e, February 12th, 2005 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6
7 Modifications for Zip64 support
8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9
10 For more info read MiniZip_info.txt
6 11
7 Copyright (C) 1998-2005 Gilles Vollant
8*/ 12*/
9 13
10#include <stdlib.h> 14#include <stdlib.h>
@@ -21,40 +25,13 @@
21#define INVALID_SET_FILE_POINTER ((DWORD)-1) 25#define INVALID_SET_FILE_POINTER ((DWORD)-1)
22#endif 26#endif
23 27
24voidpf ZCALLBACK win32_open_file_func OF(( 28voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
25 voidpf opaque, 29uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
26 const char* filename, 30uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
27 int mode)); 31ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
28 32long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
29uLong ZCALLBACK win32_read_file_func OF(( 33int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
30 voidpf opaque, 34int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
31 voidpf stream,
32 void* buf,
33 uLong size));
34
35uLong ZCALLBACK win32_write_file_func OF((
36 voidpf opaque,
37 voidpf stream,
38 const void* buf,
39 uLong size));
40
41long ZCALLBACK win32_tell_file_func OF((
42 voidpf opaque,
43 voidpf stream));
44
45long ZCALLBACK win32_seek_file_func OF((
46 voidpf opaque,
47 voidpf stream,
48 uLong offset,
49 int origin));
50
51int ZCALLBACK win32_close_file_func OF((
52 voidpf opaque,
53 voidpf stream));
54
55int ZCALLBACK win32_error_file_func OF((
56 voidpf opaque,
57 voidpf stream));
58 35
59typedef struct 36typedef struct
60{ 37{
@@ -62,69 +39,121 @@ typedef struct
62 int error; 39 int error;
63} WIN32FILE_IOWIN; 40} WIN32FILE_IOWIN;
64 41
65voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
66 voidpf opaque;
67 const char* filename;
68 int mode;
69{
70 const char* mode_fopen = NULL;
71 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
72 HANDLE hFile = 0;
73 voidpf ret=NULL;
74 42
75 dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; 43static void win32_translate_open_mode(int mode,
44 DWORD* lpdwDesiredAccess,
45 DWORD* lpdwCreationDisposition,
46 DWORD* lpdwShareMode,
47 DWORD* lpdwFlagsAndAttributes)
48{
49 *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
76 50
77 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 51 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
78 { 52 {
79 dwDesiredAccess = GENERIC_READ; 53 *lpdwDesiredAccess = GENERIC_READ;
80 dwCreationDisposition = OPEN_EXISTING; 54 *lpdwCreationDisposition = OPEN_EXISTING;
81 dwShareMode = FILE_SHARE_READ; 55 *lpdwShareMode = FILE_SHARE_READ;
82 } 56 }
83 else 57 else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
84 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
85 { 58 {
86 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 59 *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
87 dwCreationDisposition = OPEN_EXISTING; 60 *lpdwCreationDisposition = OPEN_EXISTING;
88 } 61 }
89 else 62 else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
90 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
91 { 63 {
92 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 64 *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
93 dwCreationDisposition = CREATE_ALWAYS; 65 *lpdwCreationDisposition = CREATE_ALWAYS;
94 } 66 }
67}
95 68
96 if ((filename!=NULL) && (dwDesiredAccess != 0)) 69static voidpf win32_build_iowin(HANDLE hFile)
97 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, 70{
98 dwCreationDisposition, dwFlagsAndAttributes, NULL); 71 voidpf ret=NULL;
99
100 if (hFile == INVALID_HANDLE_VALUE)
101 hFile = NULL;
102 72
103 if (hFile != NULL) 73 if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
104 { 74 {
105 WIN32FILE_IOWIN w32fiow; 75 WIN32FILE_IOWIN w32fiow;
106 w32fiow.hf = hFile; 76 w32fiow.hf = hFile;
107 w32fiow.error = 0; 77 w32fiow.error = 0;
108 ret = malloc(sizeof(WIN32FILE_IOWIN)); 78 ret = malloc(sizeof(WIN32FILE_IOWIN));
79
109 if (ret==NULL) 80 if (ret==NULL)
110 CloseHandle(hFile); 81 CloseHandle(hFile);
111 else *((WIN32FILE_IOWIN*)ret) = w32fiow; 82 else
83 *((WIN32FILE_IOWIN*)ret) = w32fiow;
112 } 84 }
113 return ret; 85 return ret;
114} 86}
115 87
88voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
89{
90 const char* mode_fopen = NULL;
91 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
92 HANDLE hFile = NULL;
93
94 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
95
96 if ((filename!=NULL) && (dwDesiredAccess != 0))
97 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
98
99 return win32_build_iowin(hFile);
100}
101
116 102
117uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) 103voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
118 voidpf opaque; 104{
119 voidpf stream; 105 const char* mode_fopen = NULL;
120 void* buf; 106 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
121 uLong size; 107 HANDLE hFile = NULL;
108
109 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
110
111 if ((filename!=NULL) && (dwDesiredAccess != 0))
112 hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
113
114 return win32_build_iowin(hFile);
115}
116
117
118voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
119{
120 const char* mode_fopen = NULL;
121 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
122 HANDLE hFile = NULL;
123
124 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
125
126 if ((filename!=NULL) && (dwDesiredAccess != 0))
127 hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
128
129 return win32_build_iowin(hFile);
130}
131
132
133voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
134{
135 const char* mode_fopen = NULL;
136 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
137 HANDLE hFile = NULL;
138
139 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
140
141 if ((filename!=NULL) && (dwDesiredAccess != 0))
142 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
143
144 return win32_build_iowin(hFile);
145}
146
147
148uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
122{ 149{
123 uLong ret=0; 150 uLong ret=0;
124 HANDLE hFile = NULL; 151 HANDLE hFile = NULL;
125 if (stream!=NULL) 152 if (stream!=NULL)
126 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 153 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
154
127 if (hFile != NULL) 155 if (hFile != NULL)
156 {
128 if (!ReadFile(hFile, buf, size, &ret, NULL)) 157 if (!ReadFile(hFile, buf, size, &ret, NULL))
129 { 158 {
130 DWORD dwErr = GetLastError(); 159 DWORD dwErr = GetLastError();
@@ -132,23 +161,21 @@ uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
132 dwErr = 0; 161 dwErr = 0;
133 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 162 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
134 } 163 }
164 }
135 165
136 return ret; 166 return ret;
137} 167}
138 168
139 169
140uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) 170uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
141 voidpf opaque;
142 voidpf stream;
143 const void* buf;
144 uLong size;
145{ 171{
146 uLong ret=0; 172 uLong ret=0;
147 HANDLE hFile = NULL; 173 HANDLE hFile = NULL;
148 if (stream!=NULL) 174 if (stream!=NULL)
149 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 175 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
150 176
151 if (hFile !=NULL) 177 if (hFile != NULL)
178 {
152 if (!WriteFile(hFile, buf, size, &ret, NULL)) 179 if (!WriteFile(hFile, buf, size, &ret, NULL))
153 { 180 {
154 DWORD dwErr = GetLastError(); 181 DWORD dwErr = GetLastError();
@@ -156,13 +183,12 @@ uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
156 dwErr = 0; 183 dwErr = 0;
157 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 184 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
158 } 185 }
186 }
159 187
160 return ret; 188 return ret;
161} 189}
162 190
163long ZCALLBACK win32_tell_file_func (opaque, stream) 191long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
164 voidpf opaque;
165 voidpf stream;
166{ 192{
167 long ret=-1; 193 long ret=-1;
168 HANDLE hFile = NULL; 194 HANDLE hFile = NULL;
@@ -183,11 +209,32 @@ long ZCALLBACK win32_tell_file_func (opaque, stream)
183 return ret; 209 return ret;
184} 210}
185 211
186long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) 212ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
187 voidpf opaque; 213{
188 voidpf stream; 214 ZPOS64_T ret= (ZPOS64_T)-1;
189 uLong offset; 215 HANDLE hFile = NULL;
190 int origin; 216 if (stream!=NULL)
217 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
218
219 if (hFile)
220 {
221 LARGE_INTEGER li;
222 li.QuadPart = 0;
223 li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_CURRENT);
224 if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
225 {
226 DWORD dwErr = GetLastError();
227 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
228 ret = (ZPOS64_T)-1;
229 }
230 else
231 ret=li.QuadPart;
232 }
233 return ret;
234}
235
236
237long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
191{ 238{
192 DWORD dwMoveMethod=0xFFFFFFFF; 239 DWORD dwMoveMethod=0xFFFFFFFF;
193 HANDLE hFile = NULL; 240 HANDLE hFile = NULL;
@@ -224,9 +271,46 @@ long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
224 return ret; 271 return ret;
225} 272}
226 273
227int ZCALLBACK win32_close_file_func (opaque, stream) 274long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
228 voidpf opaque; 275{
229 voidpf stream; 276 DWORD dwMoveMethod=0xFFFFFFFF;
277 HANDLE hFile = NULL;
278 long ret=-1;
279
280 if (stream!=NULL)
281 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
282
283 switch (origin)
284 {
285 case ZLIB_FILEFUNC_SEEK_CUR :
286 dwMoveMethod = FILE_CURRENT;
287 break;
288 case ZLIB_FILEFUNC_SEEK_END :
289 dwMoveMethod = FILE_END;
290 break;
291 case ZLIB_FILEFUNC_SEEK_SET :
292 dwMoveMethod = FILE_BEGIN;
293 break;
294 default: return -1;
295 }
296
297 if (hFile)
298 {
299 LARGE_INTEGER* li = (LARGE_INTEGER*)&offset;
300 DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMoveMethod);
301 if (dwSet == INVALID_SET_FILE_POINTER)
302 {
303 DWORD dwErr = GetLastError();
304 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
305 ret = -1;
306 }
307 else
308 ret=0;
309 }
310 return ret;
311}
312
313int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
230{ 314{
231 int ret=-1; 315 int ret=-1;
232 316
@@ -244,9 +328,7 @@ int ZCALLBACK win32_close_file_func (opaque, stream)
244 return ret; 328 return ret;
245} 329}
246 330
247int ZCALLBACK win32_error_file_func (opaque, stream) 331int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
248 voidpf opaque;
249 voidpf stream;
250{ 332{
251 int ret=-1; 333 int ret=-1;
252 if (stream!=NULL) 334 if (stream!=NULL)
@@ -256,8 +338,7 @@ int ZCALLBACK win32_error_file_func (opaque, stream)
256 return ret; 338 return ret;
257} 339}
258 340
259void fill_win32_filefunc (pzlib_filefunc_def) 341void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
260 zlib_filefunc_def* pzlib_filefunc_def;
261{ 342{
262 pzlib_filefunc_def->zopen_file = win32_open_file_func; 343 pzlib_filefunc_def->zopen_file = win32_open_file_func;
263 pzlib_filefunc_def->zread_file = win32_read_file_func; 344 pzlib_filefunc_def->zread_file = win32_read_file_func;
@@ -266,5 +347,43 @@ void fill_win32_filefunc (pzlib_filefunc_def)
266 pzlib_filefunc_def->zseek_file = win32_seek_file_func; 347 pzlib_filefunc_def->zseek_file = win32_seek_file_func;
267 pzlib_filefunc_def->zclose_file = win32_close_file_func; 348 pzlib_filefunc_def->zclose_file = win32_close_file_func;
268 pzlib_filefunc_def->zerror_file = win32_error_file_func; 349 pzlib_filefunc_def->zerror_file = win32_error_file_func;
269 pzlib_filefunc_def->opaque=NULL; 350 pzlib_filefunc_def->opaque = NULL;
351}
352
353void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
354{
355 pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
356 pzlib_filefunc_def->zread_file = win32_read_file_func;
357 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
358 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
359 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
360 pzlib_filefunc_def->zclose_file = win32_close_file_func;
361 pzlib_filefunc_def->zerror_file = win32_error_file_func;
362 pzlib_filefunc_def->opaque = NULL;
363}
364
365
366void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
367{
368 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
369 pzlib_filefunc_def->zread_file = win32_read_file_func;
370 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
371 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
372 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
373 pzlib_filefunc_def->zclose_file = win32_close_file_func;
374 pzlib_filefunc_def->zerror_file = win32_error_file_func;
375 pzlib_filefunc_def->opaque = NULL;
376}
377
378
379void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
380{
381 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
382 pzlib_filefunc_def->zread_file = win32_read_file_func;
383 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
384 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
385 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
386 pzlib_filefunc_def->zclose_file = win32_close_file_func;
387 pzlib_filefunc_def->zerror_file = win32_error_file_func;
388 pzlib_filefunc_def->opaque = NULL;
270} 389}
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h
index a3a437a..cc77ec4 100644
--- a/contrib/minizip/iowin32.h
+++ b/contrib/minizip/iowin32.h
@@ -1,10 +1,14 @@
1/* iowin32.h -- IO base function header for compress/uncompress .zip 1/* iowin32.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 Version 1.1, January 7th, 2010
3 This IO API version uses the Win32 API (for Microsoft Windows) 3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4 4
5 Version 1.01e, February 12th, 2005 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6
7 Modifications for Zip64 support
8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9
10 For more info read MiniZip_info.txt
6 11
7 Copyright (C) 1998-2005 Gilles Vollant
8*/ 12*/
9 13
10#include <windows.h> 14#include <windows.h>
@@ -15,6 +19,9 @@ extern "C" {
15#endif 19#endif
16 20
17void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 21void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
22void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
23void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
24void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
18 25
19#ifdef __cplusplus 26#ifdef __cplusplus
20} 27}
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c
index f599938..c0a07ab 100644
--- a/contrib/minizip/miniunz.c
+++ b/contrib/minizip/miniunz.c
@@ -1,10 +1,31 @@
1/* 1/*
2 miniunz.c 2 miniunz.c
3 Version 1.01e, February 12th, 2005 3 Version 1.1, January 7th, 2010
4 sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4 5
5 Copyright (C) 1998-2005 Gilles Vollant 6 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
7
8 Modifications of Unzip for Zip64
9 Copyright (C) 2007-2008 Even Rouault
10
11 Modifications for Zip64 support on both zip and unzip
12 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
6*/ 13*/
7 14
15#ifndef _WIN32
16 #ifndef __USE_FILE_OFFSET64
17 #define __USE_FILE_OFFSET64
18 #endif
19 #ifndef __USE_LARGEFILE64
20 #define __USE_LARGEFILE64
21 #endif
22 #ifndef _LARGEFILE64_SOURCE
23 #define _LARGEFILE64_SOURCE
24 #endif
25 #ifndef _FILE_OFFSET_BIT
26 #define _FILE_OFFSET_BIT 64
27 #endif
28#endif
8 29
9#include <stdio.h> 30#include <stdio.h>
10#include <stdlib.h> 31#include <stdlib.h>
@@ -27,7 +48,7 @@
27#define WRITEBUFFERSIZE (8192) 48#define WRITEBUFFERSIZE (8192)
28#define MAXFILENAME (256) 49#define MAXFILENAME (256)
29 50
30#ifdef WIN32 51#ifdef _WIN32
31#define USEWIN32IOAPI 52#define USEWIN32IOAPI
32#include "iowin32.h" 53#include "iowin32.h"
33#endif 54#endif
@@ -51,11 +72,11 @@ void change_file_date(filename,dosdate,tmu_date)
51 uLong dosdate; 72 uLong dosdate;
52 tm_unz tmu_date; 73 tm_unz tmu_date;
53{ 74{
54#ifdef WIN32 75#ifdef _WIN32
55 HANDLE hFile; 76 HANDLE hFile;
56 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; 77 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
57 78
58 hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, 79 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
59 0,NULL,OPEN_EXISTING,0,NULL); 80 0,NULL,OPEN_EXISTING,0,NULL);
60 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); 81 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
61 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); 82 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
@@ -91,8 +112,8 @@ int mymkdir(dirname)
91 const char* dirname; 112 const char* dirname;
92{ 113{
93 int ret=0; 114 int ret=0;
94#ifdef WIN32 115#ifdef _WIN32
95 ret = mkdir(dirname); 116 ret = _mkdir(dirname);
96#else 117#else
97#ifdef unix 118#ifdef unix
98 ret = mkdir (dirname,0775); 119 ret = mkdir (dirname,0775);
@@ -112,6 +133,11 @@ int makedir (newdir)
112 return 0; 133 return 0;
113 134
114 buffer = (char*)malloc(len+1); 135 buffer = (char*)malloc(len+1);
136 if (buffer==NULL)
137 {
138 printf("Error allocating memory\n");
139 return UNZ_INTERNALERROR;
140 }
115 strcpy(buffer,newdir); 141 strcpy(buffer,newdir);
116 142
117 if (buffer[len-1] == '/') { 143 if (buffer[len-1] == '/') {
@@ -164,34 +190,61 @@ void do_help()
164 " -p extract crypted file using password\n\n"); 190 " -p extract crypted file using password\n\n");
165} 191}
166 192
193void Display64BitsSize(ZPOS64_T n, int size_char)
194{
195 /* to avoid compatibility problem , we do here the conversion */
196 char number[21];
197 int offset=19;
198 int pos_string = 19;
199 number[20]=0;
200 for (;;) {
201 number[offset]=(char)((n%10)+'0');
202 if (number[offset] != '0')
203 pos_string=offset;
204 n/=10;
205 if (offset==0)
206 break;
207 offset--;
208 }
209 {
210 int size_display_string = 19-pos_string;
211 while (size_char > size_display_string)
212 {
213 size_char--;
214 printf(" ");
215 }
216 }
217
218 printf("%s",&number[pos_string]);
219}
167 220
168int do_list(uf) 221int do_list(uf)
169 unzFile uf; 222 unzFile uf;
170{ 223{
171 uLong i; 224 uLong i;
172 unz_global_info gi; 225 unz_global_info64 gi;
173 int err; 226 int err;
174 227
175 err = unzGetGlobalInfo (uf,&gi); 228 err = unzGetGlobalInfo64(uf,&gi);
176 if (err!=UNZ_OK) 229 if (err!=UNZ_OK)
177 printf("error %d with zipfile in unzGetGlobalInfo \n",err); 230 printf("error %d with zipfile in unzGetGlobalInfo \n",err);
178 printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); 231 printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
179 printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); 232 printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
180 for (i=0;i<gi.number_entry;i++) 233 for (i=0;i<gi.number_entry;i++)
181 { 234 {
182 char filename_inzip[256]; 235 char filename_inzip[256];
183 unz_file_info file_info; 236 unz_file_info64 file_info;
184 uLong ratio=0; 237 uLong ratio=0;
185 const char *string_method; 238 const char *string_method;
186 char charCrypt=' '; 239 char charCrypt=' ';
187 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 240 err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
188 if (err!=UNZ_OK) 241 if (err!=UNZ_OK)
189 { 242 {
190 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 243 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
191 break; 244 break;
192 } 245 }
193 if (file_info.uncompressed_size>0) 246 if (file_info.uncompressed_size>0)
194 ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; 247 ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
195 248
196 /* display a '*' if the file is crypted */ 249 /* display a '*' if the file is crypted */
197 if ((file_info.flag & 1) != 0) 250 if ((file_info.flag & 1) != 0)
@@ -211,12 +264,17 @@ int do_list(uf)
211 string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ 264 string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
212 } 265 }
213 else 266 else
267 if (file_info.compression_method==Z_BZIP2ED)
268 {
269 string_method="BZip2 ";
270 }
271 else
214 string_method="Unkn. "; 272 string_method="Unkn. ";
215 273
216 printf("%7lu %6s%c%7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", 274 Display64BitsSize(file_info.uncompressed_size,7);
217 file_info.uncompressed_size,string_method, 275 printf(" %6s%c",string_method,charCrypt);
218 charCrypt, 276 Display64BitsSize(file_info.compressed_size,7);
219 file_info.compressed_size, 277 printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
220 ratio, 278 ratio,
221 (uLong)file_info.tmu_date.tm_mon + 1, 279 (uLong)file_info.tmu_date.tm_mon + 1,
222 (uLong)file_info.tmu_date.tm_mday, 280 (uLong)file_info.tmu_date.tm_mday,
@@ -252,9 +310,9 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
252 void* buf; 310 void* buf;
253 uInt size_buf; 311 uInt size_buf;
254 312
255 unz_file_info file_info; 313 unz_file_info64 file_info;
256 uLong ratio=0; 314 uLong ratio=0;
257 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 315 err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
258 316
259 if (err!=UNZ_OK) 317 if (err!=UNZ_OK)
260 { 318 {
@@ -306,7 +364,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
306 { 364 {
307 char rep=0; 365 char rep=0;
308 FILE* ftestexist; 366 FILE* ftestexist;
309 ftestexist = fopen(write_filename,"rb"); 367 ftestexist = fopen64(write_filename,"rb");
310 if (ftestexist!=NULL) 368 if (ftestexist!=NULL)
311 { 369 {
312 fclose(ftestexist); 370 fclose(ftestexist);
@@ -337,7 +395,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
337 395
338 if ((skip==0) && (err==UNZ_OK)) 396 if ((skip==0) && (err==UNZ_OK))
339 { 397 {
340 fout=fopen(write_filename,"wb"); 398 fout=fopen64(write_filename,"wb");
341 399
342 /* some zipfile don't contain directory alone before file */ 400 /* some zipfile don't contain directory alone before file */
343 if ((fout==NULL) && ((*popt_extract_without_path)==0) && 401 if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
@@ -347,7 +405,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
347 *(filename_withoutpath-1)='\0'; 405 *(filename_withoutpath-1)='\0';
348 makedir(write_filename); 406 makedir(write_filename);
349 *(filename_withoutpath-1)=c; 407 *(filename_withoutpath-1)=c;
350 fout=fopen(write_filename,"wb"); 408 fout=fopen64(write_filename,"wb");
351 } 409 }
352 410
353 if (fout==NULL) 411 if (fout==NULL)
@@ -409,11 +467,11 @@ int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
409 const char* password; 467 const char* password;
410{ 468{
411 uLong i; 469 uLong i;
412 unz_global_info gi; 470 unz_global_info64 gi;
413 int err; 471 int err;
414 FILE* fout=NULL; 472 FILE* fout=NULL;
415 473
416 err = unzGetGlobalInfo (uf,&gi); 474 err = unzGetGlobalInfo64(uf,&gi);
417 if (err!=UNZ_OK) 475 if (err!=UNZ_OK)
418 printf("error %d with zipfile in unzGetGlobalInfo \n",err); 476 printf("error %d with zipfile in unzGetGlobalInfo \n",err);
419 477
@@ -470,6 +528,7 @@ int main(argc,argv)
470 const char *password=NULL; 528 const char *password=NULL;
471 char filename_try[MAXFILENAME+16] = ""; 529 char filename_try[MAXFILENAME+16] = "";
472 int i; 530 int i;
531 int ret_value=0;
473 int opt_do_list=0; 532 int opt_do_list=0;
474 int opt_do_extract=1; 533 int opt_do_extract=1;
475 int opt_do_extract_withoutpath=0; 534 int opt_do_extract_withoutpath=0;
@@ -532,7 +591,7 @@ int main(argc,argv)
532 { 591 {
533 592
534# ifdef USEWIN32IOAPI 593# ifdef USEWIN32IOAPI
535 zlib_filefunc_def ffunc; 594 zlib_filefunc64_def ffunc;
536# endif 595# endif
537 596
538 strncpy(filename_try, zipfilename,MAXFILENAME-1); 597 strncpy(filename_try, zipfilename,MAXFILENAME-1);
@@ -540,18 +599,18 @@ int main(argc,argv)
540 filename_try[ MAXFILENAME ] = '\0'; 599 filename_try[ MAXFILENAME ] = '\0';
541 600
542# ifdef USEWIN32IOAPI 601# ifdef USEWIN32IOAPI
543 fill_win32_filefunc(&ffunc); 602 fill_win32_filefunc64A(&ffunc);
544 uf = unzOpen2(zipfilename,&ffunc); 603 uf = unzOpen2_64(zipfilename,&ffunc);
545# else 604# else
546 uf = unzOpen(zipfilename); 605 uf = unzOpen64(zipfilename);
547# endif 606# endif
548 if (uf==NULL) 607 if (uf==NULL)
549 { 608 {
550 strcat(filename_try,".zip"); 609 strcat(filename_try,".zip");
551# ifdef USEWIN32IOAPI 610# ifdef USEWIN32IOAPI
552 uf = unzOpen2(filename_try,&ffunc); 611 uf = unzOpen2_64(filename_try,&ffunc);
553# else 612# else
554 uf = unzOpen(filename_try); 613 uf = unzOpen64(filename_try);
555# endif 614# endif
556 } 615 }
557 } 616 }
@@ -564,22 +623,26 @@ int main(argc,argv)
564 printf("%s opened\n",filename_try); 623 printf("%s opened\n",filename_try);
565 624
566 if (opt_do_list==1) 625 if (opt_do_list==1)
567 return do_list(uf); 626 ret_value = do_list(uf);
568 else if (opt_do_extract==1) 627 else if (opt_do_extract==1)
569 { 628 {
629#ifdef _WIN32
630 if (opt_extractdir && _chdir(dirname))
631#else
570 if (opt_extractdir && chdir(dirname)) 632 if (opt_extractdir && chdir(dirname))
633#endif
571 { 634 {
572 printf("Error changing into %s, aborting\n", dirname); 635 printf("Error changing into %s, aborting\n", dirname);
573 exit(-1); 636 exit(-1);
574 } 637 }
575 638
576 if (filename_to_extract == NULL) 639 if (filename_to_extract == NULL)
577 return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); 640 ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
578 else 641 else
579 return do_extract_onefile(uf,filename_to_extract, 642 ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
580 opt_do_extract_withoutpath,opt_overwrite,password);
581 } 643 }
582 unzCloseCurrentFile(uf);
583 644
584 return 0; 645 unzClose(uf);
646
647 return ret_value;
585} 648}
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c
index f2dfecd..4ce33af 100644
--- a/contrib/minizip/minizip.c
+++ b/contrib/minizip/minizip.c
@@ -1,10 +1,33 @@
1/* 1/*
2 minizip.c 2 minizip.c
3 Version 1.01e, February 12th, 2005 3 Version 1.1, January 7th, 2010
4 sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4 5
5 Copyright (C) 1998-2005 Gilles Vollant 6 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
7
8 Modifications of Unzip for Zip64
9 Copyright (C) 2007-2008 Even Rouault
10
11 Modifications for Zip64 support on both zip and unzip
12 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
6*/ 13*/
7 14
15
16#ifndef _WIN32
17 #ifndef __USE_FILE_OFFSET64
18 #define __USE_FILE_OFFSET64
19 #endif
20 #ifndef __USE_LARGEFILE64
21 #define __USE_LARGEFILE64
22 #endif
23 #ifndef _LARGEFILE64_SOURCE
24 #define _LARGEFILE64_SOURCE
25 #endif
26 #ifndef _FILE_OFFSET_BIT
27 #define _FILE_OFFSET_BIT 64
28 #endif
29#endif
30
8#include <stdio.h> 31#include <stdio.h>
9#include <stdlib.h> 32#include <stdlib.h>
10#include <string.h> 33#include <string.h>
@@ -24,9 +47,9 @@
24 47
25#include "zip.h" 48#include "zip.h"
26 49
27#ifdef WIN32 50#ifdef _WIN32
28#define USEWIN32IOAPI 51 #define USEWIN32IOAPI
29#include "iowin32.h" 52 #include "iowin32.h"
30#endif 53#endif
31 54
32 55
@@ -34,7 +57,7 @@
34#define WRITEBUFFERSIZE (16384) 57#define WRITEBUFFERSIZE (16384)
35#define MAXFILENAME (256) 58#define MAXFILENAME (256)
36 59
37#ifdef WIN32 60#ifdef _WIN32
38uLong filetime(f, tmzip, dt) 61uLong filetime(f, tmzip, dt)
39 char *f; /* name of file to get info on */ 62 char *f; /* name of file to get info on */
40 tm_zip *tmzip; /* return value: access, modific. and creation times */ 63 tm_zip *tmzip; /* return value: access, modific. and creation times */
@@ -44,9 +67,9 @@ uLong filetime(f, tmzip, dt)
44 { 67 {
45 FILETIME ftLocal; 68 FILETIME ftLocal;
46 HANDLE hFind; 69 HANDLE hFind;
47 WIN32_FIND_DATA ff32; 70 WIN32_FIND_DATAA ff32;
48 71
49 hFind = FindFirstFile(f,&ff32); 72 hFind = FindFirstFileA(f,&ff32);
50 if (hFind != INVALID_HANDLE_VALUE) 73 if (hFind != INVALID_HANDLE_VALUE)
51 { 74 {
52 FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); 75 FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
@@ -119,7 +142,7 @@ int check_exist_file(filename)
119{ 142{
120 FILE* ftestexist; 143 FILE* ftestexist;
121 int ret = 1; 144 int ret = 1;
122 ftestexist = fopen(filename,"rb"); 145 ftestexist = fopen64(filename,"rb");
123 if (ftestexist==NULL) 146 if (ftestexist==NULL)
124 ret = 0; 147 ret = 0;
125 else 148 else
@@ -129,18 +152,20 @@ int check_exist_file(filename)
129 152
130void do_banner() 153void do_banner()
131{ 154{
132 printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); 155 printf("MiniZip64 1.0, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
133 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); 156 printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
157 printf("more info on MiniZip64 at http://result42.com/projects/MiniZip64\n\n");
134} 158}
135 159
136void do_help() 160void do_help()
137{ 161{
138 printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \ 162 printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
139 " -o Overwrite existing file.zip\n" \ 163 " -o Overwrite existing file.zip\n" \
140 " -a Append to existing file.zip\n" \ 164 " -a Append to existing file.zip\n" \
141 " -0 Store only\n" \ 165 " -0 Store only\n" \
142 " -1 Compress faster\n" \ 166 " -1 Compress faster\n" \
143 " -9 Compress better\n\n"); 167 " -9 Compress better\n\n" \
168 " -j exclude path. store only the file name.\n\n");
144} 169}
145 170
146/* calculate the CRC32 of a file, 171/* calculate the CRC32 of a file,
@@ -149,7 +174,7 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne
149{ 174{
150 unsigned long calculate_crc=0; 175 unsigned long calculate_crc=0;
151 int err=ZIP_OK; 176 int err=ZIP_OK;
152 FILE * fin = fopen(filenameinzip,"rb"); 177 FILE * fin = fopen64(filenameinzip,"rb");
153 unsigned long size_read = 0; 178 unsigned long size_read = 0;
154 unsigned long total_read = 0; 179 unsigned long total_read = 0;
155 if (fin==NULL) 180 if (fin==NULL)
@@ -179,10 +204,33 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne
179 fclose(fin); 204 fclose(fin);
180 205
181 *result_crc=calculate_crc; 206 *result_crc=calculate_crc;
182 printf("file %s crc %x\n",filenameinzip,calculate_crc); 207 printf("file %s crc %lx\n", filenameinzip, calculate_crc);
183 return err; 208 return err;
184} 209}
185 210
211int isLargeFile(const char* filename)
212{
213 int largeFile = 0;
214 ZPOS64_T pos = 0;
215 FILE* pFile = fopen64(filename, "rb");
216
217 if(pFile != NULL)
218 {
219 int n = fseeko64(pFile, 0, SEEK_END);
220
221 pos = ftello64(pFile);
222
223 printf("File : %s is %lld bytes\n", filename, pos);
224
225 if(pos >= 0xffffffff)
226 largeFile = 1;
227
228 fclose(pFile);
229 }
230
231 return largeFile;
232}
233
186int main(argc,argv) 234int main(argc,argv)
187 int argc; 235 int argc;
188 char *argv[]; 236 char *argv[];
@@ -190,6 +238,7 @@ int main(argc,argv)
190 int i; 238 int i;
191 int opt_overwrite=0; 239 int opt_overwrite=0;
192 int opt_compress_level=Z_DEFAULT_COMPRESSION; 240 int opt_compress_level=Z_DEFAULT_COMPRESSION;
241 int opt_exclude_path=0;
193 int zipfilenamearg = 0; 242 int zipfilenamearg = 0;
194 char filename_try[MAXFILENAME+16]; 243 char filename_try[MAXFILENAME+16];
195 int zipok; 244 int zipok;
@@ -222,6 +271,8 @@ int main(argc,argv)
222 opt_overwrite = 2; 271 opt_overwrite = 2;
223 if ((c>='0') && (c<='9')) 272 if ((c>='0') && (c<='9'))
224 opt_compress_level = c-'0'; 273 opt_compress_level = c-'0';
274 if ((c=='j') || (c=='J'))
275 opt_exclude_path = 1;
225 276
226 if (((c=='p') || (c=='P')) && (i+1<argc)) 277 if (((c=='p') || (c=='P')) && (i+1<argc))
227 { 278 {
@@ -231,8 +282,12 @@ int main(argc,argv)
231 } 282 }
232 } 283 }
233 else 284 else
285 {
234 if (zipfilenamearg == 0) 286 if (zipfilenamearg == 0)
287 {
235 zipfilenamearg = i ; 288 zipfilenamearg = i ;
289 }
290 }
236 } 291 }
237 } 292 }
238 293
@@ -245,7 +300,9 @@ int main(argc,argv)
245 } 300 }
246 301
247 if (zipfilenamearg==0) 302 if (zipfilenamearg==0)
303 {
248 zipok=0; 304 zipok=0;
305 }
249 else 306 else
250 { 307 {
251 int i,len; 308 int i,len;
@@ -302,11 +359,11 @@ int main(argc,argv)
302 zipFile zf; 359 zipFile zf;
303 int errclose; 360 int errclose;
304# ifdef USEWIN32IOAPI 361# ifdef USEWIN32IOAPI
305 zlib_filefunc_def ffunc; 362 zlib_filefunc64_def ffunc;
306 fill_win32_filefunc(&ffunc); 363 fill_win32_filefunc64A(&ffunc);
307 zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); 364 zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
308# else 365# else
309 zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); 366 zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
310# endif 367# endif
311 368
312 if (zf == NULL) 369 if (zf == NULL)
@@ -329,8 +386,10 @@ int main(argc,argv)
329 FILE * fin; 386 FILE * fin;
330 int size_read; 387 int size_read;
331 const char* filenameinzip = argv[i]; 388 const char* filenameinzip = argv[i];
389 const char *savefilenameinzip;
332 zip_fileinfo zi; 390 zip_fileinfo zi;
333 unsigned long crcFile=0; 391 unsigned long crcFile=0;
392 int zip64 = 0;
334 393
335 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = 394 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
336 zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; 395 zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
@@ -347,20 +406,49 @@ int main(argc,argv)
347*/ 406*/
348 if ((password != NULL) && (err==ZIP_OK)) 407 if ((password != NULL) && (err==ZIP_OK))
349 err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); 408 err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
350 409
351 err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, 410 zip64 = isLargeFile(filenameinzip);
411
412 /* The path name saved, should not include a leading slash. */
413 /*if it did, windows/xp and dynazip couldn't read the zip file. */
414 savefilenameinzip = filenameinzip;
415 while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
416 {
417 savefilenameinzip++;
418 }
419
420 /*should the zip file contain any path at all?*/
421 if( opt_exclude_path )
422 {
423 const char *tmpptr;
424 const char *lastslash = 0;
425 for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
426 {
427 if( *tmpptr == '\\' || *tmpptr == '/')
428 {
429 lastslash = tmpptr;
430 }
431 }
432 if( lastslash != NULL )
433 {
434 savefilenameinzip = lastslash+1; // base filename follows last slash.
435 }
436 }
437
438 /**/
439 err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
352 NULL,0,NULL,0,NULL /* comment*/, 440 NULL,0,NULL,0,NULL /* comment*/,
353 (opt_compress_level != 0) ? Z_DEFLATED : 0, 441 (opt_compress_level != 0) ? Z_DEFLATED : 0,
354 opt_compress_level,0, 442 opt_compress_level,0,
355 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ 443 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
356 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 444 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
357 password,crcFile); 445 password,crcFile, zip64);
358 446
359 if (err != ZIP_OK) 447 if (err != ZIP_OK)
360 printf("error in opening %s in zipfile\n",filenameinzip); 448 printf("error in opening %s in zipfile\n",filenameinzip);
361 else 449 else
362 { 450 {
363 fin = fopen(filenameinzip,"rb"); 451 fin = fopen64(filenameinzip,"rb");
364 if (fin==NULL) 452 if (fin==NULL)
365 { 453 {
366 err=ZIP_ERRNO; 454 err=ZIP_ERRNO;
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c
index 8a50ee4..bc5c798 100644
--- a/contrib/minizip/mztools.c
+++ b/contrib/minizip/mztools.c
@@ -1,281 +1,281 @@
1/* 1/*
2 Additional tools for Minizip 2 Additional tools for Minizip
3 Code: Xavier Roche '2004 3 Code: Xavier Roche '2004
4 License: Same as ZLIB (www.gzip.org) 4 License: Same as ZLIB (www.gzip.org)
5*/ 5*/
6 6
7/* Code */ 7/* Code */
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h> 10#include <string.h>
11#include "zlib.h" 11#include "zlib.h"
12#include "unzip.h" 12#include "unzip.h"
13 13
14#define READ_8(adr) ((unsigned char)*(adr)) 14#define READ_8(adr) ((unsigned char)*(adr))
15#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) 15#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
16#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) 16#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
17 17
18#define WRITE_8(buff, n) do { \ 18#define WRITE_8(buff, n) do { \
19 *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ 19 *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
20} while(0) 20} while(0)
21#define WRITE_16(buff, n) do { \ 21#define WRITE_16(buff, n) do { \
22 WRITE_8((unsigned char*)(buff), n); \ 22 WRITE_8((unsigned char*)(buff), n); \
23 WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ 23 WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
24} while(0) 24} while(0)
25#define WRITE_32(buff, n) do { \ 25#define WRITE_32(buff, n) do { \
26 WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ 26 WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
27 WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ 27 WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
28} while(0) 28} while(0)
29 29
30extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) 30extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
31const char* file; 31const char* file;
32const char* fileOut; 32const char* fileOut;
33const char* fileOutTmp; 33const char* fileOutTmp;
34uLong* nRecovered; 34uLong* nRecovered;
35uLong* bytesRecovered; 35uLong* bytesRecovered;
36{ 36{
37 int err = Z_OK; 37 int err = Z_OK;
38 FILE* fpZip = fopen(file, "rb"); 38 FILE* fpZip = fopen(file, "rb");
39 FILE* fpOut = fopen(fileOut, "wb"); 39 FILE* fpOut = fopen(fileOut, "wb");
40 FILE* fpOutCD = fopen(fileOutTmp, "wb"); 40 FILE* fpOutCD = fopen(fileOutTmp, "wb");
41 if (fpZip != NULL && fpOut != NULL) { 41 if (fpZip != NULL && fpOut != NULL) {
42 int entries = 0; 42 int entries = 0;
43 uLong totalBytes = 0; 43 uLong totalBytes = 0;
44 char header[30]; 44 char header[30];
45 char filename[256]; 45 char filename[256];
46 char extra[1024]; 46 char extra[1024];
47 int offset = 0; 47 int offset = 0;
48 int offsetCD = 0; 48 int offsetCD = 0;
49 while ( fread(header, 1, 30, fpZip) == 30 ) { 49 while ( fread(header, 1, 30, fpZip) == 30 ) {
50 int currentOffset = offset; 50 int currentOffset = offset;
51 51
52 /* File entry */ 52 /* File entry */
53 if (READ_32(header) == 0x04034b50) { 53 if (READ_32(header) == 0x04034b50) {
54 unsigned int version = READ_16(header + 4); 54 unsigned int version = READ_16(header + 4);
55 unsigned int gpflag = READ_16(header + 6); 55 unsigned int gpflag = READ_16(header + 6);
56 unsigned int method = READ_16(header + 8); 56 unsigned int method = READ_16(header + 8);
57 unsigned int filetime = READ_16(header + 10); 57 unsigned int filetime = READ_16(header + 10);
58 unsigned int filedate = READ_16(header + 12); 58 unsigned int filedate = READ_16(header + 12);
59 unsigned int crc = READ_32(header + 14); /* crc */ 59 unsigned int crc = READ_32(header + 14); /* crc */
60 unsigned int cpsize = READ_32(header + 18); /* compressed size */ 60 unsigned int cpsize = READ_32(header + 18); /* compressed size */
61 unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ 61 unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
62 unsigned int fnsize = READ_16(header + 26); /* file name length */ 62 unsigned int fnsize = READ_16(header + 26); /* file name length */
63 unsigned int extsize = READ_16(header + 28); /* extra field length */ 63 unsigned int extsize = READ_16(header + 28); /* extra field length */
64 filename[0] = extra[0] = '\0'; 64 filename[0] = extra[0] = '\0';
65 65
66 /* Header */ 66 /* Header */
67 if (fwrite(header, 1, 30, fpOut) == 30) { 67 if (fwrite(header, 1, 30, fpOut) == 30) {
68 offset += 30; 68 offset += 30;
69 } else { 69 } else {
70 err = Z_ERRNO; 70 err = Z_ERRNO;
71 break; 71 break;
72 } 72 }
73 73
74 /* Filename */ 74 /* Filename */
75 if (fnsize > 0) { 75 if (fnsize > 0) {
76 if (fread(filename, 1, fnsize, fpZip) == fnsize) { 76 if (fread(filename, 1, fnsize, fpZip) == fnsize) {
77 if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { 77 if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
78 offset += fnsize; 78 offset += fnsize;
79 } else { 79 } else {
80 err = Z_ERRNO; 80 err = Z_ERRNO;
81 break; 81 break;
82 } 82 }
83 } else { 83 } else {
84 err = Z_ERRNO; 84 err = Z_ERRNO;
85 break; 85 break;
86 } 86 }
87 } else { 87 } else {
88 err = Z_STREAM_ERROR; 88 err = Z_STREAM_ERROR;
89 break; 89 break;
90 } 90 }
91 91
92 /* Extra field */ 92 /* Extra field */
93 if (extsize > 0) { 93 if (extsize > 0) {
94 if (fread(extra, 1, extsize, fpZip) == extsize) { 94 if (fread(extra, 1, extsize, fpZip) == extsize) {
95 if (fwrite(extra, 1, extsize, fpOut) == extsize) { 95 if (fwrite(extra, 1, extsize, fpOut) == extsize) {
96 offset += extsize; 96 offset += extsize;
97 } else { 97 } else {
98 err = Z_ERRNO; 98 err = Z_ERRNO;
99 break; 99 break;
100 } 100 }
101 } else { 101 } else {
102 err = Z_ERRNO; 102 err = Z_ERRNO;
103 break; 103 break;
104 } 104 }
105 } 105 }
106 106
107 /* Data */ 107 /* Data */
108 { 108 {
109 int dataSize = cpsize; 109 int dataSize = cpsize;
110 if (dataSize == 0) { 110 if (dataSize == 0) {
111 dataSize = uncpsize; 111 dataSize = uncpsize;
112 } 112 }
113 if (dataSize > 0) { 113 if (dataSize > 0) {
114 char* data = malloc(dataSize); 114 char* data = malloc(dataSize);
115 if (data != NULL) { 115 if (data != NULL) {
116 if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { 116 if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
117 if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { 117 if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
118 offset += dataSize; 118 offset += dataSize;
119 totalBytes += dataSize; 119 totalBytes += dataSize;
120 } else { 120 } else {
121 err = Z_ERRNO; 121 err = Z_ERRNO;
122 } 122 }
123 } else { 123 } else {
124 err = Z_ERRNO; 124 err = Z_ERRNO;
125 } 125 }
126 free(data); 126 free(data);
127 if (err != Z_OK) { 127 if (err != Z_OK) {
128 break; 128 break;
129 } 129 }
130 } else { 130 } else {
131 err = Z_MEM_ERROR; 131 err = Z_MEM_ERROR;
132 break; 132 break;
133 } 133 }
134 } 134 }
135 } 135 }
136 136
137 /* Central directory entry */ 137 /* Central directory entry */
138 { 138 {
139 char header[46]; 139 char header[46];
140 char* comment = ""; 140 char* comment = "";
141 int comsize = (int) strlen(comment); 141 int comsize = (int) strlen(comment);
142 WRITE_32(header, 0x02014b50); 142 WRITE_32(header, 0x02014b50);
143 WRITE_16(header + 4, version); 143 WRITE_16(header + 4, version);
144 WRITE_16(header + 6, version); 144 WRITE_16(header + 6, version);
145 WRITE_16(header + 8, gpflag); 145 WRITE_16(header + 8, gpflag);
146 WRITE_16(header + 10, method); 146 WRITE_16(header + 10, method);
147 WRITE_16(header + 12, filetime); 147 WRITE_16(header + 12, filetime);
148 WRITE_16(header + 14, filedate); 148 WRITE_16(header + 14, filedate);
149 WRITE_32(header + 16, crc); 149 WRITE_32(header + 16, crc);
150 WRITE_32(header + 20, cpsize); 150 WRITE_32(header + 20, cpsize);
151 WRITE_32(header + 24, uncpsize); 151 WRITE_32(header + 24, uncpsize);
152 WRITE_16(header + 28, fnsize); 152 WRITE_16(header + 28, fnsize);
153 WRITE_16(header + 30, extsize); 153 WRITE_16(header + 30, extsize);
154 WRITE_16(header + 32, comsize); 154 WRITE_16(header + 32, comsize);
155 WRITE_16(header + 34, 0); /* disk # */ 155 WRITE_16(header + 34, 0); /* disk # */
156 WRITE_16(header + 36, 0); /* int attrb */ 156 WRITE_16(header + 36, 0); /* int attrb */
157 WRITE_32(header + 38, 0); /* ext attrb */ 157 WRITE_32(header + 38, 0); /* ext attrb */
158 WRITE_32(header + 42, currentOffset); 158 WRITE_32(header + 42, currentOffset);
159 /* Header */ 159 /* Header */
160 if (fwrite(header, 1, 46, fpOutCD) == 46) { 160 if (fwrite(header, 1, 46, fpOutCD) == 46) {
161 offsetCD += 46; 161 offsetCD += 46;
162 162
163 /* Filename */ 163 /* Filename */
164 if (fnsize > 0) { 164 if (fnsize > 0) {
165 if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { 165 if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
166 offsetCD += fnsize; 166 offsetCD += fnsize;
167 } else { 167 } else {
168 err = Z_ERRNO; 168 err = Z_ERRNO;
169 break; 169 break;
170 } 170 }
171 } else { 171 } else {
172 err = Z_STREAM_ERROR; 172 err = Z_STREAM_ERROR;
173 break; 173 break;
174 } 174 }
175 175
176 /* Extra field */ 176 /* Extra field */
177 if (extsize > 0) { 177 if (extsize > 0) {
178 if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { 178 if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
179 offsetCD += extsize; 179 offsetCD += extsize;
180 } else { 180 } else {
181 err = Z_ERRNO; 181 err = Z_ERRNO;
182 break; 182 break;
183 } 183 }
184 } 184 }
185 185
186 /* Comment field */ 186 /* Comment field */
187 if (comsize > 0) { 187 if (comsize > 0) {
188 if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { 188 if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
189 offsetCD += comsize; 189 offsetCD += comsize;
190 } else { 190 } else {
191 err = Z_ERRNO; 191 err = Z_ERRNO;
192 break; 192 break;
193 } 193 }
194 } 194 }
195 195
196 196
197 } else { 197 } else {
198 err = Z_ERRNO; 198 err = Z_ERRNO;
199 break; 199 break;
200 } 200 }
201 } 201 }
202 202
203 /* Success */ 203 /* Success */
204 entries++; 204 entries++;
205 205
206 } else { 206 } else {
207 break; 207 break;
208 } 208 }
209 } 209 }
210 210
211 /* Final central directory */ 211 /* Final central directory */
212 { 212 {
213 int entriesZip = entries; 213 int entriesZip = entries;
214 char header[22]; 214 char header[22];
215 char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; 215 char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
216 int comsize = (int) strlen(comment); 216 int comsize = (int) strlen(comment);
217 if (entriesZip > 0xffff) { 217 if (entriesZip > 0xffff) {
218 entriesZip = 0xffff; 218 entriesZip = 0xffff;
219 } 219 }
220 WRITE_32(header, 0x06054b50); 220 WRITE_32(header, 0x06054b50);
221 WRITE_16(header + 4, 0); /* disk # */ 221 WRITE_16(header + 4, 0); /* disk # */
222 WRITE_16(header + 6, 0); /* disk # */ 222 WRITE_16(header + 6, 0); /* disk # */
223 WRITE_16(header + 8, entriesZip); /* hack */ 223 WRITE_16(header + 8, entriesZip); /* hack */
224 WRITE_16(header + 10, entriesZip); /* hack */ 224 WRITE_16(header + 10, entriesZip); /* hack */
225 WRITE_32(header + 12, offsetCD); /* size of CD */ 225 WRITE_32(header + 12, offsetCD); /* size of CD */
226 WRITE_32(header + 16, offset); /* offset to CD */ 226 WRITE_32(header + 16, offset); /* offset to CD */
227 WRITE_16(header + 20, comsize); /* comment */ 227 WRITE_16(header + 20, comsize); /* comment */
228 228
229 /* Header */ 229 /* Header */
230 if (fwrite(header, 1, 22, fpOutCD) == 22) { 230 if (fwrite(header, 1, 22, fpOutCD) == 22) {
231 231
232 /* Comment field */ 232 /* Comment field */
233 if (comsize > 0) { 233 if (comsize > 0) {
234 if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { 234 if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
235 err = Z_ERRNO; 235 err = Z_ERRNO;
236 } 236 }
237 } 237 }
238 238
239 } else { 239 } else {
240 err = Z_ERRNO; 240 err = Z_ERRNO;
241 } 241 }
242 } 242 }
243 243
244 /* Final merge (file + central directory) */ 244 /* Final merge (file + central directory) */
245 fclose(fpOutCD); 245 fclose(fpOutCD);
246 if (err == Z_OK) { 246 if (err == Z_OK) {
247 fpOutCD = fopen(fileOutTmp, "rb"); 247 fpOutCD = fopen(fileOutTmp, "rb");
248 if (fpOutCD != NULL) { 248 if (fpOutCD != NULL) {
249 int nRead; 249 int nRead;
250 char buffer[8192]; 250 char buffer[8192];
251 while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { 251 while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
252 if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { 252 if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
253 err = Z_ERRNO; 253 err = Z_ERRNO;
254 break; 254 break;
255 } 255 }
256 } 256 }
257 fclose(fpOutCD); 257 fclose(fpOutCD);
258 } 258 }
259 } 259 }
260 260
261 /* Close */ 261 /* Close */
262 fclose(fpZip); 262 fclose(fpZip);
263 fclose(fpOut); 263 fclose(fpOut);
264 264
265 /* Wipe temporary file */ 265 /* Wipe temporary file */
266 (void)remove(fileOutTmp); 266 (void)remove(fileOutTmp);
267 267
268 /* Number of recovered entries */ 268 /* Number of recovered entries */
269 if (err == Z_OK) { 269 if (err == Z_OK) {
270 if (nRecovered != NULL) { 270 if (nRecovered != NULL) {
271 *nRecovered = entries; 271 *nRecovered = entries;
272 } 272 }
273 if (bytesRecovered != NULL) { 273 if (bytesRecovered != NULL) {
274 *bytesRecovered = totalBytes; 274 *bytesRecovered = totalBytes;
275 } 275 }
276 } 276 }
277 } else { 277 } else {
278 err = Z_STREAM_ERROR; 278 err = Z_STREAM_ERROR;
279 } 279 }
280 return err; 280 return err;
281} 281}
diff --git a/contrib/minizip/mztools.h b/contrib/minizip/mztools.h
index eee78dc..82d1597 100644
--- a/contrib/minizip/mztools.h
+++ b/contrib/minizip/mztools.h
@@ -1,31 +1,31 @@
1/* 1/*
2 Additional tools for Minizip 2 Additional tools for Minizip
3 Code: Xavier Roche '2004 3 Code: Xavier Roche '2004
4 License: Same as ZLIB (www.gzip.org) 4 License: Same as ZLIB (www.gzip.org)
5*/ 5*/
6 6
7#ifndef _zip_tools_H 7#ifndef _zip_tools_H
8#define _zip_tools_H 8#define _zip_tools_H
9 9
10#ifdef __cplusplus 10#ifdef __cplusplus
11extern "C" { 11extern "C" {
12#endif 12#endif
13 13
14#ifndef _ZLIB_H 14#ifndef _ZLIB_H
15#include "zlib.h" 15#include "zlib.h"
16#endif 16#endif
17 17
18#include "unzip.h" 18#include "unzip.h"
19 19
20/* Repair a ZIP file (missing central directory) 20/* Repair a ZIP file (missing central directory)
21 file: file to recover 21 file: file to recover
22 fileOut: output file after recovery 22 fileOut: output file after recovery
23 fileOutTmp: temporary file name used for recovery 23 fileOutTmp: temporary file name used for recovery
24*/ 24*/
25extern int ZEXPORT unzRepair(const char* file, 25extern int ZEXPORT unzRepair(const char* file,
26 const char* fileOut, 26 const char* fileOut,
27 const char* fileOutTmp, 27 const char* fileOutTmp,
28 uLong* nRecovered, 28 uLong* nRecovered,
29 uLong* bytesRecovered); 29 uLong* bytesRecovered);
30 30
31#endif 31#endif
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index e115663..050d506 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -1,43 +1,75 @@
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, January 7th, 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 For more info read MiniZip_info.txt
14
15
16 ------------------------------------------------------------------------------------
17 Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
18 compatibility with older software. The following is from the original crypt.c.
19 Code woven in by Terry Thorsen 1/2003.
8 20
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. 21 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15 22
16 See the accompanying file LICENSE, version 2000-Apr-09 or later 23 See the accompanying file LICENSE, version 2000-Apr-09 or later
17 (the contents of which are also included in zip.h) for terms of use. 24 (the contents of which are also included in zip.h) for terms of use.
18 If, for some reason, all these files are missing, the Info-ZIP license 25 If, for some reason, all these files are missing, the Info-ZIP license
19 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 26 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/ 27
21/* 28 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
22 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
23 29
24 The encryption/decryption parts of this source code (as opposed to the 30 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The 31 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA. 32 whole source package can be freely distributed, including from the USA.
27 (Prior to January 2000, re-export from the US was a violation of US law.) 33 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */
29 34
30/* 35 This encryption code is a direct transcription of the algorithm from
31 This encryption code is a direct transcription of the algorithm from
32 Roger Schlafly, described by Phil Katz in the file appnote.txt. This 36 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
33 file (appnote.txt) is distributed with the PKZIP program (even in the 37 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities). 38 version without encryption capabilities).
35 */ 39
40 ------------------------------------------------------------------------------------
41
42 Changes in unzip64.c
43
44 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
45 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
46 2007-2008 - Even Rouault - Remove old C style function prototypes
47 2007-2008 - Even Rouault - Add unzip support for ZIP64
48
49 Copyright (C) 2007-2008 Even Rouault
50
51
52 Okt-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).
53 Okt-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
54 should only read the compressed/uncompressed size from the Zip64 format if
55 the size from normal header was 0xFFFFFFFF
56 Okt-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
57 Okt-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
58 Patch created by Daniel Borca
59
60 Copyright (C) 2009 Mathias Svensson
61
62*/
36 63
37 64
38#include <stdio.h> 65#include <stdio.h>
39#include <stdlib.h> 66#include <stdlib.h>
40#include <string.h> 67#include <string.h>
68
69#ifndef NOUNCRYPT
70 #define NOUNCRYPT
71#endif
72
41#include "zlib.h" 73#include "zlib.h"
42#include "unzip.h" 74#include "unzip.h"
43 75
@@ -85,16 +117,14 @@ woven in by Terry Thorsen 1/2003.
85#define SIZEZIPLOCALHEADER (0x1e) 117#define SIZEZIPLOCALHEADER (0x1e)
86 118
87 119
88
89
90const char unz_copyright[] = 120const char unz_copyright[] =
91 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; 121 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
92 122
93/* unz_file_info_interntal contain internal info about a file in zipfile*/ 123/* unz_file_info_interntal contain internal info about a file in zipfile*/
94typedef struct unz_file_info_internal_s 124typedef struct unz_file_info64_internal_s
95{ 125{
96 uLong offset_curfile;/* relative offset of local header 4 bytes */ 126 ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
97} unz_file_info_internal; 127} unz_file_info64_internal;
98 128
99 129
100/* file_in_zip_read_info_s contain internal information about a file in zipfile, 130/* file_in_zip_read_info_s contain internal information about a file in zipfile,
@@ -104,52 +134,61 @@ typedef struct
104 char *read_buffer; /* internal buffer for compressed data */ 134 char *read_buffer; /* internal buffer for compressed data */
105 z_stream stream; /* zLib stream structure for inflate */ 135 z_stream stream; /* zLib stream structure for inflate */
106 136
107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 137#ifdef HAVE_BZIP2
138 bz_stream bstream; /* bzLib stream structure for bziped */
139#endif
140
141 ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
108 uLong stream_initialised; /* flag set if stream structure is initialised*/ 142 uLong stream_initialised; /* flag set if stream structure is initialised*/
109 143
110 uLong offset_local_extrafield;/* offset of the local extra field */ 144 ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
111 uInt size_local_extrafield;/* size of the local extra field */ 145 uInt size_local_extrafield;/* size of the local extra field */
112 uLong pos_local_extrafield; /* position in the local extra field in read*/ 146 ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/
147 ZPOS64_T total_out_64;
113 148
114 uLong crc32; /* crc32 of all data uncompressed */ 149 uLong crc32; /* crc32 of all data uncompressed */
115 uLong crc32_wait; /* crc32 we must obtain after decompress all */ 150 uLong crc32_wait; /* crc32 we must obtain after decompress all */
116 uLong rest_read_compressed; /* number of byte to be decompressed */ 151 ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 152 ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
118 zlib_filefunc_def z_filefunc; 153 zlib_filefunc64_32_def z_filefunc;
119 voidpf filestream; /* io structore of the zipfile */ 154 voidpf filestream; /* io structore of the zipfile */
120 uLong compression_method; /* compression method (0==store) */ 155 uLong compression_method; /* compression method (0==store) */
121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 156 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
122 int raw; 157 int raw;
123} file_in_zip_read_info_s; 158} file_in_zip64_read_info_s;
124 159
125 160
126/* unz_s contain internal information about the zipfile 161/* unz64_s contain internal information about the zipfile
127*/ 162*/
128typedef struct 163typedef struct
129{ 164{
130 zlib_filefunc_def z_filefunc; 165 zlib_filefunc64_32_def z_filefunc;
166 int is64bitOpenFunction;
131 voidpf filestream; /* io structore of the zipfile */ 167 voidpf filestream; /* io structore of the zipfile */
132 unz_global_info gi; /* public global information */ 168 unz_global_info64 gi; /* public global information */
133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 169 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*/ 170 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*/ 171 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*/ 172 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*/ 173 ZPOS64_T central_pos; /* position of the beginning of the central dir*/
138 174
139 uLong size_central_dir; /* size of the central directory */ 175 ZPOS64_T size_central_dir; /* size of the central directory */
140 uLong offset_central_dir; /* offset of start of central directory with 176 ZPOS64_T offset_central_dir; /* offset of start of central directory with
141 respect to the starting disk number */ 177 respect to the starting disk number */
142 178
143 unz_file_info cur_file_info; /* public info about the current file in zip*/ 179 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*/ 180 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 181 file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
146 file if we are decompressing it */ 182 file if we are decompressing it */
147 int encrypted; 183 int encrypted;
184
185 int isZip64;
186
148# ifndef NOUNCRYPT 187# ifndef NOUNCRYPT
149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 188 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
150 const unsigned long* pcrc_32_tab; 189 const unsigned long* pcrc_32_tab;
151# endif 190# endif
152} unz_s; 191} unz64_s;
153 192
154 193
155#ifndef NOUNCRYPT 194#ifndef NOUNCRYPT
@@ -163,18 +202,15 @@ typedef struct
163*/ 202*/
164 203
165 204
166local int unzlocal_getByte OF(( 205local int unz64local_getByte OF((
167 const zlib_filefunc_def* pzlib_filefunc_def, 206 const zlib_filefunc64_32_def* pzlib_filefunc_def,
168 voidpf filestream, 207 voidpf filestream,
169 int *pi)); 208 int *pi));
170 209
171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) 210local 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{ 211{
176 unsigned char c; 212 unsigned char c;
177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 213 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
178 if (err==1) 214 if (err==1)
179 { 215 {
180 *pi = (int)c; 216 *pi = (int)c;
@@ -182,7 +218,7 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
182 } 218 }
183 else 219 else
184 { 220 {
185 if (ZERROR(*pzlib_filefunc_def,filestream)) 221 if (ZERROR64(*pzlib_filefunc_def,filestream))
186 return UNZ_ERRNO; 222 return UNZ_ERRNO;
187 else 223 else
188 return UNZ_EOF; 224 return UNZ_EOF;
@@ -193,26 +229,25 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
193/* =========================================================================== 229/* ===========================================================================
194 Reads a long in LSB order from the given gz_stream. Sets 230 Reads a long in LSB order from the given gz_stream. Sets
195*/ 231*/
196local int unzlocal_getShort OF(( 232local int unz64local_getShort OF((
197 const zlib_filefunc_def* pzlib_filefunc_def, 233 const zlib_filefunc64_32_def* pzlib_filefunc_def,
198 voidpf filestream, 234 voidpf filestream,
199 uLong *pX)); 235 uLong *pX));
200 236
201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) 237local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
202 const zlib_filefunc_def* pzlib_filefunc_def; 238 voidpf filestream,
203 voidpf filestream; 239 uLong *pX)
204 uLong *pX;
205{ 240{
206 uLong x ; 241 uLong x ;
207 int i; 242 int i = 0;
208 int err; 243 int err;
209 244
210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 245 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
211 x = (uLong)i; 246 x = (uLong)i;
212 247
213 if (err==UNZ_OK) 248 if (err==UNZ_OK)
214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 249 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
215 x += ((uLong)i)<<8; 250 x |= ((uLong)i)<<8;
216 251
217 if (err==UNZ_OK) 252 if (err==UNZ_OK)
218 *pX = x; 253 *pX = x;
@@ -221,33 +256,32 @@ local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
221 return err; 256 return err;
222} 257}
223 258
224local int unzlocal_getLong OF(( 259local int unz64local_getLong OF((
225 const zlib_filefunc_def* pzlib_filefunc_def, 260 const zlib_filefunc64_32_def* pzlib_filefunc_def,
226 voidpf filestream, 261 voidpf filestream,
227 uLong *pX)); 262 uLong *pX));
228 263
229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) 264local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
230 const zlib_filefunc_def* pzlib_filefunc_def; 265 voidpf filestream,
231 voidpf filestream; 266 uLong *pX)
232 uLong *pX;
233{ 267{
234 uLong x ; 268 uLong x ;
235 int i; 269 int i = 0;
236 int err; 270 int err;
237 271
238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 272 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
239 x = (uLong)i; 273 x = (uLong)i;
240 274
241 if (err==UNZ_OK) 275 if (err==UNZ_OK)
242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 276 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
243 x += ((uLong)i)<<8; 277 x |= ((uLong)i)<<8;
244 278
245 if (err==UNZ_OK) 279 if (err==UNZ_OK)
246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 280 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
247 x += ((uLong)i)<<16; 281 x |= ((uLong)i)<<16;
248 282
249 if (err==UNZ_OK) 283 if (err==UNZ_OK)
250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 284 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
251 x += ((uLong)i)<<24; 285 x += ((uLong)i)<<24;
252 286
253 if (err==UNZ_OK) 287 if (err==UNZ_OK)
@@ -257,11 +291,60 @@ local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
257 return err; 291 return err;
258} 292}
259 293
294local int unz64local_getLong64 OF((
295 const zlib_filefunc64_32_def* pzlib_filefunc_def,
296 voidpf filestream,
297 ZPOS64_T *pX));
298
299
300local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
301 voidpf filestream,
302 ZPOS64_T *pX)
303{
304 ZPOS64_T x ;
305 int i = 0;
306 int err;
307
308 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
309 x = (ZPOS64_T)i;
310
311 if (err==UNZ_OK)
312 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
313 x |= ((ZPOS64_T)i)<<8;
314
315 if (err==UNZ_OK)
316 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
317 x |= ((ZPOS64_T)i)<<16;
318
319 if (err==UNZ_OK)
320 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
321 x |= ((ZPOS64_T)i)<<24;
322
323 if (err==UNZ_OK)
324 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
325 x |= ((ZPOS64_T)i)<<32;
326
327 if (err==UNZ_OK)
328 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
329 x |= ((ZPOS64_T)i)<<40;
330
331 if (err==UNZ_OK)
332 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
333 x |= ((ZPOS64_T)i)<<48;
334
335 if (err==UNZ_OK)
336 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
337 x |= ((ZPOS64_T)i)<<56;
338
339 if (err==UNZ_OK)
340 *pX = x;
341 else
342 *pX = 0;
343 return err;
344}
260 345
261/* My own strcmpi / strcasecmp */ 346/* My own strcmpi / strcasecmp */
262local int strcmpcasenosensitive_internal (fileName1,fileName2) 347local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
263 const char* fileName1;
264 const char* fileName2;
265{ 348{
266 for (;;) 349 for (;;)
267 { 350 {
@@ -302,10 +385,10 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
302 (like 1 on Unix, 2 on Windows) 385 (like 1 on Unix, 2 on Windows)
303 386
304*/ 387*/
305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) 388extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
306 const char* fileName1; 389 const char* fileName2,
307 const char* fileName2; 390 int iCaseSensitivity)
308 int iCaseSensitivity; 391
309{ 392{
310 if (iCaseSensitivity==0) 393 if (iCaseSensitivity==0)
311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 394 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
@@ -324,25 +407,20 @@ extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivit
324 Locate the Central directory of a zipfile (at the end, just before 407 Locate the Central directory of a zipfile (at the end, just before
325 the global comment) 408 the global comment)
326*/ 409*/
327local uLong unzlocal_SearchCentralDir OF(( 410local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
328 const zlib_filefunc_def* pzlib_filefunc_def, 411local 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{ 412{
335 unsigned char* buf; 413 unsigned char* buf;
336 uLong uSizeFile; 414 ZPOS64_T uSizeFile;
337 uLong uBackRead; 415 ZPOS64_T uBackRead;
338 uLong uMaxBack=0xffff; /* maximum size of global comment */ 416 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
339 uLong uPosFound=0; 417 ZPOS64_T uPosFound=0;
340 418
341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 419 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
342 return 0; 420 return 0;
343 421
344 422
345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 423 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
346 424
347 if (uMaxBack>uSizeFile) 425 if (uMaxBack>uSizeFile)
348 uMaxBack = uSizeFile; 426 uMaxBack = uSizeFile;
@@ -354,7 +432,8 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
354 uBackRead = 4; 432 uBackRead = 4;
355 while (uBackRead<uMaxBack) 433 while (uBackRead<uMaxBack)
356 { 434 {
357 uLong uReadSize,uReadPos ; 435 uLong uReadSize;
436 ZPOS64_T uReadPos ;
358 int i; 437 int i;
359 if (uBackRead+BUFREADCOMMENT>uMaxBack) 438 if (uBackRead+BUFREADCOMMENT>uMaxBack)
360 uBackRead = uMaxBack; 439 uBackRead = uMaxBack;
@@ -363,11 +442,11 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
363 uReadPos = uSizeFile-uBackRead ; 442 uReadPos = uSizeFile-uBackRead ;
364 443
365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 444 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 445 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 446 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
368 break; 447 break;
369 448
370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 449 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
371 break; 450 break;
372 451
373 for (i=(int)uReadSize-3; (i--)>0;) 452 for (i=(int)uReadSize-3; (i--)>0;)
@@ -385,6 +464,112 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
385 return uPosFound; 464 return uPosFound;
386} 465}
387 466
467
468/*
469 Locate the Central directory 64 of a zipfile (at the end, just before
470 the global comment)
471*/
472local ZPOS64_T unz64local_SearchCentralDir64 OF((
473 const zlib_filefunc64_32_def* pzlib_filefunc_def,
474 voidpf filestream));
475
476local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
477 voidpf filestream)
478{
479 unsigned char* buf;
480 ZPOS64_T uSizeFile;
481 ZPOS64_T uBackRead;
482 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
483 ZPOS64_T uPosFound=0;
484 uLong uL;
485 ZPOS64_T relativeOffset;
486
487 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
488 return 0;
489
490
491 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
492
493 if (uMaxBack>uSizeFile)
494 uMaxBack = uSizeFile;
495
496 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
497 if (buf==NULL)
498 return 0;
499
500 uBackRead = 4;
501 while (uBackRead<uMaxBack)
502 {
503 uLong uReadSize;
504 ZPOS64_T uReadPos;
505 int i;
506 if (uBackRead+BUFREADCOMMENT>uMaxBack)
507 uBackRead = uMaxBack;
508 else
509 uBackRead+=BUFREADCOMMENT;
510 uReadPos = uSizeFile-uBackRead ;
511
512 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
513 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
514 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
515 break;
516
517 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
518 break;
519
520 for (i=(int)uReadSize-3; (i--)>0;)
521 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
522 ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
523 {
524 uPosFound = uReadPos+i;
525 break;
526 }
527
528 if (uPosFound!=0)
529 break;
530 }
531 TRYFREE(buf);
532 if (uPosFound == 0)
533 return 0;
534
535 /* Zip64 end of central directory locator */
536 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
537 return 0;
538
539 /* the signature, already checked */
540 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
541 return 0;
542
543 /* number of the disk with the start of the zip64 end of central directory */
544 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
545 return 0;
546 if (uL != 0)
547 return 0;
548
549 /* relative offset of the zip64 end of central directory record */
550 if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
551 return 0;
552
553 /* total number of disks */
554 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
555 return 0;
556 if (uL != 1)
557 return 0;
558
559 /* Goto end of central directory record */
560 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
561 return 0;
562
563 /* the signature */
564 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
565 return 0;
566
567 if (uL != 0x06064b50)
568 return 0;
569
570 return relativeOffset;
571}
572
388/* 573/*
389 Open a Zip file. path contain the full pathname (by example, 574 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 575 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
@@ -394,19 +579,20 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
394 Else, the return value is a unzFile Handle, usable with other function 579 Else, the return value is a unzFile Handle, usable with other function
395 of this unzip package. 580 of this unzip package.
396*/ 581*/
397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) 582local unzFile unzOpenInternal (const void *path,
398 const char *path; 583 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
399 zlib_filefunc_def* pzlib_filefunc_def; 584 int is64bitOpenFunction)
400{ 585{
401 unz_s us; 586 unz64_s us;
402 unz_s *s; 587 unz64_s *s;
403 uLong central_pos,uL; 588 ZPOS64_T central_pos;
589 uLong uL;
404 590
405 uLong number_disk; /* number of the current dist, used for 591 uLong number_disk; /* number of the current dist, used for
406 spaning ZIP, unsupported, always 0*/ 592 spaning ZIP, unsupported, always 0*/
407 uLong number_disk_with_CD; /* number the the disk with central dir, used 593 uLong number_disk_with_CD; /* number the the disk with central dir, used
408 for spaning ZIP, unsupported, always 0*/ 594 for spaning ZIP, unsupported, always 0*/
409 uLong number_entry_CD; /* total number of entries in 595 ZPOS64_T number_entry_CD; /* total number of entries in
410 the central dir 596 the central dir
411 (same than number_entry on nospan) */ 597 (same than number_entry on nospan) */
412 598
@@ -415,63 +601,137 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
415 if (unz_copyright[0]!=' ') 601 if (unz_copyright[0]!=' ')
416 return NULL; 602 return NULL;
417 603
418 if (pzlib_filefunc_def==NULL) 604 us.z_filefunc.zseek32_file = NULL;
419 fill_fopen_filefunc(&us.z_filefunc); 605 us.z_filefunc.ztell32_file = NULL;
606 if (pzlib_filefunc64_32_def==NULL)
607 fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
420 else 608 else
421 us.z_filefunc = *pzlib_filefunc_def; 609 us.z_filefunc = *pzlib_filefunc64_32_def;
610 us.is64bitOpenFunction = is64bitOpenFunction;
611
612
422 613
423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, 614 us.filestream = ZOPEN64(us.z_filefunc,
424 path, 615 path,
425 ZLIB_FILEFUNC_MODE_READ | 616 ZLIB_FILEFUNC_MODE_READ |
426 ZLIB_FILEFUNC_MODE_EXISTING); 617 ZLIB_FILEFUNC_MODE_EXISTING);
427 if (us.filestream==NULL) 618 if (us.filestream==NULL)
428 return NULL; 619 return NULL;
429 620
430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); 621 central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
431 if (central_pos==0) 622 if (central_pos)
432 err=UNZ_ERRNO; 623 {
624 uLong uS;
625 ZPOS64_T uL64;
626
627 us.isZip64 = 1;
433 628
434 if (ZSEEK(us.z_filefunc, us.filestream, 629 if (ZSEEK64(us.z_filefunc, us.filestream,
435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 630 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
436 err=UNZ_ERRNO; 631 err=UNZ_ERRNO;
437 632
438 /* the signature, already checked */ 633 /* the signature, already checked */
439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 634 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
440 err=UNZ_ERRNO; 635 err=UNZ_ERRNO;
441 636
442 /* number of this disk */ 637 /* size of zip64 end of central directory record */
443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 638 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
444 err=UNZ_ERRNO; 639 err=UNZ_ERRNO;
445 640
446 /* number of the disk with the start of the central directory */ 641 /* version made by */
447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 642 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
448 err=UNZ_ERRNO; 643 err=UNZ_ERRNO;
449 644
450 /* total number of entries in the central dir on this disk */ 645 /* version needed to extract */
451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) 646 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
452 err=UNZ_ERRNO; 647 err=UNZ_ERRNO;
453 648
454 /* total number of entries in the central dir */ 649 /* number of this disk */
455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) 650 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
456 err=UNZ_ERRNO; 651 err=UNZ_ERRNO;
457 652
458 if ((number_entry_CD!=us.gi.number_entry) || 653 /* number of the disk with the start of the central directory */
459 (number_disk_with_CD!=0) || 654 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
460 (number_disk!=0)) 655 err=UNZ_ERRNO;
461 err=UNZ_BADZIPFILE;
462 656
463 /* size of the central directory */ 657 /* 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) 658 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
465 err=UNZ_ERRNO; 659 err=UNZ_ERRNO;
660
661 /* total number of entries in the central directory */
662 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
663 err=UNZ_ERRNO;
664
665 if ((number_entry_CD!=us.gi.number_entry) ||
666 (number_disk_with_CD!=0) ||
667 (number_disk!=0))
668 err=UNZ_BADZIPFILE;
669
670 /* size of the central directory */
671 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
672 err=UNZ_ERRNO;
466 673
467 /* offset of start of central directory with respect to the 674 /* offset of start of central directory with respect to the
468 starting disk number */ 675 starting disk number */
469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) 676 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
470 err=UNZ_ERRNO; 677 err=UNZ_ERRNO;
471 678
472 /* zipfile comment length */ 679 us.gi.size_comment = 0;
473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) 680 }
474 err=UNZ_ERRNO; 681 else
682 {
683 central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
684 if (central_pos==0)
685 err=UNZ_ERRNO;
686
687 us.isZip64 = 0;
688
689 if (ZSEEK64(us.z_filefunc, us.filestream,
690 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
691 err=UNZ_ERRNO;
692
693 /* the signature, already checked */
694 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
695 err=UNZ_ERRNO;
696
697 /* number of this disk */
698 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
699 err=UNZ_ERRNO;
700
701 /* number of the disk with the start of the central directory */
702 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
703 err=UNZ_ERRNO;
704
705 /* total number of entries in the central dir on this disk */
706 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
707 err=UNZ_ERRNO;
708 us.gi.number_entry = uL;
709
710 /* total number of entries in the central dir */
711 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
712 err=UNZ_ERRNO;
713 number_entry_CD = uL;
714
715 if ((number_entry_CD!=us.gi.number_entry) ||
716 (number_disk_with_CD!=0) ||
717 (number_disk!=0))
718 err=UNZ_BADZIPFILE;
719
720 /* size of the central directory */
721 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
722 err=UNZ_ERRNO;
723 us.size_central_dir = uL;
724
725 /* offset of start of central directory with respect to the
726 starting disk number */
727 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
728 err=UNZ_ERRNO;
729 us.offset_central_dir = uL;
730
731 /* zipfile comment length */
732 if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
733 err=UNZ_ERRNO;
734 }
475 735
476 if ((central_pos<us.offset_central_dir+us.size_central_dir) && 736 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
477 (err==UNZ_OK)) 737 (err==UNZ_OK))
@@ -479,7 +739,7 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
479 739
480 if (err!=UNZ_OK) 740 if (err!=UNZ_OK)
481 { 741 {
482 ZCLOSE(us.z_filefunc, us.filestream); 742 ZCLOSE64(us.z_filefunc, us.filestream);
483 return NULL; 743 return NULL;
484 } 744 }
485 745
@@ -490,17 +750,52 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
490 us.encrypted = 0; 750 us.encrypted = 0;
491 751
492 752
493 s=(unz_s*)ALLOC(sizeof(unz_s)); 753 s=(unz64_s*)ALLOC(sizeof(unz64_s));
494 *s=us; 754 if( s != NULL)
495 unzGoToFirstFile((unzFile)s); 755 {
756 *s=us;
757 unzGoToFirstFile((unzFile)s);
758 }
496 return (unzFile)s; 759 return (unzFile)s;
497} 760}
498 761
499 762
500extern unzFile ZEXPORT unzOpen (path) 763extern unzFile ZEXPORT unzOpen2 (const char *path,
501 const char *path; 764 zlib_filefunc_def* pzlib_filefunc32_def)
502{ 765{
503 return unzOpen2(path, NULL); 766 if (pzlib_filefunc32_def != NULL)
767 {
768 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
769 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
770 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
771 }
772 else
773 return unzOpenInternal(path, NULL, 0);
774}
775
776extern unzFile ZEXPORT unzOpen2_64 (const void *path,
777 zlib_filefunc64_def* pzlib_filefunc_def)
778{
779 if (pzlib_filefunc_def != NULL)
780 {
781 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
782 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
783 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
784 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
785 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
786 }
787 else
788 return unzOpenInternal(path, NULL, 1);
789}
790
791extern unzFile ZEXPORT unzOpen (const char *path)
792{
793 return unzOpenInternal(path, NULL, 0);
794}
795
796extern unzFile ZEXPORT unzOpen64 (const void *path)
797{
798 return unzOpenInternal(path, NULL, 1);
504} 799}
505 800
506/* 801/*
@@ -508,18 +803,17 @@ extern unzFile ZEXPORT unzOpen (path)
508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), 803 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 804 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
510 return UNZ_OK if there is no problem. */ 805 return UNZ_OK if there is no problem. */
511extern int ZEXPORT unzClose (file) 806extern int ZEXPORT unzClose (unzFile file)
512 unzFile file;
513{ 807{
514 unz_s* s; 808 unz64_s* s;
515 if (file==NULL) 809 if (file==NULL)
516 return UNZ_PARAMERROR; 810 return UNZ_PARAMERROR;
517 s=(unz_s*)file; 811 s=(unz64_s*)file;
518 812
519 if (s->pfile_in_zip_read!=NULL) 813 if (s->pfile_in_zip_read!=NULL)
520 unzCloseCurrentFile(file); 814 unzCloseCurrentFile(file);
521 815
522 ZCLOSE(s->z_filefunc, s->filestream); 816 ZCLOSE64(s->z_filefunc, s->filestream);
523 TRYFREE(s); 817 TRYFREE(s);
524 return UNZ_OK; 818 return UNZ_OK;
525} 819}
@@ -529,28 +823,34 @@ extern int ZEXPORT unzClose (file)
529 Write info about the ZipFile in the *pglobal_info structure. 823 Write info about the ZipFile in the *pglobal_info structure.
530 No preparation of the structure is needed 824 No preparation of the structure is needed
531 return UNZ_OK if there is no problem. */ 825 return UNZ_OK if there is no problem. */
532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) 826extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
533 unzFile file;
534 unz_global_info *pglobal_info;
535{ 827{
536 unz_s* s; 828 unz64_s* s;
537 if (file==NULL) 829 if (file==NULL)
538 return UNZ_PARAMERROR; 830 return UNZ_PARAMERROR;
539 s=(unz_s*)file; 831 s=(unz64_s*)file;
540 *pglobal_info=s->gi; 832 *pglobal_info=s->gi;
541 return UNZ_OK; 833 return UNZ_OK;
542} 834}
543 835
544 836extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
837{
838 unz64_s* s;
839 if (file==NULL)
840 return UNZ_PARAMERROR;
841 s=(unz64_s*)file;
842 /* to do : check if number_entry is not truncated */
843 pglobal_info32->number_entry = (uLong)s->gi.number_entry;
844 pglobal_info32->size_comment = s->gi.size_comment;
845 return UNZ_OK;
846}
545/* 847/*
546 Translate date/time from Dos format to tm_unz (readable more easilty) 848 Translate date/time from Dos format to tm_unz (readable more easilty)
547*/ 849*/
548local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) 850local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
549 uLong ulDosDate;
550 tm_unz* ptm;
551{ 851{
552 uLong uDate; 852 ZPOS64_T uDate;
553 uDate = (uLong)(ulDosDate>>16); 853 uDate = (ZPOS64_T)(ulDosDate>>16);
554 ptm->tm_mday = (uInt)(uDate&0x1f) ; 854 ptm->tm_mday = (uInt)(uDate&0x1f) ;
555 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; 855 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
556 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; 856 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
@@ -563,9 +863,9 @@ local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
563/* 863/*
564 Get Info about the current file in the zipfile, with internal only info 864 Get Info about the current file in the zipfile, with internal only info
565*/ 865*/
566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, 866local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
567 unz_file_info *pfile_info, 867 unz_file_info64 *pfile_info,
568 unz_file_info_internal 868 unz_file_info64_internal
569 *pfile_info_internal, 869 *pfile_info_internal,
570 char *szFileName, 870 char *szFileName,
571 uLong fileNameBufferSize, 871 uLong fileNameBufferSize,
@@ -574,33 +874,29 @@ local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
574 char *szComment, 874 char *szComment,
575 uLong commentBufferSize)); 875 uLong commentBufferSize));
576 876
577local int unzlocal_GetCurrentFileInfoInternal (file, 877local int unz64local_GetCurrentFileInfoInternal (unzFile file,
578 pfile_info, 878 unz_file_info64 *pfile_info,
579 pfile_info_internal, 879 unz_file_info64_internal
580 szFileName, fileNameBufferSize, 880 *pfile_info_internal,
581 extraField, extraFieldBufferSize, 881 char *szFileName,
582 szComment, commentBufferSize) 882 uLong fileNameBufferSize,
583 unzFile file; 883 void *extraField,
584 unz_file_info *pfile_info; 884 uLong extraFieldBufferSize,
585 unz_file_info_internal *pfile_info_internal; 885 char *szComment,
586 char *szFileName; 886 uLong commentBufferSize)
587 uLong fileNameBufferSize;
588 void *extraField;
589 uLong extraFieldBufferSize;
590 char *szComment;
591 uLong commentBufferSize;
592{ 887{
593 unz_s* s; 888 unz64_s* s;
594 unz_file_info file_info; 889 unz_file_info64 file_info;
595 unz_file_info_internal file_info_internal; 890 unz_file_info64_internal file_info_internal;
596 int err=UNZ_OK; 891 int err=UNZ_OK;
597 uLong uMagic; 892 uLong uMagic;
598 long lSeek=0; 893 long lSeek=0;
894 uLong uL;
599 895
600 if (file==NULL) 896 if (file==NULL)
601 return UNZ_PARAMERROR; 897 return UNZ_PARAMERROR;
602 s=(unz_s*)file; 898 s=(unz64_s*)file;
603 if (ZSEEK(s->z_filefunc, s->filestream, 899 if (ZSEEK64(s->z_filefunc, s->filestream,
604 s->pos_in_central_dir+s->byte_before_the_zipfile, 900 s->pos_in_central_dir+s->byte_before_the_zipfile,
605 ZLIB_FILEFUNC_SEEK_SET)!=0) 901 ZLIB_FILEFUNC_SEEK_SET)!=0)
606 err=UNZ_ERRNO; 902 err=UNZ_ERRNO;
@@ -608,57 +904,63 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
608 904
609 /* we check the magic */ 905 /* we check the magic */
610 if (err==UNZ_OK) 906 if (err==UNZ_OK)
611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 907 {
908 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
612 err=UNZ_ERRNO; 909 err=UNZ_ERRNO;
613 else if (uMagic!=0x02014b50) 910 else if (uMagic!=0x02014b50)
614 err=UNZ_BADZIPFILE; 911 err=UNZ_BADZIPFILE;
912 }
615 913
616 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) 914 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
617 err=UNZ_ERRNO; 915 err=UNZ_ERRNO;
618 916
619 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) 917 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
620 err=UNZ_ERRNO; 918 err=UNZ_ERRNO;
621 919
622 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) 920 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
623 err=UNZ_ERRNO; 921 err=UNZ_ERRNO;
624 922
625 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) 923 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
626 err=UNZ_ERRNO; 924 err=UNZ_ERRNO;
627 925
628 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) 926 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
629 err=UNZ_ERRNO; 927 err=UNZ_ERRNO;
630 928
631 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 929 unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
632 930
633 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) 931 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
634 err=UNZ_ERRNO; 932 err=UNZ_ERRNO;
635 933
636 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) 934 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
637 err=UNZ_ERRNO; 935 err=UNZ_ERRNO;
936 file_info.compressed_size = uL;
638 937
639 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) 938 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
640 err=UNZ_ERRNO; 939 err=UNZ_ERRNO;
940 file_info.uncompressed_size = uL;
641 941
642 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) 942 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
643 err=UNZ_ERRNO; 943 err=UNZ_ERRNO;
644 944
645 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) 945 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
646 err=UNZ_ERRNO; 946 err=UNZ_ERRNO;
647 947
648 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) 948 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
649 err=UNZ_ERRNO; 949 err=UNZ_ERRNO;
650 950
651 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) 951 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
652 err=UNZ_ERRNO; 952 err=UNZ_ERRNO;
653 953
654 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) 954 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
655 err=UNZ_ERRNO; 955 err=UNZ_ERRNO;
656 956
657 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) 957 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
658 err=UNZ_ERRNO; 958 err=UNZ_ERRNO;
659 959
660 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) 960 // relative offset of local header
961 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
661 err=UNZ_ERRNO; 962 err=UNZ_ERRNO;
963 file_info_internal.offset_curfile = uL;
662 964
663 lSeek+=file_info.size_filename; 965 lSeek+=file_info.size_filename;
664 if ((err==UNZ_OK) && (szFileName!=NULL)) 966 if ((err==UNZ_OK) && (szFileName!=NULL))
@@ -673,33 +975,105 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
673 uSizeRead = fileNameBufferSize; 975 uSizeRead = fileNameBufferSize;
674 976
675 if ((file_info.size_filename>0) && (fileNameBufferSize>0)) 977 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
676 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) 978 if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
677 err=UNZ_ERRNO; 979 err=UNZ_ERRNO;
678 lSeek -= uSizeRead; 980 lSeek -= uSizeRead;
679 } 981 }
680 982
681 983 // Read extrafield
682 if ((err==UNZ_OK) && (extraField!=NULL)) 984 if ((err==UNZ_OK) && (extraField!=NULL))
683 { 985 {
684 uLong uSizeRead ; 986 ZPOS64_T uSizeRead ;
685 if (file_info.size_file_extra<extraFieldBufferSize) 987 if (file_info.size_file_extra<extraFieldBufferSize)
686 uSizeRead = file_info.size_file_extra; 988 uSizeRead = file_info.size_file_extra;
687 else 989 else
688 uSizeRead = extraFieldBufferSize; 990 uSizeRead = extraFieldBufferSize;
689 991
690 if (lSeek!=0) 992 if (lSeek!=0)
691 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 993 {
994 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
692 lSeek=0; 995 lSeek=0;
693 else 996 else
694 err=UNZ_ERRNO; 997 err=UNZ_ERRNO;
998 }
999
695 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 1000 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
696 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) 1001 if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
697 err=UNZ_ERRNO; 1002 err=UNZ_ERRNO;
698 lSeek += file_info.size_file_extra - uSizeRead; 1003
1004 lSeek += file_info.size_file_extra - (uLong)uSizeRead;
699 } 1005 }
700 else 1006 else
701 lSeek+=file_info.size_file_extra; 1007 lSeek += file_info.size_file_extra;
1008
1009
1010 if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
1011 {
1012 uLong acc = 0;
1013
1014 // since lSeek now points to after the extra field we need to move back
1015 lSeek -= file_info.size_file_extra;
1016
1017 if (lSeek!=0)
1018 {
1019 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1020 lSeek=0;
1021 else
1022 err=UNZ_ERRNO;
1023 }
1024
1025 while(acc < file_info.size_file_extra)
1026 {
1027 uLong headerId;
1028 uLong dataSize;
702 1029
1030 if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
1031 err=UNZ_ERRNO;
1032
1033 if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
1034 err=UNZ_ERRNO;
1035
1036 /* ZIP64 extra fields */
1037 if (headerId == 0x0001)
1038 {
1039 uLong uL;
1040
1041 if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1)
1042 {
1043 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1044 err=UNZ_ERRNO;
1045 }
1046
1047 if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1)
1048 {
1049 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1050 err=UNZ_ERRNO;
1051 }
1052
1053 if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1)
1054 {
1055 /* Relative Header offset */
1056 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1057 err=UNZ_ERRNO;
1058 }
1059
1060 if(file_info.disk_num_start == (unsigned long)-1)
1061 {
1062 /* Disk Start Number */
1063 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1064 err=UNZ_ERRNO;
1065 }
1066
1067 }
1068 else
1069 {
1070 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
1071 err=UNZ_ERRNO;
1072 }
1073
1074 acc += 2 + 2 + dataSize;
1075 }
1076 }
703 1077
704 if ((err==UNZ_OK) && (szComment!=NULL)) 1078 if ((err==UNZ_OK) && (szComment!=NULL))
705 { 1079 {
@@ -713,18 +1087,22 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
713 uSizeRead = commentBufferSize; 1087 uSizeRead = commentBufferSize;
714 1088
715 if (lSeek!=0) 1089 if (lSeek!=0)
716 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1090 {
1091 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
717 lSeek=0; 1092 lSeek=0;
718 else 1093 else
719 err=UNZ_ERRNO; 1094 err=UNZ_ERRNO;
1095 }
1096
720 if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 1097 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
721 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) 1098 if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
722 err=UNZ_ERRNO; 1099 err=UNZ_ERRNO;
723 lSeek+=file_info.size_file_comment - uSizeRead; 1100 lSeek+=file_info.size_file_comment - uSizeRead;
724 } 1101 }
725 else 1102 else
726 lSeek+=file_info.size_file_comment; 1103 lSeek+=file_info.size_file_comment;
727 1104
1105
728 if ((err==UNZ_OK) && (pfile_info!=NULL)) 1106 if ((err==UNZ_OK) && (pfile_info!=NULL))
729 *pfile_info=file_info; 1107 *pfile_info=file_info;
730 1108
@@ -741,41 +1119,70 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
741 No preparation of the structure is needed 1119 No preparation of the structure is needed
742 return UNZ_OK if there is no problem. 1120 return UNZ_OK if there is no problem.
743*/ 1121*/
744extern int ZEXPORT unzGetCurrentFileInfo (file, 1122extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
745 pfile_info, 1123 unz_file_info64 * pfile_info,
746 szFileName, fileNameBufferSize, 1124 char * szFileName, uLong fileNameBufferSize,
747 extraField, extraFieldBufferSize, 1125 void *extraField, uLong extraFieldBufferSize,
748 szComment, commentBufferSize) 1126 char* szComment, uLong commentBufferSize)
749 unzFile file;
750 unz_file_info *pfile_info;
751 char *szFileName;
752 uLong fileNameBufferSize;
753 void *extraField;
754 uLong extraFieldBufferSize;
755 char *szComment;
756 uLong commentBufferSize;
757{ 1127{
758 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, 1128 return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
759 szFileName,fileNameBufferSize, 1129 szFileName,fileNameBufferSize,
760 extraField,extraFieldBufferSize, 1130 extraField,extraFieldBufferSize,
761 szComment,commentBufferSize); 1131 szComment,commentBufferSize);
762} 1132}
763 1133
1134extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
1135 unz_file_info * pfile_info,
1136 char * szFileName, uLong fileNameBufferSize,
1137 void *extraField, uLong extraFieldBufferSize,
1138 char* szComment, uLong commentBufferSize)
1139{
1140 int err;
1141 unz_file_info64 file_info64;
1142 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
1143 szFileName,fileNameBufferSize,
1144 extraField,extraFieldBufferSize,
1145 szComment,commentBufferSize);
1146 if (err==UNZ_OK)
1147 {
1148 pfile_info->version = file_info64.version;
1149 pfile_info->version_needed = file_info64.version_needed;
1150 pfile_info->flag = file_info64.flag;
1151 pfile_info->compression_method = file_info64.compression_method;
1152 pfile_info->dosDate = file_info64.dosDate;
1153 pfile_info->crc = file_info64.crc;
1154
1155 pfile_info->size_filename = file_info64.size_filename;
1156 pfile_info->size_file_extra = file_info64.size_file_extra;
1157 pfile_info->size_file_comment = file_info64.size_file_comment;
1158
1159 pfile_info->disk_num_start = file_info64.disk_num_start;
1160 pfile_info->internal_fa = file_info64.internal_fa;
1161 pfile_info->external_fa = file_info64.external_fa;
1162
1163 pfile_info->tmu_date = file_info64.tmu_date,
1164
1165
1166 pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1167 pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1168
1169 }
1170 return err;
1171}
764/* 1172/*
765 Set the current file of the zipfile to the first file. 1173 Set the current file of the zipfile to the first file.
766 return UNZ_OK if there is no problem 1174 return UNZ_OK if there is no problem
767*/ 1175*/
768extern int ZEXPORT unzGoToFirstFile (file) 1176extern int ZEXPORT unzGoToFirstFile (unzFile file)
769 unzFile file;
770{ 1177{
771 int err=UNZ_OK; 1178 int err=UNZ_OK;
772 unz_s* s; 1179 unz64_s* s;
773 if (file==NULL) 1180 if (file==NULL)
774 return UNZ_PARAMERROR; 1181 return UNZ_PARAMERROR;
775 s=(unz_s*)file; 1182 s=(unz64_s*)file;
776 s->pos_in_central_dir=s->offset_central_dir; 1183 s->pos_in_central_dir=s->offset_central_dir;
777 s->num_file=0; 1184 s->num_file=0;
778 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1185 err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
779 &s->cur_file_info_internal, 1186 &s->cur_file_info_internal,
780 NULL,0,NULL,0,NULL,0); 1187 NULL,0,NULL,0,NULL,0);
781 s->current_file_ok = (err == UNZ_OK); 1188 s->current_file_ok = (err == UNZ_OK);
@@ -787,15 +1194,14 @@ extern int ZEXPORT unzGoToFirstFile (file)
787 return UNZ_OK if there is no problem 1194 return UNZ_OK if there is no problem
788 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 1195 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
789*/ 1196*/
790extern int ZEXPORT unzGoToNextFile (file) 1197extern int ZEXPORT unzGoToNextFile (unzFile file)
791 unzFile file;
792{ 1198{
793 unz_s* s; 1199 unz64_s* s;
794 int err; 1200 int err;
795 1201
796 if (file==NULL) 1202 if (file==NULL)
797 return UNZ_PARAMERROR; 1203 return UNZ_PARAMERROR;
798 s=(unz_s*)file; 1204 s=(unz64_s*)file;
799 if (!s->current_file_ok) 1205 if (!s->current_file_ok)
800 return UNZ_END_OF_LIST_OF_FILE; 1206 return UNZ_END_OF_LIST_OF_FILE;
801 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ 1207 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
@@ -805,7 +1211,7 @@ extern int ZEXPORT unzGoToNextFile (file)
805 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 1211 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
806 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; 1212 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
807 s->num_file++; 1213 s->num_file++;
808 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1214 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
809 &s->cur_file_info_internal, 1215 &s->cur_file_info_internal,
810 NULL,0,NULL,0,NULL,0); 1216 NULL,0,NULL,0,NULL,0);
811 s->current_file_ok = (err == UNZ_OK); 1217 s->current_file_ok = (err == UNZ_OK);
@@ -821,21 +1227,18 @@ extern int ZEXPORT unzGoToNextFile (file)
821 UNZ_OK if the file is found. It becomes the current file. 1227 UNZ_OK if the file is found. It becomes the current file.
822 UNZ_END_OF_LIST_OF_FILE if the file is not found 1228 UNZ_END_OF_LIST_OF_FILE if the file is not found
823*/ 1229*/
824extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) 1230extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
825 unzFile file;
826 const char *szFileName;
827 int iCaseSensitivity;
828{ 1231{
829 unz_s* s; 1232 unz64_s* s;
830 int err; 1233 int err;
831 1234
832 /* We remember the 'current' position in the file so that we can jump 1235 /* We remember the 'current' position in the file so that we can jump
833 * back there if we fail. 1236 * back there if we fail.
834 */ 1237 */
835 unz_file_info cur_file_infoSaved; 1238 unz_file_info64 cur_file_infoSaved;
836 unz_file_info_internal cur_file_info_internalSaved; 1239 unz_file_info64_internal cur_file_info_internalSaved;
837 uLong num_fileSaved; 1240 ZPOS64_T num_fileSaved;
838 uLong pos_in_central_dirSaved; 1241 ZPOS64_T pos_in_central_dirSaved;
839 1242
840 1243
841 if (file==NULL) 1244 if (file==NULL)
@@ -844,7 +1247,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
844 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 1247 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
845 return UNZ_PARAMERROR; 1248 return UNZ_PARAMERROR;
846 1249
847 s=(unz_s*)file; 1250 s=(unz64_s*)file;
848 if (!s->current_file_ok) 1251 if (!s->current_file_ok)
849 return UNZ_END_OF_LIST_OF_FILE; 1252 return UNZ_END_OF_LIST_OF_FILE;
850 1253
@@ -859,7 +1262,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
859 while (err == UNZ_OK) 1262 while (err == UNZ_OK)
860 { 1263 {
861 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 1264 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
862 err = unzGetCurrentFileInfo(file,NULL, 1265 err = unzGetCurrentFileInfo64(file,NULL,
863 szCurrentFileName,sizeof(szCurrentFileName)-1, 1266 szCurrentFileName,sizeof(szCurrentFileName)-1,
864 NULL,0,NULL,0); 1267 NULL,0,NULL,0);
865 if (err == UNZ_OK) 1268 if (err == UNZ_OK)
@@ -895,20 +1298,18 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
895/* 1298/*
896typedef struct unz_file_pos_s 1299typedef struct unz_file_pos_s
897{ 1300{
898 uLong pos_in_zip_directory; // offset in file 1301 ZPOS64_T pos_in_zip_directory; // offset in file
899 uLong num_of_file; // # of file 1302 ZPOS64_T num_of_file; // # of file
900} unz_file_pos; 1303} unz_file_pos;
901*/ 1304*/
902 1305
903extern int ZEXPORT unzGetFilePos(file, file_pos) 1306extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
904 unzFile file;
905 unz_file_pos* file_pos;
906{ 1307{
907 unz_s* s; 1308 unz64_s* s;
908 1309
909 if (file==NULL || file_pos==NULL) 1310 if (file==NULL || file_pos==NULL)
910 return UNZ_PARAMERROR; 1311 return UNZ_PARAMERROR;
911 s=(unz_s*)file; 1312 s=(unz64_s*)file;
912 if (!s->current_file_ok) 1313 if (!s->current_file_ok)
913 return UNZ_END_OF_LIST_OF_FILE; 1314 return UNZ_END_OF_LIST_OF_FILE;
914 1315
@@ -918,23 +1319,35 @@ extern int ZEXPORT unzGetFilePos(file, file_pos)
918 return UNZ_OK; 1319 return UNZ_OK;
919} 1320}
920 1321
921extern int ZEXPORT unzGoToFilePos(file, file_pos) 1322extern int ZEXPORT unzGetFilePos(
922 unzFile file; 1323 unzFile file,
923 unz_file_pos* file_pos; 1324 unz_file_pos* file_pos)
1325{
1326 unz64_file_pos file_pos64;
1327 int err = unzGetFilePos64(file,&file_pos64);
1328 if (err==UNZ_OK)
1329 {
1330 file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
1331 file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1332 }
1333 return err;
1334}
1335
1336extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
924{ 1337{
925 unz_s* s; 1338 unz64_s* s;
926 int err; 1339 int err;
927 1340
928 if (file==NULL || file_pos==NULL) 1341 if (file==NULL || file_pos==NULL)
929 return UNZ_PARAMERROR; 1342 return UNZ_PARAMERROR;
930 s=(unz_s*)file; 1343 s=(unz64_s*)file;
931 1344
932 /* jump to the right spot */ 1345 /* jump to the right spot */
933 s->pos_in_central_dir = file_pos->pos_in_zip_directory; 1346 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
934 s->num_file = file_pos->num_of_file; 1347 s->num_file = file_pos->num_of_file;
935 1348
936 /* set the current file */ 1349 /* set the current file */
937 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1350 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
938 &s->cur_file_info_internal, 1351 &s->cur_file_info_internal,
939 NULL,0,NULL,0,NULL,0); 1352 NULL,0,NULL,0,NULL,0);
940 /* return results */ 1353 /* return results */
@@ -942,6 +1355,19 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
942 return err; 1355 return err;
943} 1356}
944 1357
1358extern int ZEXPORT unzGoToFilePos(
1359 unzFile file,
1360 unz_file_pos* file_pos)
1361{
1362 unz64_file_pos file_pos64;
1363 if (file_pos == NULL)
1364 return UNZ_PARAMERROR;
1365
1366 file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
1367 file_pos64.num_of_file = file_pos->num_of_file;
1368 return unzGoToFilePos64(file,&file_pos64);
1369}
1370
945/* 1371/*
946// Unzip Helper Functions - should be here? 1372// Unzip Helper Functions - should be here?
947/////////////////////////////////////////// 1373///////////////////////////////////////////
@@ -954,13 +1380,9 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
954 store in *piSizeVar the size of extra info in local header 1380 store in *piSizeVar the size of extra info in local header
955 (filename and size of extra field data) 1381 (filename and size of extra field data)
956*/ 1382*/
957local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, 1383local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
958 poffset_local_extrafield, 1384 ZPOS64_T * poffset_local_extrafield,
959 psize_local_extrafield) 1385 uInt * psize_local_extrafield)
960 unz_s* s;
961 uInt* piSizeVar;
962 uLong *poffset_local_extrafield;
963 uInt *psize_local_extrafield;
964{ 1386{
965 uLong uMagic,uData,uFlags; 1387 uLong uMagic,uData,uFlags;
966 uLong size_filename; 1388 uLong size_filename;
@@ -971,65 +1393,66 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
971 *poffset_local_extrafield = 0; 1393 *poffset_local_extrafield = 0;
972 *psize_local_extrafield = 0; 1394 *psize_local_extrafield = 0;
973 1395
974 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + 1396 if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
975 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 1397 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
976 return UNZ_ERRNO; 1398 return UNZ_ERRNO;
977 1399
978 1400
979 if (err==UNZ_OK) 1401 if (err==UNZ_OK)
980 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 1402 {
1403 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
981 err=UNZ_ERRNO; 1404 err=UNZ_ERRNO;
982 else if (uMagic!=0x04034b50) 1405 else if (uMagic!=0x04034b50)
983 err=UNZ_BADZIPFILE; 1406 err=UNZ_BADZIPFILE;
1407 }
984 1408
985 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1409 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
986 err=UNZ_ERRNO; 1410 err=UNZ_ERRNO;
987/* 1411/*
988 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 1412 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
989 err=UNZ_BADZIPFILE; 1413 err=UNZ_BADZIPFILE;
990*/ 1414*/
991 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) 1415 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
992 err=UNZ_ERRNO; 1416 err=UNZ_ERRNO;
993 1417
994 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1418 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
995 err=UNZ_ERRNO; 1419 err=UNZ_ERRNO;
996 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 1420 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
997 err=UNZ_BADZIPFILE; 1421 err=UNZ_BADZIPFILE;
998 1422
999 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 1423 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1424/* #ifdef HAVE_BZIP2 */
1425 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1426/* #endif */
1000 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1427 (s->cur_file_info.compression_method!=Z_DEFLATED))
1001 err=UNZ_BADZIPFILE; 1428 err=UNZ_BADZIPFILE;
1002 1429
1003 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ 1430 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1004 err=UNZ_ERRNO; 1431 err=UNZ_ERRNO;
1005 1432
1006 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ 1433 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1007 err=UNZ_ERRNO; 1434 err=UNZ_ERRNO;
1008 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && 1435 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
1009 ((uFlags & 8)==0))
1010 err=UNZ_BADZIPFILE; 1436 err=UNZ_BADZIPFILE;
1011 1437
1012 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ 1438 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1013 err=UNZ_ERRNO; 1439 err=UNZ_ERRNO;
1014 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && 1440 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
1015 ((uFlags & 8)==0))
1016 err=UNZ_BADZIPFILE; 1441 err=UNZ_BADZIPFILE;
1017 1442
1018 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ 1443 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1019 err=UNZ_ERRNO; 1444 err=UNZ_ERRNO;
1020 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && 1445 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
1021 ((uFlags & 8)==0))
1022 err=UNZ_BADZIPFILE; 1446 err=UNZ_BADZIPFILE;
1023 1447
1024 1448 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1025 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1026 err=UNZ_ERRNO; 1449 err=UNZ_ERRNO;
1027 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1450 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1028 err=UNZ_BADZIPFILE; 1451 err=UNZ_BADZIPFILE;
1029 1452
1030 *piSizeVar += (uInt)size_filename; 1453 *piSizeVar += (uInt)size_filename;
1031 1454
1032 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) 1455 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1033 err=UNZ_ERRNO; 1456 err=UNZ_ERRNO;
1034 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1457 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1035 SIZEZIPLOCALHEADER + size_filename; 1458 SIZEZIPLOCALHEADER + size_filename;
@@ -1044,18 +1467,14 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
1044 Open for reading data the current file in the zipfile. 1467 Open for reading data the current file in the zipfile.
1045 If there is no error and the file is opened, the return value is UNZ_OK. 1468 If there is no error and the file is opened, the return value is UNZ_OK.
1046*/ 1469*/
1047extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) 1470extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
1048 unzFile file; 1471 int* level, int raw, const char* password)
1049 int* method;
1050 int* level;
1051 int raw;
1052 const char* password;
1053{ 1472{
1054 int err=UNZ_OK; 1473 int err=UNZ_OK;
1055 uInt iSizeVar; 1474 uInt iSizeVar;
1056 unz_s* s; 1475 unz64_s* s;
1057 file_in_zip_read_info_s* pfile_in_zip_read_info; 1476 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1058 uLong offset_local_extrafield; /* offset of the local extra field */ 1477 ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
1059 uInt size_local_extrafield; /* size of the local extra field */ 1478 uInt size_local_extrafield; /* size of the local extra field */
1060# ifndef NOUNCRYPT 1479# ifndef NOUNCRYPT
1061 char source[12]; 1480 char source[12];
@@ -1066,19 +1485,17 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1066 1485
1067 if (file==NULL) 1486 if (file==NULL)
1068 return UNZ_PARAMERROR; 1487 return UNZ_PARAMERROR;
1069 s=(unz_s*)file; 1488 s=(unz64_s*)file;
1070 if (!s->current_file_ok) 1489 if (!s->current_file_ok)
1071 return UNZ_PARAMERROR; 1490 return UNZ_PARAMERROR;
1072 1491
1073 if (s->pfile_in_zip_read != NULL) 1492 if (s->pfile_in_zip_read != NULL)
1074 unzCloseCurrentFile(file); 1493 unzCloseCurrentFile(file);
1075 1494
1076 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, 1495 if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1077 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1078 return UNZ_BADZIPFILE; 1496 return UNZ_BADZIPFILE;
1079 1497
1080 pfile_in_zip_read_info = (file_in_zip_read_info_s*) 1498 pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
1081 ALLOC(sizeof(file_in_zip_read_info_s));
1082 if (pfile_in_zip_read_info==NULL) 1499 if (pfile_in_zip_read_info==NULL)
1083 return UNZ_INTERNALERROR; 1500 return UNZ_INTERNALERROR;
1084 1501
@@ -1111,31 +1528,60 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1111 } 1528 }
1112 1529
1113 if ((s->cur_file_info.compression_method!=0) && 1530 if ((s->cur_file_info.compression_method!=0) &&
1531/* #ifdef HAVE_BZIP2 */
1532 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1533/* #endif */
1114 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1534 (s->cur_file_info.compression_method!=Z_DEFLATED))
1535
1115 err=UNZ_BADZIPFILE; 1536 err=UNZ_BADZIPFILE;
1116 1537
1117 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1538 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1118 pfile_in_zip_read_info->crc32=0; 1539 pfile_in_zip_read_info->crc32=0;
1119 pfile_in_zip_read_info->compression_method = 1540 pfile_in_zip_read_info->total_out_64=0;
1120 s->cur_file_info.compression_method; 1541 pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
1121 pfile_in_zip_read_info->filestream=s->filestream; 1542 pfile_in_zip_read_info->filestream=s->filestream;
1122 pfile_in_zip_read_info->z_filefunc=s->z_filefunc; 1543 pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1123 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; 1544 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1124 1545
1125 pfile_in_zip_read_info->stream.total_out = 0; 1546 pfile_in_zip_read_info->stream.total_out = 0;
1126 1547
1127 if ((s->cur_file_info.compression_method==Z_DEFLATED) && 1548 if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
1128 (!raw))
1129 { 1549 {
1550#ifdef HAVE_BZIP2
1551 pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
1552 pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
1553 pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
1554 pfile_in_zip_read_info->bstream.state = (voidpf)0;
1555
1130 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1556 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1131 pfile_in_zip_read_info->stream.zfree = (free_func)0; 1557 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1132 pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1558 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1133 pfile_in_zip_read_info->stream.next_in = (voidpf)0; 1559 pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1134 pfile_in_zip_read_info->stream.avail_in = 0; 1560 pfile_in_zip_read_info->stream.avail_in = 0;
1135 1561
1562 err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1563 if (err == Z_OK)
1564 pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
1565 else
1566 {
1567 TRYFREE(pfile_in_zip_read_info);
1568 return err;
1569 }
1570#else
1571 pfile_in_zip_read_info->raw=1;
1572#endif
1573 }
1574 else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
1575 {
1576 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1577 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1578 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1579 pfile_in_zip_read_info->stream.next_in = 0;
1580 pfile_in_zip_read_info->stream.avail_in = 0;
1581
1136 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1582 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1137 if (err == Z_OK) 1583 if (err == Z_OK)
1138 pfile_in_zip_read_info->stream_initialised=1; 1584 pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
1139 else 1585 else
1140 { 1586 {
1141 TRYFREE(pfile_in_zip_read_info); 1587 TRYFREE(pfile_in_zip_read_info);
@@ -1162,8 +1608,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1162 pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1608 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1163 1609
1164 s->pfile_in_zip_read = pfile_in_zip_read_info; 1610 s->pfile_in_zip_read = pfile_in_zip_read_info;
1165 1611 s->encrypted = 0;
1166 s->encrypted = 0;
1167 1612
1168# ifndef NOUNCRYPT 1613# ifndef NOUNCRYPT
1169 if (password != NULL) 1614 if (password != NULL)
@@ -1171,12 +1616,12 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1171 int i; 1616 int i;
1172 s->pcrc_32_tab = get_crc_table(); 1617 s->pcrc_32_tab = get_crc_table();
1173 init_keys(password,s->keys,s->pcrc_32_tab); 1618 init_keys(password,s->keys,s->pcrc_32_tab);
1174 if (ZSEEK(s->z_filefunc, s->filestream, 1619 if (ZSEEK64(s->z_filefunc, s->filestream,
1175 s->pfile_in_zip_read->pos_in_zipfile + 1620 s->pfile_in_zip_read->pos_in_zipfile +
1176 s->pfile_in_zip_read->byte_before_the_zipfile, 1621 s->pfile_in_zip_read->byte_before_the_zipfile,
1177 SEEK_SET)!=0) 1622 SEEK_SET)!=0)
1178 return UNZ_INTERNALERROR; 1623 return UNZ_INTERNALERROR;
1179 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) 1624 if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
1180 return UNZ_INTERNALERROR; 1625 return UNZ_INTERNALERROR;
1181 1626
1182 for (i = 0; i<12; i++) 1627 for (i = 0; i<12; i++)
@@ -1191,28 +1636,39 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1191 return UNZ_OK; 1636 return UNZ_OK;
1192} 1637}
1193 1638
1194extern int ZEXPORT unzOpenCurrentFile (file) 1639extern int ZEXPORT unzOpenCurrentFile (unzFile file)
1195 unzFile file;
1196{ 1640{
1197 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); 1641 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1198} 1642}
1199 1643
1200extern int ZEXPORT unzOpenCurrentFilePassword (file, password) 1644extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
1201 unzFile file;
1202 const char* password;
1203{ 1645{
1204 return unzOpenCurrentFile3(file, NULL, NULL, 0, password); 1646 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1205} 1647}
1206 1648
1207extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) 1649extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
1208 unzFile file;
1209 int* method;
1210 int* level;
1211 int raw;
1212{ 1650{
1213 return unzOpenCurrentFile3(file, method, level, raw, NULL); 1651 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1214} 1652}
1215 1653
1654/** Addition for GDAL : START */
1655
1656extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
1657{
1658 unz64_s* s;
1659 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1660 s=(unz64_s*)file;
1661 if (file==NULL)
1662 return 0; //UNZ_PARAMERROR;
1663 pfile_in_zip_read_info=s->pfile_in_zip_read;
1664 if (pfile_in_zip_read_info==NULL)
1665 return 0; //UNZ_PARAMERROR;
1666 return pfile_in_zip_read_info->pos_in_zipfile +
1667 pfile_in_zip_read_info->byte_before_the_zipfile;
1668}
1669
1670/** Addition for GDAL : END */
1671
1216/* 1672/*
1217 Read bytes from the current file. 1673 Read bytes from the current file.
1218 buf contain buffer where data must be copied 1674 buf contain buffer where data must be copied
@@ -1223,18 +1679,15 @@ extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1223 return <0 with error code if there is an error 1679 return <0 with error code if there is an error
1224 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1680 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1225*/ 1681*/
1226extern int ZEXPORT unzReadCurrentFile (file, buf, len) 1682extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1227 unzFile file;
1228 voidp buf;
1229 unsigned len;
1230{ 1683{
1231 int err=UNZ_OK; 1684 int err=UNZ_OK;
1232 uInt iRead = 0; 1685 uInt iRead = 0;
1233 unz_s* s; 1686 unz64_s* s;
1234 file_in_zip_read_info_s* pfile_in_zip_read_info; 1687 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1235 if (file==NULL) 1688 if (file==NULL)
1236 return UNZ_PARAMERROR; 1689 return UNZ_PARAMERROR;
1237 s=(unz_s*)file; 1690 s=(unz64_s*)file;
1238 pfile_in_zip_read_info=s->pfile_in_zip_read; 1691 pfile_in_zip_read_info=s->pfile_in_zip_read;
1239 1692
1240 if (pfile_in_zip_read_info==NULL) 1693 if (pfile_in_zip_read_info==NULL)
@@ -1272,13 +1725,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1272 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; 1725 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1273 if (uReadThis == 0) 1726 if (uReadThis == 0)
1274 return UNZ_EOF; 1727 return UNZ_EOF;
1275 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1728 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1276 pfile_in_zip_read_info->filestream, 1729 pfile_in_zip_read_info->filestream,
1277 pfile_in_zip_read_info->pos_in_zipfile + 1730 pfile_in_zip_read_info->pos_in_zipfile +
1278 pfile_in_zip_read_info->byte_before_the_zipfile, 1731 pfile_in_zip_read_info->byte_before_the_zipfile,
1279 ZLIB_FILEFUNC_SEEK_SET)!=0) 1732 ZLIB_FILEFUNC_SEEK_SET)!=0)
1280 return UNZ_ERRNO; 1733 return UNZ_ERRNO;
1281 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1734 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1282 pfile_in_zip_read_info->filestream, 1735 pfile_in_zip_read_info->filestream,
1283 pfile_in_zip_read_info->read_buffer, 1736 pfile_in_zip_read_info->read_buffer,
1284 uReadThis)!=uReadThis) 1737 uReadThis)!=uReadThis)
@@ -1324,6 +1777,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1324 *(pfile_in_zip_read_info->stream.next_out+i) = 1777 *(pfile_in_zip_read_info->stream.next_out+i) =
1325 *(pfile_in_zip_read_info->stream.next_in+i); 1778 *(pfile_in_zip_read_info->stream.next_in+i);
1326 1779
1780 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
1781
1327 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1782 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1328 pfile_in_zip_read_info->stream.next_out, 1783 pfile_in_zip_read_info->stream.next_out,
1329 uDoCopy); 1784 uDoCopy);
@@ -1335,11 +1790,54 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1335 pfile_in_zip_read_info->stream.total_out += uDoCopy; 1790 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1336 iRead += uDoCopy; 1791 iRead += uDoCopy;
1337 } 1792 }
1338 else 1793 else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
1339 { 1794 {
1795#ifdef HAVE_BZIP2
1340 uLong uTotalOutBefore,uTotalOutAfter; 1796 uLong uTotalOutBefore,uTotalOutAfter;
1341 const Bytef *bufBefore; 1797 const Bytef *bufBefore;
1342 uLong uOutThis; 1798 uLong uOutThis;
1799
1800 pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
1801 pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
1802 pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
1803 pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
1804 pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
1805 pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
1806 pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
1807 pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
1808
1809 uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
1810 bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
1811
1812 err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
1813
1814 uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
1815 uOutThis = uTotalOutAfter-uTotalOutBefore;
1816
1817 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1818
1819 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
1820 pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
1821 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1822
1823 pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
1824 pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
1825 pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
1826 pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
1827 pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
1828 pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
1829
1830 if (err==BZ_STREAM_END)
1831 return (iRead==0) ? UNZ_EOF : iRead;
1832 if (err!=BZ_OK)
1833 break;
1834#endif
1835 } // end Z_BZIP2ED
1836 else
1837 {
1838 ZPOS64_T uTotalOutBefore,uTotalOutAfter;
1839 const Bytef *bufBefore;
1840 ZPOS64_T uOutThis;
1343 int flush=Z_SYNC_FLUSH; 1841 int flush=Z_SYNC_FLUSH;
1344 1842
1345 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1843 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
@@ -1359,6 +1857,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1359 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1857 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1360 uOutThis = uTotalOutAfter-uTotalOutBefore; 1858 uOutThis = uTotalOutAfter-uTotalOutBefore;
1361 1859
1860 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1861
1362 pfile_in_zip_read_info->crc32 = 1862 pfile_in_zip_read_info->crc32 =
1363 crc32(pfile_in_zip_read_info->crc32,bufBefore, 1863 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1364 (uInt)(uOutThis)); 1864 (uInt)(uOutThis));
@@ -1384,14 +1884,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1384/* 1884/*
1385 Give the current position in uncompressed data 1885 Give the current position in uncompressed data
1386*/ 1886*/
1387extern z_off_t ZEXPORT unztell (file) 1887extern z_off_t ZEXPORT unztell (unzFile file)
1388 unzFile file;
1389{ 1888{
1390 unz_s* s; 1889 unz64_s* s;
1391 file_in_zip_read_info_s* pfile_in_zip_read_info; 1890 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1392 if (file==NULL) 1891 if (file==NULL)
1393 return UNZ_PARAMERROR; 1892 return UNZ_PARAMERROR;
1394 s=(unz_s*)file; 1893 s=(unz64_s*)file;
1395 pfile_in_zip_read_info=s->pfile_in_zip_read; 1894 pfile_in_zip_read_info=s->pfile_in_zip_read;
1396 1895
1397 if (pfile_in_zip_read_info==NULL) 1896 if (pfile_in_zip_read_info==NULL)
@@ -1400,18 +1899,33 @@ extern z_off_t ZEXPORT unztell (file)
1400 return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1899 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1401} 1900}
1402 1901
1902extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
1903{
1904
1905 unz64_s* s;
1906 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1907 if (file==NULL)
1908 return (ZPOS64_T)-1;
1909 s=(unz64_s*)file;
1910 pfile_in_zip_read_info=s->pfile_in_zip_read;
1911
1912 if (pfile_in_zip_read_info==NULL)
1913 return (ZPOS64_T)-1;
1914
1915 return pfile_in_zip_read_info->total_out_64;
1916}
1917
1403 1918
1404/* 1919/*
1405 return 1 if the end of file was reached, 0 elsewhere 1920 return 1 if the end of file was reached, 0 elsewhere
1406*/ 1921*/
1407extern int ZEXPORT unzeof (file) 1922extern int ZEXPORT unzeof (unzFile file)
1408 unzFile file;
1409{ 1923{
1410 unz_s* s; 1924 unz64_s* s;
1411 file_in_zip_read_info_s* pfile_in_zip_read_info; 1925 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1412 if (file==NULL) 1926 if (file==NULL)
1413 return UNZ_PARAMERROR; 1927 return UNZ_PARAMERROR;
1414 s=(unz_s*)file; 1928 s=(unz64_s*)file;
1415 pfile_in_zip_read_info=s->pfile_in_zip_read; 1929 pfile_in_zip_read_info=s->pfile_in_zip_read;
1416 1930
1417 if (pfile_in_zip_read_info==NULL) 1931 if (pfile_in_zip_read_info==NULL)
@@ -1426,9 +1940,9 @@ extern int ZEXPORT unzeof (file)
1426 1940
1427 1941
1428/* 1942/*
1429 Read extra field from the current file (opened by unzOpenCurrentFile) 1943Read extra field from the current file (opened by unzOpenCurrentFile)
1430 This is the local-header version of the extra field (sometimes, there is 1944This is the local-header version of the extra field (sometimes, there is
1431 more info in the local-header version than in the central-header) 1945more info in the local-header version than in the central-header)
1432 1946
1433 if buf==NULL, it return the size of the local extra field that can be read 1947 if buf==NULL, it return the size of the local extra field that can be read
1434 1948
@@ -1437,19 +1951,16 @@ extern int ZEXPORT unzeof (file)
1437 the return value is the number of bytes copied in buf, or (if <0) 1951 the return value is the number of bytes copied in buf, or (if <0)
1438 the error code 1952 the error code
1439*/ 1953*/
1440extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) 1954extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
1441 unzFile file;
1442 voidp buf;
1443 unsigned len;
1444{ 1955{
1445 unz_s* s; 1956 unz64_s* s;
1446 file_in_zip_read_info_s* pfile_in_zip_read_info; 1957 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1447 uInt read_now; 1958 uInt read_now;
1448 uLong size_to_read; 1959 ZPOS64_T size_to_read;
1449 1960
1450 if (file==NULL) 1961 if (file==NULL)
1451 return UNZ_PARAMERROR; 1962 return UNZ_PARAMERROR;
1452 s=(unz_s*)file; 1963 s=(unz64_s*)file;
1453 pfile_in_zip_read_info=s->pfile_in_zip_read; 1964 pfile_in_zip_read_info=s->pfile_in_zip_read;
1454 1965
1455 if (pfile_in_zip_read_info==NULL) 1966 if (pfile_in_zip_read_info==NULL)
@@ -1469,14 +1980,14 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1469 if (read_now==0) 1980 if (read_now==0)
1470 return 0; 1981 return 0;
1471 1982
1472 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1983 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1473 pfile_in_zip_read_info->filestream, 1984 pfile_in_zip_read_info->filestream,
1474 pfile_in_zip_read_info->offset_local_extrafield + 1985 pfile_in_zip_read_info->offset_local_extrafield +
1475 pfile_in_zip_read_info->pos_local_extrafield, 1986 pfile_in_zip_read_info->pos_local_extrafield,
1476 ZLIB_FILEFUNC_SEEK_SET)!=0) 1987 ZLIB_FILEFUNC_SEEK_SET)!=0)
1477 return UNZ_ERRNO; 1988 return UNZ_ERRNO;
1478 1989
1479 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1990 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1480 pfile_in_zip_read_info->filestream, 1991 pfile_in_zip_read_info->filestream,
1481 buf,read_now)!=read_now) 1992 buf,read_now)!=read_now)
1482 return UNZ_ERRNO; 1993 return UNZ_ERRNO;
@@ -1488,16 +1999,15 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1488 Close the file in zip opened with unzipOpenCurrentFile 1999 Close the file in zip opened with unzipOpenCurrentFile
1489 Return UNZ_CRCERROR if all the file was read but the CRC is not good 2000 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1490*/ 2001*/
1491extern int ZEXPORT unzCloseCurrentFile (file) 2002extern int ZEXPORT unzCloseCurrentFile (unzFile file)
1492 unzFile file;
1493{ 2003{
1494 int err=UNZ_OK; 2004 int err=UNZ_OK;
1495 2005
1496 unz_s* s; 2006 unz64_s* s;
1497 file_in_zip_read_info_s* pfile_in_zip_read_info; 2007 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1498 if (file==NULL) 2008 if (file==NULL)
1499 return UNZ_PARAMERROR; 2009 return UNZ_PARAMERROR;
1500 s=(unz_s*)file; 2010 s=(unz64_s*)file;
1501 pfile_in_zip_read_info=s->pfile_in_zip_read; 2011 pfile_in_zip_read_info=s->pfile_in_zip_read;
1502 2012
1503 if (pfile_in_zip_read_info==NULL) 2013 if (pfile_in_zip_read_info==NULL)
@@ -1514,8 +2024,13 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1514 2024
1515 TRYFREE(pfile_in_zip_read_info->read_buffer); 2025 TRYFREE(pfile_in_zip_read_info->read_buffer);
1516 pfile_in_zip_read_info->read_buffer = NULL; 2026 pfile_in_zip_read_info->read_buffer = NULL;
1517 if (pfile_in_zip_read_info->stream_initialised) 2027 if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
1518 inflateEnd(&pfile_in_zip_read_info->stream); 2028 inflateEnd(&pfile_in_zip_read_info->stream);
2029#ifdef HAVE_BZIP2
2030 else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
2031 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2032#endif
2033
1519 2034
1520 pfile_in_zip_read_info->stream_initialised = 0; 2035 pfile_in_zip_read_info->stream_initialised = 0;
1521 TRYFREE(pfile_in_zip_read_info); 2036 TRYFREE(pfile_in_zip_read_info);
@@ -1531,29 +2046,25 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1531 uSizeBuf is the size of the szComment buffer. 2046 uSizeBuf is the size of the szComment buffer.
1532 return the number of byte copied or an error code <0 2047 return the number of byte copied or an error code <0
1533*/ 2048*/
1534extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) 2049extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
1535 unzFile file;
1536 char *szComment;
1537 uLong uSizeBuf;
1538{ 2050{
1539 int err=UNZ_OK; 2051 unz64_s* s;
1540 unz_s* s;
1541 uLong uReadThis ; 2052 uLong uReadThis ;
1542 if (file==NULL) 2053 if (file==NULL)
1543 return UNZ_PARAMERROR; 2054 return (uLong)UNZ_PARAMERROR;
1544 s=(unz_s*)file; 2055 s=(unz64_s*)file;
1545 2056
1546 uReadThis = uSizeBuf; 2057 uReadThis = uSizeBuf;
1547 if (uReadThis>s->gi.size_comment) 2058 if (uReadThis>s->gi.size_comment)
1548 uReadThis = s->gi.size_comment; 2059 uReadThis = s->gi.size_comment;
1549 2060
1550 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) 2061 if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1551 return UNZ_ERRNO; 2062 return UNZ_ERRNO;
1552 2063
1553 if (uReadThis>0) 2064 if (uReadThis>0)
1554 { 2065 {
1555 *szComment='\0'; 2066 *szComment='\0';
1556 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) 2067 if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1557 return UNZ_ERRNO; 2068 return UNZ_ERRNO;
1558 } 2069 }
1559 2070
@@ -1563,14 +2074,13 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1563} 2074}
1564 2075
1565/* Additions by RX '2004 */ 2076/* Additions by RX '2004 */
1566extern uLong ZEXPORT unzGetOffset (file) 2077extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
1567 unzFile file;
1568{ 2078{
1569 unz_s* s; 2079 unz64_s* s;
1570 2080
1571 if (file==NULL) 2081 if (file==NULL)
1572 return UNZ_PARAMERROR; 2082 return 0; //UNZ_PARAMERROR;
1573 s=(unz_s*)file; 2083 s=(unz64_s*)file;
1574 if (!s->current_file_ok) 2084 if (!s->current_file_ok)
1575 return 0; 2085 return 0;
1576 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) 2086 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
@@ -1579,22 +2089,35 @@ extern uLong ZEXPORT unzGetOffset (file)
1579 return s->pos_in_central_dir; 2089 return s->pos_in_central_dir;
1580} 2090}
1581 2091
1582extern int ZEXPORT unzSetOffset (file, pos) 2092extern uLong ZEXPORT unzGetOffset (unzFile file)
1583 unzFile file; 2093{
1584 uLong pos; 2094 ZPOS64_T offset64;
2095
2096 if (file==NULL)
2097 return 0; //UNZ_PARAMERROR;
2098 offset64 = unzGetOffset64(file);
2099 return (uLong)offset64;
2100}
2101
2102extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
1585{ 2103{
1586 unz_s* s; 2104 unz64_s* s;
1587 int err; 2105 int err;
1588 2106
1589 if (file==NULL) 2107 if (file==NULL)
1590 return UNZ_PARAMERROR; 2108 return UNZ_PARAMERROR;
1591 s=(unz_s*)file; 2109 s=(unz64_s*)file;
1592 2110
1593 s->pos_in_central_dir = pos; 2111 s->pos_in_central_dir = pos;
1594 s->num_file = s->gi.number_entry; /* hack */ 2112 s->num_file = s->gi.number_entry; /* hack */
1595 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 2113 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1596 &s->cur_file_info_internal, 2114 &s->cur_file_info_internal,
1597 NULL,0,NULL,0,NULL,0); 2115 NULL,0,NULL,0,NULL,0);
1598 s->current_file_ok = (err == UNZ_OK); 2116 s->current_file_ok = (err == UNZ_OK);
1599 return err; 2117 return err;
1600} 2118}
2119
2120extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
2121{
2122 return unzSetOffset64(file,pos);
2123}
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h
index b247937..a2e698f 100644
--- a/contrib/minizip/unzip.h
+++ b/contrib/minizip/unzip.h
@@ -1,20 +1,20 @@
1/* unzip.h -- IO for uncompress .zip files using zlib 1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, January 7th, 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 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g 7 Modifications of Unzip for Zip64
7 WinZip, InfoZip tools and compatible. 8 Copyright (C) 2007-2008 Even Rouault
8 9
9 Multi volume ZipFile (span) are not supported. 10 Modifications for Zip64 support on both zip and unzip
10 Encryption compatible with pkzip 2.04g only supported 11 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
11 Old compressions used by old PKZip 1.x are not supported
12 12
13 For more info read MiniZip_info.txt
13 14
14 I WAIT FEEDBACK at mail info@winimage.com 15 ---------------------------------------------------------------------------------
15 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution 16
16 17 Condition of use and distribution are the same than zlib :
17 Condition of use and distribution are the same than zlib :
18 18
19 This software is provided 'as-is', without any express or implied 19 This software is provided 'as-is', without any express or implied
20 warranty. In no event will the authors be held liable for any damages 20 warranty. In no event will the authors be held liable for any damages
@@ -32,18 +32,16 @@
32 misrepresented as being the original software. 32 misrepresented as being the original software.
33 3. This notice may not be removed or altered from any source distribution. 33 3. This notice may not be removed or altered from any source distribution.
34 34
35 ---------------------------------------------------------------------------------
35 36
36*/ 37 Changes
38
39 See header of unzip64.c
37 40
38/* for more info about .ZIP format, see
39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
40 http://www.info-zip.org/pub/infozip/doc/
41 PkWare has also a specification at :
42 ftp://ftp.pkware.com/probdesc.zip
43*/ 41*/
44 42
45#ifndef _unz_H 43#ifndef _unz64_H
46#define _unz_H 44#define _unz64_H
47 45
48#ifdef __cplusplus 46#ifdef __cplusplus
49extern "C" { 47extern "C" {
@@ -53,10 +51,16 @@ extern "C" {
53#include "zlib.h" 51#include "zlib.h"
54#endif 52#endif
55 53
56#ifndef _ZLIBIOAPI_H 54#ifndef _ZLIBIOAPI_H
57#include "ioapi.h" 55#include "ioapi.h"
58#endif 56#endif
59 57
58#ifdef HAVE_BZIP2
59#include "bzlib.h"
60#endif
61
62#define Z_BZIP2ED 12
63
60#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 64#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
61/* like the STRICT of WIN32, we define a pointer that cannot be converted 65/* like the STRICT of WIN32, we define a pointer that cannot be converted
62 from (void*) without cast */ 66 from (void*) without cast */
@@ -89,15 +93,42 @@ typedef struct tm_unz_s
89 93
90/* unz_global_info structure contain global data about the ZIPfile 94/* unz_global_info structure contain global data about the ZIPfile
91 These data comes from the end of central dir */ 95 These data comes from the end of central dir */
96typedef struct unz_global_info64_s
97{
98 ZPOS64_T number_entry; /* total number of entries in
99 the central dir on this disk */
100 uLong size_comment; /* size of the global comment of the zipfile */
101} unz_global_info64;
102
92typedef struct unz_global_info_s 103typedef struct unz_global_info_s
93{ 104{
94 uLong number_entry; /* total number of entries in 105 uLong number_entry; /* total number of entries in
95 the central dir on this disk */ 106 the central dir on this disk */
96 uLong size_comment; /* size of the global comment of the zipfile */ 107 uLong size_comment; /* size of the global comment of the zipfile */
97} unz_global_info; 108} unz_global_info;
98 109
99
100/* unz_file_info contain information about a file in the zipfile */ 110/* unz_file_info contain information about a file in the zipfile */
111typedef struct unz_file_info64_s
112{
113 uLong version; /* version made by 2 bytes */
114 uLong version_needed; /* version needed to extract 2 bytes */
115 uLong flag; /* general purpose bit flag 2 bytes */
116 uLong compression_method; /* compression method 2 bytes */
117 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
118 uLong crc; /* crc-32 4 bytes */
119 ZPOS64_T compressed_size; /* compressed size 8 bytes */
120 ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
121 uLong size_filename; /* filename length 2 bytes */
122 uLong size_file_extra; /* extra field length 2 bytes */
123 uLong size_file_comment; /* file comment length 2 bytes */
124
125 uLong disk_num_start; /* disk number start 2 bytes */
126 uLong internal_fa; /* internal file attributes 2 bytes */
127 uLong external_fa; /* external file attributes 4 bytes */
128
129 tm_unz tmu_date;
130} unz_file_info64;
131
101typedef struct unz_file_info_s 132typedef struct unz_file_info_s
102{ 133{
103 uLong version; /* version made by 2 bytes */ 134 uLong version; /* version made by 2 bytes */
@@ -133,6 +164,7 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
133 164
134 165
135extern unzFile ZEXPORT unzOpen OF((const char *path)); 166extern unzFile ZEXPORT unzOpen OF((const char *path));
167extern unzFile ZEXPORT unzOpen64 OF((const void *path));
136/* 168/*
137 Open a Zip file. path contain the full pathname (by example, 169 Open a Zip file. path contain the full pathname (by example,
138 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 170 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
@@ -141,8 +173,14 @@ extern unzFile ZEXPORT unzOpen OF((const char *path));
141 return value is NULL. 173 return value is NULL.
142 Else, the return value is a unzFile Handle, usable with other function 174 Else, the return value is a unzFile Handle, usable with other function
143 of this unzip package. 175 of this unzip package.
176 the "64" function take a const void* pointer, because the path is just the
177 value passed to the open64_file_func callback.
178 Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
179 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
180 does not describe the reality
144*/ 181*/
145 182
183
146extern unzFile ZEXPORT unzOpen2 OF((const char *path, 184extern unzFile ZEXPORT unzOpen2 OF((const char *path,
147 zlib_filefunc_def* pzlib_filefunc_def)); 185 zlib_filefunc_def* pzlib_filefunc_def));
148/* 186/*
@@ -150,6 +188,13 @@ extern unzFile ZEXPORT unzOpen2 OF((const char *path,
150 for read/write the zip file (see ioapi.h) 188 for read/write the zip file (see ioapi.h)
151*/ 189*/
152 190
191extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
192 zlib_filefunc64_def* pzlib_filefunc_def));
193/*
194 Open a Zip file, like unz64Open, but provide a set of file low level API
195 for read/write the zip file (see ioapi.h)
196*/
197
153extern int ZEXPORT unzClose OF((unzFile file)); 198extern int ZEXPORT unzClose OF((unzFile file));
154/* 199/*
155 Close a ZipFile opened with unzipOpen. 200 Close a ZipFile opened with unzipOpen.
@@ -159,6 +204,9 @@ extern int ZEXPORT unzClose OF((unzFile file));
159 204
160extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 205extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
161 unz_global_info *pglobal_info)); 206 unz_global_info *pglobal_info));
207
208extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
209 unz_global_info64 *pglobal_info));
162/* 210/*
163 Write info about the ZipFile in the *pglobal_info structure. 211 Write info about the ZipFile in the *pglobal_info structure.
164 No preparation of the structure is needed 212 No preparation of the structure is needed
@@ -221,8 +269,31 @@ extern int ZEXPORT unzGoToFilePos(
221 unzFile file, 269 unzFile file,
222 unz_file_pos* file_pos); 270 unz_file_pos* file_pos);
223 271
272typedef struct unz64_file_pos_s
273{
274 ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
275 ZPOS64_T num_of_file; /* # of file */
276} unz64_file_pos;
277
278extern int ZEXPORT unzGetFilePos64(
279 unzFile file,
280 unz64_file_pos* file_pos);
281
282extern int ZEXPORT unzGoToFilePos64(
283 unzFile file,
284 const unz64_file_pos* file_pos);
285
224/* ****************************************** */ 286/* ****************************************** */
225 287
288extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
289 unz_file_info64 *pfile_info,
290 char *szFileName,
291 uLong fileNameBufferSize,
292 void *extraField,
293 uLong extraFieldBufferSize,
294 char *szComment,
295 uLong commentBufferSize));
296
226extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 297extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
227 unz_file_info *pfile_info, 298 unz_file_info *pfile_info,
228 char *szFileName, 299 char *szFileName,
@@ -244,6 +315,14 @@ extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
244 (commentBufferSize is the size of the buffer) 315 (commentBufferSize is the size of the buffer)
245*/ 316*/
246 317
318
319/** Addition for GDAL : START */
320
321extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
322
323/** Addition for GDAL : END */
324
325
247/***************************************************************************/ 326/***************************************************************************/
248/* for reading the content of the current zipfile, you can open it, read data 327/* for reading the content of the current zipfile, you can open it, read data
249 from it, and close it (you can close it before reading all the file) 328 from it, and close it (you can close it before reading all the file)
@@ -312,6 +391,8 @@ extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
312*/ 391*/
313 392
314extern z_off_t ZEXPORT unztell OF((unzFile file)); 393extern z_off_t ZEXPORT unztell OF((unzFile file));
394
395extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
315/* 396/*
316 Give the current position in uncompressed data 397 Give the current position in uncompressed data
317*/ 398*/
@@ -340,9 +421,11 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
340/***************************************************************************/ 421/***************************************************************************/
341 422
342/* Get the current file offset */ 423/* Get the current file offset */
424extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
343extern uLong ZEXPORT unzGetOffset (unzFile file); 425extern uLong ZEXPORT unzGetOffset (unzFile file);
344 426
345/* Set the current file offset */ 427/* Set the current file offset */
428extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
346extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 429extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
347 430
348 431
@@ -351,4 +434,4 @@ extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
351} 434}
352#endif 435#endif
353 436
354#endif /* _unz_H */ 437#endif /* _unz64_H */
diff --git a/contrib/minizip/zconf.h b/contrib/minizip/zconf.h
new file mode 100644
index 0000000..03a9431
--- /dev/null
+++ b/contrib/minizip/zconf.h
@@ -0,0 +1,332 @@
1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#ifndef ZCONF_H
9#define ZCONF_H
10
11/*
12 * If you *really* need a unique prefix for all types and library functions,
13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14 */
15#ifdef Z_PREFIX
16# define deflateInit_ z_deflateInit_
17# define deflate z_deflate
18# define deflateEnd z_deflateEnd
19# define inflateInit_ z_inflateInit_
20# define inflate z_inflate
21# define inflateEnd z_inflateEnd
22# define deflateInit2_ z_deflateInit2_
23# define deflateSetDictionary z_deflateSetDictionary
24# define deflateCopy z_deflateCopy
25# define deflateReset z_deflateReset
26# define deflateParams z_deflateParams
27# define deflateBound z_deflateBound
28# define deflatePrime z_deflatePrime
29# define inflateInit2_ z_inflateInit2_
30# define inflateSetDictionary z_inflateSetDictionary
31# define inflateSync z_inflateSync
32# define inflateSyncPoint z_inflateSyncPoint
33# define inflateCopy z_inflateCopy
34# define inflateReset z_inflateReset
35# define inflateBack z_inflateBack
36# define inflateBackEnd z_inflateBackEnd
37# define compress z_compress
38# define compress2 z_compress2
39# define compressBound z_compressBound
40# define uncompress z_uncompress
41# define adler32 z_adler32
42# define crc32 z_crc32
43# define get_crc_table z_get_crc_table
44# define zError z_zError
45
46# define alloc_func z_alloc_func
47# define free_func z_free_func
48# define in_func z_in_func
49# define out_func z_out_func
50# define Byte z_Byte
51# define uInt z_uInt
52# define uLong z_uLong
53# define Bytef z_Bytef
54# define charf z_charf
55# define intf z_intf
56# define uIntf z_uIntf
57# define uLongf z_uLongf
58# define voidpf z_voidpf
59# define voidp z_voidp
60#endif
61
62#if defined(__MSDOS__) && !defined(MSDOS)
63# define MSDOS
64#endif
65#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
66# define OS2
67#endif
68#if defined(_WINDOWS) && !defined(WINDOWS)
69# define WINDOWS
70#endif
71#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
72# ifndef WIN32
73# define WIN32
74# endif
75#endif
76#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
77# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
78# ifndef SYS16BIT
79# define SYS16BIT
80# endif
81# endif
82#endif
83
84/*
85 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
86 * than 64k bytes at a time (needed on systems with 16-bit int).
87 */
88#ifdef SYS16BIT
89# define MAXSEG_64K
90#endif
91#ifdef MSDOS
92# define UNALIGNED_OK
93#endif
94
95#ifdef __STDC_VERSION__
96# ifndef STDC
97# define STDC
98# endif
99# if __STDC_VERSION__ >= 199901L
100# ifndef STDC99
101# define STDC99
102# endif
103# endif
104#endif
105#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
106# define STDC
107#endif
108#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
109# define STDC
110#endif
111#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
112# define STDC
113#endif
114#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
115# define STDC
116#endif
117
118#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
119# define STDC
120#endif
121
122#ifndef STDC
123# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
124# define const /* note: need a more gentle solution here */
125# endif
126#endif
127
128/* Some Mac compilers merge all .h files incorrectly: */
129#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
130# define NO_DUMMY_DECL
131#endif
132
133/* Maximum value for memLevel in deflateInit2 */
134#ifndef MAX_MEM_LEVEL
135# ifdef MAXSEG_64K
136# define MAX_MEM_LEVEL 8
137# else
138# define MAX_MEM_LEVEL 9
139# endif
140#endif
141
142/* Maximum value for windowBits in deflateInit2 and inflateInit2.
143 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
144 * created by gzip. (Files created by minigzip can still be extracted by
145 * gzip.)
146 */
147#ifndef MAX_WBITS
148# define MAX_WBITS 15 /* 32K LZ77 window */
149#endif
150
151/* The memory requirements for deflate are (in bytes):
152 (1 << (windowBits+2)) + (1 << (memLevel+9))
153 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
154 plus a few kilobytes for small objects. For example, if you want to reduce
155 the default memory requirements from 256K to 128K, compile with
156 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
157 Of course this will generally degrade compression (there's no free lunch).
158
159 The memory requirements for inflate are (in bytes) 1 << windowBits
160 that is, 32K for windowBits=15 (default value) plus a few kilobytes
161 for small objects.
162*/
163
164 /* Type declarations */
165
166#ifndef OF /* function prototypes */
167# ifdef STDC
168# define OF(args) args
169# else
170# define OF(args) ()
171# endif
172#endif
173
174/* The following definitions for FAR are needed only for MSDOS mixed
175 * model programming (small or medium model with some far allocations).
176 * This was tested only with MSC; for other MSDOS compilers you may have
177 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
178 * just define FAR to be empty.
179 */
180#ifdef SYS16BIT
181# if defined(M_I86SM) || defined(M_I86MM)
182 /* MSC small or medium model */
183# define SMALL_MEDIUM
184# ifdef _MSC_VER
185# define FAR _far
186# else
187# define FAR far
188# endif
189# endif
190# if (defined(__SMALL__) || defined(__MEDIUM__))
191 /* Turbo C small or medium model */
192# define SMALL_MEDIUM
193# ifdef __BORLANDC__
194# define FAR _far
195# else
196# define FAR far
197# endif
198# endif
199#endif
200
201#if defined(WINDOWS) || defined(WIN32)
202 /* If building or using zlib as a DLL, define ZLIB_DLL.
203 * This is not mandatory, but it offers a little performance increase.
204 */
205# ifdef ZLIB_DLL
206# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
207# ifdef ZLIB_INTERNAL
208# define ZEXTERN extern __declspec(dllexport)
209# else
210# define ZEXTERN extern __declspec(dllimport)
211# endif
212# endif
213# endif /* ZLIB_DLL */
214 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
215 * define ZLIB_WINAPI.
216 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
217 */
218# ifdef ZLIB_WINAPI
219# ifdef FAR
220# undef FAR
221# endif
222# include <windows.h>
223 /* No need for _export, use ZLIB.DEF instead. */
224 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
225# define ZEXPORT WINAPI
226# ifdef WIN32
227# define ZEXPORTVA WINAPIV
228# else
229# define ZEXPORTVA FAR CDECL
230# endif
231# endif
232#endif
233
234#if defined (__BEOS__)
235# ifdef ZLIB_DLL
236# ifdef ZLIB_INTERNAL
237# define ZEXPORT __declspec(dllexport)
238# define ZEXPORTVA __declspec(dllexport)
239# else
240# define ZEXPORT __declspec(dllimport)
241# define ZEXPORTVA __declspec(dllimport)
242# endif
243# endif
244#endif
245
246#ifndef ZEXTERN
247# define ZEXTERN extern
248#endif
249#ifndef ZEXPORT
250# define ZEXPORT
251#endif
252#ifndef ZEXPORTVA
253# define ZEXPORTVA
254#endif
255
256#ifndef FAR
257# define FAR
258#endif
259
260#if !defined(__MACTYPES__)
261typedef unsigned char Byte; /* 8 bits */
262#endif
263typedef unsigned int uInt; /* 16 bits or more */
264typedef unsigned long uLong; /* 32 bits or more */
265
266#ifdef SMALL_MEDIUM
267 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
268# define Bytef Byte FAR
269#else
270 typedef Byte FAR Bytef;
271#endif
272typedef char FAR charf;
273typedef int FAR intf;
274typedef uInt FAR uIntf;
275typedef uLong FAR uLongf;
276
277#ifdef STDC
278 typedef void const *voidpc;
279 typedef void FAR *voidpf;
280 typedef void *voidp;
281#else
282 typedef Byte const *voidpc;
283 typedef Byte FAR *voidpf;
284 typedef Byte *voidp;
285#endif
286
287#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
288# include <sys/types.h> /* for off_t */
289# include <unistd.h> /* for SEEK_* and off_t */
290# ifdef VMS
291# include <unixio.h> /* for off_t */
292# endif
293# define z_off_t off_t
294#endif
295#ifndef SEEK_SET
296# define SEEK_SET 0 /* Seek from beginning of file. */
297# define SEEK_CUR 1 /* Seek from current position. */
298# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
299#endif
300#ifndef z_off_t
301# define z_off_t long
302#endif
303
304#if defined(__OS400__)
305# define NO_vsnprintf
306#endif
307
308#if defined(__MVS__)
309# define NO_vsnprintf
310# ifdef FAR
311# undef FAR
312# endif
313#endif
314
315/* MVS linker does not support external names larger than 8 bytes */
316#if defined(__MVS__)
317# pragma map(deflateInit_,"DEIN")
318# pragma map(deflateInit2_,"DEIN2")
319# pragma map(deflateEnd,"DEEND")
320# pragma map(deflateBound,"DEBND")
321# pragma map(inflateInit_,"ININ")
322# pragma map(inflateInit2_,"ININ2")
323# pragma map(inflateEnd,"INEND")
324# pragma map(inflateSync,"INSY")
325# pragma map(inflateSetDictionary,"INSEDI")
326# pragma map(compressBound,"CMBND")
327# pragma map(inflate_table,"INTABL")
328# pragma map(inflate_fast,"INFA")
329# pragma map(inflate_copyright,"INCOPY")
330#endif
331
332#endif /* ZCONF_H */
diff --git a/contrib/minizip/zconf.in.h b/contrib/minizip/zconf.in.h
new file mode 100644
index 0000000..03a9431
--- /dev/null
+++ b/contrib/minizip/zconf.in.h
@@ -0,0 +1,332 @@
1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#ifndef ZCONF_H
9#define ZCONF_H
10
11/*
12 * If you *really* need a unique prefix for all types and library functions,
13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14 */
15#ifdef Z_PREFIX
16# define deflateInit_ z_deflateInit_
17# define deflate z_deflate
18# define deflateEnd z_deflateEnd
19# define inflateInit_ z_inflateInit_
20# define inflate z_inflate
21# define inflateEnd z_inflateEnd
22# define deflateInit2_ z_deflateInit2_
23# define deflateSetDictionary z_deflateSetDictionary
24# define deflateCopy z_deflateCopy
25# define deflateReset z_deflateReset
26# define deflateParams z_deflateParams
27# define deflateBound z_deflateBound
28# define deflatePrime z_deflatePrime
29# define inflateInit2_ z_inflateInit2_
30# define inflateSetDictionary z_inflateSetDictionary
31# define inflateSync z_inflateSync
32# define inflateSyncPoint z_inflateSyncPoint
33# define inflateCopy z_inflateCopy
34# define inflateReset z_inflateReset
35# define inflateBack z_inflateBack
36# define inflateBackEnd z_inflateBackEnd
37# define compress z_compress
38# define compress2 z_compress2
39# define compressBound z_compressBound
40# define uncompress z_uncompress
41# define adler32 z_adler32
42# define crc32 z_crc32
43# define get_crc_table z_get_crc_table
44# define zError z_zError
45
46# define alloc_func z_alloc_func
47# define free_func z_free_func
48# define in_func z_in_func
49# define out_func z_out_func
50# define Byte z_Byte
51# define uInt z_uInt
52# define uLong z_uLong
53# define Bytef z_Bytef
54# define charf z_charf
55# define intf z_intf
56# define uIntf z_uIntf
57# define uLongf z_uLongf
58# define voidpf z_voidpf
59# define voidp z_voidp
60#endif
61
62#if defined(__MSDOS__) && !defined(MSDOS)
63# define MSDOS
64#endif
65#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
66# define OS2
67#endif
68#if defined(_WINDOWS) && !defined(WINDOWS)
69# define WINDOWS
70#endif
71#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
72# ifndef WIN32
73# define WIN32
74# endif
75#endif
76#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
77# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
78# ifndef SYS16BIT
79# define SYS16BIT
80# endif
81# endif
82#endif
83
84/*
85 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
86 * than 64k bytes at a time (needed on systems with 16-bit int).
87 */
88#ifdef SYS16BIT
89# define MAXSEG_64K
90#endif
91#ifdef MSDOS
92# define UNALIGNED_OK
93#endif
94
95#ifdef __STDC_VERSION__
96# ifndef STDC
97# define STDC
98# endif
99# if __STDC_VERSION__ >= 199901L
100# ifndef STDC99
101# define STDC99
102# endif
103# endif
104#endif
105#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
106# define STDC
107#endif
108#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
109# define STDC
110#endif
111#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
112# define STDC
113#endif
114#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
115# define STDC
116#endif
117
118#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
119# define STDC
120#endif
121
122#ifndef STDC
123# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
124# define const /* note: need a more gentle solution here */
125# endif
126#endif
127
128/* Some Mac compilers merge all .h files incorrectly: */
129#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
130# define NO_DUMMY_DECL
131#endif
132
133/* Maximum value for memLevel in deflateInit2 */
134#ifndef MAX_MEM_LEVEL
135# ifdef MAXSEG_64K
136# define MAX_MEM_LEVEL 8
137# else
138# define MAX_MEM_LEVEL 9
139# endif
140#endif
141
142/* Maximum value for windowBits in deflateInit2 and inflateInit2.
143 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
144 * created by gzip. (Files created by minigzip can still be extracted by
145 * gzip.)
146 */
147#ifndef MAX_WBITS
148# define MAX_WBITS 15 /* 32K LZ77 window */
149#endif
150
151/* The memory requirements for deflate are (in bytes):
152 (1 << (windowBits+2)) + (1 << (memLevel+9))
153 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
154 plus a few kilobytes for small objects. For example, if you want to reduce
155 the default memory requirements from 256K to 128K, compile with
156 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
157 Of course this will generally degrade compression (there's no free lunch).
158
159 The memory requirements for inflate are (in bytes) 1 << windowBits
160 that is, 32K for windowBits=15 (default value) plus a few kilobytes
161 for small objects.
162*/
163
164 /* Type declarations */
165
166#ifndef OF /* function prototypes */
167# ifdef STDC
168# define OF(args) args
169# else
170# define OF(args) ()
171# endif
172#endif
173
174/* The following definitions for FAR are needed only for MSDOS mixed
175 * model programming (small or medium model with some far allocations).
176 * This was tested only with MSC; for other MSDOS compilers you may have
177 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
178 * just define FAR to be empty.
179 */
180#ifdef SYS16BIT
181# if defined(M_I86SM) || defined(M_I86MM)
182 /* MSC small or medium model */
183# define SMALL_MEDIUM
184# ifdef _MSC_VER
185# define FAR _far
186# else
187# define FAR far
188# endif
189# endif
190# if (defined(__SMALL__) || defined(__MEDIUM__))
191 /* Turbo C small or medium model */
192# define SMALL_MEDIUM
193# ifdef __BORLANDC__
194# define FAR _far
195# else
196# define FAR far
197# endif
198# endif
199#endif
200
201#if defined(WINDOWS) || defined(WIN32)
202 /* If building or using zlib as a DLL, define ZLIB_DLL.
203 * This is not mandatory, but it offers a little performance increase.
204 */
205# ifdef ZLIB_DLL
206# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
207# ifdef ZLIB_INTERNAL
208# define ZEXTERN extern __declspec(dllexport)
209# else
210# define ZEXTERN extern __declspec(dllimport)
211# endif
212# endif
213# endif /* ZLIB_DLL */
214 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
215 * define ZLIB_WINAPI.
216 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
217 */
218# ifdef ZLIB_WINAPI
219# ifdef FAR
220# undef FAR
221# endif
222# include <windows.h>
223 /* No need for _export, use ZLIB.DEF instead. */
224 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
225# define ZEXPORT WINAPI
226# ifdef WIN32
227# define ZEXPORTVA WINAPIV
228# else
229# define ZEXPORTVA FAR CDECL
230# endif
231# endif
232#endif
233
234#if defined (__BEOS__)
235# ifdef ZLIB_DLL
236# ifdef ZLIB_INTERNAL
237# define ZEXPORT __declspec(dllexport)
238# define ZEXPORTVA __declspec(dllexport)
239# else
240# define ZEXPORT __declspec(dllimport)
241# define ZEXPORTVA __declspec(dllimport)
242# endif
243# endif
244#endif
245
246#ifndef ZEXTERN
247# define ZEXTERN extern
248#endif
249#ifndef ZEXPORT
250# define ZEXPORT
251#endif
252#ifndef ZEXPORTVA
253# define ZEXPORTVA
254#endif
255
256#ifndef FAR
257# define FAR
258#endif
259
260#if !defined(__MACTYPES__)
261typedef unsigned char Byte; /* 8 bits */
262#endif
263typedef unsigned int uInt; /* 16 bits or more */
264typedef unsigned long uLong; /* 32 bits or more */
265
266#ifdef SMALL_MEDIUM
267 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
268# define Bytef Byte FAR
269#else
270 typedef Byte FAR Bytef;
271#endif
272typedef char FAR charf;
273typedef int FAR intf;
274typedef uInt FAR uIntf;
275typedef uLong FAR uLongf;
276
277#ifdef STDC
278 typedef void const *voidpc;
279 typedef void FAR *voidpf;
280 typedef void *voidp;
281#else
282 typedef Byte const *voidpc;
283 typedef Byte FAR *voidpf;
284 typedef Byte *voidp;
285#endif
286
287#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
288# include <sys/types.h> /* for off_t */
289# include <unistd.h> /* for SEEK_* and off_t */
290# ifdef VMS
291# include <unixio.h> /* for off_t */
292# endif
293# define z_off_t off_t
294#endif
295#ifndef SEEK_SET
296# define SEEK_SET 0 /* Seek from beginning of file. */
297# define SEEK_CUR 1 /* Seek from current position. */
298# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
299#endif
300#ifndef z_off_t
301# define z_off_t long
302#endif
303
304#if defined(__OS400__)
305# define NO_vsnprintf
306#endif
307
308#if defined(__MVS__)
309# define NO_vsnprintf
310# ifdef FAR
311# undef FAR
312# endif
313#endif
314
315/* MVS linker does not support external names larger than 8 bytes */
316#if defined(__MVS__)
317# pragma map(deflateInit_,"DEIN")
318# pragma map(deflateInit2_,"DEIN2")
319# pragma map(deflateEnd,"DEEND")
320# pragma map(deflateBound,"DEBND")
321# pragma map(inflateInit_,"ININ")
322# pragma map(inflateInit2_,"ININ2")
323# pragma map(inflateEnd,"INEND")
324# pragma map(inflateSync,"INSY")
325# pragma map(inflateSetDictionary,"INSEDI")
326# pragma map(compressBound,"CMBND")
327# pragma map(inflate_table,"INTABL")
328# pragma map(inflate_fast,"INFA")
329# pragma map(inflate_copyright,"INCOPY")
330#endif
331
332#endif /* ZCONF_H */
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 7fbe002..e12da4c 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -1,12 +1,23 @@
1/* zip.c -- IO on .zip files using zlib 1/* zip.c -- IO on .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, January 7th, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 4
4 27 Dec 2004 Rolf Kalbermatter 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5 Modification to zipOpen2 to support globalComment retrieval.
6 6
7 Copyright (C) 1998-2005 Gilles Vollant 7 Modifications for Zip64 support
8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9
10 For more info read MiniZip_info.txt
11
12 Changes
13 Okt-2009 - Mathias Svensson - Remove old C style function prototypes
14 Okt-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
15 Okt-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
16 Okt-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
17 It is used when recreting zip archive with RAW when deleting items from a zip.
18 ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed.
19 Okt-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
8 20
9 Read zip.h for more info
10*/ 21*/
11 22
12 23
@@ -39,7 +50,7 @@
39#endif 50#endif
40 51
41#ifndef Z_BUFSIZE 52#ifndef Z_BUFSIZE
42#define Z_BUFSIZE (16384) 53#define Z_BUFSIZE (64*1024) //(16384)
43#endif 54#endif
44 55
45#ifndef Z_MAXFILENAMEINZIP 56#ifndef Z_MAXFILENAMEINZIP
@@ -60,6 +71,10 @@
60 71
61/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 72/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
62 73
74
75// NOT sure that this work on ALL platform
76#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
77
63#ifndef SEEK_CUR 78#ifndef SEEK_CUR
64#define SEEK_CUR 1 79#define SEEK_CUR 1
65#endif 80#endif
@@ -79,8 +94,7 @@
79# define DEF_MEM_LEVEL MAX_MEM_LEVEL 94# define DEF_MEM_LEVEL MAX_MEM_LEVEL
80#endif 95#endif
81#endif 96#endif
82const char zip_copyright[] = 97const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
83 " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
84 98
85 99
86#define SIZEDATA_INDATABLOCK (4096-(4*4)) 100#define SIZEDATA_INDATABLOCK (4096-(4*4))
@@ -88,6 +102,8 @@ const char zip_copyright[] =
88#define LOCALHEADERMAGIC (0x04034b50) 102#define LOCALHEADERMAGIC (0x04034b50)
89#define CENTRALHEADERMAGIC (0x02014b50) 103#define CENTRALHEADERMAGIC (0x02014b50)
90#define ENDHEADERMAGIC (0x06054b50) 104#define ENDHEADERMAGIC (0x06054b50)
105#define ZIP64ENDHEADERMAGIC (0x6064b50)
106#define ZIP64ENDLOCHEADERMAGIC (0x7064b50)
91 107
92#define FLAG_LOCALHEADER_OFFSET (0x06) 108#define FLAG_LOCALHEADER_OFFSET (0x06)
93#define CRC_LOCALHEADER_OFFSET (0x0e) 109#define CRC_LOCALHEADER_OFFSET (0x0e)
@@ -113,13 +129,19 @@ typedef struct linkedlist_data_s
113typedef struct 129typedef struct
114{ 130{
115 z_stream stream; /* zLib stream structure for inflate */ 131 z_stream stream; /* zLib stream structure for inflate */
132#ifdef HAVE_BZIP2
133 bz_stream bstream; /* bzLib stream structure for bziped */
134#endif
135
116 int stream_initialised; /* 1 is stream is initialised */ 136 int stream_initialised; /* 1 is stream is initialised */
117 uInt pos_in_buffered_data; /* last written byte in buffered_data */ 137 uInt pos_in_buffered_data; /* last written byte in buffered_data */
118 138
119 uLong pos_local_header; /* offset of the local header of the file 139 ZPOS64_T pos_local_header; /* offset of the local header of the file
120 currenty writing */ 140 currenty writing */
121 char* central_header; /* central header data for the current file */ 141 char* central_header; /* central header data for the current file */
142 uLong size_centralExtra;
122 uLong size_centralheader; /* size of the central header for cur file */ 143 uLong size_centralheader; /* size of the central header for cur file */
144 uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
123 uLong flag; /* flag of the file currently writing */ 145 uLong flag; /* flag of the file currently writing */
124 146
125 int method; /* compression method of file currenty wr.*/ 147 int method; /* compression method of file currenty wr.*/
@@ -128,29 +150,34 @@ typedef struct
128 uLong dosDate; 150 uLong dosDate;
129 uLong crc32; 151 uLong crc32;
130 int encrypt; 152 int encrypt;
153 int zip64; /* Add ZIP64 extened information in the extra field */
154 ZPOS64_T pos_zip64extrainfo;
155 ZPOS64_T totalCompressedData;
156 ZPOS64_T totalUncompressedData;
131#ifndef NOCRYPT 157#ifndef NOCRYPT
132 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 158 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
133 const unsigned long* pcrc_32_tab; 159 const unsigned long* pcrc_32_tab;
134 int crypt_header_size; 160 int crypt_header_size;
135#endif 161#endif
136} curfile_info; 162} curfile64_info;
137 163
138typedef struct 164typedef struct
139{ 165{
140 zlib_filefunc_def z_filefunc; 166 zlib_filefunc64_32_def z_filefunc;
141 voidpf filestream; /* io structore of the zipfile */ 167 voidpf filestream; /* io structore of the zipfile */
142 linkedlist_data central_dir;/* datablock with central dir in construction*/ 168 linkedlist_data central_dir;/* datablock with central dir in construction*/
143 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ 169 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
144 curfile_info ci; /* info on the file curretly writing */ 170 curfile64_info ci; /* info on the file curretly writing */
171
172 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
173 ZPOS64_T add_position_when_writting_offset;
174 ZPOS64_T number_entry;
145 175
146 uLong begin_pos; /* position of the beginning of the zipfile */
147 uLong add_position_when_writting_offset;
148 uLong number_entry;
149#ifndef NO_ADDFILEINEXISTINGZIP 176#ifndef NO_ADDFILEINEXISTINGZIP
150 char *globalcomment; 177 char *globalcomment;
151#endif 178#endif
152} zip_internal;
153 179
180} zip64_internal;
154 181
155 182
156#ifndef NOCRYPT 183#ifndef NOCRYPT
@@ -172,8 +199,7 @@ local linkedlist_datablock_internal* allocate_new_datablock()
172 return ldi; 199 return ldi;
173} 200}
174 201
175local void free_datablock(ldi) 202local void free_datablock(linkedlist_datablock_internal* ldi)
176 linkedlist_datablock_internal* ldi;
177{ 203{
178 while (ldi!=NULL) 204 while (ldi!=NULL)
179 { 205 {
@@ -183,24 +209,19 @@ local void free_datablock(ldi)
183 } 209 }
184} 210}
185 211
186local void init_linkedlist(ll) 212local void init_linkedlist(linkedlist_data* ll)
187 linkedlist_data* ll;
188{ 213{
189 ll->first_block = ll->last_block = NULL; 214 ll->first_block = ll->last_block = NULL;
190} 215}
191 216
192local void free_linkedlist(ll) 217local void free_linkedlist(linkedlist_data* ll)
193 linkedlist_data* ll;
194{ 218{
195 free_datablock(ll->first_block); 219 free_datablock(ll->first_block);
196 ll->first_block = ll->last_block = NULL; 220 ll->first_block = ll->last_block = NULL;
197} 221}
198 222
199 223
200local int add_data_in_datablock(ll,buf,len) 224local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
201 linkedlist_data* ll;
202 const void* buf;
203 uLong len;
204{ 225{
205 linkedlist_datablock_internal* ldi; 226 linkedlist_datablock_internal* ldi;
206 const unsigned char* from_copy; 227 const unsigned char* from_copy;
@@ -258,18 +279,13 @@ local int add_data_in_datablock(ll,buf,len)
258#ifndef NO_ADDFILEINEXISTINGZIP 279#ifndef NO_ADDFILEINEXISTINGZIP
259/* =========================================================================== 280/* ===========================================================================
260 Inputs a long in LSB order to the given file 281 Inputs a long in LSB order to the given file
261 nbByte == 1, 2 or 4 (byte, short or long) 282 nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
262*/ 283*/
263 284
264local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, 285local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
265 voidpf filestream, uLong x, int nbByte)); 286local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
266local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
267 const zlib_filefunc_def* pzlib_filefunc_def;
268 voidpf filestream;
269 uLong x;
270 int nbByte;
271{ 287{
272 unsigned char buf[4]; 288 unsigned char buf[8];
273 int n; 289 int n;
274 for (n = 0; n < nbByte; n++) 290 for (n = 0; n < nbByte; n++)
275 { 291 {
@@ -284,17 +300,14 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
284 } 300 }
285 } 301 }
286 302
287 if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) 303 if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
288 return ZIP_ERRNO; 304 return ZIP_ERRNO;
289 else 305 else
290 return ZIP_OK; 306 return ZIP_OK;
291} 307}
292 308
293local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); 309local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
294local void ziplocal_putValue_inmemory (dest, x, nbByte) 310local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
295 void* dest;
296 uLong x;
297 int nbByte;
298{ 311{
299 unsigned char* buf=(unsigned char*)dest; 312 unsigned char* buf=(unsigned char*)dest;
300 int n; 313 int n;
@@ -315,14 +328,12 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte)
315/****************************************************************************/ 328/****************************************************************************/
316 329
317 330
318local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) 331local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
319 const tm_zip* ptm;
320 uLong dosDate;
321{ 332{
322 uLong year = (uLong)ptm->tm_year; 333 uLong year = (uLong)ptm->tm_year;
323 if (year>1980) 334 if (year>=1980)
324 year-=1980; 335 year-=1980;
325 else if (year>80) 336 else if (year>=80)
326 year-=80; 337 year-=80;
327 return 338 return
328 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | 339 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
@@ -332,18 +343,12 @@ local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
332 343
333/****************************************************************************/ 344/****************************************************************************/
334 345
335local int ziplocal_getByte OF(( 346local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
336 const zlib_filefunc_def* pzlib_filefunc_def,
337 voidpf filestream,
338 int *pi));
339 347
340local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) 348local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
341 const zlib_filefunc_def* pzlib_filefunc_def;
342 voidpf filestream;
343 int *pi;
344{ 349{
345 unsigned char c; 350 unsigned char c;
346 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 351 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
347 if (err==1) 352 if (err==1)
348 { 353 {
349 *pi = (int)c; 354 *pi = (int)c;
@@ -351,7 +356,7 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
351 } 356 }
352 else 357 else
353 { 358 {
354 if (ZERROR(*pzlib_filefunc_def,filestream)) 359 if (ZERROR64(*pzlib_filefunc_def,filestream))
355 return ZIP_ERRNO; 360 return ZIP_ERRNO;
356 else 361 else
357 return ZIP_EOF; 362 return ZIP_EOF;
@@ -362,25 +367,19 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
362/* =========================================================================== 367/* ===========================================================================
363 Reads a long in LSB order from the given gz_stream. Sets 368 Reads a long in LSB order from the given gz_stream. Sets
364*/ 369*/
365local int ziplocal_getShort OF(( 370local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
366 const zlib_filefunc_def* pzlib_filefunc_def, 371
367 voidpf filestream, 372local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
368 uLong *pX));
369
370local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
371 const zlib_filefunc_def* pzlib_filefunc_def;
372 voidpf filestream;
373 uLong *pX;
374{ 373{
375 uLong x ; 374 uLong x ;
376 int i; 375 int i = 0;
377 int err; 376 int err;
378 377
379 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 378 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
380 x = (uLong)i; 379 x = (uLong)i;
381 380
382 if (err==ZIP_OK) 381 if (err==ZIP_OK)
383 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 382 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
384 x += ((uLong)i)<<8; 383 x += ((uLong)i)<<8;
385 384
386 if (err==ZIP_OK) 385 if (err==ZIP_OK)
@@ -390,33 +389,27 @@ local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
390 return err; 389 return err;
391} 390}
392 391
393local int ziplocal_getLong OF(( 392local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
394 const zlib_filefunc_def* pzlib_filefunc_def,
395 voidpf filestream,
396 uLong *pX));
397 393
398local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) 394local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
399 const zlib_filefunc_def* pzlib_filefunc_def;
400 voidpf filestream;
401 uLong *pX;
402{ 395{
403 uLong x ; 396 uLong x ;
404 int i; 397 int i = 0;
405 int err; 398 int err;
406 399
407 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 400 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
408 x = (uLong)i; 401 x = (uLong)i;
409 402
410 if (err==ZIP_OK) 403 if (err==ZIP_OK)
411 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 404 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
412 x += ((uLong)i)<<8; 405 x += ((uLong)i)<<8;
413 406
414 if (err==ZIP_OK) 407 if (err==ZIP_OK)
415 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 408 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
416 x += ((uLong)i)<<16; 409 x += ((uLong)i)<<16;
417 410
418 if (err==ZIP_OK) 411 if (err==ZIP_OK)
419 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 412 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
420 x += ((uLong)i)<<24; 413 x += ((uLong)i)<<24;
421 414
422 if (err==ZIP_OK) 415 if (err==ZIP_OK)
@@ -426,6 +419,54 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
426 return err; 419 return err;
427} 420}
428 421
422local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
423
424
425local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
426{
427 ZPOS64_T x;
428 int i = 0;
429 int err;
430
431 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
432 x = (ZPOS64_T)i;
433
434 if (err==ZIP_OK)
435 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
436 x += ((ZPOS64_T)i)<<8;
437
438 if (err==ZIP_OK)
439 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
440 x += ((ZPOS64_T)i)<<16;
441
442 if (err==ZIP_OK)
443 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
444 x += ((ZPOS64_T)i)<<24;
445
446 if (err==ZIP_OK)
447 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
448 x += ((ZPOS64_T)i)<<32;
449
450 if (err==ZIP_OK)
451 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
452 x += ((ZPOS64_T)i)<<40;
453
454 if (err==ZIP_OK)
455 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
456 x += ((ZPOS64_T)i)<<48;
457
458 if (err==ZIP_OK)
459 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
460 x += ((ZPOS64_T)i)<<56;
461
462 if (err==ZIP_OK)
463 *pX = x;
464 else
465 *pX = 0;
466
467 return err;
468}
469
429#ifndef BUFREADCOMMENT 470#ifndef BUFREADCOMMENT
430#define BUFREADCOMMENT (0x400) 471#define BUFREADCOMMENT (0x400)
431#endif 472#endif
@@ -433,87 +474,391 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
433 Locate the Central directory of a zipfile (at the end, just before 474 Locate the Central directory of a zipfile (at the end, just before
434 the global comment) 475 the global comment)
435*/ 476*/
436local uLong ziplocal_SearchCentralDir OF(( 477local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
437 const zlib_filefunc_def* pzlib_filefunc_def,
438 voidpf filestream));
439 478
440local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) 479local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
441 const zlib_filefunc_def* pzlib_filefunc_def;
442 voidpf filestream;
443{ 480{
444 unsigned char* buf; 481 unsigned char* buf;
445 uLong uSizeFile; 482 ZPOS64_T uSizeFile;
446 uLong uBackRead; 483 ZPOS64_T uBackRead;
447 uLong uMaxBack=0xffff; /* maximum size of global comment */ 484 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
448 uLong uPosFound=0; 485 ZPOS64_T uPosFound=0;
486
487 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
488 return 0;
489
490
491 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
492
493 if (uMaxBack>uSizeFile)
494 uMaxBack = uSizeFile;
495
496 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
497 if (buf==NULL)
498 return 0;
499
500 uBackRead = 4;
501 while (uBackRead<uMaxBack)
502 {
503 uLong uReadSize;
504 ZPOS64_T uReadPos ;
505 int i;
506 if (uBackRead+BUFREADCOMMENT>uMaxBack)
507 uBackRead = uMaxBack;
508 else
509 uBackRead+=BUFREADCOMMENT;
510 uReadPos = uSizeFile-uBackRead ;
511
512 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
513 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
514 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
515 break;
516
517 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
518 break;
519
520 for (i=(int)uReadSize-3; (i--)>0;)
521 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
522 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
523 {
524 uPosFound = uReadPos+i;
525 break;
526 }
449 527
450 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 528 if (uPosFound!=0)
451 return 0; 529 break;
530 }
531 TRYFREE(buf);
532 return uPosFound;
533}
452 534
535/*
536Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
537the global comment)
538*/
539local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
453 540
454 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 541local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
542{
543 unsigned char* buf;
544 ZPOS64_T uSizeFile;
545 ZPOS64_T uBackRead;
546 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
547 ZPOS64_T uPosFound=0;
548 uLong uL;
549 ZPOS64_T relativeOffset;
550
551 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
552 return 0;
553
554 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
555
556 if (uMaxBack>uSizeFile)
557 uMaxBack = uSizeFile;
558
559 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
560 if (buf==NULL)
561 return 0;
562
563 uBackRead = 4;
564 while (uBackRead<uMaxBack)
565 {
566 uLong uReadSize;
567 ZPOS64_T uReadPos;
568 int i;
569 if (uBackRead+BUFREADCOMMENT>uMaxBack)
570 uBackRead = uMaxBack;
571 else
572 uBackRead+=BUFREADCOMMENT;
573 uReadPos = uSizeFile-uBackRead ;
455 574
456 if (uMaxBack>uSizeFile) 575 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
457 uMaxBack = uSizeFile; 576 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
577 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
578 break;
458 579
459 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 580 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
460 if (buf==NULL) 581 break;
461 return 0;
462 582
463 uBackRead = 4; 583 for (i=(int)uReadSize-3; (i--)>0;)
464 while (uBackRead<uMaxBack)
465 { 584 {
466 uLong uReadSize,uReadPos ; 585 // Signature "0x07064b50" Zip64 end of central directory locater
467 int i; 586 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
468 if (uBackRead+BUFREADCOMMENT>uMaxBack) 587 {
469 uBackRead = uMaxBack; 588 uPosFound = uReadPos+i;
470 else 589 break;
471 uBackRead+=BUFREADCOMMENT; 590 }
472 uReadPos = uSizeFile-uBackRead ; 591 }
473 592
474 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 593 if (uPosFound!=0)
475 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 594 break;
476 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 595 }
477 break;
478 596
479 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 597 TRYFREE(buf);
480 break; 598 if (uPosFound == 0)
599 return 0;
481 600
482 for (i=(int)uReadSize-3; (i--)>0;) 601 /* Zip64 end of central directory locator */
483 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 602 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
484 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 603 return 0;
485 { 604
486 uPosFound = uReadPos+i; 605 /* the signature, already checked */
487 break; 606 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
488 } 607 return 0;
489 608
490 if (uPosFound!=0) 609 /* number of the disk with the start of the zip64 end of central directory */
491 break; 610 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
611 return 0;
612 if (uL != 0)
613 return 0;
614
615 /* relative offset of the zip64 end of central directory record */
616 if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
617 return 0;
618
619 /* total number of disks */
620 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
621 return 0;
622 if (uL != 1)
623 return 0;
624
625 /* Goto Zip64 end of central directory record */
626 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
627 return 0;
628
629 /* the signature */
630 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
631 return 0;
632
633 if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
634 return 0;
635
636 return relativeOffset;
637}
638
639int LoadCentralDirectoryRecord(zip64_internal* pziinit)
640{
641 int err=ZIP_OK;
642 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
643
644 ZPOS64_T size_central_dir; /* size of the central directory */
645 ZPOS64_T offset_central_dir; /* offset of start of central directory */
646 ZPOS64_T central_pos;
647 uLong uL;
648
649 uLong number_disk; /* number of the current dist, used for
650 spaning ZIP, unsupported, always 0*/
651 uLong number_disk_with_CD; /* number the the disk with central dir, used
652 for spaning ZIP, unsupported, always 0*/
653 ZPOS64_T number_entry;
654 ZPOS64_T number_entry_CD; /* total number of entries in
655 the central dir
656 (same than number_entry on nospan) */
657 uLong VersionMadeBy;
658 uLong VersionNeeded;
659 uLong size_comment;
660
661 int hasZIP64Record = 0;
662
663 // check first if we find a ZIP64 record
664 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
665 if(central_pos > 0)
666 {
667 hasZIP64Record = 1;
668 }
669 else if(central_pos == 0)
670 {
671 central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
672 }
673
674/* disable to allow appending to empty ZIP archive
675 if (central_pos==0)
676 err=ZIP_ERRNO;
677*/
678
679 if(hasZIP64Record)
680 {
681 ZPOS64_T sizeEndOfCentralDirectory;
682 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
683 err=ZIP_ERRNO;
684
685 /* the signature, already checked */
686 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
687 err=ZIP_ERRNO;
688
689 /* size of zip64 end of central directory record */
690 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
691 err=ZIP_ERRNO;
692
693 /* version made by */
694 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
695 err=ZIP_ERRNO;
696
697 /* version needed to extract */
698 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
699 err=ZIP_ERRNO;
700
701 /* number of this disk */
702 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
703 err=ZIP_ERRNO;
704
705 /* number of the disk with the start of the central directory */
706 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
707 err=ZIP_ERRNO;
708
709 /* total number of entries in the central directory on this disk */
710 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
711 err=ZIP_ERRNO;
712
713 /* total number of entries in the central directory */
714 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
715 err=ZIP_ERRNO;
716
717 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
718 err=ZIP_BADZIPFILE;
719
720 /* size of the central directory */
721 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
722 err=ZIP_ERRNO;
723
724 /* offset of start of central directory with respect to the
725 starting disk number */
726 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
727 err=ZIP_ERRNO;
728
729 // TODO..
730 // read the comment from the standard central header.
731 size_comment = 0;
732 }
733 else
734 {
735 // Read End of central Directory info
736 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
737 err=ZIP_ERRNO;
738
739 /* the signature, already checked */
740 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
741 err=ZIP_ERRNO;
742
743 /* number of this disk */
744 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
745 err=ZIP_ERRNO;
746
747 /* number of the disk with the start of the central directory */
748 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
749 err=ZIP_ERRNO;
750
751 /* total number of entries in the central dir on this disk */
752 number_entry = 0;
753 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
754 err=ZIP_ERRNO;
755 else
756 number_entry = uL;
757
758 /* total number of entries in the central dir */
759 number_entry_CD = 0;
760 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
761 err=ZIP_ERRNO;
762 else
763 number_entry_CD = uL;
764
765 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
766 err=ZIP_BADZIPFILE;
767
768 /* size of the central directory */
769 size_central_dir = 0;
770 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
771 err=ZIP_ERRNO;
772 else
773 size_central_dir = uL;
774
775 /* offset of start of central directory with respect to the starting disk number */
776 offset_central_dir = 0;
777 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
778 err=ZIP_ERRNO;
779 else
780 offset_central_dir = uL;
781
782
783 /* zipfile global comment length */
784 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
785 err=ZIP_ERRNO;
786 }
787
788 if ((central_pos<offset_central_dir+size_central_dir) &&
789 (err==ZIP_OK))
790 err=ZIP_BADZIPFILE;
791
792 if (err!=ZIP_OK)
793 {
794 ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
795 return ZIP_ERRNO;
796 }
797
798 if (size_comment>0)
799 {
800 pziinit->globalcomment = (char*)ALLOC(size_comment+1);
801 if (pziinit->globalcomment)
802 {
803 size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
804 pziinit->globalcomment[size_comment]=0;
805 }
806 }
807
808 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
809 pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
810
811 {
812 ZPOS64_T size_central_dir_to_read = size_central_dir;
813 size_t buf_size = SIZEDATA_INDATABLOCK;
814 void* buf_read = (void*)ALLOC(buf_size);
815 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
816 err=ZIP_ERRNO;
817
818 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
819 {
820 ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
821 if (read_this > size_central_dir_to_read)
822 read_this = size_central_dir_to_read;
823
824 if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
825 err=ZIP_ERRNO;
826
827 if (err==ZIP_OK)
828 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
829
830 size_central_dir_to_read-=read_this;
492 } 831 }
493 TRYFREE(buf); 832 TRYFREE(buf_read);
494 return uPosFound; 833 }
834 pziinit->begin_pos = byte_before_the_zipfile;
835 pziinit->number_entry = number_entry_CD;
836
837 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
838 err=ZIP_ERRNO;
839
840 return err;
495} 841}
842
843
496#endif /* !NO_ADDFILEINEXISTINGZIP*/ 844#endif /* !NO_ADDFILEINEXISTINGZIP*/
497 845
846
498/************************************************************/ 847/************************************************************/
499extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) 848extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
500 const char *pathname;
501 int append;
502 zipcharpc* globalcomment;
503 zlib_filefunc_def* pzlib_filefunc_def;
504{ 849{
505 zip_internal ziinit; 850 zip64_internal ziinit;
506 zip_internal* zi; 851 zip64_internal* zi;
507 int err=ZIP_OK; 852 int err=ZIP_OK;
508 853
509 854 ziinit.z_filefunc.zseek32_file = NULL;
510 if (pzlib_filefunc_def==NULL) 855 ziinit.z_filefunc.ztell32_file = NULL;
511 fill_fopen_filefunc(&ziinit.z_filefunc); 856 if (pzlib_filefunc64_32_def==NULL)
857 fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
512 else 858 else
513 ziinit.z_filefunc = *pzlib_filefunc_def; 859 ziinit.z_filefunc = *pzlib_filefunc64_32_def;
514 860
515 ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) 861 ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
516 (ziinit.z_filefunc.opaque,
517 pathname, 862 pathname,
518 (append == APPEND_STATUS_CREATE) ? 863 (append == APPEND_STATUS_CREATE) ?
519 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : 864 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
@@ -521,7 +866,11 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
521 866
522 if (ziinit.filestream == NULL) 867 if (ziinit.filestream == NULL)
523 return NULL; 868 return NULL;
524 ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); 869
870 if (append == APPEND_STATUS_CREATEAFTER)
871 ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
872
873 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
525 ziinit.in_opened_file_inzip = 0; 874 ziinit.in_opened_file_inzip = 0;
526 ziinit.ci.stream_initialised = 0; 875 ziinit.ci.stream_initialised = 0;
527 ziinit.number_entry = 0; 876 ziinit.number_entry = 0;
@@ -529,10 +878,11 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
529 init_linkedlist(&(ziinit.central_dir)); 878 init_linkedlist(&(ziinit.central_dir));
530 879
531 880
532 zi = (zip_internal*)ALLOC(sizeof(zip_internal)); 881
882 zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
533 if (zi==NULL) 883 if (zi==NULL)
534 { 884 {
535 ZCLOSE(ziinit.z_filefunc,ziinit.filestream); 885 ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
536 return NULL; 886 return NULL;
537 } 887 }
538 888
@@ -541,122 +891,8 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
541 ziinit.globalcomment = NULL; 891 ziinit.globalcomment = NULL;
542 if (append == APPEND_STATUS_ADDINZIP) 892 if (append == APPEND_STATUS_ADDINZIP)
543 { 893 {
544 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 894 // Read and Cache Central Directory Records
545 895 err = LoadCentralDirectoryRecord(&ziinit);
546 uLong size_central_dir; /* size of the central directory */
547 uLong offset_central_dir; /* offset of start of central directory */
548 uLong central_pos,uL;
549
550 uLong number_disk; /* number of the current dist, used for
551 spaning ZIP, unsupported, always 0*/
552 uLong number_disk_with_CD; /* number the the disk with central dir, used
553 for spaning ZIP, unsupported, always 0*/
554 uLong number_entry;
555 uLong number_entry_CD; /* total number of entries in
556 the central dir
557 (same than number_entry on nospan) */
558 uLong size_comment;
559
560 central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
561 if (central_pos==0)
562 err=ZIP_ERRNO;
563
564 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
565 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
566 err=ZIP_ERRNO;
567
568 /* the signature, already checked */
569 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)
570 err=ZIP_ERRNO;
571
572 /* number of this disk */
573 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)
574 err=ZIP_ERRNO;
575
576 /* number of the disk with the start of the central directory */
577 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)
578 err=ZIP_ERRNO;
579
580 /* total number of entries in the central dir on this disk */
581 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)
582 err=ZIP_ERRNO;
583
584 /* total number of entries in the central dir */
585 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)
586 err=ZIP_ERRNO;
587
588 if ((number_entry_CD!=number_entry) ||
589 (number_disk_with_CD!=0) ||
590 (number_disk!=0))
591 err=ZIP_BADZIPFILE;
592
593 /* size of the central directory */
594 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)
595 err=ZIP_ERRNO;
596
597 /* offset of start of central directory with respect to the
598 starting disk number */
599 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
600 err=ZIP_ERRNO;
601
602 /* zipfile global comment length */
603 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
604 err=ZIP_ERRNO;
605
606 if ((central_pos<offset_central_dir+size_central_dir) &&
607 (err==ZIP_OK))
608 err=ZIP_BADZIPFILE;
609
610 if (err!=ZIP_OK)
611 {
612 ZCLOSE(ziinit.z_filefunc, ziinit.filestream);
613 return NULL;
614 }
615
616 if (size_comment>0)
617 {
618 ziinit.globalcomment = ALLOC(size_comment+1);
619 if (ziinit.globalcomment)
620 {
621 size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment);
622 ziinit.globalcomment[size_comment]=0;
623 }
624 }
625
626 byte_before_the_zipfile = central_pos -
627 (offset_central_dir+size_central_dir);
628 ziinit.add_position_when_writting_offset = byte_before_the_zipfile;
629
630 {
631 uLong size_central_dir_to_read = size_central_dir;
632 size_t buf_size = SIZEDATA_INDATABLOCK;
633 void* buf_read = (void*)ALLOC(buf_size);
634 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
635 offset_central_dir + byte_before_the_zipfile,
636 ZLIB_FILEFUNC_SEEK_SET) != 0)
637 err=ZIP_ERRNO;
638
639 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
640 {
641 uLong read_this = SIZEDATA_INDATABLOCK;
642 if (read_this > size_central_dir_to_read)
643 read_this = size_central_dir_to_read;
644 if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)
645 err=ZIP_ERRNO;
646
647 if (err==ZIP_OK)
648 err = add_data_in_datablock(&ziinit.central_dir,buf_read,
649 (uLong)read_this);
650 size_central_dir_to_read-=read_this;
651 }
652 TRYFREE(buf_read);
653 }
654 ziinit.begin_pos = byte_before_the_zipfile;
655 ziinit.number_entry = number_entry_CD;
656
657 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
658 offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
659 err=ZIP_ERRNO;
660 } 896 }
661 897
662 if (globalcomment) 898 if (globalcomment)
@@ -680,37 +916,150 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
680 } 916 }
681} 917}
682 918
683extern zipFile ZEXPORT zipOpen (pathname, append) 919extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
684 const char *pathname; 920{
685 int append; 921 if (pzlib_filefunc32_def != NULL)
922 {
923 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
924 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
925 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
926 }
927 else
928 return zipOpen3(pathname, append, globalcomment, NULL);
929}
930
931extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
932{
933 if (pzlib_filefunc_def != NULL)
934 {
935 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
936 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
937 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
938 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
939 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
940 }
941 else
942 return zipOpen3(pathname, append, globalcomment, NULL);
943}
944
945
946
947extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
948{
949 return zipOpen3((const void*)pathname,append,NULL,NULL);
950}
951
952extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
686{ 953{
687 return zipOpen2(pathname,append,NULL,NULL); 954 return zipOpen3(pathname,append,NULL,NULL);
688} 955}
689 956
690extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, 957int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
691 extrafield_local, size_extrafield_local,
692 extrafield_global, size_extrafield_global,
693 comment, method, level, raw,
694 windowBits, memLevel, strategy,
695 password, crcForCrypting)
696 zipFile file;
697 const char* filename;
698 const zip_fileinfo* zipfi;
699 const void* extrafield_local;
700 uInt size_extrafield_local;
701 const void* extrafield_global;
702 uInt size_extrafield_global;
703 const char* comment;
704 int method;
705 int level;
706 int raw;
707 int windowBits;
708 int memLevel;
709 int strategy;
710 const char* password;
711 uLong crcForCrypting;
712{ 958{
713 zip_internal* zi; 959 /* write the local header */
960 int err;
961 uInt size_filename = (uInt)strlen(filename);
962 uInt size_extrafield = size_extrafield_local;
963
964 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
965
966 if (err==ZIP_OK)
967 {
968 if(zi->ci.zip64)
969 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
970 else
971 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
972 }
973
974 if (err==ZIP_OK)
975 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
976
977 if (err==ZIP_OK)
978 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
979
980 if (err==ZIP_OK)
981 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
982
983 // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
984 if (err==ZIP_OK)
985 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
986 if (err==ZIP_OK)
987 {
988 if(zi->ci.zip64)
989 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
990 else
991 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
992 }
993 if (err==ZIP_OK)
994 {
995 if(zi->ci.zip64)
996 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
997 else
998 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
999 }
1000
1001 if (err==ZIP_OK)
1002 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
1003
1004 if(zi->ci.zip64)
1005 {
1006 size_extrafield += 20;
1007 }
1008
1009 if (err==ZIP_OK)
1010 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
1011
1012 if ((err==ZIP_OK) && (size_filename > 0))
1013 {
1014 if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
1015 err = ZIP_ERRNO;
1016 }
1017
1018 if ((err==ZIP_OK) && (size_extrafield_local > 0))
1019 {
1020 if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
1021 err = ZIP_ERRNO;
1022 }
1023
1024
1025 if ((err==ZIP_OK) && (zi->ci.zip64))
1026 {
1027 // write the Zip64 extended info
1028 short HeaderID = 1;
1029 short DataSize = 16;
1030 ZPOS64_T CompressedSize = 0;
1031 ZPOS64_T UncompressedSize = 0;
1032
1033 // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
1034 zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
1035
1036 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
1037 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
1038
1039 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
1040 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
1041 }
1042
1043 return err;
1044}
1045
1046/*
1047 NOTE.
1048 When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped
1049 before calling this function it can be done with zipRemoveExtraInfoBlock
1050
1051 It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
1052 unnecessary allocations.
1053 */
1054extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1055 const void* extrafield_local, uInt size_extrafield_local,
1056 const void* extrafield_global, uInt size_extrafield_global,
1057 const char* comment, int method, int level, int raw,
1058 int windowBits,int memLevel, int strategy,
1059 const char* password, uLong crcForCrypting,
1060 uLong versionMadeBy, uLong flagBase, int zip64)
1061{
1062 zip64_internal* zi;
714 uInt size_filename; 1063 uInt size_filename;
715 uInt size_comment; 1064 uInt size_comment;
716 uInt i; 1065 uInt i;
@@ -723,10 +1072,16 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
723 1072
724 if (file == NULL) 1073 if (file == NULL)
725 return ZIP_PARAMERROR; 1074 return ZIP_PARAMERROR;
1075
1076#ifdef HAVE_BZIP2
1077 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
1078 return ZIP_PARAMERROR;
1079#else
726 if ((method!=0) && (method!=Z_DEFLATED)) 1080 if ((method!=0) && (method!=Z_DEFLATED))
727 return ZIP_PARAMERROR; 1081 return ZIP_PARAMERROR;
1082#endif
728 1083
729 zi = (zip_internal*)file; 1084 zi = (zip64_internal*)file;
730 1085
731 if (zi->in_opened_file_inzip == 1) 1086 if (zi->in_opened_file_inzip == 1)
732 { 1087 {
@@ -735,7 +1090,6 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
735 return err; 1090 return err;
736 } 1091 }
737 1092
738
739 if (filename==NULL) 1093 if (filename==NULL)
740 filename="-"; 1094 filename="-";
741 1095
@@ -752,10 +1106,11 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
752 { 1106 {
753 if (zipfi->dosDate != 0) 1107 if (zipfi->dosDate != 0)
754 zi->ci.dosDate = zipfi->dosDate; 1108 zi->ci.dosDate = zipfi->dosDate;
755 else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); 1109 else
1110 zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
756 } 1111 }
757 1112
758 zi->ci.flag = 0; 1113 zi->ci.flag = flagBase;
759 if ((level==8) || (level==9)) 1114 if ((level==8) || (level==9))
760 zi->ci.flag |= 2; 1115 zi->ci.flag |= 2;
761 if ((level==2)) 1116 if ((level==2))
@@ -771,37 +1126,43 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
771 zi->ci.stream_initialised = 0; 1126 zi->ci.stream_initialised = 0;
772 zi->ci.pos_in_buffered_data = 0; 1127 zi->ci.pos_in_buffered_data = 0;
773 zi->ci.raw = raw; 1128 zi->ci.raw = raw;
774 zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; 1129 zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
775 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
776 size_extrafield_global + size_comment;
777 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
778 1130
779 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); 1131 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
1132 zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
1133
1134 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
1135
1136 zi->ci.size_centralExtra = size_extrafield_global;
1137 zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
780 /* version info */ 1138 /* version info */
781 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); 1139 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
782 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); 1140 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
783 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); 1141 zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
784 ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); 1142 zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
785 ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); 1143 zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
786 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ 1144 zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
787 ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ 1145 zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
788 ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ 1146 zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
789 ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); 1147 zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
790 ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); 1148 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
791 ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); 1149 zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
792 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ 1150 zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
793 1151
794 if (zipfi==NULL) 1152 if (zipfi==NULL)
795 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); 1153 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
796 else 1154 else
797 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); 1155 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
798 1156
799 if (zipfi==NULL) 1157 if (zipfi==NULL)
800 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); 1158 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
801 else 1159 else
802 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); 1160 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
803 1161
804 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); 1162 if(zi->ci.pos_local_header >= 0xffffffff)
1163 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
1164 else
1165 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4);
805 1166
806 for (i=0;i<size_filename;i++) 1167 for (i=0;i<size_filename;i++)
807 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); 1168 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
@@ -816,63 +1177,66 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
816 if (zi->ci.central_header == NULL) 1177 if (zi->ci.central_header == NULL)
817 return ZIP_INTERNALERROR; 1178 return ZIP_INTERNALERROR;
818 1179
819 /* write the local header */ 1180 zi->ci.zip64 = zip64;
820 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); 1181 zi->ci.totalCompressedData = 0;
821 1182 zi->ci.totalUncompressedData = 0;
822 if (err==ZIP_OK) 1183 zi->ci.pos_zip64extrainfo = 0;
823 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ 1184
824 if (err==ZIP_OK) 1185 err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
825 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); 1186
826 1187#ifdef HAVE_BZIP2
827 if (err==ZIP_OK) 1188 zi->ci.bstream.avail_in = (uInt)0;
828 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); 1189 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
829 1190 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
830 if (err==ZIP_OK) 1191 zi->ci.bstream.total_in_hi32 = 0;
831 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); 1192 zi->ci.bstream.total_in_lo32 = 0;
832 1193 zi->ci.bstream.total_out_hi32 = 0;
833 if (err==ZIP_OK) 1194 zi->ci.bstream.total_out_lo32 = 0;
834 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ 1195#endif
835 if (err==ZIP_OK)
836 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
837 if (err==ZIP_OK)
838 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
839
840 if (err==ZIP_OK)
841 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
842
843 if (err==ZIP_OK)
844 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
845
846 if ((err==ZIP_OK) && (size_filename>0))
847 if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
848 err = ZIP_ERRNO;
849
850 if ((err==ZIP_OK) && (size_extrafield_local>0))
851 if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)
852 !=size_extrafield_local)
853 err = ZIP_ERRNO;
854 1196
855 zi->ci.stream.avail_in = (uInt)0; 1197 zi->ci.stream.avail_in = (uInt)0;
856 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1198 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
857 zi->ci.stream.next_out = zi->ci.buffered_data; 1199 zi->ci.stream.next_out = zi->ci.buffered_data;
858 zi->ci.stream.total_in = 0; 1200 zi->ci.stream.total_in = 0;
859 zi->ci.stream.total_out = 0; 1201 zi->ci.stream.total_out = 0;
1202 zi->ci.stream.data_type = Z_BINARY;
860 1203
1204#ifdef HAVE_BZIP2
1205 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1206#else
861 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1207 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1208#endif
862 { 1209 {
863 zi->ci.stream.zalloc = (alloc_func)0; 1210 if(zi->ci.method == Z_DEFLATED)
864 zi->ci.stream.zfree = (free_func)0; 1211 {
865 zi->ci.stream.opaque = (voidpf)0; 1212 zi->ci.stream.zalloc = (alloc_func)0;
1213 zi->ci.stream.zfree = (free_func)0;
1214 zi->ci.stream.opaque = (voidpf)0;
866 1215
867 if (windowBits>0) 1216 if (windowBits>0)
868 windowBits = -windowBits; 1217 windowBits = -windowBits;
869 1218
870 err = deflateInit2(&zi->ci.stream, level, 1219 err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
871 Z_DEFLATED, windowBits, memLevel, strategy); 1220
1221 if (err==Z_OK)
1222 zi->ci.stream_initialised = Z_DEFLATED;
1223 }
1224 else if(zi->ci.method == Z_BZIP2ED)
1225 {
1226#ifdef HAVE_BZIP2
1227 // Init BZip stuff here
1228 zi->ci.bstream.bzalloc = 0;
1229 zi->ci.bstream.bzfree = 0;
1230 zi->ci.bstream.opaque = (voidpf)0;
1231
1232 err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
1233 if(err == BZ_OK)
1234 zi->ci.stream_initialised = Z_BZIP2ED;
1235#endif
1236 }
872 1237
873 if (err==Z_OK)
874 zi->ci.stream_initialised = 1;
875 } 1238 }
1239
876# ifndef NOCRYPT 1240# ifndef NOCRYPT
877 zi->ci.crypt_header_size = 0; 1241 zi->ci.crypt_header_size = 0;
878 if ((err==Z_OK) && (password != NULL)) 1242 if ((err==Z_OK) && (password != NULL))
@@ -886,7 +1250,7 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
886 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); 1250 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
887 zi->ci.crypt_header_size = sizeHead; 1251 zi->ci.crypt_header_size = sizeHead;
888 1252
889 if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) 1253 if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
890 err = ZIP_ERRNO; 1254 err = ZIP_ERRNO;
891 } 1255 }
892# endif 1256# endif
@@ -896,53 +1260,105 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
896 return err; 1260 return err;
897} 1261}
898 1262
899extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, 1263extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
900 extrafield_local, size_extrafield_local, 1264 const void* extrafield_local, uInt size_extrafield_local,
901 extrafield_global, size_extrafield_global, 1265 const void* extrafield_global, uInt size_extrafield_global,
902 comment, method, level, raw) 1266 const char* comment, int method, int level, int raw,
903 zipFile file; 1267 int windowBits,int memLevel, int strategy,
904 const char* filename; 1268 const char* password, uLong crcForCrypting,
905 const zip_fileinfo* zipfi; 1269 uLong versionMadeBy, uLong flagBase)
906 const void* extrafield_local; 1270{
907 uInt size_extrafield_local; 1271 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
908 const void* extrafield_global; 1272 extrafield_local, size_extrafield_local,
909 uInt size_extrafield_global; 1273 extrafield_global, size_extrafield_global,
910 const char* comment; 1274 comment, method, level, raw,
911 int method; 1275 windowBits, memLevel, strategy,
912 int level; 1276 password, crcForCrypting, versionMadeBy, flagBase, 0);
913 int raw; 1277}
1278
1279extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1280 const void* extrafield_local, uInt size_extrafield_local,
1281 const void* extrafield_global, uInt size_extrafield_global,
1282 const char* comment, int method, int level, int raw,
1283 int windowBits,int memLevel, int strategy,
1284 const char* password, uLong crcForCrypting)
1285{
1286 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1287 extrafield_local, size_extrafield_local,
1288 extrafield_global, size_extrafield_global,
1289 comment, method, level, raw,
1290 windowBits, memLevel, strategy,
1291 password, crcForCrypting, VERSIONMADEBY, 0, 0);
1292}
1293
1294extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1295 const void* extrafield_local, uInt size_extrafield_local,
1296 const void* extrafield_global, uInt size_extrafield_global,
1297 const char* comment, int method, int level, int raw,
1298 int windowBits,int memLevel, int strategy,
1299 const char* password, uLong crcForCrypting, int zip64)
1300{
1301 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1302 extrafield_local, size_extrafield_local,
1303 extrafield_global, size_extrafield_global,
1304 comment, method, level, raw,
1305 windowBits, memLevel, strategy,
1306 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1307}
1308
1309extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1310 const void* extrafield_local, uInt size_extrafield_local,
1311 const void* extrafield_global, uInt size_extrafield_global,
1312 const char* comment, int method, int level, int raw)
1313{
1314 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1315 extrafield_local, size_extrafield_local,
1316 extrafield_global, size_extrafield_global,
1317 comment, method, level, raw,
1318 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1319 NULL, 0, VERSIONMADEBY, 0, 0);
1320}
1321
1322extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1323 const void* extrafield_local, uInt size_extrafield_local,
1324 const void* extrafield_global, uInt size_extrafield_global,
1325 const char* comment, int method, int level, int raw, int zip64)
914{ 1326{
915 return zipOpenNewFileInZip3 (file, filename, zipfi, 1327 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
916 extrafield_local, size_extrafield_local, 1328 extrafield_local, size_extrafield_local,
917 extrafield_global, size_extrafield_global, 1329 extrafield_global, size_extrafield_global,
918 comment, method, level, raw, 1330 comment, method, level, raw,
919 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 1331 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
920 NULL, 0); 1332 NULL, 0, VERSIONMADEBY, 0, zip64);
1333}
1334
1335extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1336 const void* extrafield_local, uInt size_extrafield_local,
1337 const void*extrafield_global, uInt size_extrafield_global,
1338 const char* comment, int method, int level, int zip64)
1339{
1340 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1341 extrafield_local, size_extrafield_local,
1342 extrafield_global, size_extrafield_global,
1343 comment, method, level, 0,
1344 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1345 NULL, 0, VERSIONMADEBY, 0, zip64);
921} 1346}
922 1347
923extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, 1348extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
924 extrafield_local, size_extrafield_local, 1349 const void* extrafield_local, uInt size_extrafield_local,
925 extrafield_global, size_extrafield_global, 1350 const void*extrafield_global, uInt size_extrafield_global,
926 comment, method, level) 1351 const char* comment, int method, int level)
927 zipFile file;
928 const char* filename;
929 const zip_fileinfo* zipfi;
930 const void* extrafield_local;
931 uInt size_extrafield_local;
932 const void* extrafield_global;
933 uInt size_extrafield_global;
934 const char* comment;
935 int method;
936 int level;
937{ 1352{
938 return zipOpenNewFileInZip2 (file, filename, zipfi, 1353 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
939 extrafield_local, size_extrafield_local, 1354 extrafield_local, size_extrafield_local,
940 extrafield_global, size_extrafield_global, 1355 extrafield_global, size_extrafield_global,
941 comment, method, level, 0); 1356 comment, method, level, 0,
1357 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1358 NULL, 0, VERSIONMADEBY, 0, 0);
942} 1359}
943 1360
944local int zipFlushWriteBuffer(zi) 1361local int zip64FlushWriteBuffer(zip64_internal* zi)
945 zip_internal* zi;
946{ 1362{
947 int err=ZIP_OK; 1363 int err=ZIP_OK;
948 1364
@@ -952,169 +1368,372 @@ local int zipFlushWriteBuffer(zi)
952 uInt i; 1368 uInt i;
953 int t; 1369 int t;
954 for (i=0;i<zi->ci.pos_in_buffered_data;i++) 1370 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
955 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, 1371 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
956 zi->ci.buffered_data[i],t);
957#endif 1372#endif
958 } 1373 }
959 if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) 1374
960 !=zi->ci.pos_in_buffered_data) 1375 if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
961 err = ZIP_ERRNO; 1376 err = ZIP_ERRNO;
1377
1378 zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
1379
1380#ifdef HAVE_BZIP2
1381 if(zi->ci.method == Z_BZIP2ED)
1382 {
1383 zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
1384 zi->ci.bstream.total_in_lo32 = 0;
1385 zi->ci.bstream.total_in_hi32 = 0;
1386 }
1387 else
1388#endif
1389 {
1390 zi->ci.totalUncompressedData += zi->ci.stream.total_in;
1391 zi->ci.stream.total_in = 0;
1392 }
1393
1394
962 zi->ci.pos_in_buffered_data = 0; 1395 zi->ci.pos_in_buffered_data = 0;
1396
963 return err; 1397 return err;
964} 1398}
965 1399
966extern int ZEXPORT zipWriteInFileInZip (file, buf, len) 1400extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
967 zipFile file;
968 const void* buf;
969 unsigned len;
970{ 1401{
971 zip_internal* zi; 1402 zip64_internal* zi;
972 int err=ZIP_OK; 1403 int err=ZIP_OK;
973 1404
974 if (file == NULL) 1405 if (file == NULL)
975 return ZIP_PARAMERROR; 1406 return ZIP_PARAMERROR;
976 zi = (zip_internal*)file; 1407 zi = (zip64_internal*)file;
977 1408
978 if (zi->in_opened_file_inzip == 0) 1409 if (zi->in_opened_file_inzip == 0)
979 return ZIP_PARAMERROR; 1410 return ZIP_PARAMERROR;
980 1411
981 zi->ci.stream.next_in = (void*)buf; 1412 zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
982 zi->ci.stream.avail_in = len;
983 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
984 1413
985 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) 1414#ifdef HAVE_BZIP2
1415 if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
986 { 1416 {
987 if (zi->ci.stream.avail_out == 0) 1417 zi->ci.bstream.next_in = (void*)buf;
1418 zi->ci.bstream.avail_in = len;
1419 err = BZ_RUN_OK;
1420
1421 while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
1422 {
1423 if (zi->ci.bstream.avail_out == 0)
988 { 1424 {
989 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) 1425 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
990 err = ZIP_ERRNO; 1426 err = ZIP_ERRNO;
991 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1427 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
992 zi->ci.stream.next_out = zi->ci.buffered_data; 1428 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
993 } 1429 }
994 1430
995 1431
996 if(err != ZIP_OK) 1432 if(err != BZ_RUN_OK)
997 break; 1433 break;
998 1434
999 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1435 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1000 { 1436 {
1001 uLong uTotalOutBefore = zi->ci.stream.total_out; 1437 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1002 err=deflate(&zi->ci.stream, Z_NO_FLUSH); 1438// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
1003 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1439 err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1004 1440
1441 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
1005 } 1442 }
1006 else 1443 }
1007 { 1444
1008 uInt copy_this,i; 1445 if(err == BZ_RUN_OK)
1009 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) 1446 err = ZIP_OK;
1010 copy_this = zi->ci.stream.avail_in; 1447 }
1011 else 1448 else
1012 copy_this = zi->ci.stream.avail_out; 1449#endif
1013 for (i=0;i<copy_this;i++) 1450 {
1014 *(((char*)zi->ci.stream.next_out)+i) = 1451 zi->ci.stream.next_in = (Bytef*)buf;
1015 *(((const char*)zi->ci.stream.next_in)+i); 1452 zi->ci.stream.avail_in = len;
1016 { 1453
1017 zi->ci.stream.avail_in -= copy_this; 1454 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1018 zi->ci.stream.avail_out-= copy_this; 1455 {
1019 zi->ci.stream.next_in+= copy_this; 1456 if (zi->ci.stream.avail_out == 0)
1020 zi->ci.stream.next_out+= copy_this; 1457 {
1021 zi->ci.stream.total_in+= copy_this; 1458 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1022 zi->ci.stream.total_out+= copy_this; 1459 err = ZIP_ERRNO;
1023 zi->ci.pos_in_buffered_data += copy_this; 1460 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1024 } 1461 zi->ci.stream.next_out = zi->ci.buffered_data;
1025 } 1462 }
1463
1464
1465 if(err != ZIP_OK)
1466 break;
1467
1468 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1469 {
1470 uLong uTotalOutBefore = zi->ci.stream.total_out;
1471 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
1472 if(uTotalOutBefore > zi->ci.stream.total_out)
1473 {
1474 int bBreak = 0;
1475 bBreak++;
1476 }
1477
1478 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1479 }
1480 else
1481 {
1482 uInt copy_this,i;
1483 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1484 copy_this = zi->ci.stream.avail_in;
1485 else
1486 copy_this = zi->ci.stream.avail_out;
1487
1488 for (i = 0; i < copy_this; i++)
1489 *(((char*)zi->ci.stream.next_out)+i) =
1490 *(((const char*)zi->ci.stream.next_in)+i);
1491 {
1492 zi->ci.stream.avail_in -= copy_this;
1493 zi->ci.stream.avail_out-= copy_this;
1494 zi->ci.stream.next_in+= copy_this;
1495 zi->ci.stream.next_out+= copy_this;
1496 zi->ci.stream.total_in+= copy_this;
1497 zi->ci.stream.total_out+= copy_this;
1498 zi->ci.pos_in_buffered_data += copy_this;
1499 }
1500 }
1501 }// while(...)
1026 } 1502 }
1027 1503
1028 return err; 1504 return err;
1029} 1505}
1030 1506
1031extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) 1507extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
1032 zipFile file;
1033 uLong uncompressed_size;
1034 uLong crc32;
1035{ 1508{
1036 zip_internal* zi; 1509 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1037 uLong compressed_size; 1510}
1511
1512extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
1513{
1514 zip64_internal* zi;
1515 ZPOS64_T compressed_size;
1516 uLong invalidValue = 0xffffffff;
1517 short datasize = 0;
1038 int err=ZIP_OK; 1518 int err=ZIP_OK;
1039 1519
1040 if (file == NULL) 1520 if (file == NULL)
1041 return ZIP_PARAMERROR; 1521 return ZIP_PARAMERROR;
1042 zi = (zip_internal*)file; 1522 zi = (zip64_internal*)file;
1043 1523
1044 if (zi->in_opened_file_inzip == 0) 1524 if (zi->in_opened_file_inzip == 0)
1045 return ZIP_PARAMERROR; 1525 return ZIP_PARAMERROR;
1046 zi->ci.stream.avail_in = 0; 1526 zi->ci.stream.avail_in = 0;
1047 1527
1048 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1528 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1049 while (err==ZIP_OK) 1529 {
1530 while (err==ZIP_OK)
1531 {
1532 uLong uTotalOutBefore;
1533 if (zi->ci.stream.avail_out == 0)
1534 {
1535 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1536 err = ZIP_ERRNO;
1537 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1538 zi->ci.stream.next_out = zi->ci.buffered_data;
1539 }
1540 uTotalOutBefore = zi->ci.stream.total_out;
1541 err=deflate(&zi->ci.stream, Z_FINISH);
1542 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1543 }
1544 }
1545 else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1050 { 1546 {
1547#ifdef HAVE_BZIP2
1548 err = BZ_FINISH_OK;
1549 while (err==BZ_FINISH_OK)
1550 {
1051 uLong uTotalOutBefore; 1551 uLong uTotalOutBefore;
1052 if (zi->ci.stream.avail_out == 0) 1552 if (zi->ci.bstream.avail_out == 0)
1053 { 1553 {
1054 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) 1554 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1055 err = ZIP_ERRNO; 1555 err = ZIP_ERRNO;
1056 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1556 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1057 zi->ci.stream.next_out = zi->ci.buffered_data; 1557 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1058 } 1558 }
1059 uTotalOutBefore = zi->ci.stream.total_out; 1559 uTotalOutBefore = zi->ci.bstream.total_out_lo32;
1060 err=deflate(&zi->ci.stream, Z_FINISH); 1560 err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
1061 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1561 if(err == BZ_STREAM_END)
1562 err = Z_STREAM_END;
1563
1564 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
1565 }
1566
1567 if(err == BZ_FINISH_OK)
1568 err = ZIP_OK;
1569#endif
1062 } 1570 }
1063 1571
1064 if (err==Z_STREAM_END) 1572 if (err==Z_STREAM_END)
1065 err=ZIP_OK; /* this is normal */ 1573 err=ZIP_OK; /* this is normal */
1066 1574
1067 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) 1575 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1068 if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) 1576 {
1577 if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
1069 err = ZIP_ERRNO; 1578 err = ZIP_ERRNO;
1579 }
1070 1580
1071 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1581 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1072 { 1582 {
1073 err=deflateEnd(&zi->ci.stream); 1583 int tmp_err = deflateEnd(&zi->ci.stream);
1584 if (err == ZIP_OK)
1585 err = tmp_err;
1074 zi->ci.stream_initialised = 0; 1586 zi->ci.stream_initialised = 0;
1075 } 1587 }
1588#ifdef HAVE_BZIP2
1589 else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1590 {
1591 int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
1592 if (err==ZIP_OK)
1593 err = tmperr;
1594 zi->ci.stream_initialised = 0;
1595 }
1596#endif
1076 1597
1077 if (!zi->ci.raw) 1598 if (!zi->ci.raw)
1078 { 1599 {
1079 crc32 = (uLong)zi->ci.crc32; 1600 crc32 = (uLong)zi->ci.crc32;
1080 uncompressed_size = (uLong)zi->ci.stream.total_in; 1601 uncompressed_size = zi->ci.totalUncompressedData;
1081 } 1602 }
1082 compressed_size = (uLong)zi->ci.stream.total_out; 1603 compressed_size = zi->ci.totalCompressedData;
1604
1083# ifndef NOCRYPT 1605# ifndef NOCRYPT
1084 compressed_size += zi->ci.crypt_header_size; 1606 compressed_size += zi->ci.crypt_header_size;
1085# endif 1607# endif
1086 1608
1087 ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ 1609 // update Current Item crc and sizes,
1088 ziplocal_putValue_inmemory(zi->ci.central_header+20, 1610 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
1089 compressed_size,4); /*compr size*/ 1611 {
1612 /*version Made by*/
1613 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
1614 /*version needed*/
1615 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
1616
1617 }
1618
1619 zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
1620
1621
1622 if(compressed_size >= 0xffffffff)
1623 zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
1624 else
1625 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
1626
1627 /// set internal file attributes field
1090 if (zi->ci.stream.data_type == Z_ASCII) 1628 if (zi->ci.stream.data_type == Z_ASCII)
1091 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); 1629 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1092 ziplocal_putValue_inmemory(zi->ci.central_header+24, 1630
1093 uncompressed_size,4); /*uncompr size*/ 1631 if(uncompressed_size >= 0xffffffff)
1632 zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
1633 else
1634 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
1635
1636 // Add ZIP64 extra info field for uncompressed size
1637 if(uncompressed_size >= 0xffffffff)
1638 datasize += 8;
1639
1640 // Add ZIP64 extra info field for compressed size
1641 if(compressed_size >= 0xffffffff)
1642 datasize += 8;
1643
1644 // Add ZIP64 extra info field for relative offset to local file header of current file
1645 if(zi->ci.pos_local_header >= 0xffffffff)
1646 datasize += 8;
1647
1648 if(datasize > 0)
1649 {
1650 char* p = NULL;
1651
1652 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
1653 {
1654 // we can not write more data to the buffer that we have room for.
1655 return ZIP_BADZIPFILE;
1656 }
1657
1658 p = zi->ci.central_header + zi->ci.size_centralheader;
1659
1660 // Add Extra Information Header for 'ZIP64 information'
1661 zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
1662 p += 2;
1663 zip64local_putValue_inmemory(p, datasize, 2); // DataSize
1664 p += 2;
1665
1666 if(uncompressed_size >= 0xffffffff)
1667 {
1668 zip64local_putValue_inmemory(p, uncompressed_size, 8);
1669 p += 8;
1670 }
1094 1671
1672 if(compressed_size >= 0xffffffff)
1673 {
1674 zip64local_putValue_inmemory(p, compressed_size, 8);
1675 p += 8;
1676 }
1677
1678 if(zi->ci.pos_local_header >= 0xffffffff)
1679 {
1680 zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
1681 p += 8;
1682 }
1683
1684 // Update how much extra free space we got in the memory buffer
1685 // and increase the centralheader size so the new ZIP64 fields are included
1686 // ( 4 below is the size of HeaderID and DataSize field )
1687 zi->ci.size_centralExtraFree -= datasize + 4;
1688 zi->ci.size_centralheader += datasize + 4;
1689
1690 // Update the extra info size field
1691 zi->ci.size_centralExtra += datasize + 4;
1692 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
1693 }
1694
1095 if (err==ZIP_OK) 1695 if (err==ZIP_OK)
1096 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, 1696 err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
1097 (uLong)zi->ci.size_centralheader); 1697
1098 free(zi->ci.central_header); 1698 free(zi->ci.central_header);
1099 1699
1100 if (err==ZIP_OK) 1700 if (err==ZIP_OK)
1101 { 1701 {
1102 long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); 1702 // Update the LocalFileHeader with the new values.
1103 if (ZSEEK(zi->z_filefunc,zi->filestream, 1703
1104 zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) 1704 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1705
1706 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
1105 err = ZIP_ERRNO; 1707 err = ZIP_ERRNO;
1106 1708
1107 if (err==ZIP_OK) 1709 if (err==ZIP_OK)
1108 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ 1710 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1109 1711
1110 if (err==ZIP_OK) /* compressed size, unknown */ 1712 if(uncompressed_size >= 0xffffffff)
1111 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); 1713 {
1714 if(zi->ci.pos_zip64extrainfo > 0)
1715 {
1716 // Update the size in the ZIP64 extended field.
1717 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
1718 err = ZIP_ERRNO;
1719
1720 if (err==ZIP_OK) /* compressed size, unknown */
1721 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
1722
1723 if (err==ZIP_OK) /* uncompressed size, unknown */
1724 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
1725 }
1726 }
1727 else
1728 {
1729 if (err==ZIP_OK) /* compressed size, unknown */
1730 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1112 1731
1113 if (err==ZIP_OK) /* uncompressed size, unknown */ 1732 if (err==ZIP_OK) /* uncompressed size, unknown */
1114 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); 1733 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1734 }
1115 1735
1116 if (ZSEEK(zi->z_filefunc,zi->filestream, 1736 if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1117 cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1118 err = ZIP_ERRNO; 1737 err = ZIP_ERRNO;
1119 } 1738 }
1120 1739
@@ -1124,24 +1743,150 @@ extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
1124 return err; 1743 return err;
1125} 1744}
1126 1745
1127extern int ZEXPORT zipCloseFileInZip (file) 1746extern int ZEXPORT zipCloseFileInZip (zipFile file)
1128 zipFile file;
1129{ 1747{
1130 return zipCloseFileInZipRaw (file,0,0); 1748 return zipCloseFileInZipRaw (file,0,0);
1131} 1749}
1132 1750
1133extern int ZEXPORT zipClose (file, global_comment) 1751int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
1134 zipFile file; 1752{
1135 const char* global_comment; 1753 int err = ZIP_OK;
1754 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
1755
1756 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
1757
1758 /*num disks*/
1759 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1760 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1761
1762 /*relative offset*/
1763 if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
1764 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
1765
1766 /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
1767 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1768 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
1769
1770 return err;
1771}
1772
1773int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1136{ 1774{
1137 zip_internal* zi; 1775 int err = ZIP_OK;
1776
1777 uLong Zip64DataSize = 44;
1778
1779 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
1780
1781 if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
1782 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
1783
1784 if (err==ZIP_OK) /* version made by */
1785 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1786
1787 if (err==ZIP_OK) /* version needed */
1788 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1789
1790 if (err==ZIP_OK) /* number of this disk */
1791 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1792
1793 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1794 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1795
1796 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1797 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1798
1799 if (err==ZIP_OK) /* total number of entries in the central dir */
1800 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1801
1802 if (err==ZIP_OK) /* size of the central directory */
1803 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
1804
1805 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1806 {
1807 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1808 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
1809 }
1810 return err;
1811}
1812int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1813{
1814 int err = ZIP_OK;
1815
1816 /*signature*/
1817 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1818
1819 if (err==ZIP_OK) /* number of this disk */
1820 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1821
1822 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1823 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1824
1825 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1826 {
1827 {
1828 if(zi->number_entry >= 0xFFFF)
1829 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
1830 else
1831 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1832 }
1833 }
1834
1835 if (err==ZIP_OK) /* total number of entries in the central dir */
1836 {
1837 if(zi->number_entry >= 0xFFFF)
1838 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
1839 else
1840 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1841 }
1842
1843 if (err==ZIP_OK) /* size of the central directory */
1844 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1845
1846 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1847 {
1848 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1849 if(pos >= 0xffffffff)
1850 {
1851 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
1852 }
1853 else
1854 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
1855 }
1856
1857 return err;
1858}
1859
1860int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
1861{
1862 int err = ZIP_OK;
1863 uInt size_global_comment = 0;
1864
1865 if(global_comment != NULL)
1866 size_global_comment = (uInt)strlen(global_comment);
1867
1868 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
1869
1870 if (err == ZIP_OK && size_global_comment > 0)
1871 {
1872 if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
1873 err = ZIP_ERRNO;
1874 }
1875 return err;
1876}
1877
1878extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
1879{
1880 zip64_internal* zi;
1138 int err = 0; 1881 int err = 0;
1139 uLong size_centraldir = 0; 1882 uLong size_centraldir = 0;
1140 uLong centraldir_pos_inzip; 1883 ZPOS64_T centraldir_pos_inzip;
1141 uInt size_global_comment; 1884 ZPOS64_T pos;
1885
1142 if (file == NULL) 1886 if (file == NULL)
1143 return ZIP_PARAMERROR; 1887 return ZIP_PARAMERROR;
1144 zi = (zip_internal*)file; 1888
1889 zi = (zip64_internal*)file;
1145 1890
1146 if (zi->in_opened_file_inzip == 1) 1891 if (zi->in_opened_file_inzip == 1)
1147 { 1892 {
@@ -1152,61 +1897,42 @@ extern int ZEXPORT zipClose (file, global_comment)
1152 if (global_comment==NULL) 1897 if (global_comment==NULL)
1153 global_comment = zi->globalcomment; 1898 global_comment = zi->globalcomment;
1154#endif 1899#endif
1155 if (global_comment==NULL) 1900
1156 size_global_comment = 0; 1901 centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1157 else
1158 size_global_comment = (uInt)strlen(global_comment);
1159 1902
1160 centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
1161 if (err==ZIP_OK) 1903 if (err==ZIP_OK)
1162 { 1904 {
1163 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; 1905 linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
1164 while (ldi!=NULL) 1906 while (ldi!=NULL)
1165 { 1907 {
1166 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) 1908 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
1167 if (ZWRITE(zi->z_filefunc,zi->filestream, 1909 {
1168 ldi->data,ldi->filled_in_this_block) 1910 if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
1169 !=ldi->filled_in_this_block )
1170 err = ZIP_ERRNO; 1911 err = ZIP_ERRNO;
1912 }
1171 1913
1172 size_centraldir += ldi->filled_in_this_block; 1914 size_centraldir += ldi->filled_in_this_block;
1173 ldi = ldi->next_datablock; 1915 ldi = ldi->next_datablock;
1174 } 1916 }
1175 } 1917 }
1176 free_datablock(zi->central_dir.first_block); 1918 free_linkedlist(&(zi->central_dir));
1177
1178 if (err==ZIP_OK) /* Magic End */
1179 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1180
1181 if (err==ZIP_OK) /* number of this disk */
1182 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1183
1184 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1185 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1186
1187 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1188 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1189
1190 if (err==ZIP_OK) /* total number of entries in the central dir */
1191 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1192
1193 if (err==ZIP_OK) /* size of the central directory */
1194 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1195 1919
1196 if (err==ZIP_OK) /* offset of start of central directory with respect to the 1920 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1197 starting disk number */ 1921 if(pos >= 0xffffffff)
1198 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, 1922 {
1199 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); 1923 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
1924 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1925
1926 Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
1927 }
1200 1928
1201 if (err==ZIP_OK) /* zipfile comment length */ 1929 if (err==ZIP_OK)
1202 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); 1930 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1203 1931
1204 if ((err==ZIP_OK) && (size_global_comment>0)) 1932 if(err == ZIP_OK)
1205 if (ZWRITE(zi->z_filefunc,zi->filestream, 1933 err = Write_GlobalComment(zi, global_comment);
1206 global_comment,size_global_comment) != size_global_comment)
1207 err = ZIP_ERRNO;
1208 1934
1209 if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) 1935 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
1210 if (err == ZIP_OK) 1936 if (err == ZIP_OK)
1211 err = ZIP_ERRNO; 1937 err = ZIP_ERRNO;
1212 1938
@@ -1217,3 +1943,61 @@ extern int ZEXPORT zipClose (file, global_comment)
1217 1943
1218 return err; 1944 return err;
1219} 1945}
1946
1947extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
1948{
1949 char* p = pData;
1950 int size = 0;
1951 char* pNewHeader;
1952 char* pTmp;
1953 short header;
1954 short dataSize;
1955
1956 int retVal = ZIP_OK;
1957
1958 if(pData == NULL || *dataLen < 4)
1959 return ZIP_PARAMERROR;
1960
1961 pNewHeader = (char*)ALLOC(*dataLen);
1962 pTmp = pNewHeader;
1963
1964 while(p < (pData + *dataLen))
1965 {
1966 header = *(short*)p;
1967 dataSize = *(((short*)p)+1);
1968
1969 if( header == sHeader ) // Header found.
1970 {
1971 p += dataSize + 4; // skip it. do not copy to temp buffer
1972 }
1973 else
1974 {
1975 // Extra Info block should not be removed, So copy it to the temp buffer.
1976 memcpy(pTmp, p, dataSize + 4);
1977 p += dataSize + 4;
1978 size += dataSize + 4;
1979 }
1980
1981 }
1982
1983 if(size < *dataLen)
1984 {
1985 // clean old extra info block.
1986 memset(pData,0, *dataLen);
1987
1988 // copy the new extra info block over the old
1989 if(size > 0)
1990 memcpy(pData, pNewHeader, size);
1991
1992 // set the new extra info size
1993 *dataLen = size;
1994
1995 retVal = ZIP_OK;
1996 }
1997 else
1998 retVal = ZIP_ERRNO;
1999
2000 TRYFREE(pNewHeader);
2001
2002 return retVal;
2003}
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h
index acacce8..a33a52d 100644
--- a/contrib/minizip/zip.h
+++ b/contrib/minizip/zip.h
@@ -1,19 +1,15 @@
1/* zip.h -- IO for compress .zip files using zlib 1/* zip.h -- IO on .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, January 7th, 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 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g 7 Modifications for Zip64 support
7 WinZip, InfoZip tools and compatible. 8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
8 Multi volume ZipFile (span) are not supported.
9 Encryption compatible with pkzip 2.04g only supported
10 Old compressions used by old PKZip 1.x are not supported
11 9
12 For uncompress .zip file, look at unzip.h 10 For more info read MiniZip_info.txt
13 11
14 12 ---------------------------------------------------------------------------
15 I WAIT FEEDBACK at mail info@winimage.com
16 Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
17 13
18 Condition of use and distribution are the same than zlib : 14 Condition of use and distribution are the same than zlib :
19 15
@@ -33,23 +29,23 @@
33 misrepresented as being the original software. 29 misrepresented as being the original software.
34 3. This notice may not be removed or altered from any source distribution. 30 3. This notice may not be removed or altered from any source distribution.
35 31
32 ---------------------------------------------------------------------------
36 33
37*/ 34 Changes
35
36 See header of zip.h
38 37
39/* for more info about .ZIP format, see
40 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
41 http://www.info-zip.org/pub/infozip/doc/
42 PkWare has also a specification at :
43 ftp://ftp.pkware.com/probdesc.zip
44*/ 38*/
45 39
46#ifndef _zip_H 40#ifndef _zip12_H
47#define _zip_H 41#define _zip12_H
48 42
49#ifdef __cplusplus 43#ifdef __cplusplus
50extern "C" { 44extern "C" {
51#endif 45#endif
52 46
47//#define HAVE_BZIP2
48
53#ifndef _ZLIB_H 49#ifndef _ZLIB_H
54#include "zlib.h" 50#include "zlib.h"
55#endif 51#endif
@@ -58,6 +54,12 @@ extern "C" {
58#include "ioapi.h" 54#include "ioapi.h"
59#endif 55#endif
60 56
57#ifdef HAVE_BZIP2
58#include "bzlib.h"
59#endif
60
61#define Z_BZIP2ED 12
62
61#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 63#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
62/* like the STRICT of WIN32, we define a pointer that cannot be converted 64/* like the STRICT of WIN32, we define a pointer that cannot be converted
63 from (void*) without cast */ 65 from (void*) without cast */
@@ -112,6 +114,7 @@ typedef const char* zipcharpc;
112#define APPEND_STATUS_ADDINZIP (2) 114#define APPEND_STATUS_ADDINZIP (2)
113 115
114extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 116extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
117extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
115/* 118/*
116 Create a zipfile. 119 Create a zipfile.
117 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on 120 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
@@ -136,6 +139,11 @@ extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
136 zipcharpc* globalcomment, 139 zipcharpc* globalcomment,
137 zlib_filefunc_def* pzlib_filefunc_def)); 140 zlib_filefunc_def* pzlib_filefunc_def));
138 141
142extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
143 int append,
144 zipcharpc* globalcomment,
145 zlib_filefunc64_def* pzlib_filefunc_def));
146
139extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 147extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
140 const char* filename, 148 const char* filename,
141 const zip_fileinfo* zipfi, 149 const zip_fileinfo* zipfi,
@@ -146,6 +154,19 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
146 const char* comment, 154 const char* comment,
147 int method, 155 int method,
148 int level)); 156 int level));
157
158extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
159 const char* filename,
160 const zip_fileinfo* zipfi,
161 const void* extrafield_local,
162 uInt size_extrafield_local,
163 const void* extrafield_global,
164 uInt size_extrafield_global,
165 const char* comment,
166 int method,
167 int level,
168 int zip64));
169
149/* 170/*
150 Open a file in the ZIP for writing. 171 Open a file in the ZIP for writing.
151 filename : the filename in zip (if NULL, '-' without quote will be used 172 filename : the filename in zip (if NULL, '-' without quote will be used
@@ -157,6 +178,9 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
157 if comment != NULL, comment contain the comment string 178 if comment != NULL, comment contain the comment string
158 method contain the compression method (0 for store, Z_DEFLATED for deflate) 179 method contain the compression method (0 for store, Z_DEFLATED for deflate)
159 level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 180 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
181 zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
182 this MUST be '1' if the uncompressed size is >= 0xffffffff.
183
160*/ 184*/
161 185
162 186
@@ -172,6 +196,19 @@ extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
172 int level, 196 int level,
173 int raw)); 197 int raw));
174 198
199
200extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
201 const char* filename,
202 const zip_fileinfo* zipfi,
203 const void* extrafield_local,
204 uInt size_extrafield_local,
205 const void* extrafield_global,
206 uInt size_extrafield_global,
207 const char* comment,
208 int method,
209 int level,
210 int raw,
211 int zip64));
175/* 212/*
176 Same than zipOpenNewFileInZip, except if raw=1, we write raw file 213 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
177 */ 214 */
@@ -191,13 +228,79 @@ extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
191 int memLevel, 228 int memLevel,
192 int strategy, 229 int strategy,
193 const char* password, 230 const char* password,
194 uLong crcForCtypting)); 231 uLong crcForCrypting));
232
233extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
234 const char* filename,
235 const zip_fileinfo* zipfi,
236 const void* extrafield_local,
237 uInt size_extrafield_local,
238 const void* extrafield_global,
239 uInt size_extrafield_global,
240 const char* comment,
241 int method,
242 int level,
243 int raw,
244 int windowBits,
245 int memLevel,
246 int strategy,
247 const char* password,
248 uLong crcForCrypting,
249 int zip64
250 ));
195 251
196/* 252/*
197 Same than zipOpenNewFileInZip2, except 253 Same than zipOpenNewFileInZip2, except
198 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 254 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
199 password : crypting password (NULL for no crypting) 255 password : crypting password (NULL for no crypting)
200 crcForCtypting : crc of file to compress (needed for crypting) 256 crcForCrypting : crc of file to compress (needed for crypting)
257 */
258
259extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
260 const char* filename,
261 const zip_fileinfo* zipfi,
262 const void* extrafield_local,
263 uInt size_extrafield_local,
264 const void* extrafield_global,
265 uInt size_extrafield_global,
266 const char* comment,
267 int method,
268 int level,
269 int raw,
270 int windowBits,
271 int memLevel,
272 int strategy,
273 const char* password,
274 uLong crcForCrypting,
275 uLong versionMadeBy,
276 uLong flagBase
277 ));
278
279
280extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
281 const char* filename,
282 const zip_fileinfo* zipfi,
283 const void* extrafield_local,
284 uInt size_extrafield_local,
285 const void* extrafield_global,
286 uInt size_extrafield_global,
287 const char* comment,
288 int method,
289 int level,
290 int raw,
291 int windowBits,
292 int memLevel,
293 int strategy,
294 const char* password,
295 uLong crcForCrypting,
296 uLong versionMadeBy,
297 uLong flagBase,
298 int zip64
299 ));
300/*
301 Same than zipOpenNewFileInZip4, except
302 versionMadeBy : value for Version made by field
303 flag : value for flag field (compression level info will be added)
201 */ 304 */
202 305
203 306
@@ -216,8 +319,13 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
216extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, 319extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
217 uLong uncompressed_size, 320 uLong uncompressed_size,
218 uLong crc32)); 321 uLong crc32));
322
323extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
324 ZPOS64_T uncompressed_size,
325 uLong crc32));
326
219/* 327/*
220 Close the current file in the zipfile, for fiel opened with 328 Close the current file in the zipfile, for file opened with
221 parameter raw=1 in zipOpenNewFileInZip2 329 parameter raw=1 in zipOpenNewFileInZip2
222 uncompressed_size and crc32 are value for the uncompressed size 330 uncompressed_size and crc32 are value for the uncompressed size
223*/ 331*/
@@ -228,8 +336,27 @@ extern int ZEXPORT zipClose OF((zipFile file,
228 Close the zipfile 336 Close the zipfile
229*/ 337*/
230 338
339
340extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
341/*
342 zipRemoveExtraInfoBlock - Added by Mathias Svensson
343
344 Remove extra information block from a extra information data for the local file header or central directory header
345
346 It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
347
348 0x0001 is the signature header for the ZIP64 extra information blocks
349
350 usage.
351 Remove ZIP64 Extra information from a central director extra field data
352 zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
353
354 Remove ZIP64 Extra information from a Local File Header extra field data
355 zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
356*/
357
231#ifdef __cplusplus 358#ifdef __cplusplus
232} 359}
233#endif 360#endif
234 361
235#endif /* _zip_H */ 362#endif /* _zip64_H */
diff --git a/contrib/pascal/zlibd32.mak b/contrib/pascal/zlibd32.mak
index 88fafa0..203a4c9 100644
--- a/contrib/pascal/zlibd32.mak
+++ b/contrib/pascal/zlibd32.mak
@@ -18,10 +18,10 @@ LDFLAGS =
18# variables 18# variables
19ZLIB_LIB = zlib.lib 19ZLIB_LIB = zlib.lib
20 20
21OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj 21OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
22OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 22OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
23OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj 23OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
24OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 24OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
25 25
26 26
27# targets 27# targets
@@ -38,8 +38,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
38 38
39deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 39deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
40 40
41gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
42
41gzio.obj: gzio.c zutil.h zlib.h zconf.h 43gzio.obj: gzio.c zutil.h zlib.h zconf.h
42 44
45gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
46
47gzread.obj: gzread.c zlib.h zconf.h gzguts.h
48
49gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
50
43infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 51infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
44 inffast.h inffixed.h 52 inffast.h inffixed.h
45 53
diff --git a/contrib/vstudio/vc7/zlib.rc b/contrib/vstudio/vc7/zlib.rc
index 98ca20b..7bb4bb7 100644
--- a/contrib/vstudio/vc7/zlib.rc
+++ b/contrib/vstudio/vc7/zlib.rc
@@ -2,8 +2,8 @@
2 2
3#define IDR_VERSION1 1 3#define IDR_VERSION1 1
4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1,2,3,4 5 FILEVERSION 1,2,3,5
6 PRODUCTVERSION 1,2,3,4 6 PRODUCTVERSION 1,2,3,5
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0 8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32 9 FILEOS VOS_DOS_WINDOWS32
@@ -17,7 +17,7 @@ BEGIN
17 17
18 BEGIN 18 BEGIN
19 VALUE "FileDescription", "zlib data compression library\0" 19 VALUE "FileDescription", "zlib data compression library\0"
20 VALUE "FileVersion", "1.2.3.4\0" 20 VALUE "FileVersion", "1.2.3.5\0"
21 VALUE "InternalName", "zlib\0" 21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlib.dll\0" 22 VALUE "OriginalFilename", "zlib.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0" 23 VALUE "ProductName", "ZLib.DLL\0"
diff --git a/contrib/vstudio/vc7/zlibstat.vcproj b/contrib/vstudio/vc7/zlibstat.vcproj
index 766d7a4..3c37959 100644
--- a/contrib/vstudio/vc7/zlibstat.vcproj
+++ b/contrib/vstudio/vc7/zlibstat.vcproj
@@ -201,9 +201,21 @@
201 RelativePath="..\..\masmx86\gvmat32c.c"> 201 RelativePath="..\..\masmx86\gvmat32c.c">
202 </File> 202 </File>
203 <File 203 <File
204 RelativePath="..\..\..\gzclose.c">
205 </File>
206 <File
204 RelativePath="..\..\..\gzio.c"> 207 RelativePath="..\..\..\gzio.c">
205 </File> 208 </File>
206 <File 209 <File
210 RelativePath="..\..\..\gzlib.c">
211 </File>
212 <File
213 RelativePath="..\..\..\gzread.c">
214 </File>
215 <File
216 RelativePath="..\..\..\gzwrite.c">
217 </File>
218 <File
207 RelativePath="..\..\..\infback.c"> 219 RelativePath="..\..\..\infback.c">
208 </File> 220 </File>
209 <File 221 <File
diff --git a/contrib/vstudio/vc7/zlibvc.vcproj b/contrib/vstudio/vc7/zlibvc.vcproj
index 8533b49..2c66643 100644
--- a/contrib/vstudio/vc7/zlibvc.vcproj
+++ b/contrib/vstudio/vc7/zlibvc.vcproj
@@ -348,9 +348,21 @@
348 </FileConfiguration> 348 </FileConfiguration>
349 </File> 349 </File>
350 <File 350 <File
351 RelativePath="..\..\..\gzclose.c">
352 </File>
353 <File
351 RelativePath="..\..\..\gzio.c"> 354 RelativePath="..\..\..\gzio.c">
352 </File> 355 </File>
353 <File 356 <File
357 RelativePath="..\..\..\gzlib.c">
358 </File>
359 <File
360 RelativePath="..\..\..\gzread.c">
361 </File>
362 <File
363 RelativePath="..\..\..\gzwrite.c">
364 </File>
365 <File
354 RelativePath="..\..\..\infback.c"> 366 RelativePath="..\..\..\infback.c">
355 </File> 367 </File>
356 <File 368 <File
diff --git a/contrib/vstudio/vc8/zlibstat.vcproj b/contrib/vstudio/vc8/zlibstat.vcproj
index fb97037..51a4073 100644
--- a/contrib/vstudio/vc8/zlibstat.vcproj
+++ b/contrib/vstudio/vc8/zlibstat.vcproj
@@ -760,8 +760,19 @@
760 </FileConfiguration> 760 </FileConfiguration>
761 </File> 761 </File>
762 <File 762 <File
763 RelativePath="..\..\..\gzio.c" 763 RelativePath="..\..\..\gzclose.c">
764 > 764 </File>
765 <File
766 RelativePath="..\..\..\gzio.c">
767 </File>
768 <File
769 RelativePath="..\..\..\gzlib.c">
770 </File>
771 <File
772 RelativePath="..\..\..\gzread.c">
773 </File>
774 <File
775 RelativePath="..\..\..\gzwrite.c">
765 </File> 776 </File>
766 <File 777 <File
767 RelativePath="..\..\..\infback.c" 778 RelativePath="..\..\..\infback.c"
diff --git a/contrib/vstudio/vc8/zlibvc.vcproj b/contrib/vstudio/vc8/zlibvc.vcproj
index e717011..f06273b 100644
--- a/contrib/vstudio/vc8/zlibvc.vcproj
+++ b/contrib/vstudio/vc8/zlibvc.vcproj
@@ -1005,8 +1005,19 @@
1005 </FileConfiguration> 1005 </FileConfiguration>
1006 </File> 1006 </File>
1007 <File 1007 <File
1008 RelativePath="..\..\..\gzio.c" 1008 RelativePath="..\..\..\gzclose.c">
1009 > 1009 </File>
1010 <File
1011 RelativePath="..\..\..\gzio.c">
1012 </File>
1013 <File
1014 RelativePath="..\..\..\gzlib.c">
1015 </File>
1016 <File
1017 RelativePath="..\..\..\gzread.c">
1018 </File>
1019 <File
1020 RelativePath="..\..\..\gzwrite.c">
1010 </File> 1021 </File>
1011 <File 1022 <File
1012 RelativePath="..\..\..\infback.c" 1023 RelativePath="..\..\..\infback.c"
diff --git a/contrib/nintendods/Makefile b/nintendods/Makefile
index 21337d0..21337d0 100644
--- a/contrib/nintendods/Makefile
+++ b/nintendods/Makefile
diff --git a/contrib/nintendods/README b/nintendods/README
index ba7a37d..ba7a37d 100644
--- a/contrib/nintendods/README
+++ b/nintendods/README