PageRenderTime 75ms CodeModel.GetById 39ms RepoModel.GetById 0ms app.codeStats 0ms

/libexplain-1.0.D001/libexplain/buffer/gai_strerror.c

#
C | 101 lines | 75 code | 9 blank | 17 comment | 5 complexity | dc85695c141f48ba8e89d7077ba0b0bd MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. /*
  2. * libexplain - Explain errno values returned by libc functions
  3. * Copyright (C) 2008, 2009 Peter Miller
  4. *
  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
  7. * published by the Free Software Foundation; either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <libexplain/ac/netdb.h>
  19. #include <libexplain/buffer/gai_strerror.h>
  20. #include <libexplain/buffer/strerror.h>
  21. #include <libexplain/option.h>
  22. #include <libexplain/parse_bits.h>
  23. #include <libexplain/sizeof.h>
  24. static const explain_parse_bits_table_t table[] =
  25. {
  26. { "EAI_BADFLAGS", EAI_BADFLAGS },
  27. { "EAI_NONAME", EAI_NONAME },
  28. { "EAI_AGAIN", EAI_AGAIN },
  29. { "EAI_FAIL", EAI_FAIL },
  30. { "EAI_FAMILY", EAI_FAMILY },
  31. { "EAI_SOCKTYPE", EAI_SOCKTYPE },
  32. { "EAI_SERVICE", EAI_SERVICE },
  33. { "EAI_MEMORY", EAI_MEMORY },
  34. { "EAI_SYSTEM", EAI_SYSTEM },
  35. #ifdef EAI_OVERFLOW
  36. { "EAI_OVERFLOW", EAI_OVERFLOW },
  37. #endif
  38. #ifdef EAI_NODATA
  39. { "EAI_NODATA", EAI_NODATA },
  40. #endif
  41. #ifdef EAI_ADDRFAMILY
  42. { "EAI_ADDRFAMILY", EAI_ADDRFAMILY },
  43. #endif
  44. #ifdef EAI_INPROGRESS
  45. { "EAI_INPROGRESS", EAI_INPROGRESS },
  46. #endif
  47. #ifdef EAI_CANCELED
  48. { "EAI_CANCELED", EAI_CANCELED },
  49. #endif
  50. #ifdef EAI_NOTCANCELED
  51. { "EAI_NOTCANCELED", EAI_NOTCANCELED },
  52. #endif
  53. #ifdef EAI_ALLDONE
  54. { "EAI_ALLDONE", EAI_ALLDONE },
  55. #endif
  56. #ifdef EAI_INTR
  57. { "EAI_INTR", EAI_INTR },
  58. #endif
  59. #ifdef EAI_IDN_ENCODE
  60. { "EAI_IDN_ENCODE", EAI_IDN_ENCODE },
  61. #endif
  62. };
  63. void
  64. explain_buffer_gai_strerror(explain_string_buffer_t *sb, int errnum)
  65. {
  66. const explain_parse_bits_table_t *tp;
  67. int first;
  68. if (errnum > 0)
  69. {
  70. explain_buffer_strerror(sb, errnum);
  71. return;
  72. }
  73. explain_string_buffer_puts(sb, gai_strerror(errnum));
  74. first = 1;
  75. if (explain_option_numeric_errno())
  76. {
  77. explain_string_buffer_printf(sb, " (%d", errnum);
  78. first = 0;
  79. }
  80. tp = explain_parse_bits_find_by_value(errnum, table, SIZEOF(table));
  81. if (tp)
  82. {
  83. if (first)
  84. explain_string_buffer_puts(sb, " (");
  85. else
  86. explain_string_buffer_puts(sb, ", ");
  87. explain_string_buffer_puts(sb, tp->name);
  88. first = 0;
  89. }
  90. if (!first)
  91. explain_string_buffer_putc(sb, ')');
  92. }