mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
AK: Remove Error::from_string_view_or_print_error_and_return_errno
This was for use within Serenity's kernel. In Ladybird, it is just some indirection to Error::from_string_view.
This commit is contained in:
parent
e2b863ed3f
commit
4f132b9e40
Notes:
github-actions[bot]
2025-05-11 01:21:22 +00:00
Author: https://github.com/trflynn89
Commit: 4f132b9e40
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4689
6 changed files with 13 additions and 24 deletions
|
@ -17,11 +17,6 @@
|
||||||
|
|
||||||
namespace AK {
|
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
|
#ifdef AK_OS_WINDOWS
|
||||||
Error Error::from_windows_error(u32 windows_error)
|
Error Error::from_windows_error(u32 windows_error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,12 +36,6 @@ public:
|
||||||
static Error from_windows_error();
|
static Error from_windows_error();
|
||||||
#endif
|
#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)
|
static Error from_syscall(StringView syscall_name, int rc)
|
||||||
{
|
{
|
||||||
return Error(syscall_name, rc);
|
return Error(syscall_name, rc);
|
||||||
|
|
|
@ -15,18 +15,18 @@ namespace AK {
|
||||||
ErrorOr<ByteBuffer> decode_hex(StringView input)
|
ErrorOr<ByteBuffer> decode_hex(StringView input)
|
||||||
{
|
{
|
||||||
if ((input.length() % 2) != 0)
|
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));
|
auto output = TRY(ByteBuffer::create_zeroed(input.length() / 2));
|
||||||
|
|
||||||
for (size_t i = 0; i < input.length() / 2; ++i) {
|
for (size_t i = 0; i < input.length() / 2; ++i) {
|
||||||
auto const c1 = decode_hex_digit(input[i * 2]);
|
auto const c1 = decode_hex_digit(input[i * 2]);
|
||||||
if (c1 >= 16)
|
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]);
|
auto const c2 = decode_hex_digit(input[i * 2 + 1]);
|
||||||
if (c2 >= 16)
|
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;
|
output[i] = (c1 << 4) + c2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ ErrorOr<Bytes> FixedMemoryStream::read_some(Bytes bytes)
|
||||||
ErrorOr<void> FixedMemoryStream::read_until_filled(AK::Bytes bytes)
|
ErrorOr<void> FixedMemoryStream::read_until_filled(AK::Bytes bytes)
|
||||||
{
|
{
|
||||||
if (remaining() < bytes.size())
|
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_bytes.slice(m_offset).copy_trimmed_to(bytes);
|
||||||
m_offset += bytes.size();
|
m_offset += bytes.size();
|
||||||
|
@ -71,19 +71,19 @@ ErrorOr<size_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode)
|
||||||
switch (seek_mode) {
|
switch (seek_mode) {
|
||||||
case SeekMode::SetPosition:
|
case SeekMode::SetPosition:
|
||||||
if (offset > static_cast<i64>(m_bytes.size()))
|
if (offset > static_cast<i64>(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;
|
m_offset = offset;
|
||||||
break;
|
break;
|
||||||
case SeekMode::FromCurrentPosition:
|
case SeekMode::FromCurrentPosition:
|
||||||
if (offset + static_cast<i64>(m_offset) > static_cast<i64>(m_bytes.size()))
|
if (offset + static_cast<i64>(m_offset) > static_cast<i64>(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;
|
m_offset += offset;
|
||||||
break;
|
break;
|
||||||
case SeekMode::FromEndPosition:
|
case SeekMode::FromEndPosition:
|
||||||
if (-offset > static_cast<i64>(m_bytes.size()))
|
if (-offset > static_cast<i64>(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;
|
m_offset = m_bytes.size() + offset;
|
||||||
break;
|
break;
|
||||||
|
@ -108,7 +108,7 @@ ErrorOr<size_t> FixedMemoryStream::write_some(ReadonlyBytes bytes)
|
||||||
ErrorOr<void> FixedMemoryStream::write_until_depleted(ReadonlyBytes bytes)
|
ErrorOr<void> FixedMemoryStream::write_until_depleted(ReadonlyBytes bytes)
|
||||||
{
|
{
|
||||||
if (remaining() < bytes.size())
|
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));
|
TRY(write_some(bytes));
|
||||||
return {};
|
return {};
|
||||||
|
@ -185,7 +185,7 @@ ErrorOr<void> AllocatingMemoryStream::discard(size_t count)
|
||||||
VERIFY(m_write_offset >= m_read_offset);
|
VERIFY(m_write_offset >= m_read_offset);
|
||||||
|
|
||||||
if (count > used_buffer_size())
|
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;
|
m_read_offset += count;
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
{
|
{
|
||||||
if constexpr (!IsConst<T>) {
|
if constexpr (!IsConst<T>) {
|
||||||
if (!m_writing_enabled)
|
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<T*>(m_bytes.offset_pointer(m_offset));
|
T* value = reinterpret_cast<T*>(m_bytes.offset_pointer(m_offset));
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
{
|
{
|
||||||
if constexpr (!IsConst<T>) {
|
if constexpr (!IsConst<T>) {
|
||||||
if (!m_writing_enabled)
|
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<T> span { reinterpret_cast<T*>(m_bytes.offset_pointer(m_offset)), count };
|
Span<T> span { reinterpret_cast<T*>(m_bytes.offset_pointer(m_offset)), count };
|
||||||
|
|
|
@ -17,7 +17,7 @@ ErrorOr<void> Stream::read_until_filled(Bytes buffer)
|
||||||
size_t nread = 0;
|
size_t nread = 0;
|
||||||
while (nread < buffer.size()) {
|
while (nread < buffer.size()) {
|
||||||
if (is_eof())
|
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));
|
auto result = read_some(buffer.slice(nread));
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
|
@ -70,7 +70,7 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
|
||||||
|
|
||||||
while (discarded_bytes > 0) {
|
while (discarded_bytes > 0) {
|
||||||
if (is_eof())
|
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))));
|
auto slice = TRY(read_some(buffer.span().slice(0, min(discarded_bytes, continuous_read_size))));
|
||||||
discarded_bytes -= slice.size();
|
discarded_bytes -= slice.size();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue