Rizin
unix-like reverse engineering framework and cli tools
miniunz.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utime.h>
#include "unzip.h"

Go to the source code of this file.

Macros

#define __USE_FILE_OFFSET64
 
#define __USE_LARGEFILE64
 
#define _LARGEFILE64_SOURCE
 
#define _FILE_OFFSET_BIT   64
 
#define FOPEN_FUNC(filename, mode)   fopen64(filename, mode)
 
#define FTELLO_FUNC(stream)   ftello64(stream)
 
#define FSEEKO_FUNC(stream, offset, origin)   fseeko64(stream, offset, origin)
 
#define CASESENSITIVITY   (0)
 
#define WRITEBUFFERSIZE   (8192)
 
#define MAXFILENAME   (256)
 

Functions

static void change_file_date (char *filename, uLong dosdate, tm_unz tmu_date) const
 
static int mymkdir (char *dirname) const
 
static int makedir (char *newdir) const
 
static void do_banner ()
 
static void do_help ()
 
static void Display64BitsSize (ZPOS64_T n, int size_char)
 
static int do_list (unzFile uf)
 
static int do_extract_currentfile (unzFile uf, const int *popt_extract_without_path, int *popt_overwrite, const char *password)
 
static int do_extract (unzFile uf, int opt_extract_without_path, int opt_overwrite, const char *password)
 
static int do_extract_onefile (unzFile uf, const char *filename, int opt_extract_without_path, int opt_overwrite, const char *password)
 
int main (int argc, argv)
 

Macro Definition Documentation

◆ __USE_FILE_OFFSET64

#define __USE_FILE_OFFSET64

Definition at line 17 of file miniunz.c.

◆ __USE_LARGEFILE64

#define __USE_LARGEFILE64

Definition at line 20 of file miniunz.c.

◆ _FILE_OFFSET_BIT

#define _FILE_OFFSET_BIT   64

Definition at line 26 of file miniunz.c.

◆ _LARGEFILE64_SOURCE

#define _LARGEFILE64_SOURCE

Definition at line 23 of file miniunz.c.

◆ CASESENSITIVITY

#define CASESENSITIVITY   (0)

Definition at line 61 of file miniunz.c.

◆ FOPEN_FUNC

#define FOPEN_FUNC (   filename,
  mode 
)    fopen64(filename, mode)

Definition at line 36 of file miniunz.c.

◆ FSEEKO_FUNC

#define FSEEKO_FUNC (   stream,
  offset,
  origin 
)    fseeko64(stream, offset, origin)

Definition at line 38 of file miniunz.c.

◆ FTELLO_FUNC

#define FTELLO_FUNC (   stream)    ftello64(stream)

Definition at line 37 of file miniunz.c.

◆ MAXFILENAME

#define MAXFILENAME   (256)

Definition at line 63 of file miniunz.c.

◆ WRITEBUFFERSIZE

#define WRITEBUFFERSIZE   (8192)

Definition at line 62 of file miniunz.c.

Function Documentation

◆ change_file_date()

static void change_file_date ( char *  filename,
uLong  dosdate,
tm_unz  tmu_date 
) const
static

Definition at line 84 of file miniunz.c.

88 {
89 #ifdef _WIN32
90  HANDLE hFile;
91  FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
92 
93  hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
94  0,NULL,OPEN_EXISTING,0,NULL);
95  GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
96  DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
97  LocalFileTimeToFileTime(&ftLocal,&ftm);
98  SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
99  CloseHandle(hFile);
100 #else
101 #if defined(unix) || defined(__APPLE__)
102  (void)dosdate;
103  struct utimbuf ut;
104  struct tm newdate;
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;
110  if (tmu_date.tm_year > 1900)
111  newdate.tm_year=tmu_date.tm_year - 1900;
112  else
113  newdate.tm_year=tmu_date.tm_year ;
114  newdate.tm_isdst=-1;
115 
116  ut.actime=ut.modtime=mktime(&newdate);
117  utime(filename,&ut);
118 #endif
119 #endif
120 }
#define NULL
Definition: cris-opc.c:27
const char * filename
Definition: ioapi.h:137
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
Definition: sflib.h:57
int tm_mday
Definition: unzip.h:89
int tm_mon
Definition: unzip.h:90
int tm_hour
Definition: unzip.h:88
int tm_year
Definition: unzip.h:91
int tm_sec
Definition: unzip.h:86
int tm_min
Definition: unzip.h:87
DWORD * HANDLE

