about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--argp/argp-fmtstream.c42
-rw-r--r--argp/argp-help.c103
-rw-r--r--assert/assert-perr.c10
-rw-r--r--assert/assert.c11
-rw-r--r--debug/Makefile3
-rw-r--r--debug/Versions3
-rw-r--r--debug/mbsnrtowcs_chk.c31
-rw-r--r--debug/mbsrtowcs_chk.c31
-rw-r--r--debug/tst-chk1.c108
-rw-r--r--debug/wcrtomb_chk.c35
-rw-r--r--debug/wcsnrtombs_chk.c31
-rw-r--r--debug/wcsrtombs_chk.c31
-rw-r--r--gmon/gmon.c13
-rw-r--r--inet/rcmd.c103
-rw-r--r--malloc/obstack.c11
-rw-r--r--misc/getpass.c20
-rw-r--r--posix/getopt.c50
-rw-r--r--resolv/res_hconf.c60
-rw-r--r--stdio-common/perror.c7
-rw-r--r--stdio-common/psignal.c22
-rw-r--r--stdlib/fmtmsg.c52
-rw-r--r--sunrpc/auth_unix.c9
-rw-r--r--sunrpc/clnt_perr.c21
-rw-r--r--sunrpc/clnt_tcp.c9
-rw-r--r--sunrpc/clnt_udp.c9
-rw-r--r--sunrpc/clnt_unix.c9
-rw-r--r--sunrpc/svc_simple.c14
-rw-r--r--sunrpc/svc_tcp.c17
-rw-r--r--sunrpc/svc_udp.c30
-rw-r--r--sunrpc/svc_unix.c16
-rw-r--r--sunrpc/xdr.c17
-rw-r--r--sunrpc/xdr_array.c9
-rw-r--r--sunrpc/xdr_rec.c8
-rw-r--r--sunrpc/xdr_ref.c9
-rw-r--r--sysdeps/generic/wordexp.c7
-rw-r--r--wcsmbs/bits/wchar2.h111
37 files changed, 581 insertions, 508 deletions
diff --git a/ChangeLog b/ChangeLog
index dd4c6b89b1..16bbe91385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,23 @@
+2005-07-20  Ulrich Drepper  <drepper@redhat.com>
+
+	* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
+	wcsrtombs, mbsnrtowcs, and wcsnrtombs.
+	* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
+	wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
+	* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
+	__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
+	* debug/tst-chk1.c: Add tests for new functions.
+	* debug/mbsnrtowcs_chk.c: New file.
+	* debug/mbsrtowcs_chk.c: New file.
+	* debug/wcrtomb_chk.c: New file.
+	* debug/wcsnrtombs_chk.c: New file.
+	* debug/wcsrtombs_chk.c: New file.
+
 2005-07-19  Ulrich Drepper  <drepper@redhat.com>
 
 	* stdio-common/Makefile (aux): Add fxprintf.
 	* stdio-common/fxprintf.c: New file.
-	* include/stdio.h: Add declaration for stdio.h.
+	* include/stdio.h: Add declaration for __fxprintf.
 	* argp/argp-fmtstream.c: Use __fxprintf instead of inline stream
 	orientation test and two separate function calls.
 	* argp/argp-help.c: Likewise.
diff --git a/argp/argp-fmtstream.c b/argp/argp-fmtstream.c
index 215160bdcd..efa8388a84 100644
--- a/argp/argp-fmtstream.c
+++ b/argp/argp-fmtstream.c
@@ -1,5 +1,5 @@
 /* Word-wrapping and line-truncating streams
-   Copyright (C) 1997,1998,1999,2001,2002,2003 Free Software Foundation, Inc.
+   Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
@@ -102,11 +102,11 @@ __argp_fmtstream_free (argp_fmtstream_t fs)
   if (fs->p > fs->buf)
     {
 #ifdef USE_IN_LIBIO
-      if (_IO_fwide (fs->stream, 0) > 0)
-	__fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf);
-      else
+      __fxprintf (fs->stream, "%.*s", L"%.*s",
+		  (int) (fs->p - fs->buf), fs->buf);
+#else
+      fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
 #endif
-	fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
     }
   free (fs->buf);
   free (fs);
@@ -291,17 +291,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
 	      else
 		/* Output the first line so we can use the space.  */
 		{
-#ifdef USE_IN_LIBIO
-		  if (_IO_fwide (fs->stream, 0) > 0)
-		    __fwprintf (fs->stream, L"%.*s\n",
-				(int) (nl - fs->buf), fs->buf);
-		  else
+#ifdef _LIBC
+		  __fxprintf (fs->stream, "%.*s\n", L"%.*s\n",
+			      (int) (nl - fs->buf), fs->buf);
+#else
+		  if (nl > fs->buf)
+		    fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
+		  putc_unlocked ('\n', fs->stream);
 #endif
-		    {
-		      if (nl > fs->buf)
-			fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
-		      putc_unlocked ('\n', fs->stream);
-		    }
+
 		  len += buf - fs->buf;
 		  nl = buf = fs->buf;
 		}
@@ -360,15 +358,13 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
       /* Flush FS's buffer.  */
       __argp_fmtstream_update (fs);
 
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (fs->stream, 0) > 0)
-	{
-	  __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf);
-	  wrote = fs->p - fs->buf;
-	}
-      else
+#ifdef _LIBC
+      __fxprintf (fs->stream, "%.*s", L"%.*s",
+		  (int) (fs->p - fs->buf), fs->buf);
+      wrote = fs->p - fs->buf;
+#else
+      wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
 #endif
