diff options
-rw-r--r-- | libbb/strrstr.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/libbb/strrstr.c b/libbb/strrstr.c index 5a2685920..126fed75c 100644 --- a/libbb/strrstr.c +++ b/libbb/strrstr.c | |||
@@ -13,19 +13,16 @@ | |||
13 | * The strrstr() function finds the last occurrence of the substring needle | 13 | * The strrstr() function finds the last occurrence of the substring needle |
14 | * in the string haystack. The terminating nul characters are not compared. | 14 | * in the string haystack. The terminating nul characters are not compared. |
15 | */ | 15 | */ |
16 | char* strrstr(const char *haystack, const char *needle) | 16 | char *strrstr(const char *haystack, const char *needle) |
17 | { | 17 | { |
18 | char *r = NULL; | 18 | char *r = NULL; |
19 | 19 | ||
20 | if (!needle[0]) | 20 | do { |
21 | return r; | 21 | char *p = strstr(haystack, needle); |
22 | while (1) { | 22 | if (p) |
23 | char *p = strstr(haystack, needle); | ||
24 | if (!p) | ||
25 | return r; | ||
26 | r = p; | 23 | r = p; |
27 | haystack = p + 1; | 24 | } while (*haystack++); |
28 | } | 25 | return r; |
29 | } | 26 | } |
30 | 27 | ||
31 | #ifdef __DO_STRRSTR_TEST | 28 | #ifdef __DO_STRRSTR_TEST |