sync with waldi
[oweals/busybox.git] / libbb / last_char_is.c
index 36b695b40af3136a6135efcf013a11702f51b02f..9bd70996c03f362833f6f49748579069dd8545e3 100644 (file)
  *
  */
 
+#include <string.h>
 #include "libbb.h"
 
 /* Find out if the last character of a string matches the one given Don't
  * underrun the buffer if the string length is 0.  Also avoids a possible
  * space-hogging inline of strlen() per usage.
  */
-char * last_char_is(char *s, int c)
+char * last_char_is(const char *s, int c)
 {
-       char *sret  = s+strlen(s)-1;
-       if (sret>=s && *sret == c) { 
-               return sret;
-       } else {
-               return NULL;
+       char *sret = (char *)s;
+       if (sret) {
+               sret = strrchr(sret, c);
+               if(sret != NULL && *(sret+1) != 0)
+                       sret = NULL;
        }
+       return sret;
 }