2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include "namespace.h"
40 #include "reentrant.h"
42 #include "un-namespace.h"
45 * Entries EAI_ADDRFAMILY (1) and EAI_NODATA (7) were omitted from RFC 3493,
46 * but are or may be used as extensions or in old code.
48 static const char *ai_errlist[] = {
50 "Address family for hostname not supported", /* EAI_ADDRFAMILY */
51 "Name could not be resolved at this time", /* EAI_AGAIN */
52 "Flags parameter had an invalid value", /* EAI_BADFLAGS */
53 "Non-recoverable failure in name resolution", /* EAI_FAIL */
54 "Address family not recognized", /* EAI_FAMILY */
55 "Memory allocation failure", /* EAI_MEMORY */
56 "No address associated with hostname", /* EAI_NODATA*/
57 "Name does not resolve", /* EAI_NONAME */
58 "Service was not recognized for socket type", /* EAI_SERVICE */
59 "Intended socket type was not recognized", /* EAI_SOCKTYPE */
60 "System error returned in errno", /* EAI_SYSTEM */
61 "Invalid value for hints", /* EAI_BADHINTS */
62 "Resolved protocol is unknown", /* EAI_PROTOCOL */
63 "Argument buffer overflow" /* EAI_OVERFLOW */
67 static char gai_buf[NL_TEXTMAX];
68 static once_t gai_init_once = ONCE_INITIALIZER;
69 static thread_key_t gai_key;
70 static int gai_keycreated = 0;
75 gai_keycreated = (thr_keycreate(&gai_key, free) == 0);
80 gai_strerror(int ecode)
89 if (thr_once(&gai_init_once, gai_keycreate) != 0 ||
92 if ((buf = thr_getspecific(gai_key)) == NULL) {
93 if ((buf = malloc(sizeof(gai_buf))) == NULL)
95 if (thr_setspecific(gai_key, buf) != 0) {
102 catd = catopen("libc", NL_CAT_LOCALE);
103 if (ecode > 0 && ecode < EAI_MAX)
104 strlcpy(buf, catgets(catd, 3, ecode, ai_errlist[ecode]),
107 strlcpy(buf, catgets(catd, 3, NL_MSGMAX - 1, "Success"),
110 strlcpy(buf, catgets(catd, 3, NL_MSGMAX, "Unknown error"),
117 if (ecode >= 0 && ecode < EAI_MAX)
118 return ai_errlist[ecode];
119 return "Unknown error";