From 2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Tue, 1 Jul 2025 17:07:04 +0100 Subject: add nihil.std --- nihil.posix/execvp.ccm | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'nihil.posix/execvp.ccm') 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 -#include -#include -#include - 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 +execvp(std::filesystem::path const &file, argv &&args) -> std::expected { - 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 -- cgit v1.2.3