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:
Brian Gianforcaro 2021-04-21 02:11:04 -07:00 committed by Linus Groh
parent 56ba3e1cbd
commit 14f6425b8f
Notes: sideshowbarker 2024-07-18 19:18:52 +09:00
2 changed files with 21 additions and 10 deletions

View file

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

View file

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