From 3bf995cdf6b65321ed02189dd76559e4fd9dd32f Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 21 Mar 2026 10:44:58 +0000 Subject: [PATCH] lib: c: io: implement lseek() --- lib/libc/include/unistd.h | 3 +++ lib/libc/io/unistd/lseek.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/libc/io/unistd/lseek.c diff --git a/lib/libc/include/unistd.h b/lib/libc/include/unistd.h index fc07165..2932824 100644 --- a/lib/libc/include/unistd.h +++ b/lib/libc/include/unistd.h @@ -2,6 +2,7 @@ #define UNISTD_H_ #include +#include extern int open(const char *path, int flags); extern int close(int fd); @@ -9,4 +10,6 @@ extern int close(int fd); extern int read(int fd, void *buf, size_t count); extern int write(int fd, const void *buf, size_t count); +extern off_t lseek(int fd, off_t offset, int whence); + #endif diff --git a/lib/libc/io/unistd/lseek.c b/lib/libc/io/unistd/lseek.c new file mode 100644 index 0000000..fcdf71e --- /dev/null +++ b/lib/libc/io/unistd/lseek.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +off_t lseek(int fd, off_t offset, int whence) +{ + int err; + off_t new_offset; + + kern_status_t status = fs_seek(fd, offset, whence, &err, &new_offset); + if (status != KERN_OK) { + return __set_errno(__errno_from_kern_status(status)); + } + + if (err != SUCCESS) { + return __set_errno(err); + } + + return new_offset; +}