mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:58:14 +00:00
LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in StringViews and might have a non-properly-null-terminated string as a value. As a bonus, using StringView (and DeprecatedString where necessary) leads to nicer looking code too :^)
This commit is contained in:
parent
60908adcbe
commit
500044906d
43 changed files with 122 additions and 145 deletions
|
@ -45,8 +45,8 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
bool single_shot = false;
|
||||
char const* omit_pid_value = nullptr;
|
||||
char const* process_name = nullptr;
|
||||
StringView omit_pid_value;
|
||||
StringView process_name;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(single_shot, "Only return one pid", nullptr, 's');
|
||||
|
@ -56,11 +56,11 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
args_parser.parse(args);
|
||||
|
||||
pid_t pid_to_omit = 0;
|
||||
if (omit_pid_value) {
|
||||
if (!strcmp(omit_pid_value, "%PPID")) {
|
||||
if (!omit_pid_value.is_empty()) {
|
||||
if (omit_pid_value == "%PPID"sv) {
|
||||
pid_to_omit = getppid();
|
||||
} else {
|
||||
auto number = StringView { omit_pid_value, strlen(omit_pid_value) }.to_uint();
|
||||
auto number = omit_pid_value.to_uint();
|
||||
if (!number.has_value()) {
|
||||
warnln("Invalid value for -o");
|
||||
args_parser.print_usage(stderr, args.strings[0]);
|
||||
|
@ -69,5 +69,5 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
pid_to_omit = number.value();
|
||||
}
|
||||
}
|
||||
return pid_of(process_name, single_shot, omit_pid_value != nullptr, pid_to_omit);
|
||||
return pid_of(process_name, single_shot, !omit_pid_value.is_empty(), pid_to_omit);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue