]> git.cworth.org Git - fips/blobdiff - xmalloc.c
Add explicit link to libpthread, to work around debugging issues
[fips] / xmalloc.c
index 22eb7cf49a6ce0de945327140421f2d7c7a31192..e8b93670f0f086503f5f20558df9f5b254711bda 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "xmalloc.h"
 
@@ -30,6 +31,52 @@ xmalloc (size_t size)
        void *ret;
 
        ret = malloc (size);
+       if (size != 0 && ret == NULL) {
+               fprintf (stderr, "Out of memory\n");
+               exit (1);
+       }
+
+       return ret;
+}
+
+void *
+xcalloc (size_t nmemb, size_t size)
+{
+       void *ret;
+
+       ret = calloc (nmemb, size);
+       if (size != 0 && ret == NULL) {
+               fprintf (stderr, "Out of memory\n");
+               exit (1);
+       }
+
+       return ret;
+}
+
+void *
+xrealloc (void *ptr, size_t size)
+{
+       void *ret;
+
+       ret = realloc (ptr, size);
+       if (size != 0 && ret == NULL) {
+               fprintf (stderr, "Out of memory\n");
+               exit (1);
+       }
+
+       return ret;
+}
+
+char *
+xstrdup (const char *s)
+{
+       void *ret;
+
+       if (s == NULL)
+               return NULL;
+
+       ret = strdup (s);
+
        if (ret == NULL) {
                fprintf (stderr, "Out of memory\n");
                exit (1);
@@ -37,3 +84,4 @@ xmalloc (size_t size)
 
        return ret;
 }
+