diff options
author | Anton Kling <anton@kling.gg> | 2023-11-24 21:47:02 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-24 21:47:02 +0100 |
commit | 4764846cc2afe0e56f4490e3973b7322c2129e29 (patch) | |
tree | 64aa0b7df0f5422a6c52f0b67f4b9a9158bfa8da /kernel/syscalls | |
parent | 08b63b747f9a6b4d1460195f6ca68680abcdd656 (diff) |
Refactor write() and pwrite()
Diffstat (limited to 'kernel/syscalls')
-rw-r--r-- | kernel/syscalls/pwrite.c | 6 | ||||
-rw-r--r-- | kernel/syscalls/write.c | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/kernel/syscalls/pwrite.c b/kernel/syscalls/pwrite.c new file mode 100644 index 0000000..b1e47fe --- /dev/null +++ b/kernel/syscalls/pwrite.c @@ -0,0 +1,6 @@ +#include <fs/vfs.h> +#include <syscalls.h> + +int syscall_pwrite(int fd, const char *buf, size_t count, size_t offset) { + return vfs_pwrite(fd, (char*)buf, count, offset); +} diff --git a/kernel/syscalls/write.c b/kernel/syscalls/write.c new file mode 100644 index 0000000..bdd3927 --- /dev/null +++ b/kernel/syscalls/write.c @@ -0,0 +1,12 @@ +#include <fs/vfs.h> +#include <syscalls.h> +#include <errno.h> + +int syscall_write(int fd, const char *buf, size_t count) { + vfs_fd_t *fd_ptr = get_vfs_fd(fd); + if (!fd_ptr) + return -EBADF; + int rc = vfs_pwrite(fd, (char *)buf, count, fd_ptr->offset); + fd_ptr->offset += rc; + return rc; +} |