/* * Releases all the nodes in the list. */ void collections_list_release(collections_listnode *start) { collections_release_data data_free = ((collections_header_data*)start->data)->data_free; collections_listnode* cur = start->next; // // travel through the rest of the // list and release all the nodes. // while (cur != start) { void * data = cur->data; if (data != NULL && data_free) { data_free(data); } list_destroy_node(start, cur); cur = start->next; } // // release the header. // free(start->data); free(start); return; }
void list_destroy(struct list *l) { if ((NULL != l) && (0 < list_length(l))) { while (NULL != list_head_node(l)) { struct node *h = list_pop(l); list_destroy_node(l, &h); } } l->dummy.next = &(l->dummy); l->dummy.prev = &(l->dummy); }
void * collections_list_remove_if(collections_listnode *start, collections_list_predicate p, void *arg) { collections_listnode *cur = start->next; while (cur != start) { if (p(cur->data, arg)) { void *data = cur->data; list_destroy_node(start, cur); return data; } cur = cur->next; } return NULL; }
/** * Process the removal of one product from the inventory. * * @return SUCCESS on success, else -1 */ static int do_rm(void) { Product *p = NULL; char bc[BARCODE_SZ] = {0}; struct node *np = NULL; // recv barcode RECV(STDIN, bc, BARCODE_SZ); // find product in inventory with matching barcode np = list_find_node_with_data(&inv, prod_has_bc, (void *)bc); // if not found, return -1 if (NULL == np) return -1; // delete product from inventory list_remove_node(&inv, np); // destroy product list_destroy_node(&inv, &np); return SUCCESS; }
void list_destroy(list_t * new_list) { list_node_t *iter = NULL; list_node_t *next = NULL; return_if_fail(new_list != NULL); dlist_lock(new_list); iter = new_list->head.next; while (iter != &new_list->head) { next = iter->next; list_destroy_node(new_list, iter); iter = next; } new_list->head.next = &new_list->head; new_list->head.prev = &new_list->head; dlist_destroy_locker(new_list); SAFE_FREE(new_list); return; }
static inline void list_del_and_destroy_node(list_t * list, list_node_t * entry) { list_delete(entry); list_destroy_node(list, entry); }