Luna/libs/libc/src/init.cpp

18 lines
535 B
C++
Raw Normal View History

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
extern "C" void initialize_libc()
{
close(0); // If it was already open, close it
close(1); // If it was already open, close it
errno = 0; // If it was not open. the kernel will throw us EBADF. Let's ignore that, since we don't care.
stderr = fopen("/dev/console", "rw");
if (!stderr) exit(errno);
stdout = fopen("/dev/console", "rw");
if (!stdout) exit(errno);
clearerr(stderr);
clearerr(stdout);
}