]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/calloc.c
re PR other/10810 (gcc-3.3 fails make check: buffer overrun in test_demangle.c)
[thirdparty/gcc.git] / libiberty / calloc.c
CommitLineData
3da5522a
KG
1/* calloc -- allocate memory which has been initialized to zero.
2 This function is in the public domain. */
aaa5f039
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*/
3da5522a 14
a9acf741 15#include "ansidecl.h"
a9acf741
KG
16#ifdef ANSI_PROTOTYPES
17#include <stddef.h>
18#else
19#define size_t unsigned long
20#endif
21
22/* For systems with larger pointers than ints, this must be declared. */
23PTR malloc PARAMS ((size_t));
c9ac9147 24void bzero PARAMS ((PTR, size_t));
a9acf741
KG
25
26PTR
27calloc (nelem, elsize)
28 size_t nelem, elsize;
29{
30 register PTR ptr;
31
32 if (nelem == 0 || elsize == 0)
33 nelem = elsize = 1;
34
35 ptr = malloc (nelem * elsize);
36 if (ptr) bzero (ptr, nelem * elsize);
37
38 return ptr;
39}