aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/last_char_is.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c
index 4e2ee92ed..9bd70996c 100644
--- a/libbb/last_char_is.c
+++ b/libbb/last_char_is.c
@@ -28,13 +28,11 @@
*/
char * last_char_is(const char *s, int c)
{
- char *sret;
- if (!s)
- return NULL;
- sret = (char *)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;
}