소스 검색

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

Andreas Kling 3 년 전
부모
커밋
e76b21a66f
3개의 변경된 파일11개의 추가작업 그리고 13개의 파일을 삭제
  1. 5 5
      Userland/Libraries/LibCore/GetPassword.cpp
  2. 2 4
      Userland/Libraries/LibCore/GetPassword.h
  3. 4 4
      Userland/Utilities/test-imap.cpp

+ 5 - 5
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);
 

+ 2 - 4
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);
 
 }

+ 4 - 4
Userland/Utilities/test-imap.cpp

@@ -35,12 +35,12 @@ int main(int argc, char** argv)
     args_parser.parse(argc, argv);
 
     if (interactive_password) {
-        auto password_or_err = Core::get_password();
-        if (password_or_err.is_error()) {
-            warnln("{}", password_or_err.error().string());
+        auto password_or_error = Core::get_password();
+        if (password_or_error.is_error()) {
+            warnln("{}", password_or_error.error());
             return 1;
         }
-        password = password_or_err.release_value();
+        password = password_or_error.release_value();
     } else {
         auto standard_input = Core::File::standard_input();
         password = Core::SecretString::take_ownership(standard_input->read_all());