strerror-pr29.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* strerror-pr29.c --- Convert PR29 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 "pr29.h"
  25. #include "gettext.h"
  26. #define _(String) dgettext (PACKAGE, String)
  27. /**
  28. * pr29_strerror:
  29. * @rc: an #Pr29_rc 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. * PR29_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. * PR29_PROBLEM: A problem sequence was encountered.
  38. * PR29_STRINGPREP_ERROR: The character set conversion failed (only
  39. * for pr29_8z()).
  40. *
  41. * Return value: Returns a pointer to a statically allocated string
  42. * containing a description of the error with the return code @rc.
  43. **/
  44. const char *
  45. pr29_strerror (Pr29_rc rc)
  46. {
  47. const char *p;
  48. bindtextdomain (PACKAGE, LOCALEDIR);
  49. switch (rc)
  50. {
  51. case PR29_SUCCESS:
  52. p = _("Success");
  53. break;
  54. case PR29_PROBLEM:
  55. p = _("String not idempotent under Unicode NFKC normalization");
  56. break;
  57. case PR29_STRINGPREP_ERROR:
  58. p = _("String preparation failed");
  59. break;
  60. default:
  61. p = _("Unknown error");
  62. break;
  63. }
  64. return p;
  65. }