- struct udev_list_entry *entry;
- int i = 0;
-
- if (list->unique) {
- /* lookup existing name or insertion-index */
- i = list_search(list, name);
- if (i >= 0) {
- entry = list->entries[i];
-
- dbg(list->udev, "'%s' is already in the list\n", name);
- free(entry->value);
- if (value == NULL) {
- entry->value = NULL;
- dbg(list->udev, "'%s' value unset\n", name);
- return entry;
- }
- entry->value = strdup(value);
- if (entry->value == NULL)
- return NULL;
- dbg(list->udev, "'%s' value replaced with '%s'\n", name, value);
- return entry;
- }
- }
-
- /* add new name */
- entry = calloc(1, sizeof(struct udev_list_entry));
- if (entry == NULL)
- return NULL;
- entry->name = strdup(name);
- if (entry->name == NULL) {
- free(entry);
- return NULL;
- }
- if (value != NULL) {
- entry->value = strdup(value);
- if (entry->value == NULL) {
- free(entry->name);
- free(entry);
- return NULL;
- }
- }
-
- if (list->unique) {
- /* allocate or enlarge sorted array if needed */
- if (list->entries_cur >= list->entries_max) {
- unsigned int add;
-
- add = list->entries_max;
- if (add < 1)
- add = 64;
- list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
- if (list->entries == NULL) {
- free(entry->name);
- free(entry->value);
- return NULL;
- }
- list->entries_max += add;
- }
-
- /* the negative i returned the insertion index */
- i = (-i)-1;
-
- /* insert into sorted list */
- if ((unsigned int)i < list->entries_cur)
- udev_list_entry_insert_before(entry, list->entries[i]);
- else
- udev_list_entry_append(entry, list);
-
- /* insert into sorted array */
- memmove(&list->entries[i+1], &list->entries[i],
- (list->entries_cur - i) * sizeof(struct udev_list_entry *));
- list->entries[i] = entry;
- list->entries_cur++;
- } else {
- udev_list_entry_append(entry, list);
- }
-
- dbg(list->udev, "'%s=%s' added\n", entry->name, entry->value);
- return entry;
+ struct udev_list_entry *entry;
+ int i = 0;
+
+ if (list->unique) {
+ /* lookup existing name or insertion-index */
+ i = list_search(list, name);
+ if (i >= 0) {
+ entry = list->entries[i];
+
+ dbg(list->udev, "'%s' is already in the list\n", name);
+ free(entry->value);
+ if (value == NULL) {
+ entry->value = NULL;
+ dbg(list->udev, "'%s' value unset\n", name);
+ return entry;
+ }
+ entry->value = strdup(value);
+ if (entry->value == NULL)
+ return NULL;
+ dbg(list->udev, "'%s' value replaced with '%s'\n", name, value);
+ return entry;
+ }
+ }
+
+ /* add new name */
+ entry = calloc(1, sizeof(struct udev_list_entry));
+ if (entry == NULL)
+ return NULL;
+ entry->name = strdup(name);
+ if (entry->name == NULL) {
+ free(entry);
+ return NULL;
+ }
+ if (value != NULL) {
+ entry->value = strdup(value);
+ if (entry->value == NULL) {
+ free(entry->name);
+ free(entry);
+ return NULL;
+ }
+ }
+
+ if (list->unique) {
+ /* allocate or enlarge sorted array if needed */
+ if (list->entries_cur >= list->entries_max) {
+ unsigned int add;
+
+ add = list->entries_max;
+ if (add < 1)
+ add = 64;
+ list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
+ if (list->entries == NULL) {
+ free(entry->name);
+ free(entry->value);
+ return NULL;
+ }
+ list->entries_max += add;
+ }
+
+ /* the negative i returned the insertion index */
+ i = (-i)-1;
+
+ /* insert into sorted list */
+ if ((unsigned int)i < list->entries_cur)
+ udev_list_entry_insert_before(entry, list->entries[i]);
+ else
+ udev_list_entry_append(entry, list);
+
+ /* insert into sorted array */
+ memmove(&list->entries[i+1], &list->entries[i],
+ (list->entries_cur - i) * sizeof(struct udev_list_entry *));
+ list->entries[i] = entry;
+ list->entries_cur++;
+ } else {
+ udev_list_entry_append(entry, list);
+ }
+
+ dbg(list->udev, "'%s=%s' added\n", entry->name, entry->value);
+ return entry;