diff options
Diffstat (limited to 'src/archive')
-rw-r--r-- | src/archive/bz2_plugin.c | 55 | ||||
-rw-r--r-- | src/archive/iso_plugin.c | 1 | ||||
-rw-r--r-- | src/archive/zip_plugin.c | 3 |
3 files changed, 33 insertions, 26 deletions
diff --git a/src/archive/bz2_plugin.c b/src/archive/bz2_plugin.c index 0ef042e90..693dd4dba 100644 --- a/src/archive/bz2_plugin.c +++ b/src/archive/bz2_plugin.c @@ -21,9 +21,9 @@ * single bz2 archive handling (requires libbz2) */ +#include "config.h" #include "archive_api.h" #include "input_plugin.h" -#include "config.h" #include <stdint.h> #include <stddef.h> @@ -32,23 +32,22 @@ #include <bzlib.h> #ifdef HAVE_OLDER_BZIP2 -#define BZ2_bzDecompressInit bzDecompressInit -#define BZ2_bzDecompress bzDecompress +#define BZ2_bzDecompressInit bzDecompressInit +#define BZ2_bzDecompress bzDecompress #endif #define BZ_BUFSIZE 5000 typedef struct { - char *name; - bool reset; + char *name; + bool reset; struct input_stream istream; - int last_bz_result; - int last_parent_result; - bz_stream bzstream; - char *buffer; + int last_bz_result; + int last_parent_result; + bz_stream bzstream; + char *buffer; } bz2_context; - static const struct input_plugin bz2_inputplugin; /* single archive handling allocation helpers */ @@ -85,22 +84,21 @@ bz2_destroy(bz2_context *data) /* archive open && listing routine */ static struct archive_file * -bz2_open(char * pathname) +bz2_open(char *pathname) { bz2_context *context; char *name; int len; - context = g_malloc(sizeof(bz2_context)); - if (!context) { - return NULL; - } + context = g_malloc(sizeof(*context)); + //open archive if (!input_stream_open(&context->istream, pathname)) { g_warning("failed to open an bzip2 archive %s\n",pathname); g_free(context); return NULL; } + //capture filename name = strrchr(pathname, '/'); if (name == NULL) { @@ -108,12 +106,15 @@ bz2_open(char * pathname) g_free(context); return NULL; } - context->name = g_strdup(name+1); + + context->name = g_strdup(name + 1); + //remove suffix len = strlen(context->name); if (len > 4) { - context->name[len-4] = 0; //remove .bz2 suffix + context->name[len - 4] = 0; //remove .bz2 suffix } + return (struct archive_file *) context; } @@ -129,10 +130,12 @@ bz2_scan_next(struct archive_file *file) { bz2_context *context = (bz2_context *) file; char *name = NULL; + if (context->reset) { name = context->name; context->reset = false; } + return name; } @@ -154,6 +157,7 @@ bz2_open_stream(struct archive_file *file, struct input_stream *is, G_GNUC_UNUSED const char *path) { bz2_context *context = (bz2_context *) file; + //setup file ops is->plugin = &bz2_inputplugin; //insert back reference @@ -164,6 +168,7 @@ bz2_open_stream(struct archive_file *file, struct input_stream *is, g_warning("alloc bz2 failed\n"); return false; } + return true; } @@ -177,9 +182,8 @@ bz2_is_close(struct input_stream *is) bz2_close((struct archive_file *)context); } -static int -bz2_fillbuffer(bz2_context *context, - size_t numBytes) +static bool +bz2_fillbuffer(bz2_context *context, size_t numBytes) { size_t count; bz_stream *bzstream; @@ -187,14 +191,15 @@ bz2_fillbuffer(bz2_context *context, bzstream = &context->bzstream; if (bzstream->avail_in > 0) - return 0; + return true; count = input_stream_read(&context->istream, - context->buffer, BZ_BUFSIZE); + context->buffer, BZ_BUFSIZE); if (count == 0) { if (bzstream->avail_out == numBytes) - return -1; + return false; + if (!input_stream_eof(&context->istream)) context->last_parent_result = 1; } else { @@ -202,7 +207,7 @@ bz2_fillbuffer(bz2_context *context, bzstream->avail_in = count; } - return 0; + return true; } static size_t @@ -224,7 +229,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t size) bzstream->avail_out = numBytes; while (bzstream->avail_out != 0) { - if (bz2_fillbuffer(context, numBytes) != 0) + if (!bz2_fillbuffer(context, numBytes)) break; bz_result = BZ2_bzDecompress(bzstream); diff --git a/src/archive/iso_plugin.c b/src/archive/iso_plugin.c index 9063af0fc..b56653d56 100644 --- a/src/archive/iso_plugin.c +++ b/src/archive/iso_plugin.c @@ -21,6 +21,7 @@ * iso archive handling (requires cdio, and iso9660) */ +#include "config.h" #include "archive_api.h" #include "input_plugin.h" diff --git a/src/archive/zip_plugin.c b/src/archive/zip_plugin.c index 243d46418..95bc1d02b 100644 --- a/src/archive/zip_plugin.c +++ b/src/archive/zip_plugin.c @@ -21,6 +21,7 @@ * zip archive handling (requires zziplib) */ +#include "config.h" #include "archive_api.h" #include "archive_api.h" #include "input_plugin.h" @@ -160,7 +161,7 @@ zip_is_eof(struct input_stream *is) static bool zip_is_seek(G_GNUC_UNUSED struct input_stream *is, - G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence) + G_GNUC_UNUSED goffset offset, G_GNUC_UNUSED int whence) { zip_context *context = (zip_context *) is->data; zzip_off_t ofs = zzip_seek(context->file, offset, whence); |