wcsstr.c revision 105844
176612Stshiozak/*- 2105844Stjr * Copyright (c) 1990, 1993 3105844Stjr * The Regents of the University of California. All rights reserved. 476612Stshiozak * 5105844Stjr * This code is derived from software contributed to Berkeley by 6105844Stjr * Chris Torek. 7105844Stjr * 876612Stshiozak * Redistribution and use in source and binary forms, with or without 976612Stshiozak * modification, are permitted provided that the following conditions 1076612Stshiozak * are met: 1176612Stshiozak * 1. Redistributions of source code must retain the above copyright 1276612Stshiozak * notice, this list of conditions and the following disclaimer. 1376612Stshiozak * 2. Redistributions in binary form must reproduce the above copyright 1476612Stshiozak * notice, this list of conditions and the following disclaimer in the 1576612Stshiozak * documentation and/or other materials provided with the distribution. 16105844Stjr * 3. All advertising materials mentioning features or use of this software 17105844Stjr * must display the following acknowledgement: 18105844Stjr * This product includes software developed by the University of 19105844Stjr * California, Berkeley and its contributors. 20105844Stjr * 4. Neither the name of the University nor the names of its contributors 21105844Stjr * may be used to endorse or promote products derived from this software 22105844Stjr * without specific prior written permission. 2376612Stshiozak * 24105844Stjr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2576612Stshiozak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2676612Stshiozak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27105844Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2876612Stshiozak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2976612Stshiozak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3076612Stshiozak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3176612Stshiozak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3276612Stshiozak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3376612Stshiozak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3476612Stshiozak * SUCH DAMAGE. 3576612Stshiozak */ 3676612Stshiozak 3792986Sobrien#if 0 3876612Stshiozak#if defined(LIBC_SCCS) && !defined(lint) 39105844Stjrstatic char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; 4076612Stshiozak#endif /* LIBC_SCCS and not lint */ 4192986Sobrien#endif 42105844Stjr#include <sys/cdefs.h> 4386170Sobrien__FBSDID("$FreeBSD: head/lib/libc/string/wcsstr.c 105844 2002-10-24 02:53:45Z tjr $"); 4476612Stshiozak 4576612Stshiozak#include <wchar.h> 4676612Stshiozak 47105844Stjr/* 48105844Stjr * Find the first occurrence of find in s. 49105844Stjr */ 5076612Stshiozakwchar_t * 51105844Stjrwcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find) 5276612Stshiozak{ 53105844Stjr wchar_t c, sc; 54105844Stjr size_t len; 5576612Stshiozak 56105844Stjr if ((c = *find++) != 0) { 57105844Stjr len = wcslen(find); 58105844Stjr do { 59105844Stjr do { 60105844Stjr if ((sc = *s++) == L'\0') 61105844Stjr return (NULL); 62105844Stjr } while (sc != c); 63105844Stjr } while (wcsncmp(s, find, len) != 0); 64105844Stjr s--; 6576612Stshiozak } 66105844Stjr return ((wchar_t *)s); 6776612Stshiozak} 68