Kernel: Fix SYS_SEEK with SEEK_END

I was subtracting the offset from file end when I should have added it.
This commit is contained in:
Bananymous 2024-08-12 19:13:27 +03:00
parent 45ffa1b79c
commit 39be57424c
1 changed files with 7 additions and 7 deletions

View File

@ -217,23 +217,23 @@ namespace Kernel
{
TRY(validate_fd(fd));
off_t new_offset = 0;
off_t base_offset;
switch (whence)
{
case SEEK_SET:
base_offset = 0;
break;
case SEEK_CUR:
new_offset = m_open_files[fd]->offset + offset;
base_offset = m_open_files[fd]->offset;
break;
case SEEK_END:
new_offset = m_open_files[fd]->inode->size() - offset;
break;
case SEEK_SET:
new_offset = offset;
base_offset = m_open_files[fd]->inode->size();
break;
default:
return BAN::Error::from_errno(EINVAL);
}
const off_t new_offset = base_offset + offset;
if (new_offset < 0)
return BAN::Error::from_errno(EINVAL);