tst-iconv4.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Derived from BZ #9793
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  5. #include <iconv.h>
  6. #endif
  7. static int
  8. do_test (void)
  9. {
  10. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  11. iconv_t cd = iconv_open ("ASCII//TRANSLIT", "UTF-8");
  12. if (cd == (iconv_t) -1)
  13. {
  14. puts ("iconv_open failed");
  15. return 1;
  16. }
  17. char input[2] = { 0xc2, 0xae }; /* Registered trademark */
  18. char *inptr = input;
  19. size_t insize = sizeof (input);
  20. char output[2]; /* Too short to contain "(R)". */
  21. char *outptr = output;
  22. size_t outsize = sizeof (output);
  23. size_t ret = iconv (cd, &inptr, &insize, &outptr, &outsize);
  24. if (ret != (size_t) -1)
  25. {
  26. puts ("iconv succeeded");
  27. return 1;
  28. }
  29. if (errno != E2BIG)
  30. {
  31. puts ("iconv did not set errno to E2BIG");
  32. return 1;
  33. }
  34. int res = 0;
  35. if (inptr != input)
  36. {
  37. puts ("inptr changed");
  38. res = 1;
  39. }
  40. if (insize != sizeof (input))
  41. {
  42. puts ("insize changed");
  43. res = 1;
  44. }
  45. if (outptr != output)
  46. {
  47. puts ("outptr changed");
  48. res = 1;
  49. }
  50. if (outsize != sizeof (output))
  51. {
  52. puts ("outsize changed");
  53. res = 1;
  54. }
  55. if (iconv_close (cd) == -1)
  56. {
  57. puts ("iconv_close failed");
  58. res = 1;
  59. }
  60. return res;
  61. #else
  62. return 23;
  63. #endif
  64. }
  65. #define TEST_FUNCTION do_test ()
  66. #include "../test-skeleton.c"