summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_write_set_compression_none.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libarchive/archive_write_set_compression_none.c')
-rw-r--r--lib/libarchive/archive_write_set_compression_none.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/libarchive/archive_write_set_compression_none.c b/lib/libarchive/archive_write_set_compression_none.c
index 9e43365..3fdaa67 100644
--- a/lib/libarchive/archive_write_set_compression_none.c
+++ b/lib/libarchive/archive_write_set_compression_none.c
@@ -89,13 +89,14 @@ archive_compressor_none_init(struct archive *a)
memset(state, 0, sizeof(*state));
state->buffer_size = a->bytes_per_block;
- state->buffer = (char *)malloc(state->buffer_size);
-
- if (state->buffer == NULL) {
- archive_set_error(a, ENOMEM,
- "Can't allocate output buffer");
- free(state);
- return (ARCHIVE_FATAL);
+ if (state->buffer_size != 0) {
+ state->buffer = (char *)malloc(state->buffer_size);
+ if (state->buffer == NULL) {
+ archive_set_error(a, ENOMEM,
+ "Can't allocate output buffer");
+ free(state);
+ return (ARCHIVE_FATAL);
+ }
}
state->next = state->buffer;
@@ -129,7 +130,27 @@ archive_compressor_none_write(struct archive *a, const void *vbuff,
}
remaining = length;
- while (remaining > 0) {
+
+ /*
+ * If there is no buffer for blocking, just pass the data
+ * straight through to the client write callback. In
+ * particular, this supports "no write delay" operation for
+ * special applications. Just set the block size to zero.
+ */
+ if (state->buffer_size == 0) {
+ while (remaining > 0) {
+ bytes_written = (a->client_writer)(a, a->client_data,
+ buff, remaining);
+ if (bytes_written <= 0)
+ return (ARCHIVE_FATAL);
+ remaining -= bytes_written;
+ buff += bytes_written;
+ }
+ a->file_position += length;
+ return (ARCHIVE_OK);
+ }
+
+ while ((remaining > 0) || (state->avail == 0)) {
/*
* If we have a full output block, write it and reset the
* output buffer.
OpenPOWER on IntegriCloud