aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-01-30 08:06:24 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-02-05 12:35:16 +0000
commitaae794e9bdd5f19019560041479cf7ebc46b4fa5 (patch)
tree9081f69f3e50dfffbcfb6e56169476cbae7e926c
parentbox-drawings: handle architecture with soft-float (diff)
xmalloc: add xreallocarray()
-rw-r--r--xmalloc.c7
-rw-r--r--xmalloc.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/xmalloc.c b/xmalloc.c
index ded7f4e3..0a67cdb2 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -36,6 +36,13 @@ xrealloc(void *ptr, size_t size)
return unlikely(size == 0) ? alloc : check_alloc(alloc);
}
+void *
+xreallocarray(void *ptr, size_t n, size_t size)
+{
+ void *alloc = reallocarray(ptr, n, size);
+ return unlikely(size == 0) ? alloc : check_alloc(alloc);
+}
+
char *
xstrdup(const char *str)
{
diff --git a/xmalloc.h b/xmalloc.h
index 8a2c208f..03e6eb0d 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -12,6 +12,7 @@
void *xmalloc(size_t size) XMALLOC;
void *xcalloc(size_t nmemb, size_t size) XMALLOC;
void *xrealloc(void *ptr, size_t size);
+void *xreallocarray(void *ptr, size_t n, size_t size);
char *xstrdup(const char *str) XSTRDUP;
char *xstrndup(const char *str, size_t n) XSTRDUP;
char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC;