1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2008, 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.1.1.1 2008-09-23 16:32:05 hoffman 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
));
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
)
140 int Curl_llist_move(struct curl_llist
*list
, struct curl_llist_element
*e
,
141 struct curl_llist
*to_list
, struct curl_llist_element
*to_e
)
143 /* Remove element from list */
144 if(e
== NULL
|| list
->size
== 0)
147 if(e
== list
->head
) {
148 list
->head
= e
->next
;
150 if(list
->head
== NULL
)
153 e
->next
->prev
= NULL
;
156 e
->prev
->next
= e
->next
;
158 list
->tail
= e
->prev
;
160 e
->next
->prev
= e
->prev
;
165 /* Add element to to_list after to_e */
166 if(to_list
->size
== 0) {
168 to_list
->head
->prev
= NULL
;
169 to_list
->head
->next
= NULL
;
173 e
->next
= to_e
->next
;
176 to_e
->next
->prev
= e
;