strerror-punycode.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* strerror-punycode.c --- Convert punycode errors into text.
  2. * Copyright (C) 2004, 2005, 2006, 2007, 2008 Simon Josefsson
  3. *
  4. * This file is part of GNU Libidn.
  5. *
  6. * GNU Libidn is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * GNU Libidn is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with GNU Libidn; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  19. *
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. # include "idn_config.h"
  23. #endif
  24. #include "punycode.h"
  25. #include "gettext.h"
  26. #define _(String) dgettext (PACKAGE, String)
  27. /**
  28. * punycode_strerror - return string describing punycode error code
  29. * @rc: an #Punycode_status 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. * PUNYCODE_SUCCESS: Successful operation. This value is guaranteed
  35. * to always be zero, the remaining ones are only guaranteed to hold
  36. * non-zero values, for logical comparison purposes.
  37. * PUNYCODE_BAD_INPUT: Input is invalid.
  38. * PUNYCODE_BIG_OUTPUT: Output would exceed the space provided.
  39. * PUNYCODE_OVERFLOW: Input needs wider integers to process.
  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. punycode_strerror (Punycode_status rc)
  46. {
  47. const char *p;
  48. bindtextdomain (PACKAGE, LOCALEDIR);
  49. switch (rc)
  50. {
  51. case PUNYCODE_SUCCESS:
  52. p = _("Success");
  53. break;
  54. case PUNYCODE_BAD_INPUT:
  55. p = _("Invalid input");
  56. break;
  57. case PUNYCODE_BIG_OUTPUT:
  58. p = _("Output would exceed the buffer space provided");
  59. break;
  60. case PUNYCODE_OVERFLOW:
  61. p = _("String size limit exceeded");
  62. break;
  63. default:
  64. p = _("Unknown error");
  65. break;
  66. }
  67. return p;
  68. }