gai_strerror.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (C) 1997, 2001-2002, 2004-2006, 2008-2023 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 file is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. This file 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, see <https://www.gnu.org/licenses/>. */
  15. #ifndef _LIBC
  16. # include <config.h>
  17. #endif
  18. #include <stdio.h>
  19. #include <netdb.h>
  20. #ifdef _LIBC
  21. # include <libintl.h>
  22. #else
  23. # include "gettext.h"
  24. # define _(String) gettext (String)
  25. # define N_(String) String
  26. #endif
  27. #if HAVE_DECL_GAI_STRERROR
  28. # include <sys/socket.h>
  29. # undef gai_strerror
  30. # if HAVE_DECL_GAI_STRERRORA
  31. # define gai_strerror gai_strerrorA
  32. # endif
  33. const char *
  34. rpl_gai_strerror (int code)
  35. {
  36. return gai_strerror (code);
  37. }
  38. #else /* !HAVE_DECL_GAI_STRERROR */
  39. static struct
  40. {
  41. int code;
  42. const char *msg;
  43. }
  44. values[] =
  45. {
  46. { EAI_ADDRFAMILY, N_("Address family for hostname not supported") },
  47. { EAI_AGAIN, N_("Temporary failure in name resolution") },
  48. { EAI_BADFLAGS, N_("Bad value for ai_flags") },
  49. { EAI_FAIL, N_("Non-recoverable failure in name resolution") },
  50. { EAI_FAMILY, N_("ai_family not supported") },
  51. { EAI_MEMORY, N_("Memory allocation failure") },
  52. { EAI_NODATA, N_("No address associated with hostname") },
  53. { EAI_NONAME, N_("Name or service not known") },
  54. { EAI_SERVICE, N_("Servname not supported for ai_socktype") },
  55. { EAI_SOCKTYPE, N_("ai_socktype not supported") },
  56. { EAI_SYSTEM, N_("System error") },
  57. { EAI_OVERFLOW, N_("Argument buffer too small") },
  58. #ifdef EAI_INPROGRESS
  59. { EAI_INPROGRESS, N_("Processing request in progress") },
  60. { EAI_CANCELED, N_("Request canceled") },
  61. { EAI_NOTCANCELED, N_("Request not canceled") },
  62. { EAI_ALLDONE, N_("All requests done") },
  63. { EAI_INTR, N_("Interrupted by a signal") },
  64. { EAI_IDN_ENCODE, N_("Parameter string not correctly encoded") }
  65. #endif
  66. };
  67. const char *
  68. gai_strerror (int code)
  69. {
  70. size_t i;
  71. for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
  72. if (values[i].code == code)
  73. return _(values[i].msg);
  74. return _("Unknown error");
  75. }
  76. # ifdef _LIBC
  77. libc_hidden_def (gai_strerror)
  78. # endif
  79. #endif /* !HAVE_DECL_GAI_STRERROR */