[PATCH] strcasestr compatibility replacement
[git.git] / compat / strcasestr.c
diff --git a/compat/strcasestr.c b/compat/strcasestr.c
new file mode 100644 (file)
index 0000000..b96414d
--- /dev/null
@@ -0,0 +1,23 @@
+#include <string.h>
+#include <ctype.h>
+
+char *gitstrcasestr(const char *haystack, const char *needle)
+{
+       int nlen = strlen(needle);
+       int hlen = strlen(haystack) - nlen + 1;
+       int i;
+
+       for (i = 0; i < hlen; i++) {
+               int j;
+               for (j = 0; j < nlen; 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;
+}