diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-15 22:39:04 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-15 22:39:04 +0200 |
commit | 7a1ea510a9fc43ccbc257601b149a90920332e13 (patch) | |
tree | 75ac252bb8ce029c62d6834e4ca927f59eaf5769 /src/lib/libkogata/stdio.c | |
parent | d415aca695956c79110c88fa58c12bf55c0e2163 (diff) | |
download | kogata-7a1ea510a9fc43ccbc257601b149a90920332e13.tar.gz kogata-7a1ea510a9fc43ccbc257601b149a90920332e13.zip |
Add Lua source, not compiled yet as libc/libm functions remain unimplemented
Diffstat (limited to 'src/lib/libkogata/stdio.c')
-rw-r--r-- | src/lib/libkogata/stdio.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/libkogata/stdio.c b/src/lib/libkogata/stdio.c index e62aa30..94dec22 100644 --- a/src/lib/libkogata/stdio.c +++ b/src/lib/libkogata/stdio.c @@ -7,7 +7,7 @@ fd_t stdio = 1; -int getc() { +int getchar() { char chr; size_t sz = read(stdio, 0, 1, &chr); ASSERT(sz == 1); @@ -15,39 +15,41 @@ int getc() { } -void putc(int c) { +int putchar(int c) { char chr = c; write(stdio, 0, 1, &chr); + return 0; //TODO what? } -void puts(char* s) { - write(stdio, 0, strlen(s), s); +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 = getc(); + int c = getchar(); if (c == '\n') { - putc('\n'); + putchar('\n'); buf[i] = 0; break; } else if (c == '\b') { if (i > 0) { i--; - putc('\b'); + putchar('\b'); } } else if (c >= ' ') { buf[i] = c; if (i < l-1) { i++; - putc(c); + putchar(c); } } } } -void printf(char* fmt, ...) { +int printf(const char* fmt, ...) { va_list ap; char buffer[256]; @@ -55,7 +57,7 @@ void printf(char* fmt, ...) { vsnprintf(buffer, 256, fmt, ap); va_end(ap); - puts(buffer); + return puts(buffer); } /* vim: set ts=4 sw=4 tw=0 noet :*/ |