diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/strstr.c | 43 |
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 | */ |
24 | char *strstr(const char *search, const char *find) | 22 | char *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 | |||