summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorvenaas <venaas>2008-06-04 09:47:10 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2008-06-04 09:47:10 +0000
commita582d087ba99b9f4705eda48c063253384f67888 (patch)
treea938d040080789f66277ce3f337a7c2a9e3262eb /list.c
parent3f6b6b2b4e0441d2c58bf285478cdee78bea4f05 (diff)
made list_removedata() remove all occurences
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@280 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'list.c')
-rw-r--r--list.c23
1 files 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;
+ }
}
}