From 10f719a83045fc81d709872b9fbba2e750b6438b Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 26 Jul 2015 12:42:53 +0300 Subject: [PATCH] Add support for fprintf(stderr, ...). --- software/libbase/console.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/software/libbase/console.c b/software/libbase/console.c index f6887bb7..af8d140f 100644 --- a/software/libbase/console.c +++ b/software/libbase/console.c @@ -3,6 +3,8 @@ #include #include +FILE *stdin, *stdout, *stderr; + static console_write_hook write_hook; static console_read_hook read_hook; static console_read_nonblock_hook read_nonblock_hook; @@ -60,11 +62,28 @@ void putsnonl(const char *s) } } +#define PRINTF_BUFFER_SIZE 256 + int printf(const char *fmt, ...) { va_list args; int len; - char outbuf[256]; + char outbuf[PRINTF_BUFFER_SIZE]; + + va_start(args, fmt); + len = vscnprintf(outbuf, sizeof(outbuf), fmt, args); + va_end(args); + outbuf[len] = 0; + putsnonl(outbuf); + + return len; +} + +int fprintf(FILE *stream, const char *fmt, ...) +{ + va_list args; + int len; + char outbuf[PRINTF_BUFFER_SIZE]; va_start(args, fmt); len = vscnprintf(outbuf, sizeof(outbuf), fmt, args); -- 2.30.2