tst-iconv2.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (C) 2001-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <stddef.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  21. #include <iconv.h>
  22. #endif
  23. static int
  24. do_test (void)
  25. {
  26. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  27. char buf[3];
  28. const wchar_t wc[1] = L"a";
  29. iconv_t cd;
  30. char *inptr;
  31. size_t inlen;
  32. char *outptr;
  33. size_t outlen;
  34. size_t n;
  35. int e;
  36. int result = 0;
  37. cd = iconv_open ("UCS4", "WCHAR_T");
  38. if (cd == (iconv_t) -1)
  39. {
  40. printf ("cannot convert from wchar_t to UCS4: %m\n");
  41. exit (1);
  42. }
  43. inptr = (char *) wc;
  44. inlen = sizeof (wchar_t);
  45. outptr = buf;
  46. outlen = 3;
  47. n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
  48. e = errno;
  49. if (n != (size_t) -1)
  50. {
  51. printf ("incorrect iconv() return value: %zd, expected -1\n", n);
  52. result = 1;
  53. }
  54. if (e != E2BIG)
  55. {
  56. printf ("incorrect error value: %s, expected %s\n",
  57. strerror (e), strerror (E2BIG));
  58. result = 1;
  59. }
  60. if (inptr != (char *) wc)
  61. {
  62. puts ("inptr changed");
  63. result = 1;
  64. }
  65. if (inlen != sizeof (wchar_t))
  66. {
  67. puts ("inlen changed");
  68. result = 1;
  69. }
  70. if (outptr != buf)
  71. {
  72. puts ("outptr changed");
  73. result = 1;
  74. }
  75. if (outlen != 3)
  76. {
  77. puts ("outlen changed");
  78. result = 1;
  79. }
  80. iconv_close (cd);
  81. return result;
  82. #else
  83. return 23;
  84. #endif
  85. }
  86. #define TEST_FUNCTION do_test ()
  87. #include "../test-skeleton.c"