cls_multi_schar.c (main): Fix initialization error.
[official-gcc.git] / libiberty / calloc.c
blob50736823077c017e799f596873668629c932659c
1 /* calloc -- allocate memory which has been initialized to zero.
2 This function is in the public domain. */
4 /*
6 @deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
8 Uses @code{malloc} to allocate storage for @var{nelem} objects of
9 @var{elsize} bytes each, then zeros the memory.
11 @end deftypefn
15 #include "ansidecl.h"
16 #ifdef ANSI_PROTOTYPES
17 #include <stddef.h>
18 #else
19 #define size_t unsigned long
20 #endif
22 /* For systems with larger pointers than ints, this must be declared. */
23 PTR malloc PARAMS ((size_t));
24 void bzero PARAMS ((PTR, size_t));
26 PTR
27 calloc (nelem, elsize)
28 size_t nelem, elsize;
30 register PTR ptr;
32 if (nelem == 0 || elsize == 0)
33 nelem = elsize = 1;
35 ptr = malloc (nelem * elsize);
36 if (ptr) bzero (ptr, nelem * elsize);
38 return ptr;