summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/libarchive/archive_read_support_format_raw.c
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2016-06-20 17:11:11 +0000
committerjoerg <joerg@pkgsrc.org>2016-06-20 17:11:11 +0000
commitf67a2b170587775e96627a49fc615267312586d3 (patch)
tree02c059d4e8b4d0cd6c197e12c85e780cf7cfdc26 /archivers/libarchive/files/libarchive/archive_read_support_format_raw.c
parent87546b4ede6db5d7ce4cc1156faa7166273805b3 (diff)
downloadpkgsrc-f67a2b170587775e96627a49fc615267312586d3.tar.gz
Import libarchive-3.2.1:
- security fixes and other bugfixes - support for multhreading in xz 5.2+
Diffstat (limited to 'archivers/libarchive/files/libarchive/archive_read_support_format_raw.c')
-rw-r--r--archivers/libarchive/files/libarchive/archive_read_support_format_raw.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/archivers/libarchive/files/libarchive/archive_read_support_format_raw.c b/archivers/libarchive/files/libarchive/archive_read_support_format_raw.c
index 7a8481bf221..efa2c6a33c7 100644
--- a/archivers/libarchive/files/libarchive/archive_read_support_format_raw.c
+++ b/archivers/libarchive/files/libarchive/archive_read_support_format_raw.c
@@ -40,13 +40,14 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_raw.c 201107
struct raw_info {
int64_t offset; /* Current position in the file. */
+ int64_t unconsumed;
int end_of_file;
};
-static int archive_read_format_raw_bid(struct archive_read *);
+static int archive_read_format_raw_bid(struct archive_read *, int);
static int archive_read_format_raw_cleanup(struct archive_read *);
static int archive_read_format_raw_read_data(struct archive_read *,
- const void **, size_t *, off_t *);
+ const void **, size_t *, int64_t *);
static int archive_read_format_raw_read_data_skip(struct archive_read *);
static int archive_read_format_raw_read_header(struct archive_read *,
struct archive_entry *);
@@ -58,6 +59,9 @@ archive_read_support_format_raw(struct archive *_a)
struct archive_read *a = (struct archive_read *)_a;
int r;
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_read_support_format_raw");
+
info = (struct raw_info *)calloc(1, sizeof(*info));
if (info == NULL) {
archive_set_error(&a->archive, ENOMEM,
@@ -73,7 +77,10 @@ archive_read_support_format_raw(struct archive *_a)
archive_read_format_raw_read_header,
archive_read_format_raw_read_data,
archive_read_format_raw_read_data_skip,
- archive_read_format_raw_cleanup);
+ NULL,
+ archive_read_format_raw_cleanup,
+ NULL,
+ NULL);
if (r != ARCHIVE_OK)
free(info);
return (r);
@@ -87,12 +94,11 @@ archive_read_support_format_raw(struct archive *_a)
* include "raw" as part of support_format_all().
*/
static int
-archive_read_format_raw_bid(struct archive_read *a)
+archive_read_format_raw_bid(struct archive_read *a, int best_bid)
{
-
- if (__archive_read_ahead(a, 1, NULL) == NULL)
- return (-1);
- return (1);
+ if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) != NULL)
+ return (1);
+ return (-1);
}
/*
@@ -109,32 +115,40 @@ archive_read_format_raw_read_header(struct archive_read *a,
return (ARCHIVE_EOF);
a->archive.archive_format = ARCHIVE_FORMAT_RAW;
- a->archive.archive_format_name = "Raw data";
+ a->archive.archive_format_name = "raw";
archive_entry_set_pathname(entry, "data");
- /* XXX should we set mode to mimic a regular file? XXX */
+ archive_entry_set_filetype(entry, AE_IFREG);
+ archive_entry_set_perm(entry, 0644);
/* I'm deliberately leaving most fields unset here. */
return (ARCHIVE_OK);
}
static int
archive_read_format_raw_read_data(struct archive_read *a,
- const void **buff, size_t *size, off_t *offset)
+ const void **buff, size_t *size, int64_t *offset)
{
struct raw_info *info;
ssize_t avail;
info = (struct raw_info *)(a->format->data);
+
+ /* Consume the bytes we read last time. */
+ if (info->unconsumed) {
+ __archive_read_consume(a, info->unconsumed);
+ info->unconsumed = 0;
+ }
+
if (info->end_of_file)
return (ARCHIVE_EOF);
/* Get whatever bytes are immediately available. */
*buff = __archive_read_ahead(a, 1, &avail);
if (avail > 0) {
- /* Consume and return the bytes we just read */
- __archive_read_consume(a, avail);
+ /* Return the bytes we just read */
*size = avail;
*offset = info->offset;
info->offset += *size;
+ info->unconsumed = avail;
return (ARCHIVE_OK);
} else if (0 == avail) {
/* Record and return end-of-file. */
@@ -146,31 +160,22 @@ archive_read_format_raw_read_data(struct archive_read *a,
/* Record and return an error. */
*size = 0;
*offset = info->offset;
- return (avail);
+ return ((int)avail);
}
}
static int
archive_read_format_raw_read_data_skip(struct archive_read *a)
{
- struct raw_info *info;
- off_t bytes_skipped;
- int64_t request = 1024 * 1024 * 1024UL; /* Skip 1 GB at a time. */
+ struct raw_info *info = (struct raw_info *)(a->format->data);
- info = (struct raw_info *)(a->format->data);
- if (info->end_of_file)
- return (ARCHIVE_EOF);
- info->end_of_file = 1;
-
- for (;;) {
- bytes_skipped = __archive_read_skip_lenient(a, request);
- if (bytes_skipped < 0)
- return (ARCHIVE_FATAL);
- if (bytes_skipped < request)
- return (ARCHIVE_OK);
- /* We skipped all the bytes we asked for. There might
- * be more, so try again. */
+ /* Consume the bytes we read last time. */
+ if (info->unconsumed) {
+ __archive_read_consume(a, info->unconsumed);
+ info->unconsumed = 0;
}
+ info->end_of_file = 1;
+ return (ARCHIVE_OK);
}
static int