[PATCH] error, warn, warnx: Use __fxprintf for wide printing [BZ #23519]
Gabriel F. T. Gomes
gabriel@inconstante.eti.br
Tue Aug 14 13:22:00 GMT 2018
On Tue, 14 Aug 2018, Florian Weimer wrote:
> 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)
>+ __vfxprintf (stderr, format, ap);
>+ __fxprintf (stderr, "\n");
Is it true that you can remove the call to 'convert_and_print' because
__fxprintf and __vfxprintf already check the wideness of the output and
convert (indirectly via locked_vfxprintf)?
It appears so, and your patch looks good to me.
>--- a/misc/error.c
>+++ b/misc/error.c
>@@ -203,72 +203,14 @@ static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3))
> error_tail (int status, int errnum, const char *message, va_list args)
> {
> #if _LIBC
>+ int ret = __vfxprintf (stderr, message, args);
>+ if (ret < 0 && errno == ENOMEM && _IO_fwide (stderr, 0) > 0)
>+ /* Leave a trace in case the heap allocation of the message string
>+ failed. */
>+ fputws_unlocked (L"out of memory\n", stderr);
>+#else
>+ vfprintf (stderr, message, args);
> #endif
Just out of curiosity, how do we know that other programs use this code
outside of glibc? (assuming this is the reason for the _LIBC check).
More information about the Libc-alpha
mailing list