# HG changeset patch # User Matti Hamalainen # Date 1337988327 -10800 # Node ID 48926b3ff59844259df506b99fdbc39a2155d414 # Parent 2c90b33d3617f6e907a170277006a4cf9d8562a8 Add new linked list handling functions: th_llist_foreach() and th_llist_foreach_cond() diff -r 2c90b33d3617 -r 48926b3ff598 th_util.c --- 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; diff -r 2c90b33d3617 -r 48926b3ff598 th_util.h --- a/th_util.h Sat May 26 01:04:12 2012 +0300 +++ b/th_util.h Sat May 26 02:25:27 2012 +0300 @@ -115,6 +115,9 @@ size_t th_llist_length(const qlist_t *list); ssize_t th_llist_position(const qlist_t *list, const qlist_t *node); +void th_llist_foreach(qlist_t *list, void (*func)(qlist_t *node)); +qlist_t * th_llist_foreach_cond(qlist_t *list, int (*func)(qlist_t *node), int *ret); + qlist_t * th_llist_find(qlist_t *list, const void *data); qlist_t * th_llist_find_func(qlist_t *list, const void *userdata, int (compare)(const void *, const void *));