1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

core/clist: make clist_foreach() return break-causing node

This commit is contained in:
Kaspar Schleiser 2018-04-24 22:29:45 +02:00
parent b11b806465
commit 7c7bb45ce7

View File

@ -325,24 +325,28 @@ static inline clist_node_t *clist_remove(clist_node_t *list, clist_node_t *node)
* The pointer supplied by @p arg will be passed to every call to @p func.
*
* If @p func returns non-zero, traversal will be aborted like when calling
* break within a for loop.
* break within a for loop, returning the corresponding node.
*
* @param[in] list List to traverse.
* @param[in] func Function to call for each member.
* @param[in] arg Pointer to pass to every call to @p func
*
* @returns NULL on empty list or full traversal
* @returns node that caused @p func(node, arg) to exit non-zero
*/
static inline void clist_foreach(clist_node_t *list, int(*func)(clist_node_t *, void *), void *arg)
static inline clist_node_t *clist_foreach(clist_node_t *list, int(*func)(clist_node_t *, void *), void *arg)
{
clist_node_t *node = list->next;
if (! node) {
return;
if (node) {
do {
node = node->next;
if (func(node, arg)) {
return node;
}
} while (node != list->next);
}
do {
node = node->next;
if (func(node, arg)) {
return;
}
} while (node != list->next);
return NULL;
}
/**