mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
LibC: Add pwrite(..) implementation to match the existing pread(..)
Add a basic non-thread safe implementation of pwrite, following the existing pread(..) design. This is needed for https://fio.readthedocs.io
This commit is contained in:
parent
56ba3e1cbd
commit
14f6425b8f
Notes:
sideshowbarker
2024-07-18 19:18:52 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/14f6425b8fd Pull-request: https://github.com/SerenityOS/serenity/pull/6527 Reviewed-by: https://github.com/gunnarbeutner Reviewed-by: https://github.com/linusg
2 changed files with 21 additions and 10 deletions
|
@ -289,12 +289,32 @@ ssize_t read(int fd, void* buf, size_t count)
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void* buf, size_t count)
|
||||
{
|
||||
int rc = syscall(SC_write, fd, buf, count);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
ssize_t pwrite(int fd, const 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 nwritten = write(fd, buf, count);
|
||||
lseek(fd, old_offset, SEEK_SET);
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
int ttyname_r(int fd, char* buffer, size_t size)
|
||||
{
|
||||
int rc = syscall(SC_ttyname, fd, buffer, size);
|
||||
|
@ -769,16 +789,6 @@ int unveil(const char* path, const char* permissions)
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
char* getpass(const char* prompt)
|
||||
{
|
||||
dbgln("FIXME: getpass('{}')", prompt);
|
||||
|
|
|
@ -101,6 +101,7 @@ int tcsetpgrp(int fd, pid_t pgid);
|
|||
ssize_t read(int fd, void* buf, size_t count);
|
||||
ssize_t pread(int fd, void* buf, size_t count, off_t);
|
||||
ssize_t write(int fd, const void* buf, size_t count);
|
||||
ssize_t pwrite(int fd, const void* buf, size_t count, off_t);
|
||||
int close(int fd);
|
||||
int chdir(const char* path);
|
||||
int fchdir(int fd);
|
||||
|
|
Loading…
Reference in a new issue