forked from Bananymous/banan-os
Kernel/LibC: opening standard files is done in libc
This commit is contained in:
@@ -27,6 +27,15 @@ FILE* stdin = &s_files[0];
|
||||
FILE* stdout = &s_files[1];
|
||||
FILE* stderr = &s_files[2];
|
||||
|
||||
extern "C" void _init_stdio()
|
||||
{
|
||||
char tty[L_ctermid];
|
||||
ctermid(tty);
|
||||
if (open(tty, O_RDONLY) != 0) _exit(1);
|
||||
if (open(tty, O_WRONLY) != 1) _exit(1);
|
||||
if (open(tty, O_WRONLY) != 2) _exit(1);
|
||||
}
|
||||
|
||||
void clearerr(FILE* file)
|
||||
{
|
||||
file->eof = false;
|
||||
@@ -155,7 +164,7 @@ FILE* fopen(const char* pathname, const char* mode)
|
||||
uint8_t flags = 0;
|
||||
if (mode[0] == 'r')
|
||||
flags |= O_RDONLY;
|
||||
else if (mode[0] == 'b')
|
||||
else if (mode[0] == 'w')
|
||||
flags |= O_WRONLY | O_CREAT | O_TRUNC;
|
||||
else if (mode[0] == 'a')
|
||||
flags |= O_WRONLY | O_CREAT | O_APPEND;
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" void _init_stdio();
|
||||
|
||||
extern "C" void _init_libc()
|
||||
{
|
||||
_init_stdio();
|
||||
}
|
||||
|
||||
void _exit(int status)
|
||||
{
|
||||
syscall(SYS_EXIT, status);
|
||||
@@ -139,4 +146,4 @@ pid_t fork(void)
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
return syscall(SYS_SLEEP, seconds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user