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 diff --git a/Makefile b/Makefile index 877e0b8..957fadc 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ # Define NO_CURL if you do not have curl installed. git-http-pull is not # built, and you cannot use http:// and https:// transports. # +# Define NO_STRCASESTR if you don't have strcasestr. +# # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. # @@ -203,6 +205,10 @@ ifdef NEEDS_NSL LIBS += -lnsl SIMPLE_LIB += -lnsl endif +ifdef NO_STRCASESTR + DEFINES += -Dstrcasestr=gitstrcasestr + LIB_OBJS += compat/strcasestr.o +endif DEFINES += '-DSHA1_HEADER=$(SHA1_HEADER)' diff --git a/compat/strcasestr.c b/compat/strcasestr.c new file mode 100644 index 0000000..b96414d --- /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 v0.10.2-6-g49f6