1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2006, 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.2 2007/03/15 19:22:13 andy Exp $
22 ***************************************************************************/
32 /* this must be the last include file */
36 Curl_llist_init(struct curl_llist
*l
, curl_llist_dtor dtor
)
45 Curl_llist_alloc(curl_llist_dtor dtor
)
47 struct curl_llist
*list
;
49 list
= (struct curl_llist
*)malloc(sizeof(struct curl_llist
));
53 Curl_llist_init(list
, dtor
);
59 * Curl_llist_insert_next() returns 1 on success and 0 on failure.
62 Curl_llist_insert_next(struct curl_llist
*list
, struct curl_llist_element
*e
,
65 struct curl_llist_element
*ne
=
66 (struct curl_llist_element
*) malloc(sizeof(struct curl_llist_element
));
71 if (list
->size
== 0) {
73 list
->head
->prev
= NULL
;
74 list
->head
->next
= NULL
;
95 Curl_llist_remove(struct curl_llist
*list
, struct curl_llist_element
*e
,
98 if (e
== NULL
|| list
->size
== 0)
101 if (e
== list
->head
) {
102 list
->head
= e
->next
;
104 if (list
->head
== NULL
)
107 e
->next
->prev
= NULL
;
109 e
->prev
->next
= e
->next
;
111 list
->tail
= e
->prev
;
113 e
->next
->prev
= e
->prev
;
116 list
->dtor(user
, e
->ptr
);
124 Curl_llist_destroy(struct curl_llist
*list
, void *user
)
127 while (list
->size
> 0)
128 Curl_llist_remove(list
, list
->tail
, user
);
135 Curl_llist_count(struct curl_llist
*list
)