[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 14/16] fs/fat: Simplify to use grub_utf16_to_utf8_alloc()
From: |
Vitaly Kuzmichev |
Subject: |
[PATCH v5 14/16] fs/fat: Simplify to use grub_utf16_to_utf8_alloc() |
Date: |
Tue, 22 Aug 2023 23:39:22 +0200 |
Transform grub_fat_label() function to use grub_utf16_to_utf8_alloc()
helper function to convert volume label from UTF-16 to UTF-8.
Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmichev@rtsoft.de>
---
grub-core/fs/fat.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
index 24d0b629b..64e9be80d 100644
--- a/grub-core/fs/fat.c
+++ b/grub-core/fs/fat.c
@@ -1157,23 +1157,19 @@ grub_fat_label (grub_device_t device, char **label)
/* Volume label. */
if (dir.entry_type == 0x83)
{
+ grub_uint8_t *p;
grub_size_t chc;
- grub_uint16_t t[ARRAY_SIZE (dir.type_specific.volume_label.str)];
- grub_size_t i;
- *label = grub_malloc (ARRAY_SIZE (dir.type_specific.volume_label.str)
- * GRUB_MAX_UTF8_PER_UTF16 + 1);
- if (!*label)
+
+ chc = grub_min(dir.type_specific.volume_label.character_count,
+ ARRAY_SIZE (dir.type_specific.volume_label.str));
+ p = grub_utf16_to_utf8_alloc (dir.type_specific.volume_label.str,
+ chc, UTF16_LE);
+ if (!p)
{
grub_free (root.data);
return grub_errno;
}
- chc = dir.type_specific.volume_label.character_count;
- if (chc > ARRAY_SIZE (dir.type_specific.volume_label.str))
- chc = ARRAY_SIZE (dir.type_specific.volume_label.str);
- for (i = 0; i < chc; i++)
- t[i] = grub_le_to_cpu16 (dir.type_specific.volume_label.str[i]);
- *grub_utf16_to_utf8 ((grub_uint8_t *) *label, t,
- chc, UTF16_CPU) = '\0';
+ *label = (char *) p;
}
}
--
2.34.1
- [PATCH v5 05/16] commands/search: Add support to search by partition PARTUUID, (continued)
- [PATCH v5 05/16] commands/search: Add support to search by partition PARTUUID, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 10/16] commands/search: Add support to search by partition PARTLABEL, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 13/16] fs/f2fs: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 07/16] include/grub/charset.h: Add grub_utf16_{strlen, strnlen}(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 06/16] include/grub/charset.h: Enhance grub_utf16_to_utf8(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 14/16] fs/fat: Simplify to use grub_utf16_to_utf8_alloc(),
Vitaly Kuzmichev <=
- [PATCH v5 08/16] include/grub/charset.h: Add grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 15/16] fs/iso9660: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 09/16] partmap/gpt: Add grub_gpt_partition_get_label(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 16/16] fs/ntfs: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22