mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 08:05:56 -05:00
23 lines
573 B
C
23 lines
573 B
C
#include <string.h>
|
|
|
|
/* 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;
|
|
}
|
|
|