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. */
26 #include <chartypes.h>
30 /* Determine if s2 occurs in s1. If so, return a pointer to the
31 match in s1. The compare is case insensitive. This is a
32 case-insensitive strstr(3). */
38 register int i, l, len, c;
40 c = TOLOWER ((unsigned char)s2[0]);
43 for (i = 0; (len - i) >= l; i++)
44 if ((TOLOWER ((unsigned char)s1[i]) == c) && (strncasecmp (s1 + i, s2, l) == 0))
45 return ((char *)s1 + i);