gai_strerror.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008, 2009, 2010 Free
  2. Software 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. static struct
  29. {
  30. int code;
  31. const char *msg;
  32. }
  33. values[] =
  34. {
  35. { EAI_ADDRFAMILY, N_("Address family for hostname not supported") },
  36. { EAI_AGAIN, N_("Temporary failure in name resolution") },
  37. { EAI_BADFLAGS, N_("Bad value for ai_flags") },
  38. { EAI_FAIL, N_("Non-recoverable failure in name resolution") },
  39. { EAI_FAMILY, N_("ai_family not supported") },
  40. { EAI_MEMORY, N_("Memory allocation failure") },
  41. { EAI_NODATA, N_("No address associated with hostname") },
  42. { EAI_NONAME, N_("Name or service not known") },
  43. { EAI_SERVICE, N_("Servname not supported for ai_socktype") },
  44. { EAI_SOCKTYPE, N_("ai_socktype not supported") },
  45. { EAI_SYSTEM, N_("System error") },
  46. { EAI_OVERFLOW, N_("Argument buffer too small") },
  47. #ifdef EAI_INPROGRESS
  48. { EAI_INPROGRESS, N_("Processing request in progress") },
  49. { EAI_CANCELED, N_("Request canceled") },
  50. { EAI_NOTCANCELED, N_("Request not canceled") },
  51. { EAI_ALLDONE, N_("All requests done") },
  52. { EAI_INTR, N_("Interrupted by a signal") },
  53. { EAI_IDN_ENCODE, N_("Parameter string not correctly encoded") }
  54. #endif
  55. };
  56. const char *
  57. gai_strerror (int code)
  58. {
  59. size_t i;
  60. for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
  61. if (values[i].code == code)
  62. return _(values[i].msg);
  63. return _("Unknown error");
  64. }
  65. #ifdef _LIBC
  66. libc_hidden_def (gai_strerror)
  67. #endif