]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (script) improve separator usage in named-fields dump
authorKarel Zak <kzak@redhat.com>
Wed, 3 Sep 2025 09:30:57 +0000 (11:30 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Sep 2025 09:30:57 +0000 (11:30 +0200)
Ensure that name=value pairs are separated by commas.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/script.c

index 098a42f25dcc5b2cee0841b408a2ec3848103751..62ca5eeb2a2e983507ccbc61cd1ca4a09f9f7f12 100644 (file)
@@ -691,30 +691,36 @@ static int write_file_sfdisk(struct fdisk_script *dp, FILE *f)
        fdisk_reset_iter(&itr, FDISK_ITER_FORWARD);
        while (fdisk_table_next_partition(dp->table, &itr, &pa) == 0) {
                char *p = NULL;
+               int sep = 0;
 
                if (devname)
                        p = fdisk_partname(devname, pa->partno + 1);
                if (p) {
                        DBG(SCRIPT, ul_debugobj(dp, "write %s entry", p));
-                       fprintf(f, "%s :", p);
+                       fprintf(f, "%s : ", p);
                        free(p);
                } else
-                       fprintf(f, "%zu :", pa->partno + 1);
+                       fprintf(f, "%zu : ", pa->partno + 1);
 
                if (fdisk_partition_has_start(pa))
-                       fprintf(f, " start=%12ju", (uintmax_t)pa->start);
+                       sep = fprintf(f, "start=%12ju", (uintmax_t)pa->start);
                if (fdisk_partition_has_size(pa))
-                       fprintf(f, ", size=%12ju", (uintmax_t)pa->size);
+                       sep = fprintf(f, "%ssize=%12ju",
+                                       sep ? ", " : " ", (uintmax_t)pa->size);
 
                if (pa->type && fdisk_parttype_get_string(pa->type))
-                       fprintf(f, ", type=%s", fdisk_parttype_get_string(pa->type));
+                       sep = fprintf(f, "%stype=%s",
+                                       sep ? ", " : " ",
+                                       fdisk_parttype_get_string(pa->type));
                else if (pa->type)
-                       fprintf(f, ", type=%x", fdisk_parttype_get_code(pa->type));
+                       sep = fprintf(f, "%stype=%x",
+                                       sep ? ", " : " ",
+                                       fdisk_parttype_get_code(pa->type));
 
                if (pa->uuid)
-                       fprintf(f, ", uuid=%s", pa->uuid);
+                       sep = fprintf(f, "%suuid=%s", sep ? ", " : " ", pa->uuid);
                if (pa->name && *pa->name) {
-                       fputs(", name=", f);
+                       sep = fprintf(f, "%sname=", sep ? ", " : " ");
                        fputs_quoted(pa->name, f);
                }
 
@@ -723,10 +729,12 @@ static int write_file_sfdisk(struct fdisk_script *dp, FILE *f)
                        struct fdisk_label *lb = script_get_label(dp);
 
                        if (!lb || fdisk_label_get_type(lb) != FDISK_DISKLABEL_DOS)
-                               fprintf(f, ", attrs=\"%s\"", pa->attrs);
+                               sep = fprintf(f, "%sattrs=\"%s\"",
+                                               sep ? ", " : " ",
+                                               pa->attrs);
                }
                if (fdisk_partition_is_bootable(pa))
-                       fprintf(f, ", bootable");
+                       sep = fprintf(f, "%sbootable", sep ? ", " : " ");
                fputc('\n', f);
        }