From b9f5f92bff69059471a76e73539780eedb356455 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 25 Dec 2023 19:08:04 +0100 Subject: kernel: _sys_getnull() (basically /dev/null) --- src/libc/socket.c | 9 +++++++-- src/libc/syscall.c | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/libc') diff --git a/src/libc/socket.c b/src/libc/socket.c index a8871a3..5ea7266 100644 --- a/src/libc/socket.c +++ b/src/libc/socket.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -10,8 +11,12 @@ int socket(int domain, int type, int protocol) { if (domain != AF_INET || type != SOCK_STREAM || protocol != IPPROTO_TCP) { return errno = ENOSYS, -1; } - // TODO! /dev/null - return dup(1); // yolo + int h = _sys_getnull(0); + if (h < 0) { + return errno = -h, -1; + } else { + return h; + } } int bind(int, const struct sockaddr *, socklen_t) { diff --git a/src/libc/syscall.c b/src/libc/syscall.c index 8142028..f44c775 100644 --- a/src/libc/syscall.c +++ b/src/libc/syscall.c @@ -94,6 +94,10 @@ uint64_t _sys_time(int flags) { return (uint64_t)_syscall(_SYS_TIME, (long)flags, 0, 0, 0, 0); } +hid_t _sys_getnull(int flags) { + return (hid_t)_syscall(_SYS_GETNULL, (long)flags, 0, 0, 0, 0); +} + long _sys_execbuf(void __user *buf, size_t len) { return _syscall(_SYS_EXECBUF, (long)buf, (long)len, 0, 0, 0); } -- cgit v1.2.3