1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

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.
This commit is contained in:
Rodrigo Tobar 2021-10-12 21:15:18 +08:00 committed by Andreas Kling
parent e1093c3403
commit 8ac1e6e73b

View file

@ -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)