Espresso 0.0.1a
This commit is contained in:
62
lib/stdio.c
Normal file
62
lib/stdio.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include <drivers/ps2_keyboard.h>
|
||||
#include <fs/vfs.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern bool ps2keyboard_initialized;
|
||||
|
||||
char getchar(void)
|
||||
{
|
||||
if (ps2keyboard_initialized)
|
||||
{
|
||||
return get_char();
|
||||
}
|
||||
|
||||
return '\0';
|
||||
}
|
||||
|
||||
char* getstring(void)
|
||||
{
|
||||
if (ps2keyboard_initialized)
|
||||
{
|
||||
return get_string();
|
||||
}
|
||||
|
||||
return "HELLO\0";
|
||||
}
|
||||
|
||||
char* fgets(char* buf, int n, FILE file)
|
||||
{
|
||||
if (!buf || n <= 1 || file < 1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int total_read = 0;
|
||||
char c;
|
||||
|
||||
while (total_read < n - 1)
|
||||
{
|
||||
int bytes = read_file(file, &c, 1);
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
break; /* EOF or error */
|
||||
}
|
||||
|
||||
buf[total_read++] = c;
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
break; /* Stop at newline */
|
||||
}
|
||||
}
|
||||
|
||||
if (total_read == 0)
|
||||
{
|
||||
return NULL; /* Nothing read (e.g. EOF) */
|
||||
}
|
||||
|
||||
buf[total_read] = '\0';
|
||||
return buf;
|
||||
}
|
Reference in New Issue
Block a user