blob: 5eac31562e643bbe399d6115cc492259d3abb3d9 (
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
48
49
50
|
/*
* 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>
#include "nihil.hh"
module nihil.posix;
import nihil.error;
import nihil.monad;
namespace nihil {
#ifdef NIHIL_HAVE_FEXECVE
auto execvp(std::string_view file, argv &&argv) -> std::expected<fexecv, error>
{
auto execfd = open_in_path(file);
if (!execfd)
return std::unexpected(error(
std::format("executable not found in path: {}", file)));
return fexecv(std::move(*execfd), std::move(argv));
}
#else // !NIHIL_HAVE_FEXECVE
auto execvp(std::string_view file, nihil::argv &&argv) -> std::expected<nihil::execv, nihil::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));
}
#endif // NIHIL_HAVE_FEXECVE
} // namespace nihil
|