strcasestr.c (633B)
1 /* ISC license. */ 2 3 #include <skalibs/sysdeps.h> 4 5 #ifndef SKALIBS_HASSTRCASESTR 6 7 #include <string.h> 8 9 #include <skalibs/bytestr.h> 10 11 /* XXX: copies strings on the stack, careful with long strings */ 12 13 char *strcasestr (char const *haystack, char const *needle) 14 { 15 size_t nlen = strlen(needle) ; 16 size_t hlen = strlen(haystack) ; 17 char *p ; 18 char lneedle[nlen + 1] ; 19 char lhaystack[hlen + 1] ; 20 memcpy(lneedle, needle, nlen + 1) ; 21 memcpy(lhaystack, haystack, hlen + 1) ; 22 case_lowerb(lneedle, nlen) ; 23 case_lowerb(lhaystack, hlen) ; 24 p = strstr(lhaystack, lneedle) ; 25 return p ? haystack + (p - lhaystack) : 0 ; 26 } 27 28 #endif