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 |
| 12 | int printf(const char *fmt, ...) |
| 13 | { |
| 14 | va_list args; |
| 15 | char buf[PRINT_BUFFER_SIZE]; |
| 16 | int count; |
| 17 | |
| 18 | va_start(args, fmt); |
| 19 | vsnprintf(buf, sizeof(buf) - 1, fmt, args); |
| 20 | va_end(args); |
| 21 | |
| 22 | /* Use putchar directly as 'puts()' adds a newline. */ |
| 23 | buf[PRINT_BUFFER_SIZE - 1] = '\0'; |
| 24 | count = 0; |
| 25 | while (buf[count]) |
| 26 | { |
| 27 | if (putchar(buf[count]) != EOF) { |
| 28 | count++; |
| 29 | } else { |
| 30 | count = EOF; |
| 31 | break; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return count; |
| 36 | } |