From 332b253a476ea5a6801230ca8b9fc220764a7cb3 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 10 Feb 2023 11:42:54 +0100 Subject: [PATCH] AK: Provide `is_errno` for Kernel Errors It wouldn't make much sense on its own (as the Kernel only has errno Errors), but it's an easy fix for not having to ifdef away every single usage of `is_errno` in code that is shared between Userland and Kernel. --- AK/Error.h | 2 +- AK/Stream.cpp | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/AK/Error.h b/AK/Error.h index 302de1cf3c7..02eccaf5ca0 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -76,11 +76,11 @@ public: } int code() const { return m_code; } -#ifndef KERNEL bool is_errno() const { return m_code != 0; } +#ifndef KERNEL bool is_syscall() const { return m_syscall; diff --git a/AK/Stream.cpp b/AK/Stream.cpp index 2b0ae90da2c..c47afe3dbf6 100644 --- a/AK/Stream.cpp +++ b/AK/Stream.cpp @@ -20,15 +20,10 @@ ErrorOr Stream::read_entire_buffer(Bytes buffer) auto result = read(buffer.slice(nread)); if (result.is_error()) { -#ifdef KERNEL - if (result.error().code() == EINTR) { - continue; - } -#else if (result.error().is_errno() && result.error().code() == EINTR) { continue; } -#endif + return result.release_error(); } @@ -89,15 +84,10 @@ ErrorOr Stream::write_entire_buffer(ReadonlyBytes buffer) while (nwritten < buffer.size()) { auto result = write(buffer.slice(nwritten)); if (result.is_error()) { -#ifdef KERNEL - if (result.error().code() == EINTR) { - continue; - } -#else if (result.error().is_errno() && result.error().code() == EINTR) { continue; } -#endif + return result.release_error(); }