References HANDLE, NULL, tm_unz_s::tm_hour, tm_unz_s::tm_mday, tm_unz_s::tm_min, tm_unz_s::tm_mon, tm_unz_s::tm_sec, tm_unz_s::tm_year, and utime.

Referenced by do_extract_currentfile().

◆ Display64BitsSize()

static void Display64BitsSize ( ZPOS64_T  n,
int  size_char 
)
static

Definition at line 208 of file miniunz.c.

209 {
210  /* to avoid compatibility problem , we do here the conversion */
211  char number[21];
212  int offset=19;
213  int pos_string = 19;
214  number[20]=0;
215  for (;;) {
216  number[offset]=(char)((n%10)+'0');
217  if (number[offset] != '0')
218  pos_string=offset;
219  n/=10;
220  if (offset==0)
221  break;
222  offset--;
223  }
224  {
225  int size_display_string = 19-pos_string;
226  while (size_char > size_display_string)
227  {
228  size_char--;
229  printf(" ");
230  }
231  }
232 
233  printf("%s",&number[pos_string]);
234 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
voidpf uLong offset
Definition: ioapi.h:144
int n
Definition: mipsasm.c:19

References n, and printf().

Referenced by do_list().

◆ do_banner()

static void do_banner ( )
static

Definition at line 190 of file miniunz.c.

191 {
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");
194 }

References printf().

Referenced by main().

◆ do_extract()

static int do_extract ( unzFile  uf,
int  opt_extract_without_path,
int  opt_overwrite,
const char*  password 
)
static

Definition at line 476 of file miniunz.c.

481 {
482  uLong i;
484  int err;
485 
486  err = unzGetGlobalInfo64(uf,&gi);
487  if (err!=UNZ_OK)
488  printf("error %d with zipfile in unzGetGlobalInfo \n",err);
489 
490  for (i=0;i<gi.number_entry;i++)
491  {
492  if (do_extract_currentfile(uf,&opt_extract_without_path,
493  &opt_overwrite,
494  password) != UNZ_OK)
495  break;
496 
497  if ((i+1)<gi.number_entry)
498  {
499  err = unzGoToNextFile(uf);
500  if (err!=UNZ_OK)
501  {
502  printf("error %d with zipfile in unzGoToNextFile\n",err);
503  break;
504  }
505  }
506  }
507 
508  return 0;
509 }
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
static int do_extract_currentfile(unzFile uf, const int *popt_extract_without_path, int *popt_overwrite, const char *password)
Definition: miniunz.c:314
ZPOS64_T number_entry
Definition: unzip.h:98
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:828
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1199
#define UNZ_OK
Definition: unzip.h:74
unsigned long uLong
Definition: zconf.h:394

References do_extract_currentfile(), err, i, unz_global_info64_s::number_entry, printf(), UNZ_OK, unzGetGlobalInfo64(), and unzGoToNextFile().

Referenced by main().

◆ do_extract_currentfile()

static int do_extract_currentfile ( unzFile  uf,
const int popt_extract_without_path,
int popt_overwrite,
const char*  password 
)
static

Definition at line 314 of file miniunz.c.

319 {
320  char filename_inzip[256];
321  char* filename_withoutpath;
322  char* p;
323  int err=UNZ_OK;
324  FILE *fout=NULL;
325  void* buf;
326  uInt size_buf;
327 
328  unz_file_info64 file_info;
329  err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
330 
331  if (err!=UNZ_OK)
332  {
333  printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
334  return err;
335  }
336 
337  size_buf = WRITEBUFFERSIZE;
338  buf = (void*)malloc(size_buf);
339  if (buf==NULL)
340  {
341  printf("Error allocating memory\n");
342  return UNZ_INTERNALERROR;
343  }
344 
345  p = filename_withoutpath = filename_inzip;
346  while ((*p) != '\0')
347  {
348  if (((*p)=='/') || ((*p)=='\\'))
349  filename_withoutpath = p+1;
350  p++;
351  }
352 
353  if ((*filename_withoutpath)=='\0')
354  {
355  if ((*popt_extract_without_path)==0)
356  {
357  printf("creating directory: %s\n",filename_inzip);
358  mymkdir(filename_inzip);
359  }
360  }
361  else
362  {
363  const char* write_filename;
364  int skip=0;
365 
366  if ((*popt_extract_without_path)==0)
367  write_filename = filename_inzip;
368  else
369  write_filename = filename_withoutpath;
370 
371  err = unzOpenCurrentFilePassword(uf,password);
372  if (err!=UNZ_OK)
373  {
374  printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
375  }
376 
377  if (((*popt_overwrite)==0) && (err==UNZ_OK))
378  {
379  char rep=0;
380  FILE* ftestexist;
381  ftestexist = FOPEN_FUNC(write_filename,"rb");
382  if (ftestexist!=NULL)
383  {
384  fclose(ftestexist);
385  do
386  {
387  char answer[128];
388  int ret;
389 
390  printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
391  ret = scanf("%1s",answer);
392  if (ret != 1)
393  {
394  exit(EXIT_FAILURE);
395  }
396  rep = answer[0] ;
397  if ((rep>='a') && (rep<='z'))
398  rep -= 0x20;
399  }
400  while ((rep!='Y') && (rep!='N') && (rep!='A'));
401  }
402 
403  if (rep == 'N')
404  skip = 1;
405 
406  if (rep == 'A')
407  *popt_overwrite=1;
408  }
409 
410  if ((skip==0) && (err==UNZ_OK))
411  {
412  fout=FOPEN_FUNC(write_filename,"wb");
413  /* some zipfile don't contain directory alone before file */
414  if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
415  (filename_withoutpath!=(char*)filename_inzip))
416  {
417  char c=*(filename_withoutpath-1);
418  *(filename_withoutpath-1)='\0';
419  makedir(write_filename);
420  *(filename_withoutpath-1)=c;
421  fout=FOPEN_FUNC(write_filename,"wb");
422  }
423 
424  if (fout==NULL)
425  {
426  printf("error opening %s\n",write_filename);
427  }
428  }
429 
430  if (fout!=NULL)
431  {
432  printf(" extracting: %s\n",write_filename);
433 
434  do
435  {
436  err = unzReadCurrentFile(uf,buf,size_buf);
437  if (err<0)
438  {
439  printf("error %d with zipfile in unzReadCurrentFile\n",err);
440  break;
441  }
442  if (err>0)
443  if (fwrite(buf,(unsigned)err,1,fout)!=1)
444  {
445  printf("error in writing extracted file\n");
446  err=UNZ_ERRNO;
447  break;
448  }
449  }
450  while (err>0);
451  if (fout)
452  fclose(fout);
453 
454  if (err==0)
455  change_file_date(write_filename,file_info.dosDate,
456  file_info.tmu_date);
457  }
458 
459  if (err==UNZ_OK)
460  {
461  err = unzCloseCurrentFile (uf);
462  if (err!=UNZ_OK)
463  {
464  printf("error %d with zipfile in unzCloseCurrentFile\n",err);
465  }
466  }
467  else
468  unzCloseCurrentFile(uf); /* don't lose the error */
469  }
470 
471  free(buf);
472  return err;
473 }
void skip(file *in, unsigned n)
Definition: gzappend.c:202
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
void * malloc(size_t size)
Definition: malloc.c:123
static void change_file_date(char *filename, uLong dosdate, tm_unz tmu_date) const
Definition: miniunz.c:84
static int makedir(char *newdir) const
Definition: miniunz.c:140
#define FOPEN_FUNC(filename, mode)
Definition: miniunz.c:36
static int mymkdir(char *dirname) const
Definition: miniunz.c:126
#define WRITEBUFFERSIZE
Definition: miniunz.c:62
string FILE
Definition: benchmark.py:21
#define c(i)
Definition: sha256.c:43
uLong dosDate
Definition: unzip.h:117
tm_unz tmu_date
Definition: unzip.h:129
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
Definition: unzip.c:1646
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1124
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Definition: unzip.c:1684
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.c:2007
#define UNZ_INTERNALERROR
Definition: unzip.h:80
#define UNZ_ERRNO
Definition: unzip.h:76
unsigned int uInt
Definition: zconf.h:393

