{"thread":{"id":"62451","subject":"[PATCH] compat: only replace hstrerror if NO_IPV6.","startedAt":"2024-11-05T10:24:43Z","lastAt":"2024-11-07T17:56:18Z","messageCount":2,"participants":["Jonas 'Sortie' Termansen","Torsten Bögershausen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"506654","messageId":"436f1046-a997-4bd1-9d4e-17a429822c07@maxsi.org","threadId":"62451","inReplyTo":null,"subject":"[PATCH] compat: only replace hstrerror if NO_IPV6.","fromName":"Jonas 'Sortie' Termansen","fromEmail":"sortie@maxsi.org","sentAt":"2024-11-05T10:23:33Z","receivedAt":"2024-11-05T10:24:43Z","isPatch":true,"sender":{"key":"sortie@maxsi.org","avatar":"https://avatars.githubusercontent.com/u/3636196?v=4"},"body":"Modern POSIX-1.2024 systems might only have getaddrinfo(3) but not\ngethostbyname(3) (and hstrerror(3)). Git will only use getaddrinfo\nin this case and not hstrerror, but will still attempt to replace\nthe missing hstrerror function, and the build fails due to the\nmissing the error constants.\n\nThis change declares githstrerror only if it is going to be used.\n\nSigned-off-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>\n---\n compat/hstrerror.c | 2 ++\n git-compat-util.h  | 2 ++\n 2 files changed, 4 insertions(+)\n\ndiff --git a/compat/hstrerror.c b/compat/hstrerror.c\nindex b85a2fa956..0a481d97dc 100644\n--- a/compat/hstrerror.c\n+++ b/compat/hstrerror.c\n@@ -2,6 +2,7 @@\n #include <stdio.h>\n #include <netdb.h>\n \n+#ifdef NO_IPV6\n const char *githstrerror(int err)\n {\n \tstatic char buffer[48];\n@@ -19,3 +20,4 @@ const char *githstrerror(int err)\n \tsnprintf(buffer, sizeof(buffer), \"Name resolution error %d\", err);\n \treturn buffer;\n }\n+#endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e4a306dd56..4a1072b9cf 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -930,10 +930,12 @@ uintmax_t gitstrtoumax(const char *, char **, int);\n intmax_t gitstrtoimax(const char *, char **, int);\n #endif\n \n+#ifdef NO_IPV6\n #ifdef NO_HSTRERROR\n #define hstrerror githstrerror\n const char *githstrerror(int herror);\n #endif\n+#endif\n \n #ifdef NO_MEMMEM\n #define memmem gitmemmem\n-- \n2.45.2\n\n"},{"id":"506809","messageId":"20241107175606.GA15130@tb-raspi4","threadId":"62451","inReplyTo":"436f1046-a997-4bd1-9d4e-17a429822c07@maxsi.org","subject":"Re: [PATCH] compat: only replace hstrerror if NO_IPV6.","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2024-11-07T17:56:06Z","receivedAt":"2024-11-07T17:56:18Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Tue, Nov 05, 2024 at 11:23:33AM +0100, Jonas 'Sortie' Termansen wrote:\n> Modern POSIX-1.2024 systems might only have getaddrinfo(3) but not\n> gethostbyname(3) (and hstrerror(3)). Git will only use getaddrinfo\n> in this case and not hstrerror, but will still attempt to replace\n> the missing hstrerror function, and the build fails due to the\n> missing the error constants.\n>\n> This change declares githstrerror only if it is going to be used.\n>\n> Signed-off-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>\n\nThanks for the heads up. Out of interest, is this a real system,\nor a fix for future problems ?\n\nAfter reading the commit message and doing some digging, things become more clear.\n\nHow about something more verbatim, does this makes sense:\n\nModern POSIX-1.2024 systems might only have getaddrinfo(3) but not\ngethostbyname(3) (and hstrerror(3)). Git is then compiled to use\ngetaddrinfo() and not hstrerror().\nHowever, the function githstrerror() is still compiled (but not used),\nand even worse, the compilation fails due missing the error constants.\n\nThis change implemets githstrerror() only if it is going to be used,\nfor systems that have both NO_IPV6 and NO_HSTRERROR defined.\n\n\nFor a side question, please see below.\n\n> ---\n>  compat/hstrerror.c | 2 ++\n>  git-compat-util.h  | 2 ++\n>  2 files changed, 4 insertions(+)\n>\n> diff --git a/compat/hstrerror.c b/compat/hstrerror.c\n> index b85a2fa956..0a481d97dc 100644\n> --- a/compat/hstrerror.c\n> +++ b/compat/hstrerror.c\n> @@ -2,6 +2,7 @@\n>  #include <stdio.h>\n>  #include <netdb.h>\n>\n> +#ifdef NO_IPV6\n\nshould we add\n  #ifdef NO_HSTRERROR\nhere as well, to make things even more clear ?\n\n>  const char *githstrerror(int err)\n>  {\n>  \tstatic char buffer[48];\n> @@ -19,3 +20,4 @@ const char *githstrerror(int err)\n>  \tsnprintf(buffer, sizeof(buffer), \"Name resolution error %d\", err);\n>  \treturn buffer;\n>  }\n> +#endif\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index e4a306dd56..4a1072b9cf 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -930,10 +930,12 @@ uintmax_t gitstrtoumax(const char *, char **, int);\n>  intmax_t gitstrtoimax(const char *, char **, int);\n>  #endif\n>\n> +#ifdef NO_IPV6\n>  #ifdef NO_HSTRERROR\n>  #define hstrerror githstrerror\n>  const char *githstrerror(int herror);\n>  #endif\n> +#endif\n>\n>  #ifdef NO_MEMMEM\n>  #define memmem gitmemmem\n> --\n> 2.45.2\n>\n>\n"}]}