1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2003, 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 http://curl.haxx.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.
22 ***************************************************************************/
32 /* this must be the last include file */
36 Curl_llist_init(curl_llist *l, curl_llist_dtor dtor)
45 Curl_llist_alloc(curl_llist_dtor dtor)
49 list = (curl_llist *)malloc(sizeof(curl_llist));
53 Curl_llist_init(list, dtor);
59 Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p)
61 curl_llist_element *ne;
63 ne = (curl_llist_element *) malloc(sizeof(curl_llist_element));
65 if (list->size == 0) {
67 list->head->prev = NULL;
68 list->head->next = NULL;
87 Curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p)
89 curl_llist_element *ne;
91 ne = (curl_llist_element *) malloc(sizeof(curl_llist_element));
93 if (list->size == 0) {
95 list->head->prev = NULL;
96 list->head->next = NULL;
114 Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user)
116 if (e == NULL || list->size == 0)
119 if (e == list->head) {
120 list->head = e->next;
122 if (list->head == NULL)
125 e->next->prev = NULL;
127 e->prev->next = e->next;
129 list->tail = e->prev;
131 e->next->prev = e->prev;
134 list->dtor(user, e->ptr);
142 Curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user)
144 return Curl_llist_remove(list, e->next, user);
148 Curl_llist_remove_prev(curl_llist *list, curl_llist_element *e, void *user)
150 return Curl_llist_remove(list, e->prev, user);
154 Curl_llist_count(curl_llist *list)
160 Curl_llist_destroy(curl_llist *list, void *user)
163 while (list->size > 0)
164 Curl_llist_remove(list, list->tail, user);