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.
This commit is contained in:
apio 2022-10-11 21:12:19 +02:00
parent 0f47f59364
commit b67011c626
2 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include <luna.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
@ -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();
}
}

View File

@ -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.