(root)/
glibc-2.38/
libio/
bug-wsetpos.c
       1  /* Test program for fsetpos on a wide character stream.  */
       2  
       3  #include <assert.h>
       4  #include <stdio.h>
       5  #include <wchar.h>
       6  
       7  #include <support/xunistd.h>
       8  
       9  static void do_prepare (void);
      10  #define PREPARE(argc, argv) do_prepare ()
      11  static int do_test (void);
      12  #define TEST_FUNCTION do_test ()
      13  #include <test-skeleton.c>
      14  
      15  static const char pattern[] = "12345";
      16  static char *temp_file;
      17  
      18  static void
      19  do_prepare (void)
      20  {
      21    int fd = create_temp_file ("bug-wsetpos.", &temp_file);
      22    if (fd == -1)
      23      {
      24        printf ("cannot create temporary file: %m\n");
      25        exit (1);
      26      }
      27    xwrite (fd, pattern, sizeof (pattern));
      28    close (fd);
      29  }
      30  
      31  static int
      32  do_test (void)
      33  {
      34    FILE *fp = fopen (temp_file, "r");
      35    fpos_t pos;
      36    wchar_t c;
      37  
      38    if (fp == NULL)
      39      {
      40        printf ("fdopen: %m\n");
      41        return 1;
      42      }
      43  
      44    c = fgetwc (fp); assert (c == L'1');
      45    c = fgetwc (fp); assert (c == L'2');
      46  
      47    if (fgetpos (fp, &pos) == EOF)
      48      {
      49        printf ("fgetpos: %m\n");
      50        return 1;
      51      }
      52  
      53    rewind (fp);
      54    if (ferror (fp))
      55      {
      56        printf ("rewind: %m\n");
      57        return 1;
      58      }
      59  
      60    c = fgetwc (fp); assert (c == L'1');
      61  
      62    if (fsetpos (fp, &pos) == EOF)
      63      {
      64        printf ("fsetpos: %m\n");
      65        return 1;
      66      }
      67  
      68    c = fgetwc (fp);
      69    if (c != L'3')
      70      {
      71        puts ("fsetpos failed");
      72        return 1;
      73      }
      74  
      75    puts ("Test succeeded.");
      76    return 0;
      77  }