1 /* strindex.c - Find if one string appears as a substring of another string,
2 without regard to case. */
5 Free Software Foundation, Inc.
7 This file is part of GNU Bash, the Bourne Again SHell.
9 Bash is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with Bash; see the file COPYING. If not, write to the Free Software
21 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
31 # define to_upper(c) (islower(c) ? toupper(c) : (c))
32 # define to_lower(c) (isupper(c) ? tolower(c) : (c))
35 /* Determine if s2 occurs in s1. If so, return a pointer to the
36 match in s1. The compare is case insensitive. This is a
37 case-insensitive strstr(3). */
43 register int i, l, len, c;
48 for (i = 0; (len - i) >= l; i++)
49 if ((to_upper (s1[i]) == c) && (strncasecmp (s1 + i, s2, l) == 0))
50 return ((char *)s1 + i);