Skip to content

Commit

Permalink
ar: handle partial writes from archive_write_data
Browse files Browse the repository at this point in the history
libarchive may limit a single archive_write_data call to handling
0x7fffffff bytes. Add a loop to handle partial writes.

Reviewed by:	kib, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D11715
  • Loading branch information
emaste committed Jul 24, 2017
1 parent dcbe705 commit 3f71a0c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions usr.bin/ar/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,17 @@ prefault_buffer(const char *buf, size_t s)
static void
write_data(struct bsdar *bsdar, struct archive *a, const void *buf, size_t s)
{
ssize_t written;

prefault_buffer(buf, s);
if (archive_write_data(a, buf, s) != (ssize_t)s)
bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s",
archive_error_string(a));
while (s > 0) {
written = archive_write_data(a, buf, s);
if (written < 0)
bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s",
archive_error_string(a));
buf = (const char *)buf + written;
s -= written;
}
}

/*
Expand Down

0 comments on commit 3f71a0c

Please sign in to comment.