]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: return bytes processed from gpt_entry_set_name(), process rc
authorVaclav Dolezal <vdolezal@redhat.com>
Tue, 19 Dec 2017 09:39:19 +0000 (10:39 +0100)
committerVaclav Dolezal <vdolezal@redhat.com>
Tue, 19 Dec 2017 09:48:13 +0000 (10:48 +0100)
Made gpt_entry_set_name() return number of utf8 bytes processed on
success, so info message about change can be accurate.

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
libfdisk/src/gpt.c

index 8598dbd2e097778ecdcb77a467ec2e7fcd52f2f3..543b971995a8c6fd4106f15fb7b43b07a8f939b6 100644 (file)
@@ -420,7 +420,7 @@ static int gpt_entry_set_name(struct gpt_entry *e, char *str)
        for (i = 0; i < GPT_PART_NAME_LEN; i++)
                e->name[i] = cpu_to_le16(name[i]);
 
-       return 0;
+       return (int)((char *) in - str);
 }
 
 static int gpt_entry_set_uuid(struct gpt_entry *e, char *str)
@@ -1900,11 +1900,14 @@ static int gpt_set_partition(struct fdisk_context *cxt, size_t n,
        }
 
        if (pa->name) {
+               int len;
                char *old = encode_to_utf8((unsigned char *)e->name, sizeof(e->name));
-               gpt_entry_set_name(e, pa->name);
-
-               fdisk_info(cxt, _("Partition name changed from '%s' to '%.*s'."),
-                       old, (int) GPT_PART_NAME_LEN, pa->name);
+               len = gpt_entry_set_name(e, pa->name);
+               if (len < 0)
+                       fdisk_info(cxt, _("Failed to translate partition name, name not changed."));
+               else
+                       fdisk_info(cxt, _("Partition name changed from '%s' to '%.*s'."),
+                               old, len, pa->name);
                free(old);
        }