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

source code of glibc/libio/bug-wfflush.c