added ucx_list_remove

Sun, 15 Jan 2012 14:20:25 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 15 Jan 2012 14:20:25 +0100
changeset 23
ccc294fafb9b
parent 22
76cdd8209f1f
child 24
e04822101291

added ucx_list_remove

ucx/list.c file | annotate | diff | comparison | revisions
ucx/list.h file | annotate | diff | comparison | revisions
--- a/ucx/list.c	Sun Jan 15 14:12:34 2012 +0100
+++ b/ucx/list.c	Sun Jan 15 14:20:25 2012 +0100
@@ -117,3 +117,22 @@
         e = n;
     }
 }
+
+/* list specific functions */
+UcxList *ucx_list_remove(UcxList *l, UcxList *e) {
+    if (e == l) {
+        l = e->next;
+        free(e);
+    } else {
+        UcxList *f = l;
+        while (f->next != NULL && f->next != e) {
+            f = f->next;
+        }
+        /* perform remove iff this element is found in this list */
+        if (f->next == e) {
+            f->next = e->next;
+            free(e);
+        }
+    }
+    return l;
+}
\ No newline at end of file
--- a/ucx/list.h	Sun Jan 15 14:12:34 2012 +0100
+++ b/ucx/list.h	Sun Jan 15 14:20:25 2012 +0100
@@ -30,6 +30,8 @@
 size_t ucx_list_size(UcxList *l);
 void ucx_list_foreach(UcxList *l, ucx_callback fnc, void *data);
 
+/* list specific functions */
+UcxList *ucx_list_remove(UcxList *l, UcxList *e);
 
 #ifdef	__cplusplus
 }

mercurial