]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: modernize set_gpt_flags()
authorLennart Poettering <lennart@poettering.net>
Thu, 9 Jan 2025 10:17:40 +0000 (11:17 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 10 Jan 2025 07:08:07 +0000 (16:08 +0900)
src/repart/repart.c

index bed4fd92bc2d7ed81774eff341fccad5e726f8a1..2be7b0724689bda22fc1b0d3d120196fa046cef9 100644 (file)
@@ -6310,20 +6310,15 @@ static int context_acquire_partition_uuids_and_labels(Context *context) {
 
 static int set_gpt_flags(struct fdisk_partition *q, uint64_t flags) {
         _cleanup_free_ char *a = NULL;
+        int r;
 
-        for (unsigned i = 0; i < sizeof(flags) * 8; i++) {
-                uint64_t bit = UINT64_C(1) << i;
-                char buf[DECIMAL_STR_MAX(unsigned)+1];
-
-                if (!FLAGS_SET(flags, bit))
-                        continue;
-
-                xsprintf(buf, "%u", i);
-                if (!strextend_with_separator(&a, ",", buf))
-                        return -ENOMEM;
+        BIT_FOREACH(i, flags) {
+                r = strextendf_with_separator(&a, ",", "%i", i);
+                if (r < 0)
+                        return r;
         }
 
-        return fdisk_partition_set_attrs(q, a);
+        return fdisk_partition_set_attrs(q, strempty(a));
 }
 
 static uint64_t partition_merge_flags(Partition *p) {