]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | Uses @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 | 16 | #include <stddef.h> |
a9acf741 KG |
17 | |
18 | /* For systems with larger pointers than ints, this must be declared. */ | |
50b009c5 ML |
19 | void *malloc (size_t); |
20 | void bzero (void *, size_t); | |
a9acf741 | 21 | |
50b009c5 | 22 | void * |
9486db4f | 23 | calloc (size_t nelem, size_t elsize) |
a9acf741 | 24 | { |
50b009c5 | 25 | register void *ptr; |
a9acf741 KG |
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 | } |