mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +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:
parent
e1093c3403
commit
8ac1e6e73b
1 changed files with 2 additions and 6 deletions
|
@ -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)
|
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.
|
int rc = syscall(SC_pread, fd, buf, count, offset);
|
||||||
off_t old_offset = lseek(fd, 0, SEEK_CUR);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
lseek(fd, offset, SEEK_SET);
|
|
||||||
ssize_t nread = read(fd, buf, count);
|
|
||||||
lseek(fd, old_offset, SEEK_SET);
|
|
||||||
return nread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t write(int fd, const void* buf, size_t count)
|
ssize_t write(int fd, const void* buf, size_t count)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue