From 39be57424cdf4cc1bf8fb65bd53c2a9bef2be6a6 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 12 Aug 2024 19:13:27 +0300 Subject: [PATCH] Kernel: Fix SYS_SEEK with SEEK_END I was subtracting the offset from file end when I should have added it. --- kernel/kernel/OpenFileDescriptorSet.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/kernel/OpenFileDescriptorSet.cpp b/kernel/kernel/OpenFileDescriptorSet.cpp index 58b0dbf4..521b1637 100644 --- a/kernel/kernel/OpenFileDescriptorSet.cpp +++ b/kernel/kernel/OpenFileDescriptorSet.cpp @@ -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);