ef34af24dc
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>
24 lines
438 B
C
24 lines
438 B
C
#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;
|
|
}
|