summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorRodrigo Tobar <rtobarc@gmail.com>2021-10-12 21:15:18 +0800
committerAndreas Kling <kling@serenityos.org>2021-10-13 16:10:50 +0200
commit8ac1e6e73babefc19fa2138dd8e4238984272958 (patch)
tree40f56c7ddff61ac79a88a8d1ca59b668d604e425 /Userland/Libraries/LibC
parente1093c3403dd86475dbe73c1f1ecd028de563898 (diff)
downloadserenity-8ac1e6e73babefc19fa2138dd8e4238984272958.zip
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.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/unistd.cpp8
1 files 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)