diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-12 21:07:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-12 21:28:55 +0200 |
commit | fdfda6dec20101013bb33633e657f06ef2a1ea96 (patch) | |
tree | 2157f8281cd9bc33a6984455c4831c397d2bd30c /Libraries/LibC/pwd.cpp | |
parent | 15f4043a7a80f52c0fa05c4e69771e758464cd20 (diff) | |
download | serenity-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 'Libraries/LibC/pwd.cpp')
-rw-r--r-- | Libraries/LibC/pwd.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Libraries/LibC/pwd.cpp b/Libraries/LibC/pwd.cpp index 520a5fc8f5..1d32197b77 100644 --- a/Libraries/LibC/pwd.cpp +++ b/Libraries/LibC/pwd.cpp @@ -128,19 +128,18 @@ next_entry: auto& e_gecos = parts[4]; auto& e_dir = parts[5]; auto& e_shell = parts[6]; - bool ok; - uid_t e_uid = e_uid_string.to_uint(ok); - if (!ok) { + auto e_uid = e_uid_string.to_uint(); + if (!e_uid.has_value()) { fprintf(stderr, "getpwent(): Malformed UID on line %u\n", __pwdb_line_number); goto next_entry; } - gid_t e_gid = e_gid_string.to_uint(ok); - if (!ok) { + auto e_gid = e_gid_string.to_uint(); + if (!e_gid.has_value()) { fprintf(stderr, "getpwent(): Malformed GID on line %u\n", __pwdb_line_number); goto next_entry; } - __pwdb_entry->pw_uid = e_uid; - __pwdb_entry->pw_gid = e_gid; + __pwdb_entry->pw_uid = e_uid.value(); + __pwdb_entry->pw_gid = e_gid.value(); __pwdb_entry->pw_name = __pwdb_entry->name_buffer; __pwdb_entry->pw_passwd = __pwdb_entry->passwd_buffer; __pwdb_entry->pw_gecos = __pwdb_entry->gecos_buffer; |