From e8b04e0e2c9e8a4f825193b907d04c3b3165a842 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 16 Mar 2024 20:28:10 +0000 Subject: xmalloc: add xmemdup() and use to replace some uses of xmalloc+memcpy --- xmalloc.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'xmalloc.h') 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) { -- cgit v1.3