blob: 8ae7c2635951da770d90d24faee31a3b331f3e84 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdarg.h>
8#include <stdio.h>
9
10/* Choose max of 512 chars for now. */
11#define PRINT_BUFFER_SIZE 512
Sandrine Bailleux68261382018-11-08 13:54:32 +010012
13int vprintf(const char *fmt, va_list args)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020014{
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020015 char buf[PRINT_BUFFER_SIZE];
16 int count;
17
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018 vsnprintf(buf, sizeof(buf) - 1, fmt, args);
Sandrine Bailleux68261382018-11-08 13:54:32 +010019 buf[PRINT_BUFFER_SIZE - 1] = '\0';
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020020
21 /* Use putchar directly as 'puts()' adds a newline. */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020022 count = 0;
Sandrine Bailleux68261382018-11-08 13:54:32 +010023 while (buf[count] != 0) {
24 if (putchar(buf[count]) == EOF) {
25 return EOF;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020026 }
Sandrine Bailleux68261382018-11-08 13:54:32 +010027 count++;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020028 }
29
30 return count;
31}
Sandrine Bailleux68261382018-11-08 13:54:32 +010032
33int printf(const char *fmt, ...)
34{
35 va_list args;
36
37 va_start(args, fmt);
38 int count = vprintf(fmt, args);
39 va_end(args);
40
41 return count;
42}