1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Curl_llist_insert_next: allow insertion first in the list

When we specify the "insert after" entry as NULL, this function now
inserts the new entry first in the list.
This commit is contained in:
Daniel Stenberg 2010-08-10 10:52:26 +02:00
parent 4d53dc5d80
commit 03da3ba1c0

View File

@ -55,7 +55,13 @@ Curl_llist_alloc(curl_llist_dtor dtor)
}
/*
* Curl_llist_insert_next() returns 1 on success and 0 on failure.
* Curl_llist_insert_next()
*
* Inserts a new list element after the given one 'e'. If the given existing
* entry is NULL and the list already has elements, the new one will be
* inserted first in the list.
*
* Returns: 1 on success and 0 on failure.
*/
int
Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
@ -73,14 +79,20 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
list->tail = ne;
}
else {
ne->next = e->next;
/* if 'e' is NULL here, we insert the new element first in the list */
ne->next = e?e->next:list->head;
ne->prev = e;
if(e->next) {
if(!e) {
list->head->prev = ne;
list->head = ne;
}
else if(e->next) {
e->next->prev = ne;
}
else {
list->tail = ne;
}
if(e)
e->next = ne;
}