Fix typos.
[platform/upstream/glibc.git] / libio / bug-rewind.c
1 #include <stdio.h>
2 #include <wchar.h>
3
4 #define PASSED  0
5 #define FAILED  3
6
7
8 static int fd;
9
10 static void prepare (void);
11 #define PREPARE(argc, argv) prepare ()
12
13
14 #define TEST_FUNCTION do_test ()
15 static int do_test (void);
16 #include "../test-skeleton.c"
17
18
19 static void
20 prepare (void)
21 {
22   fd = create_temp_file ("wrewind.", NULL);
23   if (fd == -1)
24     exit (3);
25 }
26
27
28 static int
29 do_test (void)
30 {
31   FILE *fptr;
32   char arg1;
33   char arg2;
34   int ret1, ret2, result, num;
35
36   ret1 = 0;
37   ret2 = 0;
38
39   fptr = fdopen (fd, "w+");
40   if (fptr == NULL)
41     {
42       printf ("Unable to open file.\n");
43       return 1;
44     }
45
46   if (fwprintf (fptr, L"cderf") <= 0)
47     {
48       printf ("Unable to write to file with fwprintf().\n");
49       fclose (fptr);
50       return 2;
51     }
52
53   rewind (fptr);
54   ret1 = fwscanf (fptr, L"%c%c", &arg1, &arg2);
55
56   rewind (fptr);
57   ret2 = fwscanf (fptr, L"%c%n%c", &arg1, &num, &arg2);
58
59   if (arg2 != 'd')
60     {
61       result = FAILED;
62       printf ("rewind after first fwscanf failed\n");
63     }
64   else
65     {
66       printf ("Passed\n");
67       result = PASSED;
68     }
69
70
71   fclose (fptr);
72   return result;
73 }