-	wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
       if (wrote == fs->p - fs->buf)
 	{
 	  fs->p = fs->buf;
diff --git a/argp/argp-help.c b/argp/argp-help.c
index 67018709d3..c5a9e84f7e 100644
--- a/argp/argp-help.c
+++ b/argp/argp-help.c
@@ -1,5 +1,5 @@
 /* Hierarchial argument parsing help output
-   Copyright (C) 1995-2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
@@ -1763,33 +1763,26 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 
 	  va_start (ap, fmt);
 
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stream, 0) > 0)
-	    {
-	      char *buf;
+#ifdef _LIBC
+	  char *buf;
 
-	      if (__asprintf (&buf, fmt, ap) < 0)
-		buf = NULL;
+	  if (__asprintf (&buf, fmt, ap) < 0)
+	    buf = NULL;
 
-	      __fwprintf (stream, L"%s: %s\n",
-			  state ? state->name : __argp_short_program_name (),
-			  buf);
+	  __fxprintf (stream, "%s: %s\n", L"%s: %s\n",
+		      state ? state->name : __argp_short_program_name (), buf);
 
-	      free (buf);
-	    }
-	  else
-#endif
-	    {
-	      fputs_unlocked (state
-			      ? state->name : __argp_short_program_name (),
-			      stream);
-	      putc_unlocked (':', stream);
-	      putc_unlocked (' ', stream);
+	  free (buf);
+#else
+	  fputs_unlocked (state ? state->name : __argp_short_program_name (),
+			  stream);
+	  putc_unlocked (':', stream);
+	  putc_unlocked (' ', stream);
 
-	      vfprintf (stream, fmt, ap);
+	  vfprintf (stream, fmt, ap);
 
-	      putc_unlocked ('\n', stream);
-	    }
+	  putc_unlocked ('\n', stream);
+#endif
 
 	  __argp_state_help (state, stream, ARGP_HELP_STD_ERR);
 
@@ -1827,41 +1820,34 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 	  __flockfile (stream);
 #endif
 
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stream, 0) > 0)
-	    __fwprintf (stream, L"%s",
-			state ? state->name : __argp_short_program_name ());
-	  else
+#ifdef _LIBC
+	  __fxprintf (stream, "%s", L"%s",
+		      state ? state->name : __argp_short_program_name ());
+#else
+	  fputs_unlocked (state ? state->name : __argp_short_program_name (),
+			  stream);
 #endif
-	    fputs_unlocked (state
-			    ? state->name : __argp_short_program_name (),
-			    stream);
 
 	  if (fmt)
 	    {
 	      va_list ap;
 
 	      va_start (ap, fmt);
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stream, 0) > 0)
-		{
-		  char *buf;
+#ifdef _LIBC
+	      char *buf;
 
-		  if (__asprintf (&buf, fmt, ap) < 0)
-		    buf = NULL;
+	      if (__asprintf (&buf, fmt, ap) < 0)
+		buf = NULL;
 
-		  __fwprintf (stream, L": %s", buf);
+	      __fxprintf (stream, ": %s", L": %s", buf);
 
-		  free (buf);
-		}
-	      else
-#endif
-		{
-		  putc_unlocked (':', stream);
-		  putc_unlocked (' ', stream);
+	      free (buf);
+#else
+	      putc_unlocked (':', stream);
+	      putc_unlocked (' ', stream);
 
-		  vfprintf (stream, fmt, ap);
-		}
+	      vfprintf (stream, fmt, ap);
+#endif
 
 	      va_end (ap);
 	    }
@@ -1870,21 +1856,18 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 	    {
 	      char buf[200];
 
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stream, 0) > 0)
-		__fwprintf (stream, L": %s",
-			    __strerror_r (errnum, buf, sizeof (buf)));
-	      else
-#endif
-		{
-		  putc_unlocked (':', stream);
-		  putc_unlocked (' ', stream);
-#if defined _LIBC || defined HAVE_STRERROR_R
-		  fputs (__strerror_r (errnum, buf, sizeof (buf)), stream);
+#ifdef _LIBC
+	      __fxprintf (stream, ": %s", L": %s",
+			  __strerror_r (errnum, buf, sizeof (buf)));
 #else
-		  fputs (strerror (errnum), stream);
+	      putc_unlocked (':', stream);
+	      putc_unlocked (' ', stream);
+# ifdef HAVE_STRERROR_R
+	      fputs (__strerror_r (errnum, buf, sizeof (buf)), stream);
+# else
+	      fputs (strerror (errnum), stream);
+# endif
 #endif
-		}
 	    }
 
 #ifdef USE_IN_LIBIO
diff --git a/assert/assert-perr.c b/assert/assert-perr.c
index 3017c9fd9c..b5890d226a 100644
--- a/assert/assert-perr.c
+++ b/assert/assert-perr.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994-1998,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1994-1998,2001,2002,2005 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
@@ -61,13 +61,7 @@ __assert_perror_fail (int errnum,
 		  __strerror_r (errnum, errbuf, sizeof errbuf)) >= 0)
     {
       /* Print the message.  */
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s", buf);
-      else
-#endif
-	(void) fputs (buf, stderr);
-
+      (void) __fxprintf (NULL, "%s", L"%s", buf);
       (void) fflush (stderr);
 
       /* We have to free the buffer since the appplication might catch the
diff --git a/assert/assert.c b/assert/assert.c
index 20c86eba52..7b7f255717 100644
--- a/assert/assert.c
+++ b/assert/assert.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991,1994-1996,1998,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1994-1996,1998,2001,2002,2005
+   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
@@ -60,13 +61,7 @@ __assert_fail (const char *assertion, const char *file, unsigned int line,
 		  assertion) >= 0)
     {
       /* Print the message.  */
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s", buf);
-      else
-#endif
-	(void) fputs (buf, stderr);
-
+      (void) __fxprintf (NULL, "%s", L"%s", buf);
       (void) fflush (stderr);
 
       /* We have to free the buffer since the application might catch the
diff --git a/debug/Makefile b/debug/Makefile
index e3fccc192e..009c05c9d9 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -38,7 +38,8 @@ routines  = backtrace backtracesyms backtracesymsfd noophooks \
 	    swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \
 	    vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \
 	    confstr_chk getgroups_chk ttyname_r_chk getlogin_r_chk \
-	    gethostname_chk getdomainname_chk \
+	    gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \
+	    wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk \
 	    stack_chk_fail \
 	    $(static-only-routines)
 static-only-routines := warning-nop stack_chk_fail_local
diff --git a/debug/Versions b/debug/Versions
index f33fbed6ef..2f4183bceb 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -30,7 +30,8 @@ libc {
     __swprintf_chk; __vswprintf_chk; __wprintf_chk; __fwprintf_chk;
     __vwprintf_chk; __vfwprintf_chk; __fgetws_chk; __fgetws_unlocked_chk;
     __confstr_chk; __getgroups_chk; __ttyname_r_chk; __getlogin_r_chk;
-    __gethostname_chk; __getdomainname_chk;
+    __gethostname_chk; __getdomainname_chk; __wcrtomb_chk; __mbsnrtowcs_chk;
+    __wcsnrtombs_chk; __mbsrtowcs_chk; __wcsrtombs_chk;
 
     __stack_chk_fail;
   }
diff --git a/debug/mbsnrtowcs_chk.c b/debug/mbsnrtowcs_chk.c
new file mode 100644
index 0000000000..2041eac87f
--- /dev/null
+++ b/debug/mbsnrtowcs_chk.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2005 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <locale.h>
+#include <wchar.h>
+
+
+size_t
+__mbsnrtowcs_chk (wchar_t *dst, __const char **src, size_t nmc, size_t len,
+		  mbstate_t *ps, size_t dstlen)
+{
+  if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0))
+    __chk_fail ();
+
+  return __mbsnrtowcs (dst, src, nmc, len, ps);
+}
diff --git a/debug/mbsrtowcs_chk.c b/debug/mbsrtowcs_chk.c
new file mode 100644
index 0000000000..fd4b3bf76b
--- /dev/null
+++ b/debug/mbsrtowcs_chk.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2005 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <locale.h>
+#include <wchar.h>
+
+
+size_t
+__mbsrtowcs_chk (wchar_t *dst, __const char **src, size_t len,
+		 mbstate_t *ps, size_t dstlen)
+{
+  if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0))
+    __chk_fail ();
+
+  return __mbsrtowcs (dst, src, len, ps);
+}
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index 47938bbf36..62b0fa6f40 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -76,6 +76,7 @@ char buf[10];
 wchar_t wbuf[10];
 volatile size_t l0;
 volatile char *p;
+volatile wchar_t *wp;
 const char *str1 = "JIHGFEDCBA";
 const char *str2 = "F";
 const char *str3 = "%s%n%s%n";
@@ -502,7 +503,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wmempcpy (wbuf + 6, L"abcde", l0 + 5);
+    wp = wmempcpy (wbuf + 6, L"abcde", l0 + 5);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -514,7 +515,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wcpcpy (wbuf + 9, wstr2);
+  wp = wcpcpy (wbuf + 9, wstr2);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -544,7 +545,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wmempcpy (wa.buf1 + 6, L"abcde", l0 + 5);
+  wp = wmempcpy (wa.buf1 + 6, L"abcde", l0 + 5);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -562,7 +563,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wcpcpy (wa.buf1 + (O + 8), wstr2);
+  wp = wcpcpy (wa.buf1 + (O + 8), wstr2);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -1056,6 +1057,105 @@ do_test (void)
 	}
       CHK_FAIL_END
 #endif
+
+      mbstate_t s;
+      memset (&s, '\0', sizeof (s));
+      if (wcrtomb (enough, L'A', &s) != 1)
+	{
+	  puts ("first wcrtomb test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      char smallbuf[2];
+      if (wcrtomb (smallbuf, L'\x100', &s) != 2)
+	{
+	  puts ("second wcrtomb test failed");
+	  ret = 1;
+	}
+      CHK_FAIL_END
+#endif
+
+      wchar_t wenough[10];
+      memset (&s, '\0', sizeof (s));
+      const char *cp = "A";
+      if (mbsrtowcs (wenough, &cp, 10, &s) != 1)
+	{
+	  puts ("first mbsrtowcs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      wchar_t wsmallbuf[2];
+      cp = "ABC";
+      mbsrtowcs (wsmallbuf, &cp, 10, &s);
+      CHK_FAIL_END
+#endif
+
+      memset (&s, '\0', sizeof (s));
+      cp = "A";
+      if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1)
+	{
+	  puts ("first mbsnrtowcs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      wchar_t wsmallbuf[2];
+      cp = "ABC";
+      mbsnrtowcs (wsmallbuf, &cp, 3, 10, &s);
+      CHK_FAIL_END
+#endif
+
+      memset (&s, '\0', sizeof (s));
+      const wchar_t *wcp = L"A";
+      if (wcsrtombs (enough, &wcp, 10, &s) != 1)
+	{
+	  puts ("first wcsrtombs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      char smallbuf[2];
+      wcp = L"ABC";
+      wcsrtombs (smallbuf, &wcp, 10, &s);
+      CHK_FAIL_END
+#endif
+
+      memset (&s, '\0', sizeof (s));
+      wcp = L"A";
+      if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1)
+	{
+	  puts ("first wcsnrtombs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      char smallbuf[2];
+      wcp = L"ABC";
+      wcsnrtombs (smallbuf, &wcp, 3, 10, &s);
+      CHK_FAIL_END
+#endif
     }
   else
     {
diff --git a/debug/wcrtomb_chk.c b/debug/wcrtomb_chk.c
new file mode 100644
index 0000000000..228430f373
--- /dev/null
+++ b/debug/wcrtomb_chk.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2005 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <langinfo.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <locale/localeinfo.h>
+
+
+size_t
+__wcrtomb_chk (char *s, wchar_t wchar, mbstate_t *ps, size_t buflen)
+{
+  /* We do not have to implement the full wctomb semantics since we
+     know that S cannot be NULL when we come here.  */
+  if (buflen < MB_CUR_MAX)
+    __chk_fail ();
+
+  return __wcrtomb (s, wchar, ps);
+}
diff --git a/debug/wcsnrtombs_chk.c b/debug/wcsnrtombs_chk.c
new file mode 100644
index 0000000000..67644bd557
--- /dev/null
+++ b/debug/wcsnrtombs_chk.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2005 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <locale.h>
+#include <wchar.h>
+
+
+size_t
+__wcsnrtombs_chk (char *dst, __const wchar_t **src, size_t nwc, size_t len,
+		  mbstate_t *ps, size_t dstlen)
+{
+  if (__builtin_expect (dstlen < len, 0))
+    __chk_fail ();
+
+  return __wcsnrtombs (dst, src, nwc, len, ps);
+}
diff --git a/debug/wcsrtombs_chk.c b/debug/wcsrtombs_chk.c
new file mode 100644
index 0000000000..9334267bae
--- /dev/null
+++ b/debug/wcsrtombs_chk.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2005 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <locale.h>
+#include <wchar.h>
+
+
+size_t
+__wcsrtombs_chk (char *dst, __const wchar_t **src, size_t len,
+		 mbstate_t *ps, size_t dstlen)
+{
+  if (__builtin_expect (dstlen < len, 0))
+    __chk_fail ();
+
+  return __wcsrtombs (dst, src, len, ps);
+}
diff --git a/gmon/gmon.c b/gmon/gmon.c
index 8eb0736193..3ad581d2a9 100644
--- a/gmon/gmon.c
+++ b/gmon/gmon.c
@@ -331,7 +331,7 @@ write_gmon (void)
       {
 	size_t len = strlen (env);
 	char buf[len + 20];
-	sprintf (buf, "%s.%u", env, __getpid ());
+	snprintf (buf, sizeof (buf), "%s.%u", env, __getpid ());
 	fd = open_not_cancel (buf, O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, 0666);
       }
 
