New function: xalloc_and_zero()
This commit is contained in:
parent
4059151732
commit
699e159a7a
2 changed files with 16 additions and 0 deletions
|
@ -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));
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in a new issue