UE: factorize calloc() calls and exit on failure

This commit is contained in:
Frédéric Leroy
2017-01-25 13:29:10 +01:00
parent dcf35b2af1
commit e36aee0b7f
13 changed files with 62 additions and 147 deletions
+23
View File
@@ -0,0 +1,23 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "utils.h"
void *calloc_or_fail(size_t size) {
void *ptr = calloc(1, size);
if (ptr == NULL) {
fprintf(stderr, "[UE] Failed to calloc %zu bytes", size);
exit(EXIT_FAILURE);
}
return ptr;
}
void *malloc_or_fail(size_t size) {
void *ptr = malloc(size);
if (ptr == NULL) {
fprintf(stderr, "[UE] Failed to malloc %zu bytes", size);
exit(EXIT_FAILURE);
}
return ptr;
}