Skip to content

Commit fa0c87c

Browse files
raalkmlgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18a9368 commit fa0c87c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ ifeq ($(uname_S),SunOS)
410410
NEEDS_NSL = YesPlease
411411
SHELL_PATH = /bin/bash
412412
NO_STRCASESTR = YesPlease
413+
NO_HSTRERROR = YesPlease
413414
ifeq ($(uname_R),5.8)
414415
NEEDS_LIBICONV = YesPlease
415416
NO_UNSETENV = YesPlease
@@ -654,6 +655,10 @@ endif
654655
ifdef NO_PERL_MAKEMAKER
655656
export NO_PERL_MAKEMAKER
656657
endif
658+
ifdef NO_HSTRERROR
659+
COMPAT_CFLAGS += -DNO_HSTRERROR
660+
COMPAT_OBJS += compat/hstrerror.o
661+
endif
657662

658663
ifeq ($(TCLTK_PATH),)
659664
NO_TCLTK=NoThanks

compat/hstrerror.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <string.h>
2+
#include <stdio.h>
3+
#include <netdb.h>
4+
5+
const char *githstrerror(int err)
6+
{
7+
static char buffer[48];
8+
switch (err)
9+
{
10+
case HOST_NOT_FOUND:
11+
return "Authoritative answer: host not found";
12+
case NO_DATA:
13+
return "Valid name, no data record of requested type";
14+
case NO_RECOVERY:
15+
return "Non recoverable errors, FORMERR, REFUSED, NOTIMP";
16+
case TRY_AGAIN:
17+
return "Non-authoritative \"host not found\", or SERVERFAIL";
18+
}
19+
sprintf(buffer, "Name resolution error %d", err);
20+
return buffer;
21+
}

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ extern size_t gitstrlcpy(char *, const char *, size_t);
167167
extern uintmax_t gitstrtoumax(const char *, char **, int);
168168
#endif
169169

170+
#ifdef NO_HSTRERROR
171+
#define hstrerror githstrerror
172+
extern const char *githstrerror(int herror);
173+
#endif
174+
170175
extern void release_pack_memory(size_t, int);
171176

172177
static inline char* xstrdup(const char *str)

0 commit comments

Comments
 (0)