summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2018-11-08 13:54:32 +0100
committerSandrine Bailleux <sandrine.bailleux@arm.com>2018-12-13 16:07:05 +0100
commit6826138602bcdb8985bde0fa6295cb47f7174e3a (patch)
treeedb94321a679a680cc83a8fc1daf2b63f572d642 /lib
parent125d58c4c065e27c7764ed9f05236f70fc7a5788 (diff)
Add vprintf() in standard C library
This is a trivial, unoptimised implementation. Change-Id: Ia05a3fbbc7582583f7e8ae06e464c96a6b4e766d Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/printf.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/stdlib/printf.c b/lib/stdlib/printf.c
index 6329157..8ae7c26 100644
--- a/lib/stdlib/printf.c
+++ b/lib/stdlib/printf.c
@@ -9,28 +9,34 @@
/* Choose max of 512 chars for now. */
#define PRINT_BUFFER_SIZE 512
-int printf(const char *fmt, ...)
+
+int vprintf(const char *fmt, va_list args)
{
- va_list args;
char buf[PRINT_BUFFER_SIZE];
int count;
- va_start(args, fmt);
vsnprintf(buf, sizeof(buf) - 1, fmt, args);
- va_end(args);
+ buf[PRINT_BUFFER_SIZE - 1] = '\0';
/* Use putchar directly as 'puts()' adds a newline. */
- buf[PRINT_BUFFER_SIZE - 1] = '\0';
count = 0;
- while (buf[count])
- {
- if (putchar(buf[count]) != EOF) {
- count++;
- } else {
- count = EOF;
- break;
+ while (buf[count] != 0) {
+ if (putchar(buf[count]) == EOF) {
+ return EOF;
}
+ count++;
}
return count;
}
+
+int printf(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ int count = vprintf(fmt, args);
+ va_end(args);
+
+ return count;
+}