aboutsummaryrefslogtreecommitdiff
path: root/zlib/contrib/minizip/miniunz.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-06-22 15:56:58 +0200
committermarha <marha@users.sourceforge.net>2012-06-22 15:56:58 +0200
commit66841fa144ddd72df67ab1ddf880ca508d4bc9e3 (patch)
tree7cf0afebcfa94bcc8b2046c85532efcf6b0f91d0 /zlib/contrib/minizip/miniunz.c
parent1a68b7aceea62a76127f0fa13b3f127e37b2ec76 (diff)
parent7baa3d795c87c11550f1686488c968320428cbf9 (diff)
downloadvcxsrv-66841fa144ddd72df67ab1ddf880ca508d4bc9e3.tar.gz
vcxsrv-66841fa144ddd72df67ab1ddf880ca508d4bc9e3.tar.bz2
vcxsrv-66841fa144ddd72df67ab1ddf880ca508d4bc9e3.zip
Merge remote-tracking branch 'origin/released'
Conflicts: zlib/Makefile
Diffstat (limited to 'zlib/contrib/minizip/miniunz.c')
-rw-r--r--zlib/contrib/minizip/miniunz.c171
1 files changed, 123 insertions, 48 deletions
diff --git a/zlib/contrib/minizip/miniunz.c b/zlib/contrib/minizip/miniunz.c
index f59993888..3d65401be 100644
--- a/zlib/contrib/minizip/miniunz.c
+++ b/zlib/contrib/minizip/miniunz.c
@@ -1,10 +1,43 @@
/*
miniunz.c
- Version 1.01e, February 12th, 2005
+ Version 1.1, February 14h, 2010
+ sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
- Copyright (C) 1998-2005 Gilles Vollant
+ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
+
+ Modifications of Unzip for Zip64
+ Copyright (C) 2007-2008 Even Rouault
+
+ Modifications for Zip64 support on both zip and unzip
+ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/
+#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
+ #ifndef __USE_FILE_OFFSET64
+ #define __USE_FILE_OFFSET64
+ #endif
+ #ifndef __USE_LARGEFILE64
+ #define __USE_LARGEFILE64
+ #endif
+ #ifndef _LARGEFILE64_SOURCE
+ #define _LARGEFILE64_SOURCE
+ #endif
+ #ifndef _FILE_OFFSET_BIT
+ #define _FILE_OFFSET_BIT 64
+ #endif
+#endif
+
+#ifdef __APPLE__
+// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
+#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
+#define FTELLO_FUNC(stream) ftello(stream)
+#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
+#else
+#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
+#define FTELLO_FUNC(stream) ftello64(stream)
+#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
+#endif
+
#include <stdio.h>
#include <stdlib.h>
@@ -13,21 +46,22 @@
#include <errno.h>
#include <fcntl.h>
-#ifdef unix
-# include <unistd.h>
-# include <utime.h>
-#else
+#ifdef _WIN32
# include <direct.h>
# include <io.h>
+#else
+# include <unistd.h>
+# include <utime.h>
#endif
+
#include "unzip.h"
#define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (8192)
#define MAXFILENAME (256)
-#ifdef WIN32
+#ifdef _WIN32
#define USEWIN32IOAPI
#include "iowin32.h"
#endif
@@ -51,11 +85,11 @@ void change_file_date(filename,dosdate,tmu_date)
uLong dosdate;
tm_unz tmu_date;
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE hFile;
FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
- hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE,
+ hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
0,NULL,OPEN_EXISTING,0,NULL);
GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
@@ -63,7 +97,7 @@ void change_file_date(filename,dosdate,tmu_date)
SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
CloseHandle(hFile);
#else
-#ifdef unix
+#ifdef unix || __APPLE__
struct utimbuf ut;
struct tm newdate;
newdate.tm_sec = tmu_date.tm_sec;
@@ -91,12 +125,12 @@ int mymkdir(dirname)
const char* dirname;
{
int ret=0;
-#ifdef WIN32
- ret = mkdir(dirname);
-#else
-#ifdef unix
+#ifdef _WIN32
+ ret = _mkdir(dirname);
+#elif unix
+ ret = mkdir (dirname,0775);
+#elif __APPLE__
ret = mkdir (dirname,0775);
-#endif
#endif
return ret;
}
@@ -112,6 +146,11 @@ int makedir (newdir)
return 0;
buffer = (char*)malloc(len+1);
+ if (buffer==NULL)
+ {
+ printf("Error allocating memory\n");
+ return UNZ_INTERNALERROR;
+ }
strcpy(buffer,newdir);
if (buffer[len-1] == '/') {
@@ -164,34 +203,61 @@ void do_help()
" -p extract crypted file using password\n\n");
}
+void Display64BitsSize(ZPOS64_T n, int size_char)
+{
+ /* to avoid compatibility problem , we do here the conversion */
+ char number[21];
+ int offset=19;
+ int pos_string = 19;
+ number[20]=0;
+ for (;;) {
+ number[offset]=(char)((n%10)+'0');
+ if (number[offset] != '0')
+ pos_string=offset;
+ n/=10;
+ if (offset==0)
+ break;
+ offset--;
+ }
+ {
+ int size_display_string = 19-pos_string;
+ while (size_char > size_display_string)
+ {
+ size_char--;
+ printf(" ");
+ }
+ }
+
+ printf("%s",&number[pos_string]);
+}
int do_list(uf)
unzFile uf;
{
uLong i;
- unz_global_info gi;
+ unz_global_info64 gi;
int err;
- err = unzGetGlobalInfo (uf,&gi);
+ err = unzGetGlobalInfo64(uf,&gi);
if (err!=UNZ_OK)
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
- printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
- printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
+ printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
+ printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
for (i=0;i<gi.number_entry;i++)
{
char filename_inzip[256];
- unz_file_info file_info;
+ unz_file_info64 file_info;
uLong ratio=0;
const char *string_method;
char charCrypt=' ';
- err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
+ err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if (err!=UNZ_OK)
{
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
break;
}
if (file_info.uncompressed_size>0)
- ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
+ ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
/* display a '*' if the file is crypted */
if ((file_info.flag & 1) != 0)
@@ -211,12 +277,17 @@ int do_list(uf)
string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
}
else
+ if (file_info.compression_method==Z_BZIP2ED)
+ {
+ string_method="BZip2 ";
+ }
+ else
string_method="Unkn. ";
- printf("%7lu %6s%c%7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
- file_info.uncompressed_size,string_method,
- charCrypt,
- file_info.compressed_size,
+ Display64BitsSize(file_info.uncompressed_size,7);
+ printf(" %6s%c",string_method,charCrypt);
+ Display64BitsSize(file_info.compressed_size,7);
+ printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
ratio,
(uLong)file_info.tmu_date.tm_mon + 1,
(uLong)file_info.tmu_date.tm_mday,
@@ -252,9 +323,9 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
void* buf;
uInt size_buf;
- unz_file_info file_info;
+ unz_file_info64 file_info;
uLong ratio=0;
- err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
+ err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if (err!=UNZ_OK)
{
@@ -306,7 +377,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
{
char rep=0;
FILE* ftestexist;
- ftestexist = fopen(write_filename,"rb");
+ ftestexist = FOPEN_FUNC(write_filename,"rb");
if (ftestexist!=NULL)
{
fclose(ftestexist);
@@ -317,7 +388,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
ret = scanf("%1s",answer);
- if (ret != 1)
+ if (ret != 1)
{
exit(EXIT_FAILURE);
}
@@ -337,8 +408,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
if ((skip==0) && (err==UNZ_OK))
{
- fout=fopen(write_filename,"wb");
-
+ fout=FOPEN_FUNC(write_filename,"wb");
/* some zipfile don't contain directory alone before file */
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
(filename_withoutpath!=(char*)filename_inzip))
@@ -347,7 +417,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
*(filename_withoutpath-1)='\0';
makedir(write_filename);
*(filename_withoutpath-1)=c;
- fout=fopen(write_filename,"wb");
+ fout=FOPEN_FUNC(write_filename,"wb");
}
if (fout==NULL)
@@ -409,11 +479,11 @@ int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
const char* password;
{
uLong i;
- unz_global_info gi;
+ unz_global_info64 gi;
int err;
FILE* fout=NULL;
- err = unzGetGlobalInfo (uf,&gi);
+ err = unzGetGlobalInfo64(uf,&gi);
if (err!=UNZ_OK)
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
@@ -470,6 +540,7 @@ int main(argc,argv)
const char *password=NULL;
char filename_try[MAXFILENAME+16] = "";
int i;
+ int ret_value=0;
int opt_do_list=0;
int opt_do_extract=1;
int opt_do_extract_withoutpath=0;
@@ -532,7 +603,7 @@ int main(argc,argv)
{
# ifdef USEWIN32IOAPI
- zlib_filefunc_def ffunc;
+ zlib_filefunc64_def ffunc;
# endif
strncpy(filename_try, zipfilename,MAXFILENAME-1);
@@ -540,18 +611,18 @@ int main(argc,argv)
filename_try[ MAXFILENAME ] = '\0';
# ifdef USEWIN32IOAPI
- fill_win32_filefunc(&ffunc);
- uf = unzOpen2(zipfilename,&ffunc);
+ fill_win32_filefunc64A(&ffunc);
+ uf = unzOpen2_64(zipfilename,&ffunc);
# else
- uf = unzOpen(zipfilename);
+ uf = unzOpen64(zipfilename);
# endif
if (uf==NULL)
{
strcat(filename_try,".zip");
# ifdef USEWIN32IOAPI
- uf = unzOpen2(filename_try,&ffunc);
+ uf = unzOpen2_64(filename_try,&ffunc);
# else
- uf = unzOpen(filename_try);
+ uf = unzOpen64(filename_try);
# endif
}
}
@@ -564,22 +635,26 @@ int main(argc,argv)
printf("%s opened\n",filename_try);
if (opt_do_list==1)
- return do_list(uf);
+ ret_value = do_list(uf);
else if (opt_do_extract==1)
{
- if (opt_extractdir && chdir(dirname))
+#ifdef _WIN32
+ if (opt_extractdir && _chdir(dirname))
+#else
+ if (opt_extractdir && chdir(dirname))
+#endif
{
printf("Error changing into %s, aborting\n", dirname);
exit(-1);
}
if (filename_to_extract == NULL)
- return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
+ ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
else
- return do_extract_onefile(uf,filename_to_extract,
- opt_do_extract_withoutpath,opt_overwrite,password);
+ ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
}
- unzCloseCurrentFile(uf);
- return 0;
+ unzClose(uf);
+
+ return ret_value;
}