@@ -343,14 +343,9 @@ write_gmon (void)
 	  {
 	    char buf[300];
 	    int errnum = errno;
-#ifdef USE_IN_LIBIO
-	    if (_IO_fwide (stderr, 0) > 0)
-	      __fwprintf (stderr, L"_mcleanup: gmon.out: %s\n",
-			  __strerror_r (errnum, buf, sizeof buf));
-	    else
-#endif
-	      fprintf (stderr, "_mcleanup: gmon.out: %s\n",
-		       __strerror_r (errnum, buf, sizeof buf));
+	    __fxprintf (NULL, "_mcleanup: gmon.out: %s\n",
+			L"_mcleanup: gmon.out: %s\n",
+			__strerror_r (errnum, buf, sizeof buf));
 	    return;
 	  }
       }
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 0bcb731a16..8d236ad099 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -137,21 +137,15 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 	(void)__snprintf(num, sizeof(num), "%d", ntohs(rport));
 	error = getaddrinfo(*ahost, num, &hints, &res);
 	if (error) {
-		if (error == EAI_NONAME && *ahost != NULL) {
-			if (_IO_fwide (stderr, 0) > 0)
-				__fwprintf(stderr, L"%s: Unknown host\n",
-					   *ahost);
-			else
-				fprintf(stderr, "%s: Unknown host\n", *ahost);
-		} else {
-			if (_IO_fwide (stderr, 0) > 0)
-				__fwprintf(stderr, L"rcmd: getaddrinfo: %s\n",
-					   gai_strerror(error));
-			else
-				fprintf(stderr, "rcmd: getaddrinfo: %s\n",
-					gai_strerror(error));
-		}
-                return (-1);
+		if (error == EAI_NONAME && *ahost != NULL)
+			__fxprintf(NULL, "%s: Unknown host\n",
+				   L"%s: Unknown host\n", *ahost);
+		else
+			__fxprintf(NULL, "rcmd: getaddrinfo: %s\n",
+				   L"rcmd: getaddrinfo: %s\n",
+				   gai_strerror(error));
+
+                return -1;
 	}
 
 	pfd[0].events = POLLIN;
@@ -161,13 +155,9 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 		free (ahostbuf);
 		ahostbuf = strdup (res->ai_canonname);
 		if (ahostbuf == NULL) {
-			if (_IO_fwide (stderr, 0) > 0)
-				__fwprintf(stderr, L"%s",
-					   _("rcmd: Cannot allocate memory\n"));
-			else
-				fputs(_("rcmd: Cannot allocate memory\n"),
-				      stderr);
-			return (-1);
+			__fxprintf(NULL, "%s", L"%s",
+				   _("rcmd: Cannot allocate memory\n"));
+			return -1;
 		}
 		*ahost = ahostbuf;
 	} else
@@ -180,20 +170,13 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 
 		s = rresvport_af(&lport, ai->ai_family);
 		if (s < 0) {
-			if (errno == EAGAIN) {
-				if (_IO_fwide (stderr, 0) > 0)
-					__fwprintf(stderr, L"%s",
-						   _("rcmd: socket: All ports in use\n"));
-				else
-					fputs(_("rcmd: socket: All ports in use\n"),
-					      stderr);
-			} else {
-				if (_IO_fwide (stderr, 0) > 0)
-					__fwprintf(stderr,
-						   L"rcmd: socket: %m\n");
-				else
-					fprintf(stderr, "rcmd: socket: %m\n");
-			}
+			if (errno == EAGAIN)
+				__fxprintf(NULL, "%s", L"%s", _("\
+rcmd: socket: All ports in use\n"));
+			else
+				__fxprintf(NULL, "rcmd: socket: %m\n",
+					   L"rcmd: socket: %m\n");
+
 			__sigsetmask(oldmask);
 			freeaddrinfo(res);
 			return -1;
@@ -220,10 +203,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 			if (__asprintf (&buf, _("connect to address %s: "),
 					paddr) >= 0)
 			  {
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf(stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf(NULL, "%s", L"%s", buf);
 			    free (buf);
 			  }
 			__set_errno (oerrno);
@@ -235,10 +215,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 				    NI_NUMERICHOST);
 			if (__asprintf (&buf, _("Trying %s...\n"), paddr) >= 0)
 			  {
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf (stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf (NULL, "%s", L"%s", buf);
 			    free (buf);
 			  }
 			continue;
@@ -251,14 +228,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 			continue;
 		}
 		freeaddrinfo(res);
-		if (_IO_fwide (stderr, 0) > 0)
-			(void)__fwprintf(stderr, L"%s: %s\n", *ahost,
-					 __strerror_r(errno,
-						      errbuf, sizeof (errbuf)));
-		else
-			(void)fprintf(stderr, "%s: %s\n", *ahost,
-				      __strerror_r(errno,
-						   errbuf, sizeof (errbuf)));
+		(void)__fxprintf(NULL, "%s: %s\n", L"%s: %s\n", *ahost,
+				 __strerror_r(errno, errbuf, sizeof (errbuf)));
 		__sigsetmask(oldmask);
 		return -1;
 	}
