diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-12-11 12:39:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-12-11 12:39:26 +0000 |
commit | f4fa52d7633d9d67d4c41f76b0e317c6232eb907 (patch) | |
tree | 54f24ace52d7a9c4a1302a9762cef5b3d2537905 /lib/filesystem.h | |
parent | Save texture to TGA using mmap (diff) | |
download | ilt-f4fa52d7633d9d67d4c41f76b0e317c6232eb907.tar.bz2 ilt-f4fa52d7633d9d67d4c41f76b0e317c6232eb907.tar.xz ilt-f4fa52d7633d9d67d4c41f76b0e317c6232eb907.zip |
Add a mini C filesystem wrapper library with mmap support
Diffstat (limited to 'lib/filesystem.h')
-rw-r--r-- | lib/filesystem.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/filesystem.h b/lib/filesystem.h new file mode 100644 index 0000000..0c44236 --- /dev/null +++ b/lib/filesystem.h @@ -0,0 +1,42 @@ +#pragma once + +#include "special_members.hpp" +#include <cstddef> +#include <sys/types.h> + +namespace filesystem { + class [[nodiscard]] memmap final { + public: + memmap(size_t length, int prot, int flags, int fd, off_t offset); + ~memmap(); + NO_MOVE(memmap); + NO_COPY(memmap); + + template<typename T> + T * + get() + { + return static_cast<T *>(addr); + } + + void msync(int flags) const; + + private: + void * addr; + size_t length; + }; + + class [[nodiscard]] fh final { + public: + fh(const char * path, int flags, int mode); + ~fh(); + NO_MOVE(fh); + NO_COPY(fh); + + void truncate(size_t size); + memmap mmap(size_t length, size_t offset, int prot, int flags); + + private: + int h; + }; +} |