diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-01-17 14:52:46 +0100 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-01-19 11:41:56 +0100 |
commit | daf181caa8b520636d561e56d73775e53e98c78d (patch) | |
tree | 34a9a6d0a711aee9f7c2952af214c42797a3fe1d /Userland | |
parent | 1ca62de558d0583eee3fa2922e062f8d65bc3b2f (diff) | |
download | serenity-daf181caa8b520636d561e56d73775e53e98c78d.zip |
LibCore: Let offset-related Stream functions return an unsigned value
A negative return value doesn't make sense for any of those functions.
The return types were inherited from POSIX, where they also need to have
an indicator for an error (negative values).
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibCore/MemoryStream.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/MemoryStream.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/Stream.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/Stream.h | 10 |
4 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibCore/MemoryStream.cpp b/Userland/Libraries/LibCore/MemoryStream.cpp index 6a7d529159..625a1edcb9 100644 --- a/Userland/Libraries/LibCore/MemoryStream.cpp +++ b/Userland/Libraries/LibCore/MemoryStream.cpp @@ -63,7 +63,7 @@ ErrorOr<Bytes> FixedMemoryStream::read(Bytes bytes) return bytes.trim(to_read); } -ErrorOr<off_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode) +ErrorOr<size_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode) { switch (seek_mode) { case SeekMode::SetPosition: @@ -85,7 +85,7 @@ ErrorOr<off_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode) m_offset = m_bytes.size() - offset; break; } - return static_cast<off_t>(m_offset); + return m_offset; } ErrorOr<size_t> FixedMemoryStream::write(ReadonlyBytes bytes) diff --git a/Userland/Libraries/LibCore/MemoryStream.h b/Userland/Libraries/LibCore/MemoryStream.h index 590e702b59..9ae0f53b54 100644 --- a/Userland/Libraries/LibCore/MemoryStream.h +++ b/Userland/Libraries/LibCore/MemoryStream.h @@ -28,7 +28,7 @@ public: virtual ErrorOr<void> truncate(off_t) override; virtual ErrorOr<Bytes> read(Bytes bytes) override; - virtual ErrorOr<off_t> seek(i64 offset, SeekMode seek_mode = SeekMode::SetPosition) override; + virtual ErrorOr<size_t> seek(i64 offset, SeekMode seek_mode = SeekMode::SetPosition) override; virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override; virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes bytes) override; diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index 23b26aa85b..022535a6f6 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -108,14 +108,14 @@ ErrorOr<void> Stream::write_entire_buffer(ReadonlyBytes buffer) return {}; } -ErrorOr<off_t> SeekableStream::tell() const +ErrorOr<size_t> SeekableStream::tell() const { // Seek with 0 and SEEK_CUR does not modify anything despite the const_cast, // so it's safe to do this. return const_cast<SeekableStream*>(this)->seek(0, SeekMode::FromCurrentPosition); } -ErrorOr<off_t> SeekableStream::size() +ErrorOr<size_t> SeekableStream::size() { auto original_position = TRY(tell()); @@ -280,7 +280,7 @@ void File::close() m_fd = -1; } -ErrorOr<off_t> File::seek(i64 offset, SeekMode mode) +ErrorOr<size_t> File::seek(i64 offset, SeekMode mode) { int syscall_mode; switch (mode) { @@ -297,7 +297,7 @@ ErrorOr<off_t> File::seek(i64 offset, SeekMode mode) VERIFY_NOT_REACHED(); } - off_t seek_result = TRY(System::lseek(m_fd, offset, syscall_mode)); + size_t seek_result = TRY(System::lseek(m_fd, offset, syscall_mode)); m_last_read_was_eof = false; return seek_result; } diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index 44fb97e881..7e3cf6f23a 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -152,13 +152,13 @@ class SeekableStream : public Stream { public: /// Seeks to the given position in the given mode. Returns either the /// current position of the file, or an errno in the case of an error. - virtual ErrorOr<off_t> seek(i64 offset, SeekMode) = 0; + virtual ErrorOr<size_t> seek(i64 offset, SeekMode) = 0; /// Returns the current position of the file, or an errno in the case of /// an error. - virtual ErrorOr<off_t> tell() const; + virtual ErrorOr<size_t> tell() const; /// Returns the total size of the stream, or an errno in the case of an /// error. May not preserve the original position on the stream on failure. - virtual ErrorOr<off_t> size(); + virtual ErrorOr<size_t> size(); /// Shrinks or extends the stream to the given size. Returns an errno in /// the case of an error. virtual ErrorOr<void> truncate(off_t length) = 0; @@ -306,7 +306,7 @@ public: virtual bool is_eof() const override; virtual bool is_open() const override; virtual void close() override; - virtual ErrorOr<off_t> seek(i64 offset, SeekMode) override; + virtual ErrorOr<size_t> seek(i64 offset, SeekMode) override; virtual ErrorOr<void> truncate(off_t length) override; int leak_fd(Badge<::IPC::File>) @@ -871,7 +871,7 @@ public: virtual bool is_eof() const override { return m_helper.is_eof(); } virtual bool is_open() const override { return m_helper.stream().is_open(); } virtual void close() override { m_helper.stream().close(); } - virtual ErrorOr<off_t> seek(i64 offset, SeekMode mode) override + virtual ErrorOr<size_t> seek(i64 offset, SeekMode mode) override { if (mode == SeekMode::FromCurrentPosition) { // If possible, seek using the buffer alone. |