summaryrefslogtreecommitdiff
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 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id: $ 8 * $Id: $
9 * 9 *
10 * Copyright (C) 2007 by Christian Gmeiner 10 * Copyright (C) 1991, 1992 Linus Torvalds
11 * (from linux/lib/string.c)
11 * 12 *
12 ****************************************************************************/ 13 ****************************************************************************/
13 14
14#include <string.h> 15#include <string.h>
15 16
16/** 17/**
17 * Locate substring. 18 * strstr - Find the first substring in a %NUL terminated string
18 * @param search c string to be scanned. 19 * @s1: The string to be searched
19 * @param find c string containing the sequence of characters to match. 20 * @s2: The string to search for
20 * @return a pointer to the first occurrence in search of any of the
21 * entire sequence of characters specified in find, or a
22 * null pointer if the sequence is not present in search.
23 */ 21 */
24char *strstr(const char *search, const char *find) 22char *strstr(const char *s1, const char *s2)
25{ 23{
26 char *hend; 24 int l1, l2;
27 char *a, *b;
28 25
29 if (*find == 0) return (char*)search; 26 l2 = strlen(s2);
30 hend = (char *)search + strlen(search) - strlen(find) + 1; 27 if (!l2)
31 while (search < hend) { 28 return (char *)s1;
32 if (*search == *find) { 29 l1 = strlen(s1);
33 a = (char *)search; 30 while (l1 >= l2) {
34 b = (char *)find; 31 l1--;
35 for (;;) { 32 if (!memcmp(s1, s2, l2))
36 if (*b == 0) return (char*)search; 33 return (char *)s1;
37 if (*a++ != *b++) { 34 s1++;
38 break;
39 }
40 }
41 }
42 search++;
43 } 35 }
44 return 0; 36 return NULL;
45} 37}
38