20 lines
377 B
C
20 lines
377 B
C
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <errno.h>
|
|
|
|
void *xcalloc(size_t nmemb, size_t size)
|
|
{
|
|
void *ptr = calloc(nmemb, size);
|
|
if (ptr == NULL && (nmemb || size))
|
|
abort();
|
|
return ptr;
|
|
}
|
|
|
|
void *reallocarray(void *ptr, size_t nmemb, size_t size)
|
|
{
|
|
if (nmemb && size > (SIZE_MAX / nmemb)) {
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
return realloc(ptr, nmemb * size);
|
|
}
|