Commit 3d5be386 3d5be3869b3a6761b38084af1135bb0883e6172f by Sergey Poznyakoff

(list_replace): New function.

1 parent b54042f7
......@@ -31,6 +31,7 @@ extern int list_prepend __P ((list_t, void *item));
extern int list_is_empty __P ((list_t));
extern int list_count __P ((list_t, size_t *pcount));
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));
typedef int list_action_t __PMT ((void* item, void* cbdata));
......
......@@ -151,7 +151,29 @@ list_remove (list_t list, void *item)
}
}
monitor_unlock (list->monitor);
return ENOENT;
return status;
}
int
list_replace (list_t list, void *old_item, void *new_item)
{
struct list_data *current, *previous;
int status = ENOENT;
if (list == NULL)
return EINVAL;
monitor_wrlock (list->monitor);
for (previous = &(list->head), current = list->head.next;
current != &(list->head); previous = current, current = current->next)
{
if (current->item == old_item)
{
current->item = new_item;
status = 0;
break;
}
}
monitor_unlock (list->monitor);
return status;
}
/* FIXME: FIXME: FIXME: URGENT:
......