summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7271328)
raw | patch | inline | side by side (parent: 7271328)
author | Linus Torvalds <torvalds@osdl.org> | |
Mon, 19 Sep 2005 01:30:50 +0000 (18:30 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 19 Sep 2005 15:49:39 +0000 (08:49 -0700) |
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>
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>
Makefile | patch | blob | history | |
compat/strcasestr.c | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile b/Makefile
index 877e0b8a662a66b50e7145e609cb98f15f77b4e6..957fadc57c713f9521dd158bab5f661c0c562247 100644 (file)
--- a/Makefile
+++ b/Makefile
# 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.
#
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
--- /dev/null
+++ b/compat/strcasestr.c
@@ -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;
+}