OLD | NEW |
1 /* | 1 /* |
2 miniunz.c | 2 miniunz.c |
3 Version 1.01e, February 12th, 2005 | 3 Version 1.1, February 14h, 2010 |
| 4 sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizi
p.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> |
11 #include <string.h> | 32 #include <string.h> |
12 #include <time.h> | 33 #include <time.h> |
13 #include <errno.h> | 34 #include <errno.h> |
14 #include <fcntl.h> | 35 #include <fcntl.h> |
15 | 36 |
16 #ifdef unix | 37 #ifdef unix |
17 # include <unistd.h> | 38 # include <unistd.h> |
18 # include <utime.h> | 39 # include <utime.h> |
19 #else | 40 #else |
20 # include <direct.h> | 41 # include <direct.h> |
21 # include <io.h> | 42 # include <io.h> |
22 #endif | 43 #endif |
23 | 44 |
24 #include "unzip.h" | 45 #include "unzip.h" |
25 | 46 |
26 #define CASESENSITIVITY (0) | 47 #define CASESENSITIVITY (0) |
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 |
34 /* | 55 /* |
35 mini unzip, demo of unzip package | 56 mini unzip, demo of unzip package |
36 | 57 |
37 usage : | 58 usage : |
38 Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] | 59 Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] |
39 | 60 |
40 list the file in the zipfile, and print the content of FILE_ID.ZIP or README.T
XT | 61 list the file in the zipfile, and print the content of FILE_ID.ZIP or README.T
XT |
41 if it exists | 62 if it exists |
42 */ | 63 */ |
43 | 64 |
44 | 65 |
45 /* change_file_date : change the date/time of a file | 66 /* change_file_date : change the date/time of a file |
46 filename : the filename of the file where date/time must be modified | 67 filename : the filename of the file where date/time must be modified |
47 dosdate : the new date at the MSDos format (4 bytes) | 68 dosdate : the new date at the MSDos format (4 bytes) |
48 tmu_date : the SAME new date at the tm_unz format */ | 69 tmu_date : the SAME new date at the tm_unz format */ |
49 void change_file_date(filename,dosdate,tmu_date) | 70 void change_file_date(filename,dosdate,tmu_date) |
50 const char *filename; | 71 const char *filename; |
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); |
62 LocalFileTimeToFileTime(&ftLocal,&ftm); | 83 LocalFileTimeToFileTime(&ftLocal,&ftm); |
63 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); | 84 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); |
64 CloseHandle(hFile); | 85 CloseHandle(hFile); |
65 #else | 86 #else |
66 #ifdef unix | 87 #ifdef unix |
67 struct utimbuf ut; | 88 struct utimbuf ut; |
68 struct tm newdate; | 89 struct tm newdate; |
(...skipping 15 matching lines...) Expand all Loading... |
84 } | 105 } |
85 | 106 |
86 | 107 |
87 /* mymkdir and change_file_date are not 100 % portable | 108 /* mymkdir and change_file_date are not 100 % portable |
88 As I don't know well Unix, I wait feedback for the unix portion */ | 109 As I don't know well Unix, I wait feedback for the unix portion */ |
89 | 110 |
90 int mymkdir(dirname) | 111 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); |
99 #endif | 120 #endif |
100 #endif | 121 #endif |
101 return ret; | 122 return ret; |
102 } | 123 } |
103 | 124 |
104 int makedir (newdir) | 125 int makedir (newdir) |
105 char *newdir; | 126 char *newdir; |
106 { | 127 { |
107 char *buffer ; | 128 char *buffer ; |
108 char *p; | 129 char *p; |
109 int len = (int)strlen(newdir); | 130 int len = (int)strlen(newdir); |
110 | 131 |
111 if (len <= 0) | 132 if (len <= 0) |
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] == '/') { |
118 buffer[len-1] = '\0'; | 144 buffer[len-1] = '\0'; |
119 } | 145 } |
120 if (mymkdir(buffer) == 0) | 146 if (mymkdir(buffer) == 0) |
121 { | 147 { |
122 free(buffer); | 148 free(buffer); |
123 return 1; | 149 return 1; |
124 } | 150 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [fil
e_to_extr.] [-d extractdir]\n\n" \ | 183 printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [fil
e_to_extr.] [-d extractdir]\n\n" \ |
158 " -e Extract without pathname (junk paths)\n" \ | 184 " -e Extract without pathname (junk paths)\n" \ |
159 " -x Extract with pathname\n" \ | 185 " -x Extract with pathname\n" \ |
160 " -v list files\n" \ | 186 " -v list files\n" \ |
161 " -l list files\n" \ | 187 " -l list files\n" \ |
162 " -d directory to extract into\n" \ | 188 " -d directory to extract into\n" \ |
163 " -o overwrite files without prompting\n" \ | 189 " -o overwrite files without prompting\n" \ |
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(filena
me_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.uncompress
ed_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) |
198 charCrypt='*'; | 251 charCrypt='*'; |
199 | 252 |
200 if (file_info.compression_method==0) | 253 if (file_info.compression_method==0) |
201 string_method="Stored"; | 254 string_method="Stored"; |
202 else | 255 else |
203 if (file_info.compression_method==Z_DEFLATED) | 256 if (file_info.compression_method==Z_DEFLATED) |
204 { | 257 { |
205 uInt iLevel=(uInt)((file_info.flag & 0x6)/2); | 258 uInt iLevel=(uInt)((file_info.flag & 0x6)/2); |
206 if (iLevel==0) | 259 if (iLevel==0) |
207 string_method="Defl:N"; | 260 string_method="Defl:N"; |
208 else if (iLevel==1) | 261 else if (iLevel==1) |
209 string_method="Defl:X"; | 262 string_method="Defl:X"; |
210 else if ((iLevel==2) || (iLevel==3)) | 263 else if ((iLevel==2) || (iLevel==3)) |
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, |
223 (uLong)file_info.tmu_date.tm_year % 100, | 281 (uLong)file_info.tmu_date.tm_year % 100, |
224 (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_m
in, | 282 (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_m
in, |
225 (uLong)file_info.crc,filename_inzip); | 283 (uLong)file_info.crc,filename_inzip); |
226 if ((i+1)<gi.number_entry) | 284 if ((i+1)<gi.number_entry) |
227 { | 285 { |
228 err = unzGoToNextFile(uf); | 286 err = unzGoToNextFile(uf); |
229 if (err!=UNZ_OK) | 287 if (err!=UNZ_OK) |
(...skipping 15 matching lines...) Expand all Loading... |
245 const char* password; | 303 const char* password; |
246 { | 304 { |
247 char filename_inzip[256]; | 305 char filename_inzip[256]; |
248 char* filename_withoutpath; | 306 char* filename_withoutpath; |
249 char* p; | 307 char* p; |
250 int err=UNZ_OK; | 308 int err=UNZ_OK; |
251 FILE *fout=NULL; | 309 FILE *fout=NULL; |
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_inz
ip),NULL,0,NULL,0); | 315 err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_i
nzip),NULL,0,NULL,0); |
258 | 316 |
259 if (err!=UNZ_OK) | 317 if (err!=UNZ_OK) |
260 { | 318 { |
261 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); | 319 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); |
262 return err; | 320 return err; |
263 } | 321 } |
264 | 322 |
265 size_buf = WRITEBUFFERSIZE; | 323 size_buf = WRITEBUFFERSIZE; |
266 buf = (void*)malloc(size_buf); | 324 buf = (void*)malloc(size_buf); |
267 if (buf==NULL) | 325 if (buf==NULL) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 err = unzOpenCurrentFilePassword(uf,password); | 357 err = unzOpenCurrentFilePassword(uf,password); |
300 if (err!=UNZ_OK) | 358 if (err!=UNZ_OK) |
301 { | 359 { |
302 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); | 360 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); |
303 } | 361 } |
304 | 362 |
305 if (((*popt_overwrite)==0) && (err==UNZ_OK)) | 363 if (((*popt_overwrite)==0) && (err==UNZ_OK)) |
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); |
313 do | 371 do |
314 { | 372 { |
315 char answer[128]; | 373 char answer[128]; |
316 int ret; | 374 int ret; |
317 | 375 |
318 printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll:
",write_filename); | 376 printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll:
",write_filename); |
319 ret = scanf("%1s",answer); | 377 ret = scanf("%1s",answer); |
320 if (ret != 1) | 378 if (ret != 1) |
321 { | 379 { |
322 exit(EXIT_FAILURE); | 380 exit(EXIT_FAILURE); |
323 } | 381 } |
324 rep = answer[0] ; | 382 rep = answer[0] ; |
325 if ((rep>='a') && (rep<='z')) | 383 if ((rep>='a') && (rep<='z')) |
326 rep -= 0x20; | 384 rep -= 0x20; |
327 } | 385 } |
328 while ((rep!='Y') && (rep!='N') && (rep!='A')); | 386 while ((rep!='Y') && (rep!='N') && (rep!='A')); |
329 } | 387 } |
330 | 388 |
331 if (rep == 'N') | 389 if (rep == 'N') |
332 skip = 1; | 390 skip = 1; |
333 | 391 |
334 if (rep == 'A') | 392 if (rep == 'A') |
335 *popt_overwrite=1; | 393 *popt_overwrite=1; |
336 } | 394 } |
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) && |
344 (filename_withoutpath!=(char*)filename_inzip)) | 402 (filename_withoutpath!=(char*)filename_inzip)) |
345 { | 403 { |
346 char c=*(filename_withoutpath-1); | 404 char c=*(filename_withoutpath-1); |
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) |
354 { | 412 { |
355 printf("error opening %s\n",write_filename); | 413 printf("error opening %s\n",write_filename); |
356 } | 414 } |
357 } | 415 } |
358 | 416 |
359 if (fout!=NULL) | 417 if (fout!=NULL) |
360 { | 418 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 460 } |
403 | 461 |
404 | 462 |
405 int do_extract(uf,opt_extract_without_path,opt_overwrite,password) | 463 int do_extract(uf,opt_extract_without_path,opt_overwrite,password) |
406 unzFile uf; | 464 unzFile uf; |
407 int opt_extract_without_path; | 465 int opt_extract_without_path; |
408 int opt_overwrite; | 466 int opt_overwrite; |
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 |
420 for (i=0;i<gi.number_entry;i++) | 478 for (i=0;i<gi.number_entry;i++) |
421 { | 479 { |
422 if (do_extract_currentfile(uf,&opt_extract_without_path, | 480 if (do_extract_currentfile(uf,&opt_extract_without_path, |
423 &opt_overwrite, | 481 &opt_overwrite, |
424 password) != UNZ_OK) | 482 password) != UNZ_OK) |
425 break; | 483 break; |
426 | 484 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 521 |
464 int main(argc,argv) | 522 int main(argc,argv) |
465 int argc; | 523 int argc; |
466 char *argv[]; | 524 char *argv[]; |
467 { | 525 { |
468 const char *zipfilename=NULL; | 526 const char *zipfilename=NULL; |
469 const char *filename_to_extract=NULL; | 527 const char *filename_to_extract=NULL; |
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; |
476 int opt_overwrite=0; | 535 int opt_overwrite=0; |
477 int opt_extractdir=0; | 536 int opt_extractdir=0; |
478 const char *dirname=NULL; | 537 const char *dirname=NULL; |
479 unzFile uf=NULL; | 538 unzFile uf=NULL; |
480 | 539 |
481 do_banner(); | 540 do_banner(); |
482 if (argc==1) | 541 if (argc==1) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 else if ((filename_to_extract==NULL) && (!opt_extractdir)) | 584 else if ((filename_to_extract==NULL) && (!opt_extractdir)) |
526 filename_to_extract = argv[i] ; | 585 filename_to_extract = argv[i] ; |
527 } | 586 } |
528 } | 587 } |
529 } | 588 } |
530 | 589 |
531 if (zipfilename!=NULL) | 590 if (zipfilename!=NULL) |
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); |
539 /* strncpy doesnt append the trailing NULL, of the string is too long. *
/ | 598 /* strncpy doesnt append the trailing NULL, of the string is too long. *
/ |
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 } |
558 | 617 |
559 if (uf==NULL) | 618 if (uf==NULL) |
560 { | 619 { |
561 printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); | 620 printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); |
562 return 1; | 621 return 1; |
563 } | 622 } |
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 { |
570 if (opt_extractdir && chdir(dirname)) | 629 #ifdef _WIN32 |
| 630 if (opt_extractdir && _chdir(dirname)) |
| 631 #else |
| 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,passwo
rd); | 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_extra
ct_withoutpath, opt_overwrite, password); |
580 opt_do_extract_withoutpath,opt_overwrite,p
assword); | |
581 } | 643 } |
582 unzCloseCurrentFile(uf); | |
583 | 644 |
584 return 0; | 645 unzClose(uf); |
| 646 |
| 647 return ret_value; |
585 } | 648 } |
OLD | NEW |