References c, change_file_date(), unz_file_info64_s::dosDate, err, test-lz4-list::exit, benchmark::FILE, FOPEN_FUNC, free(), makedir(), malloc(), mymkdir(), NULL, p, printf(), skip(), unz_file_info64_s::tmu_date, UNZ_ERRNO, UNZ_INTERNALERROR, UNZ_OK, unzCloseCurrentFile(), unzGetCurrentFileInfo64(), unzOpenCurrentFilePassword(), unzReadCurrentFile(), and WRITEBUFFERSIZE.

Referenced by do_extract(), and do_extract_onefile().

◆ do_extract_onefile()

static int do_extract_onefile ( unzFile  uf,
const char*  filename,
int  opt_extract_without_path,
int  opt_overwrite,
const char*  password 
)
static

Definition at line 511 of file miniunz.c.

517 {
519  {
520  printf("file %s not found in the zipfile\n",filename);
521  return 2;
522  }
523 
524  if (do_extract_currentfile(uf,&opt_extract_without_path,
525  &opt_overwrite,
526  password) == UNZ_OK)
527  return 0;
528  else
529  return 1;
530 }
#define CASESENSITIVITY
Definition: miniunz.c:61
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
Definition: unzip.c:1232

References CASESENSITIVITY, do_extract_currentfile(), printf(), UNZ_OK, and unzLocateFile().

