From 3e7902f7d790a486d3d9cb978df193f07f3a6ad9 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sun, 29 Jun 2025 20:29:50 +0100 Subject: finish macOS support --- nihil.posix/execvp.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 nihil.posix/execvp.cc (limited to 'nihil.posix/execvp.cc') 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 +#include +#include +#include +#include +#include + +#include +#include +#include + +#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 +{ + 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 +{ + 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 -- cgit v1.2.3