xref: /haiku/src/system/libroot/posix/stdlib/reallocarray.cpp (revision 344ded80d400028c8f561b4b876257b94c12db4a)
1 /*
2  * Copyright 2024, Jérôme Duval, jerome.duval@gmail.com
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <stdlib.h>
8 
9 #include <errno.h>
10 #include <stdint.h>
11 
12 
13 extern "C" void*
14 reallocarray(void* ptr, size_t nelem, size_t elsize)
15 {
16 	if (elsize != 0 && nelem != 0 && nelem > SIZE_MAX / elsize) {
17 		errno = ENOMEM;
18 		return NULL;
19 	}
20 	return realloc(ptr, nelem * elsize);
21 }
22