diff options
author | Andi Kleen <ak@linux.intel.com> | 2008-12-12 14:06:55 +0100 |
---|---|---|
committer | Andi Kleen <ak@linux.intel.com> | 2008-12-12 14:06:55 +0100 |
commit | 93cf332ea98d9ab4847e8129c63e7ff1ccc37ea0 (patch) | |
tree | 6beaba0c5c6ffd70ed2bd3f6919cf566f8441d68 | |
parent | 52ce278dc54376ca27d3a96678fad9712d2aa58e (diff) | |
download | mce-inject-93cf332ea98d9ab4847e8129c63e7ff1ccc37ea0.tar.gz |
Add xcalloc()
Signed-off-by: Andi Kleen <ak@linux.intel.com>
-rw-r--r-- | util.c | 20 | ||||
-rw-r--r-- | util.h | 1 |
2 files changed, 17 insertions, 4 deletions
@@ -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; } @@ -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") |