From 6de7dc5879b3605a180dafa05f792f132eafdcaa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 3 Jan 2002 10:22:59 +0000 Subject: Sterling Hughes' provided initial DNS cache source code. --- lib/llist.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 lib/llist.c (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c new file mode 100644 index 000000000..b031cf6ac --- /dev/null +++ b/lib/llist.c @@ -0,0 +1,165 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2001, Daniel Stenberg, , et al + * + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + *****************************************************************************/ + +#include "setup.h" + + +#include + +#include "llist.h" + +#ifdef MALLOCDEBUG +/* this must be the last include file */ +#include "memdebug.h" +#endif +void +curl_llist_init(curl_llist *l, curl_llist_dtor dtor) +{ + l->size = 0; + l->dtor = dtor; + l->head = NULL; + l->tail = NULL; +} + +curl_llist * +curl_llist_alloc(curl_llist_dtor dtor) +{ + curl_llist *list; + + list = malloc(sizeof(curl_llist)); + curl_llist_init(list, dtor); + + return list; +} + +int +curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) +{ + curl_llist_element *ne; + + ne = (curl_llist_element *) malloc(sizeof(curl_llist_element)); + ne->ptr = (void *) p; + if (list->size == 0) { + list->head = ne; + list->head->prev = NULL; + list->head->next = NULL; + list->tail = ne; + } else { + ne->next = e->next; + ne->prev = e; + if (e->next) { + e->next->prev = ne; + } else { + list->tail = ne; + } + e->next = ne; + } + + ++list->size; + + return 1; +} + +int +curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) +{ + curl_llist_element *ne; + + ne = (curl_llist_element *) malloc(sizeof(curl_llist_element)); + ne->ptr = (void *) p; + if (list->size == 0) { + list->head = ne; + list->head->prev = NULL; + list->head->next = NULL; + list->tail = ne; + } else { + ne->next = e; + ne->prev = e->prev; + if (e->prev) + e->prev->next = ne; + else + list->head = ne; + e->prev = ne; + } + + ++list->size; + + return 1; +} + +int +curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) +{ + if (e == NULL || list->size == 0) + return 1; + + if (e == list->head) { + list->head = e->next; + + if (list->head == NULL) + list->tail = NULL; + else + e->next->prev = NULL; + } else { + e->prev->next = e->next; + if (!e->next) + list->tail = e->prev; + else + e->next->prev = e->prev; + } + + list->dtor(user, e->ptr); + free(e); + --list->size; + + return 1; +} + +int +curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user) +{ + return curl_llist_remove(list, e->next, user); +} + +int +curl_llist_remove_prev(curl_llist *list, curl_llist_element *e, void *user) +{ + return curl_llist_remove(list, e->prev, user); +} + +size_t +curl_llist_count(curl_llist *list) +{ + return list->size; +} + +void +curl_llist_destroy(curl_llist *list, void *user) +{ + while (list->size > 0) { + curl_llist_remove(list, CURL_LLIST_TAIL(list), user); + } + + free(list); + list = NULL; +} -- cgit v1.2.1 From cbaecca8e948cda6c603a715ac1e984784d77855 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 18 Jan 2002 10:30:51 +0000 Subject: added typecast for a malloc() return, and added check for NULL --- lib/llist.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index b031cf6ac..9103ff254 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -46,7 +46,10 @@ curl_llist_alloc(curl_llist_dtor dtor) { curl_llist *list; - list = malloc(sizeof(curl_llist)); + list = (curl_llist *)malloc(sizeof(curl_llist)); + if(NULL == list) + return NULL; + curl_llist_init(list, dtor); return list; -- cgit v1.2.1 From e452f467d46d06cb6eee7d314ee5d78efd4e8e9c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 17 Feb 2002 14:55:35 +0000 Subject: Philip Gladstone's 64-bit issues corrected. Reminder for the future: when we're using malloc() we MUST include as otherwise 64bit archs go bananas. Bug report #517687 --- lib/llist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 9103ff254..0d969aeed 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2001, Daniel Stenberg, , et al + * Copyright (C) 2002, Daniel Stenberg, , et al * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. @@ -23,8 +23,8 @@ #include "setup.h" - #include +#include #include "llist.h" -- cgit v1.2.1 From 974f314f5785156af6983675aeb28313cc8ba2ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 07:54:55 +0000 Subject: copyright string (year) update --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 0d969aeed..e84508038 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2002, Daniel Stenberg, , et al + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. -- cgit v1.2.1 From 8358505b6daec39a5bf0937a8524488a4e284912 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 27 Apr 2002 13:07:51 +0000 Subject: Now uses Curl_ as prefix for internal global symbols. curl_ should only be used for "exported" globals. --- lib/llist.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index e84508038..7d0862032 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -33,7 +33,7 @@ #include "memdebug.h" #endif void -curl_llist_init(curl_llist *l, curl_llist_dtor dtor) +Curl_llist_init(curl_llist *l, curl_llist_dtor dtor) { l->size = 0; l->dtor = dtor; @@ -42,7 +42,7 @@ curl_llist_init(curl_llist *l, curl_llist_dtor dtor) } curl_llist * -curl_llist_alloc(curl_llist_dtor dtor) +Curl_llist_alloc(curl_llist_dtor dtor) { curl_llist *list; @@ -50,13 +50,13 @@ curl_llist_alloc(curl_llist_dtor dtor) if(NULL == list) return NULL; - curl_llist_init(list, dtor); + Curl_llist_init(list, dtor); return list; } int -curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) +Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) { curl_llist_element *ne; @@ -84,7 +84,7 @@ curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) } int -curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) +Curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) { curl_llist_element *ne; @@ -111,7 +111,7 @@ curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) } int -curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) +Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) { if (e == NULL || list->size == 0) return 1; @@ -139,28 +139,28 @@ curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) } int -curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user) +Curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user) { - return curl_llist_remove(list, e->next, user); + return Curl_llist_remove(list, e->next, user); } int -curl_llist_remove_prev(curl_llist *list, curl_llist_element *e, void *user) +Curl_llist_remove_prev(curl_llist *list, curl_llist_element *e, void *user) { - return curl_llist_remove(list, e->prev, user); + return Curl_llist_remove(list, e->prev, user); } size_t -curl_llist_count(curl_llist *list) +Curl_llist_count(curl_llist *list) { return list->size; } void -curl_llist_destroy(curl_llist *list, void *user) +Curl_llist_destroy(curl_llist *list, void *user) { while (list->size > 0) { - curl_llist_remove(list, CURL_LLIST_TAIL(list), user); + Curl_llist_remove(list, CURL_LLIST_TAIL(list), user); } free(list); -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/llist.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 7d0862032..a9e65a8a9 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index a9e65a8a9..ceee9e822 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 308bc9d919d57388f269c473778ea7f6a331d1c5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 26 Jun 2003 11:22:12 +0000 Subject: use CURLDEBUG instead of MALLOCDEBUG for preprocessor conditions --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index ceee9e822..9e38f6766 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -28,7 +28,7 @@ #include "llist.h" -#ifdef MALLOCDEBUG +#ifdef CURLDEBUG /* this must be the last include file */ #include "memdebug.h" #endif -- cgit v1.2.1 From 4281470fca67dd51ffba1799d303e2eedaa1efa8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 14 Aug 2003 15:06:08 +0000 Subject: Curl_llist_destroy() checks the input for non-NULL --- lib/llist.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 9e38f6766..7ffdb1043 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -159,10 +159,10 @@ Curl_llist_count(curl_llist *list) void Curl_llist_destroy(curl_llist *list, void *user) { - while (list->size > 0) { - Curl_llist_remove(list, CURL_LLIST_TAIL(list), user); - } + if(list) { + while (list->size > 0) + Curl_llist_remove(list, CURL_LLIST_TAIL(list), user); - free(list); - list = NULL; + free(list); + } } -- cgit v1.2.1 From adcbe03aeb72e25c2c1509c0ad3fd1d1e620b6db Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Sep 2003 12:44:35 +0000 Subject: Uses less macros. #ifdef'ed out unused functions. Edited slightly to be more in the same style as other curl source code. The only actual code change is an added check after a malloc() call. --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 7ffdb1043..57c15154c 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -161,7 +161,7 @@ Curl_llist_destroy(curl_llist *list, void *user) { if(list) { while (list->size > 0) - Curl_llist_remove(list, CURL_LLIST_TAIL(list), user); + Curl_llist_remove(list, list->tail, user); free(list); } -- cgit v1.2.1 From 6fde14727321fd5903cc0c951c687164e7182a42 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 11 Sep 2003 22:13:37 +0000 Subject: #ifdef 0'ed Curl_llist_insert_prev and Curl_llist_remove_next, as they are not used by any code in libcurl! --- lib/llist.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 57c15154c..56d15950e 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -83,6 +83,7 @@ Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) return 1; } +#if 0 int Curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) { @@ -109,6 +110,7 @@ Curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) return 1; } +#endif int Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) @@ -138,6 +140,7 @@ Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) return 1; } +#if 0 int Curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user) { @@ -155,6 +158,7 @@ Curl_llist_count(curl_llist *list) { return list->size; } +#endif void Curl_llist_destroy(curl_llist *list, void *user) -- cgit v1.2.1 From 053f6c85efd0bf698f73343989474d672d0563a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jan 2004 09:19:33 +0000 Subject: updated year in the copyright string --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 56d15950e..087cf8545 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 228fea46280d521dde6b214bb24fb20d9b6975f0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 10 May 2004 08:57:37 +0000 Subject: make Curl_llist_insert_next() fail properly if malloc() fails --- lib/llist.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 087cf8545..0f347acb9 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -55,24 +55,31 @@ Curl_llist_alloc(curl_llist_dtor dtor) return list; } +/* + * Curl_llist_insert_next() returns 1 on success and 0 on failure. + */ int Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) { - curl_llist_element *ne; + curl_llist_element *ne = + (curl_llist_element *) malloc(sizeof(curl_llist_element)); + if(!ne) + return 0; - ne = (curl_llist_element *) malloc(sizeof(curl_llist_element)); ne->ptr = (void *) p; if (list->size == 0) { list->head = ne; list->head->prev = NULL; list->head->next = NULL; list->tail = ne; - } else { + } + else { ne->next = e->next; ne->prev = e; if (e->next) { e->next->prev = ne; - } else { + } + else { list->tail = ne; } e->next = ne; -- cgit v1.2.1 From bbafb2eb27954c34967f91c705e74cc0c186970d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 May 2004 11:30:23 +0000 Subject: curl_global_init_mem() allows the memory functions to be replaced. memory.h is included everywhere for this. --- lib/llist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 0f347acb9..2f059991d 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -27,11 +27,11 @@ #include #include "llist.h" +#include "memory.h" -#ifdef CURLDEBUG /* this must be the last include file */ #include "memdebug.h" -#endif + void Curl_llist_init(curl_llist *l, curl_llist_dtor dtor) { -- cgit v1.2.1 From c39858aac0584716282dcb097ce9d972b43dbcb2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 07:43:48 +0000 Subject: Source cleanups. The major one being that we now _always_ use a Curl_addrinfo linked list for name resolved data, even on hosts/systems with only IPv4 stacks as this simplifies a lot of code. --- lib/llist.c | 65 ++++++++----------------------------------------------------- 1 file changed, 8 insertions(+), 57 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 2f059991d..961848692 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -32,7 +32,7 @@ /* this must be the last include file */ #include "memdebug.h" -void +void Curl_llist_init(curl_llist *l, curl_llist_dtor dtor) { l->size = 0; @@ -90,36 +90,7 @@ Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) return 1; } -#if 0 -int -Curl_llist_insert_prev(curl_llist *list, curl_llist_element *e, const void *p) -{ - curl_llist_element *ne; - - ne = (curl_llist_element *) malloc(sizeof(curl_llist_element)); - ne->ptr = (void *) p; - if (list->size == 0) { - list->head = ne; - list->head->prev = NULL; - list->head->next = NULL; - list->tail = ne; - } else { - ne->next = e; - ne->prev = e->prev; - if (e->prev) - e->prev->next = ne; - else - list->head = ne; - e->prev = ne; - } - - ++list->size; - - return 1; -} -#endif - -int +int Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) { if (e == NULL || list->size == 0) @@ -147,27 +118,7 @@ Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) return 1; } -#if 0 -int -Curl_llist_remove_next(curl_llist *list, curl_llist_element *e, void *user) -{ - return Curl_llist_remove(list, e->next, user); -} - -int -Curl_llist_remove_prev(curl_llist *list, curl_llist_element *e, void *user) -{ - return Curl_llist_remove(list, e->prev, user); -} - -size_t -Curl_llist_count(curl_llist *list) -{ - return list->size; -} -#endif - -void +void Curl_llist_destroy(curl_llist *list, void *user) { if(list) { -- cgit v1.2.1 From 043d70fcdfa50c93dc826069aa5836206f8e3e2d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Jan 2005 00:06:29 +0000 Subject: Use plain structs and not typedef'ed ones in the hash and linked-list code. --- lib/llist.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 961848692..ae5a466c6 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -33,7 +33,7 @@ #include "memdebug.h" void -Curl_llist_init(curl_llist *l, curl_llist_dtor dtor) +Curl_llist_init(struct curl_llist *l, curl_llist_dtor dtor) { l->size = 0; l->dtor = dtor; @@ -41,12 +41,12 @@ Curl_llist_init(curl_llist *l, curl_llist_dtor dtor) l->tail = NULL; } -curl_llist * +struct curl_llist * Curl_llist_alloc(curl_llist_dtor dtor) { - curl_llist *list; + struct curl_llist *list; - list = (curl_llist *)malloc(sizeof(curl_llist)); + list = (struct curl_llist *)malloc(sizeof(struct curl_llist)); if(NULL == list) return NULL; @@ -59,10 +59,11 @@ Curl_llist_alloc(curl_llist_dtor dtor) * Curl_llist_insert_next() returns 1 on success and 0 on failure. */ int -Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) +Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, + const void *p) { - curl_llist_element *ne = - (curl_llist_element *) malloc(sizeof(curl_llist_element)); + struct curl_llist_element *ne = + (struct curl_llist_element *) malloc(sizeof(struct curl_llist_element)); if(!ne) return 0; @@ -91,7 +92,8 @@ Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) } int -Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) +Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, + void *user) { if (e == NULL || list->size == 0) return 1; @@ -119,7 +121,7 @@ Curl_llist_remove(curl_llist *list, curl_llist_element *e, void *user) } void -Curl_llist_destroy(curl_llist *list, void *user) +Curl_llist_destroy(struct curl_llist *list, void *user) { if(list) { while (list->size > 0) -- cgit v1.2.1 From b7eeb6e67fca686f840eacd6b8394edb58b07482 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 7 Sep 2006 21:49:20 +0000 Subject: Major overhaul introducing http pipelining support and shared connection cache within the multi handle. --- lib/llist.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index ae5a466c6..0caa25ad6 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -130,3 +130,9 @@ Curl_llist_destroy(struct curl_llist *list, void *user) free(list); } } + +size_t +Curl_llist_count(struct curl_llist *list) +{ + return list->size; +} -- cgit v1.2.1 From b2c378267beecae61b5fa608d2af3b3e4f0868d1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 25 Oct 2006 07:19:45 +0000 Subject: updated copyright year --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 0caa25ad6..921d1d1f9 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/llist.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 921d1d1f9..0ace1bdd4 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -68,7 +68,7 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, return 0; ne->ptr = (void *) p; - if (list->size == 0) { + if(list->size == 0) { list->head = ne; list->head->prev = NULL; list->head->next = NULL; @@ -77,7 +77,7 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, else { ne->next = e->next; ne->prev = e; - if (e->next) { + if(e->next) { e->next->prev = ne; } else { @@ -95,19 +95,19 @@ int Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, void *user) { - if (e == NULL || list->size == 0) + if(e == NULL || list->size == 0) return 1; - if (e == list->head) { + if(e == list->head) { list->head = e->next; - if (list->head == NULL) + if(list->head == NULL) list->tail = NULL; else e->next->prev = NULL; } else { e->prev->next = e->next; - if (!e->next) + if(!e->next) list->tail = e->prev; else e->next->prev = e->prev; @@ -124,7 +124,7 @@ void Curl_llist_destroy(struct curl_llist *list, void *user) { if(list) { - while (list->size > 0) + while(list->size > 0) Curl_llist_remove(list, list->tail, user); free(list); -- cgit v1.2.1 From b3de497d8316647d988e97703f975e0acd40cacd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 16 Jan 2008 12:24:00 +0000 Subject: Dmitry Kurochkin worked a lot on improving the HTTP Pipelining support that previously had a number of flaws, perhaps most notably when an application fired up N transfers at once as then they wouldn't pipeline at all that nicely as anyone would think... Test case 530 was also updated to take the improved functionality into account. --- lib/llist.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 0ace1bdd4..43d46233e 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -136,3 +136,52 @@ Curl_llist_count(struct curl_llist *list) { return list->size; } + +int 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; + + if(e == list->head) { + list->head = e->next; + + if(list->head == NULL) + list->tail = NULL; + else + e->next->prev = NULL; + } + else { + e->prev->next = e->next; + if(!e->next) + list->tail = e->prev; + else + e->next->prev = e->prev; + } + + --list->size; + + /* Add element to to_list after to_e */ + if(to_list->size == 0) { + to_list->head = e; + to_list->head->prev = NULL; + to_list->head->next = NULL; + to_list->tail = e; + } + else { + e->next = to_e->next; + e->prev = to_e; + if(to_e->next) { + to_e->next->prev = e; + } + else { + to_list->tail = e; + } + to_e->next = e; + } + + ++to_list->size; + + return 1; +} -- cgit v1.2.1 From 59e378f48fed849e8e41f0bc6a10bf7a1732ae8a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 05:29:05 +0000 Subject: remove unnecessary typecasting of malloc() --- lib/llist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 43d46233e..cd9edad63 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -46,7 +46,7 @@ Curl_llist_alloc(curl_llist_dtor dtor) { struct curl_llist *list; - list = (struct curl_llist *)malloc(sizeof(struct curl_llist)); + list = malloc(sizeof(struct curl_llist)); if(NULL == list) return NULL; @@ -62,8 +62,7 @@ int Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, const void *p) { - struct curl_llist_element *ne = - (struct curl_llist_element *) malloc(sizeof(struct curl_llist_element)); + struct curl_llist_element *ne = malloc(sizeof(struct curl_llist_element)); if(!ne) return 0; -- cgit v1.2.1 From 5779283a52a1369cccbe1a1d314e2ec8ac949e0f Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 19 Oct 2008 20:17:16 +0000 Subject: attempt to fix or allow further detection of an elusive icc SIGSEGV --- lib/llist.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index cd9edad63..0d08321c6 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -113,6 +113,8 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, } list->dtor(user, e->ptr); + + memset(e, 0, sizeof(struct curl_llist_element)); free(e); --list->size; @@ -126,6 +128,7 @@ Curl_llist_destroy(struct curl_llist *list, void *user) while(list->size > 0) Curl_llist_remove(list, list->tail, user); + memset(list, 0, sizeof(struct curl_llist)); free(list); } } -- cgit v1.2.1 From 6bd91936ff9d525d3e1dee8f6d97d887072cb480 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 20 Oct 2008 23:24:35 +0000 Subject: remove debug-code which zero-filled some structures before free()ing them --- lib/llist.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 0d08321c6..4a41b80c1 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -114,7 +114,6 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, list->dtor(user, e->ptr); - memset(e, 0, sizeof(struct curl_llist_element)); free(e); --list->size; @@ -128,7 +127,6 @@ Curl_llist_destroy(struct curl_llist *list, void *user) while(list->size > 0) Curl_llist_remove(list, list->tail, user); - memset(list, 0, sizeof(struct curl_llist)); free(list); } } -- cgit v1.2.1 From 33a3753c3f41d546ebf3350685eb7201d25783f4 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 21 Apr 2009 11:46:16 +0000 Subject: libcurl's memory.h renamed to curl_memory.h --- lib/llist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 4a41b80c1..a262fee29 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -27,7 +27,7 @@ #include #include "llist.h" -#include "memory.h" +#include "curl_memory.h" /* this must be the last include file */ #include "memdebug.h" -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/llist.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index a262fee29..a121c603d 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 1d594772fd15143ad602ac90f5bb2f58f8b06f1a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 8 Aug 2010 23:49:49 +0200 Subject: llist: hide Curl_llist_init Curl_llist_init is never used outside of llist.c and thus it should be static. I also removed the protos for Curl_llist_insert_prev and Curl_llist_remove_next which are functions we removed from llist.c ages ago. --- lib/llist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index a121c603d..081b3ed89 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -31,8 +31,8 @@ /* this must be the last include file */ #include "memdebug.h" -void -Curl_llist_init(struct curl_llist *l, curl_llist_dtor dtor) +static void +llist_init(struct curl_llist *l, curl_llist_dtor dtor) { l->size = 0; l->dtor = dtor; @@ -49,7 +49,7 @@ Curl_llist_alloc(curl_llist_dtor dtor) if(NULL == list) return NULL; - Curl_llist_init(list, dtor); + llist_init(list, dtor); return list; } -- cgit v1.2.1 From 03da3ba1c0c26fa3d7113d469eac992cf972dc5a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 10 Aug 2010 10:52:26 +0200 Subject: Curl_llist_insert_next: allow insertion first in the list When we specify the "insert after" entry as NULL, this function now inserts the new entry first in the list. --- lib/llist.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 081b3ed89..71238fa73 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -55,7 +55,13 @@ Curl_llist_alloc(curl_llist_dtor dtor) } /* - * Curl_llist_insert_next() returns 1 on success and 0 on failure. + * Curl_llist_insert_next() + * + * Inserts a new list element after the given one 'e'. If the given existing + * 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. */ int Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, @@ -73,15 +79,21 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, list->tail = ne; } else { - ne->next = e->next; + /* if 'e' is NULL here, we insert the new element first in the list */ + ne->next = e?e->next:list->head; ne->prev = e; - if(e->next) { + if(!e) { + list->head->prev = ne; + list->head = ne; + } + else if(e->next) { e->next->prev = ne; } else { list->tail = ne; } - e->next = ne; + if(e) + e->next = ne; } ++list->size; -- cgit v1.2.1 From b903186fa0189ff241d756d25d07fdfe9885ae49 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 20 Apr 2011 15:17:42 +0200 Subject: source cleanup: unify look, style and indent levels By the use of a the new lib/checksrc.pl script that checks that our basic source style rules are followed. --- lib/llist.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 71238fa73..42364b121 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -115,7 +115,8 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, list->tail = NULL; else e->next->prev = NULL; - } else { + } + else { e->prev->next = e->next; if(!e->next) list->tail = e->prev; @@ -149,7 +150,8 @@ Curl_llist_count(struct curl_llist *list) } int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e, - struct curl_llist *to_list, struct curl_llist_element *to_e) + struct curl_llist *to_list, + struct curl_llist_element *to_e) { /* Remove element from list */ if(e == NULL || list->size == 0) -- cgit v1.2.1 From 0f7bea7c3a6ddb0bf43f890c764322faaa3ba561 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 10 Jun 2011 14:40:46 +0200 Subject: unittest: mark all unit tested functions With "@unittest: [num]" in the header comment for each tested function. Shows we have a log way to go still... --- lib/llist.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 42364b121..9478a708d 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -62,6 +62,8 @@ Curl_llist_alloc(curl_llist_dtor dtor) * inserted first in the list. * * Returns: 1 on success and 0 on failure. + * + * @unittest: 1300 */ int Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, @@ -101,9 +103,11 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, return 1; } -int -Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, - void *user) +/* + * @unittest: 1300 + */ +int Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, + void *user) { if(e == NULL || list->size == 0) return 1; -- cgit v1.2.1 From c9f16e67eff98c8c6a3e6ff32927af8c002ac2d8 Mon Sep 17 00:00:00 2001 From: Amr Shahin Date: Sun, 19 Jun 2011 03:27:22 +0300 Subject: unitteset: Curl_llist_move adding unit test for Curl_llist_move, documenting unit-tested functions in llist.c, changing unit-test to unittest, replacing assert calls with abort_unless calls --- lib/llist.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 9478a708d..8b4bc7f20 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -31,6 +31,9 @@ /* this must be the last include file */ #include "memdebug.h" +/* + * @unittest: 1300 + */ static void llist_init(struct curl_llist *l, curl_llist_dtor dtor) { @@ -106,8 +109,9 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, /* * @unittest: 1300 */ -int Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, - void *user) +int +Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, + void *user) { if(e == NULL || list->size == 0) return 1; @@ -153,6 +157,9 @@ Curl_llist_count(struct curl_llist *list) return list->size; } +/* + * @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) -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/llist.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 8b4bc7f20..9ad1db59b 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -22,9 +22,6 @@ #include "setup.h" -#include -#include - #include "llist.h" #include "curl_memory.h" -- cgit v1.2.1 From 17f48fe87979f159e2d8769d678641c60f4c0eed Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 7 Oct 2011 20:50:57 +0200 Subject: libcurl: some OOM handling fixes --- lib/llist.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 9ad1db59b..0aecf1083 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -131,6 +131,10 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, list->dtor(user, e->ptr); + e->ptr = NULL; + e->prev = NULL; + e->next = NULL; + free(e); --list->size; -- cgit v1.2.1 From 584dc8b8af862f7f47a3a9f02f874ac0bd0076be Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 11 Oct 2011 19:41:30 +0200 Subject: OOM handling/cleanup slight adjustments --- lib/llist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 0aecf1083..a302e32d5 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -46,7 +46,7 @@ Curl_llist_alloc(curl_llist_dtor dtor) struct curl_llist *list; list = malloc(sizeof(struct curl_llist)); - if(NULL == list) + if(!list) return NULL; llist_init(list, dtor); -- cgit v1.2.1