diff -r cff9c4101dd7 -r a9bbd82d2dce src/server/ucx/list.c --- a/src/server/ucx/list.c Sat Jan 14 14:33:38 2012 +0100 +++ b/src/server/ucx/list.c Sun Jan 15 17:00:16 2012 +0100 @@ -15,7 +15,7 @@ int ucx_list_equals(UcxList *l1, UcxList *l2, cmp_func fnc, void* data) { if (l1 == l2) return 1; - + while (l1 != NULL && l2 != NULL) { if (fnc == NULL) { if (l1->data != l2->data) return 0; @@ -25,7 +25,7 @@ l1 = l1->next; l2 = l2->next; } - + return (l1 == NULL && l2 == NULL); } @@ -41,7 +41,7 @@ UcxList *ucx_list_append(UcxList *l, void *data) { UcxList *nl = (UcxList*) malloc(sizeof(UcxList)); if (nl == NULL) return NULL; - + nl->data = data; nl->next = NULL; if (l == NULL) { @@ -56,7 +56,7 @@ UcxList *ucx_list_prepend(UcxList *l, void *data) { UcxList *nl = ucx_list_append(NULL, data); if (nl == NULL) return NULL; - + if (l != NULL) { nl->next = l; } @@ -75,7 +75,7 @@ UcxList *ucx_list_last(UcxList *l) { if (l == NULL) return NULL; - + UcxList *e = l; while (e->next != NULL) { e = e->next; @@ -91,13 +91,13 @@ e = e->next; index--; } - + return index == 0 ? e : NULL; } size_t ucx_list_size(UcxList *l) { if (l == NULL) return 0; - + UcxList *e = l; size_t s = 1; while (e->next != NULL) { @@ -110,8 +110,29 @@ void ucx_list_foreach(UcxList *l, ucx_callback fnc, void* data) { UcxList *e = l; + UcxList *n; while (e != NULL) { + n = e->next; fnc(e, data); - e = e->next; + e = n; } } + +/* list specific functions */ +UcxList *ucx_list_remove(UcxList *l, UcxList *e) { + if (e == l) { + l = e->next; + free(e); + } else { + UcxList *f = l; + while (f->next != NULL && f->next != e) { + f = f->next; + } + /* perform remove iff this element is found in this list */ + if (f->next == e) { + f->next = e->next; + free(e); + } + } + return l; +}