Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 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 Bailleux | 6826138 | 2018-11-08 13:54:32 +0100 | [diff] [blame] | 12 | |
| 13 | int vprintf(const char *fmt, va_list args) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 14 | { |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 15 | char buf[PRINT_BUFFER_SIZE]; |
| 16 | int count; |
| 17 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 18 | vsnprintf(buf, sizeof(buf) - 1, fmt, args); |
Sandrine Bailleux | 6826138 | 2018-11-08 13:54:32 +0100 | [diff] [blame] | 19 | buf[PRINT_BUFFER_SIZE - 1] = '\0'; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 20 | |
| 21 | /* Use putchar directly as 'puts()' adds a newline. */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 22 | count = 0; |
Sandrine Bailleux | 6826138 | 2018-11-08 13:54:32 +0100 | [diff] [blame] | 23 | while (buf[count] != 0) { |
| 24 | if (putchar(buf[count]) == EOF) { |
| 25 | return EOF; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 26 | } |
Sandrine Bailleux | 6826138 | 2018-11-08 13:54:32 +0100 | [diff] [blame] | 27 | count++; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | return count; |
| 31 | } |
Sandrine Bailleux | 6826138 | 2018-11-08 13:54:32 +0100 | [diff] [blame] | 32 | |
| 33 | int 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 | } |