From d824800f5ce9aa3db470c5e3fd5d8ac4f9f1172f Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 23 Jan 2012 00:02:34 +0100 Subject: [PATCH] strcasestr(): Custom implementation for WIN32 Pointed out by linfk. --- util.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/util.h b/util.h index b815a7d..2711c6d 100644 --- a/util.h +++ b/util.h @@ -11,6 +11,23 @@ #define sleep(seconds) Sleep((seconds) * 1000) #define __sync_fetch_and_add(ap, b) InterlockedExchangeAdd((unsigned long *) (ap), (b)); #define __sync_fetch_and_sub(ap, b) InterlockedExchangeAdd((unsigned long *) (ap), -(b)); + +#include +static inline const char * +strcasestr(const char *haystack, const char *needle) +{ + for (const char *p = haystack; *p; p++) { + for (int ni = 0; needle[ni]; ni++) { + if (!p[ni]) + return NULL; + if (toupper(p[ni]) != toupper(needle[ni])) + goto more_hay; + } + return p; +more_hay:; + } + return NULL; +} #endif /* Misc. definitions. */ -- 2.11.4.GIT