From: solar Date: Mon, 30 Jan 2006 20:52:12 +0000 (+0000) Subject: Initial checkin. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=43641351ed6e3781a06055d82a54b95c2c31fd97;p=fw%2Fpdclib Initial checkin. git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@130 546481bc-9713-0410-bf18-d3337bbf4a3e --- diff --git a/functions/stdlib/calloc.c b/functions/stdlib/calloc.c new file mode 100644 index 0000000..1e568b4 --- /dev/null +++ b/functions/stdlib/calloc.c @@ -0,0 +1,50 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* void * calloc( size_t, size_t ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST + +void * calloc( size_t nmemb, size_t size ) +{ + void * rc = malloc( nmemb * size ); + if ( rc != NULL ) + { + memset( rc, 0, nmemb * size ); + } + return rc; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + char * s; + BEGIN_TESTS; + TESTCASE( ( s = calloc( 3, 2 ) ) != NULL ); + TESTCASE( s[0] == '\0' ); + TESTCASE( s[5] == '\0' ); + free( s ); + TESTCASE( ( s = calloc( 6, 1 ) ) != NULL ); + TESTCASE( s[0] == '\0' ); + TESTCASE( s[5] == '\0' ); + free( s ); + TESTCASE( ( s = calloc( 1, 6 ) ) != NULL ); + TESTCASE( s[0] == '\0' ); + TESTCASE( s[5] == '\0' ); + free( s ); + return TEST_RESULTS; +} + +#endif