From: Ralph Corderoy Date: Tue, 18 Oct 2016 15:33:12 +0000 (+0100) Subject: Rewrite r1bindex() using strrchr(3). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/106540f53db1a9b8d72f5392c343b9582a445044?hp=ab93c0ed5565bb0b878015b53365ed9cab1b2890 Rewrite r1bindex() using strrchr(3). --- diff --git a/sbr/r1bindex.c b/sbr/r1bindex.c index 92818f9a..b4ad0e8f 100644 --- a/sbr/r1bindex.c +++ b/sbr/r1bindex.c @@ -12,23 +12,17 @@ #include - char * r1bindex(char *str, int chr) { - char *cp; - - /* find null at the end of the string */ - for (cp = str; *cp; cp++) - continue; + char *r; - /* backup to the rightmost character */ - --cp; + if (!chr) + return str; /* Match old behaviour, don't know if it's used. */ - /* now search for the rightmost occurrence of the character */ - while (cp >= str && *cp != chr) - --cp; + r = strrchr(str, chr); + if (r) + return r + 1; - /* now move one to the right */ - return (++cp); + return str; }