1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 ***************************************************************************/
25 #include "curl_setup.h"
27 #include <curl/curl.h>
30 #include "curl_memory.h"
32 /* this must be the last include file */
39 Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor)
48 * Curl_llist_insert_next()
50 * Inserts a new list element after the given one 'e'. If the given existing
51 * entry is NULL and the list already has elements, the new one will be
52 * inserted first in the list.
54 * The 'ne' argument should be a pointer into the object to store.
59 Curl_llist_insert_next(struct Curl_llist *list, struct Curl_llist_element *e,
61 struct Curl_llist_element *ne)
66 list->head->prev = NULL;
67 list->head->next = NULL;
71 /* if 'e' is NULL here, we insert the new element first in the list */
72 ne->next = e?e->next:list->head;
75 list->head->prev = ne;
95 Curl_llist_remove(struct Curl_llist *list, struct Curl_llist_element *e,
99 if(!e || list->size == 0)
102 if(e == list->head) {
103 list->head = e->next;
108 e->next->prev = NULL;
112 e->prev->next = e->next;
115 list->tail = e->prev;
117 e->next->prev = e->prev;
128 /* call the dtor() last for when it actually frees the 'e' memory itself */
130 list->dtor(user, ptr);
134 Curl_llist_destroy(struct Curl_llist *list, void *user)
137 while(list->size > 0)
138 Curl_llist_remove(list, list->tail, user);
143 Curl_llist_count(struct Curl_llist *list)