diff options
author | Daniel Stenberg <daniel@haxx.se> | 2010-08-10 10:52:26 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2010-08-15 13:16:39 +0200 |
commit | 03da3ba1c0c26fa3d7113d469eac992cf972dc5a (patch) | |
tree | 7bb6f5f8f51ff150b2991a57e9ba5ff49554cdb3 /lib/llist.c | |
parent | 4d53dc5d8036c199a5eed6f1df4ae89d9f0a1857 (diff) | |
download | curl-03da3ba1c0c26fa3d7113d469eac992cf972dc5a.tar.gz |
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.
Diffstat (limited to 'lib/llist.c')
-rw-r--r-- | lib/llist.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/llist.c b/lib/llist.c index 081b3ed89..71238fa73 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -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,15 +79,21 @@ 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; } - e->next = ne; + if(e) + e->next = ne; } ++list->size; |