From b67011c6263b50d73ebca570480d618df8b3de3c Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 11 Oct 2022 21:12:19 +0200 Subject: [PATCH] libc: Use the new write() syscall The new one is write(fd, buf, count). The old one was write(buf, count). So the old one tries to pass buf as a file descriptor, and write() complains that 4000000 is too large of a file descriptor and throws EBADF. We now use the new syscall, through the wrapper that fwrite() provides us. --- libs/libc/src/luna.cpp | 3 ++- libs/libc/src/stdio.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/libc/src/luna.cpp b/libs/libc/src/luna.cpp index eee9f2ae..7d031cdb 100644 --- a/libs/libc/src/luna.cpp +++ b/libs/libc/src/luna.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -20,7 +21,7 @@ extern "C" noreturn void __luna_abort(const char* message) { - syscall(SYS_write, message, strlen(message)); + fwrite(message, strlen(message), 1, stdout); abort(); } } \ No newline at end of file diff --git a/libs/libc/src/stdio.cpp b/libs/libc/src/stdio.cpp index c19aff27..c7604a98 100644 --- a/libs/libc/src/stdio.cpp +++ b/libs/libc/src/stdio.cpp @@ -10,9 +10,9 @@ extern "C" { int puts(const char* s) { - long nwritten = syscall(SYS_write, s, strlen(s)); + long nwritten = fwrite(s, strlen(s), 1, stdout); if (nwritten < 0) return -1; - nwritten += syscall(SYS_write, "\n", 1); + nwritten += fwrite("\n", 1, 1, stdout); return (int)nwritten; } void perror(const char* s) // FIXME: Print to stderr, whenever we have an stderr.