summaryrefslogtreecommitdiff
path: root/kernel/cpu
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-06-26 20:37:16 +0200
committerAnton Kling <anton@kling.gg>2024-06-26 20:37:16 +0200
commita7eeb66a1b3ab5f4aea31798a384d7c5b886b3e1 (patch)
tree799f1134ab2ab22eaebb832aa6be1181901b3fc3 /kernel/cpu
parent8c032568c572ad346491f78325c278b886122ec5 (diff)
Libc/Kernel: Add fcntl()
Diffstat (limited to 'kernel/cpu')
-rw-r--r--kernel/cpu/syscall.c19
1 files changed, 18 insertions, 1 deletions
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 <cpu/syscall.h>
#include <drivers/pst.h>
#include <errno.h>
+#include <fcntl.h>
#include <fs/tmpfs.h>
#include <fs/vfs.h>
#include <interrupts.h>
@@ -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);