ccc/util.c

30 lines
540 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
void die(char *reason)
{
2024-03-10 11:54:08 +01:00
fprintf(stderr, "%s\n", reason);
exit(EXIT_FAILURE);
}
void *memalloc(size_t size)
{
void *ptr = malloc(size);
if (!ptr) {
fprintf(stderr, "ccc: Error allocating memory\n");
exit(EXIT_FAILURE);
}
return ptr;
}
void *rememalloc(void *ptr, size_t size)
{
ptr = realloc(ptr, size);
if (!ptr) {
perror("ccc");
fprintf(stderr, "ccc: Error allocating memory\n");
exit(EXIT_FAILURE);
}
return ptr;
}