about summary refs log tree commit diff
path: root/misc/err.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-08-14 13:36:10 +0200
committerFlorian Weimer <fweimer@redhat.com>2018-08-14 17:54:49 +0200
commitfdb16de38705ccff0dbf38af9956eb4165710106 (patch)
treec02ed2ab338c6caabe2aa69f2c52ab6dac545d3d /misc/err.c
parent599cf3976679e1b345307d9c02057f02aa95528f (diff)
downloadglibc-fdb16de38705ccff0dbf38af9956eb4165710106.tar.gz
glibc-fdb16de38705ccff0dbf38af9956eb4165710106.tar.xz
glibc-fdb16de38705ccff0dbf38af9956eb4165710106.zip
error, warn, warnx: Use __fxprintf for wide printing [BZ #23519]
Also introduce the __vfxprintf function.
Diffstat (limited to 'misc/err.c')
-rw-r--r--misc/err.c82
1 files changed, 9 insertions, 73 deletions
diff --git a/misc/err.c b/misc/err.c
index 2b836e8358..b6afe65516 100644
--- a/misc/err.c
+++ b/misc/err.c
@@ -37,68 +37,14 @@ extern char *__progname;
   va_end (ap);								      \
 }
 
-static void
-convert_and_print (const char *format, __gnuc_va_list ap)
-{
-#define ALLOCA_LIMIT	2000
-  size_t len;
-  wchar_t *wformat = NULL;
-  mbstate_t st;
-  size_t res;
-  const char *tmp;
-
-  if (format == NULL)
-    return;
-
-  len = strlen (format) + 1;
-
-  do
-    {
-      if (len < ALLOCA_LIMIT)
-	wformat = (wchar_t *) alloca (len * sizeof (wchar_t));
-      else
-	{
-	  if (wformat != NULL && len / 2 < ALLOCA_LIMIT)
-	    wformat = NULL;
-
-	  wformat = (wchar_t *) realloc (wformat, len * sizeof (wchar_t));
-
-	  if (wformat == NULL)
-	    {
-	      fputws_unlocked (L"out of memory\n", stderr);
-	      return;
-	    }
-	}
-
-      memset (&st, '\0', sizeof (st));
-      tmp =format;
-    }
-  while ((res = __mbsrtowcs (wformat, &tmp, len, &st)) == len);
-
-  if (res == (size_t) -1)
-    /* The string cannot be converted.  */
-    wformat = (wchar_t *) L"???";
-
-  __vfwprintf (stderr, wformat, ap);
-}
-
 void
 vwarnx (const char *format, __gnuc_va_list ap)
 {
   flockfile (stderr);
-  if (_IO_fwide (stderr, 0) > 0)
-    {
-      __fwprintf (stderr, L"%s: ", __progname);
-      convert_and_print (format, ap);
-      putwc_unlocked (L'\n', stderr);
-    }
-  else
-    {
-      fprintf (stderr, "%s: ", __progname);
-      if (format)
-	vfprintf (stderr, format, ap);
-      putc_unlocked ('\n', stderr);
-    }
+  __fxprintf (stderr, "%s: ", __progname);
+  if (format != NULL)
+    __vfxprintf (stderr, format, ap);
+  __fxprintf (stderr, "\n");
   funlockfile (stderr);
 }
 libc_hidden_def (vwarnx)
@@ -109,27 +55,17 @@ vwarn (const char *format, __gnuc_va_list ap)
   int error = errno;
 
   flockfile (stderr);
-  if (_IO_fwide (stderr, 0) > 0)
+  if (format != NULL)
     {
-      __fwprintf (stderr, L"%s: ", __progname);
-      if (format)
-	{
-	  convert_and_print (format, ap);
-	  fputws_unlocked (L": ", stderr);
-	}
+      __fxprintf (stderr, "%s: ", __progname);
+      __vfxprintf (stderr, format, ap);
       __set_errno (error);
-      __fwprintf (stderr, L"%m\n");
+      __fxprintf (stderr, ": %m\n");
     }
   else
     {
-      fprintf (stderr, "%s: ", __progname);
-      if (format)
-	{
-	  vfprintf (stderr, format, ap);
-	  fputs_unlocked (": ", stderr);
-	}
       __set_errno (error);
-      fprintf (stderr, "%m\n");
+      __fxprintf (stderr, "%s: %m\n", __progname);
     }
   funlockfile (stderr);
 }