libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit b14053bea488126a2cb64f176e480bbc456b9d23
parent e9a2eb54d9fefd38574958c759e6d660085e7888
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 12 Jun 2010 20:46:13 +0000

cleaning

Diffstat:
Msrc/common/unzip.c | 18++++++++----------
Msrc/plugins/zip_extractor.c | 58++++++++++++++++++++++------------------------------------
2 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/src/common/unzip.c b/src/common/unzip.c @@ -89,9 +89,6 @@ typedef struct unz_global_info_s #ifndef ALLOC # define ALLOC(size) (malloc(size)) #endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif #define SIZECENTRALDIRITEM (0x2e) #define SIZEZIPLOCALHEADER (0x1e) @@ -356,7 +353,7 @@ unzlocal_SearchCentralDir(const EXTRACTOR_unzip_filefunc_def* pzlib_filefunc_def if (uPosFound!=0) break; } - TRYFREE(buf); + free(buf); return uPosFound; } @@ -695,13 +692,14 @@ EXTRACTOR_common_unzip_close_current_file (EXTRACTOR_unzip_file file) } - TRYFREE(pfile_in_zip_read_info->read_buffer); + if (NULL != pfile_in_zip_read_info->read_buffer) + free(pfile_in_zip_read_info->read_buffer); pfile_in_zip_read_info->read_buffer = NULL; if (pfile_in_zip_read_info->stream_initialised) inflateEnd(&pfile_in_zip_read_info->stream); pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); + free(pfile_in_zip_read_info); s->pfile_in_zip_read=NULL; @@ -724,7 +722,7 @@ int EXTRACTOR_common_unzip_close (EXTRACTOR_unzip_file file) EXTRACTOR_common_unzip_close_current_file(file); ZCLOSE(s->z_filefunc, s->filestream); - TRYFREE(s); + free(s); return EXTRACTOR_UNZIP_OK; } @@ -1127,10 +1125,10 @@ EXTRACTOR_common_unzip_open_current_file3 (EXTRACTOR_unzip_file file, pfile_in_zip_read_info->raw=raw; if (pfile_in_zip_read_info->read_buffer==NULL) - { - TRYFREE(pfile_in_zip_read_info); + { + free(pfile_in_zip_read_info); return EXTRACTOR_UNZIP_INTERNALERROR; - } + } pfile_in_zip_read_info->stream_initialised=0; diff --git a/src/plugins/zip_extractor.c b/src/plugins/zip_extractor.c @@ -152,14 +152,13 @@ EXTRACTOR_zip_extract (const unsigned char *data, pos = &data[offset--]; if (offset == stop) { - #if DEBUG_EXTRACT_ZIP - fprintf (stderr, + fprintf (stderr, "Did not find end of central directory structure signature. offset: %i\n", offset); -#endif /* */ - return 0; +#endif + return 0; } /* offset should now point to the start of the end-of-central directory structure */ @@ -180,26 +179,20 @@ EXTRACTOR_zip_extract (const unsigned char *data, filecomment[filecomment_length] = '\0'; } } + +#if DEBUG_EXTRACT_ZIP if ((0 != pos[4]) && (0 != pos[5])) - { + fprintf (stderr, + "WARNING: This seems to be the last disk in a multi-volume" + " ZIP archive, and so this might not work.\n"); +#endif #if DEBUG_EXTRACT_ZIP - fprintf (stderr, - "WARNING: This seems to be the last disk in a multi-volume" - " ZIP archive, and so this might not work.\n"); - -#endif /* */ - } if ((pos[8] != pos[10]) && (pos[9] != pos[11])) - { - -#if DEBUG_EXTRACT_ZIP - fprintf (stderr, - "WARNING: May not be able to find all the files in this" - " ZIP archive (no multi-volume support right now).\n"); - -#endif /* */ - } + fprintf (stderr, + "WARNING: May not be able to find all the files in this" + " ZIP archive (no multi-volume support right now).\n"); +#endif entry_total = pos[10] + (pos[11] << 8); entry_count = 0; @@ -246,18 +239,17 @@ EXTRACTOR_zip_extract (const unsigned char *data, */ if (!(('P' == pos[0]) && ('K' == pos[1]) && (0x01 == pos[2]) && (0x02 == pos[3]))) - { - + { #if DEBUG_EXTRACT_ZIP fprintf (stderr, "Did not find central directory structure signature. offset: %i\n", offset); - + #endif if (filecomment != NULL) free (filecomment); return 0; - } + } start = NULL; info = NULL; @@ -278,8 +270,7 @@ EXTRACTOR_zip_extract (const unsigned char *data, fprintf (stderr, "Found filename length %i Comment length: %i\n", name_length, comment_length); -#endif /* */ - +#endif /* yay, finally get filenames */ if (start == NULL) { @@ -316,8 +307,7 @@ EXTRACTOR_zip_extract (const unsigned char *data, pos = &data[offset]; /* check for next header entry (0x02014b50) or (0x06054b50) if at end */ if (('P' != pos[0]) && ('K' != pos[1])) - { - + { #if DEBUG_EXTRACT_ZIP fprintf (stderr, "Did not find next header in central directory.\n"); @@ -345,15 +335,11 @@ EXTRACTOR_zip_extract (const unsigned char *data, /* TODO: should this return an error? indicates corrupt zipfile (or disk missing in middle of multi-disk)? */ - if (entry_count != entry_total) - { - #if DEBUG_EXTRACT_ZIP - fprintf (stderr, - "WARNING: Did not find all of the zipfile entries that we should have.\n"); - -#endif /* */ - } + if (entry_count != entry_total) + fprintf (stderr, + "WARNING: Did not find all of the zipfile entries that we should have.\n"); +#endif ret = proc (proc_cls, "zip",