| 1 | /* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008, 2009, 2010 Free |
| 2 | Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU Lesser General Public License as published by |
| 8 | the Free Software Foundation; either version 2, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public License |
| 17 | along with this program; if not, write to the Free Software Foundation, |
| 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
| 19 | |
| 20 | #ifndef _LIBC |
| 21 | # include <config.h> |
| 22 | #endif |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <netdb.h> |
| 26 | |
| 27 | #ifdef _LIBC |
| 28 | # include <libintl.h> |
| 29 | #else |
| 30 | # include "gettext.h" |
| 31 | # define _(String) gettext (String) |
| 32 | # define N_(String) String |
| 33 | #endif |
| 34 | |
| 35 | static struct |
| 36 | { |
| 37 | int code; |
| 38 | const char *msg; |
| 39 | } |
| 40 | values[] = |
| 41 | { |
| 42 | { EAI_ADDRFAMILY, N_("Address family for hostname not supported") }, |
| 43 | { EAI_AGAIN, N_("Temporary failure in name resolution") }, |
| 44 | { EAI_BADFLAGS, N_("Bad value for ai_flags") }, |
| 45 | { EAI_FAIL, N_("Non-recoverable failure in name resolution") }, |
| 46 | { EAI_FAMILY, N_("ai_family not supported") }, |
| 47 | { EAI_MEMORY, N_("Memory allocation failure") }, |
| 48 | { EAI_NODATA, N_("No address associated with hostname") }, |
| 49 | { EAI_NONAME, N_("Name or service not known") }, |
| 50 | { EAI_SERVICE, N_("Servname not supported for ai_socktype") }, |
| 51 | { EAI_SOCKTYPE, N_("ai_socktype not supported") }, |
| 52 | { EAI_SYSTEM, N_("System error") }, |
| 53 | { EAI_OVERFLOW, N_("Argument buffer too small") }, |
| 54 | #ifdef EAI_INPROGRESS |
| 55 | { EAI_INPROGRESS, N_("Processing request in progress") }, |
| 56 | { EAI_CANCELED, N_("Request canceled") }, |
| 57 | { EAI_NOTCANCELED, N_("Request not canceled") }, |
| 58 | { EAI_ALLDONE, N_("All requests done") }, |
| 59 | { EAI_INTR, N_("Interrupted by a signal") }, |
| 60 | { EAI_IDN_ENCODE, N_("Parameter string not correctly encoded") } |
| 61 | #endif |
| 62 | }; |
| 63 | |
| 64 | const char * |
| 65 | gai_strerror (int code) |
| 66 | { |
| 67 | size_t i; |
| 68 | for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i) |
| 69 | if (values[i].code == code) |
| 70 | return _(values[i].msg); |
| 71 | |
| 72 | return _("Unknown error"); |
| 73 | } |
| 74 | #ifdef _LIBC |
| 75 | libc_hidden_def (gai_strerror) |
| 76 | #endif |