mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-28 16:48:18 +00:00
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 <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
fbb3ea806f
commit
1dde0d57a5
7 changed files with 27 additions and 23 deletions
|
@ -13,29 +13,29 @@
|
||||||
#define MAX_UTF8_PER_UTF16 3
|
#define MAX_UTF8_PER_UTF16 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* utf16_strlen() - Get the length of an utf16 string
|
* u16_strlen - count non-zero words
|
||||||
*
|
*
|
||||||
* Returns the number of 16 bit characters in an utf16 string, not
|
* This function matches wsclen() if the -fshort-wchar compiler flag is set.
|
||||||
* including the terminating NULL character.
|
* In the EFI context we explicitly need a function handling u16 strings.
|
||||||
*
|
*
|
||||||
* @in the string to measure
|
* @in: null terminated u16 string
|
||||||
* @return the string length
|
* ReturnValue: number of non-zero words.
|
||||||
|
* This is not the number of utf-16 letters!
|
||||||
*/
|
*/
|
||||||
size_t utf16_strlen(const uint16_t *in);
|
size_t u16_strlen(const u16 *in);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* utf16_strnlen() - Get the length of a fixed-size utf16 string.
|
* u16_strlen - count non-zero words
|
||||||
*
|
*
|
||||||
* Returns the number of 16 bit characters in an utf16 string,
|
* This function matches wscnlen_s() if the -fshort-wchar compiler flag is set.
|
||||||
* not including the terminating NULL character, but at most
|
* In the EFI context we explicitly need a function handling u16 strings.
|
||||||
* 'count' number of characters. In doing this, utf16_strnlen()
|
|
||||||
* looks at only the first 'count' characters.
|
|
||||||
*
|
*
|
||||||
* @in the string to measure
|
* @in: null terminated u16 string
|
||||||
* @count the maximum number of characters to count
|
* @count: maximum number of words to count
|
||||||
* @return the string length, up to a maximum of 'count'
|
* ReturnValue: number of non-zero words.
|
||||||
|
* This is not the number of utf-16 letters!
|
||||||
*/
|
*/
|
||||||
size_t utf16_strnlen(const uint16_t *in, size_t count);
|
size_t u16_strnlen(const u16 *in, size_t count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* utf16_strcpy() - UTF16 equivalent of strcpy()
|
* utf16_strcpy() - UTF16 equivalent of strcpy()
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
* utf8/utf16 conversion mostly lifted from grub
|
* utf8/utf16 conversion mostly lifted from grub
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t utf16_strlen(const uint16_t *in)
|
size_t u16_strlen(const u16 *in)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; in[i]; i++);
|
for (i = 0; in[i]; i++);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t utf16_strnlen(const uint16_t *in, size_t count)
|
size_t u16_strnlen(const u16 *in, size_t count)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; count-- && in[i]; i++);
|
for (i = 0; count-- && in[i]; i++);
|
||||||
|
@ -39,7 +39,11 @@ uint16_t *utf16_strcpy(uint16_t *dest, const uint16_t *src)
|
||||||
uint16_t *utf16_strdup(const uint16_t *s)
|
uint16_t *utf16_strdup(const uint16_t *s)
|
||||||
{
|
{
|
||||||
uint16_t *new;
|
uint16_t *new;
|
||||||
if (!s || !(new = malloc((utf16_strlen(s) + 1) * 2)))
|
|
||||||
|
if (!s)
|
||||||
|
return NULL;
|
||||||
|
new = malloc((u16_strlen(s) + 1) * 2);
|
||||||
|
if (!new)
|
||||||
return NULL;
|
return NULL;
|
||||||
utf16_strcpy(new, s);
|
utf16_strcpy(new, s);
|
||||||
return new;
|
return new;
|
||||||
|
|
|
@ -60,7 +60,7 @@ static void parse_load_option(struct load_option *lo, void *ptr)
|
||||||
ptr += sizeof(u16);
|
ptr += sizeof(u16);
|
||||||
|
|
||||||
lo->label = ptr;
|
lo->label = ptr;
|
||||||
ptr += (utf16_strlen(lo->label) + 1) * 2;
|
ptr += (u16_strlen(lo->label) + 1) * 2;
|
||||||
|
|
||||||
lo->file_path = ptr;
|
lo->file_path = ptr;
|
||||||
ptr += lo->file_path_length;
|
ptr += lo->file_path_length;
|
||||||
|
|
|
@ -114,7 +114,7 @@ static efi_status_t EFIAPI efi_cout_output_string(
|
||||||
|
|
||||||
EFI_ENTRY("%p, %p", this, string);
|
EFI_ENTRY("%p, %p", this, string);
|
||||||
|
|
||||||
unsigned int n16 = utf16_strlen(string);
|
unsigned int n16 = u16_strlen(string);
|
||||||
char buf[MAX_UTF8_PER_UTF16 * n16 + 1];
|
char buf[MAX_UTF8_PER_UTF16 * n16 + 1];
|
||||||
u16 *p;
|
u16 *p;
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ static struct efi_file_handle *file_open(struct file_system *fs,
|
||||||
|
|
||||||
if (file_name) {
|
if (file_name) {
|
||||||
utf16_to_utf8((u8 *)f0, (u16 *)file_name, 1);
|
utf16_to_utf8((u8 *)f0, (u16 *)file_name, 1);
|
||||||
flen = utf16_strlen((u16 *)file_name);
|
flen = u16_strlen((u16 *)file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we could have a parent, but also an absolute path: */
|
/* we could have a parent, but also an absolute path: */
|
||||||
|
|
|
@ -106,7 +106,7 @@ static efi_status_t efi_to_native(char *native, u16 *variable_name,
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = utf16_strlen((u16 *)variable_name);
|
len = u16_strlen((u16 *)variable_name);
|
||||||
if (len >= MAX_VAR_NAME)
|
if (len >= MAX_VAR_NAME)
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,7 @@ static char *string16(char *buf, char *end, u16 *s, int field_width,
|
||||||
int precision, int flags)
|
int precision, int flags)
|
||||||
{
|
{
|
||||||
u16 *str = s ? s : L"<NULL>";
|
u16 *str = s ? s : L"<NULL>";
|
||||||
int utf16_len = utf16_strnlen(str, precision);
|
int utf16_len = u16_strnlen(str, precision);
|
||||||
u8 utf8[utf16_len * MAX_UTF8_PER_UTF16];
|
u8 utf8[utf16_len * MAX_UTF8_PER_UTF16];
|
||||||
int utf8_len, i;
|
int utf8_len, i;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue