Home | History | Annotate | Download | only in stdlib
      1 /*
      2  * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
      3  *
      4  * SPDX-License-Identifier: BSD-3-Clause
      5  */
      6 
      7 #include <stdio.h>
      8 #include <stdarg.h>
      9 
     10 /* Choose max of 128 chars for now. */
     11 #define PRINT_BUFFER_SIZE 128
     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 }
     37