diff options
author | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2014-08-03 14:51:15 +0900 |
---|---|---|
committer | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2014-08-03 14:56:40 +0900 |
commit | c0dd6ae5c5369384c14fcc1486886d8463c98909 (patch) | |
tree | 3e2bdd597aac3b9b86c6e989267f757235a85c81 /libarchive/archive_read_open_fd.c | |
parent | dabd6eb78d1553a87bccc361f691fbc48e22e905 (diff) | |
download | libarchive-c0dd6ae5c5369384c14fcc1486886d8463c98909.tar.gz |
Fix issue336:7zip can not be read when opened with archive_read_open_fd.
Implenent a seek callback in archive_read_open_fd by bringin the code
from archive_open_filename.
Diffstat (limited to 'libarchive/archive_read_open_fd.c')
-rw-r--r-- | libarchive/archive_read_open_fd.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libarchive/archive_read_open_fd.c b/libarchive/archive_read_open_fd.c index e0f95bf4..f59cd07f 100644 --- a/libarchive/archive_read_open_fd.c +++ b/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) { |