29 lines
674 B
C
Raw Normal View History

2004-03-16 05:24:54 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
2004-01-13 04:29:30 +00:00
#include <string.h>
2004-03-16 05:24:54 +00:00
#if !HAVE_STRCASESTR
2004-01-13 04:29:30 +00:00
/* case-independent string matching, similar to strstr but
* matching */
char * strcasestr(char* haystack, char* needle) {
int i;
int nlength = strlen (needle);
int hlength = strlen (haystack);
if (nlength > hlength) return NULL;
if (hlength <= 0) return NULL;
if (nlength <= 0) return haystack;
/* hlength and nlength > 0, nlength <= hlength */
for (i = 0; i <= (hlength - nlength); i++) {
if (strncasecmp (haystack + i, needle, nlength) == 0) {
return haystack + i;
}
}
/* substring not found */
return NULL;
}
2004-03-16 05:24:54 +00:00
#endif /* !HAVE_STRCASESTR */