Luna/libs/libc/src/stdio.cpp

77 lines
1.5 KiB
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)
{
int nwritten = fputs(s, stdout);
if (nwritten < 0) return -1;
if (putchar('\n') < 0) return -1;
return nwritten + 1;
}
2022-10-22 10:21:04 +00:00
int fputs(const char* s, FILE* stream)
{
int result = (int)fwrite(s, strlen(s), 1, stream);
if (ferror(stream)) return -1;
return result;
}
2022-10-22 10:21:04 +00:00
int fputc(int c, FILE* stream)
{
char chr = (char)c;
fwrite(&chr, 1, 1, stream);
if (ferror(stream)) { return -1; }
return c;
}
2022-10-22 10:21:04 +00:00
int putc(int c, FILE* stream)
{
return fputc(c, stream);
}
2022-10-22 10:21:04 +00:00
int putchar(int c)
{
return fputc(c, stdout);
}
2022-10-22 10:21:04 +00:00
2022-10-11 19:13:38 +00:00
void perror(const char* s)
2022-10-08 10:42:25 +00:00
{
int savederr =
errno; // This was necessary before, but even more now since we clear errno on successful syscalls now.
2022-10-11 19:13:38 +00:00
if (s && *s) { fprintf(stderr, "%s: ", s); }
fprintf(stderr, "%s\n", strerror(savederr));
2022-10-08 10:42:25 +00:00
}
2022-10-22 10:21:04 +00:00
2022-10-22 10:20:05 +00:00
int remove(const char*)
{
NOT_IMPLEMENTED("remove");
}
2022-10-23 09:16:36 +00:00
int sscanf(const char*, const char*, ...)
{
NOT_IMPLEMENTED("sscanf");
}
int fscanf(FILE*, const char*, ...)
{
NOT_IMPLEMENTED("fscanf");
}
2022-11-03 15:52:41 +00:00
int rename(const char*, const char*)
{
NOT_IMPLEMENTED("rename");
}
FILE* tmpfile()
{
errno = ENOTSUP;
return NULL;
}
}