diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-16 15:59:46 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-16 15:59:46 +0200 |
commit | 3d6a857b9186ef6304ea6cf04627c2b787169f29 (patch) | |
tree | 756179ce1e1838f75c57e3efec2a570d72051594 /src/lib/libc/stdio.c | |
parent | 59000174aa50ed6b2d24a71576d15e6a53c5be0c (diff) | |
download | kogata-3d6a857b9186ef6304ea6cf04627c2b787169f29.tar.gz kogata-3d6a857b9186ef6304ea6cf04627c2b787169f29.zip |
Make way for libc implementation
Diffstat (limited to 'src/lib/libc/stdio.c')
-rw-r--r-- | src/lib/libc/stdio.c | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/src/lib/libc/stdio.c b/src/lib/libc/stdio.c index bd6c35b..8d4577e 100644 --- a/src/lib/libc/stdio.c +++ b/src/lib/libc/stdio.c @@ -1,52 +1,38 @@ #include <string.h> #include <stdio.h> +#include <proto/launch.h> + #include <kogata/syscall.h> #include <kogata/printf.h> +FILE *stdin = 0; +FILE *stdout = 0; +FILE *stderr = 0; -fd_t stdio = 1; +void setup_libc_stdio() { + fd_t tty_io = STD_FD_TTY_STDIO; + // fd_t tty_in = STD_FD_STDIN; + // fd_t tty_out = STD_FD_STDOUT; + // fd_t tty_err = STD_FD_STDERR; -int getchar() { - char chr; - size_t sz = read(stdio, 0, 1, &chr); - ASSERT(sz == 1); - return chr; + // TODO + if (true) { + sc_fctl(tty_io, FC_SET_BLOCKING, 0); + } } +int getchar() { + return fgetc(stdin); +} + int putchar(int c) { - char chr = c; - write(stdio, 0, 1, &chr); - return 0; //TODO what? + return fputc(c, stdout); } int puts(const char* s) { - // TODO return EOF on error - return write(stdio, 0, strlen(s), s); -} - -void getline(char* buf, size_t l) { - size_t i = 0; - while (true) { - int c = getchar(); - if (c == '\n') { - putchar('\n'); - buf[i] = 0; - break; - } else if (c == '\b') { - if (i > 0) { - i--; - putchar('\b'); - } - } else if (c >= ' ') { - buf[i] = c; - if (i < l-1) { - i++; - putchar(c); - } - } - } + return fputs(s, stdout); } int printf(const char* fmt, ...) { @@ -139,9 +125,6 @@ int fclose(FILE* f) { return 0; } -FILE *stdin = 0; -FILE *stdout = 0; -FILE *stderr = 0; void setbuf(FILE *stream, char *buf) { // TODO |