Subject: Re: [PATCH] compat: add memrchr()

From: Jonathan Nieder <[email-masked]>
Date: Fri, 15 Oct 2010 01:06:54 -0500

Ævar Arnfjörð Bjarmason wrote:

> Maybe something like this for configure.ac:
> 
>     AC_CHECK_LIB([c], [memchr],
>     [HAVE_MEMRCHR=YesPlease],
>     [HAVE_MEMRCHR=])
>     AC_SUBST(HAVE_MEMRCHR)
> 
> And documentation with the other HAVE_* variables at the top of the
> Makefile?

Hmm, the BSDs and plan 9 have an memrchr() apparently.   Any idea for
taking advantage of that (the makefile support part) that's less ugly
than this?

If we miss a platform, that's no big deal.  The 1-char-at-a-time
loop is not so slow, and the "#define memrchr gitmemrchr" ensures
that it would not conflict with the libc version.
---
diff --git a/Makefile b/Makefile
index 1f1ce04..fa91530 100644
--- a/Makefile
+++ b/Makefile
@@ -211,6 +211,8 @@ all::
 #
 # Define NO_REGEX if you have no or inferior regex support in your C library.
 #
+# Define HAVE_MEMRCHR if you have memrchr() in your C library.
+#
 # Define JSMIN to point to JavaScript minifier that functions as
 # a filter to have gitweb.js minified.
 #
@@ -1388,6 +1390,9 @@ endif
 ifdef NO_UINTMAX_T
 	BASIC_CFLAGS += -Duintmax_t=uint32_t
 endif
+ifdef HAVE_MEMRCHR
+	BASIC_CFLAGS += -DHAVE_MEMRCHR
+endif
 ifdef NO_SOCKADDR_STORAGE
 ifdef NO_IPV6
 	BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in
diff --git a/git-compat-util.h b/git-compat-util.h
index 6f1020e..45aaebc 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -366,7 +366,7 @@ extern int git_vsnprintf(char *str, size_t maxsize,
 #define HAVE_STRCHRNUL
 #define HAVE_MEMPCPY
 #endif
-#if __GLIBC_PREREQ(2, 2)
+#if __GLIBC_PREREQ(2, 2) && !defined(HAVE_MEMRCHR)
 #define HAVE_MEMRCHR
 #endif
 #endif