summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libfile.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index 6b373f05ca..1f533133c5 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -76,6 +76,31 @@ int write_full(int fd, const void *buf, size_t size)
EXPORT_SYMBOL(write_full);
/*
+ * pread_full - read to filedescriptor at offset
+ *
+ * Like pread, but this function only returns less bytes than
+ * requested when the end of file is reached.
+ */
+int pread_full(int fd, void *buf, size_t size, loff_t offset)
+{
+ size_t insize = size;
+ int now;
+
+ while (size) {
+ now = pread(fd, buf, size, offset);
+ if (now == 0)
+ break;
+ if (now < 0)
+ return now;
+ size -= now;
+ buf += now;
+ }
+
+ return insize - size;
+}
+EXPORT_SYMBOL(pread_full);
+
+/*
* read_full - read from filedescriptor
*
* Like read, but this function only returns less bytes than