miniunz.c revision 1b33c96954667ba382fa595baf7b31290bfdd517
/*
Version 1.1, February 14h, 2010
sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BIT
#define _FILE_OFFSET_BIT 64
#endif
#endif
#ifdef __APPLE__
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
#else
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
# include <direct.h>
# include <io.h>
#else
# include <unistd.h>
# include <utime.h>
#endif
#include "unzip.h"
#define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (8192)
#define MAXFILENAME (256)
#ifdef _WIN32
#define USEWIN32IOAPI
#include "iowin32.h"
#endif
/*
mini unzip, demo of unzip package
usage :
Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]
list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
if it exists
*/
dosdate : the new date at the MSDos format (4 bytes)
tmu_date : the SAME new date at the tm_unz format */
const char *filename;
{
#ifdef _WIN32
#else
else
#endif
#endif
}
/* mymkdir and change_file_date are not 100 % portable
As I don't know well Unix, I wait feedback for the unix portion */
const char* dirname;
{
int ret=0;
#ifdef _WIN32
#endif
return ret;
}
char *newdir;
{
char *buffer ;
char *p;
if (len <= 0)
return 0;
{
printf("Error allocating memory\n");
return UNZ_INTERNALERROR;
}
}
{
return 1;
}
p = buffer+1;
while (1)
{
char hold;
while(*p && *p != '\\' && *p != '/')
p++;
hold = *p;
*p = 0;
{
return 0;
}
if (hold == 0)
break;
*p++ = hold;
}
return 1;
}
void do_banner()
{
printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
}
void do_help()
{
printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
" -e Extract without pathname (junk paths)\n" \
" -x Extract with pathname\n" \
" -v list files\n" \
" -l list files\n" \
" -d directory to extract into\n" \
" -o overwrite files without prompting\n" \
" -p extract crypted file using password\n\n");
}
{
/* to avoid compatibility problem , we do here the conversion */
char number[21];
int offset=19;
int pos_string = 19;
number[20]=0;
for (;;) {
n/=10;
if (offset==0)
break;
offset--;
}
{
while (size_char > size_display_string)
{
size_char--;
printf(" ");
}
}
}
{
uLong i;
int err;
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
for (i=0;i<gi.number_entry;i++)
{
char filename_inzip[256];
const char *string_method;
char charCrypt=' ';
{
break;
}
if (file_info.uncompressed_size>0)
/* display a '*' if the file is crypted */
charCrypt='*';
if (file_info.compression_method==0)
string_method="Stored";
else
{
if (iLevel==0)
string_method="Defl:N";
else if (iLevel==1)
string_method="Defl:X";
}
else
{
string_method="BZip2 ";
}
else
string_method="Unkn. ";
printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
{
{
break;
}
}
}
return 0;
}
const int* popt_extract_without_path;
int* popt_overwrite;
const char* password;
{
char filename_inzip[256];
char* filename_withoutpath;
char* p;
void* buf;
{
return err;
}
{
printf("Error allocating memory\n");
return UNZ_INTERNALERROR;
}
while ((*p) != '\0')
{
if (((*p)=='/') || ((*p)=='\\'))
filename_withoutpath = p+1;
p++;
}
if ((*filename_withoutpath)=='\0')
{
if ((*popt_extract_without_path)==0)
{
}
}
else
{
const char* write_filename;
int skip=0;
if ((*popt_extract_without_path)==0)
else
{
}
{
char rep=0;
if (ftestexist!=NULL)
{
do
{
char answer[128];
int ret;
if (ret != 1)
{
}
rep -= 0x20;
}
}
if (rep == 'N')
skip = 1;
if (rep == 'A')
*popt_overwrite=1;
}
{
/* some zipfile don't contain directory alone before file */
(filename_withoutpath!=(char*)filename_inzip))
{
char c=*(filename_withoutpath-1);
*(filename_withoutpath-1)=c;
}
{
}
}
{
do
{
if (err<0)
{
break;
}
if (err>0)
{
printf("error in writing extracted file\n");
break;
}
}
while (err>0);
if (fout)
if (err==0)
}
{
{
}
}
else
}
return err;
}
int opt_overwrite;
const char* password;
{
uLong i;
int err;
for (i=0;i<gi.number_entry;i++)
{
break;
{
{
break;
}
}
}
return 0;
}
const char* filename;
int opt_overwrite;
const char* password;
{
{
return 2;
}
return 0;
else
return 1;
}
int argc;
char *argv[];
{
const char *zipfilename=NULL;
const char *filename_to_extract=NULL;
int i;
int ret_value=0;
int opt_do_list=0;
int opt_do_extract=1;
int opt_do_extract_withoutpath=0;
int opt_overwrite=0;
int opt_extractdir=0;
do_banner();
if (argc==1)
{
do_help();
return 0;
}
else
{
for (i=1;i<argc;i++)
{
if ((*argv[i])=='-')
{
const char *p=argv[i]+1;
while ((*p)!='\0')
{
char c=*(p++);;
if ((c=='l') || (c=='L'))
opt_do_list = 1;
if ((c=='v') || (c=='V'))
opt_do_list = 1;
if ((c=='x') || (c=='X'))
opt_do_extract = 1;
if ((c=='e') || (c=='E'))
if ((c=='o') || (c=='O'))
if ((c=='d') || (c=='D'))
{
}
{
i++;
}
}
}
else
{
if (zipfilename == NULL)
zipfilename = argv[i];
filename_to_extract = argv[i] ;
}
}
}
if (zipfilename!=NULL)
{
# ifdef USEWIN32IOAPI
# endif
/* strncpy doesnt append the trailing NULL, of the string is too long. */
# ifdef USEWIN32IOAPI
# else
# endif
{
# ifdef USEWIN32IOAPI
# else
# endif
}
}
{
return 1;
}
if (opt_do_list==1)
else if (opt_do_extract==1)
{
#ifdef _WIN32
#else
#endif
{
exit(-1);
}
if (filename_to_extract == NULL)
else
ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
}
return ret_value;
}