]> diplodocus.org Git - nmh/blobdiff - sbr/r1bindex.c
crawl_folders.h: Rename to be alongside implementation.
[nmh] / sbr / r1bindex.c
index 92818f9a5f68455a975ad09197447298e436973d..fb4595c0cd66f755a1af8ec547e887f294a3b55d 100644 (file)
@@ -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.
  * complete copyright information.
  */
 
-#include <h/mh.h>
-
+#include "h/mh.h"
+#include "r1bindex.h"
 
+/* Does not return NULL. */
 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;
 }