X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fwchar%2Fwmemchr.c;fp=functions%2Fwchar%2Fwmemchr.c;h=181da1510160682cd383cb9189634d27ce4894af;hb=507d3eccbf4c74e4694165f9e00ab79d894b4f66;hp=0000000000000000000000000000000000000000;hpb=0150bb9ffe66236b6a47c5800d8beef669d5c047;p=pdclib.old diff --git a/functions/wchar/wmemchr.c b/functions/wchar/wmemchr.c new file mode 100644 index 0000000..181da15 --- /dev/null +++ b/functions/wchar/wmemchr.c @@ -0,0 +1,39 @@ +/* wmemchr( const 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 + +#ifndef REGTEST + +wchar_t * wmemchr( const wchar_t * p, wchar_t c, size_t n ) +{ + while ( n-- ) + { + if ( *p == c ) + { + return (wchar_t*) p; + } + ++p; + } + return NULL; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( wmemchr( wabcde, L'c', 5 ) == &wabcde[2] ); + TESTCASE( wmemchr( wabcde, L'a', 1 ) == &wabcde[0] ); + TESTCASE( wmemchr( wabcde, L'a', 0 ) == NULL ); + TESTCASE( wmemchr( wabcde, L'\0', 5 ) == NULL ); + TESTCASE( wmemchr( wabcde, L'\0', 6 ) == &wabcde[5] ); + return TEST_RESULTS; +} + +#endif