Consolidate non cancellable read call
[glibc.git] / libio / tst-ungetwc1.c
blobf71b39059f43dd8507901ee67b87cf5aca6d96e4
1 /* Taken from the Li18nux base test suite. */
3 #define _XOPEN_SOURCE 500
4 #include <locale.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <wchar.h>
10 static int
11 do_test (void)
13 FILE *fp;
14 const char *str = "abcdef";
15 wint_t ret, wc, ungetone = 0x00E4; /* 0x00E4 means `a umlaut'. */
16 char fname[] = "/tmp/tst-ungetwc1.out.XXXXXX";
17 int fd;
18 int result = 0;
20 puts ("This program runs on de_DE.UTF-8 locale.");
21 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
23 fprintf (stderr, "Err: Cannot run on the de_DE.UTF-8 locale");
24 exit (EXIT_FAILURE);
27 fd = mkstemp (fname);
28 if (fd == -1)
30 printf ("cannot open temp file: %m\n");
31 exit (EXIT_FAILURE);
34 /* Write some characters to `testfile'. */
35 if ((fp = fdopen (fd, "w")) == NULL)
37 fprintf (stderr, "Cannot open 'testfile'.");
38 exit (EXIT_FAILURE);
40 fputs (str, fp);
41 fclose (fp);
43 /* Open `testfile'. */
44 if ((fp = fopen (fname, "r")) == NULL)
46 fprintf (stderr, "Cannot open 'testfile'.");
47 exit (EXIT_FAILURE);
50 /* Unget a character. */
51 ret = ungetwc (ungetone, fp);
52 printf ("Unget a character (0x%04x)\n", (unsigned int) ungetone);
53 fflush (stdout);
54 if (ret == WEOF)
56 puts ("ungetwc() returns NULL.");
57 exit (EXIT_SUCCESS);
60 /* Reget a character. */
61 wc = getwc (fp);
62 printf ("Reget a character (0x%04x)\n", (unsigned int) wc);
63 fflush (stdout);
64 if (wc == ungetone)
66 puts ("The ungotten character is equal to the regotten character.");
67 fflush (stdout);
69 else
71 puts ("The ungotten character is not equal to the regotten character.");
72 printf ("ungotten one: %04x, regetone: %04x", ungetone, wc);
73 fflush (stdout);
74 result = 1;
76 fclose (fp);
78 unlink (fname);
80 return result;
83 #define TEST_FUNCTION do_test ()
84 #include "../test-skeleton.c"