source: vendor/bash/3.1-p17/lib/sh/strindex.c

Last change on this file was 3231, checked in by bird, 18 years ago

eol style.

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1/* strindex.c - Find if one string appears as a substring of another string,
2 without regard to case. */
3
4/* Copyright (C) 2000
5 Free Software Foundation, Inc.
6
7 This file is part of GNU Bash, the Bourne Again SHell.
8
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
12 version.
13
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
17 for more details.
18
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. */
22
23#include <config.h>
24
25#include <bashansi.h>
26#include <chartypes.h>
27
28#include <stdc.h>
29
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). */
33char *
34strindex (s1, s2)
35 const char *s1;
36 const char *s2;
37{
38 register int i, l, len, c;
39
40 c = TOLOWER ((unsigned char)s2[0]);
41 len = strlen (s1);
42 l = strlen (s2);
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);
46 return ((char *)0);
47}
Note: See TracBrowser for help on using the repository browser.