]> granicus.if.org Git - imagemagick/commitdiff
Define strcasestr for Windows
authorCristy <urban-warrior@imagemagick.org>
Wed, 16 Oct 2019 11:40:13 +0000 (07:40 -0400)
committerCristy <urban-warrior@imagemagick.org>
Wed, 16 Oct 2019 11:40:13 +0000 (07:40 -0400)
MagickCore/nt-base.h

index 139ccdfaeac600da4818656bdbf86424af24f52f..0c4035916265dfd0b3c73d5efe6629938ed3e146 100644 (file)
@@ -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)