diff options
Diffstat (limited to 'Userland/Utilities/env.cpp')
-rw-r--r-- | Userland/Utilities/env.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/Userland/Utilities/env.cpp b/Userland/Utilities/env.cpp index 95a17888e4..01d693f2a5 100644 --- a/Userland/Utilities/env.cpp +++ b/Userland/Utilities/env.cpp @@ -8,7 +8,6 @@ #include <LibCore/DirIterator.h> #include <LibCore/System.h> #include <LibMain/Main.h> -#include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -18,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) bool ignore_env = false; char const* split_string = nullptr; - Vector<char const*> values; + Vector<String> values; Core::ArgsParser args_parser; args_parser.set_stop_on_first_non_option(true); @@ -34,21 +33,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) size_t argv_start; for (argv_start = 0; argv_start < values.size(); ++argv_start) { - if (StringView { values[argv_start] }.contains('=')) { - putenv(const_cast<char*>(values[argv_start])); + if (values[argv_start].contains('=')) { + putenv(const_cast<char*>(values[argv_start].characters())); } else { break; } } - Vector<String> split_string_storage; - Vector<char const*> new_argv; + Vector<StringView> new_argv; if (split_string) { for (auto view : StringView(split_string).split_view(' ')) { - split_string_storage.append(view); - } - for (auto& str : split_string_storage) { - new_argv.append(str.characters()); + new_argv.append(view); } } @@ -63,12 +58,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) return 0; } - new_argv.append(nullptr); - - char const* executable = new_argv[0]; - char* const* new_argv_ptr = const_cast<char* const*>(&new_argv[0]); - - execvp(executable, new_argv_ptr); - perror("execvp"); + TRY(Core::System::exec(new_argv[0], new_argv, Core::System::SearchInPath::Yes)); return 1; } |