libc: Add stdin

Aka keyboard :)
This commit is contained in:
apio 2022-10-19 20:43:04 +02:00
parent ba57f32f39
commit aebd860947
5 changed files with 12 additions and 13 deletions

View File

@ -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;
}

View File

@ -17,6 +17,8 @@ typedef struct
extern FILE* stderr;
extern FILE* stdout;
extern FILE* stdin;
#define stdin stdin
#define stdout stdout
#define stderr stderr

View File

@ -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"

View File

@ -7,6 +7,7 @@
FILE* stderr;
FILE* stdout;
FILE* stdin;
extern "C"
{

View File

@ -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");