diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-22 16:00:53 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-22 19:28:31 +0100 |
commit | 4e530135d554adf4e3edfafc580585b07b3b07ce (patch) | |
tree | 97e7827229074dfdaac70680e2cd7f394189f6db /AK | |
parent | d3cf68a5407a756e79a5b2f97303b855b7253e86 (diff) | |
download | serenity-4e530135d554adf4e3edfafc580585b07b3b07ce.zip |
AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failures
This creates an error that contains the name of the syscall that failed.
This allows error handlers to print out the name of the call if they
want to. :^)
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Error.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/AK/Error.h b/AK/Error.h index 1346cb02d9..b25e8348ee 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -21,9 +21,11 @@ namespace AK { class Error { public: static Error from_errno(int code) { return Error(code); } + static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); } static Error from_string_literal(StringView string_literal) { return Error(string_literal); } bool is_errno() const { return m_code != 0; } + bool is_syscall() const { return m_syscall; } int code() const { return m_code; } StringView string_literal() const { return m_string_literal; } @@ -40,8 +42,16 @@ private: { } + Error(StringView syscall_name, int rc) + : m_code(-rc) + , m_string_literal(syscall_name) + , m_syscall(true) + { + } + int m_code { 0 }; StringView m_string_literal; + bool m_syscall { false }; }; template<typename T, typename ErrorType> |