173c0c411SPawel Jakub Dawidek /*-
22cc7a555SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
3df57947fSPedro F. Giffuni *
459b34b34SWarner Losh * Copyright (c) 1990, 1993
559b34b34SWarner Losh * The Regents of the University of California. All rights reserved.
673c0c411SPawel Jakub Dawidek *
773c0c411SPawel Jakub Dawidek * This code is derived from software contributed to Berkeley by
859b34b34SWarner Losh * Chris Torek.
973c0c411SPawel Jakub Dawidek *
1073c0c411SPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without
1173c0c411SPawel Jakub Dawidek * modification, are permitted provided that the following conditions
1273c0c411SPawel Jakub Dawidek * are met:
1373c0c411SPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright
1473c0c411SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer.
1573c0c411SPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright
1673c0c411SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the
1773c0c411SPawel Jakub Dawidek * documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
1973c0c411SPawel Jakub Dawidek * may be used to endorse or promote products derived from this software
2073c0c411SPawel Jakub Dawidek * without specific prior written permission.
2173c0c411SPawel Jakub Dawidek *
2273c0c411SPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2373c0c411SPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2473c0c411SPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2573c0c411SPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2673c0c411SPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2773c0c411SPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2873c0c411SPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2973c0c411SPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3073c0c411SPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3173c0c411SPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3273c0c411SPawel Jakub Dawidek * SUCH DAMAGE.
3373c0c411SPawel Jakub Dawidek */
3473c0c411SPawel Jakub Dawidek
3559b34b34SWarner Losh #include <sys/param.h>
3659b34b34SWarner Losh #include <sys/libkern.h>
3773c0c411SPawel Jakub Dawidek
3873c0c411SPawel Jakub Dawidek /*
3959b34b34SWarner Losh * Find the first occurrence of find in s.
4073c0c411SPawel Jakub Dawidek */
4159b34b34SWarner Losh char *
strstr(const char * s,const char * find)4259b34b34SWarner Losh strstr(const char *s, const char *find)
4373c0c411SPawel Jakub Dawidek {
4459b34b34SWarner Losh char c, sc;
4559b34b34SWarner Losh size_t len;
4673c0c411SPawel Jakub Dawidek
4759b34b34SWarner Losh if ((c = *find++) != 0) {
4859b34b34SWarner Losh len = strlen(find);
4959b34b34SWarner Losh do {
5059b34b34SWarner Losh do {
51*85b64892SEd Maste if ((sc = *s++) == '\0')
5259b34b34SWarner Losh return (NULL);
5359b34b34SWarner Losh } while (sc != c);
5459b34b34SWarner Losh } while (strncmp(s, find, len) != 0);
5559b34b34SWarner Losh s--;
5673c0c411SPawel Jakub Dawidek }
5759b34b34SWarner Losh return (__DECONST(char *, s));
5873c0c411SPawel Jakub Dawidek }
59