From fa0c87c34471286b6c261c781a45ed090135295c Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 13 Jun 2007 20:54:32 +0200 Subject: [PATCH] Add a local implementation of hstrerror for the system which do not have it The function converts the value of h_errno (last error of name resolver library, see netdb.h). One of systems which supposedly do not have the function is SunOS. POSIX does not mandate its presence. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- Makefile | 5 +++++ compat/hstrerror.c | 21 +++++++++++++++++++++ git-compat-util.h | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 compat/hstrerror.c diff --git a/Makefile b/Makefile index fb11fa1987..862c2682aa 100644 --- a/Makefile +++ b/Makefile @@ -410,6 +410,7 @@ ifeq ($(uname_S),SunOS) NEEDS_NSL = YesPlease SHELL_PATH = /bin/bash NO_STRCASESTR = YesPlease + NO_HSTRERROR = YesPlease ifeq ($(uname_R),5.8) NEEDS_LIBICONV = YesPlease NO_UNSETENV = YesPlease @@ -654,6 +655,10 @@ endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif +ifdef NO_HSTRERROR + COMPAT_CFLAGS += -DNO_HSTRERROR + COMPAT_OBJS += compat/hstrerror.o +endif ifeq ($(TCLTK_PATH),) NO_TCLTK=NoThanks diff --git a/compat/hstrerror.c b/compat/hstrerror.c new file mode 100644 index 0000000000..069c555da4 --- /dev/null +++ b/compat/hstrerror.c @@ -0,0 +1,21 @@ +#include +#include +#include + +const char *githstrerror(int err) +{ + static char buffer[48]; + switch (err) + { + case HOST_NOT_FOUND: + return "Authoritative answer: host not found"; + case NO_DATA: + return "Valid name, no data record of requested type"; + case NO_RECOVERY: + return "Non recoverable errors, FORMERR, REFUSED, NOTIMP"; + case TRY_AGAIN: + return "Non-authoritative \"host not found\", or SERVERFAIL"; + } + sprintf(buffer, "Name resolution error %d", err); + return buffer; +} diff --git a/git-compat-util.h b/git-compat-util.h index 6bd8987b27..b2ab3f8256 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -167,6 +167,11 @@ extern size_t gitstrlcpy(char *, const char *, size_t); extern uintmax_t gitstrtoumax(const char *, char **, int); #endif +#ifdef NO_HSTRERROR +#define hstrerror githstrerror +extern const char *githstrerror(int herror); +#endif + extern void release_pack_memory(size_t, int); static inline char* xstrdup(const char *str)