Skip to content

Commit

Permalink
New routine to find a node on a list
Browse files Browse the repository at this point in the history
metal_list_find_node is used to ensure a node is not on a list before adding it
Signed-off-by: Tammy Leino <[email protected]>
  • Loading branch information
tammyleino committed Oct 3, 2022
1 parent 695d29b commit 0c3f072
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef __METAL_LIST__H__
#define __METAL_LIST__H__

#include <stdbool.h>
#include <stdlib.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -96,6 +97,18 @@ static inline struct metal_list *metal_list_first(struct metal_list *list)
for ((node) = (list)->next; \
(node) != (list); \
(node) = (node)->next)

static inline bool metal_list_find_node(struct metal_list *list,
struct metal_list *node)
{
struct metal_list *n;

metal_list_for_each(list, n) {
if (n == node)
return true;
}
return false;
}
/** @} */

#ifdef __cplusplus
Expand Down

0 comments on commit 0c3f072

Please sign in to comment.