// This source code is released into the public domain. module; #include #include #include #include export module nihil.posix:execv; import nihil.error; import :argv; import :executor; namespace nihil { // execv: use a filename and an argument vector to call ::execv(). export struct execv final { using tag = exec_tag; execv(std::filesystem::path path, argv &&args) noexcept : m_path(std::move(path)) , m_args(std::move(args)) { } ~execv() = default; // Movable execv(execv &&) noexcept = default; auto operator=(execv &&) noexcept -> execv & = default; // Not copyable (because m_args isn't copyable). execv(execv const &) = delete; auto operator=(this execv &, execv const &) -> execv & = delete; // Perform the execv(). This only returns on failure. [[nodiscard]] auto exec(this execv &self) -> std::expected { ::execv(self.m_path.string().c_str(), self.m_args.data()); return std::unexpected(error("execve failed", error(std::errc(errno)))); } private: std::filesystem::path m_path; argv m_args; }; } // namespace nihil