summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/util.h')
-rw-r--r--lib/libalpm/util.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index d8e6cbd8..3b8fd83d 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -39,7 +39,12 @@
#define _(s) s
#endif
-#define FREE(p) do { if (p) { free(p); p = NULL; } } while(0)
+#define ALLOC_FAIL(s) do { _alpm_log(PM_LOG_ERROR, _("alloc failure: could not allocate %d bytes\n"), s); } while(0)
+
+#define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
+#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
+
+#define FREE(p) do { if(p) { free(p); p = NULL; } } while(0)
#define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)