mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
libroot: add reallocarray() from POSIX.1-2024
Change-Id: I75d469ad9a01eb221ca607830589a7794eff71e8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8512 Reviewed-by: waddlesplash <waddlesplash@gmail.com> Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
parent
592a3b6921
commit
30179dd326
@ -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));
|
||||
|
@ -28,6 +28,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
qsort.c
|
||||
radixsort.c
|
||||
random.c
|
||||
reallocarray.cpp
|
||||
realpath.cpp
|
||||
strfmon.c
|
||||
strtol.c
|
||||
|
21
src/system/libroot/posix/stdlib/reallocarray.cpp
Normal file
21
src/system/libroot/posix/stdlib/reallocarray.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2024, Jérôme Duval, jerome.duval@gmail.com
|
||||
* 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user