]> git.meshlink.io Git - catta/blobdiff - avahi-common/malloc.c
* Improve and reorganise DBus error handling, see avahi-common/dbus.h
[catta] / avahi-common / malloc.c
index 018a0c0d95e403f7e879f450985cd06621f979b6..9b0e22e12b70ae7aa88065a75c2a2ef59232efae 100644 (file)
@@ -169,16 +169,16 @@ char *avahi_strdup(const char *s) {
 char *avahi_strndup(const char *s, size_t max) {
     char *r;
     size_t size;
+    const char *p;
     
     if (!s)
         return NULL;
 
-    size = strlen(s);
-
-    if (size > max)
-        size = max;
+    for (p = s, size = 0;
+         size < max && *p;
+         p++, size++);
     
-    if (!(r = avahi_malloc(size+1)))
+    if (!(r = avahi_new(char, size+1)))
         return NULL;
 
     memcpy(r, s, size);