diff options
author | kientzle <kientzle@FreeBSD.org> | 2007-03-03 07:37:37 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2007-03-03 07:37:37 +0000 |
commit | 1a60578adb6be1f7da9ed95f38cf52c20be13591 (patch) | |
tree | 1b026213a337089af577dee3ed6d194ee1b87d88 /lib/libarchive/archive_read_support_compression_bzip2.c | |
parent | 56746aa8e0ffff51b371e72446368d6dbbe6b4ba (diff) | |
download | FreeBSD-src-1a60578adb6be1f7da9ed95f38cf52c20be13591.zip FreeBSD-src-1a60578adb6be1f7da9ed95f38cf52c20be13591.tar.gz |
libarchive 2.0
* libarchive_test program exercises many of the core features
* Refactored old "read_extract" into new "archive_write_disk", which
uses archive_write methods to put entries onto disk. In particular,
you can now use archive_write_disk to create objects on disk
without having an archive available.
* Pushed some security checks from bsdtar down into libarchive, where
they can be better optimized.
* Rearchitected the logic for creating objects on disk to reduce
the number of system calls. Several common cases now use a
minimum number of system calls.
* Virtualized some internal interfaces to provide a clearer separation
of read and write handling and make it simpler to override key
methods.
* New "empty" format reader.
* Corrected return types (this ABI breakage required the "2.0" version bump)
* Many bug fixes.
Diffstat (limited to 'lib/libarchive/archive_read_support_compression_bzip2.c')
-rw-r--r-- | lib/libarchive/archive_read_support_compression_bzip2.c | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/lib/libarchive/archive_read_support_compression_bzip2.c b/lib/libarchive/archive_read_support_compression_bzip2.c index 307da68..969387e 100644 --- a/lib/libarchive/archive_read_support_compression_bzip2.c +++ b/lib/libarchive/archive_read_support_compression_bzip2.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_private.h" +#include "archive_read_private.h" #if HAVE_BZLIB_H struct private_data { @@ -56,19 +57,20 @@ struct private_data { int64_t total_out; }; -static int finish(struct archive *); -static ssize_t read_ahead(struct archive *, const void **, size_t); -static ssize_t read_consume(struct archive *, size_t); -static int drive_decompressor(struct archive *a, struct private_data *); +static int finish(struct archive_read *); +static ssize_t read_ahead(struct archive_read *, const void **, size_t); +static ssize_t read_consume(struct archive_read *, size_t); +static int drive_decompressor(struct archive_read *a, struct private_data *); #endif /* These two functions are defined even if we lack bzlib. See below. */ static int bid(const void *, size_t); -static int init(struct archive *, const void *, size_t); +static int init(struct archive_read *, const void *, size_t); int -archive_read_support_compression_bzip2(struct archive *a) +archive_read_support_compression_bzip2(struct archive *_a) { + struct archive_read *a = (struct archive_read *)_a; return (__archive_read_register_compression(a, bid, init)); } @@ -152,19 +154,19 @@ init(struct archive *a, const void *buff, size_t n) * Setup the callbacks. */ static int -init(struct archive *a, const void *buff, size_t n) +init(struct archive_read *a, const void *buff, size_t n) { struct private_data *state; int ret; - a->compression_code = ARCHIVE_COMPRESSION_BZIP2; - a->compression_name = "bzip2"; + a->archive.compression_code = ARCHIVE_COMPRESSION_BZIP2; + a->archive.compression_name = "bzip2"; state = (struct private_data *)malloc(sizeof(*state)); if (state == NULL) { - archive_set_error(a, ENOMEM, + archive_set_error(&a->archive, ENOMEM, "Can't allocate data for %s decompression", - a->compression_name); + a->archive.compression_name); return (ARCHIVE_FATAL); } memset(state, 0, sizeof(*state)); @@ -176,9 +178,9 @@ init(struct archive *a, const void *buff, size_t n) state->stream.avail_out = state->uncompressed_buffer_size; if (state->uncompressed_buffer == NULL) { - archive_set_error(a, ENOMEM, + archive_set_error(&a->archive, ENOMEM, "Can't allocate %s decompression buffers", - a->compression_name); + a->archive.compression_name); free(state); return (ARCHIVE_FATAL); } @@ -215,25 +217,26 @@ init(struct archive *a, const void *buff, size_t n) } /* Library setup failed: Clean up. */ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Internal error initializing %s library", a->compression_name); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing %s library", + a->archive.compression_name); free(state->uncompressed_buffer); free(state); /* Override the error message if we know what really went wrong. */ switch (ret) { case BZ_PARAM_ERROR: - archive_set_error(a, ARCHIVE_ERRNO_MISC, + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal error initializing compression library: " "invalid setup parameter"); break; case BZ_MEM_ERROR: - archive_set_error(a, ARCHIVE_ERRNO_MISC, + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal error initializing compression library: " "out of memory"); break; case BZ_CONFIG_ERROR: - archive_set_error(a, ARCHIVE_ERRNO_MISC, + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal error initializing compression library: " "mis-compiled library"); break; @@ -247,7 +250,7 @@ init(struct archive *a, const void *buff, size_t n) * as necessary. */ static ssize_t -read_ahead(struct archive *a, const void **p, size_t min) +read_ahead(struct archive_read *a, const void **p, size_t min) { struct private_data *state; int read_avail, was_avail, ret; @@ -255,7 +258,7 @@ read_ahead(struct archive *a, const void **p, size_t min) state = (struct private_data *)a->compression_data; was_avail = -1; if (!a->client_reader) { - archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER, + archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "No read callback is registered? " "This is probably an internal programming error."); return (ARCHIVE_FATAL); @@ -289,12 +292,12 @@ read_ahead(struct archive *a, const void **p, size_t min) * Mark a previously-returned block of data as read. */ static ssize_t -read_consume(struct archive *a, size_t n) +read_consume(struct archive_read *a, size_t n) { struct private_data *state; state = (struct private_data *)a->compression_data; - a->file_position += n; + a->archive.file_position += n; state->read_next += n; if (state->read_next > state->stream.next_out) __archive_errx(1, "Request to consume too many " @@ -306,7 +309,7 @@ read_consume(struct archive *a, size_t n) * Clean up the decompressor. */ static int -finish(struct archive *a) +finish(struct archive_read *a) { struct private_data *state; int ret; @@ -317,8 +320,9 @@ finish(struct archive *a) case BZ_OK: break; default: - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Failed to clean up %s compressor", a->compression_name); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up %s compressor", + a->archive.compression_name); ret = ARCHIVE_FATAL; } @@ -327,7 +331,7 @@ finish(struct archive *a) a->compression_data = NULL; if (a->client_closer != NULL) - (a->client_closer)(a, a->client_data); + (a->client_closer)(&a->archive, a->client_data); return (ret); } @@ -337,7 +341,7 @@ finish(struct archive *a) * blocks as necessary. */ static int -drive_decompressor(struct archive *a, struct private_data *state) +drive_decompressor(struct archive_read *a, struct private_data *state) { ssize_t ret; int decompressed, total_decompressed; @@ -346,7 +350,7 @@ drive_decompressor(struct archive *a, struct private_data *state) total_decompressed = 0; for (;;) { if (state->stream.avail_in == 0) { - ret = (a->client_reader)(a, a->client_data, + ret = (a->client_reader)(&a->archive, a->client_data, (const void **)&state->stream.next_in); if (ret < 0) { /* @@ -356,12 +360,12 @@ drive_decompressor(struct archive *a, struct private_data *state) goto fatal; } if (ret == 0 && total_decompressed == 0) { - archive_set_error(a, EIO, + archive_set_error(&a->archive, EIO, "Premature end of %s compressed data", - a->compression_name); + a->archive.compression_name); return (ARCHIVE_FATAL); } - a->raw_position += ret; + a->archive.raw_position += ret; state->stream.avail_in = ret; } @@ -393,8 +397,8 @@ drive_decompressor(struct archive *a, struct private_data *state) /* Return a fatal error. */ fatal: - archive_set_error(a, ARCHIVE_ERRNO_MISC, "%s decompression failed", - a->compression_name); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s decompression failed", a->archive.compression_name); return (ARCHIVE_FATAL); } |