From ef34af24dc457f7a3ccfd8047e3d21e07f3f55e4 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 18 Sep 2005 18:30:50 -0700 Subject: [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 ", updated further with a fix from Joachim B Haga "] Signed-off-by: Junio C Hamano --- compat/strcasestr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 compat/strcasestr.c (limited to 'compat/strcasestr.c') diff --git a/compat/strcasestr.c b/compat/strcasestr.c new file mode 100644 index 000000000..b96414d36 --- /dev/null +++ b/compat/strcasestr.c @@ -0,0 +1,23 @@ +#include +#include + +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; +} -- cgit v1.2.1