aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmalloc.c14
-rw-r--r--xmalloc.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/xmalloc.c b/xmalloc.c
index f249e397..d11d8dc7 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -71,6 +71,20 @@ xreallocarray(void *ptr, size_t nmemb, size_t size)
return new_ptr;
}
+void *
+xrecallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size)
+{
+ void *new_ptr;
+
+ if (nmemb == 0 || size == 0)
+ fatalx("xrecallocarray: zero size");
+ new_ptr = recallocarray(ptr, oldnmemb, nmemb, size);
+ if (new_ptr == NULL)
+ fatalx("xrecallocarray: allocating %zu * %zu bytes: %s",
+ nmemb, size, strerror(errno));
+ return new_ptr;
+}
+
char *
xstrdup(const char *str)
{
diff --git a/xmalloc.h b/xmalloc.h
index a3ee486f..3fe4f1cc 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -23,6 +23,7 @@ void *xmalloc(size_t);
void *xcalloc(size_t, size_t);
void *xrealloc(void *, size_t);
void *xreallocarray(void *, size_t, size_t);
+void *xrecallocarray(void *, size_t, size_t, size_t);
char *xstrdup(const char *);
char *xstrndup(const char *, size_t);
int xasprintf(char **, const char *, ...)