diff options
author | Zack Weinberg <zackw@panix.com> | 2017-06-08 15:39:03 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-06-08 15:39:03 -0400 |
commit | 5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch) | |
tree | 4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/libio/tst-ungetwc1.c | |
parent | 199fc19d3aaaf57944ef036e15904febe877fc93 (diff) | |
download | glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.gz glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.xz glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.zip |
Prepare for radical source tree reorganization. zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage directory, REORG.TODO, except for files that will certainly still exist in their current form at top level when we're done (COPYING, COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which are moved to the new directory OldChangeLogs, instead), and the generated file INSTALL (which is just deleted; in the new order, there will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/libio/tst-ungetwc1.c')
-rw-r--r-- | REORG.TODO/libio/tst-ungetwc1.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/REORG.TODO/libio/tst-ungetwc1.c b/REORG.TODO/libio/tst-ungetwc1.c new file mode 100644 index 0000000000..f71b39059f --- /dev/null +++ b/REORG.TODO/libio/tst-ungetwc1.c @@ -0,0 +1,84 @@ +/* Taken from the Li18nux base test suite. */ + +#define _XOPEN_SOURCE 500 +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <wchar.h> + +static int +do_test (void) +{ + FILE *fp; + const char *str = "abcdef"; + wint_t ret, wc, ungetone = 0x00E4; /* 0x00E4 means `a umlaut'. */ + char fname[] = "/tmp/tst-ungetwc1.out.XXXXXX"; + int fd; + int result = 0; + + puts ("This program runs on de_DE.UTF-8 locale."); + if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL) + { + fprintf (stderr, "Err: Cannot run on the de_DE.UTF-8 locale"); + exit (EXIT_FAILURE); + } + + fd = mkstemp (fname); + if (fd == -1) + { + printf ("cannot open temp file: %m\n"); + exit (EXIT_FAILURE); + } + + /* Write some characters to `testfile'. */ + if ((fp = fdopen (fd, "w")) == NULL) + { + fprintf (stderr, "Cannot open 'testfile'."); + exit (EXIT_FAILURE); + } + fputs (str, fp); + fclose (fp); + + /* Open `testfile'. */ + if ((fp = fopen (fname, "r")) == NULL) + { + fprintf (stderr, "Cannot open 'testfile'."); + exit (EXIT_FAILURE); + } + + /* Unget a character. */ + ret = ungetwc (ungetone, fp); + printf ("Unget a character (0x%04x)\n", (unsigned int) ungetone); + fflush (stdout); + if (ret == WEOF) + { + puts ("ungetwc() returns NULL."); + exit (EXIT_SUCCESS); + } + + /* Reget a character. */ + wc = getwc (fp); + printf ("Reget a character (0x%04x)\n", (unsigned int) wc); + fflush (stdout); + if (wc == ungetone) + { + puts ("The ungotten character is equal to the regotten character."); + fflush (stdout); + } + else + { + puts ("The ungotten character is not equal to the regotten character."); + printf ("ungotten one: %04x, regetone: %04x", ungetone, wc); + fflush (stdout); + result = 1; + } + fclose (fp); + + unlink (fname); + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |