]> git.cworth.org Git - acre/blobdiff - xmalloc.c
Add xstrdup
[acre] / xmalloc.c
index 8c97b0f95f5d0921dbc081b2f7569b257528f98f..bc6be9fb112841f1f22fc9c6f7588c45003f4e45 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -23,7 +23,9 @@
  */
 
 #include "xmalloc.h"
+
 #include <stdio.h>
+#include <string.h>
 
 /* Allocate memory using malloc(), checking for errors.
  *
@@ -60,3 +62,17 @@ xrealloc (void *ptr, size_t size)
 
     return ret;
 }
+
+char *
+xstrdup (const char *s)
+{
+    char *ret;
+
+    ret = strdup (s);
+    if (ret == NULL) {
+       fprintf (stderr, "Error: out of memory. Exiting.\n");
+       exit (1);
+    }
+
+    return ret;
+}