{"thread":{"id":"10744","subject":"[PATCH 1/2] Add strchrnul()","startedAt":"2007-11-09T00:49:36Z","lastAt":"2007-11-12T10:09:05Z","messageCount":18,"participants":["René Scharfe","Johannes Schindelin","Jeff King","Andreas Ericsson","Jakub Narebski","Junio C Hamano","David Symonds","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"58956","messageId":"4733AEA0.1060602@lsrfire.ath.cx","threadId":"10744","inReplyTo":null,"subject":"[PATCH 1/2] Add strchrnul()","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2007-11-09T00:49:36Z","receivedAt":"2007-11-09T00:49:36Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"As suggested by Pierre Habouzit, add strchrnul().  It's a useful GNU\nextension and can simplify string parser code.  There are several\nplaces in git that can be converted to strchrnul(); as a trivial\nexample, this patch introduces its usage to builtin-fetch--tool.c.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n\n Makefile              |   13 +++++++++++++\n builtin-fetch--tool.c |    8 ++------\n compat/strchrnul.c    |    8 ++++++++\n git-compat-util.h     |    5 +++++\n 4 files changed, 28 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 0d5590f..578c999 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -30,6 +30,8 @@ all::\n #\n # Define NO_MEMMEM if you don't have memmem.\n #\n+# Define NO_STRCHRNUL if you don't have strchrnul.\n+#\n # Define NO_STRLCPY if you don't have strlcpy.\n #\n # Define NO_STRTOUMAX if you don't have strtoumax in the C library.\n@@ -406,6 +408,7 @@ ifeq ($(uname_S),Darwin)\n \tOLD_ICONV = UnfortunatelyYes\n \tNO_STRLCPY = YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n endif\n ifeq ($(uname_S),SunOS)\n \tNEEDS_SOCKET = YesPlease\n@@ -413,6 +416,7 @@ ifeq ($(uname_S),SunOS)\n \tSHELL_PATH = /bin/bash\n \tNO_STRCASESTR = YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n \tNO_HSTRERROR = YesPlease\n \tifeq ($(uname_R),5.8)\n \t\tNEEDS_LIBICONV = YesPlease\n@@ -438,6 +442,7 @@ ifeq ($(uname_O),Cygwin)\n \tNO_D_INO_IN_DIRENT = YesPlease\n \tNO_STRCASESTR = YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n \tNO_SYMLINK_HEAD = YesPlease\n \tNEEDS_LIBICONV = YesPlease\n \tNO_FAST_WORKING_DIRECTORY = UnfortunatelyYes\n@@ -452,12 +457,14 @@ endif\n ifeq ($(uname_S),FreeBSD)\n \tNEEDS_LIBICONV = YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n \tBASIC_CFLAGS += -I/usr/local/include\n \tBASIC_LDFLAGS += -L/usr/local/lib\n endif\n ifeq ($(uname_S),OpenBSD)\n \tNO_STRCASESTR = YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n \tNEEDS_LIBICONV = YesPlease\n \tBASIC_CFLAGS += -I/usr/local/include\n \tBASIC_LDFLAGS += -L/usr/local/lib\n@@ -473,6 +480,7 @@ endif\n ifeq ($(uname_S),AIX)\n \tNO_STRCASESTR=YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n \tNO_STRLCPY = YesPlease\n \tNEEDS_LIBICONV=YesPlease\n endif\n@@ -485,6 +493,7 @@ ifeq ($(uname_S),IRIX64)\n \tNO_SETENV=YesPlease\n \tNO_STRCASESTR=YesPlease\n \tNO_MEMMEM = YesPlease\n+\tNO_STRCHRNUL = YesPlease\n \tNO_STRLCPY = YesPlease\n \tNO_SOCKADDR_STORAGE=YesPlease\n \tSHELL_PATH=/usr/gnu/bin/bash\n@@ -695,6 +704,10 @@ ifdef NO_MEMMEM\n \tCOMPAT_CFLAGS += -DNO_MEMMEM\n \tCOMPAT_OBJS += compat/memmem.o\n endif\n+ifdef NO_STRCHRNUL\n+\tCOMPAT_CFLAGS += -DNO_STRCHRNUL\n+\tCOMPAT_OBJS += compat/strchrnul.o\n+endif\n \n ifdef THREADED_DELTA_SEARCH\n \tBASIC_CFLAGS += -DTHREADED_DELTA_SEARCH\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 6a78517..ed60847 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -435,9 +435,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu\n \t\t\t\tcp++;\n \t\t\tif (!*cp)\n \t\t\t\tbreak;\n-\t\t\tnp = strchr(cp, '\\n');\n-\t\t\tif (!np)\n-\t\t\t\tnp = cp + strlen(cp);\n+\t\t\tnp = strchrnul(cp, '\\n');\n \t\t\tif (pass) {\n \t\t\t\tlrr_list[i].line = cp;\n \t\t\t\tlrr_list[i].name = cp + 41;\n@@ -461,9 +459,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu\n \t\t\trref++;\n \t\tif (!*rref)\n \t\t\tbreak;\n-\t\tnext = strchr(rref, '\\n');\n-\t\tif (!next)\n-\t\t\tnext = rref + strlen(rref);\n+\t\tnext = strchrnul(rref, '\\n');\n \t\trreflen = next - rref;\n \n \t\tfor (i = 0; i < lrr_count; i++) {\ndiff --git a/compat/strchrnul.c b/compat/strchrnul.c\nnew file mode 100644\nindex 0000000..51839fe\n--- /dev/null\n+++ b/compat/strchrnul.c\n@@ -0,0 +1,8 @@\n+#include \"../git-compat-util.h\"\n+\n+char *gitstrchrnul(const char *s, int c)\n+{\n+\twhile (*s && *s != c)\n+\t\ts++;\n+\treturn (char *)s;\n+}\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 7b29d1b..e72654b 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -183,6 +183,11 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n                 const void *needle, size_t needlelen);\n #endif\n \n+#ifdef NO_STRCHRNUL\n+#define strchrnul gitstrchrnul\n+char *gitstrchrnul(const char *s, int c);\n+#endif\n+\n extern void release_pack_memory(size_t, int);\n \n static inline char* xstrdup(const char *str)\n"},{"id":"58966","messageId":"Pine.LNX.4.64.0711090119430.4362@racer.site","threadId":"10744","inReplyTo":"4733AEA0.1060602@lsrfire.ath.cx","subject":"Re: [PATCH 1/2] Add strchrnul()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-09T01:21:27Z","receivedAt":"2007-11-09T01:21:27Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 9 Nov 2007, Ren? Scharfe wrote:\n\n> diff --git a/Makefile b/Makefile\n> index 0d5590f..578c999 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -30,6 +30,8 @@ all::\n>  #\n>  # Define NO_MEMMEM if you don't have memmem.\n>  #\n> +# Define NO_STRCHRNUL if you don't have strchrnul.\n> +#\n>  # Define NO_STRLCPY if you don't have strlcpy.\n>  #\n>  # Define NO_STRTOUMAX if you don't have strtoumax in the C library.\n> @@ -406,6 +408,7 @@ ifeq ($(uname_S),Darwin)\n>  \tOLD_ICONV = UnfortunatelyYes\n>  \tNO_STRLCPY = YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  endif\n>  ifeq ($(uname_S),SunOS)\n>  \tNEEDS_SOCKET = YesPlease\n> @@ -413,6 +416,7 @@ ifeq ($(uname_S),SunOS)\n>  \tSHELL_PATH = /bin/bash\n>  \tNO_STRCASESTR = YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  \tNO_HSTRERROR = YesPlease\n>  \tifeq ($(uname_R),5.8)\n>  \t\tNEEDS_LIBICONV = YesPlease\n> @@ -438,6 +442,7 @@ ifeq ($(uname_O),Cygwin)\n>  \tNO_D_INO_IN_DIRENT = YesPlease\n>  \tNO_STRCASESTR = YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  \tNO_SYMLINK_HEAD = YesPlease\n>  \tNEEDS_LIBICONV = YesPlease\n>  \tNO_FAST_WORKING_DIRECTORY = UnfortunatelyYes\n> @@ -452,12 +457,14 @@ endif\n>  ifeq ($(uname_S),FreeBSD)\n>  \tNEEDS_LIBICONV = YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  \tBASIC_CFLAGS += -I/usr/local/include\n>  \tBASIC_LDFLAGS += -L/usr/local/lib\n>  endif\n>  ifeq ($(uname_S),OpenBSD)\n>  \tNO_STRCASESTR = YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  \tNEEDS_LIBICONV = YesPlease\n>  \tBASIC_CFLAGS += -I/usr/local/include\n>  \tBASIC_LDFLAGS += -L/usr/local/lib\n> @@ -473,6 +480,7 @@ endif\n>  ifeq ($(uname_S),AIX)\n>  \tNO_STRCASESTR=YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  \tNO_STRLCPY = YesPlease\n>  \tNEEDS_LIBICONV=YesPlease\n>  endif\n> @@ -485,6 +493,7 @@ ifeq ($(uname_S),IRIX64)\n>  \tNO_SETENV=YesPlease\n>  \tNO_STRCASESTR=YesPlease\n>  \tNO_MEMMEM = YesPlease\n> +\tNO_STRCHRNUL = YesPlease\n>  \tNO_STRLCPY = YesPlease\n>  \tNO_SOCKADDR_STORAGE=YesPlease\n>  \tSHELL_PATH=/usr/gnu/bin/bash\n\nMight be easier to define HAVE_STRCHRNUL ;-)\n\n> diff --git a/compat/strchrnul.c b/compat/strchrnul.c\n> new file mode 100644\n> index 0000000..51839fe\n> --- /dev/null\n> +++ b/compat/strchrnul.c\n> @@ -0,0 +1,8 @@\n> +#include \"../git-compat-util.h\"\n> +\n> +char *gitstrchrnul(const char *s, int c)\n> +{\n> +\twhile (*s && *s != c)\n> +\t\ts++;\n> +\treturn (char *)s;\n> +}\n\nThis is so short, I think it is even better to inline it.\n\nCiao,\nDscho\n"},{"id":"58988","messageId":"20071109033136.GB31760@sigill.intra.peff.net","threadId":"10744","inReplyTo":"4733AEA0.1060602@lsrfire.ath.cx","subject":"Re: [PATCH 1/2] Add strchrnul()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-11-09T03:31:36Z","receivedAt":"2007-11-09T03:31:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Nov 09, 2007 at 01:49:36AM +0100, René Scharfe wrote:\n\n> As suggested by Pierre Habouzit, add strchrnul().  It's a useful GNU\n> extension and can simplify string parser code.  There are several\n> places in git that can be converted to strchrnul(); as a trivial\n> example, this patch introduces its usage to builtin-fetch--tool.c.\n\nMinor nit: a comment (in the code or even in the commit message)\ndescribing the what the function does would be nice. On a GNU system,\none can look at the man page, but on others there is no indication of\nwhat it does except for reading the code (and maybe the answer is \"this\nis a common library function, you idiot\", but I am familiar with many\nGNU extensions and didn't know this one).\n\n-Peff\n"},{"id":"59015","messageId":"473434ED.50002@op5.se","threadId":"10744","inReplyTo":"4733AEA0.1060602@lsrfire.ath.cx","subject":"Re: [PATCH 1/2] Add strchrnul()","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-11-09T10:22:37Z","receivedAt":"2007-11-09T10:22:37Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"René Scharfe wrote:\n> As suggested by Pierre Habouzit, add strchrnul().  It's a useful GNU\n> extension and can simplify string parser code.  There are several\n> places in git that can be converted to strchrnul(); as a trivial\n> example, this patch introduces its usage to builtin-fetch--tool.c.\n> \n> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n> ---\n> \n>  Makefile              |   13 +++++++++++++\n>  builtin-fetch--tool.c |    8 ++------\n>  compat/strchrnul.c    |    8 ++++++++\n>  git-compat-util.h     |    5 +++++\n>  4 files changed, 28 insertions(+), 6 deletions(-)\n> \n> diff --git a/Makefile b/Makefile\n> index 0d5590f..578c999 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -30,6 +30,8 @@ all::\n>  #\n>  # Define NO_MEMMEM if you don't have memmem.\n>  #\n> +# Define NO_STRCHRNUL if you don't have strchrnul.\n> +#\n\n\nThis seems overly complicated. How about this instead?\n\nFrom: Andreas Ericsson <ae@op5.se>\nSubject: [PATCH] Add strchrnul()\n\nAs suggested by Pierre Habouzit, add strchrnul().  It's a useful GNU\nextension and can simplify string parser code.  There are several\nplaces in git that can be converted to strchrnul(); as a trivial\nexample, this patch introduces its usage to builtin-fetch--tool.c.\n\nstrchrnul() was introduced in glibc in April 1999 and included in\nglibc-2.1. Checking for that version means the majority of all git\nusers would get to use the optimized version in glibc. Of the\nremaining few some might get to use a slightly slower version\nthan necessary but probably not slower than what we have today.\n\nOriginal patch by Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n\nSigned-off-by: Andreas Ericsson <ae@op5.se>\n---\n\nI'm fairly much against forcing people to know what library\nfunctions they have in order to get software to compile\nproperly. This is, imo, a neater solution, and also inlines\nthe function as suggested by Dscho.\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 7b29d1b..9fedf33 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -105,6 +105,18 @@ extern void set_die_routine(void (*routine)(const char *err\n extern void set_error_routine(void (*routine)(const char *err, va_list params))\n extern void set_warn_routine(void (*routine)(const char *warn, va_list params))\n \n+\n+#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n+# define strchrnul(s, c) gitstrchrnul(s, c)\n+static inline char *gitstrchrnul(const char *s, int c)\n+{\n+       while (*s && *s != c)\n+               s++;\n+\n+       return (char *)s;\n+}\n+#endif\n+\n #ifdef NO_MMAP\n \n #ifndef PROT_READ\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 6a78517..ed60847 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -435,9 +435,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu\n \t\t\t\tcp++;\n \t\t\tif (!*cp)\n \t\t\t\tbreak;\n-\t\t\tnp = strchr(cp, '\\n');\n-\t\t\tif (!np)\n-\t\t\t\tnp = cp + strlen(cp);\n+\t\t\tnp = strchrnul(cp, '\\n');\n \t\t\tif (pass) {\n \t\t\t\tlrr_list[i].line = cp;\n \t\t\t\tlrr_list[i].name = cp + 41;\n@@ -461,9 +459,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu\n \t\t\trref++;\n \t\tif (!*rref)\n \t\t\tbreak;\n-\t\tnext = strchr(rref, '\\n');\n-\t\tif (!next)\n-\t\t\tnext = rref + strlen(rref);\n+\t\tnext = strchrnul(rref, '\\n');\n \t\trreflen = next - rref;\n \n \t\tfor (i = 0; i < lrr_count; i++) {\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"59042","messageId":"fh1o4o$jei$1@ger.gmane.org","threadId":"10744","inReplyTo":"473434ED.50002@op5.se","subject":"Re: [PATCH 1/2] Add strchrnul()","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-09T13:42:48Z","receivedAt":"2007-11-09T13:42:48Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"[Cc: Andreas Ericsson <ae@op5.se>, \n     René Scharfe <rene.scharfe@lsrfire.ath.cx>, \n     Junio C Hamano <gitster@pobox.com>,\n     git@vger.kernel.org]\n\nAndreas Ericsson wrote:\n\n> René Scharfe wrote:\n>> As suggested by Pierre Habouzit, add strchrnul().  It's a useful GNU\n>> extension and can simplify string parser code.  There are several\n>> places in git that can be converted to strchrnul(); as a trivial\n>> example, this patch introduces its usage to builtin-fetch--tool.c.\n>> \n>> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n>> ---\n>> \n>>  Makefile              |   13 +++++++++++++\n>>  builtin-fetch--tool.c |    8 ++------\n>>  compat/strchrnul.c    |    8 ++++++++\n>>  git-compat-util.h     |    5 +++++\n>>  4 files changed, 28 insertions(+), 6 deletions(-)\n>> \n>> diff --git a/Makefile b/Makefile\n>> index 0d5590f..578c999 100644\n>> --- a/Makefile\n>> +++ b/Makefile\n>> @@ -30,6 +30,8 @@ all::\n>>  #\n>>  # Define NO_MEMMEM if you don't have memmem.\n>>  #\n>> +# Define NO_STRCHRNUL if you don't have strchrnul.\n>> +#\n\nOriginal patch lacked adding appropriate test to configure,\ni.e. something like below to configure.ac\n\n #\n # Define NO_STRCHRNUL if you don't have strchrnul.\n AC_CHECK_FUNC(strchrnul,\n [NO_STRCHRNUL=],\n [NO_STRCHRNUL=YesPlease])\n AC_SUBST(NO_STRCHRNUL)\n \nand the following line to config.mak.in\n\n NO_STRCHRNUL=@NO_STRCHRNUL@\n\n> This seems overly complicated. How about this instead?\n[...]\n> I'm fairly much against forcing people to know what library\n> functions they have in order to get software to compile\n> properly. This is, imo, a neater solution, and also inlines\n> the function as suggested by Dscho.\n\nWouldn't it be better to add ./configure check instead? See above.\n\nAlthough I guess that people using ./configure to set compilation\noptions (to generate config.mak.autogen) are minority...\n\n> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n> +# define strchrnul(s, c) gitstrchrnul(s, c)\n> +static inline char *gitstrchrnul(const char *s, int c)\n> +{\n> +       while (*s && *s != c)\n> +               s++;\n> +\n> +       return (char *)s;\n> +}\n> +#endif\n> +\n\nThis is good solution, although I'm not sure about the check itself.\nWhat if somebody has libc which is not glibc, but it does have\nstrchrnul?\n\n> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\n> index 6a78517..ed60847 100644\n> --- a/builtin-fetch--tool.c\n> +++ b/builtin-fetch--tool.c\n> @@ -435,9 +435,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu\n>                               cp++;\n>                       if (!*cp)\n>                               break;\n> -                     np = strchr(cp, '\\n');\n> -                     if (!np)\n> -                             np = cp + strlen(cp);\n> +                     np = strchrnul(cp, '\\n');\n>                       if (pass) {\n>                               lrr_list[i].line = cp;\n>                               lrr_list[i].name = cp + 41;\n> @@ -461,9 +459,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu\n>                       rref++;\n>               if (!*rref)\n>                       break;\n> -             next = strchr(rref, '\\n');\n> -             if (!next)\n> -                     next = rref + strlen(rref);\n> +             next = strchrnul(rref, '\\n');\n>               rreflen = next - rref;\n>  \n>               for (i = 0; i < lrr_count; i++) {\n\nThis IMHO should go to separate patch.\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"59048","messageId":"473467C4.8020208@op5.se","threadId":"10744","inReplyTo":"fh1o4o$jei$1@ger.gmane.org","subject":"Re: [PATCH 1/2] Add strchrnul()","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-11-09T13:59:32Z","receivedAt":"2007-11-09T13:59:32Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Jakub Narebski wrote:\n> [Cc: Andreas Ericsson <ae@op5.se>, \n>      René Scharfe <rene.scharfe@lsrfire.ath.cx>, \n>      Junio C Hamano <gitster@pobox.com>,\n>      git@vger.kernel.org]\n> \n\nI'm not sure what's up with this, but I didn't see this email on git@vger,\nso re-adding it to the Cc list now.\n\n> \n> Original patch lacked adding appropriate test to configure,\n> i.e. something like below to configure.ac\n> \n>  #\n>  # Define NO_STRCHRNUL if you don't have strchrnul.\n>  AC_CHECK_FUNC(strchrnul,\n>  [NO_STRCHRNUL=],\n>  [NO_STRCHRNUL=YesPlease])\n>  AC_SUBST(NO_STRCHRNUL)\n>  \n> and the following line to config.mak.in\n> \n>  NO_STRCHRNUL=@NO_STRCHRNUL@\n> \n>> This seems overly complicated. How about this instead?\n> [...]\n>> I'm fairly much against forcing people to know what library\n>> functions they have in order to get software to compile\n>> properly. This is, imo, a neater solution, and also inlines\n>> the function as suggested by Dscho.\n> \n> Wouldn't it be better to add ./configure check instead? See above.\n> \n> Although I guess that people using ./configure to set compilation\n> options (to generate config.mak.autogen) are minority...\n> \n\nPerhaps. I know I don't anyway, and now it's become standard not to\ndo so for a significant part of the git-tracking world.\n\n>> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n>> +# define strchrnul(s, c) gitstrchrnul(s, c)\n>> +static inline char *gitstrchrnul(const char *s, int c)\n>> +{\n>> +       while (*s && *s != c)\n>> +               s++;\n>> +\n>> +       return (char *)s;\n>> +}\n>> +#endif\n>> +\n> \n> This is good solution, although I'm not sure about the check itself.\n> What if somebody has libc which is not glibc, but it does have\n> strchrnul?\n> \n\nThey most likely fall into the minority that get to suffer from\nusing code that's as fast as what's in there today, although\na bit more readable. The glibc optimization is really only\nworthwhile for architectures where strchrnul()-like operations\nhave microcode support, or when it's used on large strings.\n\nYMMV. I suppose rewriting it as\n\n#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 1)\n# define HAVE_STRCHRNUL\n#endif\n\n#ifdef HAVE_STRCHRNUL\n...\n\nwould work too, and will provide an easier way out for other fellas\nwanting to say \"Hey, my favourite solaris libc has this too!\". OTOH,\nthat rewrite can be done when the first such case appears.\n\n\n>> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\n> \n> This IMHO should go to separate patch.\n> \n\n*shrug* Rene had it in his. Monkey see monkey do ;-)\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"59081","messageId":"200711091744.50017.jnareb@gmail.com","threadId":"10744","inReplyTo":"473467C4.8020208@op5.se","subject":"Re: [PATCH 1/2] Add strchrnul()","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-09T16:44:49Z","receivedAt":"2007-11-09T16:44:49Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Andreas Ericsson wrote:\n> Jakub Narebski wrote:\n>> René Scharfe wrote:\n\n>>> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n>>> +# define strchrnul(s, c) gitstrchrnul(s, c)\n>>> +static inline char *gitstrchrnul(const char *s, int c)\n>>> +{\n>>> +       while (*s && *s != c)\n>>> +               s++;\n>>> +\n>>> +       return (char *)s;\n>>> +}\n>>> +#endif\n>>> +\n>> \n>> This is good solution, although I'm not sure about the check itself.\n>> What if somebody has libc which is not glibc, but it does have\n>> strchrnul? \n> \n> They most likely fall into the minority that get to suffer from\n> using code that's as fast as what's in there today, although\n> a bit more readable. The glibc optimization is really only\n> worthwhile for architectures where strchrnul()-like operations\n> have microcode support, or when it's used on large strings.\n\nIf we end up using this solution, then adding test for strchrnul in the \nconfigure (configure.ac and config.mak.in) is not needed...\n\n> YMMV. I suppose rewriting it as\n> \n> #if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 1)\n\n#if !defined(HAVE_STRCHRNUL) && \\\n     defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 1)\n\n> # define HAVE_STRCHRNUL\n> #endif\n> \n> #ifdef HAVE_STRCHRNUL\n> ...\n> \n> would work too, and will provide an easier way out for other fellas\n> wanting to say \"Hey, my favourite solaris libc has this too!\". OTOH,\n> that rewrite can be done when the first such case appears.\n\n...but if we end up using this version (be it HAVE_STRCHRNUL, or \nNO_STRCHRNUL), then test for strchrnul in ./configure is I think\nnecessary.\n\n-- \nJakub Narebski\nPoland\n"},{"id":"59200","messageId":"47359C44.6090903@lsrfire.ath.cx","threadId":"10744","inReplyTo":"473434ED.50002@op5.se","subject":"[PATCH] Simplify strchrnul() compat code","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2007-11-10T11:55:48Z","receivedAt":"2007-11-10T11:55:48Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"From: Andreas Ericsson <ae@op5.se>\n\nstrchrnul() was introduced in glibc in April 1999 and included in\nglibc-2.1. Checking for that version means the majority of all git\nusers would get to use the optimized version in glibc. Of the\nremaining few some might get to use a slightly slower version\nthan necessary but probably not slower than what we have today.\n\nRediffed-against-next-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\nI agree that we can do without providing a way to use a native\nversion outside glibc until we actually encounter such a thing.\n\n Makefile           |   13 -------------\n compat/strchrnul.c |    8 --------\n git-compat-util.h  |    9 +++++++--\n 3 files changed, 7 insertions(+), 23 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 4f1d7ca..4a5d2b9 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -30,8 +30,6 @@ all::\n #\n # Define NO_MEMMEM if you don't have memmem.\n #\n-# Define NO_STRCHRNUL if you don't have strchrnul.\n-#\n # Define NO_STRLCPY if you don't have strlcpy.\n #\n # Define NO_STRTOUMAX if you don't have strtoumax in the C library.\n@@ -409,7 +407,6 @@ ifeq ($(uname_S),Darwin)\n \tOLD_ICONV = UnfortunatelyYes\n \tNO_STRLCPY = YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n endif\n ifeq ($(uname_S),SunOS)\n \tNEEDS_SOCKET = YesPlease\n@@ -417,7 +414,6 @@ ifeq ($(uname_S),SunOS)\n \tSHELL_PATH = /bin/bash\n \tNO_STRCASESTR = YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n \tNO_HSTRERROR = YesPlease\n \tifeq ($(uname_R),5.8)\n \t\tNEEDS_LIBICONV = YesPlease\n@@ -443,7 +439,6 @@ ifeq ($(uname_O),Cygwin)\n \tNO_D_INO_IN_DIRENT = YesPlease\n \tNO_STRCASESTR = YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n \tNO_SYMLINK_HEAD = YesPlease\n \tNEEDS_LIBICONV = YesPlease\n \tNO_FAST_WORKING_DIRECTORY = UnfortunatelyYes\n@@ -458,14 +453,12 @@ endif\n ifeq ($(uname_S),FreeBSD)\n \tNEEDS_LIBICONV = YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n \tBASIC_CFLAGS += -I/usr/local/include\n \tBASIC_LDFLAGS += -L/usr/local/lib\n endif\n ifeq ($(uname_S),OpenBSD)\n \tNO_STRCASESTR = YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n \tNEEDS_LIBICONV = YesPlease\n \tBASIC_CFLAGS += -I/usr/local/include\n \tBASIC_LDFLAGS += -L/usr/local/lib\n@@ -481,7 +474,6 @@ endif\n ifeq ($(uname_S),AIX)\n \tNO_STRCASESTR=YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n \tNO_STRLCPY = YesPlease\n \tNEEDS_LIBICONV=YesPlease\n endif\n@@ -494,7 +486,6 @@ ifeq ($(uname_S),IRIX64)\n \tNO_SETENV=YesPlease\n \tNO_STRCASESTR=YesPlease\n \tNO_MEMMEM = YesPlease\n-\tNO_STRCHRNUL = YesPlease\n \tNO_STRLCPY = YesPlease\n \tNO_SOCKADDR_STORAGE=YesPlease\n \tSHELL_PATH=/usr/gnu/bin/bash\n@@ -705,10 +696,6 @@ ifdef NO_MEMMEM\n \tCOMPAT_CFLAGS += -DNO_MEMMEM\n \tCOMPAT_OBJS += compat/memmem.o\n endif\n-ifdef NO_STRCHRNUL\n-\tCOMPAT_CFLAGS += -DNO_STRCHRNUL\n-\tCOMPAT_OBJS += compat/strchrnul.o\n-endif\n \n ifdef THREADED_DELTA_SEARCH\n \tBASIC_CFLAGS += -DTHREADED_DELTA_SEARCH\ndiff --git a/compat/strchrnul.c b/compat/strchrnul.c\ndeleted file mode 100644\nindex 51839fe..0000000\n--- a/compat/strchrnul.c\n+++ /dev/null\n@@ -1,8 +0,0 @@\n-#include \"../git-compat-util.h\"\n-\n-char *gitstrchrnul(const char *s, int c)\n-{\n-\twhile (*s && *s != c)\n-\t\ts++;\n-\treturn (char *)s;\n-}\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e72654b..11e6df6 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -183,9 +183,14 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n                 const void *needle, size_t needlelen);\n #endif\n \n-#ifdef NO_STRCHRNUL\n+#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n #define strchrnul gitstrchrnul\n-char *gitstrchrnul(const char *s, int c);\n+static inline char *gitstrchrnul(const char *s, int c)\n+{\n+        while (*s && *s != c)\n+                s++;\n+        return (char *)s;\n+}\n #endif\n \n extern void release_pack_memory(size_t, int);\n"},{"id":"59213","messageId":"4735BA79.5020102@op5.se","threadId":"10744","inReplyTo":"47359C44.6090903@lsrfire.ath.cx","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-11-10T14:04:41Z","receivedAt":"2007-11-10T14:04:41Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"René Scharfe wrote:\n>  \n> -#ifdef NO_STRCHRNUL\n> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n\nThis will break things for users of glibc-2.1.1 (the first release still\navailable from ftp://sources.redhat.com/pub/glibc/old-releases that\nincludes the strchrnul() function), since __GLIBC_PREREQ() was invented\nafter strchrnul() was introduced.\n\nReplacing __GLIBC__ with __GLIBC_PREREQ (as in the original patch) will\nsolve it nicely. Users of glibc-2.1.1 will be the odd minority where\nstrchrnul() is available in their libc but not used.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"59307","messageId":"7v6409f4eh.fsf@gitster.siamese.dyndns.org","threadId":"10744","inReplyTo":"4735BA79.5020102@op5.se","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-11T10:44:06Z","receivedAt":"2007-11-11T10:44:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> René Scharfe wrote:\n>>  -#ifdef NO_STRCHRNUL\n>> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n>\n> This will break things for users of glibc-2.1.1 (the first release still\n> available from ftp://sources.redhat.com/pub/glibc/old-releases that\n> includes the strchrnul() function), since __GLIBC_PREREQ() was invented\n> after strchrnul() was introduced.\n>\n> Replacing __GLIBC__ with __GLIBC_PREREQ (as in the original patch) will\n> solve it nicely. Users of glibc-2.1.1 will be the odd minority where\n> strchrnul() is available in their libc but not used.\n\nDo you mean this on top of René's patch?  Although I do not\nthink I saw \"the original patch\" that did it this way, I think\nit makes sense.\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 11e6df6..dd96f7a 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -183,7 +183,7 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n                 const void *needle, size_t needlelen);\n #endif\n \n-#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n+#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n #define strchrnul gitstrchrnul\n static inline char *gitstrchrnul(const char *s, int c)\n {\n"},{"id":"59314","messageId":"4736F723.60904@op5.se","threadId":"10744","inReplyTo":"7v6409f4eh.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-11-11T12:35:47Z","receivedAt":"2007-11-11T12:35:47Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Andreas Ericsson <ae@op5.se> writes:\n> \n>> René Scharfe wrote:\n>>>  -#ifdef NO_STRCHRNUL\n>>> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n>> This will break things for users of glibc-2.1.1 (the first release still\n>> available from ftp://sources.redhat.com/pub/glibc/old-releases that\n>> includes the strchrnul() function), since __GLIBC_PREREQ() was invented\n>> after strchrnul() was introduced.\n>>\n>> Replacing __GLIBC__ with __GLIBC_PREREQ (as in the original patch) will\n>> solve it nicely. Users of glibc-2.1.1 will be the odd minority where\n>> strchrnul() is available in their libc but not used.\n> \n> Do you mean this on top of René's patch?\n\nYes.\n\n>  Although I do not\n> think I saw \"the original patch\" that did it this way,\n\nMy memory seems to be failing. I never committed my proposal to my repo,\nand the one I sent out was the __GLIBC__ || !__GLIBC_PREREQ thing. My\napologies.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"59442","messageId":"ee77f5c20711120103s478e26cdib85f38293423d90c@mail.gmail.com","threadId":"10744","inReplyTo":"7v6409f4eh.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-12T09:03:33Z","receivedAt":"2007-11-12T09:03:33Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"On Nov 11, 2007 9:44 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Andreas Ericsson <ae@op5.se> writes:\n>\n> > René Scharfe wrote:\n> >>  -#ifdef NO_STRCHRNUL\n> >> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n> >\n> > This will break things for users of glibc-2.1.1 (the first release still\n> > available from ftp://sources.redhat.com/pub/glibc/old-releases that\n> > includes the strchrnul() function), since __GLIBC_PREREQ() was invented\n> > after strchrnul() was introduced.\n> >\n> > Replacing __GLIBC__ with __GLIBC_PREREQ (as in the original patch) will\n> > solve it nicely. Users of glibc-2.1.1 will be the odd minority where\n> > strchrnul() is available in their libc but not used.\n>\n> Do you mean this on top of René's patch?  Although I do not\n> think I saw \"the original patch\" that did it this way, I think\n> it makes sense.\n>\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 11e6df6..dd96f7a 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -183,7 +183,7 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n>                  const void *needle, size_t needlelen);\n>  #endif\n>\n> -#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n> +#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n>  #define strchrnul gitstrchrnul\n>  static inline char *gitstrchrnul(const char *s, int c)\n>  {\n\nI just tested it on my machine (OS X Tiger) now that it's in 'next',\nand this breaks the build:\n\n    CC git.o\nIn file included from builtin.h:4,\n                 from git.c:1:\ngit-compat-util.h:187:48: error: missing binary operator before token \"(\"\nmake: *** [git.o] Error 1\n\n\nI don't think I have __GLIBC_PREREQ defined anywhere I can find.\n\nDave.\n"},{"id":"59444","messageId":"473818FA.1060400@viscovery.net","threadId":"10744","inReplyTo":"ee77f5c20711120103s478e26cdib85f38293423d90c@mail.gmail.com","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-11-12T09:12:26Z","receivedAt":"2007-11-12T09:12:26Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"David Symonds schrieb:\n> On Nov 11, 2007 9:44 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> @@ -183,7 +183,7 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n>>                  const void *needle, size_t needlelen);\n>>  #endif\n>>\n>> -#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n>> +#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n>>  #define strchrnul gitstrchrnul\n>>  static inline char *gitstrchrnul(const char *s, int c)\n>>  {\n> \n> I just tested it on my machine (OS X Tiger) now that it's in 'next',\n> and this breaks the build:\n> \n>     CC git.o\n> In file included from builtin.h:4,\n>                  from git.c:1:\n> git-compat-util.h:187:48: error: missing binary operator before token \"(\"\n> make: *** [git.o] Error 1\n> \n> \n> I don't think I have __GLIBC_PREREQ defined anywhere I can find.\n\nTurn the && in that line into || and it should work.\n\n-- Hannes\n"},{"id":"59445","messageId":"ee77f5c20711120124m6281fddfs9403a46cf354b993@mail.gmail.com","threadId":"10744","inReplyTo":"473818FA.1060400@viscovery.net","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-12T09:24:09Z","receivedAt":"2007-11-12T09:24:09Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"On Nov 12, 2007 8:12 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> David Symonds schrieb:\n> > On Nov 11, 2007 9:44 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> >> @@ -183,7 +183,7 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n> >>                  const void *needle, size_t needlelen);\n> >>  #endif\n> >>\n> >> -#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)\n> >> +#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n> >>  #define strchrnul gitstrchrnul\n> >>  static inline char *gitstrchrnul(const char *s, int c)\n> >>  {\n> >\n> > I just tested it on my machine (OS X Tiger) now that it's in 'next',\n> > and this breaks the build:\n> >\n> >     CC git.o\n> > In file included from builtin.h:4,\n> >                  from git.c:1:\n> > git-compat-util.h:187:48: error: missing binary operator before token \"(\"\n> > make: *** [git.o] Error 1\n> >\n> >\n> > I don't think I have __GLIBC_PREREQ defined anywhere I can find.\n>\n> Turn the && in that line into || and it should work.\n\nNope, no dice. Plus, that'd change the logic. I also tried turning the\n(!X && !Y) into (X || Y) to no avail.\n\n\nDave.\n"},{"id":"59448","messageId":"473821CE.8050907@viscovery.net","threadId":"10744","inReplyTo":"ee77f5c20711120124m6281fddfs9403a46cf354b993@mail.gmail.com","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-11-12T09:50:06Z","receivedAt":"2007-11-12T09:50:06Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"David Symonds schrieb:\n> On Nov 12, 2007 8:12 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n>> David Symonds schrieb:\n>>> I don't think I have __GLIBC_PREREQ defined anywhere I can find.\n>> Turn the && in that line into || and it should work.\n> \n> Nope, no dice. Plus, that'd change the logic. I also tried turning the\n> (!X && !Y) into (X || Y) to no avail.\n\nOk, then how about this?\n\n---\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 3d147b6..276a437 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -184,7 +184,13 @@ void *gitmemmem(const void *haystack,\n                  const void *needle, size_t needlelen);\n  #endif\n\n-#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n+#ifdef __GLIBC_PREREQ\n+#if __GLIBC_PREREQ(2, 1)\n+#define HAVE_STRCHRNUL\n+#endif\n+#endif\n+\n+#ifndef HAVE_STRCHRNUL\n  #define strchrnul gitstrchrnul\n  static inline char *gitstrchrnul(const char *s, int c)\n  {\n"},{"id":"59450","messageId":"ee77f5c20711120152i4955ed3bh484c9ac76a7f1f5c@mail.gmail.com","threadId":"10744","inReplyTo":"473821CE.8050907@viscovery.net","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-12T09:52:36Z","receivedAt":"2007-11-12T09:52:36Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"On Nov 12, 2007 8:50 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> David Symonds schrieb:\n> > On Nov 12, 2007 8:12 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> >> David Symonds schrieb:\n> >>> I don't think I have __GLIBC_PREREQ defined anywhere I can find.\n> >> Turn the && in that line into || and it should work.\n> >\n> > Nope, no dice. Plus, that'd change the logic. I also tried turning the\n> > (!X && !Y) into (X || Y) to no avail.\n>\n> Ok, then how about this?\n>\n> ---\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 3d147b6..276a437 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -184,7 +184,13 @@ void *gitmemmem(const void *haystack,\n>                   const void *needle, size_t needlelen);\n>   #endif\n>\n> -#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n> +#ifdef __GLIBC_PREREQ\n> +#if __GLIBC_PREREQ(2, 1)\n> +#define HAVE_STRCHRNUL\n> +#endif\n> +#endif\n> +\n> +#ifndef HAVE_STRCHRNUL\n>\n>   #define strchrnul gitstrchrnul\n>   static inline char *gitstrchrnul(const char *s, int c)\n>   {\n\nYep, that works just fine. Ack.\n\n\nDave.\n"},{"id":"59454","messageId":"fh98ku$da6$1@ger.gmane.org","threadId":"10744","inReplyTo":"ee77f5c20711120152i4955ed3bh484c9ac76a7f1f5c@mail.gmail.com","subject":"Re: [PATCH] Simplify strchrnul() compat code","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-12T10:07:33Z","receivedAt":"2007-11-12T10:07:33Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"David Symonds wrote:\n> On Nov 12, 2007 8:50 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n\n>> -#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n>> +#ifdef __GLIBC_PREREQ\n>> +#if __GLIBC_PREREQ(2, 1)\n>> +#define HAVE_STRCHRNUL\n>> +#endif\n>> +#endif\n>> +\n>> +#ifndef HAVE_STRCHRNUL\n>>\n>>   #define strchrnul gitstrchrnul\n>>   static inline char *gitstrchrnul(const char *s, int c)\n>>   {\n> \n> Yep, that works just fine. Ack.\n\nThis version has also the following advantage that you can set\nHAVE_STRCHRNULL if above test does not detect it in your library.\n\nAlthought you'd better write then:\n\n+#if __GLIBC_PREREQ(2, 1) && !defined(HAVE_STRCHRNUL)\n\nAck.\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"59455","messageId":"47382641.3080109@viscovery.net","threadId":"10744","inReplyTo":"ee77f5c20711120152i4955ed3bh484c9ac76a7f1f5c@mail.gmail.com","subject":"[PATCH] Fix preprocessor logic that determines the availablity of strchrnul().","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-11-12T10:09:05Z","receivedAt":"2007-11-12T10:09:05Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Apart from the error in the condition (&& should actually be ||), the\nconstruct\n\n    #if !defined(A) || !A\n\nleads to a syntax error in the C preprocessor if A is indeed not defined.\n\nTested-by: David Symonds <dsymonds@gmail.com>\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n  git-compat-util.h |    8 +++++++-\n  1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 3d147b6..276a437 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -184,7 +184,13 @@ void *gitmemmem(const void *haystack, size_t haystacklen,\n                  const void *needle, size_t needlelen);\n  #endif\n\n-#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)\n+#ifdef __GLIBC_PREREQ\n+#if __GLIBC_PREREQ(2, 1)\n+#define HAVE_STRCHRNUL\n+#endif\n+#endif\n+\n+#ifndef HAVE_STRCHRNUL\n  #define strchrnul gitstrchrnul\n  static inline char *gitstrchrnul(const char *s, int c)\n  {\n-- \n1.5.3.5.578.g1f8ec\n"}]}