diff options
author | phantom <phantom@FreeBSD.org> | 2005-02-14 11:33:12 +0000 |
---|---|---|
committer | phantom <phantom@FreeBSD.org> | 2005-02-14 11:33:12 +0000 |
commit | eb29a7bac4636e6bec3a03173f13a68d2f0c8446 (patch) | |
tree | 0eeb069d09cbd153386f855dc2323f366df7f0fb /lib | |
parent | 4548946acd47afa9ed8af3978827f3de56d9034e (diff) | |
download | FreeBSD-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()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 50 |
1 files changed, 21 insertions, 29 deletions
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"; } |