Add PReadAll/PWriteAll for filedescriptor ptr
the newly added functions will read/write to a specified offset without
modifying file offset.
Test: treehugger
Change-Id: If0e7e3f2b9d2371838c3a7f27fe4250400ba3133
diff --git a/common/utils.h b/common/utils.h
index 0762796..616de06 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -70,6 +70,14 @@
size_t count,
off_t off);
+// https://man7.org/linux/man-pages/man2/pread.2.html
+// PWriteAll writes data at specified offset, but it DOES NOT modify file
+// position. Behaves similar to linux' pwrite syscall.
+bool PWriteAll(const FileDescriptorPtr& fd,
+ const void* buf,
+ size_t count,
+ off_t offset);
+
// Calls read() repeatedly until |count| bytes are read or EOF or EWOULDBLOCK
// is reached. Returns whether all read() calls succeeded (including EWOULDBLOCK
// as a success case), sets |eof| to whether the eof was reached and sets
@@ -90,6 +98,15 @@
off_t offset,
ssize_t* out_bytes_read);
+// https://man7.org/linux/man-pages/man2/pread.2.html
+// Reads data at specified offset, this function DOES NOT change file position.
+// Behavior is similar to linux's pread syscall.
+bool PReadAll(const FileDescriptorPtr& fd,
+ void* buf,
+ size_t count,
+ off_t offset,
+ ssize_t* out_bytes_read);
+
// Opens |path| for reading and appends its entire content to the container
// pointed to by |out_p|. Returns true upon successfully reading all of the
// file's content, false otherwise, in which case the state of the output