[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 13/16] fs/f2fs: Simplify to use grub_utf16_to_utf8_alloc()
From: |
Vitaly Kuzmichev |
Subject: |
[PATCH v5 13/16] fs/f2fs: Simplify to use grub_utf16_to_utf8_alloc() |
Date: |
Tue, 22 Aug 2023 23:39:21 +0200 |
Transform grub_f2fs_utf16_to_utf8() 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/f2fs.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
index 429a3db83..827a8c196 100644
--- a/grub-core/fs/f2fs.c
+++ b/grub-core/fs/f2fs.c
@@ -1251,25 +1251,10 @@ grub_f2fs_close (grub_file_t file)
return GRUB_ERR_NONE;
}
-static grub_uint8_t *
-grub_f2fs_utf16_to_utf8 (grub_uint16_t *in_buf_le)
+static char *
+grub_f2fs_utf16_to_utf8 (grub_uint16_t *in_buf_le, grub_size_t len)
{
- grub_uint16_t in_buf[MAX_VOLUME_NAME];
- grub_uint8_t *out_buf;
- int len = 0;
-
- out_buf = grub_malloc (MAX_VOLUME_NAME * GRUB_MAX_UTF8_PER_UTF16 + 1);
- if (!out_buf)
- return NULL;
-
- while (*in_buf_le != 0 && len < MAX_VOLUME_NAME) {
- in_buf[len] = grub_le_to_cpu16 (in_buf_le[len]);
- len++;
- }
-
- *grub_utf16_to_utf8 (out_buf, in_buf, len, UTF16_CPU) = '\0';
-
- return out_buf;
+ return (char *) grub_utf16_to_utf8_alloc (in_buf_le, len, UTF16_LE);
}
#if __GNUC__ >= 9
@@ -1287,7 +1272,8 @@ grub_f2fs_label (grub_device_t device, char **label)
data = grub_f2fs_mount (disk);
if (data)
- *label = (char *) grub_f2fs_utf16_to_utf8 (data->sblock.volume_name);
+ *label = grub_f2fs_utf16_to_utf8 (data->sblock.volume_name,
+ MAX_VOLUME_NAME);
else
*label = NULL;
--
2.34.1
- [PATCH v5 01/16] partmap/gpt: Add grub_gpt_partition_get_uuid(), (continued)
- [PATCH v5 03/16] commands/probe: Simplify 'probe --part-uuid' command, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 11/16] commands/probe: Add command option to display partition PARTLABEL, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 12/16] docs/grub.texi: Update documentation for 'probe' and 'search' commands, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 04/16] include/grub/misc.h: Fix edge case in grub_uuidcasecmp(), Vitaly Kuzmichev, 2023/08/22
- [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 <=
- [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, 2023/08/22
- [PATCH v5 08/16] include/grub/charset.h: Add grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22