some fixes + ucx_(d)list_contains

Mon, 25 Feb 2013 16:26:50 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 25 Feb 2013 16:26:50 +0100
changeset 87
bd444539cced
parent 86
55bf819cbc88
child 88
18823857ce79

some fixes + ucx_(d)list_contains

ucx/dlist.c file | annotate | diff | comparison | revisions
ucx/dlist.h file | annotate | diff | comparison | revisions
ucx/list.c file | annotate | diff | comparison | revisions
ucx/list.h file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
--- 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;
     
--- 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);
 
--- 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;
     
--- 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);
 
--- 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;

mercurial