aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/execvp.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-07-01 17:07:04 +0100
committerLexi Winter <lexi@le-fay.org>2025-07-01 17:07:04 +0100
commit2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 (patch)
tree54d37ffadf8e677938d9b7a28e4e9b71be1e75c1 /nihil.posix/execvp.ccm
parent36427c0966faa7aecd586b397ed9b845f18172f5 (diff)
downloadnihil-2e2d1bd3b6c7776b77c33b94f30ead89367a71e6.tar.gz
nihil-2e2d1bd3b6c7776b77c33b94f30ead89367a71e6.tar.bz2
add nihil.std
Diffstat (limited to 'nihil.posix/execvp.ccm')
-rw-r--r--nihil.posix/execvp.ccm23
1 files changed, 10 insertions, 13 deletions
diff --git a/nihil.posix/execvp.ccm b/nihil.posix/execvp.ccm
index 270e311..14e548e 100644
--- a/nihil.posix/execvp.ccm
+++ b/nihil.posix/execvp.ccm
@@ -1,29 +1,26 @@
// 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.std;
+import nihil.core;
import nihil.error;
import nihil.monad;
import :argv;
import :execv;
import :find_in_path;
+import :open_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.
+// execvp: equivalent to execv, except the command will be searched for in $PATH.
+
export [[nodiscard]] auto
-execvp(std::string_view file, argv &&argv) -> std::expected<execv, error>
+execvp(std::filesystem::path const &file, argv &&args) -> std::expected<execv, error>
{
- auto filename = co_await find_in_path(file);
- co_return execv(std::move(filename), std::move(argv));
+ if constexpr (features::fexecve)
+ co_return execv(co_await open_in_path(file), std::move(args));
+ else
+ co_return execv(co_await find_in_path(file), std::move(args));
}
} // namespace nihil