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/minizip.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/minizip.c')
-rw-r--r-- | contrib/minizip/minizip.c | 134 |
1 files changed, 111 insertions, 23 deletions
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c index f2dfecd..4ce33af 100644 --- a/contrib/minizip/minizip.c +++ b/contrib/minizip/minizip.c | |||
@@ -1,10 +1,33 @@ | |||
1 | /* | 1 | /* |
2 | minizip.c | 2 | minizip.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 | |||
16 | #ifndef _WIN32 | ||
17 | #ifndef __USE_FILE_OFFSET64 | ||
18 | #define __USE_FILE_OFFSET64 | ||
19 | #endif | ||
20 | #ifndef __USE_LARGEFILE64 | ||
21 | #define __USE_LARGEFILE64 | ||
22 | #endif | ||
23 | #ifndef _LARGEFILE64_SOURCE | ||
24 | #define _LARGEFILE64_SOURCE | ||
25 | #endif | ||
26 | #ifndef _FILE_OFFSET_BIT | ||
27 | #define _FILE_OFFSET_BIT 64 | ||
28 | #endif | ||
29 | #endif | ||
30 | |||
8 | #include <stdio.h> | 31 | #include <stdio.h> |
9 | #include <stdlib.h> | 32 | #include <stdlib.h> |
10 | #include <string.h> | 33 | #include <string.h> |
@@ -24,9 +47,9 @@ | |||
24 | 47 | ||
25 | #include "zip.h" | 48 | #include "zip.h" |
26 | 49 | ||
27 | #ifdef WIN32 | 50 | #ifdef _WIN32 |
28 | #define USEWIN32IOAPI | 51 | #define USEWIN32IOAPI |
29 | #include "iowin32.h" | 52 | #include "iowin32.h" |
30 | #endif | 53 | #endif |
31 | 54 | ||
32 | 55 | ||
@@ -34,7 +57,7 @@ | |||
34 | #define WRITEBUFFERSIZE (16384) | 57 | #define WRITEBUFFERSIZE (16384) |
35 | #define MAXFILENAME (256) | 58 | #define MAXFILENAME (256) |
36 | 59 | ||
37 | #ifdef WIN32 | 60 | #ifdef _WIN32 |
38 | uLong filetime(f, tmzip, dt) | 61 | uLong filetime(f, tmzip, dt) |
39 | char *f; /* name of file to get info on */ | 62 | char *f; /* name of file to get info on */ |
40 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 63 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
@@ -44,9 +67,9 @@ uLong filetime(f, tmzip, dt) | |||
44 | { | 67 | { |
45 | FILETIME ftLocal; | 68 | FILETIME ftLocal; |
46 | HANDLE hFind; | 69 | HANDLE hFind; |
47 | WIN32_FIND_DATA ff32; | 70 | WIN32_FIND_DATAA ff32; |
48 | 71 | ||
49 | hFind = FindFirstFile(f,&ff32); | 72 | hFind = FindFirstFileA(f,&ff32); |
50 | if (hFind != INVALID_HANDLE_VALUE) | 73 | if (hFind != INVALID_HANDLE_VALUE) |
51 | { | 74 | { |
52 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); | 75 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); |
@@ -119,7 +142,7 @@ int check_exist_file(filename) | |||
119 | { | 142 | { |
120 | FILE* ftestexist; | 143 | FILE* ftestexist; |
121 | int ret = 1; | 144 | int ret = 1; |
122 | ftestexist = fopen(filename,"rb"); | 145 | ftestexist = fopen64(filename,"rb"); |
123 | if (ftestexist==NULL) | 146 | if (ftestexist==NULL) |
124 | ret = 0; | 147 | ret = 0; |
125 | else | 148 | else |
@@ -129,18 +152,20 @@ int check_exist_file(filename) | |||
129 | 152 | ||
130 | void do_banner() | 153 | void do_banner() |
131 | { | 154 | { |
132 | printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); | 155 | printf("MiniZip64 1.0, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); |
133 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 156 | printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); |
157 | printf("more info on MiniZip64 at http://result42.com/projects/MiniZip64\n\n"); | ||
134 | } | 158 | } |
135 | 159 | ||
136 | void do_help() | 160 | void do_help() |
137 | { | 161 | { |
138 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \ | 162 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ |
139 | " -o Overwrite existing file.zip\n" \ | 163 | " -o Overwrite existing file.zip\n" \ |
140 | " -a Append to existing file.zip\n" \ | 164 | " -a Append to existing file.zip\n" \ |
141 | " -0 Store only\n" \ | 165 | " -0 Store only\n" \ |
142 | " -1 Compress faster\n" \ | 166 | " -1 Compress faster\n" \ |
143 | " -9 Compress better\n\n"); | 167 | " -9 Compress better\n\n" \ |
168 | " -j exclude path. store only the file name.\n\n"); | ||
144 | } | 169 | } |
145 | 170 | ||
146 | /* calculate the CRC32 of a file, | 171 | /* calculate the CRC32 of a file, |
@@ -149,7 +174,7 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne | |||
149 | { | 174 | { |
150 | unsigned long calculate_crc=0; | 175 | unsigned long calculate_crc=0; |
151 | int err=ZIP_OK; | 176 | int err=ZIP_OK; |
152 | FILE * fin = fopen(filenameinzip,"rb"); | 177 | FILE * fin = fopen64(filenameinzip,"rb"); |
153 | unsigned long size_read = 0; | 178 | unsigned long size_read = 0; |
154 | unsigned long total_read = 0; | 179 | unsigned long total_read = 0; |
155 | if (fin==NULL) | 180 | if (fin==NULL) |
@@ -179,10 +204,33 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne | |||
179 | fclose(fin); | 204 | fclose(fin); |
180 | 205 | ||
181 | *result_crc=calculate_crc; | 206 | *result_crc=calculate_crc; |
182 | printf("file %s crc %x\n",filenameinzip,calculate_crc); | 207 | printf("file %s crc %lx\n", filenameinzip, calculate_crc); |
183 | return err; | 208 | return err; |
184 | } | 209 | } |
185 | 210 | ||
211 | int isLargeFile(const char* filename) | ||
212 | { | ||
213 | int largeFile = 0; | ||
214 | ZPOS64_T pos = 0; | ||
215 | FILE* pFile = fopen64(filename, "rb"); | ||
216 | |||
217 | if(pFile != NULL) | ||
218 | { | ||
219 | int n = fseeko64(pFile, 0, SEEK_END); | ||
220 | |||
221 | pos = ftello64(pFile); | ||
222 | |||
223 | printf("File : %s is %lld bytes\n", filename, pos); | ||
224 | |||
225 | if(pos >= 0xffffffff) | ||
226 | largeFile = 1; | ||
227 | |||
228 | fclose(pFile); | ||
229 | } | ||
230 | |||
231 | return largeFile; | ||
232 | } | ||
233 | |||
186 | int main(argc,argv) | 234 | int main(argc,argv) |
187 | int argc; | 235 | int argc; |
188 | char *argv[]; | 236 | char *argv[]; |
@@ -190,6 +238,7 @@ int main(argc,argv) | |||
190 | int i; | 238 | int i; |
191 | int opt_overwrite=0; | 239 | int opt_overwrite=0; |
192 | int opt_compress_level=Z_DEFAULT_COMPRESSION; | 240 | int opt_compress_level=Z_DEFAULT_COMPRESSION; |
241 | int opt_exclude_path=0; | ||
193 | int zipfilenamearg = 0; | 242 | int zipfilenamearg = 0; |
194 | char filename_try[MAXFILENAME+16]; | 243 | char filename_try[MAXFILENAME+16]; |
195 | int zipok; | 244 | int zipok; |
@@ -222,6 +271,8 @@ int main(argc,argv) | |||
222 | opt_overwrite = 2; | 271 | opt_overwrite = 2; |
223 | if ((c>='0') && (c<='9')) | 272 | if ((c>='0') && (c<='9')) |
224 | opt_compress_level = c-'0'; | 273 | opt_compress_level = c-'0'; |
274 | if ((c=='j') || (c=='J')) | ||
275 | opt_exclude_path = 1; | ||
225 | 276 | ||
226 | if (((c=='p') || (c=='P')) && (i+1<argc)) | 277 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
227 | { | 278 | { |
@@ -231,8 +282,12 @@ int main(argc,argv) | |||
231 | } | 282 | } |
232 | } | 283 | } |
233 | else | 284 | else |
285 | { | ||
234 | if (zipfilenamearg == 0) | 286 | if (zipfilenamearg == 0) |
287 | { | ||
235 | zipfilenamearg = i ; | 288 | zipfilenamearg = i ; |
289 | } | ||
290 | } | ||
236 | } | 291 | } |
237 | } | 292 | } |
238 | 293 | ||
@@ -245,7 +300,9 @@ int main(argc,argv) | |||
245 | } | 300 | } |
246 | 301 | ||
247 | if (zipfilenamearg==0) | 302 | if (zipfilenamearg==0) |
303 | { | ||
248 | zipok=0; | 304 | zipok=0; |
305 | } | ||
249 | else | 306 | else |
250 | { | 307 | { |
251 | int i,len; | 308 | int i,len; |
@@ -302,11 +359,11 @@ int main(argc,argv) | |||
302 | zipFile zf; | 359 | zipFile zf; |
303 | int errclose; | 360 | int errclose; |
304 | # ifdef USEWIN32IOAPI | 361 | # ifdef USEWIN32IOAPI |
305 | zlib_filefunc_def ffunc; | 362 | zlib_filefunc64_def ffunc; |
306 | fill_win32_filefunc(&ffunc); | 363 | fill_win32_filefunc64A(&ffunc); |
307 | zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); | 364 | zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); |
308 | # else | 365 | # else |
309 | zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); | 366 | zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); |
310 | # endif | 367 | # endif |
311 | 368 | ||
312 | if (zf == NULL) | 369 | if (zf == NULL) |
@@ -329,8 +386,10 @@ int main(argc,argv) | |||
329 | FILE * fin; | 386 | FILE * fin; |
330 | int size_read; | 387 | int size_read; |
331 | const char* filenameinzip = argv[i]; | 388 | const char* filenameinzip = argv[i]; |
389 | const char *savefilenameinzip; | ||
332 | zip_fileinfo zi; | 390 | zip_fileinfo zi; |
333 | unsigned long crcFile=0; | 391 | unsigned long crcFile=0; |
392 | int zip64 = 0; | ||
334 | 393 | ||
335 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = | 394 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = |
336 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; | 395 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; |
@@ -347,20 +406,49 @@ int main(argc,argv) | |||
347 | */ | 406 | */ |
348 | if ((password != NULL) && (err==ZIP_OK)) | 407 | if ((password != NULL) && (err==ZIP_OK)) |
349 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); | 408 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); |
350 | 409 | ||
351 | err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, | 410 | zip64 = isLargeFile(filenameinzip); |
411 | |||
412 | /* The path name saved, should not include a leading slash. */ | ||
413 | /*if it did, windows/xp and dynazip couldn't read the zip file. */ | ||
414 | savefilenameinzip = filenameinzip; | ||
415 | while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) | ||
416 | { | ||
417 | savefilenameinzip++; | ||
418 | } | ||
419 | |||
420 | /*should the zip file contain any path at all?*/ | ||
421 | if( opt_exclude_path ) | ||
422 | { | ||
423 | const char *tmpptr; | ||
424 | const char *lastslash = 0; | ||
425 | for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) | ||
426 | { | ||
427 | if( *tmpptr == '\\' || *tmpptr == '/') | ||
428 | { | ||
429 | lastslash = tmpptr; | ||
430 | } | ||
431 | } | ||
432 | if( lastslash != NULL ) | ||
433 | { | ||
434 | savefilenameinzip = lastslash+1; // base filename follows last slash. | ||
435 | } | ||
436 | } | ||
437 | |||
438 | /**/ | ||
439 | err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, | ||
352 | NULL,0,NULL,0,NULL /* comment*/, | 440 | NULL,0,NULL,0,NULL /* comment*/, |
353 | (opt_compress_level != 0) ? Z_DEFLATED : 0, | 441 | (opt_compress_level != 0) ? Z_DEFLATED : 0, |
354 | opt_compress_level,0, | 442 | opt_compress_level,0, |
355 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ | 443 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ |
356 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | 444 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
357 | password,crcFile); | 445 | password,crcFile, zip64); |
358 | 446 | ||
359 | if (err != ZIP_OK) | 447 | if (err != ZIP_OK) |
360 | printf("error in opening %s in zipfile\n",filenameinzip); | 448 | printf("error in opening %s in zipfile\n",filenameinzip); |
361 | else | 449 | else |
362 | { | 450 | { |
363 | fin = fopen(filenameinzip,"rb"); | 451 | fin = fopen64(filenameinzip,"rb"); |
364 | if (fin==NULL) | 452 | if (fin==NULL) |
365 | { | 453 | { |
366 | err=ZIP_ERRNO; | 454 | err=ZIP_ERRNO; |