mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
pls: Don't rely on getenv
to find TERM
This allows us to skip storing the actual backing data in a separate `Vector`, as we know that we are working with `environ`-backed storage here. Also, while the logic is currently very similar to what `getenv` does internally, this allows us to eventually implement custom environment variable filters while remaining linear in run time.
This commit is contained in:
parent
00df1c9532
commit
38677f63c6
1 changed files with 11 additions and 4 deletions
|
@ -45,11 +45,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
TRY(Core::System::pledge("stdio rpath exec"));
|
||||
|
||||
Vector<String> exec_environment_strings;
|
||||
Vector<StringView> exec_environment;
|
||||
if (auto* term = getenv("TERM")) {
|
||||
exec_environment_strings.append(String::formatted("TERM={}", term));
|
||||
exec_environment.append(exec_environment_strings.last());
|
||||
for (size_t i = 0; environ[i]; ++i) {
|
||||
StringView env_view { environ[i] };
|
||||
auto maybe_needle = env_view.find('=');
|
||||
|
||||
if (!maybe_needle.has_value())
|
||||
continue;
|
||||
|
||||
if (env_view.substring_view(0, maybe_needle.value()) != "TERM"sv)
|
||||
continue;
|
||||
|
||||
exec_environment.append(env_view);
|
||||
}
|
||||
|
||||
Vector<String> exec_arguments;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue