diff options
author | ume <ume@FreeBSD.org> | 2009-11-09 12:46:59 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2009-11-09 12:46:59 +0000 |
commit | a9dc4dbb6208ebff265d4470aa4d32abe2907222 (patch) | |
tree | 8c49f7e4e5b83c1a5dd5a3167bddb097ea94216b /lib/libc | |
parent | 916f88dc5a30d26b53dcd17f3f9e551bcba53e05 (diff) | |
download | FreeBSD-src-a9dc4dbb6208ebff265d4470aa4d32abe2907222.zip FreeBSD-src-a9dc4dbb6208ebff265d4470aa4d32abe2907222.tar.gz |
Add NLS catalogs support to gai_strerror(3).
Controlled by NLS define.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/gai_strerror.c | 58 | ||||
-rw-r--r-- | lib/libc/nls/C.msg | 36 |
2 files changed, 94 insertions, 0 deletions
diff --git a/lib/libc/net/gai_strerror.c b/lib/libc/net/gai_strerror.c index 5611559..4f60f2d 100644 --- a/lib/libc/net/gai_strerror.c +++ b/lib/libc/net/gai_strerror.c @@ -30,7 +30,17 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "namespace.h" #include <netdb.h> +#if defined(NLS) +#include <nl_types.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> +#include <string.h> +#include "reentrant.h" +#endif +#include "un-namespace.h" /* Entries EAI_ADDRFAMILY (1) and EAI_NODATA (7) are obsoleted, but left */ /* for backward compatibility with userland code prior to 2553bis-02 */ @@ -52,9 +62,57 @@ static const char *ai_errlist[] = { "Argument buffer overflow" /* EAI_OVERFLOW */ }; +#if defined(NLS) +static char gai_buf[NL_TEXTMAX]; +static once_t gai_init_once = ONCE_INITIALIZER; +static thread_key_t gai_key; +static int gai_keycreated = 0; + +static void +gai_keycreate(void) +{ + gai_keycreated = (thr_keycreate(&gai_key, free) == 0); +} +#endif + const char * gai_strerror(int ecode) { +#if defined(NLS) + nl_catd catd; + char *buf; + + if (thr_main() != 0) + buf = gai_buf; + else { + if (thr_once(&gai_init_once, gai_keycreate) != 0 || + !gai_keycreated) + goto thr_err; + if ((buf = thr_getspecific(gai_key)) == NULL) { + if ((buf = malloc(sizeof(gai_buf))) == NULL) + goto thr_err; + if (thr_setspecific(gai_key, buf) != 0) { + free(buf); + goto thr_err; + } + } + } + + catd = catopen("libc", NL_CAT_LOCALE); + if (ecode > 0 && ecode < EAI_MAX) + strlcpy(buf, catgets(catd, 3, ecode, ai_errlist[ecode]), + sizeof(gai_buf)); + else if (ecode == 0) + strlcpy(buf, catgets(catd, 3, NL_MSGMAX - 1, "Success"), + sizeof(gai_buf)); + else + strlcpy(buf, catgets(catd, 3, NL_MSGMAX, "Unknown error"), + sizeof(gai_buf)); + catclose(catd); + return buf; + +thr_err: +#endif if (ecode >= 0 && ecode < EAI_MAX) return ai_errlist[ecode]; return "Unknown error"; diff --git a/lib/libc/nls/C.msg b/lib/libc/nls/C.msg index b25e83f..2210df6 100644 --- a/lib/libc/nls/C.msg +++ b/lib/libc/nls/C.msg @@ -257,3 +257,39 @@ $ SIGUSR1 30 User defined signal 1 $ SIGUSR2 31 User defined signal 2 +$ +$ gai_strerror() support catalog +$ +$set 3 +$ 1 (obsolete) +1 Address family for hostname not supported +$ EAI_AGAIN +2 Temporary failure in name resolution +$ EAI_BADFLAGS +3 Invalid value for ai_flags +$ EAI_FAIL +4 Non-recoverable failure in name resolution +$ EAI_FAMILY +5 ai_family not supported +$ EAI_MEMORY +6 Memory allocation failure +$ 7 (obsolete) +7 No address associated with hostname +$ EAI_NONAME +8 hostname nor servname provided, or not known +$ EAI_SERVICE +9 servname not supported for ai_socktype +$ EAI_SOCKTYPE +10 ai_socktype not supported +$ EAI_SYSTEM +11 System error returned in errno +$ EAI_BADHINTS +12 Invalid value for hints +$ EAI_PROTOCOL +13 Resolved protocol is unknown +$ EAI_OVERFLOW +14 Argument buffer overflow +$ 0 +32766 Success +$ NL_MSGMAX +32767 Unknown error |