X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fmemset.c;h=735a8e60623dc1f9ebeb2cbf8e7f0a218e2efc7e;hb=0c09ab83dad5042cd2a78cebe8273728feb2f45a;hp=2771ae1e580f0a86c242ff623657cc1cb3631668;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec;p=pdclib diff --git a/functions/string/memset.c b/functions/string/memset.c index 2771ae1..735a8e6 100644 --- a/functions/string/memset.c +++ b/functions/string/memset.c @@ -1,8 +1,39 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- - -void * memset( void * s, int c, size_t n ) { /* TODO */ }; +/* $Id$ */ + +/* Release $Name$ */ + +/* memset( void *, int, 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 + +void * memset( void * s, int c, size_t n ) +{ + unsigned char * p = (unsigned char *) s; + while ( n-- ) + { + *p++ = (unsigned char) c; + } + return s; +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + char s[10] = "xxxxxxxxx"; + BEGIN_TESTS; + TESTCASE( memset( s, 'o', 10 ) == s ); + TESTCASE( s[9] == 'o' ); + TESTCASE( memset( s, '_', 0 ) == s ); + TESTCASE( s[0] == 'o' ); + TESTCASE( memset( s, '_', 1 ) == s ); + TESTCASE( s[0] == '_' ); + TESTCASE( s[1] == 'o' ); + return TEST_RESULTS; +} +#endif