From a582d087ba99b9f4705eda48c063253384f67888 Mon Sep 17 00:00:00 2001 From: venaas Date: Wed, 4 Jun 2008 09:47:10 +0000 Subject: made list_removedata() remove all occurences git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@280 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- list.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/list.c b/list.c index 2b8f34a..99d4e13 100644 --- a/list.c +++ b/list.c @@ -63,29 +63,32 @@ void *list_shift(struct list *list) { return data; } -/* removes first entry with matching data pointer */ +/* removes all entries with matching data pointer */ void list_removedata(struct list *list, void *data) { struct list_node *node, *t; - if (!list->first) + if (!list || !list->first) return; node = list->first; - if (node->data == data) { + while (node->data == data) { list->first = node->next; - if (!list->first) - list->last = NULL; free(node); - return; + node = list->first; + if (!node) { + list->last = NULL; + return; + } } for (; node->next; node = node->next) if (node->next->data == data) { t = node->next; - node->next = node->next->next; - if (!node->next) /* we removed the last one */ - list->last = node; + node->next = t->next; free(t); - return; + if (!node->next) { /* we removed the last one */ + list->last = node; + return; + } } } -- cgit v1.1