[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>
Linus Torvalds committed
Sep 18, 2005 at 18:30 UTC
ef34af24dc457f7a3ccfd8047e3d21e07f3f55e4
2 files changed
+29
Makefile
+6
@@ -9,6 +9,8 @@
9
# Define NO_CURL if you do not have curl installed. git-http-pull is not
10
# built, and you cannot use http:// and https:// transports.
11
#
12
+# Define NO_STRCASESTR if you don't have strcasestr.
13
+#
14
# Define PPC_SHA1 environment variable when running make to make use of
15
# a bundled SHA1 routine optimized for PowerPC.
16
#
@@ -203,6 +205,10 @@ ifdef NEEDS_NSL
205
LIBS += -lnsl
206
SIMPLE_LIB += -lnsl
207
endif
208
+ifdef NO_STRCASESTR
209
+ DEFINES += -Dstrcasestr=gitstrcasestr
210
+ LIB_OBJS += compat/strcasestr.o
211
+endif
212
213
DEFINES += '-DSHA1_HEADER=$(SHA1_HEADER)'
214
compat/strcasestr.c
new
+23
@@ -0,0 +1,23 @@
1
+#include <string.h>
2
+#include <ctype.h>
3
+
4
+char *gitstrcasestr(const char *haystack, const char *needle)
5
+{
6
+ int nlen = strlen(needle);
7
+ int hlen = strlen(haystack) - nlen + 1;
8
+ int i;
9
+
10
+ for (i = 0; i < hlen; i++) {
11
+ int j;
12
+ for (j = 0; j < nlen; j++) {
13
+ unsigned char c1 = haystack[i+j];
14
+ unsigned char c2 = needle[j];
15
+ if (toupper(c1) != toupper(c2))
16
+ goto next;
17
+ }
18
+ return (char *) haystack + i;
19
+ next:
20
+ ;
21
+ }
22
+ return NULL;
23
+}