From 7a1ea510a9fc43ccbc257601b149a90920332e13 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 15 Jul 2016 22:39:04 +0200 Subject: Add Lua source, not compiled yet as libc/libm functions remain unimplemented --- src/lib/libkogata/stdio.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/lib/libkogata/stdio.c') 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 :*/ -- cgit v1.2.3