1*9d9553bdSguenther /* $OpenBSD: wcsstr.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */
2b689ee27Sespie /* $NetBSD: wcsstr.c,v 1.3 2003/03/05 20:18:17 tshiozak Exp $ */
3b689ee27Sespie
4b689ee27Sespie /*-
5b689ee27Sespie * Copyright (c)1999 Citrus Project,
6b689ee27Sespie * All rights reserved.
7b689ee27Sespie *
8b689ee27Sespie * Redistribution and use in source and binary forms, with or without
9b689ee27Sespie * modification, are permitted provided that the following conditions
10b689ee27Sespie * are met:
11b689ee27Sespie * 1. Redistributions of source code must retain the above copyright
12b689ee27Sespie * notice, this list of conditions and the following disclaimer.
13b689ee27Sespie * 2. Redistributions in binary form must reproduce the above copyright
14b689ee27Sespie * notice, this list of conditions and the following disclaimer in the
15b689ee27Sespie * documentation and/or other materials provided with the distribution.
16b689ee27Sespie *
17b689ee27Sespie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18b689ee27Sespie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19b689ee27Sespie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20b689ee27Sespie * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21b689ee27Sespie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22b689ee27Sespie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23b689ee27Sespie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24b689ee27Sespie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25b689ee27Sespie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26b689ee27Sespie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27b689ee27Sespie * SUCH DAMAGE.
28b689ee27Sespie *
29b689ee27Sespie * citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
30b689ee27Sespie */
31b689ee27Sespie
32b689ee27Sespie #include <wchar.h>
33b689ee27Sespie
34b689ee27Sespie wchar_t *
35b689ee27Sespie #ifdef WCSWCS
wcswcs(const wchar_t * big,const wchar_t * little)361c031cf6Sespie wcswcs(const wchar_t *big, const wchar_t *little)
37b689ee27Sespie #else
381c031cf6Sespie wcsstr(const wchar_t *big, const wchar_t *little)
39b689ee27Sespie #endif
40b689ee27Sespie {
41b689ee27Sespie const wchar_t *p;
42b689ee27Sespie const wchar_t *q;
43b689ee27Sespie const wchar_t *r;
44b689ee27Sespie
45b689ee27Sespie if (!*little) {
46b689ee27Sespie return (wchar_t *)big;
47b689ee27Sespie }
48b689ee27Sespie if (wcslen(big) < wcslen(little))
49b689ee27Sespie return NULL;
50b689ee27Sespie
51b689ee27Sespie p = big;
52b689ee27Sespie q = little;
53b689ee27Sespie while (*p) {
54b689ee27Sespie q = little;
55b689ee27Sespie r = p;
56b689ee27Sespie while (*q) {
57b689ee27Sespie if (*r != *q)
58b689ee27Sespie break;
59b689ee27Sespie q++;
60b689ee27Sespie r++;
61b689ee27Sespie }
62b689ee27Sespie if (!*q) {
63b689ee27Sespie return (wchar_t *)p;
64b689ee27Sespie }
65b689ee27Sespie p++;
66b689ee27Sespie }
67b689ee27Sespie return NULL;
68b689ee27Sespie }
6938a75b98Sguenther #ifndef WCSWCS
7038a75b98Sguenther DEF_STRONG(wcsstr);
7138a75b98Sguenther #endif
72