xref: /freebsd/lib/libc/string/wcsstr.c (revision 3fb3b97c4d38990da5f45b37e48a5110b3e9bc58)
19829d36aSTakuya SHIOZAKI /*-
2fcd7f38fSTim J. Robbins  * Copyright (c) 1990, 1993
3fcd7f38fSTim J. Robbins  *	The Regents of the University of California.  All rights reserved.
4fcd7f38fSTim J. Robbins  *
5fcd7f38fSTim J. Robbins  * This code is derived from software contributed to Berkeley by
6fcd7f38fSTim J. Robbins  * Chris Torek.
79829d36aSTakuya SHIOZAKI  *
89829d36aSTakuya SHIOZAKI  * Redistribution and use in source and binary forms, with or without
99829d36aSTakuya SHIOZAKI  * modification, are permitted provided that the following conditions
109829d36aSTakuya SHIOZAKI  * are met:
119829d36aSTakuya SHIOZAKI  * 1. Redistributions of source code must retain the above copyright
129829d36aSTakuya SHIOZAKI  *    notice, this list of conditions and the following disclaimer.
139829d36aSTakuya SHIOZAKI  * 2. Redistributions in binary form must reproduce the above copyright
149829d36aSTakuya SHIOZAKI  *    notice, this list of conditions and the following disclaimer in the
159829d36aSTakuya SHIOZAKI  *    documentation and/or other materials provided with the distribution.
16*3fb3b97cSEd Maste  * 3. Neither the name of the University nor the names of its contributors
17fcd7f38fSTim J. Robbins  *    may be used to endorse or promote products derived from this software
18fcd7f38fSTim J. Robbins  *    without specific prior written permission.
199829d36aSTakuya SHIOZAKI  *
20fcd7f38fSTim J. Robbins  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
219829d36aSTakuya SHIOZAKI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
229829d36aSTakuya SHIOZAKI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23fcd7f38fSTim J. Robbins  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
249829d36aSTakuya SHIOZAKI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
259829d36aSTakuya SHIOZAKI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
269829d36aSTakuya SHIOZAKI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
279829d36aSTakuya SHIOZAKI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
289829d36aSTakuya SHIOZAKI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
299829d36aSTakuya SHIOZAKI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
309829d36aSTakuya SHIOZAKI  * SUCH DAMAGE.
319829d36aSTakuya SHIOZAKI  */
329829d36aSTakuya SHIOZAKI 
33333fc21eSDavid E. O'Brien #if 0
349829d36aSTakuya SHIOZAKI #if defined(LIBC_SCCS) && !defined(lint)
35fcd7f38fSTim J. Robbins static char sccsid[] = "@(#)strstr.c	8.1 (Berkeley) 6/4/93";
369829d36aSTakuya SHIOZAKI #endif /* LIBC_SCCS and not lint */
37333fc21eSDavid E. O'Brien #endif
38fcd7f38fSTim J. Robbins #include <sys/cdefs.h>
39de5fe5d5SDavid E. O'Brien __FBSDID("$FreeBSD$");
409829d36aSTakuya SHIOZAKI 
419829d36aSTakuya SHIOZAKI #include <wchar.h>
429829d36aSTakuya SHIOZAKI 
43fcd7f38fSTim J. Robbins /*
44fcd7f38fSTim J. Robbins  * Find the first occurrence of find in s.
45fcd7f38fSTim J. Robbins  */
469829d36aSTakuya SHIOZAKI wchar_t *
47fcd7f38fSTim J. Robbins wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find)
489829d36aSTakuya SHIOZAKI {
49fcd7f38fSTim J. Robbins 	wchar_t c, sc;
50fcd7f38fSTim J. Robbins 	size_t len;
519829d36aSTakuya SHIOZAKI 
52bd604b4bSDaniel Gerzo 	if ((c = *find++) != L'\0') {
53fcd7f38fSTim J. Robbins 		len = wcslen(find);
54fcd7f38fSTim J. Robbins 		do {
55fcd7f38fSTim J. Robbins 			do {
56fcd7f38fSTim J. Robbins 				if ((sc = *s++) == L'\0')
57fcd7f38fSTim J. Robbins 					return (NULL);
58fcd7f38fSTim J. Robbins 			} while (sc != c);
59fcd7f38fSTim J. Robbins 		} while (wcsncmp(s, find, len) != 0);
60fcd7f38fSTim J. Robbins 		s--;
619829d36aSTakuya SHIOZAKI 	}
62fcd7f38fSTim J. Robbins 	return ((wchar_t *)s);
639829d36aSTakuya SHIOZAKI }
64