summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksims Svecovs <maksims.svecovs@arm.com>2023-05-09 12:03:31 +0100
committerMaksims Svecovs <maksims.svecovs@arm.com>2023-05-11 10:32:28 +0100
commit44d9706e5428d8e3588d04565c7cd738ffc1e472 (patch)
tree07b42054eb690555cddd887cb73c7c1a8d6b9cbb
parent658ce7ad8eceb40741cd40f1639a6d923f922fad (diff)
downloadarm-trusted-firmware-44d9706e5428d8e3588d04565c7cd738ffc1e472.tar.gz
feat(libc): add %c to printf/snprintf
Adds %c support for printf and snprintf to print one character. Required by most recent MbedTLS 3.4.0. Change-Id: I4d9b2725127a929d58946353324f99ff22b3b28b Signed-off-by: Maksims Svecovs <maksims.svecovs@arm.com>
-rw-r--r--lib/libc/printf.c7
-rw-r--r--lib/libc/snprintf.c6
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/libc/printf.c b/lib/libc/printf.c
index e52cbed73..faccfdff4 100644
--- a/lib/libc/printf.c
+++ b/lib/libc/printf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2021, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2014-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -81,6 +81,7 @@ static int unsigned_num_print(unsigned long long int unum, unsigned int radix,
* %x - hexadecimal format
* %s - string format
* %d or %i - signed decimal format
+ * %c - character format
* %u - unsigned decimal format
* %p - pointer format
*
@@ -130,6 +131,10 @@ loop:
count += unsigned_num_print(unum, 10,
padc, padn);
break;
+ case 'c':
+ (void)putchar(va_arg(args, int));
+ count++;
+ break;
case 's':
str = va_arg(args, char *);
count += string_print(str);
diff --git a/lib/libc/snprintf.c b/lib/libc/snprintf.c
index 0e3256cde..21d34168f 100644
--- a/lib/libc/snprintf.c
+++ b/lib/libc/snprintf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2022, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2017-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -85,6 +85,7 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
*
* %x (or %X) - hexadecimal format
* %d or %i - signed decimal format
+ * %c - character format
* %s - string format
* %u - unsigned decimal format
* %p - pointer format
@@ -181,6 +182,9 @@ loop:
unsigned_num_print(&s, n, &chars_printed,
unum, 10, padc, padn, false);
break;
+ case 'c':
+ CHECK_AND_PUT_CHAR(s, n, chars_printed, va_arg(args, int));
+ break;
case 's':
str = va_arg(args, char *);
string_print(&s, n, &chars_printed, str);