blob: 680a13e4b4fb61613d8202fe8e26ce8b04d1a6fb (
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
|
// This source code is released into the public domain.
module;
#include <string>
#include <expected>
#include <format>
export module nihil.posix:execvp;
import nihil.error;
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 = nihil::find_in_path(file);
if (!filename)
return std::unexpected(nihil::error(
std::format("executable not found in path: {}", file)));
return execv(std::move(*filename), std::move(argv));
}
} // namespace nihil
|