libos: Allow Process::exec to take a slice of StringViews instead of Strings as arguments
This commit is contained in:
parent
30d1dad149
commit
1fa8aeecce
@ -11,6 +11,7 @@ namespace os
|
|||||||
static Result<pid_t> fork();
|
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<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);
|
static Result<void> exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path = true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,19 @@ namespace os
|
|||||||
return err(errno);
|
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)
|
Result<void> Process::exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path)
|
||||||
{
|
{
|
||||||
Vector<const char*> argv;
|
Vector<const char*> argv;
|
||||||
|
Loading…
Reference in New Issue
Block a user