summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2010-02-06 20:41:25 +0000
committerkientzle <kientzle@FreeBSD.org>2010-02-06 20:41:25 +0000
commit418133299a436bd57451b522e1f9e62a7b322588 (patch)
tree91faae742ef289f0373e3ecb20a3cd5ed79d2568 /usr.bin/tar
parent6b176158d359046a101257872776bcfa38c2270f (diff)
downloadFreeBSD-src-418133299a436bd57451b522e1f9e62a7b322588.zip
FreeBSD-src-418133299a436bd57451b522e1f9e62a7b322588.tar.gz
Fill in some missing error handling, be a little more careful about
error reporting, prefer int64_t to off_t.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/read.c2
-rw-r--r--usr.bin/tar/write.c33
2 files changed, 18 insertions, 17 deletions
diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c
index 16334d1..def0953 100644
--- a/usr.bin/tar/read.c
+++ b/usr.bin/tar/read.c
@@ -154,7 +154,7 @@ read_archive(struct bsdtar *bsdtar, char mode)
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
if (archive_read_open_file(a, bsdtar->filename,
bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
DEFAULT_BYTES_PER_BLOCK))
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index 2ac519f..864bfd1 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -215,9 +215,9 @@ tar_mode_c(struct bsdtar *bsdtar)
}
if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar);
}
@@ -228,7 +228,7 @@ tar_mode_c(struct bsdtar *bsdtar)
void
tar_mode_r(struct bsdtar *bsdtar)
{
- off_t end_offset;
+ int64_t end_offset;
int format;
struct archive *a;
struct archive_entry *entry;
@@ -302,11 +302,12 @@ tar_mode_r(struct bsdtar *bsdtar)
format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
archive_write_set_format(a, format);
}
- lseek(bsdtar->fd, end_offset, SEEK_SET); /* XXX check return val XXX */
+ if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
+ bsdtar_errc(1, errno, "Could not seek to archive end");
if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar); /* XXX check return val XXX */
@@ -317,7 +318,7 @@ tar_mode_r(struct bsdtar *bsdtar)
void
tar_mode_u(struct bsdtar *bsdtar)
{
- off_t end_offset;
+ int64_t end_offset;
struct archive *a;
struct archive_entry *entry;
int format;
@@ -384,12 +385,12 @@ tar_mode_u(struct bsdtar *bsdtar)
bsdtar->bytes_per_block);
} else
archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
- lseek(bsdtar->fd, end_offset, SEEK_SET);
- ftruncate(bsdtar->fd, end_offset);
+ if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
+ bsdtar_errc(1, errno, "Could not seek to archive end");
if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
- bsdtar_errc(1, 0, archive_error_string(a));
+ bsdtar_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar);
@@ -438,7 +439,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
bsdtar->argv++;
arg = *bsdtar->argv;
if (arg == NULL) {
- bsdtar_warnc(1, 0,
+ bsdtar_warnc(0, "%s",
"Missing argument for -C");
bsdtar->return_value = 1;
goto cleanup;
@@ -558,7 +559,7 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
rc = append_archive(bsdtar, a, ina);
- if (archive_errno(ina)) {
+ if (rc != ARCHIVE_OK) {
bsdtar_warnc(0, "Error reading archive %s: %s",
filename, archive_error_string(ina));
bsdtar->return_value = 1;
@@ -623,7 +624,7 @@ copy_file_data(struct bsdtar *bsdtar, struct archive *a,
{
ssize_t bytes_read;
ssize_t bytes_written;
- off_t progress = 0;
+ int64_t progress = 0;
bytes_read = archive_read_data(ina, bsdtar->buff, FILEDATABUFLEN);
while (bytes_read > 0) {
@@ -771,7 +772,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
entry, -1, st);
if (r != ARCHIVE_OK)
bsdtar_warnc(archive_errno(bsdtar->diskreader),
- archive_error_string(bsdtar->diskreader));
+ "%s", archive_error_string(bsdtar->diskreader));
if (r < ARCHIVE_WARN)
continue;
@@ -935,7 +936,7 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a,
{
ssize_t bytes_read;
ssize_t bytes_written;
- off_t progress = 0;
+ int64_t progress = 0;
bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
while (bytes_read > 0) {
OpenPOWER on IntegriCloud