blob: f615641408d1b811879854c95695bd9acd03afa2 [file] [log] [blame]
Harry Liebel0f702c62013-12-17 18:19:04 +00001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Harry Liebel0f702c62013-12-17 18:19:04 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Harry Liebel0f702c62013-12-17 18:19:04 +00005 */
6
7#include <stdio.h>
8#include <stdarg.h>
9
Harry Liebel1bc9e1f2013-12-12 16:46:30 +000010/* Choose max of 128 chars for now. */
Harry Liebel0f702c62013-12-17 18:19:04 +000011#define PRINT_BUFFER_SIZE 128
12int printf(const char *fmt, ...)
13{
14 va_list args;
Harry Liebel0f702c62013-12-17 18:19:04 +000015 char buf[PRINT_BUFFER_SIZE];
Harry Liebel1bc9e1f2013-12-12 16:46:30 +000016 int count;
17
18 va_start(args, fmt);
Harry Liebel0f702c62013-12-17 18:19:04 +000019 vsnprintf(buf, sizeof(buf) - 1, fmt, args);
Harry Liebel1bc9e1f2013-12-12 16:46:30 +000020 va_end(args);
21
22 /* Use putchar directly as 'puts()' adds a newline. */
Harry Liebel0f702c62013-12-17 18:19:04 +000023 buf[PRINT_BUFFER_SIZE - 1] = '\0';
Harry Liebel1bc9e1f2013-12-12 16:46:30 +000024 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 Liebel0f702c62013-12-17 18:19:04 +000036}