]> pd.if.org Git - pdclib/blob - functions/string/memset.c
4ee2826df79c300c856fd4cfa58214430de9c4a2
[pdclib] / functions / string / memset.c
1 /* memset( void *, int, size_t )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <string.h>
8
9 #ifndef REGTEST
10
11 void * memset( void * s, int c, size_t n )
12 {
13     unsigned char * p = (unsigned char *) s;
14     while ( n-- )
15     {
16         *p++ = (unsigned char) c;
17     }
18     return s;
19 }
20
21 #endif
22
23 #ifdef TEST
24 #include <_PDCLIB_test.h>
25
26 int main( void )
27 {
28     char s[] = "xxxxxxxxx";
29     TESTCASE( memset( s, 'o', 10 ) == s );
30     TESTCASE( s[9] == 'o' );
31     TESTCASE( memset( s, '_', 0 ) == s );
32     TESTCASE( s[0] == 'o' );
33     TESTCASE( memset( s, '_', 1 ) == s );
34     TESTCASE( s[0] == '_' );
35     TESTCASE( s[1] == 'o' );
36     return TEST_RESULTS;
37 }
38 #endif