| OLD | NEW |
| 1 /* | 1 /* |
| 2 miniunz.c | 2 miniunz.c |
| 3 Version 1.1, February 14h, 2010 | 3 Version 1.1, February 14h, 2010 |
| 4 sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizi
p.html ) | 4 sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizi
p.html ) |
| 5 | 5 |
| 6 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.
com/zLibDll/minizip.html ) | 6 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.
com/zLibDll/minizip.html ) |
| 7 | 7 |
| 8 Modifications of Unzip for Zip64 | 8 Modifications of Unzip for Zip64 |
| 9 Copyright (C) 2007-2008 Even Rouault | 9 Copyright (C) 2007-2008 Even Rouault |
| 10 | 10 |
| 11 Modifications for Zip64 support on both zip and unzip | 11 Modifications for Zip64 support on both zip and unzip |
| 12 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | 12 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 #ifndef _WIN32 | 15 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) |
| 16 #ifndef __USE_FILE_OFFSET64 | 16 #ifndef __USE_FILE_OFFSET64 |
| 17 #define __USE_FILE_OFFSET64 | 17 #define __USE_FILE_OFFSET64 |
| 18 #endif | 18 #endif |
| 19 #ifndef __USE_LARGEFILE64 | 19 #ifndef __USE_LARGEFILE64 |
| 20 #define __USE_LARGEFILE64 | 20 #define __USE_LARGEFILE64 |
| 21 #endif | 21 #endif |
| 22 #ifndef _LARGEFILE64_SOURCE | 22 #ifndef _LARGEFILE64_SOURCE |
| 23 #define _LARGEFILE64_SOURCE | 23 #define _LARGEFILE64_SOURCE |
| 24 #endif | 24 #endif |
| 25 #ifndef _FILE_OFFSET_BIT | 25 #ifndef _FILE_OFFSET_BIT |
| 26 #define _FILE_OFFSET_BIT 64 | 26 #define _FILE_OFFSET_BIT 64 |
| 27 #endif | 27 #endif |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 #ifdef __APPLE__ |
| 31 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no ne
ed for specific 64 bit functions |
| 32 #define FOPEN_FUNC(filename, mode) fopen(filename, mode) |
| 33 #define FTELLO_FUNC(stream) ftello(stream) |
| 34 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) |
| 35 #else |
| 36 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) |
| 37 #define FTELLO_FUNC(stream) ftello64(stream) |
| 38 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) |
| 39 #endif |
| 40 |
| 41 |
| 30 #include <stdio.h> | 42 #include <stdio.h> |
| 31 #include <stdlib.h> | 43 #include <stdlib.h> |
| 32 #include <string.h> | 44 #include <string.h> |
| 33 #include <time.h> | 45 #include <time.h> |
| 34 #include <errno.h> | 46 #include <errno.h> |
| 35 #include <fcntl.h> | 47 #include <fcntl.h> |
| 36 | 48 |
| 37 #ifdef unix | 49 #ifdef _WIN32 |
| 50 # include <direct.h> |
| 51 # include <io.h> |
| 52 #else |
| 38 # include <unistd.h> | 53 # include <unistd.h> |
| 39 # include <utime.h> | 54 # include <utime.h> |
| 40 #else | |
| 41 # include <direct.h> | |
| 42 # include <io.h> | |
| 43 #endif | 55 #endif |
| 44 | 56 |
| 57 |
| 45 #include "unzip.h" | 58 #include "unzip.h" |
| 46 | 59 |
| 47 #define CASESENSITIVITY (0) | 60 #define CASESENSITIVITY (0) |
| 48 #define WRITEBUFFERSIZE (8192) | 61 #define WRITEBUFFERSIZE (8192) |
| 49 #define MAXFILENAME (256) | 62 #define MAXFILENAME (256) |
| 50 | 63 |
| 51 #ifdef _WIN32 | 64 #ifdef _WIN32 |
| 52 #define USEWIN32IOAPI | 65 #define USEWIN32IOAPI |
| 53 #include "iowin32.h" | 66 #include "iowin32.h" |
| 54 #endif | 67 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 77 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; | 90 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; |
| 78 | 91 |
| 79 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, | 92 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, |
| 80 0,NULL,OPEN_EXISTING,0,NULL); | 93 0,NULL,OPEN_EXISTING,0,NULL); |
| 81 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); | 94 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); |
| 82 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); | 95 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); |
| 83 LocalFileTimeToFileTime(&ftLocal,&ftm); | 96 LocalFileTimeToFileTime(&ftLocal,&ftm); |
| 84 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); | 97 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); |
| 85 CloseHandle(hFile); | 98 CloseHandle(hFile); |
| 86 #else | 99 #else |
| 87 #ifdef unix | 100 #ifdef unix || __APPLE__ |
| 88 struct utimbuf ut; | 101 struct utimbuf ut; |
| 89 struct tm newdate; | 102 struct tm newdate; |
| 90 newdate.tm_sec = tmu_date.tm_sec; | 103 newdate.tm_sec = tmu_date.tm_sec; |
| 91 newdate.tm_min=tmu_date.tm_min; | 104 newdate.tm_min=tmu_date.tm_min; |
| 92 newdate.tm_hour=tmu_date.tm_hour; | 105 newdate.tm_hour=tmu_date.tm_hour; |
| 93 newdate.tm_mday=tmu_date.tm_mday; | 106 newdate.tm_mday=tmu_date.tm_mday; |
| 94 newdate.tm_mon=tmu_date.tm_mon; | 107 newdate.tm_mon=tmu_date.tm_mon; |
| 95 if (tmu_date.tm_year > 1900) | 108 if (tmu_date.tm_year > 1900) |
| 96 newdate.tm_year=tmu_date.tm_year - 1900; | 109 newdate.tm_year=tmu_date.tm_year - 1900; |
| 97 else | 110 else |
| 98 newdate.tm_year=tmu_date.tm_year ; | 111 newdate.tm_year=tmu_date.tm_year ; |
| 99 newdate.tm_isdst=-1; | 112 newdate.tm_isdst=-1; |
| 100 | 113 |
| 101 ut.actime=ut.modtime=mktime(&newdate); | 114 ut.actime=ut.modtime=mktime(&newdate); |
| 102 utime(filename,&ut); | 115 utime(filename,&ut); |
| 103 #endif | 116 #endif |
| 104 #endif | 117 #endif |
| 105 } | 118 } |
| 106 | 119 |
| 107 | 120 |
| 108 /* mymkdir and change_file_date are not 100 % portable | 121 /* mymkdir and change_file_date are not 100 % portable |
| 109 As I don't know well Unix, I wait feedback for the unix portion */ | 122 As I don't know well Unix, I wait feedback for the unix portion */ |
| 110 | 123 |
| 111 int mymkdir(dirname) | 124 int mymkdir(dirname) |
| 112 const char* dirname; | 125 const char* dirname; |
| 113 { | 126 { |
| 114 int ret=0; | 127 int ret=0; |
| 115 #ifdef _WIN32 | 128 #ifdef _WIN32 |
| 116 ret = _mkdir(dirname); | 129 ret = _mkdir(dirname); |
| 117 #else | 130 #elif unix |
| 118 #ifdef unix | |
| 119 ret = mkdir (dirname,0775); | 131 ret = mkdir (dirname,0775); |
| 120 #endif | 132 #elif __APPLE__ |
| 133 ret = mkdir (dirname,0775); |
| 121 #endif | 134 #endif |
| 122 return ret; | 135 return ret; |
| 123 } | 136 } |
| 124 | 137 |
| 125 int makedir (newdir) | 138 int makedir (newdir) |
| 126 char *newdir; | 139 char *newdir; |
| 127 { | 140 { |
| 128 char *buffer ; | 141 char *buffer ; |
| 129 char *p; | 142 char *p; |
| 130 int len = (int)strlen(newdir); | 143 int len = (int)strlen(newdir); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 err = unzOpenCurrentFilePassword(uf,password); | 370 err = unzOpenCurrentFilePassword(uf,password); |
| 358 if (err!=UNZ_OK) | 371 if (err!=UNZ_OK) |
| 359 { | 372 { |
| 360 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); | 373 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); |
| 361 } | 374 } |
| 362 | 375 |
| 363 if (((*popt_overwrite)==0) && (err==UNZ_OK)) | 376 if (((*popt_overwrite)==0) && (err==UNZ_OK)) |
| 364 { | 377 { |
| 365 char rep=0; | 378 char rep=0; |
| 366 FILE* ftestexist; | 379 FILE* ftestexist; |
| 367 ftestexist = fopen64(write_filename,"rb"); | 380 ftestexist = FOPEN_FUNC(write_filename,"rb"); |
| 368 if (ftestexist!=NULL) | 381 if (ftestexist!=NULL) |
| 369 { | 382 { |
| 370 fclose(ftestexist); | 383 fclose(ftestexist); |
| 371 do | 384 do |
| 372 { | 385 { |
| 373 char answer[128]; | 386 char answer[128]; |
| 374 int ret; | 387 int ret; |
| 375 | 388 |
| 376 printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll:
",write_filename); | 389 printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll:
",write_filename); |
| 377 ret = scanf("%1s",answer); | 390 ret = scanf("%1s",answer); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 388 | 401 |
| 389 if (rep == 'N') | 402 if (rep == 'N') |
| 390 skip = 1; | 403 skip = 1; |
| 391 | 404 |
| 392 if (rep == 'A') | 405 if (rep == 'A') |
| 393 *popt_overwrite=1; | 406 *popt_overwrite=1; |
| 394 } | 407 } |
| 395 | 408 |
| 396 if ((skip==0) && (err==UNZ_OK)) | 409 if ((skip==0) && (err==UNZ_OK)) |
| 397 { | 410 { |
| 398 fout=fopen64(write_filename,"wb"); | 411 fout=FOPEN_FUNC(write_filename,"wb"); |
| 399 | |
| 400 /* some zipfile don't contain directory alone before file */ | 412 /* some zipfile don't contain directory alone before file */ |
| 401 if ((fout==NULL) && ((*popt_extract_without_path)==0) && | 413 if ((fout==NULL) && ((*popt_extract_without_path)==0) && |
| 402 (filename_withoutpath!=(char*)filename_inzip)) | 414 (filename_withoutpath!=(char*)filename_inzip)) |
| 403 { | 415 { |
| 404 char c=*(filename_withoutpath-1); | 416 char c=*(filename_withoutpath-1); |
| 405 *(filename_withoutpath-1)='\0'; | 417 *(filename_withoutpath-1)='\0'; |
| 406 makedir(write_filename); | 418 makedir(write_filename); |
| 407 *(filename_withoutpath-1)=c; | 419 *(filename_withoutpath-1)=c; |
| 408 fout=fopen64(write_filename,"wb"); | 420 fout=FOPEN_FUNC(write_filename,"wb"); |
| 409 } | 421 } |
| 410 | 422 |
| 411 if (fout==NULL) | 423 if (fout==NULL) |
| 412 { | 424 { |
| 413 printf("error opening %s\n",write_filename); | 425 printf("error opening %s\n",write_filename); |
| 414 } | 426 } |
| 415 } | 427 } |
| 416 | 428 |
| 417 if (fout!=NULL) | 429 if (fout!=NULL) |
| 418 { | 430 { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 if (filename_to_extract == NULL) | 651 if (filename_to_extract == NULL) |
| 640 ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite
, password); | 652 ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite
, password); |
| 641 else | 653 else |
| 642 ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extra
ct_withoutpath, opt_overwrite, password); | 654 ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extra
ct_withoutpath, opt_overwrite, password); |
| 643 } | 655 } |
| 644 | 656 |
| 645 unzClose(uf); | 657 unzClose(uf); |
| 646 | 658 |
| 647 return ret_value; | 659 return ret_value; |
| 648 } | 660 } |
| OLD | NEW |