about summary refs log tree commit diff
path: root/libio/tst-ungetwc1.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-08-09 02:01:10 +0000
committerUlrich Drepper <drepper@redhat.com>2001-08-09 02:01:10 +0000
commit8f739934b026cd0c298e3196d38d483eb1f88bed (patch)
tree41ecaffbbe2ab78a616e2e3df25e8d9588aa6c56 /libio/tst-ungetwc1.c
parent5e473a71467d30b51faadb7b5ae4305abc0a16d7 (diff)
downloadglibc-8f739934b026cd0c298e3196d38d483eb1f88bed.tar.gz
glibc-8f739934b026cd0c298e3196d38d483eb1f88bed.tar.xz
glibc-8f739934b026cd0c298e3196d38d483eb1f88bed.zip
Update.
	* libio/ioungetwc.c (ungetwc): Orient stream first.
	* libio/Makefile (tests): Add tst-ungetwc1.
	* libio/tst-ungetwc1.c: New file.
Diffstat (limited to 'libio/tst-ungetwc1.c')
-rw-r--r--libio/tst-ungetwc1.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/libio/tst-ungetwc1.c b/libio/tst-ungetwc1.c
new file mode 100644
index 0000000000..eeee7f699b
--- /dev/null
+++ b/libio/tst-ungetwc1.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, 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;
+}