wcsstr.c revision 77117
11541Srgrimes/*-
21541Srgrimes * Copyright (c)1999 Citrus Project,
31541Srgrimes * All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes *
141541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241541Srgrimes * SUCH DAMAGE.
251541Srgrimes *
261541Srgrimes *	citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
271541Srgrimes */
281541Srgrimes
291541Srgrimes#include <sys/cdefs.h>
301541Srgrimes#if defined(LIBC_SCCS) && !defined(lint)
311541Srgrimes__RCSID("$NetBSD: wcsstr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
321541Srgrimes#endif /* LIBC_SCCS and not lint */
331541Srgrimes#ifndef lint
3450477Speterstatic const char rcsid[] =
351541Srgrimes  "$FreeBSD: head/lib/libc/string/wcsstr.c 77117 2001-05-24 08:47:42Z obrien $";
361541Srgrimes#endif
3713203Swollman
381541Srgrimes#include <assert.h>
391541Srgrimes#include <wchar.h>
402112Swollman
4112221Sbdewchar_t *
4241059Speterwcsstr(big, little)
431541Srgrimes	const wchar_t *big;
4424131Sbde	const wchar_t *little;
4531561Sbde{
461541Srgrimes	const wchar_t *p;
471541Srgrimes	const wchar_t *q;
481541Srgrimes	const wchar_t *r;
491541Srgrimes
501541Srgrimes	if (!*little) {
511541Srgrimes		/* LINTED interface specification */
5254655Seivind		return (wchar_t *)big;
5347955Sdt	}
5447955Sdt	if (wcslen(big) < wcslen(little))
5530354Sphk		return NULL;
5630309Sphk
5713203Swollman	p = big;
5812819Sphk	q = little;
5962378Sgreen	while (*p) {
6012819Sphk		q = little;
6112819Sphk		r = p;
6212819Sphk		while (*q) {
6312577Sbde			if (*r != *q)
6412819Sphk				break;
6512819Sphk			q++;
661541Srgrimes			r++;
671541Srgrimes		}
681541Srgrimes		if (!*q) {
691541Srgrimes			/* LINTED interface specification */
701541Srgrimes			return (wchar_t *)p;
711541Srgrimes		}
728876Srgrimes		p++;
7317429Sphk	}
741541Srgrimes	return NULL;
751541Srgrimes}
761541Srgrimes