summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-07-07 23:39:15 +0200
committerAlexander Graf <agraf@suse.de>2018-07-25 15:00:24 +0200
commit42e2b563f6faca0325d4c88f0a17742c02875020 (patch)
tree228a21dbee626174c66c176ba69e19627771d173
parent49de24559df6d87bf83ac1a836ddc2620c91c667 (diff)
downloadu-boot-42e2b563f6faca0325d4c88f0a17742c02875020.tar.gz
efi_selftest: support printing leading zeroes
Allow specifying the precision when printing integers, e.g. efi_st_printf("%.4u-%.2u-%.2u\n", year, month, day); Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
-rw-r--r--lib/efi_selftest/efi_selftest_console.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/efi_selftest/efi_selftest_console.c b/lib/efi_selftest/efi_selftest_console.c
index c3655a1fcc..eb139c127c 100644
--- a/lib/efi_selftest/efi_selftest_console.c
+++ b/lib/efi_selftest/efi_selftest_console.c
@@ -70,11 +70,12 @@ static void pointer(void *pointer, u16 **buf)
/*
* Print an unsigned 32bit value as decimal number to an u16 string
*
- * @value: value to be printed
- * @buf: pointer to buffer address
- * on return position of terminating zero word
+ * @value: value to be printed
+ * @prec: minimum number of digits to display
+ * @buf: pointer to buffer address
+ * on return position of terminating zero word
*/
-static void uint2dec(u32 value, u16 **buf)
+static void uint2dec(u32 value, int prec, u16 **buf)
{
u16 *pos = *buf;
int i;
@@ -93,7 +94,7 @@ static void uint2dec(u32 value, u16 **buf)
for (i = 0; i < 10; ++i) {
/* Write current digit */
c = f >> 60;
- if (c || pos != *buf)
+ if (c || pos != *buf || 10 - i <= prec)
*pos++ = c + '0';
/* Eliminate current digit */
f &= 0xfffffffffffffff;
@@ -109,11 +110,12 @@ static void uint2dec(u32 value, u16 **buf)
/*
* Print a signed 32bit value as decimal number to an u16 string
*
- * @value: value to be printed
- * @buf: pointer to buffer address
+ * @value: value to be printed
+ * @prec: minimum number of digits to display
+ * @buf: pointer to buffer address
* on return position of terminating zero word
*/
-static void int2dec(s32 value, u16 **buf)
+static void int2dec(s32 value, int prec, u16 **buf)
{
u32 u;
u16 *pos = *buf;
@@ -124,7 +126,7 @@ static void int2dec(s32 value, u16 **buf)
} else {
u = value;
}
- uint2dec(u, &pos);
+ uint2dec(u, prec, &pos);
*buf = pos;
}
@@ -143,6 +145,7 @@ void efi_st_printc(int color, const char *fmt, ...)
u16 *pos = buf;
const char *s;
u16 *u;
+ int prec;
va_start(args, fmt);
@@ -172,12 +175,20 @@ void efi_st_printc(int color, const char *fmt, ...)
break;
case '%':
++c;
+ /* Parse precision */
+ if (*c == '.') {
+ ++c;
+ prec = *c - '0';
+ ++c;
+ } else {
+ prec = 0;
+ }
switch (*c) {
case '\0':
--c;
break;
case 'd':
- int2dec(va_arg(args, s32), &pos);
+ int2dec(va_arg(args, s32), prec, &pos);
break;
case 'p':
++c;
@@ -209,7 +220,7 @@ void efi_st_printc(int color, const char *fmt, ...)
*pos++ = *s;
break;
case 'u':
- uint2dec(va_arg(args, u32), &pos);
+ uint2dec(va_arg(args, u32), prec, &pos);
break;
default:
break;