Referenced by main().

◆ do_help()

static void do_help ( )
static

Definition at line 196 of file miniunz.c.

197 {
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" \
201  " -v list files\n" \
202  " -l list files\n" \
203  " -d directory to extract into\n" \
204  " -o overwrite files without prompting\n" \
205  " -p extract crypted file using password\n\n");
206 }

References printf().

Referenced by main().

◆ do_list()

static int do_list ( unzFile  uf)
static

Definition at line 236 of file miniunz.c.

238 {
239  uLong i;
241  int err;
242 
243  err = unzGetGlobalInfo64(uf,&gi);
244  if (err!=UNZ_OK)
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");
248  for (i=0;i<gi.number_entry;i++)
249  {
250  char filename_inzip[256];
251  unz_file_info64 file_info;
252  uLong ratio=0;
253  const char *string_method;
254  char charCrypt=' ';
255  err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
256  if (err!=UNZ_OK)
257  {
258  printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
259  break;
260  }
261  if (file_info.uncompressed_size>0)
262  ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
263 
264  /* display a '*' if the file is crypted */
265  if ((file_info.flag & 1) != 0)
266  charCrypt='*';
267 
268  if (file_info.compression_method==0)
269  string_method="Stored";
270  else
271  if (file_info.compression_method==Z_DEFLATED)
272  {
273  uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
274  if (iLevel==0)
275  string_method="Defl:N";
276  else if (iLevel==1)
277  string_method="Defl:X";
278  else if ((iLevel==2) || (iLevel==3))
279  string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
280  }
281  else
282  if (file_info.compression_method==Z_BZIP2ED)
283  {
284  string_method="BZip2 ";
285  }
286  else
287  string_method="Unkn. ";
288 
290  printf(" %6s%c",string_method,charCrypt);
291  Display64BitsSize(file_info.compressed_size,7);
292  printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
293  ratio,
294  (uLong)file_info.tmu_date.tm_mon + 1,
295  (uLong)file_info.tmu_date.tm_mday,
296  (uLong)file_info.tmu_date.tm_year % 100,
297  (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
298  (uLong)file_info.crc,filename_inzip);
299  if ((i+1)<gi.number_entry)
300  {
301  err = unzGoToNextFile(uf);
302  if (err!=UNZ_OK)
303  {
304  printf("error %d with zipfile in unzGoToNextFile\n",err);
305  break;
306  }
307  }
308  }
309 
310  return 0;
311 }
static void Display64BitsSize(ZPOS64_T n, int size_char)
Definition: miniunz.c:208
ZPOS64_T uncompressed_size
Definition: unzip.h:120
uLong compression_method
Definition: unzip.h:116
ZPOS64_T compressed_size
Definition: unzip.h:119
#define Z_BZIP2ED
Definition: unzip.h:62
#define Z_DEFLATED
Definition: zlib.h:209

