Move Autoconf's macro definitions into config.h.
[openvswitch] / lib / util.c
index 846ac880f2a3bc9ccd93a4e28f9e184602a1f48f..59c7806e61e3dc6cf46fa3974904a6c20dd2dfe1 100644 (file)
@@ -31,6 +31,7 @@
  * derivatives without specific, written prior permission.
  */
 
+#include <config.h>
 #include "util.h"
 #include <stdarg.h>
 #include <stdio.h>
@@ -75,13 +76,27 @@ xrealloc(void *p, size_t size)
     return p;
 }
 
+void *
+xmemdup(const void *p_, size_t size)
+{
+    void *p = xmalloc(size);
+    memcpy(p, p_, size);
+    return p;
+}
+
 char *
-xstrdup(const char *s_) 
+xmemdup0(const char *p_, size_t length)
 {
-    size_t size = strlen(s_) + 1;
-    char *s = xmalloc(size);
-    memcpy(s, s_, size);
-    return s;
+    char *p = xmalloc(length + 1);
+    memcpy(p, p_, length);
+    p[length] = '\0';
+    return p;
+}
+
+char *
+xstrdup(const char *s) 
+{
+    return xmemdup0(s, strlen(s));
 }
 
 char *