]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libudev-list: use strdup_to()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 12:10:16 +0000 (21:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 13:30:57 +0000 (22:30 +0900)
No functional change, just refactoring.

src/libudev/libudev-list.c

index a3e972b0ed515b56751f2385ccda27e45616a139..4cfc1f4c0877506d9a03e6375531102f0da64eaa 100644 (file)
@@ -72,31 +72,21 @@ struct udev_list *udev_list_new(bool unique) {
         return list;
 }
 
-struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *_name, const char *_value) {
+struct udev_list_entry* udev_list_entry_add(struct udev_list *list, const char *name, const char *value) {
         _cleanup_(udev_list_entry_freep) struct udev_list_entry *entry = NULL;
-        _cleanup_free_ char *name = NULL, *value = NULL;
 
         assert(list);
-        assert(_name);
+        assert(name);
 
-        name = strdup(_name);
-        if (!name)
+        entry = new0(struct udev_list_entry, 1);
+        if (!entry)
                 return NULL;
 
-        if (_value) {
-                value = strdup(_value);
-                if (!value)
-                        return NULL;
-        }
-
-        entry = new(struct udev_list_entry, 1);
-        if (!entry)
+        if (strdup_to(&entry->name, name) < 0)
                 return NULL;
 
-        *entry = (struct udev_list_entry) {
-                .name = TAKE_PTR(name),
-                .value = TAKE_PTR(value),
-        };
+        if (strdup_to(&entry->value, value) < 0)
+                return NULL;
 
         if (list->unique) {
                 udev_list_entry_free(hashmap_get(list->unique_entries, entry->name));