summaryrefslogtreecommitdiff
path: root/Libraries/LibC/netdb.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 /Libraries/LibC/netdb.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 'Libraries/LibC/netdb.cpp')
-rw-r--r--Libraries/LibC/netdb.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/Libraries/LibC/netdb.cpp b/Libraries/LibC/netdb.cpp
index bc8aebc400..409e068da9 100644
--- a/Libraries/LibC/netdb.cpp
+++ b/Libraries/LibC/netdb.cpp
@@ -383,12 +383,11 @@ static bool fill_getserv_buffers(char* line, ssize_t read)
perror("malformed services file: port/protocol");
return false;
}
- bool conversion_checker;
- __getserv_port_buffer = port_protocol_split[0].to_int(conversion_checker);
-
- if (!conversion_checker) {
+ auto number = port_protocol_split[0].to_int();
+ if (!number.has_value())
return false;
- }
+
+ __getserv_port_buffer = number.value();
//Removing any annoying whitespace at the end of the protocol.
port_protocol_split[1].replace(" ", "", true);
@@ -571,12 +570,11 @@ static bool fill_getproto_buffers(char* line, ssize_t read)
return false;
}
- bool conversion_checker;
- __getproto_protocol_buffer = split_line[1].to_int(conversion_checker);
-
- if (!conversion_checker) {
+ auto number = split_line[1].to_int();
+ if (!number.has_value())
return false;
- }
+
+ __getproto_protocol_buffer = number.value();
__getproto_alias_list_buffer.clear();