summaryrefslogtreecommitdiffstats
path: root/src/compat/realloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat/realloc.c')
-rw-r--r--src/compat/realloc.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/compat/realloc.c b/src/compat/realloc.c
new file mode 100644
index 0000000..4d74064
--- /dev/null
+++ b/src/compat/realloc.c
@@ -0,0 +1,17 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/* realloc replacement that can reallocate 0 byte or NULL pointers*/
+
+#undef realloc
+#include <stdlib.h>
+#include <sys/types.h>
+#include "compat.h"
+
+/* Reallocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+void *
+rpl_realloc(void *ptr, size_t n)
+{
+ if (!ptr) return malloc(n);
+ if (n == 0) n = 1;
+ return realloc(ptr, n);
+}