internal: Add pread pwrite support in sys
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I84c5e7f493afbb0894528f5d0986180b7109e170
diff --git a/internal/sys.cpp b/internal/sys.cpp
index 2e040ae..db843ac 100644
--- a/internal/sys.cpp
+++ b/internal/sys.cpp
@@ -50,6 +50,17 @@
return static_cast<int>(::read(fd, buf, count));
}
+int SysImpl::pread(int fd, void* buf, std::size_t count, off_t offset) const
+{
+ return static_cast<int>(::pread(fd, buf, count, offset));
+}
+
+int SysImpl::pwrite(int fd, const void* buf, std::size_t count,
+ off_t offset) const
+{
+ return static_cast<int>(::pwrite(fd, buf, count, offset));
+}
+
int SysImpl::close(int fd) const
{
return ::close(fd);
diff --git a/internal/sys.hpp b/internal/sys.hpp
index 265d251..41fb46b 100644
--- a/internal/sys.hpp
+++ b/internal/sys.hpp
@@ -28,6 +28,10 @@
virtual int open(const char* pathname, int flags) const = 0;
virtual int read(int fd, void* buf, std::size_t count) const = 0;
+ virtual int pread(int fd, void* buf, std::size_t count,
+ off_t offset) const = 0;
+ virtual int pwrite(int fd, const void* buf, std::size_t count,
+ off_t offset) const = 0;
virtual int close(int fd) const = 0;
virtual void* mmap(void* addr, std::size_t length, int prot, int flags,
int fd, off_t offset) const = 0;
@@ -48,6 +52,10 @@
public:
int open(const char* pathname, int flags) const override;
int read(int fd, void* buf, std::size_t count) const override;
+ int pread(int fd, void* buf, std::size_t count,
+ off_t offset) const override;
+ int pwrite(int fd, const void* buf, std::size_t count,
+ off_t offset) const override;
int close(int fd) const override;
void* mmap(void* addr, std::size_t length, int prot, int flags, int fd,
off_t offset) const override;
diff --git a/tools/test/internal_sys_mock.hpp b/tools/test/internal_sys_mock.hpp
index 06aa023..ce37d91 100644
--- a/tools/test/internal_sys_mock.hpp
+++ b/tools/test/internal_sys_mock.hpp
@@ -18,6 +18,8 @@
MOCK_CONST_METHOD2(open, int(const char*, int));
MOCK_CONST_METHOD3(read, int(int, void*, std::size_t));
+ MOCK_CONST_METHOD4(pread, int(int, void*, std::size_t, off_t));
+ MOCK_CONST_METHOD4(pwrite, int(int, const void*, std::size_t, off_t));
MOCK_CONST_METHOD1(close, int(int));
MOCK_CONST_METHOD6(mmap, void*(void*, std::size_t, int, int, int, off_t));
MOCK_CONST_METHOD2(munmap, int(void*, std::size_t));