From 152ba685f2cf6b9abb576051dccf2ce3199302df Mon Sep 17 00:00:00 2001 From: Cristy Date: Wed, 16 Oct 2019 07:40:13 -0400 Subject: [PATCH] Define strcasestr for Windows --- MagickCore/nt-base.h | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/MagickCore/nt-base.h b/MagickCore/nt-base.h index 139ccdfae..0c4035916 100644 --- a/MagickCore/nt-base.h +++ b/MagickCore/nt-base.h @@ -244,9 +244,6 @@ extern "C" { #if !defined(strcasecmp) # define strcasecmp _stricmp #endif -#if !defined(strcasestr) -# define strcasestr StrStrIA -#endif #if !defined(strncasecmp) # define strncasecmp _strnicmp #endif @@ -331,6 +328,41 @@ extern MagickExport void NTErrorHandler(const ExceptionType,const char *,const char *), NTGhostscriptUnLoadDLL(void), NTWarningHandler(const ExceptionType,const char *,const char *); + +#if !defined(strcasestr) +static inline char *strcasestr(const char *haystack,const char *needle) +{ + size_t + length_needle, + length_haystack; + + register ssize_t + i; + + if (!haystack || !needle) + return(NULL); + length_needle=strlen(needle); + length_haystack=strlen(haystack)-length_needle+1; + for (i=0; i < length_haystack; i++) + { + register size_t + j; + + for (j=0; j < length_needle; j++) + { + unsigned char c1 = haystack[i+j]; + unsigned char c2 = needle[j]; + if (toupper(c1) != toupper(c2)) + goto next; + } + return((char *) haystack+i); + next: + ; + } + return(NULL); +} +#endif + #endif #if defined(__cplusplus) || defined(c_plusplus) -- 2.40.0