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