From 1bc9e1f6ebb339136842fca0fa6f897ec20fd1aa Mon Sep 17 00:00:00 2001 From: Harry Liebel Date: Thu, 12 Dec 2013 16:46:30 +0000 Subject: Add strchr() and putchar() to local C library Change-Id: I3659e119a242f8ef828e32bfdf5d0b4b7ac4f716 --- lib/stdlib/printf.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lib/stdlib/printf.c') 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 #include - // 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; } -- cgit