aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-08-09 15:30:47 +0100
committerAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-08-10 09:36:18 +0100
commit73bc6e77f11ec5616863d3cd987a7088e69c188b (patch)
tree23f545a9c63f1fa38890789ec602a8f52df34d8b
parent781842ea8a0d144b5bf2920e0bc0a9701236bdfb (diff)
downloadtrusted-firmware-a-73bc6e77f11ec5616863d3cd987a7088e69c188b.tar.gz
tf_snprintf: Add support for '%s'
Change-Id: Ia3a159444e638f63de7dc5a6a4b76169c757188a Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
-rw-r--r--common/tf_snprintf.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/common/tf_snprintf.c b/common/tf_snprintf.c
index a99ab7ab5..6df137725 100644
--- a/common/tf_snprintf.c
+++ b/common/tf_snprintf.c
@@ -8,6 +8,17 @@
#include <platform.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,
unsigned int unum)
{
@@ -32,6 +43,7 @@ static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed,
* The following type specifiers are supported:
*
* %d or %i - signed decimal format
+ * %s - string format
* %u - unsigned decimal format
*
* The function panics on all other formats specifiers.
@@ -45,6 +57,7 @@ int tf_snprintf(char *s, size_t n, const char *fmt, ...)
va_list args;
int num;
unsigned int unum;
+ char *str;
size_t chars_printed = 0;
if (n == 1) {
@@ -79,6 +92,10 @@ int tf_snprintf(char *s, size_t n, const char *fmt, ...)
unsigned_dec_print(&s, n, &chars_printed, unum);
break;
+ case 's':
+ str = va_arg(args, char *);
+ string_print(&s, n, &chars_printed, str);
+ break;
case 'u':
unum = va_arg(args, unsigned int);
unsigned_dec_print(&s, n, &chars_printed, unum);