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 |
45 #include "unzip.h" | 57 #include "unzip.h" |
46 | 58 |
47 #define CASESENSITIVITY (0) | 59 #define CASESENSITIVITY (0) |
48 #define WRITEBUFFERSIZE (8192) | 60 #define WRITEBUFFERSIZE (8192) |
49 #define MAXFILENAME (256) | 61 #define MAXFILENAME (256) |
50 | 62 |
51 #ifdef _WIN32 | 63 #ifdef _WIN32 |
52 #define USEWIN32IOAPI | 64 #define USEWIN32IOAPI |
(...skipping 24 matching lines...) Expand all Loading... |
77 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; | 89 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; |
78 | 90 |
79 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, | 91 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, |
80 0,NULL,OPEN_EXISTING,0,NULL); | 92 0,NULL,OPEN_EXISTING,0,NULL); |
81 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); | 93 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); |
82 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); | 94 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); |
83 LocalFileTimeToFileTime(&ftLocal,&ftm); | 95 LocalFileTimeToFileTime(&ftLocal,&ftm); |
84 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); | 96 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); |
85 CloseHandle(hFile); | 97 CloseHandle(hFile); |
86 #else | 98 #else |
87 #ifdef unix | 99 #ifdef unix || __APPLE__ |
88 struct utimbuf ut; | 100 struct utimbuf ut; |
89 struct tm newdate; | 101 struct tm newdate; |
90 newdate.tm_sec = tmu_date.tm_sec; | 102 newdate.tm_sec = tmu_date.tm_sec; |
91 newdate.tm_min=tmu_date.tm_min; | 103 newdate.tm_min=tmu_date.tm_min; |
92 newdate.tm_hour=tmu_date.tm_hour; | 104 newdate.tm_hour=tmu_date.tm_hour; |
93 newdate.tm_mday=tmu_date.tm_mday; | 105 newdate.tm_mday=tmu_date.tm_mday; |
94 newdate.tm_mon=tmu_date.tm_mon; | 106 newdate.tm_mon=tmu_date.tm_mon; |
95 if (tmu_date.tm_year > 1900) | 107 if (tmu_date.tm_year > 1900) |
96 newdate.tm_year=tmu_date.tm_year - 1900; | 108 newdate.tm_year=tmu_date.tm_year - 1900; |
97 else | 109 else |
98 newdate.tm_year=tmu_date.tm_year ; | 110 newdate.tm_year=tmu_date.tm_year ; |
99 newdate.tm_isdst=-1; | 111 newdate.tm_isdst=-1; |
100 | 112 |
101 ut.actime=ut.modtime=mktime(&newdate); | 113 ut.actime=ut.modtime=mktime(&newdate); |
102 utime(filename,&ut); | 114 utime(filename,&ut); |
103 #endif | 115 #endif |
104 #endif | 116 #endif |
105 } | 117 } |
106 | 118 |
107 | 119 |
108 /* mymkdir and change_file_date are not 100 % portable | 120 /* mymkdir and change_file_date are not 100 % portable |
109 As I don't know well Unix, I wait feedback for the unix portion */ | 121 As I don't know well Unix, I wait feedback for the unix portion */ |
110 | 122 |
111 int mymkdir(dirname) | 123 int mymkdir(dirname) |
112 const char* dirname; | 124 const char* dirname; |
113 { | 125 { |
114 int ret=0; | 126 int ret=0; |
115 #ifdef _WIN32 | 127 #ifdef _WIN32 |
116 ret = _mkdir(dirname); | 128 ret = _mkdir(dirname); |
117 #else | 129 #elif unix |
118 #ifdef unix | |
119 ret = mkdir (dirname,0775); | 130 ret = mkdir (dirname,0775); |
120 #endif | 131 #elif __APPLE__ |
| 132 ret = mkdir (dirname,0775); |
121 #endif | 133 #endif |
122 return ret; | 134 return ret; |
123 } | 135 } |
124 | 136 |
125 int makedir (newdir) | 137 int makedir (newdir) |
126 char *newdir; | 138 char *newdir; |
127 { | 139 { |
128 char *buffer ; | 140 char *buffer ; |
129 char *p; | 141 char *p; |
130 int len = (int)strlen(newdir); | 142 int len = (int)strlen(newdir); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 err = unzOpenCurrentFilePassword(uf,password); | 369 err = unzOpenCurrentFilePassword(uf,password); |
358 if (err!=UNZ_OK) | 370 if (err!=UNZ_OK) |
359 { | 371 { |
360 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); | 372 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); |
361 } | 373 } |
362 | 374 |
363 if (((*popt_overwrite)==0) && (err==UNZ_OK)) | 375 if (((*popt_overwrite)==0) && (err==UNZ_OK)) |
364 { | 376 { |
365 char rep=0; | 377 char rep=0; |
366 FILE* ftestexist; | 378 FILE* ftestexist; |
367 ftestexist = fopen64(write_filename,"rb"); | 379 ftestexist = FOPEN_FUNC(write_filename,"rb"); |
368 if (ftestexist!=NULL) | 380 if (ftestexist!=NULL) |
369 { | 381 { |
370 fclose(ftestexist); | 382 fclose(ftestexist); |
371 do | 383 do |
372 { | 384 { |
373 char answer[128]; | 385 char answer[128]; |
374 int ret; | 386 int ret; |
375 | 387 |
376 printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll:
",write_filename); | 388 printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll:
",write_filename); |
377 ret = scanf("%1s",answer); | 389 ret = scanf("%1s",answer); |
(...skipping 10 matching lines...) Expand all Loading... |
388 | 400 |
389 if (rep == 'N') | 401 if (rep == 'N') |
390 skip = 1; | 402 skip = 1; |
391 | 403 |
392 if (rep == 'A') | 404 if (rep == 'A') |
393 *popt_overwrite=1; | 405 *popt_overwrite=1; |
394 } | 406 } |
395 | 407 |
396 if ((skip==0) && (err==UNZ_OK)) | 408 if ((skip==0) && (err==UNZ_OK)) |
397 { | 409 { |
398 fout=fopen64(write_filename,"wb"); | 410 fout=FOPEN_FUNC(write_filename,"wb"); |
399 | |
400 /* some zipfile don't contain directory alone before file */ | 411 /* some zipfile don't contain directory alone before file */ |
401 if ((fout==NULL) && ((*popt_extract_without_path)==0) && | 412 if ((fout==NULL) && ((*popt_extract_without_path)==0) && |
402 (filename_withoutpath!=(char*)filename_inzip)) | 413 (filename_withoutpath!=(char*)filename_inzip)) |
403 { | 414 { |
404 char c=*(filename_withoutpath-1); | 415 char c=*(filename_withoutpath-1); |
405 *(filename_withoutpath-1)='\0'; | 416 *(filename_withoutpath-1)='\0'; |
406 makedir(write_filename); | 417 makedir(write_filename); |
407 *(filename_withoutpath-1)=c; | 418 *(filename_withoutpath-1)=c; |
408 fout=fopen64(write_filename,"wb"); | 419 fout=FOPEN_FUNC(write_filename,"wb"); |
409 } | 420 } |
410 | 421 |
411 if (fout==NULL) | 422 if (fout==NULL) |
412 { | 423 { |
413 printf("error opening %s\n",write_filename); | 424 printf("error opening %s\n",write_filename); |
414 } | 425 } |
415 } | 426 } |
416 | 427 |
417 if (fout!=NULL) | 428 if (fout!=NULL) |
418 { | 429 { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 if (filename_to_extract == NULL) | 650 if (filename_to_extract == NULL) |
640 ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite
, password); | 651 ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite
, password); |
641 else | 652 else |
642 ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extra
ct_withoutpath, opt_overwrite, password); | 653 ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extra
ct_withoutpath, opt_overwrite, password); |
643 } | 654 } |
644 | 655 |
645 unzClose(uf); | 656 unzClose(uf); |
646 | 657 |
647 return ret_value; | 658 return ret_value; |
648 } | 659 } |
OLD | NEW |