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)
61 #define CASESENSITIVITY (0)
62 #define WRITEBUFFERSIZE (8192)
63 #define MAXFILENAME (256)
91 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
93 hFile = CreateFileA(
filename,GENERIC_READ | GENERIC_WRITE,
95 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
96 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
97 LocalFileTimeToFileTime(&ftLocal,&ftm);
98 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
101 #if defined(unix) || defined(__APPLE__)
105 newdate.tm_sec = tmu_date.
tm_sec;
106 newdate.tm_min=tmu_date.
tm_min;
107 newdate.tm_hour=tmu_date.
tm_hour;
108 newdate.tm_mday=tmu_date.
tm_mday;
109 newdate.tm_mon=tmu_date.
tm_mon;
111 newdate.tm_year=tmu_date.
tm_year - 1900;
113 newdate.tm_year=tmu_date.
tm_year ;
116 ut.actime=ut.modtime=mktime(&newdate);
131 ret = _mkdir(dirname);
133 ret =
mkdir (dirname,0775);
135 ret =
mkdir (dirname,0775);
145 size_t len = strlen(newdir);
153 printf(
"Error allocating memory\n");
172 while(*
p && *
p !=
'\\' && *
p !=
'/')
192 printf(
"MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
193 printf(
"more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
198 printf(
"Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
199 " -e Extract without pathname (junk paths)\n" \
200 " -x Extract with pathname\n" \
203 " -d directory to extract into\n" \
204 " -o overwrite files without prompting\n" \
205 " -p extract crypted file using password\n\n");
216 number[
offset]=(char)((
n%10)+
'0');
217 if (number[
offset] !=
'0')
225 int size_display_string = 19-pos_string;
226 while (size_char > size_display_string)
233 printf(
"%s",&number[pos_string]);
245 printf(
"error %d with zipfile in unzGetGlobalInfo \n",
err);
246 printf(
" Length Method Size Ratio Date Time CRC-32 Name\n");
247 printf(
" ------ ------ ---- ----- ---- ---- ------ ----\n");
250 char filename_inzip[256];
253 const char *string_method;
258 printf(
"error %d with zipfile in unzGetCurrentFileInfo\n",
err);
265 if ((file_info.
flag & 1) != 0)
269 string_method=
"Stored";
275 string_method=
"Defl:N";
277 string_method=
"Defl:X";
278 else if ((iLevel==2) || (iLevel==3))
279 string_method=
"Defl:F";
284 string_method=
"BZip2 ";
287 string_method=
"Unkn. ";
290 printf(
" %6s%c",string_method,charCrypt);
292 printf(
" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
298 (
uLong)file_info.
crc,filename_inzip);
304 printf(
"error %d with zipfile in unzGoToNextFile\n",
err);
316 const int* popt_extract_without_path;
318 const char* password;
320 char filename_inzip[256];
321 char* filename_withoutpath;
333 printf(
"error %d with zipfile in unzGetCurrentFileInfo\n",
err);
341 printf(
"Error allocating memory\n");
345 p = filename_withoutpath = filename_inzip;
348 if (((*
p)==
'/') || ((*
p)==
'\\'))
349 filename_withoutpath =
p+1;
353 if ((*filename_withoutpath)==
'\0')
355 if ((*popt_extract_without_path)==0)
357 printf(
"creating directory: %s\n",filename_inzip);
363 const char* write_filename;
366 if ((*popt_extract_without_path)==0)
367 write_filename = filename_inzip;
369 write_filename = filename_withoutpath;
374 printf(
"error %d with zipfile in unzOpenCurrentFilePassword\n",
err);
377 if (((*popt_overwrite)==0) && (
err==
UNZ_OK))
382 if (ftestexist!=
NULL)
390 printf(
"The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
391 ret = scanf(
"%1s",answer);
397 if ((rep>=
'a') && (rep<=
'z'))
400 while ((rep!=
'Y') && (rep!=
'N') && (rep!=
'A'));
414 if ((fout==
NULL) && ((*popt_extract_without_path)==0) &&
415 (filename_withoutpath!=(
char*)filename_inzip))
417 char c=*(filename_withoutpath-1);
418 *(filename_withoutpath-1)=
'\0';
420 *(filename_withoutpath-1)=
c;
426 printf(
"error opening %s\n",write_filename);
432 printf(
" extracting: %s\n",write_filename);
439 printf(
"error %d with zipfile in unzReadCurrentFile\n",
err);
443 if (fwrite(
buf,(
unsigned)
err,1,fout)!=1)
445 printf(
"error in writing extracted file\n");
464 printf(
"error %d with zipfile in unzCloseCurrentFile\n",
err);
476 static int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
478 int opt_extract_without_path;
480 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;
537 const char *zipfilename=
NULL;
538 const char *filename_to_extract=
NULL;
539 const char *password=
NULL;
544 int opt_do_extract=1;
545 int opt_do_extract_withoutpath=0;
547 int opt_extractdir=0;
548 const char *dirname=
NULL;
568 if ((
c==
'l') || (
c==
'L'))
570 if ((
c==
'v') || (
c==
'V'))
572 if ((
c==
'x') || (
c==
'X'))
574 if ((
c==
'e') || (
c==
'E'))
575 opt_do_extract = opt_do_extract_withoutpath = 1;
576 if ((
c==
'o') || (
c==
'O'))
578 if ((
c==
'd') || (
c==
'D'))
584 if (((
c==
'p') || (
c==
'P')) && (
i+1<argc))
593 if (zipfilename ==
NULL)
594 zipfilename =
argv[
i];
595 else if ((filename_to_extract==
NULL) && (!opt_extractdir))
596 filename_to_extract =
argv[
i] ;
601 if (zipfilename!=
NULL)
604 # ifdef USEWIN32IOAPI
612 # ifdef USEWIN32IOAPI
620 strcat(filename_try,
".zip");
621 # ifdef USEWIN32IOAPI
631 printf(
"Cannot open %s or %s.zip\n",zipfilename,zipfilename);
634 printf(
"%s opened\n",filename_try);
638 else if (opt_do_extract==1)
641 if (opt_extractdir && _chdir(dirname))
643 if (opt_extractdir &&
chdir(dirname))
646 printf(
"Error changing into %s, aborting\n", dirname);
650 if (filename_to_extract ==
NULL)
651 ret_value =
do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
653 ret_value =
do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static fork const void static count static fd const char const char static newpath chdir
void skip(file *in, unsigned n)
RZ_API void Ht_() free(HtName_(Ht) *ht)
unsigned long long int ZPOS64_T
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig mkdir
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds utime
static static fork const void static count static fd const char const char static newpath char char argv
static void change_file_date(char *filename, uLong dosdate, tm_unz tmu_date) const
static int do_list(unzFile uf)
static int makedir(char *newdir) const
#define FOPEN_FUNC(filename, mode)
static int do_extract(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char *password)
static int do_extract_currentfile(unzFile uf, const int *popt_extract_without_path, int *popt_overwrite, const char *password)
static void Display64BitsSize(ZPOS64_T n, int size_char)
static int do_extract_onefile(unzFile uf, const char *filename, int opt_extract_without_path, int opt_overwrite, const char *password)
static int mymkdir(char *dirname) const
ZPOS64_T uncompressed_size
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
unzFile ZEXPORT unzOpen64(const void *path)
int ZEXPORT unzCloseCurrentFile(unzFile file)
int ZEXPORT unzGoToNextFile(unzFile file)
int ZEXPORT unzClose(unzFile file)
#define UNZ_INTERNALERROR