From 40b04d4da530136c29b531d7dd0c52d84dbd0057 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 7 Feb 2024 15:57:44 +0000 Subject: [PATCH] Shell: Use Core::Environment instead of manually iterating environ --- Userland/Shell/Builtin.cpp | 5 +++-- Userland/Shell/Shell.cpp | 11 +++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 74c1485e29..9d7fcb36f0 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -636,8 +637,8 @@ ErrorOr Shell::builtin_export(Main::Arguments arguments) return 1; if (vars.is_empty()) { - for (size_t i = 0; environ[i]; ++i) - puts(environ[i]); + for (auto entry : Core::Environment::entries()) + outln("{}", entry.full_entry); return 0; } diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 9b4a5f1e14..05a26e8d41 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1726,13 +1727,11 @@ Vector Shell::complete_variable(StringView name, siz } // Look at the environment. - for (auto i = 0; environ[i]; ++i) { - StringView entry { environ[i], strlen(environ[i]) }; - if (entry.starts_with(pattern)) { - auto parts = entry.split_view('='); - if (parts.is_empty() || parts.first().is_empty()) + for (auto entry : Core::Environment::entries()) { + if (entry.full_entry.starts_with(pattern)) { + if (entry.name.is_empty()) continue; - ByteString name = parts.first(); + auto name = entry.name.to_byte_string(); if (suggestions.contains_slow(name)) continue; suggestions.append(move(name));