From c87f9627efc8b612eb9b000acfcc6731cad15765 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 7 Oct 2025 09:12:22 +0200 Subject: Initial commit --- src/io.hh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/io.hh (limited to 'src/io.hh') diff --git a/src/io.hh b/src/io.hh new file mode 100644 index 0000000..7c21028 --- /dev/null +++ b/src/io.hh @@ -0,0 +1,51 @@ +#ifndef IO_HH +#define IO_HH + +#include +#include +#include +#include + +namespace io { + +enum class ReadError { + Error, + Eof, + InvalidData, // invalid data read (not used by raw file) + MaxTooSmall, // max argument needs to be bigger (not used by raw file) +}; + +enum class OpenError { + NoSuchFile, + NoAccess, + Error, +}; + +class Reader { + public: + virtual ~Reader() = default; + + [[nodiscard]] virtual std::expected read(void* dst, + size_t max) = 0; + [[nodiscard]] virtual std::expected skip(size_t max) = 0; + + [[nodiscard]] std::expected repeat_read(void* dst, + size_t max); + [[nodiscard]] std::expected repeat_skip(size_t max); + + protected: + Reader() = default; + + Reader(Reader const&) = delete; + Reader& operator=(Reader const&) = delete; +}; + +[[nodiscard]] std::expected, OpenError> open( + const std::string& file_path); +[[nodiscard]] std::expected, OpenError> openat( + int dirfd, const std::string& file_path); +[[nodiscard]] std::unique_ptr memory(std::string data); + +} // namespace io + +#endif // IO_HH -- cgit v1.2.3-70-g09d2