libc: make stdout and stderr functional
what were before one extern FILE* without reference now are opened by libc on program initialization, to point to /dev/console by default.
This commit is contained in:
parent
53a4b3b85e
commit
80ab982fe4
@ -3,6 +3,7 @@ section .text
|
||||
extern _init
|
||||
extern main
|
||||
extern _fini
|
||||
extern initialize_libc
|
||||
extern exit
|
||||
|
||||
global _start
|
||||
@ -13,6 +14,8 @@ _start:
|
||||
push rbp ; rbp=0
|
||||
mov rbp, rsp
|
||||
|
||||
call initialize_libc
|
||||
|
||||
call _init
|
||||
|
||||
mov rdi, 0 ; argc = 0
|
||||
|
@ -13,13 +13,15 @@ typedef struct
|
||||
int f_err;
|
||||
} FILE;
|
||||
|
||||
extern FILE* __stderr;
|
||||
extern FILE* __stdout;
|
||||
#define stderr __stderr
|
||||
#define stdout __stdout
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern FILE* stderr;
|
||||
#define stderr stderr
|
||||
int fclose(FILE*);
|
||||
int fflush(FILE*);
|
||||
FILE* fopen(const char*, const char*);
|
||||
|
14
libs/libc/src/init.cpp
Normal file
14
libs/libc/src/init.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern "C" void initialize_libc()
|
||||
{
|
||||
__stderr = fopen("/dev/console", "rw");
|
||||
if (!stderr) exit(errno);
|
||||
__stdout = fopen("/dev/console", "rw");
|
||||
if (!stdout) exit(errno);
|
||||
clearerr(__stderr);
|
||||
clearerr(__stdout);
|
||||
}
|
Loading…
Reference in New Issue
Block a user