From 8ac1e6e73babefc19fa2138dd8e4238984272958 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Tue, 12 Oct 2021 21:15:18 +0800 Subject: [PATCH] LibC: Use the new pread syscall to implement pread This new implementation of pread saves two lseek system calls and is thread-safe thanks to it simply forwarding the call to the pread system call. --- Userland/Libraries/LibC/unistd.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index e0af881505..88d28f759d 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -296,12 +296,8 @@ ssize_t read(int fd, void* buf, size_t count) ssize_t pread(int fd, void* buf, size_t count, off_t offset) { - // FIXME: This is not thread safe and should be implemented in the kernel instead. - off_t old_offset = lseek(fd, 0, SEEK_CUR); - lseek(fd, offset, SEEK_SET); - ssize_t nread = read(fd, buf, count); - lseek(fd, old_offset, SEEK_SET); - return nread; + int rc = syscall(SC_pread, fd, buf, count, offset); + __RETURN_WITH_ERRNO(rc, rc, -1); } ssize_t write(int fd, const void* buf, size_t count)