ucx/dlist.c

changeset 22
76cdd8209f1f
parent 18
69636f81db31
child 27
22644e2572bc
--- a/ucx/dlist.c	Sat Jan 14 13:07:18 2012 +0100
+++ b/ucx/dlist.c	Sun Jan 15 14:12:34 2012 +0100
@@ -45,6 +45,7 @@
     nl->data = data;
     nl->next = NULL;
     if (l == NULL) {
+        nl->prev = NULL;
         return nl;
     } else {
         UcxDlist *t = ucx_dlist_last(l);
@@ -113,9 +114,11 @@
 
 void ucx_dlist_foreach(UcxDlist *l, ucx_callback fnc, void* data) {
     UcxDlist *e = l;
+    UcxDlist *n;
     while (e != NULL) {
+        n = e->next;
         fnc(e, data);
-        e = e->next;
+        e = n;
     }
 }
 
@@ -129,3 +132,15 @@
     }
     return e;
 }
+
+UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {
+    if (e->prev == NULL) {
+        e->next->prev = NULL;
+        l = e->next;
+    } else {
+        e->prev->next = e->next;
+        e->next->prev = e->prev;
+    }
+    free(e);
+    return l;
+}

mercurial