diff th_util.c @ 54:48926b3ff598

Add new linked list handling functions: th_llist_foreach() and th_llist_foreach_cond()
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 May 2012 02:25:27 +0300
parents 2c90b33d3617
children 300fba04b7ad
line wrap: on
line diff
--- a/th_util.c	Sat May 26 01:04:12 2012 +0300
+++ b/th_util.c	Sat May 26 02:25:27 2012 +0300
@@ -395,6 +395,37 @@
 }
 
 
+void th_llist_foreach(qlist_t *list, void (*func)(qlist_t *node))
+{
+    qlist_t *curr = list;
+
+    while (curr != NULL)
+    {
+        func(curr);
+        curr = curr->next;
+    }
+}
+
+
+qlist_t * th_llist_foreach_cond(qlist_t *list, int (*func)(qlist_t *node), int *ret)
+{
+    qlist_t *curr = list;
+
+    while (curr != NULL)
+    {
+        int res = func(curr);
+        if (res != 0)
+        {
+            *ret = res;
+            return curr;
+        }
+        curr = curr->next;
+    }
+    
+    return NULL;
+}
+
+
 qlist_t * th_llist_find(qlist_t *list, const void *data)
 {
     qlist_t *curr = list;