summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-09-18 07:04:05 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-09-18 07:04:05 +0000
commita20f32d2a504a6dcbd0cc626bea68ef546ab17ad (patch)
tree9d48a00ccefde90ad95088fc73d29c06c522c433
parent2077cebca00f57061b6a2c0ba41ab24cc97f3596 (diff)
downloadrockbox-a20f32d2a504a6dcbd0cc626bea68ef546ab17ad.tar.gz
rockbox-a20f32d2a504a6dcbd0cc626bea68ef546ab17ad.zip
import and use the Linux one instead, bound to be faster
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14741 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/strstr.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/firmware/common/strstr.c b/firmware/common/strstr.c
index 2f33629997..73fab1cc63 100644
--- a/firmware/common/strstr.c
+++ b/firmware/common/strstr.c
@@ -7,39 +7,32 @@
* \/ \/ \/ \/ \/
* $Id: $
*
- * Copyright (C) 2007 by Christian Gmeiner
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ * (from linux/lib/string.c)
*
****************************************************************************/
#include <string.h>
/**
- * Locate substring.
- * @param search c string to be scanned.
- * @param find c string containing the sequence of characters to match.
- * @return a pointer to the first occurrence in search of any of the
- * entire sequence of characters specified in find, or a
- * null pointer if the sequence is not present in search.
+ * strstr - Find the first substring in a %NUL terminated string
+ * @s1: The string to be searched
+ * @s2: The string to search for
*/
-char *strstr(const char *search, const char *find)
+char *strstr(const char *s1, const char *s2)
{
- char *hend;
- char *a, *b;
+ int l1, l2;
- if (*find == 0) return (char*)search;
- hend = (char *)search + strlen(search) - strlen(find) + 1;
- while (search < hend) {
- if (*search == *find) {
- a = (char *)search;
- b = (char *)find;
- for (;;) {
- if (*b == 0) return (char*)search;
- if (*a++ != *b++) {
- break;
- }
- }
- }
- search++;
+ l2 = strlen(s2);
+ if (!l2)
+ return (char *)s1;
+ l1 = strlen(s1);
+ while (l1 >= l2) {
+ l1--;
+ if (!memcmp(s1, s2, l2))
+ return (char *)s1;
+ s1++;
}
- return 0;
+ return NULL;
}
+