git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] compat: only replace hstrerror if NO_IPV6.
@ 2024-11-05 10:23 Jonas 'Sortie' Termansen
  2024-11-07 17:56 ` Torsten Bögershausen
  0 siblings, 1 reply; 2+ messages in thread
From: Jonas 'Sortie' Termansen @ 2024-11-05 10:23 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Modern POSIX-1.2024 systems might only have getaddrinfo(3) but not
gethostbyname(3) (and hstrerror(3)). Git will only use getaddrinfo
in this case and not hstrerror, but will still attempt to replace
the missing hstrerror function, and the build fails due to the
missing the error constants.

This change declares githstrerror only if it is going to be used.

Signed-off-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>
---
 compat/hstrerror.c | 2 ++
 git-compat-util.h  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/compat/hstrerror.c b/compat/hstrerror.c
index b85a2fa956..0a481d97dc 100644
--- a/compat/hstrerror.c
+++ b/compat/hstrerror.c
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <netdb.h>
 
+#ifdef NO_IPV6
 const char *githstrerror(int err)
 {
 	static char buffer[48];
@@ -19,3 +20,4 @@ const char *githstrerror(int err)
 	snprintf(buffer, sizeof(buffer), "Name resolution error %d", err);
 	return buffer;
 }
+#endif
diff --git a/git-compat-util.h b/git-compat-util.h
index e4a306dd56..4a1072b9cf 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -930,10 +930,12 @@ uintmax_t gitstrtoumax(const char *, char **, int);
 intmax_t gitstrtoimax(const char *, char **, int);
 #endif
 
+#ifdef NO_IPV6
 #ifdef NO_HSTRERROR
 #define hstrerror githstrerror
 const char *githstrerror(int herror);
 #endif
+#endif
 
 #ifdef NO_MEMMEM
 #define memmem gitmemmem
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] compat: only replace hstrerror if NO_IPV6.
  2024-11-05 10:23 [PATCH] compat: only replace hstrerror if NO_IPV6 Jonas 'Sortie' Termansen
@ 2024-11-07 17:56 ` Torsten Bögershausen
  0 siblings, 0 replies; 2+ messages in thread
From: Torsten Bögershausen @ 2024-11-07 17:56 UTC (permalink / raw)
  To: Jonas 'Sortie' Termansen; +Cc: git, Junio C Hamano

On Tue, Nov 05, 2024 at 11:23:33AM +0100, Jonas 'Sortie' Termansen wrote:
> Modern POSIX-1.2024 systems might only have getaddrinfo(3) but not
> gethostbyname(3) (and hstrerror(3)). Git will only use getaddrinfo
> in this case and not hstrerror, but will still attempt to replace
> the missing hstrerror function, and the build fails due to the
> missing the error constants.
>
> This change declares githstrerror only if it is going to be used.
>
> Signed-off-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>

Thanks for the heads up. Out of interest, is this a real system,
or a fix for future problems ?

After reading the commit message and doing some digging, things become more clear.

How about something more verbatim, does this makes sense:

Modern POSIX-1.2024 systems might only have getaddrinfo(3) but not
gethostbyname(3) (and hstrerror(3)). Git is then compiled to use
getaddrinfo() and not hstrerror().
However, the function githstrerror() is still compiled (but not used),
and even worse, the compilation fails due missing the error constants.

This change implemets githstrerror() only if it is going to be used,
for systems that have both NO_IPV6 and NO_HSTRERROR defined.


For a side question, please see below.

> ---
>  compat/hstrerror.c | 2 ++
>  git-compat-util.h  | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/compat/hstrerror.c b/compat/hstrerror.c
> index b85a2fa956..0a481d97dc 100644
> --- a/compat/hstrerror.c
> +++ b/compat/hstrerror.c
> @@ -2,6 +2,7 @@
>  #include <stdio.h>
>  #include <netdb.h>
>
> +#ifdef NO_IPV6

should we add
  #ifdef NO_HSTRERROR
here as well, to make things even more clear ?

>  const char *githstrerror(int err)
>  {
>  	static char buffer[48];
> @@ -19,3 +20,4 @@ const char *githstrerror(int err)
>  	snprintf(buffer, sizeof(buffer), "Name resolution error %d", err);
>  	return buffer;
>  }
> +#endif
> diff --git a/git-compat-util.h b/git-compat-util.h
> index e4a306dd56..4a1072b9cf 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -930,10 +930,12 @@ uintmax_t gitstrtoumax(const char *, char **, int);
>  intmax_t gitstrtoimax(const char *, char **, int);
>  #endif
>
> +#ifdef NO_IPV6
>  #ifdef NO_HSTRERROR
>  #define hstrerror githstrerror
>  const char *githstrerror(int herror);
>  #endif
> +#endif
>
>  #ifdef NO_MEMMEM
>  #define memmem gitmemmem
> --
> 2.45.2
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-07 17:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05 10:23 [PATCH] compat: only replace hstrerror if NO_IPV6 Jonas 'Sortie' Termansen
2024-11-07 17:56 ` Torsten Bögershausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).