Commit 73bc6e77 authored by Antonio Nino Diaz's avatar Antonio Nino Diaz
Browse files

tf_snprintf: Add support for '%s'



Change-Id: Ia3a159444e638f63de7dc5a6a4b76169c757188a
Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
parent 781842ea
...@@ -8,6 +8,17 @@ ...@@ -8,6 +8,17 @@
#include <platform.h> #include <platform.h>
#include <stdarg.h> #include <stdarg.h>
static void string_print(char **s, size_t n, size_t *chars_printed,
const char *str)
{
while (*str) {
if (*chars_printed < n)
*(*s)++ = *str;
(*chars_printed)++;
str++;
}
}
static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed, static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed,
unsigned int unum) unsigned int unum)
{ {
...@@ -32,6 +43,7 @@ static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed, ...@@ -32,6 +43,7 @@ static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed,
* The following type specifiers are supported: * The following type specifiers are supported:
* *
* %d or %i - signed decimal format * %d or %i - signed decimal format
* %s - string format
* %u - unsigned decimal format * %u - unsigned decimal format
* *
* The function panics on all other formats specifiers. * The function panics on all other formats specifiers.
...@@ -45,6 +57,7 @@ int tf_snprintf(char *s, size_t n, const char *fmt, ...) ...@@ -45,6 +57,7 @@ int tf_snprintf(char *s, size_t n, const char *fmt, ...)
va_list args; va_list args;
int num; int num;
unsigned int unum; unsigned int unum;
char *str;
size_t chars_printed = 0; size_t chars_printed = 0;
if (n == 1) { if (n == 1) {
...@@ -79,6 +92,10 @@ int tf_snprintf(char *s, size_t n, const char *fmt, ...) ...@@ -79,6 +92,10 @@ int tf_snprintf(char *s, size_t n, const char *fmt, ...)
unsigned_dec_print(&s, n, &chars_printed, unum); unsigned_dec_print(&s, n, &chars_printed, unum);
break; break;
case 's':
str = va_arg(args, char *);
string_print(&s, n, &chars_printed, str);
break;
case 'u': case 'u':
unum = va_arg(args, unsigned int); unum = va_arg(args, unsigned int);
unsigned_dec_print(&s, n, &chars_printed, unum); unsigned_dec_print(&s, n, &chars_printed, unum);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment