This commit is contained in:
2026-05-13 08:07:13 -05:00
parent 19bff9b32f
commit 7501c74712
6 changed files with 65 additions and 26 deletions

31
lib/utils.c Normal file
View File

@@ -0,0 +1,31 @@
#include "priv.h"
#include <stdlib.h>
#include <stdio.h>
__attribute__((noreturn)) void out_of_memory(void)
{
fprintf(stderr, "out of memory\n");
abort();
}
void* xmalloc(size_t n)
{
void* p = malloc(n);
if (!p) out_of_memory();
return p;
}
void* xcalloc(size_t n, size_t size)
{
void* p = calloc(n, size);
if (!p) out_of_memory();
return p;
}
void* xrealloc(void* p, size_t n)
{
void* q = realloc(p, n);
if (!q) out_of_memory();
return q;
}