summaryrefslogtreecommitdiffstats
path: root/mem.h
diff options
context:
space:
mode:
Diffstat (limited to 'mem.h')
-rw-r--r--mem.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/mem.h b/mem.h
index 032740c..2cdb36e 100644
--- a/mem.h
+++ b/mem.h
@@ -5,6 +5,7 @@
#include <stdlib.h>
#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)
@@ -16,6 +17,15 @@ static inline void *xmalloc(size_t s, const char *file, int line)
return p;
}
+static inline void *xcalloc(size_t n, size_t s, const char *file, int line)
+{
+ void *p;
+
+ if (!(p = calloc(n, s)))
+ err(1, "%s:%d: calloc", file, line);
+ return p;
+}
+
static inline void *xrealloc(void *ptr, size_t s, const char *file, int line)
{
void *p;