]> git.deb.at Git - pkg/abook.git/blobdiff - xmalloc.c
- add xstrdup to have proper checking for memory allocation failures
[pkg/abook.git] / xmalloc.c
index bc22a97b19faa6867ee9f8535a5b0ea52d3e2a3b..2b7fda6b666f2b0d715050b3ad486ff19a74c773 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "xmalloc.h"
 
 static void
 xmalloc_default_error_handler(int err)
@@ -134,10 +135,16 @@ xrealloc_inc(void *ptr, size_t size, size_t inc)
        return ptr;
 }
 
-void
-xfree(void *ptr)
+char *
+xstrdup(const char *s)
 {
-       free(ptr);
-       ptr = NULL;
+       size_t len = strlen(s);
+       void *new;
+
+       new = xmalloc_inc(len, 1);
+       if(new == NULL)
+               return NULL;
+
+       return (char *)memcpy(new, s, len + 1);
 }