blob: 230665bbb9f1fae41eb73f02b27611e44b7394b5 [file] [log] [blame]
Kun Yi73380f62019-01-09 13:35:28 -08001#pragma once
2
3#include <unistd.h>
4
5namespace binstore
6{
7
8namespace 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 */
16class 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 */
31class 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 */
42extern SysImpl sys_impl;
43
44} // namespace internal
45
46} // namespace binstore