Back to index

glibc  2.9
bug-rewind2.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <wchar.h>
00003 
00004 
00005 static int fd;
00006 
00007 static void prepare (void);
00008 #define PREPARE(argc, argv) prepare ()
00009 
00010 
00011 #define TEST_FUNCTION do_test ()
00012 static int do_test (void);
00013 #include "../test-skeleton.c"
00014 
00015 
00016 static void
00017 prepare (void)
00018 {
00019   fd = create_temp_file ("wrewind2.", NULL);
00020   if (fd == -1)
00021     exit (3);
00022 }
00023 
00024 
00025 static int
00026 do_test (void)
00027 {
00028   wchar_t dummy[10];
00029   int ret = 0;
00030   FILE *fp;
00031   int result = 0;
00032 
00033   fp = fdopen (fd, "w+");
00034   if (fp == NULL)
00035     {
00036       puts ("fopen(""testfile"", ""w+"") returned NULL.");
00037       return 1;
00038     }
00039   else
00040     {
00041       fwprintf (fp, L"abcd");
00042       printf ("current pos = %ld\n", ftell (fp));
00043       if (ftell (fp) != 4)
00044        result = 1;
00045 
00046       rewind (fp);
00047       ret = fwscanf (fp, L"%c", dummy);
00048 
00049       printf ("current pos = %ld\n", ftell (fp));
00050       if (ftell (fp) != 1)
00051        result = 1;
00052 
00053       rewind (fp);
00054       printf ("current pos = %ld\n", ftell (fp));
00055       if (ftell (fp) != 0)
00056        result = 1;
00057 
00058       fclose (fp);
00059     }
00060 
00061   return result;
00062 }