Use INTERNAL_SYSCALL.
[glibc.git] / libio / tst-ungetwc1.c
blobf74c4078933da83245ded89d9cdb8910805b3cad
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 int
11 main (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;