1 #define _XOPEN_SOURCE 500
9 const char test_locale
[] = "de_DE.UTF-8";
10 const wchar_t write_wchars
[] = {L
'A', 0x00C4, L
'B', L
'\0'};
11 /* `0x00C4' is A with diaeresis. */
12 size_t last_pos
= 2; /* Which character is last one to read. */
13 wint_t unget_wchar
= L
'C'; /* Ungotten ide characters. */
18 static int do_test (void);
19 #define TEST_FUNCTION do_test ()
21 #include "../test-skeleton.c"
32 fname
= (char *) malloc (strlen (test_dir
) + sizeof "/bug-ungetwc2.XXXXXX");
38 strcpy (stpcpy (fname
, test_dir
), "/bug-ungetwc2.XXXXXX");
42 printf ("cannot open temporary file: %m\n");
45 add_temp_file (fname
);
47 printf ("\nNote: This program runs on %s locale.\n\n", test_locale
);
49 if (setlocale (LC_ALL
, test_locale
) == NULL
)
51 fprintf (stderr
, "Cannot use `%s' locale.\n", test_locale
);
55 /* Output to the file. */
56 if ((fp
= fdopen (fd
, "w")) == NULL
)
58 setlocale (LC_ALL
, "C");
59 fprintf (stderr
, "Cannot make `%s' file.\n", fname
);
62 fprintf (fp
, "%ls", write_wchars
);
65 /* Read from the file. */
66 fp
= fopen (fname
, "r");
69 setlocale (LC_ALL
, "C");
70 error (EXIT_FAILURE
, errno
, "cannot open %s", fname
);
73 printf ("%s is opened.\n", fname
);
75 for (i
= 0; i
< last_pos
; i
++)
78 printf ("> `%lc' is gotten.\n", wc
);
81 /* Unget a wide character. */
82 ungetwc (unget_wchar
, fp
);
83 printf ("< `%lc' is ungotten.\n", unget_wchar
);
85 /* Reget the wide character. */
87 printf ("> `%lc' is regotten.\n", wc
);