Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <stdarg.h> |
| 9 | |
Harry Liebel | 1bc9e1f | 2013-12-12 16:46:30 +0000 | [diff] [blame] | 10 | /* Choose max of 128 chars for now. */ |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 11 | #define PRINT_BUFFER_SIZE 128 |
| 12 | int printf(const char *fmt, ...) |
| 13 | { |
| 14 | va_list args; |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 15 | char buf[PRINT_BUFFER_SIZE]; |
Harry Liebel | 1bc9e1f | 2013-12-12 16:46:30 +0000 | [diff] [blame] | 16 | int count; |
| 17 | |
| 18 | va_start(args, fmt); |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 19 | vsnprintf(buf, sizeof(buf) - 1, fmt, args); |
Harry Liebel | 1bc9e1f | 2013-12-12 16:46:30 +0000 | [diff] [blame] | 20 | va_end(args); |
| 21 | |
| 22 | /* Use putchar directly as 'puts()' adds a newline. */ |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 23 | buf[PRINT_BUFFER_SIZE - 1] = '\0'; |
Harry Liebel | 1bc9e1f | 2013-12-12 16:46:30 +0000 | [diff] [blame] | 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; |
Harry Liebel | 0f702c6 | 2013-12-17 18:19:04 +0000 | [diff] [blame] | 36 | } |