summaryrefslogtreecommitdiff
path: root/Userland/chown.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-12 21:07:52 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-12 21:28:55 +0200
commitfdfda6dec20101013bb33633e657f06ef2a1ea96 (patch)
tree2157f8281cd9bc33a6984455c4831c397d2bd30c /Userland/chown.cpp
parent15f4043a7a80f52c0fa05c4e69771e758464cd20 (diff)
downloadserenity-fdfda6dec20101013bb33633e657f06ef2a1ea96.zip
AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature: - int StringType::to_int(bool& ok) const And replace it with sensible new signature: - Optional<int> StringType::to_int() const
Diffstat (limited to 'Userland/chown.cpp')
-rw-r--r--Userland/chown.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/Userland/chown.cpp b/Userland/chown.cpp
index a7ea33dbc5..54809aecd5 100644
--- a/Userland/chown.cpp
+++ b/Userland/chown.cpp
@@ -54,9 +54,10 @@ int main(int argc, char** argv)
return 1;
}
- bool ok;
- new_uid = parts[0].to_uint(ok);
- if (!ok) {
+ auto number = parts[0].to_uint();
+ if (number.has_value()) {
+ new_uid = number.value();
+ } else {
auto* passwd = getpwnam(parts[0].characters());
if (!passwd) {
fprintf(stderr, "Unknown user '%s'\n", parts[0].characters());
@@ -66,8 +67,10 @@ int main(int argc, char** argv)
}
if (parts.size() == 2) {
- new_gid = parts[1].to_uint(ok);
- if (!ok) {
+ auto number = parts[1].to_uint();
+ if (number.has_value()) {
+ new_gid = number.value();
+ } else {
auto* group = getgrnam(parts[1].characters());
if (!new_gid) {
fprintf(stderr, "Unknown group '%s'\n", parts[1].characters());