15 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
16 #ifndef __USE_FILE_OFFSET64
17 #define __USE_FILE_OFFSET64
19 #ifndef __USE_LARGEFILE64
20 #define __USE_LARGEFILE64
22 #ifndef _LARGEFILE64_SOURCE
23 #define _LARGEFILE64_SOURCE
25 #ifndef _FILE_OFFSET_BIT
26 #define _FILE_OFFSET_BIT 64
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)
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)
60 #define CASESENSITIVITY (0)
61 #define WRITEBUFFERSIZE (8192)
62 #define MAXFILENAME (256)
90 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
92 hFile = CreateFileA(
filename,GENERIC_READ | GENERIC_WRITE,
93 0,NULL,OPEN_EXISTING,0,NULL);
94 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
95 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
96 LocalFileTimeToFileTime(&ftLocal,&ftm);
97 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
100 #ifdef unix || __APPLE__
103 newdate.tm_sec = tmu_date.
tm_sec;
104 newdate.tm_min=tmu_date.
tm_min;
105 newdate.tm_hour=tmu_date.
tm_hour;
106 newdate.tm_mday=tmu_date.
tm_mday;
107 newdate.tm_mon=tmu_date.
tm_mon;
109 newdate.tm_year=tmu_date.
tm_year - 1900;
111 newdate.tm_year=tmu_date.
tm_year ;
114 ut.actime=ut.modtime=mktime(&newdate);
129 ret = _mkdir(dirname);
131 ret = mkdir (dirname,0775);
133 ret = mkdir (dirname,0775);
143 int len = (
int)strlen(newdir);
151 printf(
"Error allocating memory\n");
170 while(*
p && *
p !=
'\\' && *
p !=
'/')
190 printf(
"MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
191 printf(
"more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
196 printf(
"Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
197 " -e Extract without pathname (junk paths)\n" \
198 " -x Extract with pathname\n" \
201 " -d directory to extract into\n" \
202 " -o overwrite files without prompting\n" \
203 " -p extract crypted file using password\n\n");
223 int size_display_string = 19-pos_string;
224 while (size_char > size_display_string)
243 printf(
"error %d with zipfile in unzGetGlobalInfo \n",
err);
244 printf(
" Length Method Size Ratio Date Time CRC-32 Name\n");
245 printf(
" ------ ------ ---- ----- ---- ---- ------ ----\n");
248 char filename_inzip[256];
251 const char *string_method;
256 printf(
"error %d with zipfile in unzGetCurrentFileInfo\n",
err);
263 if ((file_info.
flag & 1) != 0)
267 string_method=
"Stored";
273 string_method=
"Defl:N";
275 string_method=
"Defl:X";
276 else if ((iLevel==2) || (iLevel==3))
277 string_method=
"Defl:F";
282 string_method=
"BZip2 ";
285 string_method=
"Unkn. ";
288 printf(
" %6s%c",string_method,charCrypt);
290 printf(
" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
296 (
uLong)file_info.
crc,filename_inzip);
302 printf(
"error %d with zipfile in unzGoToNextFile\n",
err);
314 const int* popt_extract_without_path;
316 const char* password;
318 char filename_inzip[256];
319 char* filename_withoutpath;
332 printf(
"error %d with zipfile in unzGetCurrentFileInfo\n",
err);
337 buf = (
void*)malloc(size_buf);
340 printf(
"Error allocating memory\n");
344 p = filename_withoutpath = filename_inzip;
347 if (((*
p)==
'/') || ((*
p)==
'\\'))
348 filename_withoutpath =
p+1;
352 if ((*filename_withoutpath)==
'\0')
354 if ((*popt_extract_without_path)==0)
356 printf(
"creating directory: %s\n",filename_inzip);
362 const char* write_filename;
365 if ((*popt_extract_without_path)==0)
366 write_filename = filename_inzip;
368 write_filename = filename_withoutpath;
373 printf(
"error %d with zipfile in unzOpenCurrentFilePassword\n",
err);
376 if (((*popt_overwrite)==0) && (
err==
UNZ_OK))
381 if (ftestexist!=NULL)
389 printf(
"The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
390 ret = scanf(
"%1s",answer);
396 if ((
rep>=
'a') && (
rep<=
'z'))
399 while ((
rep!=
'Y') && (
rep!=
'N') && (
rep!=
'A'));
413 if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
414 (filename_withoutpath!=(
char*)filename_inzip))
416 char c=*(filename_withoutpath-1);
417 *(filename_withoutpath-1)=
'\0';
419 *(filename_withoutpath-1)=
c;
425 printf(
"error opening %s\n",write_filename);
431 printf(
" extracting: %s\n",write_filename);
438 printf(
"error %d with zipfile in unzReadCurrentFile\n",
err);
442 if (fwrite(
buf,
err,1,fout)!=1)
444 printf(
"error in writing extracted file\n");
463 printf(
"error %d with zipfile in unzCloseCurrentFile\n",
err);
475 int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
477 int opt_extract_without_path;
479 const char* password;
488 printf(
"error %d with zipfile in unzGetGlobalInfo \n",
err);
502 printf(
"error %d with zipfile in unzGoToNextFile\n",
err);
514 int opt_extract_without_path;
516 const char* password;
538 const char *zipfilename=NULL;
539 const char *filename_to_extract=NULL;
540 const char *password=NULL;
545 int opt_do_extract=1;
546 int opt_do_extract_withoutpath=0;
548 int opt_extractdir=0;
549 const char *dirname=NULL;
564 const char *
p=argv[
i]+1;
569 if ((
c==
'l') || (
c==
'L'))
571 if ((
c==
'v') || (
c==
'V'))
573 if ((
c==
'x') || (
c==
'X'))
575 if ((
c==
'e') || (
c==
'E'))
576 opt_do_extract = opt_do_extract_withoutpath = 1;
577 if ((
c==
'o') || (
c==
'O'))
579 if ((
c==
'd') || (
c==
'D'))
585 if (((
c==
'p') || (
c==
'P')) && (
i+1<argc))
594 if (zipfilename == NULL)
595 zipfilename = argv[
i];
596 else if ((filename_to_extract==NULL) && (!opt_extractdir))
597 filename_to_extract = argv[
i] ;
602 if (zipfilename!=NULL)
605 # ifdef USEWIN32IOAPI
613 # ifdef USEWIN32IOAPI
621 strcat(filename_try,
".zip");
622 # ifdef USEWIN32IOAPI
632 printf(
"Cannot open %s or %s.zip\n",zipfilename,zipfilename);
635 printf(
"%s opened\n",filename_try);
639 else if (opt_do_extract==1)
642 if (opt_extractdir && _chdir(dirname))
644 if (opt_extractdir && chdir(dirname))
647 printf(
"Error changing into %s, aborting\n", dirname);
651 if (filename_to_extract == NULL)
652 ret_value =
do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
654 ret_value =
do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);