-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
Linus Torvalds
authored and
Junio C Hamano
committed
Sep 19, 2005
1 parent
7271328
commit ef34af2
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |