mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore: Add Core::IODevice::truncate()
This is just a wrapper around ftruncate(). Today I also learned that ftruncate() does not reset the file descriptor offset. :^)
This commit is contained in:
parent
9dafbc82ff
commit
35b844ba4c
Notes:
sideshowbarker
2024-07-19 02:53:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/35b844ba4c8
2 changed files with 12 additions and 0 deletions
|
@ -266,6 +266,16 @@ bool IODevice::seek(i64 offset, SeekMode mode, off_t* pos)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool IODevice::truncate(off_t size)
|
||||
{
|
||||
int rc = ftruncate(m_fd, size);
|
||||
if (rc < 0) {
|
||||
set_error(errno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IODevice::write(const u8* data, int size)
|
||||
{
|
||||
int rc = ::write(m_fd, data, size);
|
||||
|
|
|
@ -65,6 +65,8 @@ public:
|
|||
bool write(const u8*, int size);
|
||||
bool write(const StringView&);
|
||||
|
||||
bool truncate(off_t);
|
||||
|
||||
bool can_read_line() const;
|
||||
|
||||
bool can_read() const;
|
||||
|
|
Loading…
Reference in a new issue