diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:26:49 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:26:49 -0700 |
commit | d004b047838a7e803818b4973a2e39e0ff8c1fa2 (patch) | |
tree | 9e8c804f78d73152c70d4ff24c6a7531a0d46782 /contrib/minizip/miniunz.c | |
parent | f6194ef39af5864f792412460c354cc339dde7d1 (diff) | |
download | zlib-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 'contrib/minizip/miniunz.c')
-rw-r--r-- | contrib/minizip/miniunz.c | 137 |
1 files changed, 100 insertions, 37 deletions
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 | ||
193 | void 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 | ||
168 | int do_list(uf) | 221 | int 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 | } |