tst-iconv3.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Contributed by Owen Taylor <otaylor@redhat.com>. */
  2. #include <errno.h>
  3. #include <stddef.h>
  4. #include <stdio.h>
  5. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  6. #include <iconv.h>
  7. #endif
  8. #define BUFSIZE 10000
  9. static int
  10. do_test (void)
  11. {
  12. #if defined(__GLIBC__) && !defined(__UCLIBC__)
  13. char inbuf[BUFSIZE];
  14. wchar_t outbuf[BUFSIZE];
  15. iconv_t cd;
  16. int i;
  17. char *inptr;
  18. char *outptr;
  19. size_t inbytes_left, outbytes_left;
  20. int count;
  21. int result = 0;
  22. for (i=0; i < BUFSIZE; i++)
  23. inbuf[i] = 'a';
  24. cd = iconv_open ("UCS-4LE", "UTF-8");
  25. inbytes_left = BUFSIZE;
  26. outbytes_left = BUFSIZE * 4;
  27. inptr = inbuf;
  28. outptr = (char *) outbuf;
  29. count = iconv (cd, &inptr, &inbytes_left, &outptr, &outbytes_left);
  30. if (count < 0)
  31. {
  32. if (errno == E2BIG)
  33. printf ("Received E2BIG\n");
  34. else
  35. printf ("Received something else\n");
  36. printf ("inptr change: %td\n", inptr - inbuf);
  37. printf ("inlen change: %zd\n", BUFSIZE - inbytes_left);
  38. printf ("outptr change: %td\n", outptr - (char *) outbuf);
  39. printf ("outlen change: %zd\n", BUFSIZE * 4 - outbytes_left);
  40. result = 1;
  41. }
  42. else
  43. printf ("Succeeded\n");
  44. return result;
  45. #else
  46. return 23;
  47. #endif
  48. }
  49. #define TEST_FUNCTION do_test ()
  50. #include "../test-skeleton.c"