git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Sixt <J.Sixt@eudaptics.com>, Junio C Hamano <junkio@cox.net>
Subject: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Date: Wed, 13 Jun 2007 20:54:32 +0200	[thread overview]
Message-ID: <20070613185432.GA3412@steel.home> (raw)
In-Reply-To: <81b0412b0706130051l570e6ab7y48d6eea8c6b2d97e@mail.gmail.com>

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 <raa.lkml@gmail.com>
---
 Makefile           |    5 +++++
 compat/hstrerror.c |   21 +++++++++++++++++++++
 git-compat-util.h  |    5 +++++
 3 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 compat/hstrerror.c

diff --git a/Makefile b/Makefile
index 0f6540c..e054bc7 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 0000000..069c555
--- /dev/null
+++ b/compat/hstrerror.c
@@ -0,0 +1,21 @@
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+
+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 6bd8987..b2ab3f8 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)
-- 
1.5.2.1.270.g288d3f

  parent reply	other threads:[~2007-06-13 18:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-12 16:13 [BUG] 75d8ff1 fails on SunOS 5.9 (missing hsterror) from ba505322 Randal L. Schwartz
2007-06-12 20:03 ` Alex Riesen
2007-06-12 20:52 ` [PATCH] Do not use h_errno after connect(2): the function does not set it Alex Riesen
2007-06-12 21:31   ` [PATCH] Add a local implementation of hstrerror for the system which do not have it Alex Riesen
2007-06-13  7:05     ` Johannes Sixt
     [not found]       ` <81b0412b0706130051l570e6ab7y48d6eea8c6b2d97e@mail.gmail.com>
2007-06-13 18:54         ` Alex Riesen [this message]
2007-06-16 15:21           ` Randal L. Schwartz
2007-06-18 21:28     ` Brandon Casey
2007-06-18 21:34       ` Brandon Casey
2007-06-18 21:37       ` Alex Riesen
2007-06-18 21:53         ` Brandon Casey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070613185432.GA3412@steel.home \
    --to=raa.lkml@gmail.com \
    --cc=J.Sixt@eudaptics.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).