From: Ivo Timmermans Date: Fri, 20 Oct 2000 16:43:13 +0000 (+0000) Subject: New function: xalloc_and_zero() X-Git-Tag: release-1.0.3~90 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=699e159a7a1711034f1d16d68ad1974a82e12dfc;p=tinc New function: xalloc_and_zero() --- diff --git a/lib/xalloc.h b/lib/xalloc.h index e77e6a57..84b6cacf 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -19,5 +19,6 @@ extern char *const xalloc_msg_memory_exhausted; extern void (*xalloc_fail_func) (); void *xmalloc PARAMS ((size_t n)); +void *xmalloc_and_zero PARAMS ((size_t n)); void *xcalloc PARAMS ((size_t n, size_t s)); void *xrealloc PARAMS ((void *p, size_t n)); diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 150b1aa7..037fab87 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -94,6 +94,21 @@ xmalloc (n) return p; } +/* Allocate N bytes of memory dynamically, and set it all to zero. */ + +void * +xmalloc_and_zero (n) + size_t n; +{ + void *p; + + p = malloc (n); + if (p == 0) + xalloc_fail ((int)n); + memset (p, '\0', n); + return p; +} + /* Change the size of an allocated block of memory P to N bytes, with error checking. If P is NULL, run xmalloc. */