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

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

export module nihil.posix:execvp;

import nihil.error;
import nihil.monad;
import :argv;
import :execv;
import :find_in_path;

namespace nihil {

// execvp: equivalent to execv, except the command is passed as
// a filename instead of a file descriptor.  If the filename is not
// an absolute path, it will be searched for in $PATH.
export [[nodiscard]] auto
execvp(std::string_view file, argv &&argv) -> std::expected<execv, error>
{
	auto filename = co_await find_in_path(file);
	co_return execv(std::move(filename), std::move(argv));
}

} // namespace nihil