git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] compat: only replace hstrerror if NO_IPV6.

From
Jonas 'Sortie' Termansen <sortie@maxsi.org>
Date
Nov 5, 2024, 10:23 UTC
Message-ID
<436f1046-a997-4bd1-9d4e-17a429822c07@maxsi.org>

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
Next: Torsten Bögershausen
Message 1 of 2 in “compat: only replace hstrerror if NO_IPV6.”
  1. compat: only replace hstrerror if NO_IPV6.Jonas 'Sortie' Termansen, Nov 5, 2024
  2. Torsten BögershausenNov 7, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.