1*9e66e6d7Sabs /* $NetBSD: wcsstr.c,v 1.5 2012/06/25 22:32:46 abs Exp $ */
2383f218aSitojun
3383f218aSitojun /*-
4383f218aSitojun * Copyright (c)1999 Citrus Project,
5383f218aSitojun * All rights reserved.
6383f218aSitojun *
7383f218aSitojun * Redistribution and use in source and binary forms, with or without
8383f218aSitojun * modification, are permitted provided that the following conditions
9383f218aSitojun * are met:
10383f218aSitojun * 1. Redistributions of source code must retain the above copyright
11383f218aSitojun * notice, this list of conditions and the following disclaimer.
12383f218aSitojun * 2. Redistributions in binary form must reproduce the above copyright
13383f218aSitojun * notice, this list of conditions and the following disclaimer in the
14383f218aSitojun * documentation and/or other materials provided with the distribution.
15383f218aSitojun *
16383f218aSitojun * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17383f218aSitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18383f218aSitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19383f218aSitojun * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20383f218aSitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21383f218aSitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22383f218aSitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23383f218aSitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24383f218aSitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25383f218aSitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26383f218aSitojun * SUCH DAMAGE.
27383f218aSitojun *
28383f218aSitojun * citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
29383f218aSitojun */
30383f218aSitojun
31383f218aSitojun #include <sys/cdefs.h>
32383f218aSitojun #if defined(LIBC_SCCS) && !defined(lint)
33*9e66e6d7Sabs __RCSID("$NetBSD: wcsstr.c,v 1.5 2012/06/25 22:32:46 abs Exp $");
34383f218aSitojun #endif /* LIBC_SCCS and not lint */
35383f218aSitojun
365ba790cbSlukem #include <assert.h>
37383f218aSitojun #include <wchar.h>
38383f218aSitojun
39383f218aSitojun wchar_t *
40326ed368Stshiozak #ifdef WCSWCS
wcswcs(const wchar_t * big,const wchar_t * little)41*9e66e6d7Sabs wcswcs(const wchar_t *big, const wchar_t *little)
42326ed368Stshiozak #else
43*9e66e6d7Sabs wcsstr(const wchar_t *big, const wchar_t *little)
44326ed368Stshiozak #endif
45383f218aSitojun {
46383f218aSitojun const wchar_t *p;
47383f218aSitojun const wchar_t *q;
48383f218aSitojun const wchar_t *r;
49383f218aSitojun
505ba790cbSlukem _DIAGASSERT(big != NULL);
515ba790cbSlukem _DIAGASSERT(little != NULL);
525ba790cbSlukem
5303256c6eSchristos if (!*little)
5403256c6eSchristos return __UNCONST(big);
55383f218aSitojun if (wcslen(big) < wcslen(little))
56383f218aSitojun return NULL;
57383f218aSitojun
58383f218aSitojun p = big;
59383f218aSitojun q = little;
60383f218aSitojun while (*p) {
61383f218aSitojun q = little;
62383f218aSitojun r = p;
63383f218aSitojun while (*q) {
64383f218aSitojun if (*r != *q)
65383f218aSitojun break;
66383f218aSitojun q++;
67383f218aSitojun r++;
68383f218aSitojun }
6903256c6eSchristos if (!*q)
7003256c6eSchristos return __UNCONST(p);
71383f218aSitojun p++;
72383f218aSitojun }
73383f218aSitojun return NULL;
74383f218aSitojun }
75