summaryrefslogtreecommitdiff
path: root/cat
diff options
context:
space:
mode:
authorSebastian Freundt <freundt@ga-group.nl>2014-08-12 14:55:28 +0000
committerSebastian Freundt <freundt@ga-group.nl>2014-08-13 07:05:12 +0000
commit96e57afe1fdbbfeea586b733e0c57a5c8a0ad7c9 (patch)
treeeb8c9960b336ad1f045043f16a9bad49da974e44 /cat
parent850c3c8d37900827244891e62febf77136c42bcb (diff)
downloadlibarchive-96e57afe1fdbbfeea586b733e0c57a5c8a0ad7c9.tar.gz
Allow empty files (after filters) in bsdcat command.
This changeset fixes an issue with empty compressed files, i.e. files that after inflating are of size 0: bsdcat would report unrecognized archive format for those because the raw reader is unable to handle files of zero length.
Diffstat (limited to 'cat')
-rw-r--r--cat/bsdcat.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/cat/bsdcat.c b/cat/bsdcat.c
index 3ffd99ab..8756a8b8 100644
--- a/cat/bsdcat.c
+++ b/cat/bsdcat.c
@@ -62,6 +62,7 @@ bsdcat_next()
{
a = archive_read_new();
archive_read_support_filter_all(a);
+ archive_read_support_format_empty(a);
archive_read_support_format_raw(a);
}
@@ -76,10 +77,20 @@ bsdcat_print_error(void)
void
bsdcat_read_to_stdout(char* filename)
{
- if ((archive_read_open_filename(a, filename, BYTES_PER_BLOCK) != ARCHIVE_OK)
- || (archive_read_next_header(a, &ae) != ARCHIVE_OK)
- || (archive_read_data_into_fd(a, 1) != ARCHIVE_OK))
+ int r;
+
+ if (archive_read_open_filename(a, filename, BYTES_PER_BLOCK) != ARCHIVE_OK)
+ goto err;
+ else if (r = archive_read_next_header(a, &ae),
+ r != ARCHIVE_OK && r != ARCHIVE_EOF)
+ goto err;
+ else if (r == ARCHIVE_EOF)
+ /* for empty payloads don't try and read data */
+ ;
+ else if (archive_read_data_into_fd(a, 1) != ARCHIVE_OK) {
+ err:
bsdcat_print_error();
+ }
if (archive_read_free(a) != ARCHIVE_OK)
bsdcat_print_error();
}