/** * g_list_remove_all: * @list: a #GList, this must point to the top of the list * @data: data to remove * * Removes all list nodes with data equal to @data. * Returns the new head of the list. Contrast with * g_list_remove() which removes only the first node * matching the given data. * * Returns: the (possibly changed) start of the #GList */ GList * g_list_remove_all (GList *list, gconstpointer data) { GList *tmp = list; while (tmp) { if (tmp->data != data) tmp = tmp->next; else { GList *next = tmp->next; if (tmp->prev) tmp->prev->next = next; else list = next; if (next) next->prev = tmp->prev; _g_list_free1 (tmp); tmp = next; } } return list; }
/** * g_list_remove: * @list: a #GList * @data: the data of the element to remove * * Removes an element from a #GList. * If two elements contain the same data, only the first is removed. * If none of the elements contain the data, the #GList is unchanged. * * Returns: the new start of the #GList */ GList* g_list_remove (GList *list, gconstpointer data) { GList *tmp; tmp = list; while (tmp) { if (tmp->data != data) tmp = tmp->next; else { if (tmp->prev) tmp->prev->next = tmp->next; if (tmp->next) tmp->next->prev = tmp->prev; if (list == tmp) list = list->next; _g_list_free1 (tmp); break; } } return list; }
/** * g_list_delete_link: * @list: a #GList, this must point to the top of the list * @link_: node to delete from @list * * Removes the node link_ from the list and frees it. * Compare this to g_list_remove_link() which removes the node * without freeing it. * * Returns: the (possibly changed) start of the #GList */ GList * g_list_delete_link (GList *list, GList *link_) { list = _g_list_remove_link (list, link_); _g_list_free1 (link_); return list; }
/** * g_list_remove: * @list: a #GList, this must point to the top of the list * @data: the data of the element to remove * * Removes an element from a #GList. * If two elements contain the same data, only the first is removed. * If none of the elements contain the data, the #GList is unchanged. * * Returns: the (possibly changed) start of the #GList */ GList * g_list_remove (GList *list, gconstpointer data) { GList *tmp; tmp = list; while (tmp) { if (tmp->data != data) tmp = tmp->next; else { list = _g_list_remove_link (list, tmp); _g_list_free1 (tmp); break; } } return list; }
/** * g_list_free1: * * Another name for g_list_free_1(). **/ void g_list_free_1 (GList *list) { _g_list_free1 (list); }