diff options
Diffstat (limited to 'nihil.posix/fexecv.ccm')
| -rw-r--r-- | nihil.posix/fexecv.ccm | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/nihil.posix/fexecv.ccm b/nihil.posix/fexecv.ccm index 1fe57a8..4001726 100644 --- a/nihil.posix/fexecv.ccm +++ b/nihil.posix/fexecv.ccm @@ -1,7 +1,4 @@ -/* - * This source code is released into the public domain. - */ - +// This source code is released into the public domain. module; #include <expected> @@ -27,27 +24,35 @@ namespace nihil { * * TODO: Should have a way to pass the environment (envp). */ -export struct fexecv final { +export struct fexecv final +{ using tag = exec_tag; - fexecv(fd &&execfd, argv &&args) noexcept; + fexecv(fd &&execfd, argv &&args) noexcept + : m_execfd(std::move(execfd)) + , m_args(std::move(args)) + { + } - [[nodiscard]] auto exec(this fexecv &self) - -> std::expected<void, error>; + [[nodiscard]] auto exec(this fexecv &self) -> std::expected<void, error> + { + ::fexecve(self.m_execfd.get(), self.m_args.data(), environ); + return std::unexpected(error("fexecve failed", error(std::errc(errno)))); + } // Movable - fexecv(fexecv &&) noexcept; - auto operator=(this fexecv &, fexecv &&) noexcept -> fexecv&; + fexecv(fexecv &&) noexcept = default; + auto operator=(this fexecv &, fexecv &&) noexcept -> fexecv & = default; // Not copyable (because we hold the open fd object) fexecv(fexecv const &) = delete; - auto operator=(this fexecv &, fexecv const &) -> fexecv& = delete; + auto operator=(this fexecv &, fexecv const &) -> fexecv & = delete; private: - fd m_execfd; - argv m_args; + fd m_execfd; + argv m_args; }; -#endif // NIHIL_HAVE_FEXECVE +#endif // NIHIL_HAVE_FEXECVE } // namespace nihil |
