diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2010-01-24 22:46:11 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2010-01-24 22:46:11 +0200 |
commit | df254ce03be016e217b511e7acd5d493f9929ca5 (patch) | |
tree | 8f4b899baead57de436606aa37b0bd139909402f /src/xz/file_io.c | |
parent | Set LC_NUMERIC=C when --robot is used. (diff) | |
download | xz-df254ce03be016e217b511e7acd5d493f9929ca5.tar.xz |
Add io_pread().
It will be used by --list.
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) { |