1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +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:
Andreas Kling 2020-09-06 16:09:26 +02:00
parent 9dafbc82ff
commit 35b844ba4c
2 changed files with 12 additions and 0 deletions

View file

@ -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);