X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fmemchr.c;h=fac50549cf0d0b9bf7041786737ca355f5cdde6a;hb=3309ec3ad8a5db735eaa2de7f5dc6a331d8e7319;hp=1c9563c7efa3641f166009935fe281cb0ce00c06;hpb=c8f799d852e3698468a78954d82588e841cc0b70;p=pdclib.old diff --git a/functions/string/memchr.c b/functions/string/memchr.c index 1c9563c..fac5054 100644 --- a/functions/string/memchr.c +++ b/functions/string/memchr.c @@ -1,16 +1,18 @@ -/* ---------------------------------------------------------------------------- - * $Id$ - * ---------------------------------------------------------------------------- - * Public Domain C Library - http://pdclib.sourceforge.net - * This code is Public Domain. Use, modify, and redistribute at will. - * --------------------------------------------------------------------------*/ +/* $Id$ */ -#include <__size_t.h> -#include <__NULL.h> +/* memchr( const void *, int, size_t ) -void * memchr( const void * src, int c, size_t n ) + 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 + +void * memchr( const void * s, int c, size_t n ) { - const unsigned char * p = (const unsigned char *) src; + const unsigned char * p = (const unsigned char *) s; while ( n-- ) { if ( *p == (unsigned char) c ) @@ -21,3 +23,20 @@ void * memchr( const void * src, int c, size_t n ) } return NULL; } + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + 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