aboutsummaryrefslogtreecommitdiff
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
parent5e473a71467d30b51faadb7b5ae4305abc0a16d7 (diff)
downloadglibc-8f739934b026cd0c298e3196d38d483eb1f88bed.zip
glibc-8f739934b026cd0c298e3196d38d483eb1f88bed.tar.gz
glibc-8f739934b026cd0c298e3196d38d483eb1f88bed.tar.bz2
Update.
* libio/ioungetwc.c (ungetwc): Orient stream first. * libio/Makefile (tests): Add tst-ungetwc1. * libio/tst-ungetwc1.c: New file.
-rw-r--r--ChangeLog4
-rw-r--r--libio/Makefile5
-rw-r--r--libio/ioungetwc.c10
-rw-r--r--libio/tst-ungetwc1.c81
4 files changed, 94 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b3a20f..ca238cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2001-08-08 Ulrich Drepper <drepper@redhat.com>
+ * libio/ioungetwc.c (ungetwc): Orient stream first.
+ * libio/Makefile (tests): Add tst-ungetwc1.
+ * libio/tst-ungetwc1.c: New file.
+
* libio/wfileops.c (_IO_wfile_underflow): Remove incorrect test
for possible conversion using __codecvt_do_in.
* libio/Makefile (tests): Add tst-fgetws.
diff --git a/libio/Makefile b/libio/Makefile
index 0130234..97a8f73 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -48,7 +48,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-fgetws tst-ungetwc1
test-srcs = test-freopen
all: # Make this the default target; it will be defined in Rules.
@@ -83,7 +83,8 @@ tst_wprintf2-ARGS = "Some Text"
tst-widetext-ENV = LOCPATH=$(common-objpfx)localedata LANGUAGE=C
tst-fopenloc-ENV = LOCPATH=$(common-objpfx)localedata \
MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace
-tst-fgetws-ENV = LOCPATH=$(common-objpfx)localedata LANGUAGE=C
+tst-fgetws-ENV = LOCPATH=$(common-objpfx)localedata
+tst-ungetwc1-ENV = LOCPATH=$(common-objpfx)localedata
generated = tst-fopenloc.mtrace tst-fopenloc.check
diff --git a/libio/ioungetwc.c b/libio/ioungetwc.c
index 11eb7c4..542b7b1 100644
--- a/libio/ioungetwc.c
+++ b/libio/ioungetwc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1996-1999, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -35,11 +35,13 @@ ungetwc (c, fp)
{
int result;
CHECK_FILE (fp, WEOF);
- if (c == WEOF)
- return WEOF;
_IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
_IO_flockfile (fp);
- result = _IO_sputbackwc (fp, c);
+ _IO_fwide (fp, 1);
+ if (c == WEOF)
+ result = WEOF;
+ else
+ result = _IO_sputbackwc (fp, c);
_IO_funlockfile (fp);
_IO_cleanup_region_end (0);
return result;
diff --git a/libio/tst-ungetwc1.c b/libio/tst-ungetwc1.c
new file mode 100644
index 0000000..eeee7f6
--- /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;
+}