mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
AK: Make SeekableStream::truncate()
take a size_t
Similar to the return values earlier, a signed value doesn't really make sense here. Relying on the much more standard `size_t` makes it easier to use Stream in all contexts.
This commit is contained in:
parent
a85c18d3c4
commit
371c51f934
Notes:
sideshowbarker
2024-07-17 05:02:35 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/371c51f934 Pull-request: https://github.com/SerenityOS/serenity/pull/17248 Reviewed-by: https://github.com/ADKaster ✅
@ -295,7 +295,7 @@ public:
|
||||
|
||||
return result;
|
||||
}
|
||||
virtual ErrorOr<void> truncate(off_t length) override
|
||||
virtual ErrorOr<void> truncate(size_t length) override
|
||||
{
|
||||
return m_helper.stream().truncate(length);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ void FixedMemoryStream::close()
|
||||
// FIXME: It doesn't make sense to close a memory stream. Therefore, we don't do anything here. Is that fine?
|
||||
}
|
||||
|
||||
ErrorOr<void> FixedMemoryStream::truncate(off_t)
|
||||
ErrorOr<void> FixedMemoryStream::truncate(size_t)
|
||||
{
|
||||
return Error::from_errno(EBADF);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
virtual bool is_eof() const override;
|
||||
virtual bool is_open() const override;
|
||||
virtual void close() override;
|
||||
virtual ErrorOr<void> truncate(off_t) override;
|
||||
virtual ErrorOr<void> truncate(size_t) override;
|
||||
virtual ErrorOr<Bytes> read(Bytes bytes) override;
|
||||
|
||||
virtual ErrorOr<size_t> seek(i64 offset, SeekMode seek_mode = SeekMode::SetPosition) override;
|
||||
|
@ -120,7 +120,7 @@ public:
|
||||
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;
|
||||
virtual ErrorOr<void> truncate(size_t length) = 0;
|
||||
/// Seeks until after the given amount of bytes to be discarded instead of
|
||||
/// reading and discarding everything manually;
|
||||
virtual ErrorOr<void> discard(size_t discarded_bytes) override;
|
||||
|
@ -184,8 +184,11 @@ ErrorOr<size_t> File::seek(i64 offset, SeekMode mode)
|
||||
return seek_result;
|
||||
}
|
||||
|
||||
ErrorOr<void> File::truncate(off_t length)
|
||||
ErrorOr<void> File::truncate(size_t length)
|
||||
{
|
||||
if (length > static_cast<size_t>(NumericLimits<off_t>::max()))
|
||||
return Error::from_string_literal("Length is larger than the maximum supported length");
|
||||
|
||||
return System::ftruncate(m_fd, length);
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ public:
|
||||
virtual bool is_open() const override;
|
||||
virtual void close() override;
|
||||
virtual ErrorOr<size_t> seek(i64 offset, SeekMode) override;
|
||||
virtual ErrorOr<void> truncate(off_t length) override;
|
||||
virtual ErrorOr<void> truncate(size_t length) override;
|
||||
|
||||
int leak_fd(Badge<::IPC::File>)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user