libc: Add stdin
Aka keyboard :)
This commit is contained in:
parent
ba57f32f39
commit
aebd860947
@ -138,13 +138,6 @@ void command_concat(command* cmd, const char* str)
|
||||
|
||||
int main()
|
||||
{
|
||||
FILE* fp = fopen("/dev/kbd", "r");
|
||||
if (!fp)
|
||||
{
|
||||
perror("fopen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
show_prompt();
|
||||
|
||||
char buffer[33];
|
||||
@ -154,15 +147,15 @@ int main()
|
||||
|
||||
while (1)
|
||||
{
|
||||
size_t nread = fread(buffer, sizeof(buffer) - 1, 1, fp);
|
||||
if (ferror(fp))
|
||||
size_t nread = fread(buffer, sizeof(buffer) - 1, 1, stdin);
|
||||
if (ferror(stdin))
|
||||
{
|
||||
perror("fread");
|
||||
return 1;
|
||||
}
|
||||
if (feof(fp))
|
||||
if (feof(stdin))
|
||||
{
|
||||
clearerr(fp);
|
||||
clearerr(stdin);
|
||||
msleep(20);
|
||||
continue;
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ typedef struct
|
||||
|
||||
extern FILE* stderr;
|
||||
extern FILE* stdout;
|
||||
extern FILE* stdin;
|
||||
#define stdin stdin
|
||||
#define stdout stdout
|
||||
#define stderr stderr
|
||||
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include <luna/os-limits.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"
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
FILE* stderr;
|
||||
FILE* stdout;
|
||||
FILE* stdin;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ static void terminate_libc()
|
||||
{
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
fclose(stdin);
|
||||
}
|
||||
|
||||
static void initialize_random()
|
||||
@ -52,6 +53,7 @@ static void check_for_file(int fd, FILE** target_stream, const char* path, const
|
||||
|
||||
extern "C" void initialize_libc()
|
||||
{
|
||||
check_for_file(STDIN_FILENO, &stdin, "/dev/kbd", "r");
|
||||
check_for_file(STDOUT_FILENO, &stdout, "/dev/console", "rw");
|
||||
check_for_file(STDERR_FILENO, &stderr, "/dev/console", "rw");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user