X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/5dd6771b28c257af405d7248639ed0e3bcdce38b..54fb590089a2bf43d7987861ba57acb17cebc150:/sbr/r1bindex.c?ds=sidebyside diff --git a/sbr/r1bindex.c b/sbr/r1bindex.c index 92818f9a..7dcabb50 100644 --- a/sbr/r1bindex.c +++ b/sbr/r1bindex.c @@ -1,6 +1,4 @@ - -/* - * r1bindex.c -- Given a string and a character, return a pointer +/* r1bindex.c -- Given a string and a character, return a pointer * -- to the right of the rightmost occurrence of the * -- character. If the character doesn't occur, the * -- pointer will be at the beginning of the string. @@ -12,23 +10,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; }