summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer2008-06-18 08:32:25 +0000
committerBernhard Reutner-Fischer2008-06-18 08:32:25 +0000
commit4954d47ab01624855fdf4bcf0a86fb86f6381638 (patch)
tree485cc14e7fa73ff69a308cb6bc63c190c65ac408
parent619b87dfa51588cc81c779f074c4532e18c0dbb1 (diff)
downloadbusybox-4954d47ab01624855fdf4bcf0a86fb86f6381638.zip
busybox-4954d47ab01624855fdf4bcf0a86fb86f6381638.tar.gz
- fixes from Tito
-rw-r--r--libbb/strrstr.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/libbb/strrstr.c b/libbb/strrstr.c
index 5a26859..126fed7 100644
--- a/libbb/strrstr.c
+++ b/libbb/strrstr.c
@@ -13,19 +13,16 @@
* The strrstr() function finds the last occurrence of the substring needle
* in the string haystack. The terminating nul characters are not compared.
*/
-char* strrstr(const char *haystack, const char *needle)
+char *strrstr(const char *haystack, const char *needle)
{
char *r = NULL;
-
- if (!needle[0])
- return r;
- while (1) {
- char *p = strstr(haystack, needle);
- if (!p)
- return r;
+
+ do {
+ char *p = strstr(haystack, needle);
+ if (p)
r = p;
- haystack = p + 1;
- }
+ } while (*haystack++);
+ return r;
}
#ifdef __DO_STRRSTR_TEST