16 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
17 #ifndef __USE_FILE_OFFSET64
18 #define __USE_FILE_OFFSET64
20 #ifndef __USE_LARGEFILE64
21 #define __USE_LARGEFILE64
23 #ifndef _LARGEFILE64_SOURCE
24 #define _LARGEFILE64_SOURCE
26 #ifndef _FILE_OFFSET_BIT
27 #define _FILE_OFFSET_BIT 64
33 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
34 #define FTELLO_FUNC(stream) ftello(stream)
35 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
37 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
38 #define FTELLO_FUNC(stream) ftello64(stream)
39 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
57 # include <sys/types.h>
58 # include <sys/stat.h>
70 #define WRITEBUFFERSIZE (16384)
71 #define MAXFILENAME (256)
83 WIN32_FIND_DATAA ff32;
85 hFind = FindFirstFileA(
f,&ff32);
88 FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
89 FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
97 #if defined(unix) || defined(__APPLE__)
109 if (strcmp(
f,
"-")!=0)
112 size_t len = strlen(
f);
129 filedate = localtime(&tm_t);
131 tmzip->
tm_sec = filedate->tm_sec;
132 tmzip->
tm_min = filedate->tm_min;
133 tmzip->
tm_hour = filedate->tm_hour;
134 tmzip->
tm_mday = filedate->tm_mday;
135 tmzip->
tm_mon = filedate->tm_mon ;
136 tmzip->
tm_year = filedate->tm_year;
160 if (ftestexist==
NULL)
169 printf(
"MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
170 printf(
"more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
175 printf(
"Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
176 " -o Overwrite existing file.zip\n" \
177 " -a Append to existing file.zip\n" \
179 " -1 Compress faster\n" \
180 " -9 Compress better\n\n" \
181 " -j exclude path. store only the file name.\n\n");
186 static int getFileCrc(
const char* filenameinzip,
void*
buf,
unsigned long size_buf,
unsigned long* result_crc)
188 unsigned long calculate_crc=0;
192 unsigned long size_read = 0;
193 unsigned long total_read = 0;
203 size_read = fread(
buf,1,size_buf,fin);
204 if (size_read < size_buf)
207 printf(
"error in reading %s\n",filenameinzip);
212 calculate_crc =
crc32_z(calculate_crc,
buf,size_read);
213 total_read += size_read;
215 }
while ((
err ==
ZIP_OK) && (size_read>0));
220 *result_crc=calculate_crc;
221 printf(
"file %s crc %lx\n", filenameinzip, calculate_crc);
238 if(
pos >= 0xffffffff)
254 int opt_exclude_path=0;
255 int zipfilenamearg = 0;
261 const char* password=
NULL;
281 if ((
c==
'o') || (
c==
'O'))
283 if ((
c==
'a') || (
c==
'A'))
285 if ((
c>=
'0') && (
c<=
'9'))
286 opt_compress_level =
c-
'0';
287 if ((
c==
'j') || (
c==
'J'))
288 opt_exclude_path = 1;
290 if (((
c==
'p') || (
c==
'P')) && (
i+1<argc))
299 if (zipfilenamearg == 0)
311 printf(
"Error allocating memory\n");
315 if (zipfilenamearg==0)
329 len=(
int)strlen(filename_try);
331 if (filename_try[
i]==
'.')
335 strcat(filename_try,
".zip");
337 if (opt_overwrite==2)
344 if (opt_overwrite==0)
352 printf(
"The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
353 ret = scanf(
"%1s",answer);
359 if ((rep>=
'a') && (rep<=
'z'))
362 while ((rep!=
'Y') && (rep!=
'N') && (rep!=
'A'));
374 # ifdef USEWIN32IOAPI
379 zf =
zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
384 printf(
"error opening %s\n",filename_try);
388 printf(
"creating %s\n",filename_try);
392 if (!((((*(
argv[
i]))==
'-') || ((*(
argv[
i]))==
'/')) &&
397 (strlen(
argv[
i]) == 2)))
401 const char* filenameinzip =
argv[
i];
402 const char *savefilenameinzip;
404 unsigned long crcFile=0;
427 savefilenameinzip = filenameinzip;
428 while( savefilenameinzip[0] ==
'\\' || savefilenameinzip[0] ==
'/' )
434 if( opt_exclude_path )
437 const char *lastslash = 0;
438 for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
440 if( *tmpptr ==
'\\' || *tmpptr ==
'/')
445 if( lastslash !=
NULL )
447 savefilenameinzip = lastslash+1;
455 opt_compress_level,0,
458 password,crcFile, zip64);
461 printf(
"error in opening %s in zipfile\n",filenameinzip);
468 printf(
"error in opening %s for reading\n",filenameinzip);
476 size_read = fread(
buf,1,size_buf,fin);
477 if (size_read < size_buf)
480 printf(
"error in reading %s\n",filenameinzip);
489 printf(
"error in writing %s in the zipfile\n",
494 }
while ((
err ==
ZIP_OK) && (size_read>0));
505 printf(
"error in closing %s in the zipfile\n",
512 printf(
"error in closing %s\n",filename_try);
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
unsigned long long int ZPOS64_T
#define INVALID_HANDLE_VALUE
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 argv
#define FSEEKO_FUNC(stream, offset, origin)
static int isLargeFile(const char *filename)
static int check_exist_file(char *filename) const
#define FOPEN_FUNC(filename, mode)
static int getFileCrc(const char *filenameinzip, void *buf, unsigned long size_buf, unsigned long *result_crc)
#define FTELLO_FUNC(stream)
uLong filetime(char *f, tm_zip *tmzip, uLong *dt) const
int ZEXPORT zipClose(zipFile file, const char *global_comment)
zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting, int zip64)
int ZEXPORT zipCloseFileInZip(zipFile file)
zipFile ZEXPORT zipOpen64(const void *pathname, int append)
#define ZIP_INTERNALERROR
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
#define Z_DEFAULT_STRATEGY
#define Z_DEFAULT_COMPRESSION