repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / tests / system / libroot / posix / tst-ungetwc1.c
blob39f08ed255199d6be693d8570b02dbf1f8cda7b1
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>
11 int
12 main(void)
14 FILE *fp;
15 const char *str = "abcdef";
16 wint_t ret, wc, ungetone = 0x00E4; /* 0x00E4 means `a umlaut'. */
17 char fname[] = "/tmp/tst-ungetwc1.out.XXXXXX";
18 int fd;
19 int result = 0;
21 puts("This program runs on de_DE.UTF-8 locale.");
22 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) {
29 printf("cannot open temp file: %m\n");
30 exit(EXIT_FAILURE);
33 /* Write some characters to `testfile'. */
34 if ((fp = fdopen(fd, "w")) == NULL) {
35 fprintf(stderr, "Cannot open 'testfile'.");
36 exit(EXIT_FAILURE);
38 fputs(str, fp);
39 fclose(fp);
41 /* Open `testfile'. */
42 if ((fp = fopen(fname, "r")) == NULL) {
43 fprintf(stderr, "Cannot open 'testfile'.");
44 exit(EXIT_FAILURE);
47 /* Unget a character. */
48 ret = ungetwc(ungetone, fp);
49 printf("Unget a character (0x%04x)\n", (unsigned int) ungetone);
50 fflush(stdout);
51 if (ret == WEOF) {
52 puts("ungetwc() returns NULL.");
53 exit(EXIT_SUCCESS);
56 /* Reget a character. */
57 wc = getwc(fp);
58 printf("Reget a character (0x%04x)\n", (unsigned int) wc);
59 fflush(stdout);
60 if (wc == ungetone) {
61 puts("The ungotten character is equal to the regotten character.");
62 fflush(stdout);
63 } else {
64 puts("The ungotten character is not equal to the regotten character.");
65 printf("ungotten one: %04x, regetone: %04x", ungetone, wc);
66 fflush(stdout);
67 result = 1;
69 fclose(fp);
71 unlink(fname);
73 return result;