(((_dp)->type == DEVICE_PATH_TYPE_##_type) && \
((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))
-/**
- * ascii2unicode() - convert ASCII string to UTF-16 string
- *
- * A zero terminated ASCII string is converted to a zero terminated UTF-16
- * string. The output buffer must be preassigned.
- *
- * @unicode: preassigned output buffer for UTF-16 string
- * @ascii: ASCII string to be converted
- */
-static inline void ascii2unicode(u16 *unicode, const char *ascii)
-{
- while (*ascii)
- *(unicode++) = *(ascii++);
- *unicode = 0;
-}
-
static inline int guidcmp(const void *g1, const void *g2)
{
return memcmp(g1, g2, sizeof(efi_guid_t));
static u16 *efi_str_to_u16(char *str)
{
efi_uintn_t len;
- u16 *out;
+ u16 *out, *dst;
efi_status_t ret;
- len = strlen(str) + 1;
- ret = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, len * sizeof(u16),
- (void **)&out);
+ len = sizeof(u16) * (utf8_utf16_strlen(str) + 1);
+ ret = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, len, (void **)&out);
if (ret != EFI_SUCCESS)
return NULL;
- ascii2unicode(out, str);
+ dst = out;
+ utf8_utf16_strcpy(&dst, str);
return out;
}
struct efi_file_info *info = buffer;
struct fs_dirent *dent;
unsigned int required_size;
+ u16 *dst;
if (!fh->dirs) {
assert(fh->offset == 0);
}
/* check buffer size: */
- required_size = sizeof(*info) + 2 * (strlen(dent->name) + 1);
+ required_size = sizeof(*info) +
+ 2 * (utf8_utf16_strlen(dent->name) + 1);
if (*buffer_size < required_size) {
*buffer_size = required_size;
fh->dent = dent;
if (dent->type == FS_DT_DIR)
info->attribute |= EFI_FILE_DIRECTORY;
- ascii2unicode(info->file_name, dent->name);
+ dst = info->file_name;
+ utf8_utf16_strcpy(&dst, dent->name);
fh->offset++;
{
struct file_handle *fh = to_fh(file);
efi_status_t ret = EFI_SUCCESS;
+ u16 *dst;
EFI_ENTRY("%p, %pUl, %p, %p", file, info_type, buffer_size, buffer);
loff_t file_size;
/* check buffer size: */
- required_size = sizeof(*info) + 2 * (strlen(filename) + 1);
+ required_size = sizeof(*info) +
+ 2 * (utf8_utf16_strlen(filename) + 1);
if (*buffer_size < required_size) {
*buffer_size = required_size;
ret = EFI_BUFFER_TOO_SMALL;
if (fh->isdir)
info->attribute |= EFI_FILE_DIRECTORY;
- ascii2unicode(info->file_name, filename);
+ dst = info->file_name;
+ utf8_utf16_strcpy(&dst, filename);
} else if (!guidcmp(info_type, &efi_file_system_info_guid)) {
struct efi_file_system_info *info = buffer;
disk_partition_t part;
ret = EFI_DEVICE_ERROR;
goto error;
}
- required_size = sizeof(info) + 2 *
- (strlen((const char *)part.name) + 1);
+ required_size = sizeof(*info) + 2 *
+ (utf8_utf16_strlen((const char *)part.name) +
+ 1);
if (*buffer_size < required_size) {
*buffer_size = required_size;
ret = EFI_BUFFER_TOO_SMALL;
* TODO: The volume label is not available in U-Boot.
* Use the partition name as substitute.
*/
- ascii2unicode((u16 *)info->volume_label,
- (const char *)part.name);
+ dst = info->volume_label;
+ utf8_utf16_strcpy(&dst, (const char *)part.name);
} else {
ret = EFI_UNSUPPORTED;
}