diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-05-16 15:00:44 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-05-16 15:00:44 +0800 |
| commit | e1a2e4150e1b1e6ddedde72dcb9c7146f6eaf85a (patch) | |
| tree | bd05c52569e647b5c43038dc76c4037d2f298115 | |
| parent | e3f60d06d45a89ad16831c4ea20bb67277e588b6 (diff) | |
| download | glacier-e1a2e4150e1b1e6ddedde72dcb9c7146f6eaf85a.tar.gz | |
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | mem.h | 28 |
2 files changed, 29 insertions, 1 deletions
@@ -2,7 +2,7 @@ CC = cc CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -g -O0 LDFLAGS = -HDRS = +HDRS = mem.h SRCS = main.c OBJS = $(SRCS:.c=.o) TARGET = glacier @@ -0,0 +1,28 @@ +#ifndef MEM_H +#define MEM_H + +#include <err.h> +#include <stdlib.h> + +#define MALLOC(s) xmalloc((s), __FILE__, __LINE__) +#define REALLOC(p, s) xrealloc((p), (s), __FILE__, __LINE__) + +static inline void *xmalloc(size_t s, const char *file, int line) +{ + void *p; + + if (!(p = malloc(s))) + err(1, "%s:%d: malloc", file, line); + return p; +} + +static inline void *xrealloc(void *ptr, size_t s, const char *file, int line) +{ + void *p; + + if (!(p = realloc(ptr, s))) + err(1, "%s:%d: realloc", file, line); + return p; +} + +#endif /* MEM_H */ |
