summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2005-09-18 18:30:50 -0700
committerJunio C Hamano <junkio@cox.net>2005-09-19 08:49:39 -0700
commitef34af24dc457f7a3ccfd8047e3d21e07f3f55e4 (patch)
treeca37686692dbfcd93e17fa19f423ec1be8505e21 /compat
parent727132834e6be48a93c1bd6458a29d474ce7d5d5 (diff)
downloadgit-ef34af24dc457f7a3ccfd8047e3d21e07f3f55e4.tar.gz
[PATCH] strcasestr compatibility replacement
Some C libraries lack strcasestr(); add a stupid replacement to help folks with such. [jc: original Linus posting, updated with his "also need <ctype.h>", updated further with a fix from Joachim B Haga <cjhaga@fys.uio.no>"] Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'compat')
-rw-r--r--compat/strcasestr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/compat/strcasestr.c b/compat/strcasestr.c
new file mode 100644
index 0000000000..b96414d36b
--- /dev/null
+++ b/compat/strcasestr.c
@@ -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;
+}