References unz_file_info64_s::compressed_size, unz_file_info64_s::compression_method, unz_file_info64_s::crc, Display64BitsSize(), err, unz_file_info64_s::flag, i, NULL, unz_global_info64_s::number_entry, printf(), tm_unz_s::tm_hour, tm_unz_s::tm_mday, tm_unz_s::tm_min, tm_unz_s::tm_mon, tm_unz_s::tm_year, unz_file_info64_s::tmu_date, unz_file_info64_s::uncompressed_size, UNZ_OK, unzGetCurrentFileInfo64(), unzGetGlobalInfo64(), unzGoToNextFile(), Z_BZIP2ED, and Z_DEFLATED.

Referenced by main().

◆ main()

int main ( int  argc,
argv   
)

Definition at line 533 of file miniunz.c.

536 {
537  const char *zipfilename=NULL;
538  const char *filename_to_extract=NULL;
539  const char *password=NULL;
540  char filename_try[MAXFILENAME+16] = "";
541  int i;
542  int ret_value=0;
543  int opt_do_list=0;
544  int opt_do_extract=1;
545  int opt_do_extract_withoutpath=0;
546  int opt_overwrite=0;
547  int opt_extractdir=0;
548  const char *dirname=NULL;
549  unzFile uf=NULL;
550 
551  do_banner();
552  if (argc==1)
553  {
554  do_help();
555  return 0;
556  }
557  else
558  {
559  for (i=1;i<argc;i++)
560  {
561  if ((*argv[i])=='-')
562  {
563  const char *p=argv[i]+1;
564 
565  while ((*p)!='\0')
566  {
567  char c=*(p++);;
568  if ((c=='l') || (c=='L'))
569  opt_do_list = 1;
570  if ((c=='v') || (c=='V'))
571  opt_do_list = 1;
572  if ((c=='x') || (c=='X'))
573  opt_do_extract = 1;
574  if ((c=='e') || (c=='E'))
575  opt_do_extract = opt_do_extract_withoutpath = 1;
576  if ((c=='o') || (c=='O'))
577  opt_overwrite=1;
578  if ((c=='d') || (c=='D'))
579  {
580  opt_extractdir=1;
581  dirname=argv[i+1];
582  }
583 
584  if (((c=='p') || (c=='P')) && (i+1<argc))
585  {
586  password=argv[i+1];
587  i++;
588  }
589  }
590  }
591  else
592  {
593  if (zipfilename == NULL)
594  zipfilename = argv[i];
595  else if ((filename_to_extract==NULL) && (!opt_extractdir))
596  filename_to_extract = argv[i] ;
597  }
598  }
599  }
600 
601  if (zipfilename!=NULL)
602  {
603 
604 # ifdef USEWIN32IOAPI
605  zlib_filefunc64_def ffunc;
606 # endif
607 
608  strncpy(filename_try, zipfilename,MAXFILENAME-1);
609  /* strncpy doesnt append the trailing NULL, of the string is too long. */
610  filename_try[ MAXFILENAME ] = '\0';
611 
612 # ifdef USEWIN32IOAPI
613  fill_win32_filefunc64A(&ffunc);
614  uf = unzOpen2_64(zipfilename,&ffunc);
615 # else
616  uf = unzOpen64(zipfilename);
617 # endif
618  if (uf==NULL)
619  {
620  strcat(filename_try,".zip");
621 # ifdef USEWIN32IOAPI
622  uf = unzOpen2_64(filename_try,&ffunc);
623 # else
624  uf = unzOpen64(filename_try);
625 # endif
626  }
627  }
628 
629  if (uf==NULL)
630  {
631  printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
632  return 1;
633  }
634  printf("%s opened\n",filename_try);
635 
636  if (opt_do_list==1)
637  ret_value = do_list(uf);
638  else if (opt_do_extract==1)
639  {
640 #ifdef _WIN32
641  if (opt_extractdir && _chdir(dirname))
642 #else
643  if (opt_extractdir && chdir(dirname))
644 #endif
645  {
646  printf("Error changing into %s, aborting\n", dirname);
647  exit(-1);
648  }
649 
650  if (filename_to_extract == NULL)
651  ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
652  else
653  ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
654  }
655 
656  unzClose(uf);
657 
658  return ret_value;
659 }
static static fork const void static count static fd const char const char static newpath chdir
Definition: sflib.h:33
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:439
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static void do_banner()
Definition: miniunz.c:190
#define MAXFILENAME
Definition: miniunz.c:63
static int do_list(unzFile uf)
Definition: miniunz.c:236
static int do_extract(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char *password)
Definition: miniunz.c:476
static int do_extract_onefile(unzFile uf, const char *filename, int opt_extract_without_path, int opt_overwrite, const char *password)
Definition: miniunz.c:511
static void do_help()
Definition: miniunz.c:196
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: unzip.c:778
unzFile ZEXPORT unzOpen64(const void *path)
Definition: unzip.c:798
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:808
voidp unzFile
Definition: unzip.h:70

