]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
add the "x" wrapper for reallocarray(3)
authorMasatake YAMATO <yamato@redhat.com>
Sun, 28 May 2023 03:34:21 +0000 (12:34 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 28 May 2023 03:34:21 +0000 (12:34 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
include/xalloc.h

index 1dee5fe9c243941a8a68e9920cf824b596e091a8..da9245fdba3b6efc2a0bf092f8d09dc765c51397 100644 (file)
@@ -46,6 +46,18 @@ void *xrealloc(void *ptr, const size_t size)
        return ret;
 }
 
+static inline
+__ul_calloc_size(2, 3)
+__ul_returns_nonnull
+void *xreallocarray(void *ptr, const size_t nelems, const size_t size)
+{
+       void *ret = reallocarray(ptr, nelems, size);
+
+       if (!ret && size && nelems)
+               err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size);
+       return ret;
+}
+
 static inline
 __ul_calloc_size(1, 2)
 __ul_returns_nonnull