- void_list_elt_t *prior;
- void_list_elt_t *old_elt = NULL;
- void *old_data = NULL;
-
- if (!list) {
- fprintf(stderr, "Error: void_list_remove_elt list is NULL\n");
- return NULL;
- }
- if (!target_data) {
- fprintf(stderr, "Error: void_list_remove_elt target_data is NULL\n");
- return NULL;
- }
-
- /* first element */
- if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
- old_elt = list->head;
- old_data = list->head->data;
- void_list_pop(list);
- } else {
- int found = 0;
- for (prior = list->head; prior && prior->next; prior = prior->next) {
- if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
- old_elt = prior->next;
- old_data = old_elt->data;
- found = 1;
- break;
- }
- }
- if (!found) {
- return NULL;
- }
- prior->next = old_elt->next;
-
- if (old_elt == list->tail) {
- list->tail = prior;
- }
- }
- if (old_elt)
- void_list_elt_deinit(old_elt);
-
- if (old_data)
- return old_data;
- else
- return NULL;
+ struct list_head *elt;
+ if (!list)
+ return NULL;
+ elt = list->head.prev;
+ if (elt == &list->head) {
+ return NULL;
+ }
+ return list_entry(elt, void_list_elt_t, node);