Back to index

cell-binutils  2.17cvs20070401
calloc.c
Go to the documentation of this file.
00001 /* calloc -- allocate memory which has been initialized to zero.
00002    This function is in the public domain. */
00003 
00004 /*
00005 
00006 @deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
00007 
00008 Uses @code{malloc} to allocate storage for @var{nelem} objects of
00009 @var{elsize} bytes each, then zeros the memory.
00010 
00011 @end deftypefn
00012 
00013 */
00014  
00015 #include "ansidecl.h"
00016 #include <stddef.h>
00017 
00018 /* For systems with larger pointers than ints, this must be declared.  */
00019 PTR malloc (size_t);
00020 void bzero (PTR, size_t);
00021 
00022 PTR
00023 calloc (size_t nelem, size_t elsize)
00024 {
00025   register PTR ptr;  
00026 
00027   if (nelem == 0 || elsize == 0)
00028     nelem = elsize = 1;
00029   
00030   ptr = malloc (nelem * elsize);
00031   if (ptr) bzero (ptr, nelem * elsize);
00032   
00033   return ptr;
00034 }