Browse Source

LibCore: Return `EBADF` on unsupported stream operations

Tim Schumacher 2 years ago
parent
commit
1ca62de558

+ 1 - 2
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)

+ 1 - 1
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

+ 1 - 1
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)

+ 1 - 1
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)

+ 3 - 3
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

+ 2 - 0
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.