X-Git-Url: https://git.cworth.org/git?p=fips;a=blobdiff_plain;f=xmalloc.c;h=07490c234c59436c46a1350cf435f5447ad088c8;hp=22eb7cf49a6ce0de945327140421f2d7c7a31192;hb=2c71194f453bb34ff2291c2fa7c73582a3adb05e;hpb=f478c93ea71360d85328600703710ce16d378258 diff --git a/xmalloc.c b/xmalloc.c index 22eb7cf..07490c2 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -21,6 +21,7 @@ #include #include +#include #include "xmalloc.h" @@ -30,6 +31,38 @@ 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 * +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 +70,4 @@ xmalloc (size_t size) return ret; } +