1#ifdef HAVE_CONFIG_H 2# include "config.h" 3#endif 4 5#include <string.h> 6 7#if !HAVE_STRCASESTR 8/* case-independent string matching, similar to strstr but 9 * matching */ 10char * strcasestr(char* haystack, char* needle) { 11 int i; 12 int nlength = strlen (needle); 13 int hlength = strlen (haystack); 14 15 if (nlength > hlength) return NULL; 16 if (hlength <= 0) return NULL; 17 if (nlength <= 0) return haystack; 18 /* hlength and nlength > 0, nlength <= hlength */ 19 for (i = 0; i <= (hlength - nlength); i++) { 20 if (strncasecmp (haystack + i, needle, nlength) == 0) { 21 return haystack + i; 22 } 23 } 24 /* substring not found */ 25 return NULL; 26} 27 28#endif /* !HAVE_STRCASESTR */ 29