References argv, c, chdir, do_banner(), do_extract(), do_extract_onefile(), do_help(), do_list(), test-lz4-list::exit, fill_win32_filefunc64A(), i, MAXFILENAME, NULL, p, printf(), unzClose(), unzOpen2_64(), and unzOpen64().

◆ makedir()

static int makedir ( char *  newdir) const
static

Definition at line 140 of file miniunz.c.

142 {
143  char *buffer ;
144  char *p;
145  size_t len = strlen(newdir);
146 
147  if (len == 0)
148  return 0;
149 
150  buffer = (char*)malloc(len+1);
151  if (buffer==NULL)
152  {
153  printf("Error allocating memory\n");
154  return UNZ_INTERNALERROR;
155  }
156  strcpy(buffer,newdir);
157 
158  if (buffer[len-1] == '/') {
159  buffer[len-1] = '\0';
160  }
161  if (mymkdir(buffer) == 0)
162  {
163  free(buffer);
164  return 1;
165  }
166 
167  p = buffer+1;
168  while (1)
169  {
170  char hold;
171 
172  while(*p && *p != '\\' && *p != '/')
173  p++;
174  hold = *p;
175  *p = 0;
176  if ((mymkdir(buffer) == -1) && (errno == ENOENT))
177  {
178  printf("couldn't create directory %s\n",buffer);
179  free(buffer);
180  return 0;
181  }
182  if (hold == 0)
183  break;
184  *p++ = hold;
185  }
186  free(buffer);
187  return 1;
188 }
size_t len
Definition: 6502dis.c:15
struct buffer buffer
#define ENOENT
Definition: sftypes.h:112
Definition: buffer.h:15

References ENOENT, free(), len, malloc(), mymkdir(), NULL, p, printf(), and UNZ_INTERNALERROR.

Referenced by do_extract_currentfile().

◆ mymkdir()

static int mymkdir ( char*  dirname) const
static

Definition at line 126 of file miniunz.c.

128 {
129  int ret=0;
130 #ifdef _WIN32
131  ret = _mkdir(dirname);
132 #elif unix
133  ret = mkdir (dirname,0775);
134 #elif __APPLE__
135  ret = mkdir (dirname,0775);
136 #endif
137  return ret;
138 }
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
Definition: sflib.h:66

References mkdir.

Referenced by do_extract_currentfile(), and makedir().