diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-04-02 16:48:43 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-11 21:09:42 +0200 |
commit | f64ff945b2600bf50f9e63720101d6ed2f66b117 (patch) | |
tree | 42f0c53d13c95f45bc96a74eeb2721472f50a064 /Userland/Utilities | |
parent | f0aba519c33058f1ddbb0a63fe2a9c1efe646ac9 (diff) | |
download | serenity-f64ff945b2600bf50f9e63720101d6ed2f66b117.zip |
env: Use Core::System::exec()
Diffstat (limited to 'Userland/Utilities')
-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; } |