diff options
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r-- | Userland/Libraries/LibCore/Stream.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/Stream.h | 18 |
2 files changed, 14 insertions, 14 deletions
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index 0f1f3b5371..303c0e5a8f 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -164,7 +164,7 @@ ErrorOr<size_t> File::read(Bytes buffer) // NOTE: POSIX says that if the fd is not open for reading, the call // will return EBADF. Since we already know whether we can or // can't read the file, let's avoid a syscall. - return EBADF; + return Error::from_errno(EBADF); } ssize_t rc = ::read(m_fd, buffer.data(), buffer.size()); @@ -180,7 +180,7 @@ ErrorOr<size_t> File::write(ReadonlyBytes buffer) { if (!has_flag(m_mode, OpenMode::Write)) { // NOTE: Same deal as Read. - return EBADF; + return Error::from_errno(EBADF); } ssize_t rc = ::write(m_fd, buffer.data(), buffer.size()); @@ -343,7 +343,7 @@ ErrorOr<void> Socket::connect_inet(int fd, SocketAddress const& address) ErrorOr<size_t> PosixSocketHelper::read(Bytes buffer) { if (!is_open()) { - return ENOTCONN; + return Error::from_errno(ENOTCONN); } ssize_t rc = ::recv(m_fd, buffer.data(), buffer.size(), 0); @@ -364,7 +364,7 @@ ErrorOr<size_t> PosixSocketHelper::read(Bytes buffer) ErrorOr<size_t> PosixSocketHelper::write(ReadonlyBytes buffer) { if (!is_open()) { - return ENOTCONN; + return Error::from_errno(ENOTCONN); } ssize_t rc = ::send(m_fd, buffer.data(), buffer.size(), 0); @@ -483,7 +483,7 @@ ErrorOr<NonnullOwnPtr<TCPSocket>> TCPSocket::adopt_fd(int fd) ErrorOr<size_t> PosixSocketHelper::pending_bytes() const { if (!is_open()) { - return ENOTCONN; + return Error::from_errno(ENOTCONN); } int value; diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index af409537b1..d940760da6 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -340,7 +340,7 @@ public: // datagram to be discarded. That's not very nice, so let's bail // early, telling the caller that he should allocate a bigger // buffer. - return EMSGSIZE; + return Error::from_errno(EMSGSIZE); } return m_helper.read(buffer); @@ -469,13 +469,13 @@ public: static ErrorOr<NonnullOwnPtr<BufferedType<T>>> create_buffered(NonnullOwnPtr<T> stream, size_t buffer_size) { if (!buffer_size) - return EINVAL; + return Error::from_errno(EINVAL); if (!stream->is_open()) - return ENOTCONN; + return Error::from_errno(ENOTCONN); auto maybe_buffer = ByteBuffer::create_uninitialized(buffer_size); if (!maybe_buffer.has_value()) - return ENOMEM; + return Error::from_errno(ENOMEM); return adopt_nonnull_own_or_enomem(new BufferedType<T>(move(stream), maybe_buffer.release_value())); } @@ -486,9 +486,9 @@ public: ErrorOr<size_t> read(Bytes buffer) { if (!stream().is_open()) - return ENOTCONN; + return Error::from_errno(ENOTCONN); if (!buffer.size()) - return ENOBUFS; + return Error::from_errno(ENOBUFS); // Let's try to take all we can from the buffer first. size_t buffer_nread = 0; @@ -536,10 +536,10 @@ public: ErrorOr<size_t> read_until_any_of(Bytes buffer, Array<StringView, N> candidates) { if (!stream().is_open()) - return ENOTCONN; + return Error::from_errno(ENOTCONN); if (buffer.is_empty()) - return ENOBUFS; + return Error::from_errno(ENOBUFS); // We fill the buffer through can_read_line. if (!TRY(can_read_line())) @@ -557,7 +557,7 @@ public: // violating the invariant twice the next time the user attempts // to read, which is No Good. So let's give a descriptive error // to the caller about why it can't read. - return EMSGSIZE; + return Error::from_errno(EMSGSIZE); } m_buffer.span().slice(0, m_buffered_size).copy_to(buffer); |