gai_strerror.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2001, 02 Motoyuki Kasahara
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * 3. Neither the name of the project nor the names of its contributors
  13. * may be used to endorse or promote products derived from this software
  14. * without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #include "gai_strerror.h"
  29. #ifdef ENABLE_NLS
  30. #include <libintl.h>
  31. #endif
  32. #ifdef ENABLE_NLS
  33. #define _(string) gettext(string)
  34. #ifdef gettext_noop
  35. #define N_(string) gettext_noop(string)
  36. #else
  37. #define N_(string) (string)
  38. #endif
  39. #else
  40. #define gettext(string) (string)
  41. #define _(string) (string)
  42. #define N_(string) (string)
  43. #endif
  44. /*
  45. * Error messages for gai_strerror().
  46. */
  47. static char *eai_errlist[] = {
  48. N_("Success"),
  49. /* EAI_ADDRFAMILY */
  50. N_("Address family for hostname not supported"),
  51. /* EAI_AGAIN */
  52. N_("Temporary failure in name resolution"),
  53. /* EAI_BADFLAGS */
  54. N_("Invalid value for ai_flags"),
  55. /* EAI_FAIL */
  56. N_("Non-recoverable failure in name resolution"),
  57. /* EAI_FAMILY */
  58. N_("ai_family not supported"),
  59. /* EAI_MEMORY */
  60. N_("Memory allocation failure"),
  61. /* EAI_NONAME */
  62. N_("hostname nor servname provided, or not known"),
  63. /* EAI_OVERFLOW */
  64. N_("An argument buffer overflowed"),
  65. /* EAI_SERVICE */
  66. N_("servname not supported for ai_socktype"),
  67. /* EAI_SOCKTYPE */
  68. N_("ai_socktype not supported"),
  69. /* EAI_SYSTEM */
  70. N_("System error returned in errno")
  71. };
  72. /*
  73. * gai_strerror().
  74. */
  75. const char *
  76. gai_strerror(ecode)
  77. int ecode;
  78. {
  79. if (ecode < 0 || ecode > EAI_SYSTEM)
  80. return _("Unknown error");
  81. return gettext(eai_errlist[ecode]);
  82. }