about summary refs log tree commit diff
path: root/libio/bug-ungetwc1.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-04-03 05:18:32 +0000
committerUlrich Drepper <drepper@redhat.com>2002-04-03 05:18:32 +0000
commit3384a8d67c2e46701356623fdd0a56f3b0734865 (patch)
tree67e6fbd5212fb840120798e8a861ce4f75907074 /libio/bug-ungetwc1.c
parent7a73a7e685a784b8f7014516a3c968ac74d6d3eb (diff)
downloadglibc-3384a8d67c2e46701356623fdd0a56f3b0734865.tar.gz
glibc-3384a8d67c2e46701356623fdd0a56f3b0734865.tar.xz
glibc-3384a8d67c2e46701356623fdd0a56f3b0734865.zip
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.
Diffstat (limited to 'libio/bug-ungetwc1.c')
-rw-r--r--libio/bug-ungetwc1.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/libio/bug-ungetwc1.c b/libio/bug-ungetwc1.c
new file mode 100644
index 0000000000..e1623f4efd
--- /dev/null
+++ b/libio/bug-ungetwc1.c
@@ -0,0 +1,74 @@
+#define _XOPEN_SOURCE 500
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <wchar.h>
+
+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;
+}