Files
Espresso/lib/stdio.c
2026-03-20 16:57:08 -05:00

101 lines
1.2 KiB
C

#include <drivers/ps2_keyboard.h>
#include <stdlib.h>
#include <string.h>
#include <kernel/syscall.h>
#include <tty.h>
#include <new_tty.h>
#include <stdio.h>
int write(uint32_t fd, void* data, size_t len)
{
if (fd == STDOUT)
{
print_uint((uint32_t) len);
terminal_write((char*) data, len);
}
else
{
return -1;
}
return 0;
}
int read(uint32_t fd, void* data, size_t max_len)
{
int rv = 0;
if (fd == STDIN)
{
char* sptr = (char*) data; /* this really shouldn't be needed... */
sptr = gets_new(&rv);
}
else
{
return -1;
}
return rv;
}
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* gets(void)
{
return kbd_gets();
}
char* gets_new(int* num)
{
char* __s = malloc(256);
memset(__s, 0, 256);
ssize_t n = tty_read_active(__s, 255);
*num = (int) n;
return __s;
}
int getstr(char* dest)
{
int i = 0;
char* p = gets_new(&i);
if (i != 0)
{
return -1;
}
strcpy(dest, p);
}
void putc(char c)
{
syscall1(SYS_TERMINAL_PUTCHAR, c);
}