Fossil SCM

fossil-scm / compat / zlib / contrib / minizip / minizip.c
Source Blame History 511 lines
7ef7284… drh 1 /*
7ef7284… drh 2 minizip.c
6ea30fb… florian 3 sample part of the MiniZip project - ( https://www.winimage.com/zLibDll/minizip.html )
7ef7284… drh 4
6ea30fb… florian 5 Copyright (C) 1998-2026 Gilles Vollant (minizip) ( https://www.winimage.com/zLibDll/minizip.html )
7ef7284… drh 6
7ef7284… drh 7 Modifications of Unzip for Zip64
7ef7284… drh 8 Copyright (C) 2007-2008 Even Rouault
7ef7284… drh 9
7ef7284… drh 10 Modifications for Zip64 support on both zip and unzip
6ea30fb… florian 11 Copyright (C) 2009-2010 Mathias Svensson ( https://result42.com )
7ef7284… drh 12 */
7ef7284… drh 13
7ef7284… drh 14
7ef7284… drh 15 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
7ef7284… drh 16 #ifndef __USE_FILE_OFFSET64
7ef7284… drh 17 #define __USE_FILE_OFFSET64
7ef7284… drh 18 #endif
7ef7284… drh 19 #ifndef __USE_LARGEFILE64
7ef7284… drh 20 #define __USE_LARGEFILE64
7ef7284… drh 21 #endif
7ef7284… drh 22 #ifndef _LARGEFILE64_SOURCE
7ef7284… drh 23 #define _LARGEFILE64_SOURCE
7ef7284… drh 24 #endif
7ef7284… drh 25 #ifndef _FILE_OFFSET_BIT
7ef7284… drh 26 #define _FILE_OFFSET_BIT 64
7ef7284… drh 27 #endif
7ef7284… drh 28 #endif
7ef7284… drh 29
f1f1d6c… drh 30 #if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
7ef7284… drh 31 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
7ef7284… drh 32 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
7ef7284… drh 33 #define FTELLO_FUNC(stream) ftello(stream)
7ef7284… drh 34 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
7ef7284… drh 35 #else
7ef7284… drh 36 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
7ef7284… drh 37 #define FTELLO_FUNC(stream) ftello64(stream)
7ef7284… drh 38 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
7ef7284… drh 39 #endif
7ef7284… drh 40
7ef7284… drh 41
7ef7284… drh 42
6ea30fb… florian 43 #ifndef _CRT_SECURE_NO_WARNINGS
6ea30fb… florian 44 # define _CRT_SECURE_NO_WARNINGS
6ea30fb… florian 45 #endif
7ef7284… drh 46 #include <stdio.h>
7ef7284… drh 47 #include <stdlib.h>
7ef7284… drh 48 #include <string.h>
7ef7284… drh 49 #include <time.h>
7ef7284… drh 50 #include <errno.h>
7ef7284… drh 51 #include <fcntl.h>
7ef7284… drh 52
7ef7284… drh 53 #ifdef _WIN32
7ef7284… drh 54 # include <direct.h>
7ef7284… drh 55 # include <io.h>
7ef7284… drh 56 #else
7ef7284… drh 57 # include <unistd.h>
7ef7284… drh 58 # include <utime.h>
7ef7284… drh 59 # include <sys/types.h>
7ef7284… drh 60 # include <sys/stat.h>
7ef7284… drh 61 #endif
7ef7284… drh 62
7ef7284… drh 63 #include "zip.h"
6ea30fb… florian 64 #include "ints.h"
7ef7284… drh 65
7ef7284… drh 66 #ifdef _WIN32
7ef7284… drh 67 #define USEWIN32IOAPI
7ef7284… drh 68 #include "iowin32.h"
7ef7284… drh 69 #endif
7ef7284… drh 70
7ef7284… drh 71
7ef7284… drh 72
7ef7284… drh 73 #define WRITEBUFFERSIZE (16384)
7ef7284… drh 74 #define MAXFILENAME (256)
7ef7284… drh 75
7ef7284… drh 76 #ifdef _WIN32
f1f1d6c… drh 77 /* f: name of file to get info on, tmzip: return value: access,
f1f1d6c… drh 78 modification and creation times, dt: dostime */
f1f1d6c… drh 79 static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
6ea30fb… florian 80 (void)tmzip;
7ef7284… drh 81 int ret = 0;
7ef7284… drh 82 {
7ef7284… drh 83 FILETIME ftLocal;
7ef7284… drh 84 HANDLE hFind;
7ef7284… drh 85 WIN32_FIND_DATAA ff32;
7ef7284… drh 86
7ef7284… drh 87 hFind = FindFirstFileA(f,&ff32);
7ef7284… drh 88 if (hFind != INVALID_HANDLE_VALUE)
7ef7284… drh 89 {
7ef7284… drh 90 FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
7ef7284… drh 91 FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
7ef7284… drh 92 FindClose(hFind);
7ef7284… drh 93 ret = 1;
7ef7284… drh 94 }
7ef7284… drh 95 }
7ef7284… drh 96 return ret;
7ef7284… drh 97 }
6ea30fb… florian 98 #elif defined(__unix__) || defined(__unix) || defined(__APPLE__)
f1f1d6c… drh 99 /* f: name of file to get info on, tmzip: return value: access,
f1f1d6c… drh 100 modification and creation times, dt: dostime */
f1f1d6c… drh 101 static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
adb9e8e… drh 102 (void)dt;
7ef7284… drh 103 int ret=0;
7ef7284… drh 104 struct stat s; /* results of stat() */
7ef7284… drh 105 struct tm* filedate;
7ef7284… drh 106 time_t tm_t=0;
7ef7284… drh 107
7ef7284… drh 108 if (strcmp(f,"-")!=0)
7ef7284… drh 109 {
7ef7284… drh 110 char name[MAXFILENAME+1];
adb9e8e… drh 111 size_t len = strlen(f);
7ef7284… drh 112 if (len > MAXFILENAME)
7ef7284… drh 113 len = MAXFILENAME;
7ef7284… drh 114
7ef7284… drh 115 strncpy(name, f,MAXFILENAME-1);
f1f1d6c… drh 116 /* strncpy doesn't append the trailing NULL, of the string is too long. */
7ef7284… drh 117 name[ MAXFILENAME ] = '\0';
7ef7284… drh 118
7ef7284… drh 119 if (name[len - 1] == '/')
7ef7284… drh 120 name[len - 1] = '\0';
7ef7284… drh 121 /* not all systems allow stat'ing a file with / appended */
7ef7284… drh 122 if (stat(name,&s)==0)
7ef7284… drh 123 {
7ef7284… drh 124 tm_t = s.st_mtime;
7ef7284… drh 125 ret = 1;
7ef7284… drh 126 }
7ef7284… drh 127 }
7ef7284… drh 128 filedate = localtime(&tm_t);
7ef7284… drh 129
7ef7284… drh 130 tmzip->tm_sec = filedate->tm_sec;
7ef7284… drh 131 tmzip->tm_min = filedate->tm_min;
7ef7284… drh 132 tmzip->tm_hour = filedate->tm_hour;
7ef7284… drh 133 tmzip->tm_mday = filedate->tm_mday;
7ef7284… drh 134 tmzip->tm_mon = filedate->tm_mon ;
7ef7284… drh 135 tmzip->tm_year = filedate->tm_year;
7ef7284… drh 136
7ef7284… drh 137 return ret;
7ef7284… drh 138 }
7ef7284… drh 139 #else
f1f1d6c… drh 140 /* f: name of file to get info on, tmzip: return value: access,
f1f1d6c… drh 141 modification and creation times, dt: dostime */
f1f1d6c… drh 142 static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
f1f1d6c… drh 143 (void)f;
f1f1d6c… drh 144 (void)tmzip;
f1f1d6c… drh 145 (void)dt;
7ef7284… drh 146 return 0;
7ef7284… drh 147 }
7ef7284… drh 148 #endif
7ef7284… drh 149
7ef7284… drh 150
7ef7284… drh 151
7ef7284… drh 152
f1f1d6c… drh 153 static int check_exist_file(const char* filename) {
7ef7284… drh 154 FILE* ftestexist;
7ef7284… drh 155 int ret = 1;
7ef7284… drh 156 ftestexist = FOPEN_FUNC(filename,"rb");
7ef7284… drh 157 if (ftestexist==NULL)
7ef7284… drh 158 ret = 0;
7ef7284… drh 159 else
7ef7284… drh 160 fclose(ftestexist);
7ef7284… drh 161 return ret;
7ef7284… drh 162 }
7ef7284… drh 163
f1f1d6c… drh 164 static void do_banner(void) {
7ef7284… drh 165 printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
6ea30fb… florian 166 printf("more info on MiniZip at https://www.winimage.com/zLibDll/minizip.html\n\n");
7ef7284… drh 167 }
7ef7284… drh 168
f1f1d6c… drh 169 static void do_help(void) {
7ef7284… drh 170 printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
7ef7284… drh 171 " -o Overwrite existing file.zip\n" \
7ef7284… drh 172 " -a Append to existing file.zip\n" \
7ef7284… drh 173 " -0 Store only\n" \
7ef7284… drh 174 " -1 Compress faster\n" \
7ef7284… drh 175 " -9 Compress better\n\n" \
7ef7284… drh 176 " -j exclude path. store only the file name.\n\n");
7ef7284… drh 177 }
7ef7284… drh 178
7ef7284… drh 179 /* calculate the CRC32 of a file,
7ef7284… drh 180 because to encrypt a file, we need known the CRC32 of the file before */
f1f1d6c… drh 181 static int getFileCrc(const char* filenameinzip, void* buf, unsigned long size_buf, unsigned long* result_crc) {
7ef7284… drh 182 unsigned long calculate_crc=0;
7ef7284… drh 183 int err=ZIP_OK;
7ef7284… drh 184 FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
7ef7284… drh 185
7ef7284… drh 186 unsigned long size_read = 0;
a9e589c… florian 187 /* unsigned long total_read = 0; */
7ef7284… drh 188 if (fin==NULL)
7ef7284… drh 189 {
7ef7284… drh 190 err = ZIP_ERRNO;
7ef7284… drh 191 }
7ef7284… drh 192
7ef7284… drh 193 if (err == ZIP_OK)
7ef7284… drh 194 do
7ef7284… drh 195 {
7ef7284… drh 196 err = ZIP_OK;
6ea30fb… florian 197 size_read = (unsigned long)fread(buf,1,size_buf,fin);
7ef7284… drh 198 if (size_read < size_buf)
7ef7284… drh 199 if (feof(fin)==0)
7ef7284… drh 200 {
7ef7284… drh 201 printf("error in reading %s\n",filenameinzip);
7ef7284… drh 202 err = ZIP_ERRNO;
7ef7284… drh 203 }
7ef7284… drh 204
7ef7284… drh 205 if (size_read>0)
adb9e8e… drh 206 calculate_crc = crc32_z(calculate_crc,buf,size_read);
a9e589c… florian 207 /* total_read += size_read; */
7ef7284… drh 208
7ef7284… drh 209 } while ((err == ZIP_OK) && (size_read>0));
7ef7284… drh 210
7ef7284… drh 211 if (fin)
7ef7284… drh 212 fclose(fin);
7ef7284… drh 213
7ef7284… drh 214 *result_crc=calculate_crc;
7ef7284… drh 215 printf("file %s crc %lx\n", filenameinzip, calculate_crc);
7ef7284… drh 216 return err;
7ef7284… drh 217 }
7ef7284… drh 218
f1f1d6c… drh 219 static int isLargeFile(const char* filename) {
7ef7284… drh 220 int largeFile = 0;
7ef7284… drh 221 ZPOS64_T pos = 0;
7ef7284… drh 222 FILE* pFile = FOPEN_FUNC(filename, "rb");
7ef7284… drh 223
7ef7284… drh 224 if(pFile != NULL)
7ef7284… drh 225 {
adb9e8e… drh 226 FSEEKO_FUNC(pFile, 0, SEEK_END);
adb9e8e… drh 227 pos = (ZPOS64_T)FTELLO_FUNC(pFile);
7ef7284… drh 228
6ea30fb… florian 229 printf("File : %s is %"PUI64" bytes\n", filename, pos);
7ef7284… drh 230
7ef7284… drh 231 if(pos >= 0xffffffff)
7ef7284… drh 232 largeFile = 1;
7ef7284… drh 233
7ef7284… drh 234 fclose(pFile);
7ef7284… drh 235 }
7ef7284… drh 236
7ef7284… drh 237 return largeFile;
7ef7284… drh 238 }
7ef7284… drh 239
f1f1d6c… drh 240 int main(int argc, char *argv[]) {
7ef7284… drh 241 int i;
7ef7284… drh 242 int opt_overwrite=0;
7ef7284… drh 243 int opt_compress_level=Z_DEFAULT_COMPRESSION;
7ef7284… drh 244 int opt_exclude_path=0;
7ef7284… drh 245 int zipfilenamearg = 0;
7ef7284… drh 246 char filename_try[MAXFILENAME+16];
7ef7284… drh 247 int zipok;
7ef7284… drh 248 int err=0;
6ea30fb… florian 249 unsigned long size_buf=0;
7ef7284… drh 250 void* buf=NULL;
7ef7284… drh 251 const char* password=NULL;
7ef7284… drh 252
7ef7284… drh 253
7ef7284… drh 254 do_banner();
7ef7284… drh 255 if (argc==1)
7ef7284… drh 256 {
7ef7284… drh 257 do_help();
7ef7284… drh 258 return 0;
7ef7284… drh 259 }
7ef7284… drh 260 else
7ef7284… drh 261 {
7ef7284… drh 262 for (i=1;i<argc;i++)
7ef7284… drh 263 {
7ef7284… drh 264 if ((*argv[i])=='-')
7ef7284… drh 265 {
7ef7284… drh 266 const char *p=argv[i]+1;
7ef7284… drh 267
7ef7284… drh 268 while ((*p)!='\0')
7ef7284… drh 269 {
a9e589c… florian 270 char c=*(p++);
7ef7284… drh 271 if ((c=='o') || (c=='O'))
7ef7284… drh 272 opt_overwrite = 1;
7ef7284… drh 273 if ((c=='a') || (c=='A'))
7ef7284… drh 274 opt_overwrite = 2;
7ef7284… drh 275 if ((c>='0') && (c<='9'))
7ef7284… drh 276 opt_compress_level = c-'0';
7ef7284… drh 277 if ((c=='j') || (c=='J'))
7ef7284… drh 278 opt_exclude_path = 1;
7ef7284… drh 279
7ef7284… drh 280 if (((c=='p') || (c=='P')) && (i+1<argc))
7ef7284… drh 281 {
7ef7284… drh 282 password=argv[i+1];
7ef7284… drh 283 i++;
7ef7284… drh 284 }
7ef7284… drh 285 }
7ef7284… drh 286 }
7ef7284… drh 287 else
7ef7284… drh 288 {
7ef7284… drh 289 if (zipfilenamearg == 0)
7ef7284… drh 290 {
7ef7284… drh 291 zipfilenamearg = i ;
7ef7284… drh 292 }
7ef7284… drh 293 }
7ef7284… drh 294 }
7ef7284… drh 295 }
7ef7284… drh 296
7ef7284… drh 297 size_buf = WRITEBUFFERSIZE;
7ef7284… drh 298 buf = (void*)malloc(size_buf);
7ef7284… drh 299 if (buf==NULL)
7ef7284… drh 300 {
7ef7284… drh 301 printf("Error allocating memory\n");
7ef7284… drh 302 return ZIP_INTERNALERROR;
7ef7284… drh 303 }
7ef7284… drh 304
7ef7284… drh 305 if (zipfilenamearg==0)
7ef7284… drh 306 {
7ef7284… drh 307 zipok=0;
7ef7284… drh 308 }
7ef7284… drh 309 else
7ef7284… drh 310 {
6ea30fb… florian 311 int len;
7ef7284… drh 312 int dot_found=0;
7ef7284… drh 313
7ef7284… drh 314 zipok = 1 ;
7ef7284… drh 315 strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
f1f1d6c… drh 316 /* strncpy doesn't append the trailing NULL, of the string is too long. */
7ef7284… drh 317 filename_try[ MAXFILENAME ] = '\0';
7ef7284… drh 318
7ef7284… drh 319 len=(int)strlen(filename_try);
7ef7284… drh 320 for (i=0;i<len;i++)
7ef7284… drh 321 if (filename_try[i]=='.')
7ef7284… drh 322 dot_found=1;
7ef7284… drh 323
7ef7284… drh 324 if (dot_found==0)
7ef7284… drh 325 strcat(filename_try,".zip");
7ef7284… drh 326
7ef7284… drh 327 if (opt_overwrite==2)
7ef7284… drh 328 {
7ef7284… drh 329 /* if the file don't exist, we not append file */
7ef7284… drh 330 if (check_exist_file(filename_try)==0)
7ef7284… drh 331 opt_overwrite=1;
7ef7284… drh 332 }
7ef7284… drh 333 else
7ef7284… drh 334 if (opt_overwrite==0)
7ef7284… drh 335 if (check_exist_file(filename_try)!=0)
7ef7284… drh 336 {
7ef7284… drh 337 char rep=0;
7ef7284… drh 338 do
7ef7284… drh 339 {
7ef7284… drh 340 char answer[128];
7ef7284… drh 341 int ret;
7ef7284… drh 342 printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
7ef7284… drh 343 ret = scanf("%1s",answer);
7ef7284… drh 344 if (ret != 1)
7ef7284… drh 345 {
7ef7284… drh 346 exit(EXIT_FAILURE);
7ef7284… drh 347 }
7ef7284… drh 348 rep = answer[0] ;
7ef7284… drh 349 if ((rep>='a') && (rep<='z'))
7ef7284… drh 350 rep -= 0x20;
7ef7284… drh 351 }
7ef7284… drh 352 while ((rep!='Y') && (rep!='N') && (rep!='A'));
7ef7284… drh 353 if (rep=='N')
7ef7284… drh 354 zipok = 0;
7ef7284… drh 355 if (rep=='A')
7ef7284… drh 356 opt_overwrite = 2;
7ef7284… drh 357 }
7ef7284… drh 358 }
7ef7284… drh 359
7ef7284… drh 360 if (zipok==1)
7ef7284… drh 361 {
7ef7284… drh 362 zipFile zf;
7ef7284… drh 363 int errclose;
7ef7284… drh 364 # ifdef USEWIN32IOAPI
7ef7284… drh 365 zlib_filefunc64_def ffunc;
7ef7284… drh 366 fill_win32_filefunc64A(&ffunc);
7ef7284… drh 367 zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
7ef7284… drh 368 # else
7ef7284… drh 369 zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
7ef7284… drh 370 # endif
7ef7284… drh 371
7ef7284… drh 372 if (zf == NULL)
7ef7284… drh 373 {
7ef7284… drh 374 printf("error opening %s\n",filename_try);
7ef7284… drh 375 err= ZIP_ERRNO;
7ef7284… drh 376 }
7ef7284… drh 377 else
7ef7284… drh 378 printf("creating %s\n",filename_try);
7ef7284… drh 379
7ef7284… drh 380 for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
7ef7284… drh 381 {
7ef7284… drh 382 if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
7ef7284… drh 383 ((argv[i][1]=='o') || (argv[i][1]=='O') ||
7ef7284… drh 384 (argv[i][1]=='a') || (argv[i][1]=='A') ||
7ef7284… drh 385 (argv[i][1]=='p') || (argv[i][1]=='P') ||
f1f1d6c… drh 386 ((argv[i][1]>='0') && (argv[i][1]<='9'))) &&
7ef7284… drh 387 (strlen(argv[i]) == 2)))
7ef7284… drh 388 {
f1f1d6c… drh 389 FILE * fin = NULL;
adb9e8e… drh 390 size_t size_read;
7ef7284… drh 391 const char* filenameinzip = argv[i];
7ef7284… drh 392 const char *savefilenameinzip;
7ef7284… drh 393 zip_fileinfo zi;
7ef7284… drh 394 unsigned long crcFile=0;
7ef7284… drh 395 int zip64 = 0;
7ef7284… drh 396
7ef7284… drh 397 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
7ef7284… drh 398 zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
7ef7284… drh 399 zi.dosDate = 0;
7ef7284… drh 400 zi.internal_fa = 0;
7ef7284… drh 401 zi.external_fa = 0;
7ef7284… drh 402 filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
7ef7284… drh 403
7ef7284… drh 404 /*
7ef7284… drh 405 err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
7ef7284… drh 406 NULL,0,NULL,0,NULL / * comment * /,
7ef7284… drh 407 (opt_compress_level != 0) ? Z_DEFLATED : 0,
7ef7284… drh 408 opt_compress_level);
7ef7284… drh 409 */
7ef7284… drh 410 if ((password != NULL) && (err==ZIP_OK))
7ef7284… drh 411 err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
7ef7284… drh 412
7ef7284… drh 413 zip64 = isLargeFile(filenameinzip);
7ef7284… drh 414
7ef7284… drh 415 /* The path name saved, should not include a leading slash. */
7ef7284… drh 416 /*if it did, windows/xp and dynazip couldn't read the zip file. */
7ef7284… drh 417 savefilenameinzip = filenameinzip;
7ef7284… drh 418 while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
7ef7284… drh 419 {
7ef7284… drh 420 savefilenameinzip++;
7ef7284… drh 421 }
7ef7284… drh 422
7ef7284… drh 423 /*should the zip file contain any path at all?*/
7ef7284… drh 424 if( opt_exclude_path )
7ef7284… drh 425 {
7ef7284… drh 426 const char *tmpptr;
7ef7284… drh 427 const char *lastslash = 0;
7ef7284… drh 428 for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
7ef7284… drh 429 {
7ef7284… drh 430 if( *tmpptr == '\\' || *tmpptr == '/')
7ef7284… drh 431 {
7ef7284… drh 432 lastslash = tmpptr;
7ef7284… drh 433 }
7ef7284… drh 434 }
7ef7284… drh 435 if( lastslash != NULL )
7ef7284… drh 436 {
6ea30fb… florian 437 savefilenameinzip = lastslash+1; /* base filename follows last slash. */
7ef7284… drh 438 }
7ef7284… drh 439 }
7ef7284… drh 440
7ef7284… drh 441 /**/
7ef7284… drh 442 err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
7ef7284… drh 443 NULL,0,NULL,0,NULL /* comment*/,
7ef7284… drh 444 (opt_compress_level != 0) ? Z_DEFLATED : 0,
7ef7284… drh 445 opt_compress_level,0,
7ef7284… drh 446 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
7ef7284… drh 447 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
7ef7284… drh 448 password,crcFile, zip64);
7ef7284… drh 449
7ef7284… drh 450 if (err != ZIP_OK)
7ef7284… drh 451 printf("error in opening %s in zipfile\n",filenameinzip);
7ef7284… drh 452 else
7ef7284… drh 453 {
7ef7284… drh 454 fin = FOPEN_FUNC(filenameinzip,"rb");
7ef7284… drh 455 if (fin==NULL)
7ef7284… drh 456 {
7ef7284… drh 457 err=ZIP_ERRNO;
7ef7284… drh 458 printf("error in opening %s for reading\n",filenameinzip);
7ef7284… drh 459 }
7ef7284… drh 460 }
7ef7284… drh 461
7ef7284… drh 462 if (err == ZIP_OK)
7ef7284… drh 463 do
7ef7284… drh 464 {
7ef7284… drh 465 err = ZIP_OK;
adb9e8e… drh 466 size_read = fread(buf,1,size_buf,fin);
7ef7284… drh 467 if (size_read < size_buf)
7ef7284… drh 468 if (feof(fin)==0)
7ef7284… drh 469 {
7ef7284… drh 470 printf("error in reading %s\n",filenameinzip);
7ef7284… drh 471 err = ZIP_ERRNO;
7ef7284… drh 472 }
7ef7284… drh 473
7ef7284… drh 474 if (size_read>0)
7ef7284… drh 475 {
adb9e8e… drh 476 err = zipWriteInFileInZip (zf,buf,(unsigned)size_read);
7ef7284… drh 477 if (err<0)
7ef7284… drh 478 {
7ef7284… drh 479 printf("error in writing %s in the zipfile\n",
7ef7284… drh 480 filenameinzip);
7ef7284… drh 481 }
7ef7284… drh 482
7ef7284… drh 483 }
7ef7284… drh 484 } while ((err == ZIP_OK) && (size_read>0));
7ef7284… drh 485
7ef7284… drh 486 if (fin)
7ef7284… drh 487 fclose(fin);
7ef7284… drh 488
7ef7284… drh 489 if (err<0)
7ef7284… drh 490 err=ZIP_ERRNO;
7ef7284… drh 491 else
7ef7284… drh 492 {
7ef7284… drh 493 err = zipCloseFileInZip(zf);
7ef7284… drh 494 if (err!=ZIP_OK)
7ef7284… drh 495 printf("error in closing %s in the zipfile\n",
7ef7284… drh 496 filenameinzip);
7ef7284… drh 497 }
7ef7284… drh 498 }
7ef7284… drh 499 }
7ef7284… drh 500 errclose = zipClose(zf,NULL);
7ef7284… drh 501 if (errclose != ZIP_OK)
7ef7284… drh 502 printf("error in closing %s\n",filename_try);
7ef7284… drh 503 }
7ef7284… drh 504 else
7ef7284… drh 505 {
7ef7284… drh 506 do_help();
7ef7284… drh 507 }
7ef7284… drh 508
7ef7284… drh 509 free(buf);
6ea30fb… florian 510 return err;
7ef7284… drh 511 }

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button