Skip to content
Browse files

Give formats/filters way to know data amount requested from archive_r…

…ead_data().
  • Loading branch information...
1 parent c2a8c82 commit a16da62ba7771eebd3807e18513195d0f0607d8d @amejia1 amejia1 committed Jan 25, 2013
Showing with 16 additions and 0 deletions.
  1. +6 −0 libarchive/archive_read.c
  2. +8 −0 libarchive/archive_read_private.h
  3. +2 −0 libarchive/archive_read_support_format_rar.c
View
6 libarchive/archive_read.c
@@ -660,6 +660,8 @@ _archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
a->read_data_output_offset = 0;
a->read_data_remaining = 0;
+ a->read_data_is_posix_read = 0;
+ a->read_data_requested = 0;
a->data_start_node = a->client.cursor;
/* EOF always wins; otherwise return the worst error. */
return (r2 < r1 || r2 == ARCHIVE_EOF) ? r2 : r1;
@@ -771,6 +773,8 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
while (s > 0) {
if (a->read_data_remaining == 0) {
read_buf = a->read_data_block;
+ a->read_data_is_posix_read = 1;
+ a->read_data_requested = s;
r = _archive_read_data_block(&a->archive, &read_buf,
&a->read_data_remaining, &a->read_data_offset);
a->read_data_block = read_buf;
@@ -824,6 +828,8 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
bytes_read += len;
}
}
+ a->read_data_is_posix_read = 0;
+ a->read_data_requested = 0;
return (bytes_read);
}
View
8 libarchive/archive_read_private.h
@@ -161,6 +161,14 @@ struct archive_read {
int64_t read_data_output_offset;
size_t read_data_remaining;
+ /*
+ * Used by formats/filters to determine the amount of data
+ * requested from a call to archive_read_data(). This is only
+ * useful when the format/filter has seek support.
+ */
+ char read_data_is_posix_read;
+ size_t read_data_requested;
+
/* Callbacks to open/read/write/close client archive streams. */
struct archive_read_client client;
View
2 libarchive/archive_read_support_format_rar.c
@@ -2796,6 +2796,8 @@ rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail)
int ret;
if (avail)
{
+ if (a->read_data_is_posix_read && *avail > (ssize_t)a->read_data_requested)
+ *avail = a->read_data_requested;
if (*avail > rar->bytes_remaining)
*avail = (ssize_t)rar->bytes_remaining;
if (*avail < 0)

0 comments on commit a16da62

Please sign in to comment.
Something went wrong with that request. Please try again.