X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fcalloc.c;h=fc1c80e767241ea033f2377d548aae42e0da4b37;hb=12e17136786afb1775c9dc946cbe41f5e230c24a;hp=1e568b4303551e4467ef721d35820082612d5981;hpb=7f3878e477390e4bb25fd37050633dc6e0023a7a;p=pdclib.old diff --git a/functions/stdlib/calloc.c b/functions/stdlib/calloc.c index 1e568b4..fc1c80e 100644 --- a/functions/stdlib/calloc.c +++ b/functions/stdlib/calloc.c @@ -15,9 +15,11 @@ void * calloc( size_t nmemb, size_t size ) { + /* assign memory for nmemb elements of given size */ void * rc = malloc( nmemb * size ); if ( rc != NULL ) { + /* zero-initialize the memory */ memset( rc, 0, nmemb * size ); } return rc; @@ -28,10 +30,9 @@ void * calloc( size_t nmemb, size_t size ) #ifdef TEST #include <_PDCLIB_test.h> -int main() +int main( void ) { char * s; - BEGIN_TESTS; TESTCASE( ( s = calloc( 3, 2 ) ) != NULL ); TESTCASE( s[0] == '\0' ); TESTCASE( s[5] == '\0' );