X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrrchr.c;h=7387f22f0e1953687154e312e030d0c80a9f8a82;hb=b1fc26afebd4d557ff89a44bc21767a8704c3809;hp=b29d0a6e26525d236a5d7ec64d963fb2c4e91b3a;hpb=c0169638bd02098717cb23fbbca3bcc4e4caccf0;p=pdclib diff --git a/functions/string/strrchr.c b/functions/string/strrchr.c index b29d0a6..7387f22 100644 --- a/functions/string/strrchr.c +++ b/functions/string/strrchr.c @@ -1,8 +1,4 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* strrchr( const char *, int c ) +/* strrchr( const char *, int ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -10,18 +6,34 @@ #include +#ifndef REGTEST + char * strrchr( const char * s, int c ) { size_t i = 0; - while ( p[i++] ); + while ( s[i++] ); do { - if ( p[--i] == (char) c ) + if ( s[--i] == (char) c ) { - return (char *) p + i; + return (char *) s + i; } } while ( i ); return NULL; } -#warning Test driver missing. +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + char abccd[] = "abccd"; + TESTCASE( strrchr( abcde, '\0' ) == &abcde[5] ); + TESTCASE( strrchr( abcde, 'e' ) == &abcde[4] ); + TESTCASE( strrchr( abcde, 'a' ) == &abcde[0] ); + TESTCASE( strrchr( abccd, 'c' ) == &abccd[3] ); + return TEST_RESULTS; +} +#endif