diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-29 20:29:50 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-29 20:29:50 +0100 |
| commit | 3e7902f7d790a486d3d9cb978df193f07f3a6ad9 (patch) | |
| tree | fd9815cf214daeec1cad826e040cf8a0cbb6be33 /nihil.posix/execvp.cc | |
| parent | 67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b (diff) | |
| download | nihil-3e7902f7d790a486d3d9cb978df193f07f3a6ad9.tar.gz nihil-3e7902f7d790a486d3d9cb978df193f07f3a6ad9.tar.bz2 | |
finish macOS support
Diffstat (limited to 'nihil.posix/execvp.cc')
| -rw-r--r-- | nihil.posix/execvp.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/nihil.posix/execvp.cc b/nihil.posix/execvp.cc new file mode 100644 index 0000000..5eac315 --- /dev/null +++ b/nihil.posix/execvp.cc @@ -0,0 +1,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 |
