mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03:00
env: Use Core::System::exec()
This commit is contained in:
parent
f0aba519c3
commit
f64ff945b2
Notes:
sideshowbarker
2024-07-17 12:05:11 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/f64ff945b2 Pull-request: https://github.com/SerenityOS/serenity/pull/13013 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/bgianfo
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user