diff --git a/apps/src/memeater.c b/apps/src/memeater.c index dcd6755c..a1c26c71 100644 --- a/apps/src/memeater.c +++ b/apps/src/memeater.c @@ -15,6 +15,6 @@ int main() printf("Allocating 4 MB of memory... %lx\n", (unsigned long)allocated); sleep(1); } while ((allocated = malloc(CHUNK))); - printf("Out of memory. (errno=%d, %s)\n", errno, strerror(errno)); + perror("malloc"); printf("Press any key to restart.\n"); } \ No newline at end of file diff --git a/libs/libc/include/stdio.h b/libs/libc/include/stdio.h index f2528129..adea55f3 100644 --- a/libs/libc/include/stdio.h +++ b/libs/libc/include/stdio.h @@ -35,6 +35,7 @@ extern "C" int vsprintf(char*, const char*, va_list); int vsnprintf(char*, size_t, const char*, va_list); int puts(const char*); + void perror(const char*); #ifdef __cplusplus } diff --git a/libs/libc/src/stdio.cpp b/libs/libc/src/stdio.cpp index eecf7621..a59357ad 100644 --- a/libs/libc/src/stdio.cpp +++ b/libs/libc/src/stdio.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -78,4 +79,9 @@ extern "C" va_end(ap); return written; } + void perror(const char* s) // FIXME: Print to stderr, whenever we have an stderr. + { + if (s && *s) { printf("%s: ", s); } + printf("%s\n", strerror(errno)); + } } \ No newline at end of file