gai_strerror.c 2.4 KB

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