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

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