diff options
Diffstat (limited to 'nihil.posix/execv.cc')
| -rw-r--r-- | nihil.posix/execv.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/nihil.posix/execv.cc b/nihil.posix/execv.cc new file mode 100644 index 0000000..63f9698 --- /dev/null +++ b/nihil.posix/execv.cc @@ -0,0 +1,43 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <coroutine> +#include <expected> +#include <format> +#include <string> +#include <utility> + +#include <err.h> +#include <fcntl.h> +#include <unistd.h> + +extern char **environ; + +module nihil.posix; + +import nihil.error; +import nihil.monad; + +namespace nihil { + +execv::execv(std::filesystem::path path, argv &&args) noexcept + : m_path(std::move(path)) + , m_args(std::move(args)) +{ +} + +auto execv::exec(this execv &self) -> std::expected<void, error> +{ + ::execve(self.m_path.string().c_str(), self.m_args.data(), environ); + return std::unexpected(error("execve failed", error(std::errc(errno)))); +} + +execv::execv(execv &&) noexcept = default; +execv::execv(execv const &) = default; +auto execv::operator=(this execv &, execv &&) -> execv & = default; +auto execv::operator=(this execv &, execv const &) -> execv & = default; + +} // namespace nihil |
