summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-12-14 14:30:58 +0100
committerJelle Raaijmakers <jelle@gmta.nl>2023-01-19 11:41:56 +0100
commit1ca62de558d0583eee3fa2922e062f8d65bc3b2f (patch)
tree086ed3d0503080555e5a6e17bc272bd4f633a977
parente65767c2e70b4752baeb7ba668c03effb48eb132 (diff)
downloadserenity-1ca62de558d0583eee3fa2922e062f8d65bc3b2f.zip
LibCore: Return `EBADF` on unsupported stream operations
-rw-r--r--Userland/Libraries/LibArchive/TarStream.cpp3
-rw-r--r--Userland/Libraries/LibCompress/Deflate.cpp2
-rw-r--r--Userland/Libraries/LibCompress/Gzip.cpp2
-rw-r--r--Userland/Libraries/LibCore/MemoryStream.cpp2
-rw-r--r--Userland/Libraries/LibCore/Stream.cpp6
-rw-r--r--Userland/Libraries/LibCore/Stream.h2
6 files changed, 9 insertions, 8 deletions
diff --git a/Userland/Libraries/LibArchive/TarStream.cpp b/Userland/Libraries/LibArchive/TarStream.cpp
index 7ca219f3d8..a01081c1ba 100644
--- a/Userland/Libraries/LibArchive/TarStream.cpp
+++ b/Userland/Libraries/LibArchive/TarStream.cpp
@@ -48,8 +48,7 @@ bool TarFileStream::is_eof() const
ErrorOr<size_t> TarFileStream::write(ReadonlyBytes)
{
- // This is purely for wrapping and representing file contents in an archive.
- VERIFY_NOT_REACHED();
+ return Error::from_errno(EBADF);
}
ErrorOr<NonnullOwnPtr<TarInputStream>> TarInputStream::construct(NonnullOwnPtr<Core::Stream::Stream> stream)
diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp
index 36497a7467..2d462adf44 100644
--- a/Userland/Libraries/LibCompress/Deflate.cpp
+++ b/Userland/Libraries/LibCompress/Deflate.cpp
@@ -302,7 +302,7 @@ bool DeflateDecompressor::is_eof() const { return m_state == State::Idle && m_re
ErrorOr<size_t> DeflateDecompressor::write(ReadonlyBytes)
{
- VERIFY_NOT_REACHED();
+ return Error::from_errno(EBADF);
}
bool DeflateDecompressor::is_open() const
diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp
index 502117bf23..ce856b9376 100644
--- a/Userland/Libraries/LibCompress/Gzip.cpp
+++ b/Userland/Libraries/LibCompress/Gzip.cpp
@@ -183,7 +183,7 @@ bool GzipDecompressor::is_eof() const { return m_input_stream->is_eof(); }
ErrorOr<size_t> GzipDecompressor::write(ReadonlyBytes)
{
- VERIFY_NOT_REACHED();
+ return Error::from_errno(EBADF);
}
GzipCompressor::GzipCompressor(Core::Stream::Handle<Core::Stream::Stream> stream)
diff --git a/Userland/Libraries/LibCore/MemoryStream.cpp b/Userland/Libraries/LibCore/MemoryStream.cpp
index e39603a1c6..6a7d529159 100644
--- a/Userland/Libraries/LibCore/MemoryStream.cpp
+++ b/Userland/Libraries/LibCore/MemoryStream.cpp
@@ -49,7 +49,7 @@ void FixedMemoryStream::close()
ErrorOr<void> FixedMemoryStream::truncate(off_t)
{
- return Error::from_errno(ENOTSUP);
+ return Error::from_errno(EBADF);
}
ErrorOr<Bytes> FixedMemoryStream::read(Bytes bytes)
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp
index 7a1dcb6ddd..23b26aa85b 100644
--- a/Userland/Libraries/LibCore/Stream.cpp
+++ b/Userland/Libraries/LibCore/Stream.cpp
@@ -729,7 +729,7 @@ ErrorOr<void> WrappedAKInputStream::discard(size_t discarded_bytes)
ErrorOr<size_t> WrappedAKInputStream::write(ReadonlyBytes)
{
- VERIFY_NOT_REACHED();
+ return Error::from_errno(EBADF);
}
bool WrappedAKInputStream::is_eof() const
@@ -753,7 +753,7 @@ WrappedAKOutputStream::WrappedAKOutputStream(NonnullOwnPtr<OutputStream> stream)
ErrorOr<Bytes> WrappedAKOutputStream::read(Bytes)
{
- VERIFY_NOT_REACHED();
+ return Error::from_errno(EBADF);
}
ErrorOr<size_t> WrappedAKOutputStream::write(ReadonlyBytes bytes)
@@ -768,7 +768,7 @@ ErrorOr<size_t> WrappedAKOutputStream::write(ReadonlyBytes bytes)
bool WrappedAKOutputStream::is_eof() const
{
- VERIFY_NOT_REACHED();
+ return true;
}
bool WrappedAKOutputStream::is_open() const
diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h
index 8757bf1100..44fb97e881 100644
--- a/Userland/Libraries/LibCore/Stream.h
+++ b/Userland/Libraries/LibCore/Stream.h
@@ -70,6 +70,8 @@ private:
/// The base, abstract class for stream operations. This class defines the
/// operations one can perform on every stream in LibCore.
+/// Operations without a sensible default that are unsupported by an implementation
+/// of a Stream should return EBADF as an error.
class Stream {
public:
/// Reads into a buffer, with the maximum size being the size of the buffer.