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