diff options
author | Brad King <brad.king@kitware.com> | 2015-10-21 14:12:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-10-21 14:18:52 (GMT) |
commit | 932848f420a738ee07997198fead5b2c2fbf4787 (patch) | |
tree | 40404c3244ba87c5e71e8dd076f4dbcde6d8cfeb /Utilities/cmlibarchive/libarchive/archive_read_open_fd.c | |
parent | e4b7d5afde91efafb59749a0a513732a089a6f0a (diff) | |
parent | 1a8c7bc2c649781d1163c1966245a45e0fb829ba (diff) | |
download | CMake-932848f420a738ee07997198fead5b2c2fbf4787.zip CMake-932848f420a738ee07997198fead5b2c2fbf4787.tar.gz CMake-932848f420a738ee07997198fead5b2c2fbf4787.tar.bz2 |
Merge branch 'libarchive-upstream' into update-libarchive
Resolve conflicts by integrating changes from both sides.
Diffstat (limited to 'Utilities/cmlibarchive/libarchive/archive_read_open_fd.c')
-rw-r--r-- | Utilities/cmlibarchive/libarchive/archive_read_open_fd.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c index e0f95bf..f59cd07 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c @@ -59,6 +59,7 @@ struct read_fd_data { static int file_close(struct archive *, void *); static ssize_t file_read(struct archive *, void *, const void **buff); +static int64_t file_seek(struct archive *, void *, int64_t request, int); static int64_t file_skip(struct archive *, void *, int64_t request); int @@ -102,6 +103,7 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size) archive_read_set_read_callback(a, file_read); archive_read_set_skip_callback(a, file_skip); + archive_read_set_seek_callback(a, file_seek); archive_read_set_close_callback(a, file_close); archive_read_set_callback_data(a, mine); return (archive_read_open1(a)); @@ -170,6 +172,33 @@ file_skip(struct archive *a, void *client_data, int64_t request) return (-1); } +/* + * TODO: Store the offset and use it in the read callback. + */ +static int64_t +file_seek(struct archive *a, void *client_data, int64_t request, int whence) +{ + struct read_fd_data *mine = (struct read_fd_data *)client_data; + int64_t r; + + /* We use off_t here because lseek() is declared that way. */ + /* See above for notes about when off_t is less than 64 bits. */ + r = lseek(mine->fd, request, whence); + if (r >= 0) + return r; + + if (errno == ESPIPE) { + archive_set_error(a, errno, + "A file descriptor(%d) is not seekable(PIPE)", mine->fd); + return (ARCHIVE_FAILED); + } else { + /* If the input is corrupted or truncated, fail. */ + archive_set_error(a, errno, + "Error seeking in a file descriptor(%d)", mine->fd); + return (ARCHIVE_FATAL); + } +} + static int file_close(struct archive *a, void *client_data) { |