From 4ddcc4e5d28b80eacbcc97f67218a9ce5a326963 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 31 Aug 2018 21:31:23 +0200 Subject: vsprintf.c: use #if CONFIG_IS_ENABLED(EFI_LOADER) Using CONFIG_IS_ENABLED(EFI_LOADER) allows to simply the #if statements. Suggested-by: Alexander Graf Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- lib/vsprintf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/vsprintf.c') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 914fbd30cbc..ef8b0b59895 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -294,8 +294,8 @@ static char *string16(char *buf, char *end, u16 *s, int field_width, return buf; } -#if defined(CONFIG_EFI_LOADER) && \ - !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD) +/* Device paths only exist in the EFI context. */ +#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD) static char *device_path_string(char *buf, char *end, void *dp, int field_width, int precision, int flags) { @@ -450,8 +450,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, #endif switch (*fmt) { -#if defined(CONFIG_EFI_LOADER) && \ - !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD) +/* Device paths only exist in the EFI context. */ +#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD) case 'D': return device_path_string(buf, end, ptr, field_width, precision, flags); -- cgit v1.2.3 From fbb3ea806f62b7e27bbae86c42d8f73f05de4bd7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 31 Aug 2018 21:31:25 +0200 Subject: lib: build charset.o only if needed charset.o is only needed for the EFI subsystem Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- lib/vsprintf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/vsprintf.c') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index ef8b0b59895..632796f864d 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -274,6 +274,8 @@ static char *string(char *buf, char *end, char *s, int field_width, return buf; } +/* U-Boot uses UTF-16 strings in the EFI context only. */ +#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD) static char *string16(char *buf, char *end, u16 *s, int field_width, int precision, int flags) { @@ -294,8 +296,6 @@ static char *string16(char *buf, char *end, u16 *s, int field_width, return buf; } -/* Device paths only exist in the EFI context. */ -#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD) static char *device_path_string(char *buf, char *end, void *dp, int field_width, int precision, int flags) { @@ -612,10 +612,14 @@ repeat: continue; case 's': - if (qualifier == 'l' && !IS_ENABLED(CONFIG_SPL_BUILD)) { +/* U-Boot uses UTF-16 strings in the EFI context only. */ +#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD) + if (qualifier == 'l') { str = string16(str, end, va_arg(args, u16 *), field_width, precision, flags); - } else { + } else +#endif + { str = string(str, end, va_arg(args, char *), field_width, precision, flags); } -- cgit v1.2.3 From 1dde0d57a5d1281aaa949e9bf7b5c476345a56ee Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 31 Aug 2018 21:31:26 +0200 Subject: efi_loader: rename utf16_strlen, utf16_strnlen The function names utf16_strlen() and utf16_strnlen() are misnomers. The functions do not count utf-16 characters but non-zero words. So let's rename them to u16_strlen and u16_strnlen(). In utf16_dup() avoid assignment in if clause. Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- lib/vsprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/vsprintf.c') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 632796f864d..5abf7347504 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -280,7 +280,7 @@ static char *string16(char *buf, char *end, u16 *s, int field_width, int precision, int flags) { u16 *str = s ? s : L""; - int utf16_len = utf16_strnlen(str, precision); + int utf16_len = u16_strnlen(str, precision); u8 utf8[utf16_len * MAX_UTF8_PER_UTF16]; int utf8_len, i; -- cgit v1.2.3 From 31bd711cd03dde22484cf647b9abe498ae1b0c5f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 31 Aug 2018 21:31:29 +0200 Subject: lib: vsprintf: correct printing of Unicode strings The width and precision of the printf() function refer to the number of characters not to the number of bytes printed. Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- lib/vsprintf.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'lib/vsprintf.c') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 5abf7347504..4213441fbf7 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -280,18 +280,13 @@ static char *string16(char *buf, char *end, u16 *s, int field_width, int precision, int flags) { u16 *str = s ? s : L""; - int utf16_len = u16_strnlen(str, precision); - u8 utf8[utf16_len * MAX_UTF8_PER_UTF16]; - int utf8_len, i; - - utf8_len = utf16_to_utf8(utf8, str, utf16_len) - utf8; + ssize_t len = utf16_strnlen(str, precision); if (!(flags & LEFT)) - while (utf8_len < field_width--) + for (; len < field_width; --field_width) ADDCH(buf, ' '); - for (i = 0; i < utf8_len; ++i) - ADDCH(buf, utf8[i]); - while (utf8_len < field_width--) + utf16_utf8_strncpy(&buf, str, len); + for (; len < field_width; --field_width) ADDCH(buf, ' '); return buf; } -- cgit v1.2.3