aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/execv.cc
blob: 752a96d810bf268d065084d88d953be554ce2df8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * This source code is released into the public domain.
 */

module;

#include <coroutine>
#include <expected>
#include <filesystem>
#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;
auto execv::operator=(this execv &, execv &&) noexcept -> execv & = default;

} // namespace nihil