#ifdefined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions #define FOPEN_FUNC(filename, mode) fopen(filename, mode) #define FTELLO_FUNC(stream) ftello(stream) #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) #else #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) #define FTELLO_FUNC(stream) ftello64(stream) #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) #endif
#ifdef _WIN32 # include <direct.h> # include <io.h> #else # include <unistd.h> # include <utime.h> # include <sys/types.h> # include <sys/stat.h> #endif
#ifdef _WIN32 /* f: name of file to get info on, tmzip: return value: access,
modification and creation times, dt: dostime */ staticint filetime(constchar *f, tm_zip *tmzip, uLong *dt) { int ret = 0;
{
FILETIME ftLocal;
HANDLE hFind;
WIN32_FIND_DATAA ff32;
hFind = FindFirstFileA(f,&ff32); if (hFind != INVALID_HANDLE_VALUE)
{
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
FindClose(hFind);
ret = 1;
}
} return ret;
} #else #ifdefined(unix) || defined(__APPLE__) /* f: name of file to get info on, tmzip: return value: access,
modification and creation times, dt: dostime */ staticint filetime(constchar *f, tm_zip *tmzip, uLong *dt) {
(void)dt; int ret=0; struct stat s; /* results of stat() */ struct tm* filedate;
time_t tm_t=0;
if (strcmp(f,"-")!=0)
{ char name[MAXFILENAME+1];
size_t len = strlen(f); if (len > MAXFILENAME)
len = MAXFILENAME;
strncpy(name, f,MAXFILENAME-1); /* strncpy doesn't append the trailing NULL, of the string is too long. */
name[ MAXFILENAME ] = '\0';
if (name[len - 1] == '/')
name[len - 1] = '\0'; /* not all systems allow stat'ing a file with / appended */ if (stat(name,&s)==0)
{
tm_t = s.st_mtime;
ret = 1;
}
}
filedate = localtime(&tm_t);
return ret;
} #else /* f: name of file to get info on, tmzip: return value: access,
modification and creation times, dt: dostime */ staticint filetime(constchar *f, tm_zip *tmzip, uLong *dt) {
(void)f;
(void)tmzip;
(void)dt; return 0;
} #endif #endif
staticint check_exist_file(constchar* filename) {
FILE* ftestexist; int ret = 1;
ftestexist = FOPEN_FUNC(filename,"rb"); if (ftestexist==NULL)
ret = 0; else
fclose(ftestexist); return ret;
}
staticvoid do_banner(void) {
printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
}
staticvoid do_help(void) {
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n"\ " -o Overwrite existing file.zip\n" \ " -a Append to existing file.zip\n" \ " -0 Store only\n" \ " -1 Compress faster\n" \ " -9 Compress better\n\n" \ " -j exclude path. store only the file name.\n\n");
}
/* calculate the CRC32 of a file,
because to encrypt a file, we need known the CRC32 of the file before */ staticint getFileCrc(constchar* filenameinzip, void* buf, unsignedlong size_buf, unsignedlong* result_crc) { unsignedlong calculate_crc=0; int err=ZIP_OK;
FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
unsignedlong size_read = 0; /* unsigned long total_read = 0; */ if (fin==NULL)
{
err = ZIP_ERRNO;
}
if (err == ZIP_OK) do
{
err = ZIP_OK;
size_read = fread(buf,1,size_buf,fin); if (size_read < size_buf) if (feof(fin)==0)
{
printf("error in reading %s\n",filenameinzip);
err = ZIP_ERRNO;
}
if (size_read>0)
calculate_crc = crc32_z(calculate_crc,buf,size_read); /* total_read += size_read; */
printf("File : %s is %llu bytes\n", filename, pos);
if(pos >= 0xffffffff)
largeFile = 1;
fclose(pFile);
}
return largeFile;
}
int main(int argc, char *argv[]) { int i; int opt_overwrite=0; int opt_compress_level=Z_DEFAULT_COMPRESSION; int opt_exclude_path=0; int zipfilenamearg = 0; char filename_try[MAXFILENAME+16]; int zipok; int err=0;
size_t size_buf=0; void* buf=NULL; constchar* password=NULL;
do_banner(); if (argc==1)
{
do_help(); return 0;
} else
{ for (i=1;i<argc;i++)
{ if ((*argv[i])=='-')
{ constchar *p=argv[i]+1;
while ((*p)!='\0')
{ char c=*(p++); if ((c=='o') || (c=='O'))
opt_overwrite = 1; if ((c=='a') || (c=='A'))
opt_overwrite = 2; if ((c>='0') && (c<='9'))
opt_compress_level = c-'0'; if ((c=='j') || (c=='J'))
opt_exclude_path = 1;
if (((c=='p') || (c=='P')) && (i+1<argc))
{
password=argv[i+1];
i++;
}
}
} else
{ if (zipfilenamearg == 0)
{
zipfilenamearg = i ;
}
}
}
}
if (zipfilenamearg==0)
{
zipok=0;
} else
{ int i,len; int dot_found=0;
zipok = 1 ;
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); /* strncpy doesn't append the trailing NULL, of the string is too long. */
filename_try[ MAXFILENAME ] = '\0';
len=(int)strlen(filename_try); for (i=0;i<len;i++) if (filename_try[i]=='.')
dot_found=1;
if (dot_found==0)
strcat(filename_try,".zip");
if (opt_overwrite==2)
{ /* if the file don't exist, we not append file */ if (check_exist_file(filename_try)==0)
opt_overwrite=1;
} else if (opt_overwrite==0) if (check_exist_file(filename_try)!=0)
{ char rep=0; do
{ char answer[128]; int ret;
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
ret = scanf("%1s",answer); if (ret != 1)
{ exit(EXIT_FAILURE);
}
rep = answer[0] ; if ((rep>='a') && (rep<='z'))
rep -= 0x20;
} while ((rep!='Y') && (rep!='N') && (rep!='A')); if (rep=='N')
zipok = 0; if (rep=='A')
opt_overwrite = 2;
}
}
/* The path name saved, should not include a leading slash. */ /*if it did, windows/xp and dynazip couldn't read the zip file. */
savefilenameinzip = filenameinzip; while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
{
savefilenameinzip++;
}
/*should the zip file contain any path at all?*/ if( opt_exclude_path )
{ constchar *tmpptr; constchar *lastslash = 0; for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
{ if( *tmpptr == '\\' || *tmpptr == '/')
{
lastslash = tmpptr;
}
} if( lastslash != NULL )
{
savefilenameinzip = lastslash+1; // base filename follows last slash.
}
}
if (err != ZIP_OK)
printf("error in opening %s in zipfile\n",filenameinzip); else
{
fin = FOPEN_FUNC(filenameinzip,"rb"); if (fin==NULL)
{
err=ZIP_ERRNO;
printf("error in opening %s for reading\n",filenameinzip);
}
}
if (err == ZIP_OK) do
{
err = ZIP_OK;
size_read = fread(buf,1,size_buf,fin); if (size_read < size_buf) if (feof(fin)==0)
{
printf("error in reading %s\n",filenameinzip);
err = ZIP_ERRNO;
}
if (size_read>0)
{
err = zipWriteInFileInZip (zf,buf,(unsigned)size_read); if (err<0)
{
printf("error in writing %s in the zipfile\n",
filenameinzip);
}
}
} while ((err == ZIP_OK) && (size_read>0));
if (fin)
fclose(fin);
if (err<0)
err=ZIP_ERRNO; else
{
err = zipCloseFileInZip(zf); if (err!=ZIP_OK)
printf("error in closing %s in the zipfile\n",
filenameinzip);
}
}
}
errclose = zipClose(zf,NULL); if (errclose != ZIP_OK)
printf("error in closing %s\n",filename_try);
} else
{
do_help();
}
free(buf); return 0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet am 2026-05-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.