aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.h
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2024-03-16 20:28:10 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-03-17 11:31:02 +0000
commite8b04e0e2c9e8a4f825193b907d04c3b3165a842 (patch)
treee09c19881361236101249e846d7ac8618ca4baab /xmalloc.h
parentmain/config: replace some uses of xasprintf() with xstrjoin() (diff)
xmalloc: add xmemdup() and use to replace some uses of xmalloc+memcpy
Diffstat (limited to 'xmalloc.h')
-rw-r--r--xmalloc.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/xmalloc.h b/xmalloc.h
index 74282f8f..67fa5c43 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -18,6 +18,12 @@ char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC;
char *xvasprintf(const char *format, va_list va) VPRINTF(1) XMALLOC;
char32_t *xc32dup(const char32_t *str) XSTRDUP;
+static inline void *
+xmemdup(const void *ptr, size_t size)
+{
+ return memcpy(xmalloc(size), ptr, size);
+}
+
static inline char *
xstrjoin(const char *s1, const char *s2)
{