4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
33 #include <sys/types.h>
36 #include "localeimpl.h"
39 * strcasestr() locates the first occurrence in the string s1 of the
40 * sequence of characters (excluding the terminating null character)
41 * in the string s2, ignoring case. strcasestr() returns a pointer
42 * to the located string, or a null pointer if the string is not found.
43 * If s2 is empty, the function returns s1.
47 strcasestr_l(const char *s1
, const char *s2
, locale_t loc
)
49 const int *cm
= loc
->ctype
->lc_trans_lower
;
50 const uchar_t
*us1
= (const uchar_t
*)s1
;
51 const uchar_t
*us2
= (const uchar_t
*)s2
;
55 if (us2
== NULL
|| *us2
== '\0')
59 while (*us1
!= '\0') {
60 if (c
== cm
[*us1
++]) {
62 while (cm
[c
= *++us2
] == cm
[*us1
++] && c
!= '\0')
65 return ((char *)tptr
- 1);
67 us2
= (const uchar_t
*)s2
;
76 strcasestr(const char *s1
, const char *s2
)
78 return (strcasestr_l(s1
, s2
, uselocale(NULL
)));