diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-04-03 09:26:58 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-04-03 09:26:58 +0000 |
commit | 737fa90def1d1cf859bf86222027fc38e3e0879c (patch) | |
tree | e0187079520febad117a68ee23cd36b752500816 | |
parent | a4d62195717c8ddf290e1b3e036af199e65c6827 (diff) | |
download | glibc-737fa90def1d1cf859bf86222027fc38e3e0879c.tar glibc-737fa90def1d1cf859bf86222027fc38e3e0879c.tar.gz glibc-737fa90def1d1cf859bf86222027fc38e3e0879c.tar.bz2 glibc-737fa90def1d1cf859bf86222027fc38e3e0879c.zip |
Update.
* libio/Makefile (tests): Add bug-ungetwc2.
* libio/bug-ungetwc2.c: New file.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | libio/Makefile | 2 | ||||
-rw-r--r-- | libio/bug-ungetwc1.c | 2 | ||||
-rw-r--r-- | libio/bug-ungetwc2.c | 89 |
4 files changed, 94 insertions, 2 deletions
@@ -1,5 +1,8 @@ 2002-04-03 Ulrich Drepper <drepper@redhat.com> + * libio/Makefile (tests): Add bug-ungetwc2. + * libio/bug-ungetwc2.c: New file. + * manual/install.texi: Typographical and grammatical cleanup. Patch by Dennis Grace <dgrace@us.ibm.com>. diff --git a/libio/Makefile b/libio/Makefile index fb42da2c15..b03e4895f7 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -49,7 +49,7 @@ routines := \ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc \ tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf \ - bug-ungetwc1 + bug-ungetwc1 bug-ungetwc2 test-srcs = test-freopen all: # Make this the default target; it will be defined in Rules. diff --git a/libio/bug-ungetwc1.c b/libio/bug-ungetwc1.c index e1623f4efd..8ed6acd175 100644 --- a/libio/bug-ungetwc1.c +++ b/libio/bug-ungetwc1.c @@ -36,6 +36,7 @@ do_test (void) printf ("cannot open temporary file: %m\n"); return 1; } + add_temp_file (fname); setlocale(LC_ALL, ""); @@ -45,7 +46,6 @@ do_test (void) fprintf (stderr, "Cannot make `%s' file\n", fname); exit (EXIT_FAILURE); } - add_temp_file (fname); fprintf (fp, "%s", write_chars); fclose (fp); diff --git a/libio/bug-ungetwc2.c b/libio/bug-ungetwc2.c new file mode 100644 index 0000000000..07fff695af --- /dev/null +++ b/libio/bug-ungetwc2.c @@ -0,0 +1,89 @@ +#define _XOPEN_SOURCE 500 +#include <errno.h> +#include <error.h> +#include <stdio.h> +#include <stdlib.h> +#include <locale.h> +#include <wchar.h> + +const char test_locale[] = "en_US.UTF-8"; +const wchar_t write_wchars[] = {L'A', 0x00C4, L'B', L'\0'}; + /* `0x00C4' is A with diaeresis. */ +size_t last_pos = 2; /* Which character is last one to read. */ +wint_t unget_wchar = L'C'; /* Ungotten ide characters. */ + +char *fname; + + +static int do_test (void); +#define TEST_FUNCTION do_test () + +#include "../test-skeleton.c" + + +static int +do_test (void) +{ + size_t i; + wint_t wc; + FILE *fp; + int fd; + + fname = (char *) malloc (strlen (test_dir) + sizeof "/bug-ungetwc2.XXXXXX"); + if (fname == NULL) + { + puts ("no memory"); + return 1; + } + strcpy (stpcpy (fname, test_dir), "/bug-ungetwc2.XXXXXX"); + fd = mkstemp (fname); + if (fd == -1) + { + printf ("cannot open temporary file: %m\n"); + return 1; + } + add_temp_file (fname); + + printf ("\nNote: This program runs on %s locale.\n\n", test_locale); + + if (setlocale (LC_ALL, test_locale) == NULL) + { + fprintf (stderr, "Cannot use `%s' locale.\n", test_locale); + exit (EXIT_FAILURE); + } + + /* Output to the file. */ + if ((fp = fdopen (fd, "w")) == NULL) + { + fprintf (stderr, "Cannot make `%s' file.\n", fname); + exit (EXIT_FAILURE); + } + fprintf (fp, "%ls", write_wchars); + fclose (fp); + + /* Read from the file. */ + fp = fopen (fname, "r"); + if (fp == NULL) + error (EXIT_FAILURE, errno, "cannot open %s", fname); + + printf ("%s is opened.\n", fname); + + for (i = 0; i < last_pos; i++) + { + wc = getwc (fp); + printf ("> `%lc' is gotten.\n", wc); + } + + /* Unget a wide character. */ + ungetwc (unget_wchar, fp); + printf ("< `%lc' is ungotten.\n", unget_wchar); + + /* Reget the wide character. */ + wc = getwc (fp); + printf ("> `%lc' is regotten.\n", wc); + + fflush (stdout); + fclose (fp); + + return 0; +} |