aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lib/stdlib/stdio.h2
-rw-r--r--lib/stdlib/printf.c30
2 files changed, 20 insertions, 12 deletions
diff --git a/include/lib/stdlib/stdio.h b/include/lib/stdlib/stdio.h
index 80110a8b4..55d8fe2c1 100644
--- a/include/lib/stdlib/stdio.h
+++ b/include/lib/stdlib/stdio.h
@@ -59,6 +59,8 @@ typedef __ssize_t ssize_t;
#define EOF (-1)
int printf(const char * __restrict, ...) __printflike(1, 2);
+int vprintf(const char * __restrict, __va_list);
+
int putchar(int);
int puts(const char *);
int sprintf(char * __restrict, const char * __restrict, ...)
diff --git a/lib/stdlib/printf.c b/lib/stdlib/printf.c
index 6329157d0..8ae7c2635 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;
+}