summaryrefslogtreecommitdiffstats
path: root/lib/llist.c
diff options
context:
space:
mode:
authorCurl Upstream <curl-library@cool.haxx.se>2017-06-14 06:08:56 (GMT)
committerBrad King <brad.king@kitware.com>2017-06-14 14:46:35 (GMT)
commit06d6d6c4aee149cd6560b919ef6935ef0867d921 (patch)
treed62adabf2b4b10030abf4a759b520e5edb6dd517 /lib/llist.c
parentfd7d521c9d70655618db8232d45e5aaf81700f91 (diff)
downloadCMake-06d6d6c4aee149cd6560b919ef6935ef0867d921.zip
CMake-06d6d6c4aee149cd6560b919ef6935ef0867d921.tar.gz
CMake-06d6d6c4aee149cd6560b919ef6935ef0867d921.tar.bz2
curl 2017-06-14 (54b636f1)
Code extracted from: https://github.com/curl/curl.git at commit 54b636f14546d3fde9f9c67c3b32701d78563161 (curl-7_54_1).
Diffstat (limited to 'lib/llist.c')
-rw-r--r--lib/llist.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/llist.c b/lib/llist.c
index b8836bb..4bb0a51 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -49,18 +49,15 @@ Curl_llist_init(struct curl_llist *l, curl_llist_dtor dtor)
* entry is NULL and the list already has elements, the new one will be
* inserted first in the list.
*
- * Returns: 1 on success and 0 on failure.
+ * The 'ne' argument should be a pointer into the object to store.
*
* @unittest: 1300
*/
-int
+void
Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
- const void *p)
+ const void *p,
+ struct curl_llist_element *ne)
{
- struct curl_llist_element *ne = malloc(sizeof(struct curl_llist_element));
- if(!ne)
- return 0;
-
ne->ptr = (void *) p;
if(list->size == 0) {
list->head = ne;
@@ -87,19 +84,18 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
}
++list->size;
-
- return 1;
}
/*
* @unittest: 1300
*/
-int
+void
Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
void *user)
{
+ void *ptr;
if(e == NULL || list->size == 0)
- return 1;
+ return;
if(e == list->head) {
list->head = e->next;
@@ -117,16 +113,17 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
e->next->prev = e->prev;
}
- list->dtor(user, e->ptr);
+ ptr = e->ptr;
e->ptr = NULL;
e->prev = NULL;
e->next = NULL;
- free(e);
--list->size;
- return 1;
+ /* call the dtor() last for when it actually frees the 'e' memory itself */
+ if(list->dtor)
+ list->dtor(user, ptr);
}
void
@@ -147,13 +144,13 @@ Curl_llist_count(struct curl_llist *list)
/*
* @unittest: 1300
*/
-int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
- struct curl_llist *to_list,
- struct curl_llist_element *to_e)
+void Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
+ struct curl_llist *to_list,
+ struct curl_llist_element *to_e)
{
/* Remove element from list */
if(e == NULL || list->size == 0)
- return 0;
+ return;
if(e == list->head) {
list->head = e->next;
@@ -193,6 +190,4 @@ int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
}
++to_list->size;
-
- return 1;
}