libos: Allow Process::exec to take a slice of StringViews instead of Strings as arguments

This commit is contained in:
apio 2023-05-20 12:47:10 +02:00
parent 30d1dad149
commit 1fa8aeecce
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 14 additions and 0 deletions

View File

@ -11,6 +11,7 @@ namespace os
static Result<pid_t> fork();
static Result<void> exec(StringView path, Slice<String> args, bool search_in_path = true);
static Result<void> exec(StringView path, Slice<StringView> args, bool search_in_path = true);
static Result<void> exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path = true);
};
}

View File

@ -24,6 +24,19 @@ namespace os
return err(errno);
}
Result<void> Process::exec(StringView path, Slice<StringView> args, bool search_in_path)
{
Vector<const char*> 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<char**>(argv.data()));
else
execv(path.chars(), const_cast<char**>(argv.data()));
return err(errno);
}
Result<void> Process::exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path)
{
Vector<const char*> argv;