aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libc/snprintf.c
diff options
context:
space:
mode:
authorMadhukar Pappireddy <madhukar.pappireddy@arm.com>2020-09-08 19:00:00 -0500
committerMadhukar Pappireddy <madhukar.pappireddy@arm.com>2020-09-11 11:34:01 -0500
commit77648689ad2627911a3aa6fd69463e8043889532 (patch)
tree45d3955bf2ccccc70635b498d2449f72ca739b46 /lib/libc/snprintf.c
parenta41ca4c3449c51822d318e295b21d452efac2848 (diff)
downloadplatform_external_arm-trusted-firmware-77648689ad2627911a3aa6fd69463e8043889532.tar.gz
platform_external_arm-trusted-firmware-77648689ad2627911a3aa6fd69463e8043889532.tar.bz2
platform_external_arm-trusted-firmware-77648689ad2627911a3aa6fd69463e8043889532.zip
libc: Add support for vsnprintf()
It uses the existing implementation of snprintf() function Change-Id: Ie59418564c2e415222e819cf322c34e9a4d1f336 Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Diffstat (limited to 'lib/libc/snprintf.c')
-rw-r--r--lib/libc/snprintf.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/lib/libc/snprintf.c b/lib/libc/snprintf.c
index 268632722..6e80d8c03 100644
--- a/lib/libc/snprintf.c
+++ b/lib/libc/snprintf.c
@@ -77,7 +77,7 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
}
/*******************************************************************
- * Reduced snprintf to be used for Trusted firmware.
+ * Reduced vsnprintf to be used for Trusted firmware.
* The following type specifiers are supported:
*
* %x (or %X) - hexadecimal format
@@ -97,9 +97,8 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
* buffer was big enough. If it returns a value lower than n, the
* whole string has been written.
*******************************************************************/
-int snprintf(char *s, size_t n, const char *fmt, ...)
+int vsnprintf(char *s, size_t n, const char *fmt, va_list args)
{
- va_list args;
int num;
unsigned long long int unum;
char *str;
@@ -120,7 +119,6 @@ int snprintf(char *s, size_t n, const char *fmt, ...)
n--;
}
- va_start(args, fmt);
while (*fmt != '\0') {
left = false;
padc ='\0';
@@ -221,10 +219,42 @@ loop:
chars_printed++;
}
- va_end(args);
-
- if (n > 0U)
+ if (n > 0U) {
*s = '\0';
+ }
return (int)chars_printed;
}
+
+/*******************************************************************
+ * Reduced snprintf to be used for Trusted firmware.
+ * The following type specifiers are supported:
+ *
+ * %x (or %X) - hexadecimal format
+ * %d or %i - signed decimal format
+ * %s - string format
+ * %u - unsigned decimal format
+ * %p - pointer format
+ *
+ * The following padding specifiers are supported by this print
+ * %0NN - Left-pad the number with 0s (NN is a decimal number)
+ * %NN - Left-pad the number or string with spaces (NN is a decimal number)
+ * %-NN - Right-pad the number or string with spaces (NN is a decimal number)
+ *
+ * The function panics on all other formats specifiers.
+ *
+ * It returns the number of characters that would be written if the
+ * buffer was big enough. If it returns a value lower than n, the
+ * whole string has been written.
+ *******************************************************************/
+int snprintf(char *s, size_t n, const char *fmt, ...)
+{
+ int count;
+ va_list all_args;
+
+ va_start(all_args, fmt);
+ count = vsnprintf(s, n, fmt, all_args);
+ va_end(all_args);
+
+ return count;
+}