]> pd.if.org Git - pdclib/blobdiff - functions/string/memset.c
Added test driver.
[pdclib] / functions / string / memset.c
index 2771ae1e580f0a86c242ff623657cc1cb3631668..735a8e60623dc1f9ebeb2cbf8e7f0a218e2efc7e 100644 (file)
@@ -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 <string.h>
+
+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