about summary refs log tree commit diff
path: root/libio/tst-ungetwc2.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-08-09 08:50:50 +0000
committerUlrich Drepper <drepper@redhat.com>2001-08-09 08:50:50 +0000
commit40a982a9e1b825b175be7bc7c7199c6bdf363e4b (patch)
tree7523a21da3e35bed6e56133efbe1d16dadb6e6da /libio/tst-ungetwc2.c
parent0f78390bd799fc0b0394240a9a704591481ac8c6 (diff)
downloadglibc-40a982a9e1b825b175be7bc7c7199c6bdf363e4b.tar.gz
glibc-40a982a9e1b825b175be7bc7c7199c6bdf363e4b.tar.xz
glibc-40a982a9e1b825b175be7bc7c7199c6bdf363e4b.zip
Update.
2001-08-09  Ulrich Drepper  <drepper@redhat.com>

	* libio/wfileops.c (_IO_wfile_seekoff): Don't even try to handle
	seeking with backup buffer present.
	Correct determining of internal buffer position.
	Reset also wide buffers if we reset the internal buffers.
	* libio/iofwide.c (_IO_fwide): Always determine file offset for wide
	streams.
	* libio/ioseekoff.c: Catch one unimplemented case.
	* libio/ftello.c: Don't abort if the wide stream has backup buffer.
	* libio/ftello64.c: Likewise.
	* libio/iofgetpos.c: Likewise.
	* libio/iofgetpos64.c: Likewise.
	* libio/ftell.c: Likewise.
	* libio/Makefile (tests): Add tst-ungetwc2.
	* libio/tst-ungetwc2.c: New file.
Diffstat (limited to 'libio/tst-ungetwc2.c')
-rw-r--r--libio/tst-ungetwc2.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/libio/tst-ungetwc2.c b/libio/tst-ungetwc2.c
new file mode 100644
index 0000000000..9064427532
--- /dev/null
+++ b/libio/tst-ungetwc2.c
@@ -0,0 +1,81 @@
+/* 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>
+
+int
+main (void)
+{
+  FILE *fp;
+  char *str = "abcdef";
+  wint_t ret, wc;
+  char fname[] = "/tmp/tst-ungetwc2.out.XXXXXX";
+  int fd;
+  long int pos;
+  int result = 0;
+
+  puts ("This program runs on en_US.UTF-8 locale.");
+  if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
+    {
+      fprintf (stderr, "Err: Cannot run on the en_US.UTF-8 locale\n");
+      exit (EXIT_FAILURE);
+    }
+
+  /* Write some characters to `testfile'. */
+  fd = mkstemp (fname);
+  if (fd == -1)
+    {
+      printf ("cannot open temp file: %m\n");
+      exit (EXIT_FAILURE);
+    }
+  if ((fp = fdopen (fd, "w")) == NULL)
+    {
+      fprintf (stderr, "Cannot open 'testfile'.\n");
+      exit (EXIT_FAILURE);
+    }
+  fputs (str, fp);
+  fclose (fp);
+
+  /* Open `testfile'. */
+  if ((fp = fopen (fname, "r")) == NULL)
+    {
+      fprintf (stderr, "Cannot open 'testfile'.");
+      exit (EXIT_FAILURE);
+    }
+
+  /* Get a character. */
+  wc = getwc (fp);
+  pos = ftell (fp);
+  printf ("After get a character: %ld\n", pos);
+  if (pos != 1)
+    result = 1;
+
+  /* Unget a character. */
+  ret = ungetwc (wc, fp);
+  if (ret == WEOF)
+    {
+      fprintf (stderr, "ungetwc() returns NULL.");
+      exit (EXIT_FAILURE);
+    }
+  pos = ftell (fp);
+  printf ("After unget a character: %ld\n", pos);
+  if (pos != 0)
+    result = 1;
+
+  /* Reget a character. */
+  wc = getwc (fp);
+  pos = ftell (fp);
+  printf ("After reget a character: %ld\n", pos);
+  if (pos != 1)
+    result = 1;
+
+  fclose (fp);
+
+  unlink (fname);
+
+  return result;
+}