summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-07 11:24:26 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-08 00:35:27 +0100
commite76b21a66fbcde92dc76ecffd688affd99834130 (patch)
tree99d99fc63c054a67af16483bb32afd26f56b2dec /Userland/Libraries/LibCore
parent801d46d02ca57df5dbc9698757c510517ce3bbf9 (diff)
downloadserenity-e76b21a66fbcde92dc76ecffd688affd99834130.zip
LibCore: Use ErrorOr<T> for Core::get_password()
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/GetPassword.cpp10
-rw-r--r--Userland/Libraries/LibCore/GetPassword.h6
2 files changed, 7 insertions, 9 deletions
diff --git a/Userland/Libraries/LibCore/GetPassword.cpp b/Userland/Libraries/LibCore/GetPassword.cpp
index ea454a6058..ac923ad681 100644
--- a/Userland/Libraries/LibCore/GetPassword.cpp
+++ b/Userland/Libraries/LibCore/GetPassword.cpp
@@ -13,19 +13,19 @@
namespace Core {
-Result<SecretString, OSError> get_password(const StringView& prompt)
+ErrorOr<SecretString> get_password(StringView prompt)
{
if (write(STDOUT_FILENO, prompt.characters_without_null_termination(), prompt.length()) < 0)
- return OSError(errno);
+ return Error::from_errno(errno);
termios original {};
if (tcgetattr(STDIN_FILENO, &original) < 0)
- return OSError(errno);
+ return Error::from_errno(errno);
termios no_echo = original;
no_echo.c_lflag &= ~ECHO;
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &no_echo) < 0)
- return OSError(errno);
+ return Error::from_errno(errno);
char* password = nullptr;
size_t n = 0;
@@ -37,7 +37,7 @@ Result<SecretString, OSError> get_password(const StringView& prompt)
putchar('\n');
if (line_length < 0)
- return OSError(saved_errno);
+ return Error::from_errno(saved_errno);
VERIFY(line_length != 0);
diff --git a/Userland/Libraries/LibCore/GetPassword.h b/Userland/Libraries/LibCore/GetPassword.h
index 6e1e17ed26..cdf703451e 100644
--- a/Userland/Libraries/LibCore/GetPassword.h
+++ b/Userland/Libraries/LibCore/GetPassword.h
@@ -6,13 +6,11 @@
#pragma once
-#include <AK/OSError.h>
-#include <AK/Result.h>
-#include <AK/String.h>
+#include <AK/Error.h>
#include <LibCore/SecretString.h>
namespace Core {
-Result<SecretString, OSError> get_password(const StringView& prompt = "Password: "sv);
+ErrorOr<SecretString> get_password(StringView prompt = "Password: "sv);
}