Luna/libs/libc/src/stdio.cpp

25 lines
693 B
C++
Raw Normal View History

2022-10-08 10:42:25 +00:00
#include <errno.h>
#include <luna.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C"
{
int puts(const char* s)
{
long nwritten = fwrite(s, strlen(s), 1, stdout);
if (nwritten < 0) return -1;
nwritten += fwrite("\n", 1, 1, stdout);
2022-10-07 16:19:06 +00:00
return (int)nwritten;
}
2022-10-08 10:42:25 +00:00
void perror(const char* s) // FIXME: Print to stderr, whenever we have an stderr.
{
int savederr =
errno; // This was necessary before, but even more now since we clear errno on successful syscalls now.
2022-10-08 10:42:25 +00:00
if (s && *s) { printf("%s: ", s); }
printf("%s\n", strerror(savederr));
2022-10-08 10:42:25 +00:00
}
}