diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-30 09:10:16 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-30 09:10:16 +0100 |
| commit | 36427c0966faa7aecd586b397ed9b845f18172f5 (patch) | |
| tree | 0d86c7ca9ac9e2e768b54d491bf596fb84f5e45a /nihil.posix/stat.ccm | |
| parent | 034cd404a129103a8dd7747e6bd00ffd5550da93 (diff) | |
| download | nihil-36427c0966faa7aecd586b397ed9b845f18172f5.tar.gz nihil-36427c0966faa7aecd586b397ed9b845f18172f5.tar.bz2 | |
more refactoring; add stat()
Diffstat (limited to 'nihil.posix/stat.ccm')
| -rw-r--r-- | nihil.posix/stat.ccm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nihil.posix/stat.ccm b/nihil.posix/stat.ccm new file mode 100644 index 0000000..6a0cabf --- /dev/null +++ b/nihil.posix/stat.ccm @@ -0,0 +1,36 @@ +// This source code is released into the public domain. +module; + +// Basic wrappers around stat() and fstat(). + +#include <expected> +#include <filesystem> + +#include <sys/stat.h> + +export module nihil.posix:stat; + +import :fd; + +namespace nihil { + +export [[nodiscard]] auto +stat(std::filesystem::path const &path) -> std::expected<struct ::stat, error> +{ + struct ::stat sb{}; + auto ret = ::stat(path.string().c_str(), &sb); + if (ret == -1) + return std::unexpected(error(std::errc(errno))); + return sb; +} + +export [[nodiscard]] auto stat(fd const &fd) -> std::expected<struct ::stat, error> +{ + struct ::stat sb{}; + auto ret = ::fstat(fd.get(), &sb); + if (ret == -1) + return std::unexpected(error(std::errc(errno))); + return sb; +} + +} // namespace nihil |
