Espresso 0.0.2c
This commit is contained in:
94
lib/stdio.c
94
lib/stdio.c
@ -2,8 +2,45 @@
|
||||
#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)
|
||||
@ -31,40 +68,33 @@ char* gets(void)
|
||||
return kbd_gets();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*char* fgets(char* buf, int n, FILE file)
|
||||
char* gets_new(int* num)
|
||||
{
|
||||
if (!buf || n <= 1 || file < 1)
|
||||
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 NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int total_read = 0;
|
||||
char c;
|
||||
strcpy(dest, p);
|
||||
}
|
||||
|
||||
while (total_read < n - 1)
|
||||
{
|
||||
int bytes = 0*//*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;
|
||||
}*/
|
||||
void putc(char c)
|
||||
{
|
||||
syscall1(SYS_TERMINAL_PUTCHAR, c);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user