summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphantom <phantom@FreeBSD.org>2005-02-14 11:33:12 +0000
committerphantom <phantom@FreeBSD.org>2005-02-14 11:33:12 +0000
commiteb29a7bac4636e6bec3a03173f13a68d2f0c8446 (patch)
tree0eeb069d09cbd153386f855dc2323f366df7f0fb
parent4548946acd47afa9ed8af3978827f3de56d9034e (diff)
downloadFreeBSD-src-eb29a7bac4636e6bec3a03173f13a68d2f0c8446.zip
FreeBSD-src-eb29a7bac4636e6bec3a03173f13a68d2f0c8446.tar.gz
. Convert return type of gai_strerror() to 'const char *' as POSIX requires.
. Convert ai_errlist[] to simple 'char *' array, and appropriately optimize gai_strerror()
-rw-r--r--include/netdb.h2
-rw-r--r--lib/libc/net/getaddrinfo.c50
2 files changed, 22 insertions, 30 deletions
diff --git a/include/netdb.h b/include/netdb.h
index 4278794..57cd70b 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -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);
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index 29b1f6d..eb811cb 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -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";
}
OpenPOWER on IntegriCloud