diff options
| author | Rafaël Carré <rafael.carre@gmail.com> | 2010-07-11 19:55:18 +0000 |
|---|---|---|
| committer | Rafaël Carré <rafael.carre@gmail.com> | 2010-07-11 19:55:18 +0000 |
| commit | 6aff55b202c33f80b44f762442995c61b1cf0396 (patch) | |
| tree | d88d3ec421abeacef496cd5d8a27e8ed715ee887 /firmware/libc | |
| parent | 145a89fc0bd1a6046e61fd661c9cbb2fe88e0a52 (diff) | |
| download | rockbox-6aff55b202c33f80b44f762442995c61b1cf0396.zip rockbox-6aff55b202c33f80b44f762442995c61b1cf0396.tar.gz rockbox-6aff55b202c33f80b44f762442995c61b1cf0396.tar.bz2 rockbox-6aff55b202c33f80b44f762442995c61b1cf0396.tar.xz | |
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
Diffstat (limited to 'firmware/libc')
| -rw-r--r-- | firmware/libc/strstr.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/firmware/libc/strstr.c b/firmware/libc/strstr.c index 73fab1c..ea1fe9e 100644 --- a/firmware/libc/strstr.c +++ b/firmware/libc/strstr.c @@ -5,34 +5,35 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id: $ * - * Copyright (C) 1991, 1992 Linus Torvalds - * (from linux/lib/string.c) + * Copyright (C) 2002 Manuel Novoa III + * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org> + * + * Licensed under the LGPL v2.1, code originally in uclibc * ****************************************************************************/ - #include <string.h> -/** - * strstr - Find the first substring in a %NUL terminated string - * @s1: The string to be searched - * @s2: The string to search for - */ +/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */ + char *strstr(const char *s1, const char *s2) { - int l1, l2; + register const char *s = s1; + register const char *p = s2; - 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 NULL; + do { + if (!*p) { + return (char *) s1;; + } + if (*p == *s) { + ++p; + ++s; + } else { + p = s2; + if (!*s) { + return NULL; + } + s = ++s1; + } + } while (1); } - |