]> git.ipfire.org Git - thirdparty/glibc.git/blob - libio/bug-wfflush.c
benchtests: Add random() benchmark
[thirdparty/glibc.git] / libio / bug-wfflush.c
1 /* Test program for bug in wide streams. */
2
3 #include <stdio.h>
4 #include <wchar.h>
5
6 #include <support/xunistd.h>
7
8 static void do_prepare (void);
9 #define PREPARE(argc, argv) do_prepare ()
10 static int do_test (void);
11 #define TEST_FUNCTION do_test ()
12 #include <test-skeleton.c>
13
14 static char *temp_file;
15
16 static void
17 do_prepare (void)
18 {
19 int fd = create_temp_file ("bug-ungetc.", &temp_file);
20 if (fd == -1)
21 {
22 printf ("cannot create temporary file: %m\n");
23 exit (1);
24 }
25 xwrite (fd, "1!", 2);
26 close (fd);
27 }
28
29 static int
30 do_test (void)
31 {
32 FILE *f = fopen (temp_file, "r+");
33
34 if (f == NULL)
35 {
36 printf ("fopen: %m\n");
37 return 1;
38 }
39
40 #define L_(s) L##s
41 //#define fwscanf fscanf
42 //#define fwprintf fprintf
43
44 int i;
45 if (fwscanf (f, L_("%d!"), &i) != 1)
46 {
47 printf ("fwscanf failed\n");
48 return 1;
49 }
50
51 rewind (f);
52 if (ferror (f))
53 {
54 printf ("rewind: %m\n");
55 return 1;
56 }
57
58 if (fputws (L_("1!"), f) == EOF)
59 {
60 printf ("fputws: %m\n");
61 return 1;
62 }
63
64 if (fflush (f) != 0)
65 {
66 printf ("fflush: %m\n");
67 return 1;
68 }
69
70 if (fclose (f) != 0)
71 {
72 printf ("fclose: %m\n");
73 return 1;
74 }
75
76 puts ("Test succeeded.");
77 return 0;
78 }