summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authoritskarudo <itskarudo@protonmail.com>2022-02-12 11:08:44 +0100
committerTim Flynn <trflynn89@pm.me>2022-02-12 10:53:07 -0500
commit16aeb8b51da818b2e31c41f7f5aa171f5ccdc0af (patch)
tree36e6ec873d1eb9c70532171528aa10a5b3c698c6 /Userland
parent500098c76d62682d0d3b19774d62feba7f0a1d89 (diff)
downloadserenity-16aeb8b51da818b2e31c41f7f5aa171f5ccdc0af.zip
kill: Parse CLI arguments using Arguments.strings
The previous implementation used argv and LibC to parse arguments, it now uses the Arguments.strings interface to do so.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/kill.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/Userland/Utilities/kill.cpp b/Userland/Utilities/kill.cpp
index ab31f4b2b4..194e43b922 100644
--- a/Userland/Utilities/kill.cpp
+++ b/Userland/Utilities/kill.cpp
@@ -12,7 +12,6 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
static void print_usage_and_exit()
@@ -27,9 +26,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio proc"));
int argc = arguments.argc;
- char** argv = arguments.argv;
+ auto strings = arguments.strings;
- if (argc == 2 && !strcmp(argv[1], "-l")) {
+ if (argc == 2 && strings[1] == "-l") {
for (size_t i = 0; i < NSIG; ++i) {
if (i && !(i % 5))
outln("");
@@ -45,29 +44,29 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
int pid_argi = 1;
if (argc == 3) {
pid_argi = 2;
- if (argv[1][0] != '-')
+ if (strings[1][0] != '-')
print_usage_and_exit();
Optional<unsigned> number;
- if (isalpha(argv[1][1])) {
- int value = getsignalbyname(&argv[1][1]);
+ if (isalpha(strings[1][1])) {
+ int value = getsignalbyname(&strings[1][1]);
if (value >= 0 && value < NSIG)
number = value;
}
if (!number.has_value())
- number = StringView(&argv[1][1]).to_uint();
+ number = strings[1].substring_view(1, 1).to_uint();
if (!number.has_value()) {
- warnln("'{}' is not a valid signal name or number", &argv[1][1]);
+ warnln("'{}' is not a valid signal name or number", &strings[1][1]);
return 2;
}
signum = number.value();
}
- auto pid_opt = String(argv[pid_argi]).to_int();
+ auto pid_opt = strings[pid_argi].to_int();
if (!pid_opt.has_value()) {
- warnln("'{}' is not a valid PID", argv[pid_argi]);
+ warnln("'{}' is not a valid PID", strings[pid_argi]);
return 3;
}
pid_t pid = pid_opt.value();