2003-09-17 Uwe Reimann <Uwe_Reimann@gmx.net> Hans-Peter Nilsson <hp@axis.com>
[glibc.git] / libio / bug-ftell.c
blob7eb0f46810e196e44826ce8e914dfd4a10f6552c
1 #include <locale.h>
2 #include <stdio.h>
3 #include <wchar.h>
4 #include <sys/types.h>
7 static int
8 do_test (void)
10 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
12 puts ("setlocale failed");
13 return 1;
16 FILE *fp = tmpfile ();
17 if (fp == NULL)
19 puts ("tmpfile failed");
20 return 1;
23 if (fputws (L"hello", fp) == EOF)
25 puts ("fputws failed");
26 return 1;
29 rewind (fp);
31 const wchar_t *cp;
32 unsigned int cnt;
33 for (cp = L"hello", cnt = 1; *cp != L'\0'; ++cp, ++cnt)
35 wint_t wc = fgetwc (fp);
36 if (wc != (wint_t) *cp)
38 printf ("fgetwc failed: got L'%lc', expected L'%lc'\n", wc, *cp);
39 return 1;
41 off_t o = ftello (fp);
42 if (o != cnt)
44 printf ("ftello failed: got %lu, expected %u\n",
45 (unsigned long int) o, cnt);
46 return 1;
48 printf ("round %u OK\n", cnt);
51 fclose (fp);
53 return 0;
56 #define TEST_FUNCTION do_test ()
57 #include "../test-skeleton.c"