aboutsummaryrefslogtreecommitdiff
path: root/src/xz/file_io.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2017-04-05 18:47:22 +0300
committerLasse Collin <lasse.collin@tukaani.org>2017-04-05 18:47:22 +0300
commitc28f0b3d00af87b92dda229831548d8eb0067d1d (patch)
treeab2aa7f93c98a2ad9a5dfcdd705cbb061bf00ce2 /src/xz/file_io.c
parentxz: Use POSIX_FADV_RANDOM for in "xz --list" mode. (diff)
downloadxz-c28f0b3d00af87b92dda229831548d8eb0067d1d.tar.xz
xz: Add io_seek_src().
Diffstat (limited to 'src/xz/file_io.c')
-rw-r--r--src/xz/file_io.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/xz/file_io.c b/src/xz/file_io.c
index 041bed88..48ef8223 100644
--- a/src/xz/file_io.c
+++ b/src/xz/file_io.c
@@ -1169,16 +1169,30 @@ 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)
+io_seek_src(file_pair *pair, off_t pos)
{
- // Using lseek() and read() is more portable than pread() and
- // for us it is as good as real pread().
+ assert(pos >= 0);
+
if (lseek(pair->src_fd, pos, SEEK_SET) != pos) {
message_error(_("%s: Error seeking the file: %s"),
pair->src_name, strerror(errno));
return true;
}
+ pair->src_eof = false;
+
+ return false;
+}
+
+
+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 (io_seek_src(pair, pos))
+ return true;
+
const size_t amount = io_read(pair, buf, size);
if (amount == SIZE_MAX)
return true;