- list_node_t *res;
-
- if(!list)
- return NULL;
- if(!idx)
- return NULL;
-
- if(list->callbacks->delete != NULL)
- if(list->callbacks->delete(idx->data))
- syslog(LOG_WARNING, _("List callback[delete] failed for %08lx - freeing anyway"), idx->data);
-
- free(idx->data);
-
- if(idx->prev == NULL)
- /* First element in list */
- {
- res = idx->next;
- list->head = idx->next;
- }
- if(idx->next == NULL)
- /* Last element in list */
- {
- res = NULL;
- list->tail = idx->prev;
- }
- if(idx->prev != NULL && idx->next != NULL)
- /* Neither first nor last element */
- {
- idx->prev->next = idx->next;
- idx->next->prev = idx->prev;
- }
- if(list->head == NULL)
- list->tail = NULL;
- else
- if(list->tail == NULL)
- list->head = NULL;
- free(idx);
- return res;
+ list_node_t *node;
+
+ node = list_alloc_node();
+
+ node->data = data;
+ node->prev = NULL;
+ node->next = list->head;
+ list->head = node;
+
+ if(node->next)
+ node->next->prev = node;
+ else
+ list->tail = node;
+
+ list->count++;
+
+ return node;