diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-11-05 05:26:30 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-11-05 05:26:30 +0000 |
commit | fef2e8cee8e209e7511da1d45f988dd029197358 (patch) | |
tree | bbc8fe472af0e8dbd66e73826de4bcb674aab1ff /lib/libarchive/archive_write_set_compression_none.c | |
parent | 0a60201e3c56d5679ba25dbcc969368ba3fb74ea (diff) | |
download | FreeBSD-src-fef2e8cee8e209e7511da1d45f988dd029197358.zip FreeBSD-src-fef2e8cee8e209e7511da1d45f988dd029197358.tar.gz |
Clean up the error handling in the
write path. In particular, this should
solve some problems people have seen with
bsdtar not exiting on various write errors.
Diffstat (limited to 'lib/libarchive/archive_write_set_compression_none.c')
-rw-r--r-- | lib/libarchive/archive_write_set_compression_none.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/libarchive/archive_write_set_compression_none.c b/lib/libarchive/archive_write_set_compression_none.c index 7a598c6..bca9d77 100644 --- a/lib/libarchive/archive_write_set_compression_none.c +++ b/lib/libarchive/archive_write_set_compression_none.c @@ -104,13 +104,13 @@ archive_compressor_none_init(struct archive *a) /* * Write data to the stream. */ -static ssize_t +static int archive_compressor_none_write(struct archive *a, const void *vbuff, size_t length) { const char *buff; ssize_t remaining, to_copy; - int ret; + ssize_t bytes_written; struct archive_none *state; state = a->compression_data; @@ -129,10 +129,12 @@ archive_compressor_none_write(struct archive *a, const void *vbuff, * output buffer. */ if (state->avail == 0) { - ret = (a->client_writer)(a, a->client_data, + bytes_written = (a->client_writer)(a, a->client_data, state->buffer, state->buffer_size); - /* XXX TODO: if ret < state->buffer_size XXX */ - a->raw_position += ret; + if (bytes_written <= 0) + return (ARCHIVE_FATAL); + /* XXX TODO: if bytes_written < state->buffer_size */ + a->raw_position += bytes_written; state->next = state->buffer; state->avail = state->buffer_size; } @@ -147,7 +149,7 @@ archive_compressor_none_write(struct archive *a, const void *vbuff, remaining -= to_copy; } a->file_position += length; - return (length); + return (ARCHIVE_OK); } @@ -159,6 +161,7 @@ archive_compressor_none_finish(struct archive *a) { ssize_t block_length; ssize_t target_block_length; + ssize_t bytes_written; int ret; int ret2; struct archive_none *state; @@ -193,9 +196,14 @@ archive_compressor_none_finish(struct archive *a) target_block_length - block_length); block_length = target_block_length; } - ret = (a->client_writer)(a, a->client_data, state->buffer, - block_length); - a->raw_position += ret; + bytes_written = (a->client_writer)(a, a->client_data, + state->buffer, block_length); + if (bytes_written <= 0) + ret = ARCHIVE_FATAL; + else { + a->raw_position += bytes_written; + ret = ARCHIVE_OK; + } } /* Close the output */ |