wcsstr.c revision 86170
138494Sobrien/*-
2174294Sobrien * Copyright (c)1999 Citrus Project,
338494Sobrien * All rights reserved.
438494Sobrien *
538494Sobrien * Redistribution and use in source and binary forms, with or without
638494Sobrien * modification, are permitted provided that the following conditions
738494Sobrien * are met:
838494Sobrien * 1. Redistributions of source code must retain the above copyright
938494Sobrien *    notice, this list of conditions and the following disclaimer.
1038494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1138494Sobrien *    notice, this list of conditions and the following disclaimer in the
1238494Sobrien *    documentation and/or other materials provided with the distribution.
1338494Sobrien *
1438494Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1538494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1638494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1738494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1838494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1938494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2042629Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2138494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2238494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2338494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2438494Sobrien * SUCH DAMAGE.
2538494Sobrien *
2638494Sobrien *	citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
2738494Sobrien */
2838494Sobrien
2938494Sobrien#include <sys/cdefs.h>
3038494Sobrien#if defined(LIBC_SCCS) && !defined(lint)
3138494Sobrien__RCSID("$NetBSD: wcsstr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
3238494Sobrien#endif /* LIBC_SCCS and not lint */
3338494Sobrien__FBSDID("$FreeBSD: head/lib/libc/string/wcsstr.c 86170 2001-11-07 19:55:16Z obrien $");
3438494Sobrien
3538494Sobrien#include <assert.h>
3638494Sobrien#include <wchar.h>
3738494Sobrien
3838494Sobrienwchar_t *
3938494Sobrienwcsstr(big, little)
40174294Sobrien	const wchar_t *big;
4138494Sobrien	const wchar_t *little;
4238494Sobrien{
4338494Sobrien	const wchar_t *p;
4438494Sobrien	const wchar_t *q;
4538494Sobrien	const wchar_t *r;
4638494Sobrien
4738494Sobrien	if (!*little) {
4838494Sobrien		/* LINTED interface specification */
4938494Sobrien		return (wchar_t *)big;
5038494Sobrien	}
5138494Sobrien	if (wcslen(big) < wcslen(little))
5238494Sobrien		return NULL;
5338494Sobrien
5438494Sobrien	p = big;
5538494Sobrien	q = little;
5638494Sobrien	while (*p) {
57174294Sobrien		q = little;
5838494Sobrien		r = p;
59174294Sobrien		while (*q) {
60174294Sobrien			if (*r != *q)
61174294Sobrien				break;
62174294Sobrien			q++;
63174294Sobrien			r++;
64174294Sobrien		}
6538494Sobrien		if (!*q) {
6638494Sobrien			/* LINTED interface specification */
67174294Sobrien			return (wchar_t *)p;
68174294Sobrien		}
69174294Sobrien		p++;
70174294Sobrien	}
71174294Sobrien	return NULL;
72174294Sobrien}
73174294Sobrien