diff options
author | kientzle <kientzle@FreeBSD.org> | 2006-11-15 05:14:20 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2006-11-15 05:14:20 +0000 |
commit | 8c58f2d4e886683f06f5018c49ab1c29b9a64302 (patch) | |
tree | 26d9c2a2e2f3ef0e43a46c1ba47b7fb7dad859f4 /lib/libarchive/archive_write_set_format_shar.c | |
parent | 0cea6ebe6fec73e12ddd70734e98196884ed7fa9 (diff) | |
download | FreeBSD-src-8c58f2d4e886683f06f5018c49ab1c29b9a64302.zip FreeBSD-src-8c58f2d4e886683f06f5018c49ab1c29b9a64302.tar.gz |
Change the internal API for writing data to an entry; make the
internal format-specific functions return the same as the public
function, so that the public API layer doesn't have to guess the
correct return value. This addresses an obscure problem that occurs
when someone tries to write more data than the size of the entry (as
indicated in the entry header). In this case, the return value from
archive_write_data() was incorrect, reflecting the requested write
rather than the amount actually written.
MFC after: 15 days
Diffstat (limited to 'lib/libarchive/archive_write_set_format_shar.c')
-rw-r--r-- | lib/libarchive/archive_write_set_format_shar.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libarchive/archive_write_set_format_shar.c b/lib/libarchive/archive_write_set_format_shar.c index fd451e3..88b1384 100644 --- a/lib/libarchive/archive_write_set_format_shar.c +++ b/lib/libarchive/archive_write_set_format_shar.c @@ -64,9 +64,9 @@ struct shar { static int archive_write_shar_finish(struct archive *); static int archive_write_shar_header(struct archive *, struct archive_entry *); -static int archive_write_shar_data_sed(struct archive *, +static ssize_t archive_write_shar_data_sed(struct archive *, const void * buff, size_t); -static int archive_write_shar_data_uuencode(struct archive *, +static ssize_t archive_write_shar_data_uuencode(struct archive *, const void * buff, size_t); static int archive_write_shar_finish_entry(struct archive *); static int shar_printf(struct archive *, const char *fmt, ...); @@ -323,12 +323,13 @@ archive_write_shar_header(struct archive *a, struct archive_entry *entry) } /* XXX TODO: This could be more efficient XXX */ -static int +static ssize_t archive_write_shar_data_sed(struct archive *a, const void *buff, size_t n) { struct shar *shar; const char *src; int ret; + int written = n; shar = (struct shar *)a->format_data; if (!shar->has_data) @@ -357,7 +358,9 @@ archive_write_shar_data_sed(struct archive *a, const void *buff, size_t n) if (shar->outpos > 0) ret = (a->compression_write)(a, shar->outbuff, shar->outpos); - return (ret); + if (ret != ARCHIVE_OK) + return (ret); + return (written); } #define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`') @@ -384,7 +387,7 @@ uuencode_group(struct shar *shar) shar->outbuff[shar->outpos] = 0; } -static int +static ssize_t archive_write_shar_data_uuencode(struct archive *a, const void *buff, size_t length) { @@ -413,7 +416,7 @@ archive_write_shar_data_uuencode(struct archive *a, const void *buff, shar->uubuffer[shar->uuavail++] = *src++; shar->outbytes++; } - return (ARCHIVE_OK); + return (length); } static int |