libc: Add stdin
This commit is contained in:
parent
d33fccc66f
commit
31ef96ebfc
@ -24,18 +24,19 @@ int main()
|
||||
{
|
||||
if (getpid() != 1)
|
||||
{
|
||||
printf("error: init not running as PID 1.\n");
|
||||
fprintf(stderr, "error: init not running as PID 1.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
populate_devfs();
|
||||
|
||||
// Before this point, we don't even have an stdout and stderr. Set it up now so that child processes (and us) can
|
||||
// print stuff.
|
||||
// Before this point, we don't even have an stdin, stdout and stderr. Set it up now so that child processes (and us)
|
||||
// can print stuff.
|
||||
stdin = fopen("/dev/console", "r");
|
||||
stdout = fopen("/dev/console", "w");
|
||||
stderr = fopen("/dev/console", "w");
|
||||
|
||||
fprintf(stderr, "init is running as PID %d\n", getpid());
|
||||
printf("init is running as PID %d\n", getpid());
|
||||
|
||||
pid_t ret = fork();
|
||||
|
||||
|
@ -16,8 +16,10 @@ typedef struct
|
||||
|
||||
#define EOF -1
|
||||
|
||||
extern FILE* stdin;
|
||||
extern FILE* stdout;
|
||||
extern FILE* stderr;
|
||||
#define stdin stdin
|
||||
#define stdout stdout
|
||||
#define stderr stderr
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define STDOUT_FILENO 0
|
||||
#define STDERR_FILENO 1
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
#define STDERR_FILENO 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
@ -5,6 +5,7 @@ extern "C"
|
||||
{
|
||||
void libc_init()
|
||||
{
|
||||
stdin = fdopen(STDIN_FILENO, "r");
|
||||
stdout = fdopen(STDOUT_FILENO, "w");
|
||||
stderr = fdopen(STDERR_FILENO, "w");
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
FILE* stdin = nullptr;
|
||||
FILE* stderr = nullptr;
|
||||
FILE* stdout = nullptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user