1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:37:45 +00:00

LibCore: Use LibCore syscall wrappers in get_password()

This commit is contained in:
Andreas Kling 2021-11-29 23:52:30 +01:00
parent 612eafea2c
commit 354c4690d2

View file

@ -6,6 +6,7 @@
*/ */
#include <LibCore/GetPassword.h> #include <LibCore/GetPassword.h>
#include <LibCore/System.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <termios.h> #include <termios.h>
@ -15,17 +16,13 @@ namespace Core {
ErrorOr<SecretString> get_password(StringView prompt) ErrorOr<SecretString> get_password(StringView prompt)
{ {
if (write(STDOUT_FILENO, prompt.characters_without_null_termination(), prompt.length()) < 0) TRY(Core::System::write(STDOUT_FILENO, prompt.bytes()));
return Error::from_errno(errno);
termios original {}; auto original = TRY(Core::System::tcgetattr(STDIN_FILENO));
if (tcgetattr(STDIN_FILENO, &original) < 0)
return Error::from_errno(errno);
termios no_echo = original; termios no_echo = original;
no_echo.c_lflag &= ~ECHO; no_echo.c_lflag &= ~ECHO;
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &no_echo) < 0) TRY(Core::System::tcsetattr(STDIN_FILENO, TCSAFLUSH, no_echo));
return Error::from_errno(errno);
char* password = nullptr; char* password = nullptr;
size_t n = 0; size_t n = 0;