diff options
Diffstat (limited to 'lib/stdlib/printf.c')
-rw-r--r-- | lib/stdlib/printf.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/stdlib/printf.c b/lib/stdlib/printf.c index 3d62497a..61361b9c 100644 --- a/lib/stdlib/printf.c +++ b/lib/stdlib/printf.c @@ -31,14 +31,30 @@ #include <stdio.h> #include <stdarg.h> - // Choose max of 128 chars for now. +/* Choose max of 128 chars for now. */ #define PRINT_BUFFER_SIZE 128 int printf(const char *fmt, ...) { va_list args; - va_start(args, fmt); char buf[PRINT_BUFFER_SIZE]; + int count; + + va_start(args, fmt); vsnprintf(buf, sizeof(buf) - 1, fmt, args); + va_end(args); + + /* Use putchar directly as 'puts()' adds a newline. */ buf[PRINT_BUFFER_SIZE - 1] = '\0'; - return puts(buf); + count = 0; + while (buf[count]) + { + if (putchar(buf[count]) != EOF) { + count++; + } else { + count = EOF; + break; + } + } + + return count; } |