# HG changeset patch # User Mike Becker # Date 1361806010 -3600 # Node ID bd444539ccede1086397de466dbabfafaefdbae2 # Parent 55bf819cbc8872246d3c98b61440aa8eda33d749 some fixes + ucx_(d)list_contains diff -r 55bf819cbc88 -r bd444539cced ucx/dlist.c --- a/ucx/dlist.c Mon Feb 25 13:25:07 2013 +0100 +++ b/ucx/dlist.c Mon Feb 25 16:26:50 2013 +0100 @@ -1,7 +1,6 @@ #include "dlist.h" -UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, - copy_func fnc, void *data) { +UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { UcxDlist *ret = NULL; while (l != NULL) { if (fnc != NULL) { @@ -101,6 +100,15 @@ return (UcxDlist*)(index == 0 ? e : NULL); } +int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) { + UCX_FOREACH(UcxDlist*, l, e) { + if (!fnc(elem, e->data, cmpdata)) { + return 1; + } + } + return 0; +} + size_t ucx_dlist_size(const UcxDlist *l) { if (l == NULL) return 0; diff -r 55bf819cbc88 -r bd444539cced ucx/dlist.h --- a/ucx/dlist.h Mon Feb 25 13:25:07 2013 +0100 +++ b/ucx/dlist.h Mon Feb 25 16:26:50 2013 +0100 @@ -19,8 +19,7 @@ UcxDlist *restrict prev; }; -UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, - copy_func fnc, void* data); +UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void* data); int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, cmp_func fnc, void* data); @@ -31,6 +30,7 @@ UcxDlist *ucx_dlist_last(const UcxDlist *l); UcxDlist *ucx_dlist_get(const UcxDlist *l, int index); size_t ucx_dlist_size(const UcxDlist *l); +int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata); UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data); diff -r 55bf819cbc88 -r bd444539cced ucx/list.c --- a/ucx/list.c Mon Feb 25 13:25:07 2013 +0100 +++ b/ucx/list.c Mon Feb 25 16:26:50 2013 +0100 @@ -1,7 +1,6 @@ #include "list.h" -UcxList *restrict ucx_list_clone(UcxList *restrict l, - copy_func fnc, void *data) { +UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { UcxList *ret = NULL; while (l != NULL) { if (fnc != NULL) { @@ -97,6 +96,15 @@ return (UcxList*)(index == 0 ? e : NULL); } +int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { + UCX_FOREACH(UcxList*, l, e) { + if (!fnc(elem, e->data, cmpdata)) { + return 1; + } + } + return 0; +} + size_t ucx_list_size(const UcxList *l) { if (l == NULL) return 0; diff -r 55bf819cbc88 -r bd444539cced ucx/list.h --- a/ucx/list.h Mon Feb 25 13:25:07 2013 +0100 +++ b/ucx/list.h Mon Feb 25 16:26:50 2013 +0100 @@ -18,8 +18,7 @@ UcxList *next; }; -UcxList *restrict ucx_list_clone(UcxList *restrict l, - copy_func fnc, void *data); +UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data); int ucx_list_equals(const UcxList *l1, const UcxList *l2, cmp_func fnc, void *data); @@ -30,6 +29,7 @@ UcxList *ucx_list_last(const UcxList *l); UcxList *ucx_list_get(const UcxList *l, int index); size_t ucx_list_size(const UcxList *l); +int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata); UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data); diff -r 55bf819cbc88 -r bd444539cced ucx/string.c --- a/ucx/string.c Mon Feb 25 13:25:07 2013 +0100 +++ b/ucx/string.c Mon Feb 25 16:26:50 2013 +0100 @@ -161,11 +161,13 @@ sstr_t sstrdup(sstr_t s) { sstr_t newstring; newstring.ptr = (char*) malloc(s.length + 1); - if (newstring.ptr != NULL) { + if (newstring.ptr) { newstring.length = s.length; newstring.ptr[newstring.length] = 0; memcpy(newstring.ptr, s.ptr, s.length); + } else { + newstring.length = 0; } return newstring;