PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/gai_strerror.c

https://gitlab.com/wilfred/guile
C | 92 lines | 65 code | 10 blank | 17 comment | 4 complexity | 396687399621af2a3415b9f5d47f2767 MD5 | raw file
  1. /* Copyright (C) 1997, 2001-2002, 2004-2006, 2008-2016 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, see <http://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 */