Add support for fprintf(stderr, ...).
authorwhitequark <whitequark@whitequark.org>
Sun, 26 Jul 2015 09:42:53 +0000 (12:42 +0300)
committerwhitequark <whitequark@whitequark.org>
Sun, 26 Jul 2015 09:42:53 +0000 (12:42 +0300)
software/libbase/console.c

index f6887bb702d0c165a89b818f3fb027fd3212bf6d..af8d140f7be48b8169c346c2dd129431db77b9dd 100644 (file)
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <stdarg.h>
 
+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);