diff options
Diffstat (limited to 'contrib/minizip/minizip.c')
-rw-r--r-- | contrib/minizip/minizip.c | 794 |
1 files changed, 397 insertions, 397 deletions
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c index 79e541d..7e2ce36 100644 --- a/contrib/minizip/minizip.c +++ b/contrib/minizip/minizip.c | |||
@@ -1,397 +1,397 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <time.h> | 4 | #include <time.h> |
5 | #include <errno.h> | 5 | #include <errno.h> |
6 | #include <fcntl.h> | 6 | #include <fcntl.h> |
7 | 7 | ||
8 | #ifdef unix | 8 | #ifdef unix |
9 | # include <unistd.h> | 9 | # include <unistd.h> |
10 | # include <utime.h> | 10 | # include <utime.h> |
11 | # include <sys/types.h> | 11 | # include <sys/types.h> |
12 | # include <sys/stat.h> | 12 | # include <sys/stat.h> |
13 | #else | 13 | #else |
14 | # include <direct.h> | 14 | # include <direct.h> |
15 | # include <io.h> | 15 | # include <io.h> |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | #include "zip.h" | 18 | #include "zip.h" |
19 | 19 | ||
20 | #ifdef WIN32 | 20 | #ifdef WIN32 |
21 | #define USEWIN32IOAPI | 21 | #define USEWIN32IOAPI |
22 | #include "iowin32.h" | 22 | #include "iowin32.h" |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | 25 | ||
26 | 26 | ||
27 | #define WRITEBUFFERSIZE (16384) | 27 | #define WRITEBUFFERSIZE (16384) |
28 | #define MAXFILENAME (256) | 28 | #define MAXFILENAME (256) |
29 | 29 | ||
30 | #ifdef WIN32 | 30 | #ifdef WIN32 |
31 | uLong filetime(f, tmzip, dt) | 31 | uLong filetime(f, tmzip, dt) |
32 | char *f; /* name of file to get info on */ | 32 | char *f; /* name of file to get info on */ |
33 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 33 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
34 | uLong *dt; /* dostime */ | 34 | uLong *dt; /* dostime */ |
35 | { | 35 | { |
36 | int ret = 0; | 36 | int ret = 0; |
37 | { | 37 | { |
38 | FILETIME ftLocal; | 38 | FILETIME ftLocal; |
39 | HANDLE hFind; | 39 | HANDLE hFind; |
40 | WIN32_FIND_DATA ff32; | 40 | WIN32_FIND_DATA ff32; |
41 | 41 | ||
42 | hFind = FindFirstFile(f,&ff32); | 42 | hFind = FindFirstFile(f,&ff32); |
43 | if (hFind != INVALID_HANDLE_VALUE) | 43 | if (hFind != INVALID_HANDLE_VALUE) |
44 | { | 44 | { |
45 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); | 45 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); |
46 | FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); | 46 | FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); |
47 | FindClose(hFind); | 47 | FindClose(hFind); |
48 | ret = 1; | 48 | ret = 1; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | return ret; | 51 | return ret; |
52 | } | 52 | } |
53 | #else | 53 | #else |
54 | #ifdef unix | 54 | #ifdef unix |
55 | uLong filetime(f, tmzip, dt) | 55 | uLong filetime(f, tmzip, dt) |
56 | char *f; /* name of file to get info on */ | 56 | char *f; /* name of file to get info on */ |
57 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 57 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
58 | uLong *dt; /* dostime */ | 58 | uLong *dt; /* dostime */ |
59 | { | 59 | { |
60 | int ret=0; | 60 | int ret=0; |
61 | struct stat s; /* results of stat() */ | 61 | struct stat s; /* results of stat() */ |
62 | struct tm* filedate; | 62 | struct tm* filedate; |
63 | time_t tm_t=0; | 63 | time_t tm_t=0; |
64 | 64 | ||
65 | if (strcmp(f,"-")!=0) | 65 | if (strcmp(f,"-")!=0) |
66 | { | 66 | { |
67 | char name[MAXFILENAME+1]; | 67 | char name[MAXFILENAME+1]; |
68 | int len = strlen(f); | 68 | int len = strlen(f); |
69 | 69 | ||
70 | strncpy(name, f,MAXFILENAME-1); | 70 | strncpy(name, f,MAXFILENAME-1); |
71 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ | 71 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ |
72 | name[ MAXFILENAME ] = '\0'; | 72 | name[ MAXFILENAME ] = '\0'; |
73 | 73 | ||
74 | if (name[len - 1] == '/') | 74 | if (name[len - 1] == '/') |
75 | name[len - 1] = '\0'; | 75 | name[len - 1] = '\0'; |
76 | /* not all systems allow stat'ing a file with / appended */ | 76 | /* not all systems allow stat'ing a file with / appended */ |
77 | if (stat(name,&s)==0) | 77 | if (stat(name,&s)==0) |
78 | { | 78 | { |
79 | tm_t = s.st_mtime; | 79 | tm_t = s.st_mtime; |
80 | ret = 1; | 80 | ret = 1; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | filedate = localtime(&tm_t); | 83 | filedate = localtime(&tm_t); |
84 | 84 | ||
85 | tmzip->tm_sec = filedate->tm_sec; | 85 | tmzip->tm_sec = filedate->tm_sec; |
86 | tmzip->tm_min = filedate->tm_min; | 86 | tmzip->tm_min = filedate->tm_min; |
87 | tmzip->tm_hour = filedate->tm_hour; | 87 | tmzip->tm_hour = filedate->tm_hour; |
88 | tmzip->tm_mday = filedate->tm_mday; | 88 | tmzip->tm_mday = filedate->tm_mday; |
89 | tmzip->tm_mon = filedate->tm_mon ; | 89 | tmzip->tm_mon = filedate->tm_mon ; |
90 | tmzip->tm_year = filedate->tm_year; | 90 | tmzip->tm_year = filedate->tm_year; |
91 | 91 | ||
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
94 | #else | 94 | #else |
95 | uLong filetime(f, tmzip, dt) | 95 | uLong filetime(f, tmzip, dt) |
96 | char *f; /* name of file to get info on */ | 96 | char *f; /* name of file to get info on */ |
97 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 97 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
98 | uLong *dt; /* dostime */ | 98 | uLong *dt; /* dostime */ |
99 | { | 99 | { |
100 | return 0; | 100 | return 0; |
101 | } | 101 | } |
102 | #endif | 102 | #endif |
103 | #endif | 103 | #endif |
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | 107 | ||
108 | int check_exist_file(filename) | 108 | int check_exist_file(filename) |
109 | const char* filename; | 109 | const char* filename; |
110 | { | 110 | { |
111 | FILE* ftestexist; | 111 | FILE* ftestexist; |
112 | int ret = 1; | 112 | int ret = 1; |
113 | ftestexist = fopen(filename,"rb"); | 113 | ftestexist = fopen(filename,"rb"); |
114 | if (ftestexist==NULL) | 114 | if (ftestexist==NULL) |
115 | ret = 0; | 115 | ret = 0; |
116 | else | 116 | else |
117 | fclose(ftestexist); | 117 | fclose(ftestexist); |
118 | return ret; | 118 | return ret; |
119 | } | 119 | } |
120 | 120 | ||
121 | void do_banner() | 121 | void do_banner() |
122 | { | 122 | { |
123 | printf("MiniZip 0.22, demo of zLib + Zip package written by Gilles Vollant\n"); | 123 | printf("MiniZip 0.22, demo of zLib + Zip package written by Gilles Vollant\n"); |
124 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 124 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
125 | } | 125 | } |
126 | 126 | ||
127 | void do_help() | 127 | void do_help() |
128 | { | 128 | { |
129 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \ | 129 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \ |
130 | " -o Overwrite existing file.zip\n" \ | 130 | " -o Overwrite existing file.zip\n" \ |
131 | " -a Append to existing file.zip\n" \ | 131 | " -a Append to existing file.zip\n" \ |
132 | " -0 Store only\n" \ | 132 | " -0 Store only\n" \ |
133 | " -1 Compress faster\n" \ | 133 | " -1 Compress faster\n" \ |
134 | " -9 Compress better\n\n"); | 134 | " -9 Compress better\n\n"); |
135 | } | 135 | } |
136 | 136 | ||
137 | /* calculate the CRC32 of a file, | 137 | /* calculate the CRC32 of a file, |
138 | because to encrypt a file, we need known the CRC32 of the file before */ | 138 | because to encrypt a file, we need known the CRC32 of the file before */ |
139 | int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) | 139 | int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) |
140 | { | 140 | { |
141 | unsigned long calculate_crc=0; | 141 | unsigned long calculate_crc=0; |
142 | int err=ZIP_OK; | 142 | int err=ZIP_OK; |
143 | FILE * fin = fopen(filenameinzip,"rb"); | 143 | FILE * fin = fopen(filenameinzip,"rb"); |
144 | unsigned long size_read = 0; | 144 | unsigned long size_read = 0; |
145 | unsigned long total_read = 0; | 145 | unsigned long total_read = 0; |
146 | if (fin==NULL) | 146 | if (fin==NULL) |
147 | { | 147 | { |
148 | err = ZIP_ERRNO; | 148 | err = ZIP_ERRNO; |
149 | } | 149 | } |
150 | 150 | ||
151 | if (err == ZIP_OK) | 151 | if (err == ZIP_OK) |
152 | do | 152 | do |
153 | { | 153 | { |
154 | err = ZIP_OK; | 154 | err = ZIP_OK; |
155 | size_read = (int)fread(buf,1,size_buf,fin); | 155 | size_read = (int)fread(buf,1,size_buf,fin); |
156 | if (size_read < size_buf) | 156 | if (size_read < size_buf) |
157 | if (feof(fin)==0) | 157 | if (feof(fin)==0) |
158 | { | 158 | { |
159 | printf("error in reading %s\n",filenameinzip); | 159 | printf("error in reading %s\n",filenameinzip); |
160 | err = ZIP_ERRNO; | 160 | err = ZIP_ERRNO; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (size_read>0) | 163 | if (size_read>0) |
164 | calculate_crc = crc32(calculate_crc,buf,size_read); | 164 | calculate_crc = crc32(calculate_crc,buf,size_read); |
165 | total_read += size_read; | 165 | total_read += size_read; |
166 | 166 | ||
167 | } while ((err == ZIP_OK) && (size_read>0)); | 167 | } while ((err == ZIP_OK) && (size_read>0)); |
168 | 168 | ||
169 | if (fin) | 169 | if (fin) |
170 | fclose(fin); | 170 | fclose(fin); |
171 | 171 | ||
172 | *result_crc=calculate_crc; | 172 | *result_crc=calculate_crc; |
173 | printf("file %s crc %x\n",filenameinzip,calculate_crc); | 173 | printf("file %s crc %x\n",filenameinzip,calculate_crc); |
174 | return err; | 174 | return err; |
175 | } | 175 | } |
176 | 176 | ||
177 | int main(argc,argv) | 177 | int main(argc,argv) |
178 | int argc; | 178 | int argc; |
179 | char *argv[]; | 179 | char *argv[]; |
180 | { | 180 | { |
181 | int i; | 181 | int i; |
182 | int opt_overwrite=0; | 182 | int opt_overwrite=0; |
183 | int opt_compress_level=Z_DEFAULT_COMPRESSION; | 183 | int opt_compress_level=Z_DEFAULT_COMPRESSION; |
184 | int zipfilenamearg = 0; | 184 | int zipfilenamearg = 0; |
185 | char filename_try[MAXFILENAME+16]; | 185 | char filename_try[MAXFILENAME+16]; |
186 | int zipok; | 186 | int zipok; |
187 | int err=0; | 187 | int err=0; |
188 | int size_buf=0; | 188 | int size_buf=0; |
189 | void* buf=NULL; | 189 | void* buf=NULL; |
190 | const char* password=NULL; | 190 | const char* password=NULL; |
191 | 191 | ||
192 | 192 | ||
193 | do_banner(); | 193 | do_banner(); |
194 | if (argc==1) | 194 | if (argc==1) |
195 | { | 195 | { |
196 | do_help(); | 196 | do_help(); |
197 | return 0; | 197 | return 0; |
198 | } | 198 | } |
199 | else | 199 | else |
200 | { | 200 | { |
201 | for (i=1;i<argc;i++) | 201 | for (i=1;i<argc;i++) |
202 | { | 202 | { |
203 | if ((*argv[i])=='-') | 203 | if ((*argv[i])=='-') |
204 | { | 204 | { |
205 | const char *p=argv[i]+1; | 205 | const char *p=argv[i]+1; |
206 | 206 | ||
207 | while ((*p)!='\0') | 207 | while ((*p)!='\0') |
208 | { | 208 | { |
209 | char c=*(p++);; | 209 | char c=*(p++);; |
210 | if ((c=='o') || (c=='O')) | 210 | if ((c=='o') || (c=='O')) |
211 | opt_overwrite = 1; | 211 | opt_overwrite = 1; |
212 | if ((c=='a') || (c=='A')) | 212 | if ((c=='a') || (c=='A')) |
213 | opt_overwrite = 2; | 213 | opt_overwrite = 2; |
214 | if ((c>='0') && (c<='9')) | 214 | if ((c>='0') && (c<='9')) |
215 | opt_compress_level = c-'0'; | 215 | opt_compress_level = c-'0'; |
216 | 216 | ||
217 | if (((c=='p') || (c=='P')) && (i+1<argc)) | 217 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
218 | { | 218 | { |
219 | password=argv[i+1]; | 219 | password=argv[i+1]; |
220 | i++; | 220 | i++; |
221 | } | 221 | } |
222 | } | 222 | } |
223 | } | 223 | } |
224 | else | 224 | else |
225 | if (zipfilenamearg == 0) | 225 | if (zipfilenamearg == 0) |
226 | zipfilenamearg = i ; | 226 | zipfilenamearg = i ; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | 229 | ||
230 | size_buf = WRITEBUFFERSIZE; | 230 | size_buf = WRITEBUFFERSIZE; |
231 | buf = (void*)malloc(size_buf); | 231 | buf = (void*)malloc(size_buf); |
232 | if (buf==NULL) | 232 | if (buf==NULL) |
233 | { | 233 | { |
234 | printf("Error allocating memory\n"); | 234 | printf("Error allocating memory\n"); |
235 | return ZIP_INTERNALERROR; | 235 | return ZIP_INTERNALERROR; |
236 | } | 236 | } |
237 | 237 | ||
238 | if (zipfilenamearg==0) | 238 | if (zipfilenamearg==0) |
239 | zipok=0; | 239 | zipok=0; |
240 | else | 240 | else |
241 | { | 241 | { |
242 | int i,len; | 242 | int i,len; |
243 | int dot_found=0; | 243 | int dot_found=0; |
244 | 244 | ||
245 | zipok = 1 ; | 245 | zipok = 1 ; |
246 | strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); | 246 | strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); |
247 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ | 247 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ |
248 | filename_try[ MAXFILENAME ] = '\0'; | 248 | filename_try[ MAXFILENAME ] = '\0'; |
249 | 249 | ||
250 | len=(int)strlen(filename_try); | 250 | len=(int)strlen(filename_try); |
251 | for (i=0;i<len;i++) | 251 | for (i=0;i<len;i++) |
252 | if (filename_try[i]=='.') | 252 | if (filename_try[i]=='.') |
253 | dot_found=1; | 253 | dot_found=1; |
254 | 254 | ||
255 | if (dot_found==0) | 255 | if (dot_found==0) |
256 | strcat(filename_try,".zip"); | 256 | strcat(filename_try,".zip"); |
257 | 257 | ||
258 | if (opt_overwrite==2) | 258 | if (opt_overwrite==2) |
259 | { | 259 | { |
260 | /* if the file don't exist, we not append file */ | 260 | /* if the file don't exist, we not append file */ |
261 | if (check_exist_file(filename_try)==0) | 261 | if (check_exist_file(filename_try)==0) |
262 | opt_overwrite=1; | 262 | opt_overwrite=1; |
263 | } | 263 | } |
264 | else | 264 | else |
265 | if (opt_overwrite==0) | 265 | if (opt_overwrite==0) |
266 | if (check_exist_file(filename_try)!=0) | 266 | if (check_exist_file(filename_try)!=0) |
267 | { | 267 | { |
268 | char rep=0; | 268 | char rep=0; |
269 | do | 269 | do |
270 | { | 270 | { |
271 | char answer[128]; | 271 | char answer[128]; |
272 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); | 272 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); |
273 | scanf("%1s",answer); | 273 | scanf("%1s",answer); |
274 | rep = answer[0] ; | 274 | rep = answer[0] ; |
275 | if ((rep>='a') && (rep<='z')) | 275 | if ((rep>='a') && (rep<='z')) |
276 | rep -= 0x20; | 276 | rep -= 0x20; |
277 | } | 277 | } |
278 | while ((rep!='Y') && (rep!='N') && (rep!='A')); | 278 | while ((rep!='Y') && (rep!='N') && (rep!='A')); |
279 | if (rep=='N') | 279 | if (rep=='N') |
280 | zipok = 0; | 280 | zipok = 0; |
281 | if (rep=='A') | 281 | if (rep=='A') |
282 | opt_overwrite = 2; | 282 | opt_overwrite = 2; |
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | if (zipok==1) | 286 | if (zipok==1) |
287 | { | 287 | { |
288 | zipFile zf; | 288 | zipFile zf; |
289 | int errclose; | 289 | int errclose; |
290 | #ifdef USEWIN32IOAPI | 290 | # ifdef USEWIN32IOAPI |
291 | zlib_filefunc_def ffunc; | 291 | zlib_filefunc_def ffunc; |
292 | fill_win32_filefunc(&ffunc); | 292 | fill_win32_filefunc(&ffunc); |
293 | zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); | 293 | zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); |
294 | #else | 294 | # else |
295 | zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); | 295 | zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); |
296 | #endif | 296 | # endif |
297 | 297 | ||
298 | if (zf == NULL) | 298 | if (zf == NULL) |
299 | { | 299 | { |
300 | printf("error opening %s\n",filename_try); | 300 | printf("error opening %s\n",filename_try); |
301 | err= ZIP_ERRNO; | 301 | err= ZIP_ERRNO; |
302 | } | 302 | } |
303 | else | 303 | else |
304 | printf("creating %s\n",filename_try); | 304 | printf("creating %s\n",filename_try); |
305 | 305 | ||
306 | for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) | 306 | for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) |
307 | { | 307 | { |
308 | if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) | 308 | if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) |
309 | { | 309 | { |
310 | FILE * fin; | 310 | FILE * fin; |
311 | int size_read; | 311 | int size_read; |
312 | const char* filenameinzip = argv[i]; | 312 | const char* filenameinzip = argv[i]; |
313 | zip_fileinfo zi; | 313 | zip_fileinfo zi; |
314 | unsigned long crcFile=0; | 314 | unsigned long crcFile=0; |
315 | 315 | ||
316 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = | 316 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = |
317 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; | 317 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; |
318 | zi.dosDate = 0; | 318 | zi.dosDate = 0; |
319 | zi.internal_fa = 0; | 319 | zi.internal_fa = 0; |
320 | zi.external_fa = 0; | 320 | zi.external_fa = 0; |
321 | filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); | 321 | filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); |
322 | 322 | ||
323 | /* | 323 | /* |
324 | err = zipOpenNewFileInZip(zf,filenameinzip,&zi, | 324 | err = zipOpenNewFileInZip(zf,filenameinzip,&zi, |
325 | NULL,0,NULL,0,NULL / * comment * /, | 325 | NULL,0,NULL,0,NULL / * comment * /, |
326 | (opt_compress_level != 0) ? Z_DEFLATED : 0, | 326 | (opt_compress_level != 0) ? Z_DEFLATED : 0, |
327 | opt_compress_level); | 327 | opt_compress_level); |
328 | */ | 328 | */ |
329 | if ((password != NULL) && (err==ZIP_OK)) | 329 | if ((password != NULL) && (err==ZIP_OK)) |
330 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); | 330 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); |
331 | 331 | ||
332 | err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, | 332 | err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, |
333 | NULL,0,NULL,0,NULL /* comment*/, | 333 | NULL,0,NULL,0,NULL /* comment*/, |
334 | (opt_compress_level != 0) ? Z_DEFLATED : 0, | 334 | (opt_compress_level != 0) ? Z_DEFLATED : 0, |
335 | opt_compress_level,0, | 335 | opt_compress_level,0, |
336 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ | 336 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ |
337 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | 337 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
338 | password,crcFile); | 338 | password,crcFile); |
339 | 339 | ||
340 | if (err != ZIP_OK) | 340 | if (err != ZIP_OK) |
341 | printf("error in opening %s in zipfile\n",filenameinzip); | 341 | printf("error in opening %s in zipfile\n",filenameinzip); |
342 | else | 342 | else |
343 | { | 343 | { |
344 | fin = fopen(filenameinzip,"rb"); | 344 | fin = fopen(filenameinzip,"rb"); |
345 | if (fin==NULL) | 345 | if (fin==NULL) |
346 | { | 346 | { |
347 | err=ZIP_ERRNO; | 347 | err=ZIP_ERRNO; |
348 | printf("error in opening %s for reading\n",filenameinzip); | 348 | printf("error in opening %s for reading\n",filenameinzip); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | if (err == ZIP_OK) | 352 | if (err == ZIP_OK) |
353 | do | 353 | do |
354 | { | 354 | { |
355 | err = ZIP_OK; | 355 | err = ZIP_OK; |
356 | size_read = (int)fread(buf,1,size_buf,fin); | 356 | size_read = (int)fread(buf,1,size_buf,fin); |
357 | if (size_read < size_buf) | 357 | if (size_read < size_buf) |
358 | if (feof(fin)==0) | 358 | if (feof(fin)==0) |
359 | { | 359 | { |
360 | printf("error in reading %s\n",filenameinzip); | 360 | printf("error in reading %s\n",filenameinzip); |
361 | err = ZIP_ERRNO; | 361 | err = ZIP_ERRNO; |
362 | } | 362 | } |
363 | 363 | ||
364 | if (size_read>0) | 364 | if (size_read>0) |
365 | { | 365 | { |
366 | err = zipWriteInFileInZip (zf,buf,size_read); | 366 | err = zipWriteInFileInZip (zf,buf,size_read); |
367 | if (err<0) | 367 | if (err<0) |
368 | { | 368 | { |
369 | printf("error in writing %s in the zipfile\n", | 369 | printf("error in writing %s in the zipfile\n", |
370 | filenameinzip); | 370 | filenameinzip); |
371 | } | 371 | } |
372 | 372 | ||
373 | } | 373 | } |
374 | } while ((err == ZIP_OK) && (size_read>0)); | 374 | } while ((err == ZIP_OK) && (size_read>0)); |
375 | 375 | ||
376 | if (fin) | 376 | if (fin) |
377 | fclose(fin); | 377 | fclose(fin); |
378 | 378 | ||
379 | if (err<0) | 379 | if (err<0) |
380 | err=ZIP_ERRNO; | 380 | err=ZIP_ERRNO; |
381 | else | 381 | else |
382 | { | 382 | { |
383 | err = zipCloseFileInZip(zf); | 383 | err = zipCloseFileInZip(zf); |
384 | if (err!=ZIP_OK) | 384 | if (err!=ZIP_OK) |
385 | printf("error in closing %s in the zipfile\n", | 385 | printf("error in closing %s in the zipfile\n", |
386 | filenameinzip); | 386 | filenameinzip); |
387 | } | 387 | } |
388 | } | 388 | } |
389 | } | 389 | } |
390 | errclose = zipClose(zf,NULL); | 390 | errclose = zipClose(zf,NULL); |
391 | if (errclose != ZIP_OK) | 391 | if (errclose != ZIP_OK) |
392 | printf("error in closing %s\n",filename_try); | 392 | printf("error in closing %s\n",filename_try); |
393 | } | 393 | } |
394 | 394 | ||
395 | free(buf); | 395 | free(buf); |
396 | return 0; | 396 | return 0; |
397 | } | 397 | } |