Apply vodz' last_patch52
[oweals/busybox.git] / libbb / last_char_is.c
index b4bb7ec32fad30cbae5177498d6e3653a787af92..4e2ee92ed9a71a2231a4bdafeaef1062e972ea98 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.
  */
-int last_char_is(const char *s, const int c)
+char * last_char_is(const char *s, int c)
 {
-       int  l = strlen(s);
-       if (l==0) return 0;
-       return (s[l-1] == c);
+       char *sret;
+       if (!s)
+           return NULL;
+       sret  = (char *)s+strlen(s)-1;
+       if (sret>=s && *sret == c) { 
+               return sret;
+       } else {
+               return NULL;
+       }
 }