summaryrefslogtreecommitdiff
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-01-16 13:59:21 +0300
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-01-19 18:16:33 +0300
commit04872381206a05d9b9d8211067e59b353d2929fb (patch)
tree820533c8ef0484cb13ca849cde13dd90e0536ccb /lib/vsprintf.c
parentc1528f324c6068936a629233b12c66774accc359 (diff)
downloadu-boot-04872381206a05d9b9d8211067e59b353d2929fb.tar.xz
lib: printf code %pUs for GUID text representation
In different places text representations are used for GUIDs, e.g. * command efidebug * command part list for GPT partitions To allow reducing code duplication introduce a new printf code %pUs. It will call uuid_guid_get_str() to get a text representation. If none is found it will fallback to %pUl and print a hexadecimal representation. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index de9f236b90..2c84649fa8 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -255,7 +255,7 @@ static char *number(char *buf, char *end, u64 num,
return buf;
}
-static char *string(char *buf, char *end, char *s, int field_width,
+static char *string(char *buf, char *end, const char *s, int field_width,
int precision, int flags)
{
int len, i;
@@ -387,12 +387,14 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
* %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10
* %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10
* %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10
+ * %pUs: GUID text representation if known or fallback to %pUl
*/
static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
int precision, int flags, const char *fmt)
{
char uuid[UUID_STR_LEN + 1];
int str_format;
+ const char *str;
switch (*(++fmt)) {
case 'L':
@@ -404,6 +406,13 @@ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
case 'B':
str_format = UUID_STR_FORMAT_STD | UUID_STR_UPPER_CASE;
break;
+ case 's':
+ str = uuid_guid_get_str(addr);
+ if (str)
+ return string(buf, end, str,
+ field_width, precision, flags);
+ str_format = UUID_STR_FORMAT_GUID;
+ break;
default:
str_format = UUID_STR_FORMAT_STD;
break;