From: Tim Kientzle Date: Sun, 21 Mar 2010 16:00:28 +0000 (-0400) Subject: Finish merging the archive_read_consume and archive_read_skip implementations. X-Git-Tag: v3.0.0a~1146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d1856745d185cf3844429d507088fb2f6d8d245;p=thirdparty%2Flibarchive.git Finish merging the archive_read_consume and archive_read_skip implementations. These have always been just two different ways to advance the file pointer; merging them is a simplification. The only point remaining is to actually remove one of them and change the users. SVN-Revision: 2046 --- diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index f461fe1c6..c6f1f0e0b 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -1181,62 +1181,37 @@ __archive_read_filter_ahead(struct archive_read_filter *filter, } /* - * Move the file pointer forward. This should be called after - * __archive_read_ahead() returns data to you. Don't try to move - * ahead by more than the amount of data available according to - * __archive_read_ahead(). + * Move the file pointer forward. */ -/* - * Mark the appropriate data as used. Note that the request here will - * often be much smaller than the size of the previous read_ahead - * request. - */ -ssize_t +int64_t __archive_read_consume(struct archive_read *a, size_t request) { return (__archive_read_filter_consume(a->filter, request)); } -ssize_t -__archive_read_filter_consume(struct archive_read_filter * filter, - size_t request) -{ - if (filter->avail > 0) { - /* Read came from copy buffer. */ - filter->next += request; - filter->avail -= request; - } else { - /* Read came from client buffer. */ - filter->client_next += request; - filter->client_avail -= request; - } - filter->bytes_consumed += request; - return (request); -} - -/* - * Move the file pointer ahead by an arbitrary amount. If you're - * reading uncompressed data from a disk file, this will actually - * translate into a seek() operation. Even in cases where seek() - * isn't feasible, this at least pushes the read-and-discard loop - * down closer to the data source. - */ int64_t -__archive_read_skip(struct archive_read *a, int64_t request) +__archive_read_filter_consume(struct archive_read_filter * filter, + int64_t request) { - int64_t skipped = _archive_read_filter_skip(a->filter, request); + int64_t skipped = _archive_read_filter_skip(filter, request); if (skipped == request) return (skipped); /* We hit EOF before we satisfied the skip request. */ if (skipped < 0) // Map error code to 0 for error message below. skipped = 0; - archive_set_error(&a->archive, + archive_set_error(&filter->archive->archive, ARCHIVE_ERRNO_MISC, "Truncated input file (needed %jd bytes, only %jd available)", (intmax_t)request, (intmax_t)skipped); return (ARCHIVE_FATAL); } +int64_t +__archive_read_skip(struct archive_read *a, int64_t request) +{ + return (__archive_read_filter_consume(a->filter, request)); +} + int64_t __archive_read_skip_all(struct archive_read *a) { diff --git a/libarchive/archive_read_private.h b/libarchive/archive_read_private.h index 1d41d59fb..68873f06d 100644 --- a/libarchive/archive_read_private.h +++ b/libarchive/archive_read_private.h @@ -208,8 +208,8 @@ struct archive_read_filter_bidder const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *); const void *__archive_read_filter_ahead(struct archive_read_filter *, size_t, ssize_t *); -ssize_t __archive_read_consume(struct archive_read *, size_t); -ssize_t __archive_read_filter_consume(struct archive_read_filter *, size_t); +int64_t __archive_read_consume(struct archive_read *, size_t); +int64_t __archive_read_filter_consume(struct archive_read_filter *, int64_t); int64_t __archive_read_skip(struct archive_read *, int64_t); int64_t __archive_read_skip_all(struct archive_read *); int __archive_read_program(struct archive_read_filter *, const char *);