mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
LibCore: Use ErrorOr<T> for Core::get_password()
This commit is contained in:
parent
801d46d02c
commit
e76b21a66f
3 changed files with 11 additions and 13 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue