summaryrefslogtreecommitdiff
path: root/lib/xmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xmalloc.c')
-rw-r--r--lib/xmalloc.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index bc386c83..da2f0941 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -32,4 +32,24 @@ xmalloc(unsigned size)
die("Unable to allocate %d bytes of memory", size);
}
+/**
+ * xrealloc - realloc with checking
+ * @ptr: original memory block
+ * @size: block size
+ *
+ * This function is equivalent to realloc() except that in case of
+ * failure it calls die() to quit the program instead of returning
+ * a %NULL pointer.
+ *
+ * Wherever possible, please use the memory resources instead.
+ */
+void *
+xrealloc(void *ptr, unsigned size)
+{
+ void *p = realloc(ptr, size);
+ if (p)
+ return p;
+ die("Unable to allocate %d bytes of memory", size);
+}
+
#endif