Luna/libs/libc/src/init.cpp

27 lines
621 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()
{
if (lseek(0, 0, SEEK_CUR) < 0)
{
if (errno == EBADF) stdout = fopen("/dev/console", "rw");
else
exit(errno);
if (!stdout) exit(errno);
errno = 0;
}
else { stdout = fdopen(0, "rw"); }
if (lseek(1, 0, SEEK_CUR) < 0)
{
if (errno == EBADF) stderr = fopen("/dev/console", "rw");
else
exit(errno);
if (!stderr) exit(errno);
errno = 0;
}
else { stderr = fdopen(1, "rw"); }
}