diff options
Diffstat (limited to 'src/alloc.c')
-rw-r--r-- | src/alloc.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c new file mode 100644 index 0000000..35b45c0 --- /dev/null +++ b/src/alloc.c @@ -0,0 +1,18 @@ +#include <errno.h> +#include <stdint.h> +#include <stdlib.h> + +#include "alloc.h" +#include "errors.h" + +void * +bufalloc(void *ptr, size_t nmemb, size_t size) +{ + if (size > SIZE_MAX / nmemb) { + errno = EOVERFLOW; + err("%s:", __func__); + } + if ((ptr = realloc(ptr, nmemb * size)) == NULL) + err("%s:", __func__); + return ptr; +} |