bug-ftell.c 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <wchar.h>
  4. #include <sys/types.h>
  5. static int
  6. do_test (void)
  7. {
  8. if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
  9. {
  10. puts ("setlocale failed");
  11. return 1;
  12. }
  13. FILE *fp = tmpfile ();
  14. if (fp == NULL)
  15. {
  16. puts ("tmpfile failed");
  17. return 1;
  18. }
  19. if (fputws (L"hello", fp) == EOF)
  20. {
  21. puts ("fputws failed");
  22. return 1;
  23. }
  24. rewind (fp);
  25. const wchar_t *cp;
  26. unsigned int cnt;
  27. for (cp = L"hello", cnt = 1; *cp != L'\0'; ++cp, ++cnt)
  28. {
  29. wint_t wc = fgetwc (fp);
  30. if (wc != (wint_t) *cp)
  31. {
  32. printf ("fgetwc failed: got L'%lc', expected L'%lc'\n",
  33. wc, (wint_t) *cp);
  34. return 1;
  35. }
  36. off_t o = ftello (fp);
  37. if (o != cnt)
  38. {
  39. printf ("ftello failed: got %lu, expected %u\n",
  40. (unsigned long int) o, cnt);
  41. return 1;
  42. }
  43. printf ("round %u OK\n", cnt);
  44. }
  45. fclose (fp);
  46. return 0;
  47. }
  48. #define TEST_FUNCTION do_test ()
  49. #include "../test-skeleton.c"