summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/reallocarray.c
blob: 0626f8ac6b087cab0398fc8763840a515eb2c616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "stddef.h" // for NULL

#include <errno.h>  // for ENOMEM, errno
#include <stdlib.h> // for size_t, realloc, reallocarray

void *reallocarray(void *ptr, size_t nmemb, size_t size)
{
	size_t total = nmemb * size;
	if (nmemb != 0 && total / nmemb != size) {
		errno = ENOMEM;
		return NULL;
	}
	return realloc(ptr, total);
}