From: Linus Torvalds Date: Mon, 19 Sep 2005 01:30:50 GMT Subject: Re: What to expect after GIT 0.99.7 Message-ID: In-Reply-To: <7vpsr6ymg3.fsf_-_@assigned-by-dhcp.cox.net> On Sun, 18 Sep 2005, Junio C Hamano wrote: > > * Accept patches for more portability. > > * strcasestr() in mailinfo. We may need compat/strcasestr.c; > this is bugging OpenBSD folks. Maybe something stupid like this? Totally untested, of course. Linus --- diff-tree 9b2d397a5d03514bdf3f545e459817c48579830f (from 727132834e6be48a93c1bd6458a29d474ce7d5d5) Author: Linus Torvalds Date: Sun Sep 18 18:29:07 2005 -0700 Add stupid 'strcasestr()' compat routine Signed-off-by: Linus Torvalds --- diff --git a/Makefile b/Makefile --- 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 --- /dev/null +++ b/compat/strcasestr.c @@ -0,0 +1,22 @@ +#include + +char *gitstrcasestr(const char *haystack, const char *needle) +{ + int nlen = strlen(needle); + int hlen = strlen(haystack) - nlen; + 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; +}