Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 8 | * |
Rafaël Carré | 6aff55b | 2010-07-11 19:55:18 +0000 | [diff] [blame] | 9 | * Copyright (C) 2002 Manuel Novoa III |
| 10 | * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org> |
| 11 | * |
| 12 | * Licensed under the LGPL v2.1, code originally in uclibc |
Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 13 | * |
| 14 | ****************************************************************************/ |
Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 15 | #include <string.h> |
| 16 | |
Rafaël Carré | 6aff55b | 2010-07-11 19:55:18 +0000 | [diff] [blame] | 17 | /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */ |
| 18 | |
Daniel Stenberg | a20f32d | 2007-09-18 07:04:05 +0000 | [diff] [blame] | 19 | char *strstr(const char *s1, const char *s2) |
Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 20 | { |
Rafaël Carré | c9f997c | 2010-07-11 22:37:31 +0000 | [diff] [blame] | 21 | register const char *s = s1; |
| 22 | register const char *p = s2; |
Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 23 | |
Rafaël Carré | c9f997c | 2010-07-11 22:37:31 +0000 | [diff] [blame] | 24 | do { |
| 25 | if (!*p) { |
| 26 | return (char *) s1; |
| 27 | } |
| 28 | if (*p == *s) { |
| 29 | ++p; |
| 30 | ++s; |
| 31 | } else { |
| 32 | p = s2; |
| 33 | if (!*s) { |
| 34 | return NULL; |
| 35 | } |
| 36 | s = ++s1; |
| 37 | } |
| 38 | } while (1); |
Christian Gmeiner | 2077ceb | 2007-09-17 23:06:23 +0000 | [diff] [blame] | 39 | } |