mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
strstr: replace GPLv2-only implementation from Linux by LGPLv2.1 from uclibc
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27393 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
145a89fc0b
commit
6aff55b202
1 changed files with 23 additions and 22 deletions
|
@ -5,34 +5,35 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
* $Id: $
|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
* Copyright (C) 2002 Manuel Novoa III
|
||||||
* (from linux/lib/string.c)
|
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
|
||||||
|
*
|
||||||
|
* Licensed under the LGPL v2.1, code originally in uclibc
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
|
||||||
* 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 *s1, const char *s2)
|
char *strstr(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
int l1, l2;
|
register const char *s = s1;
|
||||||
|
register const char *p = s2;
|
||||||
|
|
||||||
l2 = strlen(s2);
|
do {
|
||||||
if (!l2)
|
if (!*p) {
|
||||||
return (char *)s1;
|
return (char *) s1;;
|
||||||
l1 = strlen(s1);
|
}
|
||||||
while (l1 >= l2) {
|
if (*p == *s) {
|
||||||
l1--;
|
++p;
|
||||||
if (!memcmp(s1, s2, l2))
|
++s;
|
||||||
return (char *)s1;
|
} else {
|
||||||
s1++;
|
p = s2;
|
||||||
}
|
if (!*s) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
s = ++s1;
|
||||||
|
}
|
||||||
|
} while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue