diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-20 23:11:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-20 23:20:02 +0100 |
commit | 19d3f8cab77a95b284e30f142521c6b483221324 (patch) | |
tree | 8df3f585e91113215b52d10a9a0032c9998dc1b5 /Kernel/KResult.h | |
parent | e279b45aed5509efc537fc8c831f40733d7b1028 (diff) | |
download | serenity-19d3f8cab77a95b284e30f142521c6b483221324.zip |
Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode.
This means that kernel functions that return those types can finally
do "return EINVAL;" and it will just work.
There's a handful of functions that still deal with signed integers
that should be converted to return KResults.
Diffstat (limited to 'Kernel/KResult.h')
-rw-r--r-- | Kernel/KResult.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Kernel/KResult.h b/Kernel/KResult.h index 2629b25551..48e348b9fa 100644 --- a/Kernel/KResult.h +++ b/Kernel/KResult.h @@ -27,6 +27,8 @@ #pragma once #include <AK/Assertions.h> +#include <AK/Platform.h> +#include <AK/StdLibExtras.h> #include <LibC/errno_numbers.h> namespace Kernel { @@ -37,10 +39,9 @@ enum KSuccessTag { class [[nodiscard]] KResult { public: - ALWAYS_INLINE explicit KResult(int negative_e) - : m_error(negative_e) + KResult(ErrnoCode error) + : m_error(-error) { - ASSERT(negative_e <= 0); } KResult(KSuccessTag) : m_error(0) @@ -69,6 +70,12 @@ public: { } + KResultOr(ErrnoCode error) + : m_error(error) + , m_is_error(true) + { + } + ALWAYS_INLINE KResultOr(T&& value) { new (&m_storage) T(move(value)); |