diff --git a/apps/src/init.c b/apps/src/init.c index 4cbf51d6..007547da 100644 --- a/apps/src/init.c +++ b/apps/src/init.c @@ -43,7 +43,8 @@ int main() { if (gettid() == 0) // why are we the idle task? { - __luna_abort("SHENANIGANS! init is tid 0 (which is reserved for the idle task)\n"); + fprintf(stderr, "SHENANIGANS! init is tid 0 (which is reserved for the idle task)\n"); + return 1; } printf("Welcome to Luna!\n"); diff --git a/libs/libc/include/stdio.h b/libs/libc/include/stdio.h index 83023afb..b6386353 100644 --- a/libs/libc/include/stdio.h +++ b/libs/libc/include/stdio.h @@ -27,13 +27,13 @@ extern "C" FILE* fopen(const char*, const char*); int fprintf(FILE*, const char*, ...); size_t fread(void*, size_t, size_t, FILE*); - int fseek(FILE*, long, int); - long ftell(FILE*); + int fseek(FILE*, long, int); // Not implemented. + long ftell(FILE*); // Not implemented. size_t fwrite(const void*, size_t, size_t, FILE*); int ferror(FILE*); int feof(FILE*); void clearerr(FILE*); - void setbuf(FILE*, char*); + void setbuf(FILE*, char*); // Not implemented. int vfprintf(FILE*, const char*, va_list); int printf(const char*, ...); int vprintf(const char*, va_list); @@ -42,6 +42,10 @@ extern "C" int vsprintf(char*, const char*, va_list); int vsnprintf(char*, size_t, const char*, va_list); int puts(const char*); + int fputs(const char*, FILE*); + int fputc(int, FILE*); + int putc(int, FILE*); + int putchar(int); void perror(const char*); #ifdef __cplusplus diff --git a/libs/libc/src/stdio.cpp b/libs/libc/src/stdio.cpp index ab04a61c..c86e4f57 100644 --- a/libs/libc/src/stdio.cpp +++ b/libs/libc/src/stdio.cpp @@ -10,10 +10,31 @@ extern "C" { int puts(const char* s) { - long nwritten = fwrite(s, strlen(s), 1, stdout); + int nwritten = fputs(s, stdout); if (nwritten < 0) return -1; - nwritten += fwrite("\n", 1, 1, stdout); - return (int)nwritten; + if (putchar('\n') < 0) return -1; + return nwritten + 1; + } + int fputs(const char* s, FILE* stream) + { + int result = (int)fwrite(s, strlen(s), 1, stream); + if (ferror(stream)) return -1; + return result; + } + int fputc(int c, FILE* stream) + { + char chr = (char)c; + fwrite(&chr, 1, 1, stream); + if (ferror(stream)) { return -1; } + return c; + } + int putc(int c, FILE* stream) + { + return fputc(c, stream); + } + int putchar(int c) + { + return fputc(c, stdout); } void perror(const char* s) {