From 1fa8aeecce4b6ee2e5df4bc67dedd81628b6f119 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 20 May 2023 12:47:10 +0200 Subject: [PATCH] libos: Allow Process::exec to take a slice of StringViews instead of Strings as arguments --- libos/include/os/Process.h | 1 + libos/src/Process.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/libos/include/os/Process.h b/libos/include/os/Process.h index bbf038fd..0ac19de9 100644 --- a/libos/include/os/Process.h +++ b/libos/include/os/Process.h @@ -11,6 +11,7 @@ namespace os static Result fork(); static Result exec(StringView path, Slice args, bool search_in_path = true); + static Result exec(StringView path, Slice args, bool search_in_path = true); static Result exec(StringView path, Slice args, Slice env, bool search_in_path = true); }; } diff --git a/libos/src/Process.cpp b/libos/src/Process.cpp index 86d4227c..a20e4fbf 100644 --- a/libos/src/Process.cpp +++ b/libos/src/Process.cpp @@ -24,6 +24,19 @@ namespace os return err(errno); } + Result Process::exec(StringView path, Slice args, bool search_in_path) + { + Vector argv; + for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); } + TRY(argv.try_append(nullptr)); + + if (search_in_path) execvp(path.chars(), const_cast(argv.data())); + else + execv(path.chars(), const_cast(argv.data())); + + return err(errno); + } + Result Process::exec(StringView path, Slice args, Slice env, bool search_in_path) { Vector argv;