From 2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Tue, 1 Jul 2025 17:07:04 +0100 Subject: add nihil.std --- nihil.posix/fd.ccm | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'nihil.posix/fd.ccm') diff --git a/nihil.posix/fd.ccm b/nihil.posix/fd.ccm index 7faf2f1..8210b6d 100644 --- a/nihil.posix/fd.ccm +++ b/nihil.posix/fd.ccm @@ -1,24 +1,23 @@ // This source code is released into the public domain. module; -#include -#include -#include -#include -#include -#include - #include #include export module nihil.posix:fd; +import nihil.std; import nihil.flagset; import nihil.error; import nihil.monad; namespace nihil { +// Useful constants +export inline int constexpr stdin_fileno = STDIN_FILENO; +export inline int constexpr stdout_fileno = STDOUT_FILENO; +export inline int constexpr stderr_fileno = STDERR_FILENO; + // F_{GET,SET}FL flags struct fd_flags_tag { @@ -96,7 +95,7 @@ export struct fd final if (ret == 0) return {}; - return std::unexpected(error(std::errc(errno))); + return std::unexpected(error(sys_error())); } // Return the stored fd. @@ -124,7 +123,7 @@ export struct fd final if (ret >= 0) return ret; - return std::unexpected(error(std::errc(errno))); + return std::unexpected(error(sys_error())); } // Read data from the fd to the provided buffer. Returns a @@ -136,7 +135,7 @@ export struct fd final if (ret >= 0) return buffer.subspan(0, ret); - return std::unexpected(error(std::errc(errno))); + return std::unexpected(error(sys_error())); } private: @@ -152,7 +151,7 @@ export [[nodiscard]] auto dup(fd const &self) -> std::expected if (newfd != -1) return fd(newfd); - return std::unexpected(error(std::errc(errno))); + return std::unexpected(error(sys_error())); } // Create a copy of this fd by calling dup2(). Note that because this results @@ -170,7 +169,7 @@ export [[nodiscard]] auto dup(fd const &self, int newfd) -> std::expected std::expected if (newfd != -1) return newfd; - return std::unexpected(error(std::errc(errno))); + return std::unexpected(error(sys_error())); } // Create a copy of this fd by calling dup2(). @@ -190,7 +189,7 @@ export [[nodiscard]] auto raw_dup(fd const &self, int newfd) -> std::expected std::expected, error> auto fds = std::array{}; if (auto const ret = ::pipe(fds.data()); ret != 0) - return std::unexpected(error(std::errc(errno))); + return std::unexpected(error(sys_error())); return {{fd(fds[0]), fd(fds[1])}}; } -- cgit v1.2.3