From a7eeb66a1b3ab5f4aea31798a384d7c5b886b3e1 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 26 Jun 2024 20:37:16 +0200 Subject: Libc/Kernel: Add fcntl() --- kernel/cpu/syscall.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'kernel/cpu') diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index adbb27a..4a446d5 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,22 @@ int syscall_getpeername(int sockfd, struct sockaddr *restrict addr, return 0; } +int syscall_fcntl(int fd, int cmd, int arg) { + vfs_fd_t *fd_ptr = get_vfs_fd(fd, NULL); + if (!fd_ptr) { + return -EBADF; + } + if (F_GETFL == cmd) { + return fd_ptr->flags; + } else if (F_SETFL == cmd) { + fd_ptr->flags = arg; + return 0; + } else { + return -EINVAL; + } + return 0; +} + int (*syscall_functions[])() = { (void(*))syscall_open, (void(*))syscall_read, (void(*))syscall_write, (void(*))syscall_pread, @@ -190,7 +207,7 @@ int (*syscall_functions[])() = { (void(*))syscall_randomfill, (void(*))syscall_munmap, (void(*))syscall_open_process, (void(*))syscall_lseek, (void(*))syscall_connect, (void(*))syscall_setsockopt, - (void(*))syscall_getpeername, + (void(*))syscall_getpeername, (void(*))syscall_fcntl, }; void int_syscall(reg_t *r); -- cgit v1.2.3