libroot: add reallocarray() from POSIX.1-2024

Change-Id: I75d469ad9a01eb221ca607830589a7794eff71e8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8512
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Jérôme Duval
2024-11-04 17:55:40 +00:00
committed by waddlesplash
parent 592a3b6921
commit 30179dd326
3 changed files with 23 additions and 0 deletions
+1
View File
@@ -51,6 +51,7 @@ extern void *malloc(size_t size);
extern int posix_memalign(void **_pointer, size_t alignment, size_t size);
extern void *aligned_alloc(size_t alignment, size_t size) _ALIGNED_BY_ARG(1);
extern void *realloc(void *oldPointer, size_t newSize);
extern void *reallocarray(void *ptr, size_t nelem, size_t elsize);
/* process termination */
extern void abort(void) __attribute__((noreturn));
+1
View File
@@ -28,6 +28,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
qsort.c
radixsort.c
random.c
reallocarray.cpp
realpath.cpp
strfmon.c
strtol.c
@@ -0,0 +1,21 @@
/*
* Copyright 2024, Jérôme Duval, [email protected]
* Distributed under the terms of the MIT License.
*/
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
extern "C" void*
reallocarray(void* ptr, size_t nelem, size_t elsize)
{
if (elsize != 0 && nelem != 0 && nelem > SIZE_MAX / elsize) {
errno = ENOMEM;
return NULL;
}
return realloc(ptr, nelem * elsize);
}