diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/last_char_is.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index 3616d5916..aaa85ddd9 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c | |||
@@ -9,15 +9,15 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | /* Find out if the last character of a string matches the one given Don't | 12 | /* Find out if the last character of a string matches the one given. |
13 | * underrun the buffer if the string length is 0. Also avoids a possible | 13 | * Don't underrun the buffer if the string length is 0. |
14 | * space-hogging inline of strlen() per usage. | ||
15 | */ | 14 | */ |
16 | char* last_char_is(const char *s, int c) | 15 | char* last_char_is(const char *s, int c) |
17 | { | 16 | { |
18 | if (s) { | 17 | if (s && *s) { |
19 | s = strrchr(s, c); | 18 | size_t sz = strlen(s) - 1; |
20 | if (s && !s[1]) | 19 | s += sz; |
20 | if ( (unsigned char)*s == c) | ||
21 | return (char*)s; | 21 | return (char*)s; |
22 | } | 22 | } |
23 | return NULL; | 23 | return NULL; |