. Convert return type of gai_strerror() to 'const char *' as POSIX requires.
. Convert ai_errlist[] to simple 'char *' array, and appropriately optimize gai_strerror()
This commit is contained in:
parent
03c51c7e90
commit
ed61386604
@ -247,7 +247,7 @@ int getaddrinfo(const char *, const char *,
|
||||
int getnameinfo(const struct sockaddr *, socklen_t, char *,
|
||||
size_t, char *, size_t, int);
|
||||
void freeaddrinfo(struct addrinfo *);
|
||||
char *gai_strerror(int);
|
||||
const char *gai_strerror(int);
|
||||
void setnetgrent(const char *);
|
||||
void setservent(int);
|
||||
|
||||
|
@ -285,26 +285,23 @@ static int res_searchN(const char *, struct res_target *);
|
||||
static int res_querydomainN(const char *, const char *,
|
||||
struct res_target *);
|
||||
|
||||
static struct ai_errlist {
|
||||
const char *str;
|
||||
int code;
|
||||
} ai_errlist[] = {
|
||||
{ "Success", 0, },
|
||||
{ "Temporary failure in name resolution", EAI_AGAIN, },
|
||||
{ "Invalid value for ai_flags", EAI_BADFLAGS, },
|
||||
{ "Non-recoverable failure in name resolution", EAI_FAIL, },
|
||||
{ "ai_family not supported", EAI_FAMILY, },
|
||||
{ "Memory allocation failure", EAI_MEMORY, },
|
||||
{ "hostname nor servname provided, or not known", EAI_NONAME, },
|
||||
{ "servname not supported for ai_socktype", EAI_SERVICE, },
|
||||
{ "ai_socktype not supported", EAI_SOCKTYPE, },
|
||||
{ "System error returned in errno", EAI_SYSTEM, },
|
||||
{ "Invalid value for hints", EAI_BADHINTS, },
|
||||
{ "Resolved protocol is unknown", EAI_PROTOCOL, },
|
||||
/* backward compatibility with userland code prior to 2553bis-02 */
|
||||
{ "Address family for hostname not supported", 1, },
|
||||
{ "No address associated with hostname", 7, },
|
||||
{ NULL, -1, },
|
||||
/* Entries EAI_ADDRFAMILY (1) and EAI_NODATA (7) are obsoleted, but left */
|
||||
/* for backward compatibility with userland code prior to 2553bis-02 */
|
||||
static const char *ai_errlist[] = {
|
||||
"Success", /* 0 */
|
||||
"Address family for hostname not supported", /* 1 */
|
||||
"Temporary failure in name resolution", /* EAI_AGAIN */
|
||||
"Invalid value for ai_flags", /* EAI_BADFLAGS */
|
||||
"Non-recoverable failure in name resolution", /* EAI_FAIL */
|
||||
"ai_family not supported", /* EAI_FAMILY */
|
||||
"Memory allocation failure", /* EAI_MEMORY */
|
||||
"No address associated with hostname", /* 7 */
|
||||
"hostname nor servname provided, or not known", /* EAI_NONAME */
|
||||
"servname not supported for ai_socktype", /* EAI_SERVICE */
|
||||
"ai_socktype not supported", /* EAI_SOCKTYPE */
|
||||
"System error returned in errno", /* EAI_SYSTEM */
|
||||
"Invalid value for hints", /* EAI_BADHINTS */
|
||||
"Resolved protocol is unknown" /* EAI_PROTOCOL */
|
||||
};
|
||||
|
||||
/*
|
||||
@ -360,16 +357,11 @@ do { \
|
||||
#define MATCH(x, y, w) \
|
||||
((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
|
||||
|
||||
char *
|
||||
gai_strerror(ecode)
|
||||
int ecode;
|
||||
const char *
|
||||
gai_strerror(int ecode)
|
||||
{
|
||||
struct ai_errlist *p;
|
||||
|
||||
for (p = ai_errlist; p->str; p++) {
|
||||
if (p->code == ecode)
|
||||
return (char *)p->str;
|
||||
}
|
||||
if (ecode >= 0 && ecode < EAI_MAX)
|
||||
return ai_errlist[ecode];
|
||||
return "Unknown error";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user