@@ -281,10 +252,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
 			if (__asprintf (&buf, _("\
 rcmd: write (setting up stderr): %m\n")) >= 0)
 			  {
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf(stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf(NULL, "%s", L"%s", buf);
 			    free (buf);
 			  }
 			(void)__close(s2);
@@ -303,10 +271,7 @@ rcmd: poll (setting up stderr): %m\n")) >= 0)
 				&& __asprintf(&buf, _("\
 poll: protocol failure in circuit setup\n")) >= 0))
 			  {
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf (stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf (NULL, "%s", L"%s", buf);
 			    free  (buf);
 			  }
 			(void)__close(s2);
@@ -327,12 +292,8 @@ poll: protocol failure in circuit setup\n")) >= 0))
 		}
 		(void)__close(s2);
 		if (s3 < 0) {
-			if (_IO_fwide (stderr, 0) > 0)
-				(void)__fwprintf(stderr,
-						 L"rcmd: accept: %m\n");
-			else
-				(void)fprintf(stderr,
-					      "rcmd: accept: %m\n");
+			(void)__fxprintf(NULL, "rcmd: accept: %m\n",
+					 L"rcmd: accept: %m\n");
 			lport = 0;
 			goto bad;
 		}
@@ -344,10 +305,7 @@ poll: protocol failure in circuit setup\n")) >= 0))
 			if (__asprintf(&buf, _("\
 socket: protocol failure in circuit setup\n")) >= 0)
 			  {
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf (stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf (NULL, "%s", L"%s", buf);
 			    free (buf);
 			  }
 			goto bad2;
@@ -373,10 +331,7 @@ socket: protocol failure in circuit setup\n")) >= 0)
 		    || (n != 0
 			&& __asprintf(&buf, "rcmd: %s: %m\n", *ahost) >= 0))
 		  {
-		    if (_IO_fwide (stderr, 0) > 0)
-		      __fwprintf (stderr, L"%s", buf);
-		    else
-		      fputs (buf, stderr);
+		    __fxprintf (NULL, "%s", L"%s", buf);
 		    free (buf);
 		  }
 		goto bad2;
diff --git a/malloc/obstack.c b/malloc/obstack.c
index fddda3ec5b..7f9e24548b 100644
--- a/malloc/obstack.c
+++ b/malloc/obstack.c
@@ -1,6 +1,6 @@
 /* obstack.c - subroutines used implicitly by object stack macros
-   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
-   1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.  Its master source is NOT part of
    the C library, however.  The master source lives in /gd/gnu/lib.
 
@@ -410,12 +410,7 @@ print_and_abort (void)
      happen because the "memory exhausted" message appears in other places
      like this and the translation should be reused instead of creating
      a very similar string which requires a separate translation.  */
-# if defined _LIBC && defined USE_IN_LIBIO
-  if (_IO_fwide (stderr, 0) > 0)
-    __fwprintf (stderr, L"%s\n", _("memory exhausted"));
-  else
-# endif
-    fprintf (stderr, "%s\n", _("memory exhausted"));
+  (void) __fxprintf (NULL, "%s\n", L"%s\n", _("memory exhausted"));
   exit (obstack_exit_failure);
 }
 
diff --git a/misc/getpass.c b/misc/getpass.c
index 62e56866a1..a6e568ac08 100644
--- a/misc/getpass.c
+++ b/misc/getpass.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-1999, 2001, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1992-1999,2001,2003,2004,2005 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
@@ -91,12 +91,7 @@ getpass (prompt)
     tty_changed = 0;
 
   /* Write the prompt.  */
-#ifdef USE_IN_LIBIO
-  if (_IO_fwide (out, 0) > 0)
-    __fwprintf (out, L"%s", prompt);
-  else
-#endif
-    fputs_unlocked (prompt, out);
+  __fxprintf (out, "%s", L"%s", prompt);
   fflush_unlocked (out);
 
   /* Read the password.  */
@@ -110,15 +105,8 @@ getpass (prompt)
 	  /* Remove the newline.  */
 	  buf[nread - 1] = '\0';
 	  if (tty_changed)
-	    {
-	      /* Write the newline that was not echoed.  */
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (out, 0) > 0)
-		putwc_unlocked (L'\n', out);
-	      else
-#endif
-		putc_unlocked ('\n', out);
-	    }
+	    /* Write the newline that was not echoed.  */
+	    __fxprintf (out, "%c", L"%c", '\n');
 	}
     }
 
diff --git a/posix/getopt.c b/posix/getopt.c
index 9ad13a4a92..c294ce3711 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -576,10 +576,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 		  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
 		  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-		  if (_IO_fwide (stderr, 0) > 0)
-		    __fwprintf (stderr, L"%s", buf);
-		  else
-		    fputs (buf, stderr);
+		  __fxprintf (NULL, "%s", L"%s", buf);
 
 		  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 		  _IO_funlockfile (stderr);
@@ -654,10 +651,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 			  ((_IO_FILE *) stderr)->_flags2
 			    |= _IO_FLAGS2_NOTCANCEL;
 
-			  if (_IO_fwide (stderr, 0) > 0)
-			    __fwprintf (stderr, L"%s", buf);
-			  else
-			    fputs (buf, stderr);
+			  __fxprintf (NULL, "%s", L"%s", buf);
 
 			  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 			  _IO_funlockfile (stderr);
@@ -694,10 +688,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 			  ((_IO_FILE *) stderr)->_flags2
 			    |= _IO_FLAGS2_NOTCANCEL;
 
-			  if (_IO_fwide (stderr, 0) > 0)
-			    __fwprintf (stderr, L"%s", buf);
-			  else
-			    fputs (buf, stderr);
+			  __fxprintf (NULL, "%s", L"%s", buf);
 
 			  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 			  _IO_funlockfile (stderr);
@@ -771,10 +762,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 		  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
 		  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-		  if (_IO_fwide (stderr, 0) > 0)
-		    __fwprintf (stderr, L"%s", buf);
-		  else
-		    fputs (buf, stderr);
+		  __fxprintf (NULL, "%s", L"%s", buf);
 
 		  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 		  _IO_funlockfile (stderr);
