summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/libc/strstr.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/firmware/libc/strstr.c b/firmware/libc/strstr.c
index 73fab1cc63..ea1fe9eded 100644
--- a/firmware/libc/strstr.c
+++ b/firmware/libc/strstr.c
@@ -5,34 +5,35 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id: $
9 * 8 *
10 * Copyright (C) 1991, 1992 Linus Torvalds 9 * Copyright (C) 2002 Manuel Novoa III
11 * (from linux/lib/string.c) 10 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
11 *
12 * Licensed under the LGPL v2.1, code originally in uclibc
12 * 13 *
13 ****************************************************************************/ 14 ****************************************************************************/
14
15#include <string.h> 15#include <string.h>
16 16
17/** 17/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
18 * strstr - Find the first substring in a %NUL terminated string 18
19 * @s1: The string to be searched
20 * @s2: The string to search for
21 */
22char *strstr(const char *s1, const char *s2) 19char *strstr(const char *s1, const char *s2)
23{ 20{
24 int l1, l2; 21 register const char *s = s1;
22 register const char *p = s2;
25 23
26 l2 = strlen(s2); 24 do {
27 if (!l2) 25 if (!*p) {
28 return (char *)s1; 26 return (char *) s1;;
29 l1 = strlen(s1); 27 }
30 while (l1 >= l2) { 28 if (*p == *s) {
31 l1--; 29 ++p;
32 if (!memcmp(s1, s2, l2)) 30 ++s;
33 return (char *)s1; 31 } else {
34 s1++; 32 p = s2;
35 } 33 if (!*s) {
36 return NULL; 34 return NULL;
35 }
36 s = ++s1;
37 }
38 } while (1);
37} 39}
38