1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibCore: Use ErrorOr<T> for Core::get_password()

This commit is contained in:
Andreas Kling 2021-11-07 11:24:26 +01:00
parent 801d46d02c
commit e76b21a66f
3 changed files with 11 additions and 13 deletions

View file

@ -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);