]> diplodocus.org Git - nmh/blobdiff - sbr/r1bindex.c
new.c: Order two return statements to match comment.
[nmh] / sbr / r1bindex.c
index 92e152dbc7303b4d05ce1012a14bf9f94be2a59a..7dcabb50542d89895910c9006cc5b382cf1fd076 100644 (file)
@@ -1,12 +1,8 @@
-
-/*
- * 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.
  *
- * $Id$
- *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
 
 #include <h/mh.h>
 
-
 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;
 }