aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/fexecv.cc
blob: ad57d140a160725da0c37ffcc25e9f7ab98b2358 (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
43
44
45
46
47
/*
 * This source code is released into the public domain.
 */

module;

#include <coroutine>
#include <expected>
#include <format>
#include <string>
#include <utility>

#include <err.h>

#include "nihil.h"

#ifdef NIHIL_HAVE_FEXECVE

extern char **environ;

module nihil.posix;

import nihil.error;
import nihil.monad;

namespace nihil {

fexecv::fexecv(fd &&execfd, argv &&args) noexcept
	: m_execfd(std::move(execfd))
	, m_args(std::move(args))
{
}

auto fexecv::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))));
}

fexecv::fexecv(fexecv &&) noexcept = default;
auto fexecv::operator=(this fexecv &, fexecv &&) noexcept -> fexecv& = default;

} // namespace nihil

#endif	// NIHIL_HAVE_FEXECVE