Skip to content

Commit 19aa8c0

Browse files
committed
libudev-list: use strdup_to()
No functional change, just refactoring.
1 parent 3e8a4de commit 19aa8c0

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/libudev/libudev-list.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,21 @@ struct udev_list *udev_list_new(bool unique) {
7272
return list;
7373
}
7474

75-
struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *_name, const char *_value) {
75+
struct udev_list_entry* udev_list_entry_add(struct udev_list *list, const char *name, const char *value) {
7676
_cleanup_(udev_list_entry_freep) struct udev_list_entry *entry = NULL;
77-
_cleanup_free_ char *name = NULL, *value = NULL;
7877

7978
assert(list);
80-
assert(_name);
79+
assert(name);
8180

82-
name = strdup(_name);
83-
if (!name)
81+
entry = new0(struct udev_list_entry, 1);
82+
if (!entry)
8483
return NULL;
8584

86-
if (_value) {
87-
value = strdup(_value);
88-
if (!value)
89-
return NULL;
90-
}
91-
92-
entry = new(struct udev_list_entry, 1);
93-
if (!entry)
85+
if (strdup_to(&entry->name, name) < 0)
9486
return NULL;
9587

96-
*entry = (struct udev_list_entry) {
97-
.name = TAKE_PTR(name),
98-
.value = TAKE_PTR(value),
99-
};
88+
if (strdup_to(&entry->value, value) < 0)
89+
return NULL;
10090

10191
if (list->unique) {
10292
udev_list_entry_free(hashmap_get(list->unique_entries, entry->name));

0 commit comments

Comments
 (0)