fix windowisms: BOOL
[rofl0r-openbor.git] / source / stristr.c
blob8fafcbccbe9ca674a114d9eba2b6ca41559e7223
1 /*
2 * OpenBOR - http://www.LavaLit.com
3 * -----------------------------------------------------------------------
4 * Licensed under the BSD license, see LICENSE in OpenBOR root for details.
6 * Copyright (c) 2004 - 2011 OpenBOR Team
7 */
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
13 char *stristr(const char *String, const char *Pattern) {
14 char *pptr, *sptr, *start;
15 unsigned int slen, plen;
16 for(start = (char *) String, pptr = (char *) Pattern, slen = strlen(String), plen = strlen(Pattern);
17 slen >= plen; start++, slen--) {
18 /* find start of pattern in string */
19 while(toupper((int) *start) != toupper((int) *Pattern)) {
20 start++;
21 slen--;
22 /* if pattern longer than string */
23 if(slen < plen)
24 return (NULL);
26 sptr = start;
27 pptr = (char *) Pattern;
28 while(toupper((int) *sptr) == toupper((int) *pptr)) {
29 sptr++;
30 pptr++;
31 /* if end of pattern then pattern was found */
32 if('\0' == *pptr)
33 return (start);
36 return (NULL);