1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-29 07:05:06 +00:00

Kernel: Don't update fd offset on read/write error

If something goes wrong with a read or write operation, we don't want
to add the error number to the fd's offset. :^)
This commit is contained in:
Andreas Kling 2019-11-04 13:57:04 +01:00
parent ecd23ce1a1
commit e8fee92357

View file

@ -106,7 +106,7 @@ off_t FileDescription::seek(off_t offset, int whence)
ssize_t FileDescription::read(u8* buffer, ssize_t count)
{
int nread = m_file->read(*this, buffer, count);
if (m_file->is_seekable())
if (nread > 0 && m_file->is_seekable())
m_current_offset += nread;
return nread;
}
@ -114,7 +114,7 @@ ssize_t FileDescription::read(u8* buffer, ssize_t count)
ssize_t FileDescription::write(const u8* data, ssize_t size)
{
int nwritten = m_file->write(*this, data, size);
if (m_file->is_seekable())
if (nwritten > 0 && m_file->is_seekable())
m_current_offset += nwritten;
return nwritten;
}