summaryrefslogtreecommitdiffstats
path: root/src/llist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/llist.c')
-rw-r--r--src/llist.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/llist.c b/src/llist.c
index 847b795..f771ef3 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -112,7 +112,7 @@ llist_item_t *llist_next(llist_item_t * i)
* Return the successor of a list item if it is matched by some filter
* callback. Return NULL otherwise.
*/
-llist_item_t *llist_next_filter(llist_item_t * i, long data,
+llist_item_t *llist_next_filter(llist_item_t * i, void *data,
llist_fn_match_t fn_match)
{
if (i && i->next && fn_match(i->next->data, data))
@@ -205,14 +205,21 @@ void llist_remove(llist_t * l, llist_item_t * i)
/*
* Find the first item matched by some filter callback.
*/
-llist_item_t *llist_find_first(llist_t * l, long data,
+llist_item_t *llist_find_first(llist_t * l, void *data,
llist_fn_match_t fn_match)
{
llist_item_t *i;
- for (i = l->head; i; i = i->next) {
- if (fn_match(i->data, data))
- return i;
+ if (fn_match) {
+ for (i = l->head; i; i = i->next) {
+ if (fn_match(i->data, data))
+ return i;
+ }
+ } else {
+ for (i = l->head; i; i = i->next) {
+ if (i->data == data)
+ return i;
+ }
}
return NULL;
@@ -221,14 +228,21 @@ llist_item_t *llist_find_first(llist_t * l, long data,
/*
* Find the next item matched by some filter callback.
*/
-llist_item_t *llist_find_next(llist_item_t * i, long data,
+llist_item_t *llist_find_next(llist_item_t * i, void *data,
llist_fn_match_t fn_match)
{
if (i) {
i = i->next;
- for (; i; i = i->next) {
- if (fn_match(i->data, data))
- return i;
+ if (fn_match) {
+ for (; i; i = i->next) {
+ if (fn_match(i->data, data))
+ return i;
+ }
+ } else {
+ for (; i; i = i->next) {
+ if (i->data == data)
+ return i;
+ }
}
}
@@ -238,7 +252,7 @@ llist_item_t *llist_find_next(llist_item_t * i, long data,
/*
* Find the nth item matched by some filter callback.
*/
-llist_item_t *llist_find_nth(llist_t * l, int n, long data,
+llist_item_t *llist_find_nth(llist_t * l, int n, void *data,
llist_fn_match_t fn_match)
{
llist_item_t *i;
@@ -246,9 +260,16 @@ llist_item_t *llist_find_nth(llist_t * l, int n, long data,
if (n < 0)
return NULL;
- for (i = l->head; i; i = i->next) {
- if (fn_match(i->data, data) && (n-- == 0))
- return i;
+ if (fn_match) {
+ for (i = l->head; i; i = i->next) {
+ if (fn_match(i->data, data) && (n-- == 0))
+ return i;
+ }
+ } else {
+ for (i = l->head; i; i = i->next) {
+ if ((i->data == data) && (n-- == 0))
+ return i;
+ }
}
return NULL;