@@ -837,10 +825,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 		int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
 		((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-		if (_IO_fwide (stderr, 0) > 0)
-		  __fwprintf (stderr, L"%s", buf);
-		else
-		  fputs (buf, stderr);
+		__fxprintf (NULL, "%s", L"%s", buf);
 
 		((_IO_FILE *) stderr)->_flags2 = old_flags2;
 		_IO_funlockfile (stderr);
@@ -888,10 +873,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 		    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
 		    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-		    if (_IO_fwide (stderr, 0) > 0)
-		      __fwprintf (stderr, L"%s", buf);
-		    else
-		      fputs (buf, stderr);
+		    __fxprintf (NULL, "%s", L"%s", buf);
 
 		    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 		    _IO_funlockfile (stderr);
@@ -960,10 +942,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 		    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
 		    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-		    if (_IO_fwide (stderr, 0) > 0)
-		      __fwprintf (stderr, L"%s", buf);
-		    else
-		      fputs (buf, stderr);
+		    __fxprintf (NULL, "%s", L"%s", buf);
 
 		    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 		    _IO_funlockfile (stderr);
@@ -1005,10 +984,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 			    ((_IO_FILE *) stderr)->_flags2
 			      |= _IO_FLAGS2_NOTCANCEL;
 
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf (stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf (NULL, "%s", L"%s", buf);
 
 			    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 			    _IO_funlockfile (stderr);
@@ -1047,10 +1023,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 			    ((_IO_FILE *) stderr)->_flags2
 			      |= _IO_FLAGS2_NOTCANCEL;
 
-			    if (_IO_fwide (stderr, 0) > 0)
-			      __fwprintf (stderr, L"%s", buf);
-			    else
-			      fputs (buf, stderr);
+			    __fxprintf (NULL, "%s", L"%s", buf);
 
 			    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
 			    _IO_funlockfile (stderr);
@@ -1121,10 +1094,7 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 			int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
 			((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-			if (_IO_fwide (stderr, 0) > 0)
-			  __fwprintf (stderr, L"%s", buf);
-			else
-			  fputs (buf, stderr);
+			__fxprintf (NULL, "%s", L"%s", buf);
 
 			((_IO_FILE *) stderr)->_flags2 = old_flags2;
 			_IO_funlockfile (stderr);
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
index 91cd300482..d3de4be15a 100644
--- a/resolv/res_hconf.c
+++ b/resolv/res_hconf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995-2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995-2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by David Mosberger (davidm@azstarnet.com).
 
@@ -150,12 +150,7 @@ arg_service_list (const char *fname, int line_num, const char *args,
 			  fname, line_num, start) < 0)
 	    return 0;
 
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stderr, 0) > 0)
-	    __fwprintf (stderr, L"%s", buf);
-	  else
-#endif
-	    fputs (buf, stderr);
+	  __fxprintf (NULL, "%s", L"%s", buf);
 
 	  free (buf);
 	  return 0;
@@ -169,12 +164,7 @@ arg_service_list (const char *fname, int line_num, const char *args,
 			  fname, line_num, SERVICE_MAX) < 0)
 	    return 0;
 
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stderr, 0) > 0)
-	    __fwprintf (stderr, L"%s", buf);
-	  else
-#endif
-	    fputs (buf, stderr);
+	  __fxprintf (NULL, "%s", L"%s", buf);
 
 	  free (buf);
 	  return 0;
@@ -197,12 +187,7 @@ arg_service_list (const char *fname, int line_num, const char *args,
 			      fname, line_num) < 0)
 		return 0;
 
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stderr, 0) > 0)
-		__fwprintf (stderr, L"%s", buf);
-	      else
-#endif
-		fputs (buf, stderr);
+	      __fxprintf (NULL, "%s", L"%s", buf);
 
 	      free (buf);
 	      return 0;
@@ -238,14 +223,9 @@ arg_trimdomain_list (const char *fname, int line_num, const char *args,
 			  fname, line_num, TRIMDOMAINS_MAX) < 0)
 	    return 0;
 
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stderr, 0) > 0)
-		__fwprintf (stderr, L"%s", buf);
-	      else
-#endif
-		fputs (buf, stderr);
+	  __fxprintf (NULL, "%s", L"%s", buf);
 
-	      free (buf);
+	  free (buf);
 	  return 0;
 	}
       _res_hconf.trimdomain[_res_hconf.num_trimdomains++] =
@@ -264,12 +244,7 @@ arg_trimdomain_list (const char *fname, int line_num, const char *args,
 			      fname, line_num) < 0)
 		return 0;
 
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stderr, 0) > 0)
-		__fwprintf (stderr, L"%s", buf);
-	      else
-#endif
-		fputs (buf, stderr);
+	      __fxprintf (NULL, "%s", L"%s", buf);
 
 	      free (buf);
 	      return 0;
@@ -327,12 +302,7 @@ arg_bool (const char *fname, int line_num, const char *args, unsigned flag)
 		      fname, line_num, args) < 0)
 	return 0;
 
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	__fwprintf (stderr, L"%s", buf);
-      else
-#endif
-	fputs (buf, stderr);
+      __fxprintf (NULL, "%s", L"%s", buf);
 
       free (buf);
       return 0;
@@ -375,12 +345,7 @@ parse_line (const char *fname, int line_num, const char *str)
 		      fname, line_num, start) < 0)
 	return;
 
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	__fwprintf (stderr, L"%s", buf);
-      else
-#endif
-	fputs (buf, stderr);
+      __fxprintf (NULL, "%s", L"%s", buf);
 
       free (buf);
       return;
@@ -405,12 +370,7 @@ parse_line (const char *fname, int line_num, const char *str)
 			    fname, line_num, str) < 0)
 	      break;
 
-#ifdef USE_IN_LIBIO
-	    if (_IO_fwide (stderr, 0) > 0)
-	      __fwprintf (stderr, L"%s", buf);
-	    else
-#endif
-	      fputs (buf, stderr);
+	    __fxprintf (NULL, "%s", L"%s", buf);
 
 	    free (buf);
 	  }
diff --git a/stdio-common/perror.c b/stdio-common/perror.c
index f0751375b5..6d32e6d6e1 100644
--- a/stdio-common/perror.c
+++ b/stdio-common/perror.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1993,1997,1998,2000-2004 Free Software Foundation, Inc.
+/* Copyright (C) 1991-1993,1997,1998,2000-2005 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
@@ -37,10 +37,7 @@ perror_internal (FILE *fp, const char *s, int errnum)
 
   errstring = __strerror_r (errnum, buf, sizeof buf);
 
-  if (_IO_fwide (fp, 0) > 0)
-    (void) __fwprintf (fp, L"%s%s%s\n", s, colon, errstring);
-  else
-    (void) fprintf (fp, "%s%s%s\n", s, colon, errstring);
+  (void) __fxprintf (fp, "%s%s%s\n", L"%s%s%s\n", s, colon, errstring);
 }
 
 
diff --git a/stdio-common/psignal.c b/stdio-common/psignal.c
index 2e6588c692..6c4e823b91 100644
--- a/stdio-common/psignal.c
+++ b/stdio-common/psignal.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004, 2005
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -47,29 +47,17 @@ psignal (int sig, const char *s)
     colon = ": ";
 
   if (sig >= 0 && sig < NSIG && (desc = INTUSE(_sys_siglist)[sig]) != NULL)
-    {
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _(desc));
-      else
-	(void) fprintf (stderr, "%s%s%s\n", s, colon, _(desc));
-    }
+    (void) __fxprintf (NULL, L"%s%s%s\n", "%s%s%s\n", s, colon, _(desc));
   else
     {
       char *buf;
 
       if (__asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0)
-	{
-	  if (_IO_fwide (stderr, 0) > 0)
-	    (void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _("Unknown signal"));
-	  else
-	    (void) fprintf (stderr, "%s%s%s\n", s, colon, _("Unknown signal"));
-	}
+	(void) __fxprintf (NULL, "%s%s%s\n", L"%s%s%s\n",
+			   s, colon, _("Unknown signal"));
       else
 	{
-	  if (_IO_fwide (stderr, 0) > 0)
-	    (void) __fwprintf (stderr, L"%s",  buf);
-	  else
-	    (void) fputs (buf, stderr);
+	  (void) __fxprintf (NULL, L"%s", "%s", buf);
 
 	  free (buf);
 	}
diff --git a/stdlib/fmtmsg.c b/stdlib/fmtmsg.c
index b5d7436956..224ccf133b 100644
--- a/stdlib/fmtmsg.c
+++ b/stdlib/fmtmsg.c
@@ -154,42 +154,22 @@ fmtmsg (long int classification, const char *label, int severity,
       int do_action = (print & action_mask) && action != MM_NULLACT;
       int do_tag = (print & tag_mask) && tag != MM_NULLTAG;
 
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	{
-	  if (__fwprintf (stderr, L"%s%s%s%s%s%s%s%s%s%s\n",
-			  do_label ? label : "",
-			  do_label
-			  && (do_severity | do_text | do_action | do_tag)
-			  ? ": " : "",
-			  do_severity ? severity_rec->string : "",
-			  do_severity && (do_text | do_action | do_tag)
-			  ? ": " : "",
-			  do_text ? text : "",
-			  do_text && (do_action | do_tag) ? "\n" : "",
-			  do_action ? "TO FIX: " : "",
-			  do_action ? action : "",
-			  do_action && do_tag ? "  " : "",
-			  do_tag ? tag : "") < 0)
-	    /* Oh, oh.  An error occurred during the output.  */
-	    result = MM_NOMSG;
-	}
-      else
-#endif
-	if (fprintf (stderr, "%s%s%s%s%s%s%s%s%s%s\n",
-		     do_label ? label : "",
-		     do_label && (do_severity | do_text | do_action | do_tag)
-		     ? ": " : "",
-		     do_severity ? severity_rec->string : "",
-		     do_severity && (do_text | do_action | do_tag) ? ": " : "",
-		     do_text ? text : "",
-		     do_text && (do_action | do_tag) ? "\n" : "",
-		     do_action ? "TO FIX: " : "",
-		     do_action ? action : "",
-		     do_action && do_tag ? "  " : "",
-		     do_tag ? tag : "") < 0)
-	  /* Oh, oh.  An error occurred during the output.  */
-	  result = MM_NOMSG;
+      if (__fxprintf (stderr, "%s%s%s%s%s%s%s%s%s%s\n",
+		      L"%s%s%s%s%s%s%s%s%s%s\n",
+		      do_label ? label : "",
+		      do_label && (do_severity | do_text | do_action | do_tag)
+		      ? ": " : "",
+		      do_severity ? severity_rec->string : "",
+		      do_severity && (do_text | do_action | do_tag)
+		      ? ": " : "",
+		      do_text ? text : "",
+		      do_text && (do_action | do_tag) ? "\n" : "",
+		      do_action ? "TO FIX: " : "",
+		      do_action ? action : "",
+		      do_action && do_tag ? "  " : "",
+		      do_tag ? tag : "") < 0)
+	/* Oh, oh.  An error occurred during the output.  */
+	result = MM_NOMSG;
     }
 
   if (classification & MM_CONSOLE)
