From cd495786a88575742b343f4c63697945f7a7679b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 Feb 2020 06:59:23 +0100 Subject: [PATCH] LibC: Implement crappy version of pread() This patch adds a crappy pread() just to get "git" working locally. A proper version would be implemented in the kernel so that we don't have to mess with the file descriptor's offset at all. --- Libraries/LibC/unistd.cpp | 10 ++++++++++ Libraries/LibC/unistd.h | 1 + 2 files changed, 11 insertions(+) diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 4e14cb223e..1f76d4494f 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -702,6 +702,16 @@ 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) { dbg() << "FIXME: getpass(\"" << prompt << "\")"; diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index d0f1610a7b..cb3cde7965 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -99,6 +99,7 @@ int setgid(gid_t); pid_t tcgetpgrp(int fd); 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); int close(int fd); int chdir(const char* path);