Commit 9b7dc272 9b7dc2723bd164421d1dc25818a5e3e037eb43d0 by Sergey Poznyakoff

(list_locate): New function

1 parent 74f72efa
......@@ -35,6 +35,7 @@ extern int list_remove __P ((list_t, void *item));
extern int list_replace __P ((list_t list, void *old_item, void *new_item));
extern int list_get __P ((list_t, size_t _index, void **pitem));
extern int list_to_array __P ((list_t list, void **array, size_t count, size_t *pcount));
extern int list_locate __P ((list_t list, void *item, void **ret_item));
typedef int list_action_t __PMT ((void* item, void* cbdata));
......
......@@ -156,6 +156,32 @@ def_comp (const void *item, const void *value)
}
int
list_locate (list_t list, void *item, void **ret_item)
{
struct list_data *current, *previous;
list_comparator_t comp;
int status = ENOENT;
if (list == NULL)
return EINVAL;
comp = list->comp ? list->comp : def_comp;
monitor_wrlock (list->monitor);
for (previous = &(list->head), current = list->head.next;
current != &(list->head); previous = current, current = current->next)
{
if (comp (current->item, item) == 0)
{
if (ret_item)
*ret_item = current->item;
status = 0;
break;
}
}
monitor_unlock (list->monitor);
return status;
}
int
list_insert (list_t list, void *item, void *new_item)
{
struct list_data *current;
......