blob: d600bbeb64380cfb2175e9d3e775800f91ac3ea7 [file] [log] [blame]
Christian Gmeiner2077ceb2007-09-17 23:06:23 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Christian Gmeiner2077ceb2007-09-17 23:06:23 +00008 *
Rafaël Carré6aff55b2010-07-11 19:55:18 +00009 * 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 Gmeiner2077ceb2007-09-17 23:06:23 +000013 *
14 ****************************************************************************/
Christian Gmeiner2077ceb2007-09-17 23:06:23 +000015#include <string.h>
16
Rafaël Carré6aff55b2010-07-11 19:55:18 +000017/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
18
Daniel Stenberga20f32d2007-09-18 07:04:05 +000019char *strstr(const char *s1, const char *s2)
Christian Gmeiner2077ceb2007-09-17 23:06:23 +000020{
Rafaël Carréc9f997c2010-07-11 22:37:31 +000021 register const char *s = s1;
22 register const char *p = s2;
Christian Gmeiner2077ceb2007-09-17 23:06:23 +000023
Rafaël Carréc9f997c2010-07-11 22:37:31 +000024 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 Gmeiner2077ceb2007-09-17 23:06:23 +000039}