diff --git a/AK/Error.cpp b/AK/Error.cpp index dcff18243e6..bd70c169ce8 100644 --- a/AK/Error.cpp +++ b/AK/Error.cpp @@ -17,11 +17,6 @@ namespace AK { -Error Error::from_string_view_or_print_error_and_return_errno(StringView string_literal, [[maybe_unused]] int code) -{ - return Error::from_string_view(string_literal); -} - #ifdef AK_OS_WINDOWS Error Error::from_windows_error(u32 windows_error) { diff --git a/AK/Error.h b/AK/Error.h index 9f34f2ea668..bc8b665c90a 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -36,12 +36,6 @@ public: static Error from_windows_error(); #endif - // NOTE: For calling this method from within kernel code, we will simply print - // the error message and return the errno code. - // For calling this method from userspace programs, we will simply return from - // the Error::from_string_view method! - static Error from_string_view_or_print_error_and_return_errno(StringView string_literal, int code); - static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); diff --git a/AK/Hex.cpp b/AK/Hex.cpp index d1f00c340a9..8d2d90b6695 100644 --- a/AK/Hex.cpp +++ b/AK/Hex.cpp @@ -15,18 +15,18 @@ namespace AK { ErrorOr decode_hex(StringView input) { if ((input.length() % 2) != 0) - return Error::from_string_view_or_print_error_and_return_errno("Hex string was not an even length"sv, EINVAL); + return Error::from_string_literal("Hex string was not an even length"); auto output = TRY(ByteBuffer::create_zeroed(input.length() / 2)); for (size_t i = 0; i < input.length() / 2; ++i) { auto const c1 = decode_hex_digit(input[i * 2]); if (c1 >= 16) - return Error::from_string_view_or_print_error_and_return_errno("Hex string contains invalid digit"sv, EINVAL); + return Error::from_string_literal("Hex string contains invalid digit"); auto const c2 = decode_hex_digit(input[i * 2 + 1]); if (c2 >= 16) - return Error::from_string_view_or_print_error_and_return_errno("Hex string contains invalid digit"sv, EINVAL); + return Error::from_string_literal("Hex string contains invalid digit"); output[i] = (c1 << 4) + c2; } diff --git a/AK/MemoryStream.cpp b/AK/MemoryStream.cpp index bbc7b19947d..6a464f1a2c8 100644 --- a/AK/MemoryStream.cpp +++ b/AK/MemoryStream.cpp @@ -58,7 +58,7 @@ ErrorOr FixedMemoryStream::read_some(Bytes bytes) ErrorOr FixedMemoryStream::read_until_filled(AK::Bytes bytes) { if (remaining() < bytes.size()) - return Error::from_string_view_or_print_error_and_return_errno("Can't read past the end of the stream memory"sv, EINVAL); + return Error::from_string_literal("Can't read past the end of the stream memory"); m_bytes.slice(m_offset).copy_trimmed_to(bytes); m_offset += bytes.size(); @@ -71,19 +71,19 @@ ErrorOr FixedMemoryStream::seek(i64 offset, SeekMode seek_mode) switch (seek_mode) { case SeekMode::SetPosition: if (offset > static_cast(m_bytes.size())) - return Error::from_string_view_or_print_error_and_return_errno("Offset past the end of the stream memory"sv, EINVAL); + return Error::from_string_literal("Offset past the end of the stream memory"); m_offset = offset; break; case SeekMode::FromCurrentPosition: if (offset + static_cast(m_offset) > static_cast(m_bytes.size())) - return Error::from_string_view_or_print_error_and_return_errno("Offset past the end of the stream memory"sv, EINVAL); + return Error::from_string_literal("Offset past the end of the stream memory"); m_offset += offset; break; case SeekMode::FromEndPosition: if (-offset > static_cast(m_bytes.size())) - return Error::from_string_view_or_print_error_and_return_errno("Offset past the start of the stream memory"sv, EINVAL); + return Error::from_string_literal("Offset past the start of the stream memory"); m_offset = m_bytes.size() + offset; break; @@ -108,7 +108,7 @@ ErrorOr FixedMemoryStream::write_some(ReadonlyBytes bytes) ErrorOr FixedMemoryStream::write_until_depleted(ReadonlyBytes bytes) { if (remaining() < bytes.size()) - return Error::from_string_view_or_print_error_and_return_errno("Write of entire buffer ends past the memory area"sv, EINVAL); + return Error::from_string_literal("Write of entire buffer ends past the memory area"); TRY(write_some(bytes)); return {}; @@ -185,7 +185,7 @@ ErrorOr AllocatingMemoryStream::discard(size_t count) VERIFY(m_write_offset >= m_read_offset); if (count > used_buffer_size()) - return Error::from_string_view_or_print_error_and_return_errno("Number of discarded bytes is higher than the number of allocated bytes"sv, EINVAL); + return Error::from_string_literal("Number of discarded bytes is higher than the number of allocated bytes"); m_read_offset += count; diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index d5ca9c8a114..fa8f9f1303f 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -50,7 +50,7 @@ public: { if constexpr (!IsConst) { if (!m_writing_enabled) - return Error::from_string_view_or_print_error_and_return_errno("Tried to obtain a non-const reference from a read-only FixedMemoryStream"sv, EINVAL); + return Error::from_string_literal("Tried to obtain a non-const reference from a read-only FixedMemoryStream"); } T* value = reinterpret_cast(m_bytes.offset_pointer(m_offset)); @@ -66,7 +66,7 @@ public: { if constexpr (!IsConst) { if (!m_writing_enabled) - return Error::from_string_view_or_print_error_and_return_errno("Tried to obtain a non-const span from a read-only FixedMemoryStream"sv, EINVAL); + return Error::from_string_literal("Tried to obtain a non-const span from a read-only FixedMemoryStream"); } Span span { reinterpret_cast(m_bytes.offset_pointer(m_offset)), count }; diff --git a/AK/Stream.cpp b/AK/Stream.cpp index 2586d4cfe8c..fc043093ad1 100644 --- a/AK/Stream.cpp +++ b/AK/Stream.cpp @@ -17,7 +17,7 @@ ErrorOr Stream::read_until_filled(Bytes buffer) size_t nread = 0; while (nread < buffer.size()) { if (is_eof()) - return Error::from_string_view_or_print_error_and_return_errno("Reached end-of-file before filling the entire buffer"sv, EIO); + return Error::from_string_literal("Reached end-of-file before filling the entire buffer"); auto result = read_some(buffer.slice(nread)); if (result.is_error()) { @@ -70,7 +70,7 @@ ErrorOr Stream::discard(size_t discarded_bytes) while (discarded_bytes > 0) { if (is_eof()) - return Error::from_string_view_or_print_error_and_return_errno("Reached end-of-file before reading all discarded bytes"sv, EIO); + return Error::from_string_literal("Reached end-of-file before reading all discarded bytes"); auto slice = TRY(read_some(buffer.span().slice(0, min(discarded_bytes, continuous_read_size)))); discarded_bytes -= slice.size();