strerror-tld.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* strerror-tld.c --- Convert TLD errors into text.
  2. Copyright (C) 2004-2024 Simon Josefsson
  3. This file is part of GNU Libidn.
  4. GNU Libidn is free software: you can redistribute it and/or
  5. modify it under the terms of either:
  6. * the GNU Lesser General Public License as published by the Free
  7. Software Foundation; either version 3 of the License, or (at
  8. your option) any later version.
  9. or
  10. * the GNU General Public License as published by the Free
  11. Software Foundation; either version 2 of the License, or (at
  12. your option) any later version.
  13. or both in parallel, as here.
  14. GNU Libidn is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. General Public License for more details.
  18. You should have received copies of the GNU General Public License and
  19. the GNU Lesser General Public License along with this program. If
  20. not, see <https://www.gnu.org/licenses/>. */
  21. #ifdef HAVE_CONFIG_H
  22. # include "config.h"
  23. #endif
  24. #include "tld.h"
  25. #include "gettext.h"
  26. #define _(String) dgettext (PACKAGE, String)
  27. /**
  28. * tld_strerror:
  29. * @rc: tld return code
  30. *
  31. * Convert a return code integer to a text string. This string can be
  32. * used to output a diagnostic message to the user.
  33. *
  34. * TLD_SUCCESS: Successful operation. This value is guaranteed to
  35. * always be zero, the remaining ones are only guaranteed to hold
  36. * non-zero values, for logical comparison purposes.
  37. * TLD_INVALID: Invalid character found.
  38. * TLD_NODATA: No input data was provided.
  39. * TLD_MALLOC_ERROR: Error during memory allocation.
  40. * TLD_ICONV_ERROR: Character encoding conversion error.
  41. * TLD_NO_TLD: No top-level domain found in domain string.
  42. *
  43. * Return value: Returns a pointer to a statically allocated string
  44. * containing a description of the error with the return code @rc.
  45. **/
  46. const char *
  47. tld_strerror (Tld_rc rc)
  48. {
  49. const char *p;
  50. bindtextdomain (PACKAGE, LOCALEDIR);
  51. switch (rc)
  52. {
  53. case TLD_SUCCESS:
  54. p = _("Success");
  55. break;
  56. case TLD_INVALID:
  57. p = _("Code points prohibited by top-level domain");
  58. break;
  59. case TLD_NODATA:
  60. p = _("Missing input");
  61. break;
  62. case TLD_MALLOC_ERROR:
  63. p = _("Cannot allocate memory");
  64. break;
  65. case TLD_ICONV_ERROR:
  66. p = _("Character encoding conversion error");
  67. break;
  68. case TLD_NO_TLD:
  69. p = _("No top-level domain found in input");
  70. break;
  71. default:
  72. p = _("Unknown error");
  73. break;
  74. }
  75. return p;
  76. }