diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index 727dcfc7aa..4ba8672cfd 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -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); diff --git a/Userland/Libraries/LibC/unistd.h b/Userland/Libraries/LibC/unistd.h index 61cb577c4b..82d9193945 100644 --- a/Userland/Libraries/LibC/unistd.h +++ b/Userland/Libraries/LibC/unistd.h @@ -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);