From 3384a8d67c2e46701356623fdd0a56f3b0734865 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 3 Apr 2002 05:18:32 +0000 Subject: Update. * libio/bug-ungetwc1.c: New file. * libio/Makefile (tests): Add bug-ungetwc1. * libio/fileops.c (_IO_new_file_close_it): Only call _IO_do_flush if stream was last used for writing. --- ChangeLog | 6 +++++ libio/Makefile | 3 ++- libio/bug-ungetwc1.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libio/fileops.c | 6 ++++- 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 libio/bug-ungetwc1.c diff --git a/ChangeLog b/ChangeLog index ec3ddd4..d7e9df2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2002-04-02 Ulrich Drepper + * libio/bug-ungetwc1.c: New file. + * libio/Makefile (tests): Add bug-ungetwc1. + + * libio/fileops.c (_IO_new_file_close_it): Only call _IO_do_flush + if stream was last used for writing. + * elf/do-lookup.h (do_lookup): 2 is the first user-defined version number [PR libc/3111]. diff --git a/libio/Makefile b/libio/Makefile index af91ef2..fb42da2 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -48,7 +48,8 @@ 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 + tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf \ + bug-ungetwc1 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 new file mode 100644 index 0000000..e1623f4 --- /dev/null +++ b/libio/bug-ungetwc1.c @@ -0,0 +1,74 @@ +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include + +const char write_chars[] = "ABC"; /* Characters on testfile. */ +const wint_t unget_wchar = L'A'; /* Ungotten wide character. */ + +char *fname; + + +static int do_test (void); +#define TEST_FUNCTION do_test () + +#include "../test-skeleton.c" + + +static int +do_test (void) +{ + wint_t wc; + FILE *fp; + int fd; + + fname = (char *) malloc (strlen (test_dir) + sizeof "/bug-ungetwc1.XXXXXX"); + if (fname == NULL) + { + puts ("no memory"); + return 1; + } + strcpy (stpcpy (fname, test_dir), "/bug-ungetwc1.XXXXXX"); + fd = mkstemp (fname); + if (fd == -1) + { + printf ("cannot open temporary file: %m\n"); + return 1; + } + + setlocale(LC_ALL, ""); + + /* Output to the file. */ + if ((fp = fdopen (fd, "w")) == NULL) + { + fprintf (stderr, "Cannot make `%s' file\n", fname); + exit (EXIT_FAILURE); + } + add_temp_file (fname); + + fprintf (fp, "%s", write_chars); + fclose (fp); + + /* Read from the file. */ + fp = fopen (fname, "r"); + + while (!feof (fp)) + wc = getwc (fp); + printf ("\nThe end-of-file indicator is set.\n"); + + /* Unget a wide character. */ + ungetwc (unget_wchar, fp); + printf ("< `%lc' is ungotten.\n", unget_wchar); + + /* Check the end-of-file indicator. */ + if (feof (fp)) + printf ("The end-of-file indicator is still set.\n"); + else + printf ("The end-of-file flag is cleared.\n"); + + fflush (stdout); + fclose (fp); + + return 0; +} diff --git a/libio/fileops.c b/libio/fileops.c index 7144a87..7f833e5 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -161,7 +161,11 @@ _IO_new_file_close_it (fp) if (!_IO_file_is_open (fp)) return EOF; - write_status = _IO_do_flush (fp); + if ((fp->_flags & _IO_NO_WRITES) == 0 + && (fp->_flags & _IO_CURRENTLY_PUTTING) != 0) + write_status = _IO_do_flush (fp); + else + write_status = 0; INTUSE(_IO_unsave_markers) (fp); -- cgit v1.1