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 #ifdef unix || __APPLE__ 108 if (strcmp(
f,
"-")!=0)
119 if (name[len - 1] ==
'/')
120 name[len - 1] =
'\0';
122 if (stat(name,&s)==0)
128 filedate = localtime(&tm_t);
130 tmzip->
tm_sec = filedate->tm_sec;
131 tmzip->
tm_min = filedate->tm_min;
132 tmzip->
tm_hour = filedate->tm_hour;
133 tmzip->
tm_mday = filedate->tm_mday;
134 tmzip->
tm_mon = filedate->tm_mon ;
135 tmzip->
tm_year = filedate->tm_year;
159 if (ftestexist==
NULL)
168 printf(
"MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
169 printf(
"more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
174 printf(
"Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
175 " -o Overwrite existing file.zip\n" \
176 " -a Append to existing file.zip\n" \
178 " -1 Compress faster\n" \
179 " -9 Compress better\n\n" \
180 " -j exclude path. store only the file name.\n\n");
185 int getFileCrc(
const char* filenameinzip,
void*
buf,
unsigned long size_buf,
unsigned long* result_crc)
187 unsigned long calculate_crc=0;
191 unsigned long size_read = 0;
192 unsigned long total_read = 0;
202 size_read = (
int)fread(buf,1,size_buf,fin);
203 if (size_read < size_buf)
206 printf(
"error in reading %s\n",filenameinzip);
211 calculate_crc =
crc32(calculate_crc,buf,size_read);
212 total_read += size_read;
214 }
while ((err ==
ZIP_OK) && (size_read>0));
219 *result_crc=calculate_crc;
220 printf(
"file %s crc %lx\n", filenameinzip, calculate_crc);
235 printf(
"File : %s is %lld bytes\n", filename, pos);
237 if(pos >= 0xffffffff)
253 int opt_exclude_path=0;
254 int zipfilenamearg = 0;
275 const char *
p=argv[
i]+1;
280 if ((c==
'o') || (c==
'O'))
282 if ((c==
'a') || (c==
'A'))
284 if ((c>=
'0') && (c<=
'9'))
285 opt_compress_level = c-
'0';
286 if ((c==
'j') || (c==
'J'))
287 opt_exclude_path = 1;
289 if (((c==
'p') || (c==
'P')) && (i+1<argc))
298 if (zipfilenamearg == 0)
307 buf = (
void*)
malloc(size_buf);
310 printf(
"Error allocating memory\n");
314 if (zipfilenamearg==0)
324 strncpy(filename_try, argv[zipfilenamearg],
MAXFILENAME-1);
328 len=(
int)strlen(filename_try);
330 if (filename_try[i]==
'.')
334 strcat(filename_try,
".zip");
336 if (opt_overwrite==2)
343 if (opt_overwrite==0)
351 printf(
"The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
352 ret = scanf(
"%1s",answer);
358 if ((rep>=
'a') && (rep<=
'z'))
361 while ((rep!=
'Y') && (rep!=
'N') && (rep!=
'A'));
373 # ifdef USEWIN32IOAPI 378 zf =
zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
383 printf(
"error opening %s\n",filename_try);
387 printf(
"creating %s\n",filename_try);
389 for (i=zipfilenamearg+1;(i<argc) && (err==
ZIP_OK);i++)
391 if (!((((*(argv[i]))==
'-') || ((*(argv[i]))==
'/')) &&
392 ((argv[i][1]==
'o') || (argv[i][1]==
'O') ||
393 (argv[i][1]==
'a') || (argv[i][1]==
'A') ||
394 (argv[i][1]==
'p') || (argv[i][1]==
'P') ||
395 ((argv[i][1]>=
'0') || (argv[i][1]<=
'9'))) &&
396 (strlen(argv[i]) == 2)))
400 const char* filenameinzip = argv[
i];
401 const char *savefilenameinzip;
403 unsigned long crcFile=0;
420 err =
getFileCrc(filenameinzip,buf,size_buf,&crcFile);
426 savefilenameinzip = filenameinzip;
427 while( savefilenameinzip[0] ==
'\\' || savefilenameinzip[0] ==
'/' )
433 if( opt_exclude_path )
436 const char *lastslash = 0;
437 for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
439 if( *tmpptr ==
'\\' || *tmpptr ==
'/')
444 if( lastslash !=
NULL )
446 savefilenameinzip = lastslash+1;
454 opt_compress_level,0,
457 password,crcFile, zip64);
460 printf(
"error in opening %s in zipfile\n",filenameinzip);
467 printf(
"error in opening %s for reading\n",filenameinzip);
475 size_read = (
int)fread(buf,1,size_buf,fin);
476 if (size_read < size_buf)
479 printf(
"error in reading %s\n",filenameinzip);
488 printf(
"error in writing %s in the zipfile\n",
493 }
while ((err ==
ZIP_OK) && (size_read>0));
504 printf(
"error in closing %s in the zipfile\n",
511 printf(
"error in closing %s\n",filename_try);
#define FTELLO_FUNC(stream)
int isLargeFile(const char *filename)
#define ZIP_INTERNALERROR
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
#define Z_DEFAULT_COMPRESSION
GLenum GLuint GLenum GLsizei const GLchar * buf
#define INVALID_HANDLE_VALUE
uLong filetime(char *f, tm_zip *tmzip, uLong *dt)
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
int check_exist_file(char *filename) const
#define FSEEKO_FUNC(stream, offset, origin)
#define Z_DEFAULT_STRATEGY
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
unsigned long long int ZPOS64_T
T1_FIELD_DICT_PRIVATE password
zipFile ZEXPORT zipOpen64(const void *pathname, int append)
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)
GLuint const GLchar * name
int getFileCrc(const char *filenameinzip, void *buf, unsigned long size_buf, unsigned long *result_crc)
#define FOPEN_FUNC(filename, mode)
zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
int ZEXPORT zipCloseFileInZip(zipFile file)
int ZEXPORT zipClose(zipFile file, const char *global_comment)