From 9914d496eb45aca6522a295ce9bf03e2cd1503a5 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sat, 24 Oct 2026 08:13:27 +0800 Subject: Add mtmd to Makefile. --- mem.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 mem.h (limited to 'mem.h') diff --git a/mem.h b/mem.h new file mode 100644 index 0000000..b6ca7d6 --- /dev/null +++ b/mem.h @@ -0,0 +1,46 @@ +#ifndef MEM_H +#define MEM_H + +#include +#include +#include + +#define MALLOC(s) xmalloc((s), __FILE__, __LINE__) +#define CALLOC(n, s) xcalloc((n), (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))) { + syslog(LOG_ERR, "malloc: %s (line %d)", file, line); + exit(1); + } + return p; +} + +static inline void *xcalloc(size_t n, size_t s, const char *file, int line) +{ + void *p; + + if (!(p = calloc(n, s))) { + syslog(LOG_ERR, "calloc: %s (line %d)", file, line); + exit(1); + } + return p; +} + +static inline void *xrealloc(void *ptr, size_t s, const char *file, int line) +{ + void *p; + + if (!(p = realloc(ptr, s))) { + syslog(LOG_ERR, "realloc: %s (line %d)", file, line); + exit(1); + } + return p; +} + +#endif /* MEM_H */ + -- cgit v1.2.3