summaryrefslogtreecommitdiff
path: root/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-10 13:48:05 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-10 16:48:43 +0100
commit70fce5c4c7279c045e593a8a3a6f79ebc28e2972 (patch)
treeb59707ab45fdc5510253c120af02bfbfb030d126 /Libraries/LibCore
parenta8681da4bf2998d8f7f00b3393bd913b5c984b42 (diff)
downloadserenity-70fce5c4c7279c045e593a8a3a6f79ebc28e2972.zip
LibCore: Use OSError in get_password() return type
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r--Libraries/LibCore/GetPassword.cpp23
-rw-r--r--Libraries/LibCore/GetPassword.h3
2 files changed, 13 insertions, 13 deletions
diff --git a/Libraries/LibCore/GetPassword.cpp b/Libraries/LibCore/GetPassword.cpp
index 028e987c59..dfcff21583 100644
--- a/Libraries/LibCore/GetPassword.cpp
+++ b/Libraries/LibCore/GetPassword.cpp
@@ -32,31 +32,31 @@
namespace Core {
-Result<String, int> get_password(const StringView& prompt)
+Result<String, OSError> get_password(const StringView& prompt)
{
- fwrite(prompt.characters_without_null_termination(), sizeof(char), prompt.length(), stdout);
- fflush(stdout);
+ if (write(STDOUT_FILENO, prompt.characters_without_null_termination(), prompt.length()) < 0)
+ return OSError(errno);
- struct termios original;
- tcgetattr(STDIN_FILENO, &original);
+ termios original {};
+ if (tcgetattr(STDIN_FILENO, &original) < 0)
+ return OSError(errno);
- struct termios no_echo = original;
+ termios no_echo = original;
no_echo.c_lflag &= ~ECHO;
- if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &no_echo) < 0) {
- return errno;
- }
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &no_echo) < 0)
+ return OSError(errno);
char* password = nullptr;
size_t n = 0;
auto line_length = getline(&password, &n, stdin);
- int saved_errno = errno;
+ auto saved_errno = errno;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &original);
putchar('\n');
if (line_length < 0)
- return saved_errno;
+ return OSError(saved_errno);
ASSERT(line_length != 0);
@@ -65,7 +65,6 @@ Result<String, int> get_password(const StringView& prompt)
String s(password);
free(password);
-
return s;
}
}
diff --git a/Libraries/LibCore/GetPassword.h b/Libraries/LibCore/GetPassword.h
index b0993c56f3..c62a071935 100644
--- a/Libraries/LibCore/GetPassword.h
+++ b/Libraries/LibCore/GetPassword.h
@@ -26,11 +26,12 @@
#pragma once
+#include <AK/OSError.h>
#include <AK/Result.h>
#include <AK/String.h>
namespace Core {
-Result<String, int> get_password(const StringView& prompt = "Password: ");
+Result<String, OSError> get_password(const StringView& prompt = "Password: ");
}