From f4e13626fdc62aad9c97731641d8e7177599680e Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Thu, 23 Dec 2004 15:15:03 +0000 Subject: [PATCH] added xcalloc [r4746] --- ir/adt/xmalloc.c | 8 +++++--- ir/adt/xmalloc.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ir/adt/xmalloc.c b/ir/adt/xmalloc.c index f2b1554e4..73b9cbe0c 100644 --- a/ir/adt/xmalloc.c +++ b/ir/adt/xmalloc.c @@ -37,20 +37,22 @@ xmalloc(size_t size) { void *res = malloc (size); if (!res) xnomem(); + return res; +} - memset(res, 0x00, size); +void *xcalloc(size_t num, size_t size) { + void res = calloc(num, size); + if (!res) xnomem(); return res; } - void * xrealloc(void *ptr, size_t size) { /* ANSI blesses realloc (0, x) but SunOS chokes on it */ void *res = ptr ? realloc (ptr, size) : malloc (size); if (!res) xnomem (); - return res; } diff --git a/ir/adt/xmalloc.h b/ir/adt/xmalloc.h index 63bc309d4..9d4048c1d 100644 --- a/ir/adt/xmalloc.h +++ b/ir/adt/xmalloc.h @@ -19,6 +19,7 @@ /* xmalloc() & friends. */ void *xmalloc(size_t size); +void *xcalloc(size_t num, size_t size); void *xrealloc(void *ptr, size_t size); char *xstrdup(const char *str); void xnomem(void); -- 2.20.1