*** empty log message ***
[deliverable/binutils-gdb.git] / libiberty / calloc.c
CommitLineData
e2eaf477
ILT
1/* calloc -- allocate memory which has been initialized to zero.
2 This function is in the public domain. */
39423523
DD
3
4/*
5
6@deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
7
8Uses @code{malloc} to allocate storage for @var{nelem} objects of
9@var{elsize} bytes each, then zeros the memory.
10
11@end deftypefn
12
13*/
e2eaf477 14
252b5132 15#include "ansidecl.h"
252b5132 16#include <stddef.h>
252b5132
RH
17
18/* For systems with larger pointers than ints, this must be declared. */
9334f9c6
DD
19PTR malloc (size_t);
20void bzero (PTR, size_t);
252b5132
RH
21
22PTR
9334f9c6 23calloc (size_t nelem, size_t elsize)
252b5132
RH
24{
25 register PTR ptr;
26
27 if (nelem == 0 || elsize == 0)
28 nelem = elsize = 1;
29
30 ptr = malloc (nelem * elsize);
31 if (ptr) bzero (ptr, nelem * elsize);
32
33 return ptr;
34}
This page took 0.528328 seconds and 4 git commands to generate.