diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-06-12 15:28:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-06-12 15:28:40 +0000 |
commit | 5fdc452e7d44a7647b5cc1667df3078d53b0546e (patch) | |
tree | 801e0671c312bd8202fc67f6c579d24f77343779 /src/common | |
parent | 91fb214deea3390b64b304b6b08e533327881fbe (diff) | |
download | libextractor-5fdc452e7d44a7647b5cc1667df3078d53b0546e.tar.gz libextractor-5fdc452e7d44a7647b5cc1667df3078d53b0546e.zip |
code cleanup
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/unzip.c | 290 |
1 files changed, 124 insertions, 166 deletions
diff --git a/src/common/unzip.c b/src/common/unzip.c index 4de66fc..0b002e7 100644 --- a/src/common/unzip.c +++ b/src/common/unzip.c | |||
@@ -166,15 +166,10 @@ typedef struct | |||
166 | */ | 166 | */ |
167 | 167 | ||
168 | 168 | ||
169 | static int unzlocal_getByte OF(( | 169 | static int |
170 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, | 170 | unzlocal_getByte(const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, |
171 | voidpf filestream, | 171 | voidpf filestream, |
172 | int *pi)); | 172 | int *pi) |
173 | |||
174 | static int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) | ||
175 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def; | ||
176 | voidpf filestream; | ||
177 | int *pi; | ||
178 | { | 173 | { |
179 | unsigned char c; | 174 | unsigned char c; |
180 | int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); | 175 | int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); |
@@ -193,95 +188,80 @@ static int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) | |||
193 | } | 188 | } |
194 | 189 | ||
195 | 190 | ||
196 | /* =========================================================================== | 191 | static int |
197 | Reads a long in LSB order from the given gz_stream. Sets | 192 | unzlocal_getShort (const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, |
198 | */ | 193 | voidpf filestream, |
199 | static int unzlocal_getShort OF(( | 194 | uLong *pX) |
200 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, | ||
201 | voidpf filestream, | ||
202 | uLong *pX)); | ||
203 | |||
204 | static int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) | ||
205 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def; | ||
206 | voidpf filestream; | ||
207 | uLong *pX; | ||
208 | { | 195 | { |
209 | uLong x ; | 196 | uLong x; |
210 | int i; | 197 | int i; |
211 | int err; | 198 | int err; |
212 | 199 | ||
213 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 200 | err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); |
214 | x = (uLong)i; | 201 | *pX = 0; |
215 | 202 | if (err != EXTRACTOR_UNZIP_OK) | |
216 | if (err==EXTRACTOR_UNZIP_OK) | ||
217 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | ||
218 | x += ((uLong)i)<<8; | ||
219 | |||
220 | if (err==EXTRACTOR_UNZIP_OK) | ||
221 | *pX = x; | ||
222 | else | ||
223 | *pX = 0; | ||
224 | return err; | 203 | return err; |
204 | x = (uLong)i; | ||
205 | err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); | ||
206 | if (err != EXTRACTOR_UNZIP_OK) | ||
207 | return err; | ||
208 | x += ((uLong)i)<<8; | ||
209 | *pX = x; | ||
210 | return err; | ||
225 | } | 211 | } |
226 | 212 | ||
227 | static int unzlocal_getLong OF(( | 213 | static int |
228 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, | 214 | unzlocal_getLong (const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, |
229 | voidpf filestream, | 215 | voidpf filestream, |
230 | uLong *pX)); | 216 | uLong *pX) |
231 | |||
232 | static int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) | ||
233 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def; | ||
234 | voidpf filestream; | ||
235 | uLong *pX; | ||
236 | { | 217 | { |
237 | uLong x ; | 218 | uLong x ; |
238 | int i; | 219 | int i; |
239 | int err; | 220 | int err; |
240 | 221 | ||
241 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 222 | *pX = 0; |
242 | x = (uLong)i; | 223 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); |
243 | 224 | if (err != EXTRACTOR_UNZIP_OK) | |
244 | if (err==EXTRACTOR_UNZIP_OK) | 225 | return err; |
245 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 226 | x = (uLong)i; |
246 | x += ((uLong)i)<<8; | 227 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); |
247 | 228 | if (err != EXTRACTOR_UNZIP_OK) | |
248 | if (err==EXTRACTOR_UNZIP_OK) | ||
249 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | ||
250 | x += ((uLong)i)<<16; | ||
251 | |||
252 | if (err==EXTRACTOR_UNZIP_OK) | ||
253 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | ||
254 | x += ((uLong)i)<<24; | ||
255 | |||
256 | if (err==EXTRACTOR_UNZIP_OK) | ||
257 | *pX = x; | ||
258 | else | ||
259 | *pX = 0; | ||
260 | return err; | 229 | return err; |
230 | x += ((uLong)i)<<8; | ||
231 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | ||
232 | if (err != EXTRACTOR_UNZIP_OK) | ||
233 | return err; | ||
234 | x += ((uLong)i)<<16; | ||
235 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | ||
236 | if (err != EXTRACTOR_UNZIP_OK) | ||
237 | return err; | ||
238 | x += ((uLong)i)<<24; | ||
239 | *pX = x; | ||
240 | return err; | ||
261 | } | 241 | } |
262 | 242 | ||
263 | 243 | ||
264 | /* My own strcmpi / strcasecmp */ | 244 | /* My own strcmpi / strcasecmp */ |
265 | static int strcmpcasenosensitive_internal (fileName1,fileName2) | 245 | static int |
266 | const char* fileName1; | 246 | strcmpcasenosensitive_internal (const char* fileName1, |
267 | const char* fileName2; | 247 | const char* fileName2) |
268 | { | 248 | { |
269 | for (;;) | 249 | while (1) |
270 | { | 250 | { |
271 | char c1=*(fileName1++); | 251 | const char c1=*(fileName1++); |
272 | char c2=*(fileName2++); | 252 | const char c2=*(fileName2++); |
273 | if ((c1>='a') && (c1<='z')) | 253 | if ((c1>='a') && (c1<='z')) |
274 | c1 -= 0x20; | 254 | c1 -= 0x20; |
275 | if ((c2>='a') && (c2<='z')) | 255 | if ((c2>='a') && (c2<='z')) |
276 | c2 -= 0x20; | 256 | c2 -= 0x20; |
277 | if (c1=='\0') | 257 | if (c1=='\0') |
278 | return ((c2=='\0') ? 0 : -1); | 258 | return ((c2=='\0') ? 0 : -1); |
279 | if (c2=='\0') | 259 | if (c2=='\0') |
280 | return 1; | 260 | return 1; |
281 | if (c1<c2) | 261 | if (c1<c2) |
282 | return -1; | 262 | return -1; |
283 | if (c1>c2) | 263 | if (c1>c2) |
284 | return 1; | 264 | return 1; |
285 | } | 265 | } |
286 | } | 266 | } |
287 | 267 | ||
@@ -305,35 +285,27 @@ static int strcmpcasenosensitive_internal (fileName1,fileName2) | |||
305 | (like 1 on Unix, 2 on Windows) | 285 | (like 1 on Unix, 2 on Windows) |
306 | 286 | ||
307 | */ | 287 | */ |
308 | int EXTRACTOR_common_unzip_string_file_name_compare (fileName1,fileName2,iCaseSensitivity) | 288 | int |
309 | const char* fileName1; | 289 | EXTRACTOR_common_unzip_string_file_name_compare (const char* fileName1, |
310 | const char* fileName2; | 290 | const char* fileName2, |
311 | int iCaseSensitivity; | 291 | int iCaseSensitivity) |
312 | { | 292 | { |
313 | if (iCaseSensitivity==0) | 293 | if (iCaseSensitivity==0) |
314 | iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; | 294 | iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; |
315 | 295 | ||
316 | if (iCaseSensitivity==1) | 296 | if (iCaseSensitivity==1) |
317 | return strcmp(fileName1,fileName2); | 297 | return strcmp(fileName1,fileName2); |
318 | 298 | ||
319 | return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); | 299 | return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); |
320 | } | 300 | } |
321 | 301 | ||
322 | #ifndef BUFREADCOMMENT | 302 | #ifndef BUFREADCOMMENT |
323 | #define BUFREADCOMMENT (0x400) | 303 | #define BUFREADCOMMENT (0x400) |
324 | #endif | 304 | #endif |
325 | 305 | ||
326 | /* | 306 | static uLong |
327 | Locate the Central directory of a zipfile (at the end, just before | 307 | unzlocal_SearchCentralDir(const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, |
328 | the global comment) | 308 | voidpf filestream) |
329 | */ | ||
330 | static uLong unzlocal_SearchCentralDir OF(( | ||
331 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def, | ||
332 | voidpf filestream)); | ||
333 | |||
334 | static uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | ||
335 | const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def; | ||
336 | voidpf filestream; | ||
337 | { | 309 | { |
338 | unsigned char* buf; | 310 | unsigned char* buf; |
339 | uLong uSizeFile; | 311 | uLong uSizeFile; |
@@ -391,9 +363,9 @@ static uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |||
391 | /* | 363 | /* |
392 | Translate date/time from Dos format to EXTRACTOR_unzip_tm_unz (readable more easilty) | 364 | Translate date/time from Dos format to EXTRACTOR_unzip_tm_unz (readable more easilty) |
393 | */ | 365 | */ |
394 | static void unzlocal_DosDateToTmuDate (ulDosDate, ptm) | 366 | static void |
395 | uLong ulDosDate; | 367 | unzlocal_DosDateToTmuDate (uLong ulDosDate, |
396 | EXTRACTOR_unzip_tm_unz* ptm; | 368 | EXTRACTOR_unzip_tm_unz* ptm) |
397 | { | 369 | { |
398 | uLong uDate; | 370 | uLong uDate; |
399 | uDate = (uLong)(ulDosDate>>16); | 371 | uDate = (uLong)(ulDosDate>>16); |
@@ -408,21 +380,16 @@ static void unzlocal_DosDateToTmuDate (ulDosDate, ptm) | |||
408 | 380 | ||
409 | 381 | ||
410 | 382 | ||
411 | static int unzlocal_GetCurrentFileInfoInternal (file, | 383 | static int |
412 | pfile_info, | 384 | unzlocal_GetCurrentFileInfoInternal (EXTRACTOR_unzip_file file, |
413 | pfile_info_internal, | 385 | EXTRACTOR_unzip_file_info *pfile_info, |
414 | szFileName, fileNameBufferSize, | 386 | unz_file_info_internal *pfile_info_internal, |
415 | extraField, extraFieldBufferSize, | 387 | char *szFileName, |
416 | szComment, commentBufferSize) | 388 | uLong fileNameBufferSize, |
417 | EXTRACTOR_unzip_file file; | 389 | void *extraField, |
418 | EXTRACTOR_unzip_file_info *pfile_info; | 390 | uLong extraFieldBufferSize, |
419 | unz_file_info_internal *pfile_info_internal; | 391 | char *szComment, |
420 | char *szFileName; | 392 | uLong commentBufferSize) |
421 | uLong fileNameBufferSize; | ||
422 | void *extraField; | ||
423 | uLong extraFieldBufferSize; | ||
424 | char *szComment; | ||
425 | uLong commentBufferSize; | ||
426 | { | 393 | { |
427 | unz_s* s; | 394 | unz_s* s; |
428 | EXTRACTOR_unzip_file_info file_info; | 395 | EXTRACTOR_unzip_file_info file_info; |
@@ -574,8 +541,8 @@ static int unzlocal_GetCurrentFileInfoInternal (file, | |||
574 | Set the current file of the zipfile to the first file. | 541 | Set the current file of the zipfile to the first file. |
575 | return UNZ_OK if there is no problem | 542 | return UNZ_OK if there is no problem |
576 | */ | 543 | */ |
577 | int EXTRACTOR_common_unzip_go_to_first_file (file) | 544 | int |
578 | EXTRACTOR_unzip_file file; | 545 | EXTRACTOR_common_unzip_go_to_first_file (EXTRACTOR_unzip_file file) |
579 | { | 546 | { |
580 | int err=EXTRACTOR_UNZIP_OK; | 547 | int err=EXTRACTOR_UNZIP_OK; |
581 | unz_s* s; | 548 | unz_s* s; |
@@ -601,9 +568,9 @@ int EXTRACTOR_common_unzip_go_to_first_file (file) | |||
601 | Else, the return value is a EXTRACTOR_unzip_file Handle, usable with other function | 568 | Else, the return value is a EXTRACTOR_unzip_file Handle, usable with other function |
602 | of this unzip package. | 569 | of this unzip package. |
603 | */ | 570 | */ |
604 | EXTRACTOR_unzip_file EXTRACTOR_common_unzip_open2 (path, pzlib_filefunc_def) | 571 | EXTRACTOR_unzip_file |
605 | const char *path; | 572 | EXTRACTOR_common_unzip_open2 (const char *path, |
606 | EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def; | 573 | EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def) |
607 | { | 574 | { |
608 | unz_s us; | 575 | unz_s us; |
609 | unz_s *s; | 576 | unz_s *s; |
@@ -704,8 +671,8 @@ EXTRACTOR_unzip_file EXTRACTOR_common_unzip_open2 (path, pzlib_filefunc_def) | |||
704 | Close the file in zip opened with unzipOpenCurrentFile | 671 | Close the file in zip opened with unzipOpenCurrentFile |
705 | Return EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good | 672 | Return EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good |
706 | */ | 673 | */ |
707 | int EXTRACTOR_common_unzip_close_current_file (file) | 674 | int |
708 | EXTRACTOR_unzip_file file; | 675 | EXTRACTOR_common_unzip_close_current_file (EXTRACTOR_unzip_file file) |
709 | { | 676 | { |
710 | int err=EXTRACTOR_UNZIP_OK; | 677 | int err=EXTRACTOR_UNZIP_OK; |
711 | 678 | ||
@@ -746,8 +713,7 @@ int EXTRACTOR_common_unzip_close_current_file (file) | |||
746 | If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), | 713 | If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), |
747 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. | 714 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. |
748 | return EXTRACTOR_UNZIP_OK if there is no problem. */ | 715 | return EXTRACTOR_UNZIP_OK if there is no problem. */ |
749 | int EXTRACTOR_common_unzip_close (file) | 716 | int EXTRACTOR_common_unzip_close (EXTRACTOR_unzip_file file) |
750 | EXTRACTOR_unzip_file file; | ||
751 | { | 717 | { |
752 | unz_s* s; | 718 | unz_s* s; |
753 | if (file==NULL) | 719 | if (file==NULL) |
@@ -768,19 +734,14 @@ int EXTRACTOR_common_unzip_close (file) | |||
768 | No preparation of the structure is needed | 734 | No preparation of the structure is needed |
769 | return EXTRACTOR_UNZIP_OK if there is no problem. | 735 | return EXTRACTOR_UNZIP_OK if there is no problem. |
770 | */ | 736 | */ |
771 | int EXTRACTOR_common_unzip_get_current_file_info (file, | 737 | int EXTRACTOR_common_unzip_get_current_file_info (EXTRACTOR_unzip_file file, |
772 | pfile_info, | 738 | EXTRACTOR_unzip_file_info *pfile_info, |
773 | szFileName, fileNameBufferSize, | 739 | char *szFileName, |
774 | extraField, extraFieldBufferSize, | 740 | uLong fileNameBufferSize, |
775 | szComment, commentBufferSize) | 741 | void *extraField, |
776 | EXTRACTOR_unzip_file file; | 742 | uLong extraFieldBufferSize, |
777 | EXTRACTOR_unzip_file_info *pfile_info; | 743 | char *szComment, |
778 | char *szFileName; | 744 | uLong commentBufferSize) |
779 | uLong fileNameBufferSize; | ||
780 | void *extraField; | ||
781 | uLong extraFieldBufferSize; | ||
782 | char *szComment; | ||
783 | uLong commentBufferSize; | ||
784 | { | 745 | { |
785 | return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, | 746 | return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, |
786 | szFileName,fileNameBufferSize, | 747 | szFileName,fileNameBufferSize, |
@@ -793,8 +754,7 @@ int EXTRACTOR_common_unzip_get_current_file_info (file, | |||
793 | return EXTRACTOR_UNZIP_OK if there is no problem | 754 | return EXTRACTOR_UNZIP_OK if there is no problem |
794 | return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the actual file was the latest. | 755 | return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the actual file was the latest. |
795 | */ | 756 | */ |
796 | int EXTRACTOR_common_unzip_go_to_next_file (file) | 757 | int EXTRACTOR_common_unzip_go_to_next_file (EXTRACTOR_unzip_file file) |
797 | EXTRACTOR_unzip_file file; | ||
798 | { | 758 | { |
799 | unz_s* s; | 759 | unz_s* s; |
800 | int err; | 760 | int err; |
@@ -899,10 +859,10 @@ int EXTRACTOR_common_unzip_local_file (file, szFileName, iCaseSensitivity) | |||
899 | return <0 with error code if there is an error | 859 | return <0 with error code if there is an error |
900 | (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error) | 860 | (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error) |
901 | */ | 861 | */ |
902 | int EXTRACTOR_common_unzip_read_current_file (file, buf, len) | 862 | int |
903 | EXTRACTOR_unzip_file file; | 863 | EXTRACTOR_common_unzip_read_current_file (EXTRACTOR_unzip_file file, |
904 | voidp buf; | 864 | voidp buf, |
905 | unsigned len; | 865 | unsigned len) |
906 | { | 866 | { |
907 | int err=EXTRACTOR_UNZIP_OK; | 867 | int err=EXTRACTOR_UNZIP_OK; |
908 | uInt iRead = 0; | 868 | uInt iRead = 0; |
@@ -1040,13 +1000,11 @@ int EXTRACTOR_common_unzip_read_current_file (file, buf, len) | |||
1040 | store in *piSizeVar the size of extra info in local header | 1000 | store in *piSizeVar the size of extra info in local header |
1041 | (filename and size of extra field data) | 1001 | (filename and size of extra field data) |
1042 | */ | 1002 | */ |
1043 | static int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, | 1003 | static int |
1044 | poffset_local_extrafield, | 1004 | unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, |
1045 | psize_local_extrafield) | 1005 | uInt* piSizeVar, |
1046 | unz_s* s; | 1006 | uLong *poffset_local_extrafield, |
1047 | uInt* piSizeVar; | 1007 | uInt *psize_local_extrafield) |
1048 | uLong *poffset_local_extrafield; | ||
1049 | uInt *psize_local_extrafield; | ||
1050 | { | 1008 | { |
1051 | uLong uMagic,uData,uFlags; | 1009 | uLong uMagic,uData,uFlags; |
1052 | uLong size_filename; | 1010 | uLong size_filename; |
@@ -1132,11 +1090,11 @@ static int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, | |||
1132 | Open for reading data the current file in the zipfile. | 1090 | Open for reading data the current file in the zipfile. |
1133 | If there is no error and the file is opened, the return value is EXTRACTOR_UNZIP_OK. | 1091 | If there is no error and the file is opened, the return value is EXTRACTOR_UNZIP_OK. |
1134 | */ | 1092 | */ |
1135 | int EXTRACTOR_common_unzip_open_current_file3 (file, method, level, raw) | 1093 | int |
1136 | EXTRACTOR_unzip_file file; | 1094 | EXTRACTOR_common_unzip_open_current_file3 (EXTRACTOR_unzip_file file, |
1137 | int* method; | 1095 | int* method, |
1138 | int* level; | 1096 | int* level, |
1139 | int raw; | 1097 | int raw) |
1140 | { | 1098 | { |
1141 | int err=EXTRACTOR_UNZIP_OK; | 1099 | int err=EXTRACTOR_UNZIP_OK; |
1142 | uInt iSizeVar; | 1100 | uInt iSizeVar; |