Kun Yi | 73380f6 | 2019-01-09 13:35:28 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <unistd.h> |
| 4 | |
| 5 | namespace binstore |
| 6 | { |
| 7 | |
| 8 | namespace internal |
| 9 | { |
| 10 | |
| 11 | /** @class Sys |
| 12 | * @brief Overridable direct syscall interface |
| 13 | * |
| 14 | * TODO: factor this out into a syscall class shared by all upstream projects |
| 15 | */ |
| 16 | class Sys |
| 17 | { |
| 18 | public: |
| 19 | virtual ~Sys() = default; |
| 20 | virtual int open(const char* pathname, int flags) const = 0; |
| 21 | virtual int close(int fd) const = 0; |
| 22 | virtual off_t lseek(int fd, off_t offset, int whence) const = 0; |
| 23 | virtual ssize_t read(int fd, void* buf, size_t count) const = 0; |
| 24 | virtual ssize_t write(int fd, const void* buf, size_t count) const = 0; |
| 25 | }; |
| 26 | |
| 27 | /** @class SysImpl |
| 28 | * @brief syscall concrete implementation |
| 29 | * @details Passes through all calls to the normal linux syscalls |
| 30 | */ |
| 31 | class SysImpl : public Sys |
| 32 | { |
| 33 | public: |
| 34 | int open(const char* pathname, int flags) const override; |
| 35 | int close(int fd) const override; |
| 36 | off_t lseek(int fd, off_t offset, int whence) const override; |
| 37 | ssize_t read(int fd, void* buf, size_t count) const override; |
| 38 | ssize_t write(int fd, const void* buf, size_t count) const override; |
| 39 | }; |
| 40 | |
| 41 | /** @brief Default instantiation of sys */ |
| 42 | extern SysImpl sys_impl; |
| 43 | |
| 44 | } // namespace internal |
| 45 | |
| 46 | } // namespace binstore |