diff --git a/sunrpc/auth_unix.c b/sunrpc/auth_unix.c
index 1cf18cb6b3..f4ee1b75e4 100644
--- a/sunrpc/auth_unix.c
+++ b/sunrpc/auth_unix.c
@@ -111,13 +111,8 @@ authunix_create (char *machname, uid_t uid, gid_t gid, int len,
   if (auth == NULL || au == NULL)
     {
 no_memory:
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("authunix_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("authunix_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("authunix_create: out of memory\n"));
       mem_free (auth, sizeof (*auth));
       mem_free (au, sizeof (*au));
       return NULL;
diff --git a/sunrpc/clnt_perr.c b/sunrpc/clnt_perr.c
index 4fa5e62c0f..7fe498f5c5 100644
--- a/sunrpc/clnt_perr.c
+++ b/sunrpc/clnt_perr.c
@@ -155,12 +155,7 @@ libc_hidden_def (clnt_sperror)
 void
 clnt_perror (CLIENT * rpch, const char *msg)
 {
-#ifdef USE_IN_LIBIO
-  if (_IO_fwide (stderr, 0) > 0)
-    (void) __fwprintf (stderr, L"%s", clnt_sperror (rpch, msg));
-  else
-#endif
-    (void) fputs (clnt_sperror (rpch, msg), stderr);
+  (void) __fxprintf (NULL, "%s", L"%s", clnt_sperror (rpch, msg));
 }
 libc_hidden_def (clnt_perror)
 
@@ -289,12 +284,7 @@ libc_hidden_def (clnt_sperrno)
 void
 clnt_perrno (enum clnt_stat num)
 {
-#ifdef USE_IN_LIBIO
-  if (_IO_fwide (stderr, 0) > 0)
-    (void) __fwprintf (stderr, L"%s", clnt_sperrno (num));
-  else
-#endif
-    (void) fputs (clnt_sperrno (num), stderr);
+  (void) __fxprintf (NULL, "%s", L"%s", clnt_sperrno (num));
 }
 
 
@@ -337,12 +327,7 @@ libc_hidden_def (clnt_spcreateerror)
 void
 clnt_pcreateerror (const char *msg)
 {
-#ifdef USE_IN_LIBIO
-  if (_IO_fwide (stderr, 0) > 0)
-    (void) __fwprintf (stderr, L"%s", clnt_spcreateerror (msg));
-  else
-#endif
-    (void) fputs (clnt_spcreateerror (msg), stderr);
+  (void) __fxprintf (NULL, "%s", L"%s", clnt_spcreateerror (msg));
 }
 
 struct auth_errtab
diff --git a/sunrpc/clnt_tcp.c b/sunrpc/clnt_tcp.c
index 5d02cd99cb..f9a64f5de1 100644
--- a/sunrpc/clnt_tcp.c
+++ b/sunrpc/clnt_tcp.c
@@ -128,13 +128,8 @@ clnttcp_create (struct sockaddr_in *raddr, u_long prog, u_long vers,
   if (h == NULL || ct == NULL)
     {
       struct rpc_createerr *ce = &get_rpc_createerr ();
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("clnttcp_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("clnttcp_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("clnttcp_create: out of memory\n"));
       ce->cf_stat = RPC_SYSTEMERROR;
       ce->cf_error.re_errno = ENOMEM;
       goto fooy;
diff --git a/sunrpc/clnt_udp.c b/sunrpc/clnt_udp.c
index f3787dd1a5..fa30a6cb93 100644
--- a/sunrpc/clnt_udp.c
+++ b/sunrpc/clnt_udp.c
@@ -136,13 +136,8 @@ clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version,
   if (cl == NULL || cu == NULL)
     {
       struct rpc_createerr *ce = &get_rpc_createerr ();
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("clntudp_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("clntudp_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("clntudp_create: out of memory\n"));
       ce->cf_stat = RPC_SYSTEMERROR;
       ce->cf_error.re_errno = ENOMEM;
       goto fooy;
diff --git a/sunrpc/clnt_unix.c b/sunrpc/clnt_unix.c
index fae1cd8229..eb96656215 100644
--- a/sunrpc/clnt_unix.c
+++ b/sunrpc/clnt_unix.c
@@ -125,13 +125,8 @@ clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
   if (h == NULL || ct == NULL)
     {
       struct rpc_createerr *ce = &get_rpc_createerr ();
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("clntunix_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("clntunix_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("clntunix_create: out of memory\n"));
       ce->cf_stat = RPC_SYSTEMERROR;
       ce->cf_error.re_errno = ENOMEM;
       goto fooy;
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index 5ac21ffdbd..1344c0bd55 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -125,12 +125,7 @@ registerrpc (u_long prognum, u_long versnum, u_long procnum,
  err_out:
   if (buf == NULL)
     return -1;
-#ifdef USE_IN_LIBIO
-  if (_IO_fwide (stderr, 0) > 0)
-    (void) __fwprintf (stderr, L"%s", buf);
-  else
-#endif
-    (void) fputs (buf, stderr);
+  (void) __fxprintf (NULL, "%s", L"%s", buf);
   free (buf);
   return -1;
 }
@@ -189,12 +184,7 @@ universal (struct svc_req *rqstp, SVCXPRT *transp_l)
  err_out2:
   if (buf == NULL)
     exit (1);
-#ifdef USE_IN_LIBIO
-  if (_IO_fwide (stderr, 0) > 0)
-    __fwprintf (stderr, L"%s", buf);
-  else
-#endif
-    fputs (buf, stderr);
+  __fxprintf (NULL, "%s", L"%s", buf);
   free (buf);
   exit (1);
 }
diff --git a/sunrpc/svc_tcp.c b/sunrpc/svc_tcp.c
index 873d39d52a..5c646a46c7 100644
--- a/sunrpc/svc_tcp.c
+++ b/sunrpc/svc_tcp.c
@@ -176,12 +176,8 @@ svctcp_create (int sock, u_int sendsize, u_int recvsize)
   xprt = (SVCXPRT *) mem_alloc (sizeof (SVCXPRT));
   if (r == NULL || xprt == NULL)
     {
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s", _("svctcp_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("svctcp_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("svctcp_create: out of memory\n"));
       mem_free (r, sizeof (*r));
       mem_free (xprt, sizeof (SVCXPRT));
       return NULL;
@@ -219,13 +215,8 @@ makefd_xprt (int fd, u_int sendsize, u_int recvsize)
   cd = (struct tcp_conn *) mem_alloc (sizeof (struct tcp_conn));
   if (xprt == (SVCXPRT *) NULL || cd == NULL)
     {
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("svc_tcp: makefd_xprt: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("svc_tcp: makefd_xprt: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("svc_tcp: makefd_xprt: out of memory\n"));
       mem_free (xprt, sizeof (SVCXPRT));
       mem_free (cd, sizeof (struct tcp_conn));
       return NULL;
diff --git a/sunrpc/svc_udp.c b/sunrpc/svc_udp.c
index 45f99440b2..62fd97e2f7 100644
--- a/sunrpc/svc_udp.c
+++ b/sunrpc/svc_udp.c
@@ -149,12 +149,8 @@ svcudp_bufcreate (sock, sendsz, recvsz)
   buf = mem_alloc (((MAX (sendsz, recvsz) + 3) / 4) * 4);
   if (xprt == NULL || su == NULL || buf == NULL)
     {
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s", _("svcudp_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("svcudp_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("svcudp_create: out of memory\n"));
       mem_free (xprt, sizeof (SVCXPRT));
       mem_free (su, sizeof (*su));
       mem_free (buf, ((MAX (sendsz, recvsz) + 3) / 4) * 4);
@@ -176,14 +172,8 @@ svcudp_bufcreate (sock, sendsz, recvsz)
        + sizeof(struct cmsghdr) + sizeof (struct in_pktinfo))
       > sizeof (xprt->xp_pad))
     {
-# ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("svcudp_create: xp_pad is too small for IP_PKTINFO\n"));
-      else
-# endif
-	(void) fputs (_("svcudp_create: xp_pad is too small for IP_PKTINFO\n"),
-		      stderr);
+      (void) __fxprintf (NULL,"%s",  L"%s", _("\
+svcudp_create: xp_pad is too small for IP_PKTINFO\n"));
       return NULL;
     }
   pad = 1;
@@ -411,16 +401,8 @@ svcudp_destroy (xprt)
 
 #define SPARSENESS 4		/* 75% sparse */
 
-#ifdef USE_IN_LIBIO
-# define CACHE_PERROR(msg)	\
-	if (_IO_fwide (stderr, 0) > 0)					      \
-		(void) __fwprintf(stderr, L"%s\n", msg);		      \
-	else								      \
-		(void) fprintf(stderr, "%s\n", msg)
-#else
-# define CACHE_PERROR(msg)	\
-	(void) fprintf(stderr,"%s\n", msg)
-#endif
+#define CACHE_PERROR(msg)	\
+	(void) __fxprintf(NULL, "%s\n", L"%s\n", msg)
 
 #define ALLOC(type, size)	\
 	(type *) mem_alloc((unsigned) (sizeof(type) * (size)))
diff --git a/sunrpc/svc_unix.c b/sunrpc/svc_unix.c
index d95e884434..7672fcda48 100644
--- a/sunrpc/svc_unix.c
+++ b/sunrpc/svc_unix.c
@@ -173,12 +173,7 @@ svcunix_create (int sock, u_int sendsize, u_int recvsize, char *path)
   xprt = (SVCXPRT *) mem_alloc (sizeof (SVCXPRT));
   if (r == NULL || xprt == NULL)
     {
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	__fwprintf (stderr, L"%s", _("svcunix_create: out of memory\n"));
-      else
-#endif
-	fputs (_("svcunix_create: out of memory\n"), stderr);
+      __fxprintf (NULL, "%s", L"%s", _("svcunix_create: out of memory\n"));
       mem_free (r, sizeof (*r));
       mem_free (xprt, sizeof (SVCXPRT));
       return NULL;
@@ -216,13 +211,8 @@ makefd_xprt (int fd, u_int sendsize, u_int recvsize)
   cd = (struct unix_conn *) mem_alloc (sizeof (struct unix_conn));
   if (xprt == (SVCXPRT *) NULL || cd == (struct unix_conn *) NULL)
     {
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s",
-			   _("svc_unix: makefd_xprt: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("svc_unix: makefd_xprt: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("svc_unix: makefd_xprt: out of memory\n"));
       mem_free (xprt, sizeof (SVCXPRT));
       mem_free (cd, sizeof (struct unix_conn));
       return NULL;
diff --git a/sunrpc/xdr.c b/sunrpc/xdr.c
index 1f25e3e9c0..2f64c5b3fa 100644
--- a/sunrpc/xdr.c
+++ b/sunrpc/xdr.c
@@ -563,12 +563,8 @@ xdr_bytes (xdrs, cpp, sizep, maxsize)
 	}
       if (sp == NULL)
 	{
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stderr, 0) > 0)
-	    (void) __fwprintf (stderr, L"%s", _("xdr_bytes: out of memory\n"));
-	  else
-#endif
-	    (void) fputs (_("xdr_bytes: out of memory\n"), stderr);
+	  (void) __fxprintf (NULL, "%s", L"%s",
+			     _("xdr_bytes: out of memory\n"));
 	  return FALSE;
 	}
       /* fall into ... */
@@ -720,13 +716,8 @@ xdr_string (xdrs, cpp, maxsize)
 	*cpp = sp = (char *) mem_alloc (nodesize);
       if (sp == NULL)
 	{
-#ifdef USE_IN_LIBIO
-	  if (_IO_fwide (stderr, 0) > 0)
-	    (void) __fwprintf (stderr, L"%s",
-			       _("xdr_string: out of memory\n"));
-	  else
-#endif
-	    (void) fputs (_("xdr_string: out of memory\n"), stderr);
+	  (void) __fxprintf (NULL, "%s", L"%s",
+			     _("xdr_string: out of memory\n"));
 	  return FALSE;
 	}
       sp[size] = 0;
diff --git a/sunrpc/xdr_array.c b/sunrpc/xdr_array.c
index 9f67e7fe62..12c78d4218 100644
--- a/sunrpc/xdr_array.c
+++ b/sunrpc/xdr_array.c
@@ -105,13 +105,8 @@ xdr_array (xdrs, addrp, sizep, maxsize, elsize, elproc)
 	*addrp = target = mem_alloc (nodesize);
 	if (target == NULL)
 	  {
-#ifdef USE_IN_LIBIO
-	    if (_IO_fwide (stderr, 0) > 0)
-	      (void) __fwprintf (stderr, L"%s",
-				 _("xdr_array: out of memory\n"));
-	    else
-#endif
-	      (void) fputs (_("xdr_array: out of memory\n"), stderr);
+	    (void) __fxprintf (NULL, "%s", L"%s",
+			       _("xdr_array: out of memory\n"));
 	    return FALSE;
 	  }
 	__bzero (target, nodesize);
diff --git a/sunrpc/xdr_rec.c b/sunrpc/xdr_rec.c
index 5e59c88523..e841faa6f1 100644
--- a/sunrpc/xdr_rec.c
+++ b/sunrpc/xdr_rec.c
@@ -153,12 +153,8 @@ xdrrec_create (XDR *xdrs, u_int sendsize,
 
   if (rstrm == NULL || buf == NULL)
     {
-#ifdef USE_IN_LIBIO
-      if (_IO_fwide (stderr, 0) > 0)
-	(void) __fwprintf (stderr, L"%s", _("xdrrec_create: out of memory\n"));
-      else
-#endif
-	(void) fputs (_("xdrrec_create: out of memory\n"), stderr);
+      (void) __fxprintf (NULL, "%s", L"%s",
+			 _("xdrrec_create: out of memory\n"));
       mem_free (rstrm, sizeof (RECSTREAM));
       mem_free (buf, sendsize + recvsize + BYTES_PER_XDR_UNIT);
       /*
diff --git a/sunrpc/xdr_ref.c b/sunrpc/xdr_ref.c
index ab706d7f84..68460bdc39 100644
--- a/sunrpc/xdr_ref.c
+++ b/sunrpc/xdr_ref.c
@@ -82,13 +82,8 @@ xdr_reference (xdrs, pp, size, proc)
 	*pp = loc = (caddr_t) mem_alloc (size);
 	if (loc == NULL)
 	  {
-#ifdef USE_IN_LIBIO
-	    if (_IO_fwide (stderr, 0) > 0)
-	      (void) __fwprintf (stderr, L"%s",
-				 _("xdr_reference: out of memory\n"));
-	    else
-#endif
-	      (void) fputs (_("xdr_reference: out of memory\n"), stderr);
+	    (void) __fxprintf (NULL, "%s", L"%s",
+			       _("xdr_reference: out of memory\n"));
 	    return FALSE;
 	  }
 	__bzero (loc, (int) size);
diff --git a/sysdeps/generic/wordexp.c b/sysdeps/generic/wordexp.c
index 06d38f6b24..41bbf426d0 100644
--- a/sysdeps/generic/wordexp.c
+++ b/sysdeps/generic/wordexp.c
@@ -1798,12 +1798,7 @@ envsubst:
 	      if (str[0] == '\0')
 		str = _("parameter null or not set");
 
-#ifdef USE_IN_LIBIO
-	      if (_IO_fwide (stderr, 0) > 0)
-		__fwprintf (stderr, L"%s: %s\n", env, str);
-	      else
-#endif
-		fprintf (stderr, "%s: %s\n", env, str);
+	      __fxprintf (NULL, "%s: %s\n", L"%s: %s\n", env, str);
 	    }
 
 	  if (free_value)
diff --git a/wcsmbs/bits/wchar2.h b/wcsmbs/bits/wchar2.h
index 12f478eed8..c102948f11 100644
--- a/wcsmbs/bits/wchar2.h
+++ b/wcsmbs/bits/wchar2.h
@@ -285,3 +285,114 @@ fgetws_unlocked (wchar_t *__restrict __s, int __n, FILE *__restrict __stream)
   return __fgetws_unlocked_alias (__s, __n, __stream);
 }
 #endif
+
+
+extern size_t __wcrtomb_chk (char *__s, wchar_t __wchar, mbstate_t *__p,
+			  size_t __buflen) __THROW __wur;
+extern size_t __REDIRECT_NTH (__wcrtomb_alias,
+			      (char *__restrict __s, wchar_t __wchar,
+			       mbstate_t *__restrict __ps), wcrtomb) __wur;
+
+extern __always_inline __wur size_t
+wcrtomb (char *__s, wchar_t __wchar, mbstate_t *__ps)
+{
+  /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
+     But this would only disturb the namespace.  So we define our own
+     version here.  */
+#define __WCHAR_MB_LEN_MAX	16
+#if defined MB_LEN_MAX && MB_LEN_MAX != __WCHAR_MB_LEN_MAX
+# error "Assumed value of MB_LEN_MAX wrong"
+#endif
+  if (__bos (__s) != (size_t) -1 && __WCHAR_MB_LEN_MAX > __bos (__s))
+    return __wcrtomb_chk (__s, __wchar, __ps, __bos (__s));
+  return __wcrtomb_alias (__s, __wchar, __ps);
+}
+
+
+extern size_t __mbsrtowcs_chk (wchar_t *__restrict __dst,
+			       __const char **__restrict __src,
+			       size_t __len, mbstate_t *__restrict __ps,
+			       size_t __dstlen) __THROW;
+extern size_t __REDIRECT_NTH (__mbsrtowcs_alias,
+			      (wchar_t *__restrict __dst,
+			       __const char **__restrict __src,
+			       size_t __len, mbstate_t *__restrict __ps),
+			      mbsrtowcs);
+
+extern __always_inline size_t
+mbsrtowcs (wchar_t *__restrict __dst, __const char **__restrict __src,
+	    size_t __len, mbstate_t *__restrict __ps)
+{
+  if (__bos (__dst) != (size_t) -1
+      && (!__builtin_constant_p (__len)
+	  || __len * sizeof (wchar_t) > __bos (__dst)))
+    return __mbsrtowcs_chk (__dst, __src, __len, __ps, __bos (__dst));
+  return __mbsrtowcs_alias (__dst, __src, __len, __ps);
+}
+
+
+extern size_t __wcsrtombs_chk (char *__restrict __dst,
+			       __const wchar_t **__restrict __src,
+			       size_t __len, mbstate_t *__restrict __ps,
+			       size_t __dstlen) __THROW;
+extern size_t __REDIRECT_NTH (__wcsrtombs_alias,
+			      (char *__restrict __dst,
+			       __const wchar_t **__restrict __src,
+			       size_t __len, mbstate_t *__restrict __ps),
+			      wcsrtombs);
+
+extern __always_inline size_t
+wcsrtombs (char *__restrict __dst, __const wchar_t **__restrict __src,
+	   size_t __len, mbstate_t *__restrict __ps)
+{
+  if (__bos (__dst) != (size_t) -1
+      && (!__builtin_constant_p (__len) || __len > __bos (__dst)))
+    return __wcsrtombs_chk (__dst, __src, __len, __ps, __bos (__dst));
+  return __wcsrtombs_alias (__dst, __src, __len, __ps);
+}
+
+
+#ifdef __USE_GNU
+extern size_t __mbsnrtowcs_chk (wchar_t *__restrict __dst,
+				__const char **__restrict __src, size_t __nmc,
+				size_t __len, mbstate_t *__restrict __ps,
+				size_t __dstlen) __THROW;
+extern size_t __REDIRECT_NTH (__mbsnrtowcs_alias,
+			      (wchar_t *__restrict __dst,
+			       __const char **__restrict __src, size_t __nmc,
+			       size_t __len, mbstate_t *__restrict __ps),
+			      mbsnrtowcs);
+
+extern __always_inline size_t
+mbsnrtowcs (wchar_t *__restrict __dst, __const char **__restrict __src,
+	    size_t __nmc, size_t __len, mbstate_t *__restrict __ps)
+{
+  if (__bos (__dst) != (size_t) -1
+      && (!__builtin_constant_p (__len)
+	  || __len * sizeof (wchar_t) > __bos (__dst)))
+    return __mbsnrtowcs_chk (__dst, __src, __nmc, __len, __ps, __bos (__dst));
+  return __mbsnrtowcs_alias (__dst, __src, __nmc, __len, __ps);
+}
+
+
+extern size_t __wcsnrtombs_chk (char *__restrict __dst,
+				__const wchar_t **__restrict __src,
+				size_t __nwc, size_t __len,
+				mbstate_t *__restrict __ps, size_t __dstlen)
+     __THROW;
+extern size_t __REDIRECT_NTH (__wcsnrtombs_alias,
+			      (char *__restrict __dst,
+			       __const wchar_t **__restrict __src,
+			       size_t __nwc, size_t __len,
+			       mbstate_t *__restrict __ps), wcsnrtombs);
+
+extern __always_inline size_t
+wcsnrtombs (char *__restrict __dst, __const wchar_t **__restrict __src,
+	    size_t __nwc, size_t __len, mbstate_t *__restrict __ps)
+{
+  if (__bos (__dst) != (size_t) -1
+      && (!__builtin_constant_p (__len) || __len > __bos (__dst)))
+    return __wcsnrtombs_chk (__dst, __src, __nwc, __len, __ps, __bos (__dst));
+  return __wcsnrtombs_alias (__dst, __src, __nwc, __len, __ps);
+}
+#endif