Rename PReadAll/PWriteAll for file descriptor ptr to ReadAll/WriteAll
Utils.cc contain 2 implementation of PReadAll: 1 for unix fd, and 1 for
FileDescriptorPtr. However, the implementation for unix fd calls pread
syscall under the hood, which does not change file offset. The
implementation for FileDescriptorPtr DOES change file offset, making
code inconsistent. For now we rename inconsistent functions to
ReadAll/WriteAll. The next CL adds PReadAll/PWriteAll implementation for
FileDescriptorPtr.
Test: treehugger
Change-Id: I2781b294f0f8e866275e1649e9b45d565d4cd5b8
diff --git a/common/utils.h b/common/utils.h
index 05a92be..0762796 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -18,6 +18,7 @@
#define UPDATE_ENGINE_COMMON_UTILS_H_
#include <errno.h>
+#include <sys/types.h>
#include <time.h>
#include <unistd.h>
@@ -63,10 +64,11 @@
bool PWriteAll(int fd, const void* buf, size_t count, off_t offset);
bool WriteAll(const FileDescriptorPtr& fd, const void* buf, size_t count);
-bool PWriteAll(const FileDescriptorPtr& fd,
- const void* buf,
- size_t count,
- off_t offset);
+// WriteAll writes data at specified offset, but it modifies file position.
+bool WriteAll(const FileDescriptorPtr& fd,
+ const void* buf,
+ size_t count,
+ off_t off);
// Calls read() repeatedly until |count| bytes are read or EOF or EWOULDBLOCK
// is reached. Returns whether all read() calls succeeded (including EWOULDBLOCK
@@ -81,11 +83,12 @@
bool PReadAll(
int fd, void* buf, size_t count, off_t offset, ssize_t* out_bytes_read);
-bool PReadAll(const FileDescriptorPtr& fd,
- void* buf,
- size_t count,
- off_t offset,
- ssize_t* out_bytes_read);
+// Reads data at specified offset, this function does change file position.
+bool ReadAll(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