Back to index

glibc  2.9
bug-rewind.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <wchar.h>
00003 
00004 #define PASSED  0
00005 #define       FAILED  3
00006 
00007 
00008 static int fd;
00009 
00010 static void prepare (void);
00011 #define PREPARE(argc, argv) prepare ()
00012 
00013 
00014 #define TEST_FUNCTION do_test ()
00015 static int do_test (void);
00016 #include "../test-skeleton.c"
00017 
00018 
00019 static void
00020 prepare (void)
00021 {
00022   fd = create_temp_file ("wrewind.", NULL);
00023   if (fd == -1)
00024     exit (3);
00025 }
00026 
00027 
00028 static int
00029 do_test (void)
00030 {
00031   FILE *fptr;
00032   char arg1;
00033   char arg2;
00034   int ret1, ret2, result, num;
00035 
00036   ret1 = 0;
00037   ret2 = 0;
00038 
00039   fptr = fdopen (fd, "w+");
00040   if (fptr == NULL)
00041     {
00042       printf ("Unable to open file.\n");
00043       return 1;
00044     }
00045 
00046   if (fwprintf (fptr, L"cderf") <= 0)
00047     {
00048       printf ("Unable to write to file with fwprintf().\n");
00049       fclose (fptr);
00050       return 2;
00051     }
00052 
00053   rewind (fptr);
00054   ret1 = fwscanf (fptr, L"%c%c", &arg1, &arg2);
00055 
00056   rewind (fptr);
00057   ret2 = fwscanf (fptr, L"%c%n%c", &arg1, &num, &arg2);
00058 
00059   if (arg2 != 'd')
00060     {
00061       result = FAILED;
00062       printf ("rewind after first fwscanf failed\n");
00063     }
00064   else
00065     {
00066       printf ("Passed\n");
00067       result = PASSED;
00068     }
00069 
00070 
00071   fclose (fptr);
00072   return result;
00073 }