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