+#ifndef HAVE_STRCASECMP
+/* Fallback taken from FreeBSD. --Elizafox */
+int
+rb_strcasecmp(const char *s1, const char *s2)
+{
+ const unsigned char *us1 = (const unsigned char *)s1;
+ const unsigned char *us2 = (const unsigned char *)s2;
+
+ while (tolower(*us1) == tolower(*us2++))
+ {
+ if (*us1++ == '\0')
+ return 0;
+ }
+
+ return (tolower(*us1) - tolower(*--us2));
+}
+#else
+int
+rb_strcasecmp(const char *s1, const char *s2)
+{
+ return strcasecmp(s1, s2);
+}
+#endif
+
+#ifndef HAVE_STRNCASECMP
+/* Fallback taken from FreeBSD. --Elizafox */
+int
+rb_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ if (n != 0)
+ {
+ const unsigned char *us1 = (const unsigned char *)s1;
+ const unsigned char *us2 = (const unsigned char *)s2;
+
+ do
+ {
+ if (tolower(*us1) != tolower(*us2++))
+ return (tolower(*us1) - tolower(*--us2));
+ if (*us1++ == '\0')
+ break;
+ } while (--n != 0);
+ }
+ return 0;
+}
+#else
+int
+rb_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ return strncasecmp(s1, s2, n);
+}
+#endif
+
+#ifndef HAVE_STRCASESTR
+/* Fallback taken from FreeBSD. --Elizafox */
+char *
+rb_strcasestr(const char *s, const char *find)
+{
+ char c, sc;
+ size_t len;
+
+ if ((c = *find++) != 0) {
+ c = tolower((unsigned char)c);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+ } while ((char)tolower((unsigned char)sc) != c);
+ } while (rb_strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return ((char *)s);
+}
+#else
+char *
+rb_strcasestr(const char *s, const char *find)
+{
+ return strcasestr(s, find);
+}
+#endif
+