1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2004, 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.
21 * $Id: llist.c,v 1.12 2004/01/07 09:19:35 bagder Exp $
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;
88 Curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p)
90 curl_llist_element *ne;
92 ne = (curl_llist_element *) malloc(sizeof(curl_llist_element));
94 if (list->size == 0) {
96 list->head->prev = NULL;
97 list->head->next = NULL;
116 Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user)
118 if (e == NULL || list->size == 0)
121 if (e == list->head) {
122 list->head = e->next;
124 if (list->head == NULL)
127 e->next->prev = NULL;
129 e->prev->next = e->next;
131 list->tail = e->prev;
133 e->next->prev = e->prev;
136 list->dtor(user, e->ptr);
145 Curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user)
147 return Curl_llist_remove(list, e->next, user);
151 Curl_llist_remove_prev(curl_llist *list, curl_llist_element *e, void *user)
153 return Curl_llist_remove(list, e->prev, user);
157 Curl_llist_count(curl_llist *list)
164 Curl_llist_destroy(curl_llist *list, void *user)
167 while (list->size > 0)
168 Curl_llist_remove(list, list->tail, user);