]> pd.if.org Git - pdclib/blobdiff - functions/string/memchr.c
Added #ifdef to allow regression against system lib.
[pdclib] / functions / string / memchr.c
index 9aef229e69f040f5b74b150c3987f633ba692a13..972e7ffa82038908872e99f22e5ed2c4d9566922 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <string.h>
 
+#ifndef REGTEST
+
 void * memchr( const void * s, int c, size_t n )
 {
     const unsigned char * p = (const unsigned char *) s;
@@ -24,4 +26,19 @@ void * memchr( const void * s, int c, size_t n )
     return NULL;
 }
 
-#warning Test driver missing.
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main()
+{
+    BEGIN_TESTS;
+    TESTCASE( memchr( abcde, 'c', 5 ) == &abcde[2] );
+    TESTCASE( memchr( abcde, 'a', 1 ) == &abcde[0] );
+    TESTCASE( memchr( abcde, 'a', 0 ) == NULL );
+    TESTCASE( memchr( abcde, '\0', 5 ) == NULL );
+    TESTCASE( memchr( abcde, '\0', 6 ) == &abcde[5] );
+    return TEST_RESULTS;
+}
+#endif