wcsstr.c revision 92986
176612Stshiozak/*-
276612Stshiozak * Copyright (c)1999 Citrus Project,
376612Stshiozak * All rights reserved.
476612Stshiozak *
576612Stshiozak * Redistribution and use in source and binary forms, with or without
676612Stshiozak * modification, are permitted provided that the following conditions
776612Stshiozak * are met:
876612Stshiozak * 1. Redistributions of source code must retain the above copyright
976612Stshiozak *    notice, this list of conditions and the following disclaimer.
1076612Stshiozak * 2. Redistributions in binary form must reproduce the above copyright
1176612Stshiozak *    notice, this list of conditions and the following disclaimer in the
1276612Stshiozak *    documentation and/or other materials provided with the distribution.
1376612Stshiozak *
1476612Stshiozak * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1576612Stshiozak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1676612Stshiozak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1776612Stshiozak * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1876612Stshiozak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1976612Stshiozak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2076612Stshiozak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2176612Stshiozak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2276612Stshiozak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2376612Stshiozak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2476612Stshiozak * SUCH DAMAGE.
2576612Stshiozak *
2676612Stshiozak *	citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
2776612Stshiozak */
2876612Stshiozak
2976612Stshiozak#include <sys/cdefs.h>
3092986Sobrien#if 0
3176612Stshiozak#if defined(LIBC_SCCS) && !defined(lint)
3276612Stshiozak__RCSID("$NetBSD: wcsstr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
3376612Stshiozak#endif /* LIBC_SCCS and not lint */
3492986Sobrien#endif
3586170Sobrien__FBSDID("$FreeBSD: head/lib/libc/string/wcsstr.c 92986 2002-03-22 21:53:29Z obrien $");
3676612Stshiozak
3776612Stshiozak#include <assert.h>
3876612Stshiozak#include <wchar.h>
3976612Stshiozak
4076612Stshiozakwchar_t *
4176612Stshiozakwcsstr(big, little)
4276612Stshiozak	const wchar_t *big;
4376612Stshiozak	const wchar_t *little;
4476612Stshiozak{
4576612Stshiozak	const wchar_t *p;
4676612Stshiozak	const wchar_t *q;
4776612Stshiozak	const wchar_t *r;
4876612Stshiozak
4976612Stshiozak	if (!*little) {
5076612Stshiozak		/* LINTED interface specification */
5176612Stshiozak		return (wchar_t *)big;
5276612Stshiozak	}
5376612Stshiozak	if (wcslen(big) < wcslen(little))
5476612Stshiozak		return NULL;
5576612Stshiozak
5676612Stshiozak	p = big;
5776612Stshiozak	q = little;
5876612Stshiozak	while (*p) {
5976612Stshiozak		q = little;
6076612Stshiozak		r = p;
6176612Stshiozak		while (*q) {
6276612Stshiozak			if (*r != *q)
6376612Stshiozak				break;
6476612Stshiozak			q++;
6576612Stshiozak			r++;
6676612Stshiozak		}
6776612Stshiozak		if (!*q) {
6876612Stshiozak			/* LINTED interface specification */
6976612Stshiozak			return (wchar_t *)p;
7076612Stshiozak		}
7176612Stshiozak		p++;
7276612Stshiozak	}
7376612Stshiozak	return NULL;
7476612Stshiozak}
75