aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/execvp.ccm
blob: 14e548e1a7eb8ca47b742008244b7bb2d3314b09 (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
// This source code is released into the public domain.
export module nihil.posix:execvp;

import nihil.std;
import nihil.core;
import nihil.error;
import nihil.monad;
import :argv;
import :execv;
import :find_in_path;
import :open_in_path;

namespace nihil {

// execvp: equivalent to execv, except the command will be searched for in $PATH.

export [[nodiscard]] auto
execvp(std::filesystem::path const &file, argv &&args) -> std::expected<execv, error>
{
	if constexpr (features::fexecve)
		co_return execv(co_await open_in_path(file), std::move(args));
	else
		co_return execv(co_await find_in_path(file), std::move(args));
}

} // namespace nihil