diff options
Diffstat (limited to '')
-rw-r--r-- | src/xz/file_io.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/xz/file_io.c b/src/xz/file_io.c index d94e2321..a07501c1 100644 --- a/src/xz/file_io.c +++ b/src/xz/file_io.c @@ -812,6 +812,31 @@ io_read(file_pair *pair, io_buf *buf_union, size_t size) } +extern bool +io_pread(file_pair *pair, io_buf *buf, size_t size, off_t pos) +{ + // Using lseek() and read() is more portable than pread() and + // for us it is as good as real pread(). + if (lseek(pair->src_fd, pos, SEEK_SET) != pos) { + message_error(_("%s: Error seeking the file: %s"), + pair->src_name, strerror(errno)); + return true; + } + + const size_t amount = io_read(pair, buf, size); + if (amount == SIZE_MAX) + return true; + + if (amount != size) { + message_error(_("%s: Unexpected end of file"), + pair->src_name); + return true; + } + + return false; +} + + static bool is_sparse(const io_buf *buf) { |