gai_strerror.c 2.8 KB

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