1 /* ISC license. */ 2 3 #include <skalibs/sysdeps.h> 4 5 #ifdef SKALIBS_HASSTRCASESTR 6 7 #include <skalibs/nonposix.h> 8 #include <string.h> 9 #include <skalibs/bytestr.h> 10 case_str(char const * haystack,char const * needle)11size_t case_str (char const *haystack, char const *needle) 12 { 13 char *p = strcasestr(haystack, needle) ; 14 return p ? p - haystack : strlen(haystack) ; 15 } 16 17 #else 18 19 #include <string.h> 20 #include <strings.h> 21 #include <skalibs/bytestr.h> 22 case_str(char const * haystack,char const * needle)23size_t case_str (char const *haystack, char const *needle) 24 { 25 size_t nlen = strlen(needle) ; 26 char const *p = haystack ; 27 if (!nlen) return 0 ; 28 for (; *p ; p++) 29 if (!strncasecmp(p, needle, nlen)) return p - haystack ; 30 return strlen(haystack) ; 31 } 32 33 #endif 34