aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2008-12-12 14:06:55 +0100
committerAndi Kleen <ak@linux.intel.com>2008-12-12 14:06:55 +0100
commit93cf332ea98d9ab4847e8129c63e7ff1ccc37ea0 (patch)
tree6beaba0c5c6ffd70ed2bd3f6919cf566f8441d68
parent52ce278dc54376ca27d3a96678fad9712d2aa58e (diff)
downloadmce-inject-93cf332ea98d9ab4847e8129c63e7ff1ccc37ea0.tar.gz
Add xcalloc()
Signed-off-by: Andi Kleen <ak@linux.intel.com>
-rw-r--r--util.c20
-rw-r--r--util.h1
2 files changed, 17 insertions, 4 deletions
diff --git a/util.c b/util.c
index 17fc0af..811a285 100644
--- a/util.c
+++ b/util.c
@@ -2,13 +2,25 @@
#include <stdio.h>
#include "util.h"
+void oom(void)
+{
+ fprintf(stderr, "Out of virtual memory\n");
+ exit(1);
+}
+
+void *xcalloc(size_t a, size_t b)
+{
+ void *p = calloc(a, b);
+ if (!p)
+ oom();
+ return p;
+}
+
void *xalloc(size_t sz)
{
void *p = calloc(sz, 1);
- if (!p) {
- fprintf(stderr, "Out of virtual memory\n");
- exit(1);
- }
+ if (!p)
+ oom();
return p;
}
diff --git a/util.h b/util.h
index 2ed47be..93fd295 100644
--- a/util.h
+++ b/util.h
@@ -3,6 +3,7 @@ void err(const char *msg);
#define NEW(x) ((x) = xalloc(sizeof(*(x))))
void *xalloc(size_t sz);
+void *xcalloc(size_t a, size_t b);
#ifdef __GNUC__
#define barrier() asm volatile("" ::: "memory")