Esempio n. 1
0
/**
 * @brief Insert a list element to the specified position
 * @param list The list list pointer
 * @param data The data for the new list
 * @param pos The position to put the new list
 * @return The new list list
 */
struct dlist *dlist_insert(struct dlist *list, void *data, int pos)
{
	struct dlist *tmp = NULL, *next = NULL;

	if (pos < 0)
		return dlist_append(list, data);
	else if (pos == 0)
		return dlist_prepend(list, data);

	tmp = dlist_nth(list, pos);
	if (!tmp)
		return dlist_append(list, data);

	next = dlist_alloc();
	next->data = data;
	next->prev = tmp->prev;

	if (tmp->prev)
		tmp->prev->next = next;
	next->next = tmp;
	tmp->prev = next;

	return (tmp == list) ? next : list;
}
Esempio n. 2
0
dlist *
dlist_remove_nth(dlist *l, unsigned int n)
{
	return dlist_remove(dlist_nth(l, n));
}
Esempio n. 3
0
dlist *
dlist_remove_nth_free_data(dlist *l, unsigned int n)
{
	return dlist_remove_free_data(dlist_nth(l, n));
}