Back to index

glibc  2.9
bug-ftell.c
Go to the documentation of this file.
00001 #include <locale.h>
00002 #include <stdio.h>
00003 #include <wchar.h>
00004 #include <sys/types.h>
00005 
00006 
00007 static int
00008 do_test (void)
00009 {
00010   if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
00011     {
00012       puts ("setlocale failed");
00013       return 1;
00014     }
00015 
00016   FILE *fp = tmpfile ();
00017   if (fp == NULL)
00018     {
00019       puts ("tmpfile failed");
00020       return 1;
00021     }
00022 
00023   if (fputws (L"hello", fp) == EOF)
00024     {
00025       puts ("fputws failed");
00026       return 1;
00027     }
00028 
00029   rewind (fp);
00030 
00031   const wchar_t *cp;
00032   unsigned int cnt;
00033   for (cp = L"hello", cnt = 1; *cp != L'\0'; ++cp, ++cnt)
00034     {
00035       wint_t wc = fgetwc (fp);
00036       if (wc != (wint_t) *cp)
00037        {
00038          printf ("fgetwc failed: got L'%lc', expected L'%lc'\n",
00039                 wc, (wint_t) *cp);
00040          return 1;
00041        }
00042       off_t o = ftello (fp);
00043       if (o != cnt)
00044        {
00045          printf ("ftello failed: got %lu, expected %u\n",
00046                 (unsigned long int) o, cnt);
00047          return 1;
00048        }
00049       printf ("round %u OK\n", cnt);
00050     }
00051 
00052   fclose (fp);
00053 
00054   return 0;
00055 }
00056 
00057 #define TEST_FUNCTION do_test ()
00058 #include "../test-skeleton.c"