bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* new modules vasnwprintf, vasnwprintf-posix
@ 2023-03-17 12:15 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2023-03-17 12:15 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 2913 bytes --]

The libintl of GNU gettext contains a copy of vasnprintf.c, compiled with
'#define WIDE_CHAR_VERSION 1', that is the basis of *wprintf functions.

Before extending vasnprintf to be ISO C 23 compliant, it's useful to move
this vasnwprintf function to Gnulib. Reasons:
  - It makes maintenance easier to have all the *printf code in one place,
    not 80% in Gnulib and 20% in libintl.
  - The unit tests of Gnulib can be ported to the vasnwprintf case. And
    indeed, this shows that the code in libintl was buggy: Since _snwprintf
    has a different return value convention than snprintf, the WIDE_CHAR_VERSION
    instantiation did not work right when the provided buffer was too small.

This set of patches fixes that, and prepares for a more POSIX + ISO C compliant
variant of *printf in libintl.


2023-03-17  Bruno Haible  <bruno@clisp.org>

	vasnprintf, vasnwprintf: Include all necessary workarounds in libintl.
	* lib/vasnprintf.c: Remove IN_LIBINTL special-casing.

2023-03-17  Bruno Haible  <bruno@clisp.org>

	vasnwprintf-posix: Add tests.
	* tests/test-vasnwprintf-posix.c: New file, based on
	tests/test-vasnprintf-posix.c.
	* tests/test-vasnwprintf-posix2.sh: New file, based on
	tests/test-vasnprintf-posix2.sh.
	* tests/test-vasnwprintf-posix2.c: New file, based on
	tests/test-vasnprintf-posix2.c.
	* tests/test-vasnwprintf-posix3.c: New file, based on
	tests/test-vasnprintf-posix3.c.
	* modules/vasnwprintf-posix-tests: New file, based on
	modules/vasnprintf-posix-tests.

	vasnwprintf-posix: New module.
	* m4/vasnwprintf-posix.m4: New file.
	* modules/vasnwprintf-posix: New file, based on
	modules/vasnprintf-posix.

2023-03-17  Bruno Haible  <bruno@clisp.org>

	vasnprintf-posix: Relicense under LGPLv2+.
	* modules/vasnprintf-posix (License): Change to LGPLv2+.

2023-03-17  Bruno Haible  <bruno@clisp.org>

	vasnwprintf: Add tests.
	* tests/test-vasnwprintf.c: New file, based on tests/test-vasnprintf.c.
	* modules/vasnwprintf-tests: New file, based on
	modules/vasnprintf-tests.

	vasnwprintf: New module.
	* lib/vasnprintf.c: Enable more code for WIDE_CHAR_VERSION, because
	snwprintf()/_snwprintf() (Windows) and swprintf() (Unix) don't return
	the needed buffer size, like snprintf does.
	* lib/wprintf-parse.h: New file, based on lib/printf-parse.h and
	gettext/gettext-runtime/intl/wprintf-parse.h.
	* lib/wprintf-parse.c: New file, based on
	gettext/gettext-runtime/intl/printf.c.
	* lib/vasnwprintf.h: New file, based on lib/vasnprintf.h and
	gettext/gettext-runtime/intl/vasnwprintf.h.
	* lib/vasnwprintf.c: New file.
	* lib/asnwprintf.c: New file, based on lib/asnprintf.c.
	* m4/vasnprintf.m4 (gl_FUNC_VASNWPRINTF): New macro.
	(gl_PREREQ_VASNXPRINTF): New macro, extracted from gl_PREREQ_VASNPRINTF.
	(gl_PREREQ_VASNPRINTF): Invoke it. Don't test for wcsnlen and mbrtowc.
	(gl_PREREQ_VASNWPRINTF): New macro.
	* modules/vasnwprintf: New file, based on modules/vasnprintf.


[-- Attachment #2: 0001-vasnwprintf-New-module.patch --]
[-- Type: text/x-patch, Size: 28246 bytes --]

From cc90bee0e183c03c0ad05a14f69e59e20c1a6392 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 17 Mar 2023 12:25:37 +0100
Subject: [PATCH 1/6] vasnwprintf: New module.

* lib/vasnprintf.c: Enable more code for WIDE_CHAR_VERSION, because
snwprintf()/_snwprintf() (Windows) and swprintf() (Unix) don't return
the needed buffer size, like snprintf does.
* lib/wprintf-parse.h: New file, based on lib/printf-parse.h and
gettext/gettext-runtime/intl/wprintf-parse.h.
* lib/wprintf-parse.c: New file, based on
gettext/gettext-runtime/intl/printf.c.
* lib/vasnwprintf.h: New file, based on lib/vasnprintf.h and
gettext/gettext-runtime/intl/vasnwprintf.h.
* lib/vasnwprintf.c: New file.
* lib/asnwprintf.c: New file, based on lib/asnprintf.c.
* m4/vasnprintf.m4 (gl_FUNC_VASNWPRINTF): New macro.
(gl_PREREQ_VASNXPRINTF): New macro, extracted from gl_PREREQ_VASNPRINTF.
(gl_PREREQ_VASNPRINTF): Invoke it. Don't test for wcsnlen and mbrtowc.
(gl_PREREQ_VASNWPRINTF): New macro.
* modules/vasnwprintf: New file, based on modules/vasnprintf.
---
 ChangeLog           | 20 +++++++++++
 lib/asnwprintf.c    | 34 ++++++++++++++++++
 lib/vasnprintf.c    | 83 ++++++++++++++++++++++++++-----------------
 lib/vasnwprintf.c   | 18 ++++++++++
 lib/vasnwprintf.h   | 63 +++++++++++++++++++++++++++++++++
 lib/wprintf-parse.c | 31 ++++++++++++++++
 lib/wprintf-parse.h | 86 +++++++++++++++++++++++++++++++++++++++++++++
 m4/vasnprintf.m4    | 44 ++++++++++++++++++-----
 modules/vasnwprintf | 53 ++++++++++++++++++++++++++++
 9 files changed, 391 insertions(+), 41 deletions(-)
 create mode 100644 lib/asnwprintf.c
 create mode 100644 lib/vasnwprintf.c
 create mode 100644 lib/vasnwprintf.h
 create mode 100644 lib/wprintf-parse.c
 create mode 100644 lib/wprintf-parse.h
 create mode 100644 modules/vasnwprintf

diff --git a/ChangeLog b/ChangeLog
index 40f9259113..d1e7222441 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2023-03-17  Bruno Haible  <bruno@clisp.org>
+
+	vasnwprintf: New module.
+	* lib/vasnprintf.c: Enable more code for WIDE_CHAR_VERSION, because
+	snwprintf()/_snwprintf() (Windows) and swprintf() (Unix) don't return
+	the needed buffer size, like snprintf does.
+	* lib/wprintf-parse.h: New file, based on lib/printf-parse.h and
+	gettext/gettext-runtime/intl/wprintf-parse.h.
+	* lib/wprintf-parse.c: New file, based on
+	gettext/gettext-runtime/intl/printf.c.
+	* lib/vasnwprintf.h: New file, based on lib/vasnprintf.h and
+	gettext/gettext-runtime/intl/vasnwprintf.h.
+	* lib/vasnwprintf.c: New file.
+	* lib/asnwprintf.c: New file, based on lib/asnprintf.c.
+	* m4/vasnprintf.m4 (gl_FUNC_VASNWPRINTF): New macro.
+	(gl_PREREQ_VASNXPRINTF): New macro, extracted from gl_PREREQ_VASNPRINTF.
+	(gl_PREREQ_VASNPRINTF): Invoke it. Don't test for wcsnlen and mbrtowc.
+	(gl_PREREQ_VASNWPRINTF): New macro.
+	* modules/vasnwprintf: New file, based on modules/vasnprintf.
+
 2023-03-16  Bruno Haible  <bruno@clisp.org>
 
 	strtol, strtoll, strtoul, strtoull: Make ISO C 23 compliant.
diff --git a/lib/asnwprintf.c b/lib/asnwprintf.c
new file mode 100644
index 0000000000..a2524263e6
--- /dev/null
+++ b/lib/asnwprintf.c
@@ -0,0 +1,34 @@
+/* Formatted output to strings.
+   Copyright (C) 1999-2023 Free Software Foundation, Inc.
+
+   This file 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.
+
+   This file 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 this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "vasnwprintf.h"
+
+#include <stdarg.h>
+
+wchar_t *
+asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...)
+{
+  va_list args;
+  wchar_t *result;
+
+  va_start (args, format);
+  result = vasnwprintf (resultbuf, lengthp, format, args);
+  va_end (args);
+  return result;
+}
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 72b8cdbfa6..4354fbe67c 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -241,7 +241,7 @@ local_strnlen (const char *string, size_t maxlen)
 # endif
 #endif
 
-#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
+#if (((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
 # if HAVE_WCSLEN
 #  define local_wcslen wcslen
 # else
@@ -264,7 +264,7 @@ local_wcslen (const wchar_t *s)
 # endif
 #endif
 
-#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
+#if (!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
 # if HAVE_WCSNLEN
 #  define local_wcsnlen wcsnlen
 # else
@@ -1604,7 +1604,7 @@ is_borderline (const char *digits, size_t precision)
 
 #endif
 
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
 
 /* Use a different function name, to make it possible that the 'wchar_t'
    parametrization and the 'char' parametrization get compiled in the same
@@ -2394,7 +2394,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   }
               }
 #endif
-#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T
+#if (!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T
             else if (dp->conversion == 's'
 # if WIDE_CHAR_VERSION
                      && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
@@ -4723,10 +4723,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
                 int has_width;
 #endif
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
                 size_t width;
 #endif
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
                 int has_precision;
                 size_t precision;
 #endif
@@ -4755,7 +4755,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
                 has_width = 0;
 #endif
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
                 width = 0;
                 if (dp->width_start != dp->width_end)
                   {
@@ -4789,7 +4789,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   }
 #endif
 
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
                 has_precision = 0;
                 precision = 6;
                 if (dp->precision_start != dp->precision_end)
@@ -4988,47 +4988,63 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #endif
                   *fbp = dp->conversion;
 #if USE_SNPRINTF
-# if ((HAVE_SNPRINTF_RETVAL_C99 && HAVE_SNPRINTF_TRUNCATION_C99)            \
+                /* Decide whether to pass %n in the format string
+                   to SNPRINTF.  */
+# if ((!WIDE_CHAR_VERSION                                                   \
+       && (HAVE_SNPRINTF_RETVAL_C99 && HAVE_SNPRINTF_TRUNCATION_C99))       \
       || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3))       \
           && !defined __UCLIBC__)                                           \
       || (defined __APPLE__ && defined __MACH__)                            \
       || defined __ANDROID__                                                \
       || (defined _WIN32 && ! defined __CYGWIN__))
-                /* On systems where we know that snprintf's return value
-                   conforms to ISO C 99 (HAVE_SNPRINTF_RETVAL_C99) and that
-                   snprintf always produces NUL-terminated strings
-                   (HAVE_SNPRINTF_TRUNCATION_C99), it is possible to avoid
-                   using %n.  And it is desirable to do so, because more and
-                   more platforms no longer support %n, for "security reasons".
-                   In particular, the following platforms:
+                /* We can avoid passing %n and instead rely on SNPRINTF's
+                   return value if
+                     - !WIDE_CHAR_VERSION, because if WIDE_CHAR_VERSION,
+                       snwprintf()/_snwprintf() (Windows) and swprintf() (Unix)
+                       don't return the needed buffer size, and
+                     - we're compiling for a system where we know
+                       - that snprintf's return value conforms to ISO C 99
+                         (HAVE_SNPRINTF_RETVAL_C99) and
+                       - that snprintf always produces NUL-terminated strings
+                         (HAVE_SNPRINTF_TRUNCATION_C99).
+                   And it is desirable to do so, because more and more platforms
+                   no longer support %n, for "security reasons".  */
+                /* On specific platforms, listed below, we *must* avoid %n.
+                   In the case
+                     !WIDE_CHAR_VERSION && HAVE_SNPRINTF_RETVAL_C99 && !USE_MSVC__SNPRINTF
+                   we can rely on the return value of snprintf instead.  Whereas
+                   in the opposite case
+                     WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
+                   we need to make room based on an estimation, computed by
+                   MAX_ROOM_NEEDED.  */
+                /* The following platforms forbid %n:
                      - On glibc2 systems from 2004-10-18 or newer, the use of
                        %n in format strings in writable memory may crash the
                        program (if compiled with _FORTIFY_SOURCE=2).
-                     - On Mac OS X 10.13 or newer, the use of %n in format
+                     - On macOS 10.13 or newer, the use of %n in format
                        strings in writable memory by default crashes the
                        program.
                      - On Android, starting on 2018-03-07, the use of %n in
                        format strings produces a fatal error (see
                        <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>).
-                   On these platforms, HAVE_SNPRINTF_RETVAL_C99 and
-                   HAVE_SNPRINTF_TRUNCATION_C99 are 1. We have listed them
-                   explicitly in the condition above, in case of cross-
-                   compilation (just to be sure).  */
-                /* On native Windows systems (such as mingw), we can avoid using
-                   %n because:
+                     - On native Windows systems (such as mingw) where the OS is
+                       Windows Vista, the use of %n in format strings by default
+                       crashes the program. See
+                         <https://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
+                         <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output>
+                   On the first three of these platforms, if !WIDE_CHAR_VERSION,
+                   it is not a big deal to avoid %n, because on these platforms,
+                   HAVE_SNPRINTF_RETVAL_C99 and HAVE_SNPRINTF_TRUNCATION_C99 are
+                   1.
+                   On native Windows, if !WIDE_CHAR_VERSION, it's not a big deal
+                   either because:
                      - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
                        snprintf does not write more than the specified number
                        of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes
                        '4', '5', '6' into buf, not '4', '5', '\0'.)
                      - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf
                        allows us to recognize the case of an insufficient
-                       buffer size: it returns -1 in this case.
-                   On native Windows systems (such as mingw) where the OS is
-                   Windows Vista, the use of %n in format strings by default
-                   crashes the program. See
-                     <https://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
-                     <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output>
-                   So we should avoid %n in this situation.  */
+                       buffer size: it returns -1 in this case.  */
                 fbp[1] = '\0';
 # else           /* AIX <= 5.1, HP-UX, IRIX, OSF/1, Solaris <= 9, BeOS */
                 fbp[1] = '%';
@@ -5271,12 +5287,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                             /* Look at the snprintf() return value.  */
                             if (retcount < 0)
                               {
-# if !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
+# if WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
                                 /* HP-UX 10.20 snprintf() is doubly deficient:
                                    It doesn't understand the '%n' directive,
                                    *and* it returns -1 (rather than the length
                                    that would have been required) when the
                                    buffer is too small.
+                                   Likewise, in case of WIDE_CHAR_VERSION, the
+                                   functions snwprintf()/_snwprintf() (Windows)
+                                   or swprintf() (Unix).
                                    But a failure at this point can also come
                                    from other reasons than a too small buffer,
                                    such as an invalid wide string argument to
@@ -5697,7 +5716,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
     errno = ENOMEM;
     goto fail_with_errno;
 
-#if ENABLE_UNISTDIO || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T)
+#if ENABLE_UNISTDIO || ((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T)
   fail_with_EILSEQ:
     errno = EILSEQ;
     goto fail_with_errno;
diff --git a/lib/vasnwprintf.c b/lib/vasnwprintf.c
new file mode 100644
index 0000000000..db958e049d
--- /dev/null
+++ b/lib/vasnwprintf.c
@@ -0,0 +1,18 @@
+/* vswprintf with automatic memory allocation.
+   Copyright (C) 2003-2023 Free Software Foundation, Inc.
+
+   This file 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.
+
+   This file 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 this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#define WIDE_CHAR_VERSION 1
+#include "vasnprintf.c"
diff --git a/lib/vasnwprintf.h b/lib/vasnwprintf.h
new file mode 100644
index 0000000000..783eaf8be9
--- /dev/null
+++ b/lib/vasnwprintf.h
@@ -0,0 +1,63 @@
+/* vswprintf with automatic memory allocation.
+   Copyright (C) 2002-2023 Free Software Foundation, Inc.
+
+   This program 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.
+
+   This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _VASNWPRINTF_H
+#define _VASNWPRINTF_H
+
+/* Get va_list.  */
+#include <stdarg.h>
+
+/* Get wchar_t, size_t.  */
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Write formatted output to a string dynamically allocated with malloc().
+   You can pass a preallocated buffer for the result in RESULTBUF and its
+   size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
+   If successful, return the address of the string (this may be = RESULTBUF
+   if no dynamic memory allocation was necessary) and set *LENGTHP to the
+   number of resulting bytes, excluding the trailing NUL.  Upon error, set
+   errno and return NULL.
+
+   When dynamic memory allocation occurs, the preallocated buffer is left
+   alone (with possibly modified contents).  This makes it possible to use
+   a statically allocated or stack-allocated buffer, like this:
+
+          wchar_t buf[100];
+          size_t len = sizeof (buf) / sizeof (wchar_t);
+          wchar_t *output = vasnwprintf (buf, &len, format, args);
+          if (output == NULL)
+            ... error handling ...;
+          else
+            {
+              ... use the output string ...;
+              if (output != buf)
+                free (output);
+            }
+  */
+extern wchar_t * asnwprintf (wchar_t *resultbuf, size_t *lengthp,
+                             const wchar_t *format, ...);
+extern wchar_t * vasnwprintf (wchar_t *resultbuf, size_t *lengthp,
+                              const wchar_t *format, va_list args);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VASNWPRINTF_H */
diff --git a/lib/wprintf-parse.c b/lib/wprintf-parse.c
new file mode 100644
index 0000000000..f7b72c9ef3
--- /dev/null
+++ b/lib/wprintf-parse.c
@@ -0,0 +1,31 @@
+/* Formatted output to strings.
+   Copyright (C) 2003-2023 Free Software Foundation, Inc.
+
+   This file 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.
+
+   This file 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 this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* This file can be parametrized with the following macros:
+     STATIC             Set to 'static' to declare the function static.  */
+
+#ifndef STATIC
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "wprintf-parse.h"
+
+#define PRINTF_PARSE wprintf_parse
+#define CHAR_T wchar_t
+#define DIRECTIVE wchar_t_directive
+#define DIRECTIVES wchar_t_directives
+#include "printf-parse.c"
diff --git a/lib/wprintf-parse.h b/lib/wprintf-parse.h
new file mode 100644
index 0000000000..05799b8f15
--- /dev/null
+++ b/lib/wprintf-parse.h
@@ -0,0 +1,86 @@
+/* Parse wprintf format string.
+   Copyright (C) 1999-2023 Free Software Foundation, Inc.
+
+   This file 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.
+
+   This file 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 this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* This file can be parametrized with the following macros:
+     STATIC             Set to 'static' to declare the function static.  */
+#ifndef _WPRINTF_PARSE_H
+#define _WPRINTF_PARSE_H
+
+#if HAVE_FEATURES_H
+# include <features.h> /* for __GLIBC__, __UCLIBC__ */
+#endif
+
+#include "printf-args.h"
+
+
+/* Flags */
+#define FLAG_GROUP       1      /* ' flag */
+#define FLAG_LEFT        2      /* - flag */
+#define FLAG_SHOWSIGN    4      /* + flag */
+#define FLAG_SPACE       8      /* space flag */
+#define FLAG_ALT        16      /* # flag */
+#define FLAG_ZERO       32
+#if __GLIBC__ >= 2 && !defined __UCLIBC__
+# define FLAG_LOCALIZED 64      /* I flag, uses localized digits */
+#endif
+
+/* arg_index value indicating that no argument is consumed.  */
+#define ARG_NONE        (~(size_t)0)
+
+/* Number of directly allocated directives (no malloc() needed).  */
+#define N_DIRECT_ALLOC_DIRECTIVES 7
+
+/* A parsed directive.  */
+typedef struct
+{
+  const wchar_t* dir_start;
+  const wchar_t* dir_end;
+  int flags;
+  const wchar_t* width_start;
+  const wchar_t* width_end;
+  size_t width_arg_index;
+  const wchar_t* precision_start;
+  const wchar_t* precision_end;
+  size_t precision_arg_index;
+  wchar_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
+  size_t arg_index;
+}
+wchar_t_directive;
+
+/* A parsed format string.  */
+typedef struct
+{
+  size_t count;
+  wchar_t_directive *dir;
+  size_t max_width_length;
+  size_t max_precision_length;
+  wchar_t_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
+}
+wchar_t_directives;
+
+
+/* Parses the format string.  Fills in the number N of directives, and fills
+   in directives[0], ..., directives[N-1], and sets directives[N].dir_start
+   to the end of the format string.  Also fills in the arg_type fields of the
+   arguments and the needed count of arguments.  */
+#ifdef STATIC
+STATIC
+#else
+extern
+#endif
+int wprintf_parse (const wchar_t *format, wchar_t_directives *d, arguments *a);
+
+#endif /* _WPRINTF_PARSE_H */
diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4
index fda90c402b..cf451f9b03 100644
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 39
+# vasnprintf.m4 serial 40
 dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -29,6 +29,15 @@ AC_DEFUN([gl_REPLACE_VASNPRINTF]
   gl_PREREQ_ASNPRINTF
 ])
 
+AC_DEFUN([gl_FUNC_VASNWPRINTF],
+[
+  AC_LIBOBJ([printf-args])
+  gl_PREREQ_PRINTF_ARGS
+  gl_PREREQ_PRINTF_PARSE
+  gl_PREREQ_VASNWPRINTF
+  gl_PREREQ_ASNPRINTF
+])
+
 # Prerequisites of lib/printf-args.h, lib/printf-args.c.
 AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
 [
@@ -37,6 +46,7 @@ AC_DEFUN([gl_PREREQ_PRINTF_ARGS]
 ])
 
 # Prerequisites of lib/printf-parse.h, lib/printf-parse.c.
+# Prerequisites of lib/wprintf-parse.h, lib/wprintf-parse.c.
 AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
 [
   AC_REQUIRE([gl_FEATURES_H])
@@ -50,19 +60,13 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE]
   AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
 ])
 
-# Prerequisites of lib/vasnprintf.c.
+# Prerequisites of lib/vasnprintf.c if !WIDE_CHAR_VERSION.
 AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
 [
-  AC_REQUIRE([AC_FUNC_ALLOCA])
-  AC_REQUIRE([gt_TYPE_WCHAR_T])
-  AC_REQUIRE([gt_TYPE_WINT_T])
-  AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
+  AC_CHECK_FUNCS([snprintf strnlen wcrtomb])
   dnl Use the _snprintf function only if it is declared (because on NetBSD it
   dnl is defined as a weak alias of snprintf; we prefer to use the latter).
   AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
-  dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
-  dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
-  AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
   dnl We can avoid a lot of code by assuming that snprintf's return value
   dnl conforms to ISO C99. So check that.
   AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
@@ -84,6 +88,27 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF]
          terminated.])
       ;;
   esac
+  gl_PREREQ_VASNXPRINTF
+])
+
+# Prerequisites of lib/vasnwprintf.c.
+AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF],
+[
+  AC_CHECK_FUNCS([wcsnlen mbrtowc])
+  AC_CHECK_DECLS([_snwprintf], , , [[#include <stdio.h>]])
+  gl_PREREQ_VASNXPRINTF
+])
+
+# Common prerequisites of lib/vasnprintf.c and lib/vasnwprintf.c.
+AC_DEFUN_ONCE([gl_PREREQ_VASNXPRINTF],
+[
+  AC_REQUIRE([AC_FUNC_ALLOCA])
+  AC_REQUIRE([gt_TYPE_WCHAR_T])
+  AC_REQUIRE([gt_TYPE_WINT_T])
+  AC_CHECK_FUNCS([wcslen])
+  dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
+  dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
+  AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
 ])
 
 # Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
@@ -293,6 +318,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS]
 ])
 
 # Prerequisites of lib/asnprintf.c.
+# Prerequisites of lib/asnwprintf.c.
 AC_DEFUN([gl_PREREQ_ASNPRINTF],
 [
 ])
diff --git a/modules/vasnwprintf b/modules/vasnwprintf
new file mode 100644
index 0000000000..544d7144a4
--- /dev/null
+++ b/modules/vasnwprintf
@@ -0,0 +1,53 @@
+Description:
+vswprintf with automatic memory allocation and bounded output size.
+
+Files:
+lib/float+.h
+lib/printf-args.h
+lib/printf-args.c
+lib/wprintf-parse.h
+lib/wprintf-parse.c
+lib/printf-parse.c
+lib/vasnwprintf.h
+lib/vasnwprintf.c
+lib/vasnprintf.c
+lib/asnwprintf.c
+m4/wchar_t.m4
+m4/wint_t.m4
+m4/intmax_t.m4
+m4/stdint_h.m4
+m4/inttypes_h.m4
+m4/vasnprintf.m4
+m4/printf.m4
+m4/math_h.m4
+m4/exponentd.m4
+
+Depends-on:
+stdio
+alloca-opt
+attribute
+float
+free-posix
+stdint
+xsize
+errno
+memchr
+assert-h
+wchar
+
+configure.ac:
+AC_REQUIRE([AC_C_RESTRICT])
+gl_FUNC_VASNWPRINTF
+
+Makefile.am:
+lib_SOURCES += wprintf-parse.c vasnwprintf.c
+lib_SOURCES += asnwprintf.c
+
+Include:
+"vasnwprintf.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-- 
2.34.1


[-- Attachment #3: 0002-vasnwprintf-Add-tests.patch --]
[-- Type: text/x-patch, Size: 5371 bytes --]

From 850b1f97b631d5944a9d0aafc00c078c07ca621d Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 17 Mar 2023 12:31:24 +0100
Subject: [PATCH 2/6] vasnwprintf: Add tests.

* tests/test-vasnwprintf.c: New file, based on tests/test-vasnprintf.c.
* modules/vasnwprintf-tests: New file, based on
modules/vasnprintf-tests.
---
 ChangeLog                 |   5 ++
 modules/vasnwprintf-tests |  13 ++++
 tests/test-vasnwprintf.c  | 122 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 modules/vasnwprintf-tests
 create mode 100644 tests/test-vasnwprintf.c

diff --git a/ChangeLog b/ChangeLog
index d1e7222441..eadcbf6765 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2023-03-17  Bruno Haible  <bruno@clisp.org>
 
+	vasnwprintf: Add tests.
+	* tests/test-vasnwprintf.c: New file, based on tests/test-vasnprintf.c.
+	* modules/vasnwprintf-tests: New file, based on
+	modules/vasnprintf-tests.
+
 	vasnwprintf: New module.
 	* lib/vasnprintf.c: Enable more code for WIDE_CHAR_VERSION, because
 	snwprintf()/_snwprintf() (Windows) and swprintf() (Unix) don't return
diff --git a/modules/vasnwprintf-tests b/modules/vasnwprintf-tests
new file mode 100644
index 0000000000..e90236e8d2
--- /dev/null
+++ b/modules/vasnwprintf-tests
@@ -0,0 +1,13 @@
+Files:
+tests/test-vasnwprintf.c
+tests/macros.h
+
+Depends-on:
+wcscmp
+wmemcpy
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-vasnwprintf
+check_PROGRAMS += test-vasnwprintf
diff --git a/tests/test-vasnwprintf.c b/tests/test-vasnwprintf.c
new file mode 100644
index 0000000000..19db93694b
--- /dev/null
+++ b/tests/test-vasnwprintf.c
@@ -0,0 +1,122 @@
+/* Test of vasnwprintf() and asnwprintf() functions.
+   Copyright (C) 2007-2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+#include "vasnwprintf.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "macros.h"
+
+static void
+test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *, ...))
+{
+  wchar_t buf[8];
+  int size;
+
+  for (size = 0; size <= 8; size++)
+    {
+      size_t length = size;
+      wchar_t *result = my_asnwprintf (NULL, &length, L"%d", 12345);
+      ASSERT (result != NULL);
+      ASSERT (wcscmp (result, L"12345") == 0);
+      ASSERT (length == 5);
+      free (result);
+    }
+
+  for (size = 0; size <= 8; size++)
+    {
+      size_t length;
+      wchar_t *result;
+
+      wmemcpy (buf, L"DEADBEEF", 8);
+      length = size;
+      result = my_asnwprintf (buf, &length, L"%d", 12345);
+      ASSERT (result != NULL);
+      ASSERT (wcscmp (result, L"12345") == 0);
+      ASSERT (length == 5);
+      if (size < 5 + 1)
+        ASSERT (result != buf);
+      ASSERT (wmemcmp (buf + size, &L"DEADBEEF"[size], 8 - size) == 0);
+      if (result != buf)
+        free (result);
+    }
+
+  /* Note: This test assumes IEEE 754 representation of 'double' floats.  */
+  for (size = 0; size <= 8; size++)
+    {
+      size_t length;
+      wchar_t *result;
+
+      wmemcpy (buf, L"DEADBEEF", 8);
+      length = size;
+      result = my_asnwprintf (buf, &length, L"%2.0f", 1.6314159265358979e+125);
+      ASSERT (result != NULL);
+      /* The exact result and the result on glibc systems is
+         163141592653589790215729350939528493057529598899734151772468186268423257777068536614838678161083520756952076273094236944990208
+         On Cygwin, the result is
+         163141592653589790215729350939528493057529600000000000000000000000000000000000000000000000000000000000000000000000000000000000
+         On HP-UX 11.31 / hppa and IRIX 6.5, the result is
+         163141592653589790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+       */
+      ASSERT (wcslen (result) == 126);
+      ASSERT (wmemcmp (result, L"163141592653589790", 18) == 0);
+      ASSERT (length == 126);
+      if (size < 126 + 1)
+        ASSERT (result != buf);
+      ASSERT (wmemcmp (buf + size, &L"DEADBEEF"[size], 8 - size) == 0);
+      if (result != buf)
+        free (result);
+    }
+}
+
+static wchar_t *
+my_asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...)
+{
+  va_list args;
+  wchar_t *ret;
+
+  va_start (args, format);
+  ret = vasnwprintf (resultbuf, lengthp, format, args);
+  va_end (args);
+  return ret;
+}
+
+static void
+test_vasnwprintf ()
+{
+  test_function (my_asnwprintf);
+}
+
+static void
+test_asnwprintf ()
+{
+  test_function (asnwprintf);
+}
+
+int
+main (int argc, char *argv[])
+{
+  test_vasnwprintf ();
+  test_asnwprintf ();
+  return 0;
+}
-- 
2.34.1


[-- Attachment #4: 0003-vasnprintf-posix-Relicense-under-LGPLv2.patch --]
[-- Type: text/x-patch, Size: 1001 bytes --]

From f476d6bde10b6aade1dcdeec25cd229fc3f77b28 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 17 Mar 2023 12:42:09 +0100
Subject: [PATCH 3/6] vasnprintf-posix: Relicense under LGPLv2+.

* modules/vasnprintf-posix (License): Change to LGPLv2+.
---
 ChangeLog                | 5 +++++
 modules/vasnprintf-posix | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index eadcbf6765..d1a3edde04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-03-17  Bruno Haible  <bruno@clisp.org>
+
+	vasnprintf-posix: Relicense under LGPLv2+.
+	* modules/vasnprintf-posix (License): Change to LGPLv2+.
+
 2023-03-17  Bruno Haible  <bruno@clisp.org>
 
 	vasnwprintf: Add tests.
diff --git a/modules/vasnprintf-posix b/modules/vasnprintf-posix
index 33382f472f..10660f369d 100644
--- a/modules/vasnprintf-posix
+++ b/modules/vasnprintf-posix
@@ -36,7 +36,7 @@ Include:
 "vasnprintf.h"
 
 License:
-LGPL
+LGPLv2+
 
 Maintainer:
 all
-- 
2.34.1


[-- Attachment #5: 0004-vasnwprintf-posix-New-module.patch --]
[-- Type: text/x-patch, Size: 2881 bytes --]

From 2e284ca8234add2723d0cfaa0594f2be08b7f393 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 17 Mar 2023 12:47:49 +0100
Subject: [PATCH 4/6] vasnwprintf-posix: New module.

* m4/vasnwprintf-posix.m4: New file.
* modules/vasnwprintf-posix: New file, based on
modules/vasnprintf-posix.
---
 ChangeLog                 |  7 +++++++
 m4/vasnwprintf-posix.m4   | 21 ++++++++++++++++++++
 modules/vasnwprintf-posix | 42 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 m4/vasnwprintf-posix.m4
 create mode 100644 modules/vasnwprintf-posix

diff --git a/ChangeLog b/ChangeLog
index d1a3edde04..ea52155e29 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-03-17  Bruno Haible  <bruno@clisp.org>
+
+	vasnwprintf-posix: New module.
+	* m4/vasnwprintf-posix.m4: New file.
+	* modules/vasnwprintf-posix: New file, based on
+	modules/vasnprintf-posix.
+
 2023-03-17  Bruno Haible  <bruno@clisp.org>
 
 	vasnprintf-posix: Relicense under LGPLv2+.
diff --git a/m4/vasnwprintf-posix.m4 b/m4/vasnwprintf-posix.m4
new file mode 100644
index 0000000000..9561bcf2b6
--- /dev/null
+++ b/m4/vasnwprintf-posix.m4
@@ -0,0 +1,21 @@
+# vasnwprintf-posix.m4 serial 1
+dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_VASNWPRINTF_POSIX],
+[
+  gl_FUNC_VASNWPRINTF
+  gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+  gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+  gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
+  gl_PREREQ_VASNPRINTF_DIRECTIVE_A
+  gl_PREREQ_VASNPRINTF_DIRECTIVE_F
+  gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
+  gl_PREREQ_VASNPRINTF_FLAG_GROUPING
+  gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
+  gl_PREREQ_VASNPRINTF_FLAG_ZERO
+  gl_PREREQ_VASNPRINTF_PRECISION
+  gl_PREREQ_VASNPRINTF_ENOMEM
+])
diff --git a/modules/vasnwprintf-posix b/modules/vasnwprintf-posix
new file mode 100644
index 0000000000..ca14e64866
--- /dev/null
+++ b/modules/vasnwprintf-posix
@@ -0,0 +1,42 @@
+Description:
+POSIX compatible vswprintf with automatic memory allocation and bounded output
+size.
+
+Comment:
+This module should not be used as a dependency from a test module,
+otherwise when this module occurs as a tests-related module, it will
+have side effects on the compilation of the 'vasnwprintf' module, if
+that module occurs among the main modules in lib/.
+
+Files:
+m4/vasnwprintf-posix.m4
+m4/printf.m4
+m4/math_h.m4
+
+Depends-on:
+vasnwprintf
+isnand-nolibm
+isnanl-nolibm
+frexp-nolibm
+frexpl-nolibm
+printf-frexp
+printf-frexpl
+signbit
+fpucw
+nocrash
+printf-safe
+multiarch
+
+configure.ac:
+gl_FUNC_VASNWPRINTF_POSIX
+
+Makefile.am:
+
+Include:
+"vasnwprintf.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-- 
2.34.1


[-- Attachment #6: 0005-vasnwprintf-posix-Add-tests.patch --]
[-- Type: text/x-patch, Size: 154543 bytes --]

From e8cfb632178768a22e23a4171bb291afd3bbb5c4 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 17 Mar 2023 12:53:05 +0100
Subject: [PATCH 5/6] vasnwprintf-posix: Add tests.

* tests/test-vasnwprintf-posix.c: New file, based on
tests/test-vasnprintf-posix.c.
* tests/test-vasnwprintf-posix2.sh: New file, based on
tests/test-vasnprintf-posix2.sh.
* tests/test-vasnwprintf-posix2.c: New file, based on
tests/test-vasnprintf-posix2.c.
* tests/test-vasnwprintf-posix3.c: New file, based on
tests/test-vasnprintf-posix3.c.
* modules/vasnwprintf-posix-tests: New file, based on
modules/vasnprintf-posix-tests.
---
 ChangeLog                        |   12 +
 modules/vasnwprintf-posix-tests  |   31 +
 tests/test-vasnwprintf-posix.c   | 4029 ++++++++++++++++++++++++++++++
 tests/test-vasnwprintf-posix2.c  |   64 +
 tests/test-vasnwprintf-posix2.sh |   22 +
 tests/test-vasnwprintf-posix3.c  |  100 +
 6 files changed, 4258 insertions(+)
 create mode 100644 modules/vasnwprintf-posix-tests
 create mode 100644 tests/test-vasnwprintf-posix.c
 create mode 100644 tests/test-vasnwprintf-posix2.c
 create mode 100644 tests/test-vasnwprintf-posix2.sh
 create mode 100644 tests/test-vasnwprintf-posix3.c

diff --git a/ChangeLog b/ChangeLog
index ea52155e29..411d04e042 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2023-03-17  Bruno Haible  <bruno@clisp.org>
 
+	vasnwprintf-posix: Add tests.
+	* tests/test-vasnwprintf-posix.c: New file, based on
+	tests/test-vasnprintf-posix.c.
+	* tests/test-vasnwprintf-posix2.sh: New file, based on
+	tests/test-vasnprintf-posix2.sh.
+	* tests/test-vasnwprintf-posix2.c: New file, based on
+	tests/test-vasnprintf-posix2.c.
+	* tests/test-vasnwprintf-posix3.c: New file, based on
+	tests/test-vasnprintf-posix3.c.
+	* modules/vasnwprintf-posix-tests: New file, based on
+	modules/vasnprintf-posix-tests.
+
 	vasnwprintf-posix: New module.
 	* m4/vasnwprintf-posix.m4: New file.
 	* modules/vasnwprintf-posix: New file, based on
diff --git a/modules/vasnwprintf-posix-tests b/modules/vasnwprintf-posix-tests
new file mode 100644
index 0000000000..4f2891a4ff
--- /dev/null
+++ b/modules/vasnwprintf-posix-tests
@@ -0,0 +1,31 @@
+Files:
+tests/test-vasnwprintf-posix.c
+tests/test-vasnwprintf-posix2.sh
+tests/test-vasnwprintf-posix2.c
+tests/test-vasnwprintf-posix3.c
+tests/minus-zero.h
+tests/infinity.h
+tests/nan.h
+tests/macros.h
+m4/locale-fr.m4
+m4/codeset.m4
+
+Depends-on:
+stdint
+float
+setlocale
+wcscmp
+wcsspn
+wmemcpy
+
+configure.ac:
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+gt_LOCALE_FR
+gt_LOCALE_FR_UTF8
+
+Makefile.am:
+TESTS += test-vasnwprintf-posix test-vasnwprintf-posix2.sh test-vasnwprintf-posix3
+TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
+check_PROGRAMS += test-vasnwprintf-posix test-vasnwprintf-posix2 test-vasnwprintf-posix3
+test_vasnwprintf_posix2_LDADD = $(LDADD) $(SETLOCALE_LIB)
+test_vasnwprintf_posix3_LDADD = $(LDADD) $(SETLOCALE_LIB)
diff --git a/tests/test-vasnwprintf-posix.c b/tests/test-vasnwprintf-posix.c
new file mode 100644
index 0000000000..f686bfb9fe
--- /dev/null
+++ b/tests/test-vasnwprintf-posix.c
@@ -0,0 +1,4029 @@
+/* Test of POSIX compatible vasnwprintf() and asnwprintf() functions.
+   Copyright (C) 2007-2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+#include "vasnwprintf.h"
+
+#include <errno.h>
+#include <float.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "macros.h"
+#include "minus-zero.h"
+#include "infinity.h"
+#include "nan.h"
+
+/* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0.  */
+static int
+have_minus_zero ()
+{
+  static double plus_zero = 0.0;
+  double minus_zero = minus_zerod;
+  return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
+}
+
+/* Representation of an 80-bit 'long double' as an initializer for a sequence
+   of 'unsigned int' words.  */
+#ifdef WORDS_BIGENDIAN
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
+      ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
+      (unsigned int) (mantlo) << 16                                        \
+    }
+#else
+# define LDBL80_WORDS(exponent,manthi,mantlo) \
+    { mantlo, manthi, exponent }
+#endif
+
+static int
+wcsmatch (const wchar_t *pattern, const wchar_t *string)
+{
+  if (wcslen (pattern) != wcslen (string))
+    return 0;
+  for (; *pattern != L'\0'; pattern++, string++)
+    if (*pattern != L'*' && *string != *pattern)
+      return 0;
+  return 1;
+}
+
+/* Test whether string[start_index..end_index-1] is a valid textual
+   representation of NaN.  */
+static int
+wcsisnan (const wchar_t *string, size_t start_index, size_t end_index, int uppercase)
+{
+  if (start_index < end_index)
+    {
+      if (string[start_index] == L'-')
+        start_index++;
+      if (start_index + 3 <= end_index
+          && wmemcmp (string + start_index, uppercase ? L"NAN" : L"nan", 3) == 0)
+        {
+          start_index += 3;
+          if (start_index == end_index
+              || (string[start_index] == L'(' && string[end_index - 1] == L')'))
+            return 1;
+        }
+    }
+  return 0;
+}
+
+static void
+test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *, ...))
+{
+  wchar_t buf[8];
+  int size;
+
+  /* Test return value convention.  */
+
+  for (size = 0; size <= 8; size++)
+    {
+      size_t length = size;
+      wchar_t *result = my_asnwprintf (NULL, &length, L"%d", 12345);
+      ASSERT (result != NULL);
+      ASSERT (wcscmp (result, L"12345") == 0);
+      ASSERT (length == 5);
+      free (result);
+    }
+
+  for (size = 0; size <= 8; size++)
+    {
+      size_t length;
+      wchar_t *result;
+
+      wmemcpy (buf, L"DEADBEEF", 8);
+      length = size;
+      result = my_asnwprintf (buf, &length, L"%d", 12345);
+      ASSERT (result != NULL);
+      ASSERT (wcscmp (result, L"12345") == 0);
+      ASSERT (length == 5);
+      if (size < 6)
+        ASSERT (result != buf);
+      ASSERT (wmemcmp (buf + size, &L"DEADBEEF"[size], 8 - size) == 0);
+      if (result != buf)
+        free (result);
+    }
+
+  /* Test support of size specifiers as in C99.  */
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%ju %d", (uintmax_t) 12345671, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12345671 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%zu %d", (size_t) 12345672, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12345672 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12345673 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", (long double) 1.5, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.5 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
+     output of floating-point numbers.  */
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%a %d", 3.1416015625, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.922p+1 33") == 0
+            || wcscmp (result, L"0x3.244p+0 33") == 0
+            || wcscmp (result, L"0x6.488p-1 33") == 0
+            || wcscmp (result, L"0xc.91p-2 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%A %d", -3.1416015625, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0X1.922P+1 33") == 0
+            || wcscmp (result, L"-0X3.244P+0 33") == 0
+            || wcscmp (result, L"-0X6.488P-1 33") == 0
+            || wcscmp (result, L"-0XC.91P-2 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%a %d", 0.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x0p+0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%a %d", minus_zerod, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0x0p+0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%a %d", Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%a %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%a %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding near the decimal point.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.0a %d", 1.5, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1p+0 33") == 0
+            || wcscmp (result, L"0x2p+0 33") == 0
+            || wcscmp (result, L"0x3p-1 33") == 0
+            || wcscmp (result, L"0x6p-2 33") == 0
+            || wcscmp (result, L"0xcp-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 0.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.0a %d", 1.51, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x2p+0 33") == 0
+            || wcscmp (result, L"0x3p-1 33") == 0
+            || wcscmp (result, L"0x6p-2 33") == 0
+            || wcscmp (result, L"0xcp-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 1.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.1a %d", 1.51, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.8p+0 33") == 0
+            || wcscmp (result, L"0x3.0p-1 33") == 0
+            || wcscmp (result, L"0x6.1p-2 33") == 0
+            || wcscmp (result, L"0xc.1p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 2.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2a %d", 1.51, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.83p+0 33") == 0
+            || wcscmp (result, L"0x3.05p-1 33") == 0
+            || wcscmp (result, L"0x6.0ap-2 33") == 0
+            || wcscmp (result, L"0xc.14p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 3.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.3a %d", 1.51, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.829p+0 33") == 0
+            || wcscmp (result, L"0x3.052p-1 33") == 0
+            || wcscmp (result, L"0x6.0a4p-2 33") == 0
+            || wcscmp (result, L"0xc.148p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding can turn a ...FFF into a ...000.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.3a %d", 1.49999, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.800p+0 33") == 0
+            || wcscmp (result, L"0x3.000p-1 33") == 0
+            || wcscmp (result, L"0x6.000p-2 33") == 0
+            || wcscmp (result, L"0xc.000p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding can turn a ...FFF into a ...000.
+       This shows a Mac OS X 10.3.9 (Darwin 7.9) bug.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.1a %d", 1.999, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.0p+1 33") == 0
+            || wcscmp (result, L"0x2.0p+0 33") == 0
+            || wcscmp (result, L"0x4.0p-1 33") == 0
+            || wcscmp (result, L"0x8.0p-2 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  0x1.cp+0 33") == 0
+            || wcscmp (result, L"  0x3.8p-1 33") == 0
+            || wcscmp (result, L"    0x7p-2 33") == 0
+            || wcscmp (result, L"    0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*a %d", 10, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  0x1.cp+0 33") == 0
+            || wcscmp (result, L"  0x3.8p-1 33") == 0
+            || wcscmp (result, L"    0x7p-2 33") == 0
+            || wcscmp (result, L"    0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*a %d", -10, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.cp+0   33") == 0
+            || wcscmp (result, L"0x3.8p-1   33") == 0
+            || wcscmp (result, L"0x7p-2     33") == 0
+            || wcscmp (result, L"0xep-3     33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.10a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.c000000000p+0 33") == 0
+            || wcscmp (result, L"0x3.8000000000p-1 33") == 0
+            || wcscmp (result, L"0x7.0000000000p-2 33") == 0
+            || wcscmp (result, L"0xe.0000000000p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Large precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.50a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
+            || wcscmp (result, L"0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
+            || wcscmp (result, L"0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
+            || wcscmp (result, L"0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.cp+0   33") == 0
+            || wcscmp (result, L"0x3.8p-1   33") == 0
+            || wcscmp (result, L"0x7p-2     33") == 0
+            || wcscmp (result, L"0xep-3     33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+0x1.cp+0 33") == 0
+            || wcscmp (result, L"+0x3.8p-1 33") == 0
+            || wcscmp (result, L"+0x7p-2 33") == 0
+            || wcscmp (result, L"+0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 0x1.cp+0 33") == 0
+            || wcscmp (result, L" 0x3.8p-1 33") == 0
+            || wcscmp (result, L" 0x7p-2 33") == 0
+            || wcscmp (result, L" 0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.cp+0 33") == 0
+            || wcscmp (result, L"0x3.8p-1 33") == 0
+            || wcscmp (result, L"0x7.p-2 33") == 0
+            || wcscmp (result, L"0xe.p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#a %d", 1.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.p+0 33") == 0
+            || wcscmp (result, L"0x2.p-1 33") == 0
+            || wcscmp (result, L"0x4.p-2 33") == 0
+            || wcscmp (result, L"0x8.p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%010a %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x001.cp+0 33") == 0
+            || wcscmp (result, L"0x003.8p-1 33") == 0
+            || wcscmp (result, L"0x00007p-2 33") == 0
+            || wcscmp (result, L"0x0000ep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%010a %d", Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    /* "0000000inf 33" is not a valid result; see
+       <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
+    ASSERT (wcscmp (result, L"       inf 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050a %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    /* "0000000nan 33" is not a valid result; see
+       <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", 3.1416015625L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.922p+1 33") == 0
+            || wcscmp (result, L"0x3.244p+0 33") == 0
+            || wcscmp (result, L"0x6.488p-1 33") == 0
+            || wcscmp (result, L"0xc.91p-2 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LA %d", -3.1416015625L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0X1.922P+1 33") == 0
+            || wcscmp (result, L"-0X3.244P+0 33") == 0
+            || wcscmp (result, L"-0X6.488P-1 33") == 0
+            || wcscmp (result, L"-0XC.91P-2 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", 0.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x0p+0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", minus_zerol, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0x0p+0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+  /* asnwprintf should print something for noncanonical values.  */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%La %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+#endif
+
+  { /* Rounding near the decimal point.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.0La %d", 1.5L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x2p+0 33") == 0
+            || wcscmp (result, L"0x3p-1 33") == 0
+            || wcscmp (result, L"0x6p-2 33") == 0
+            || wcscmp (result, L"0xcp-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 0.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.0La %d", 1.51L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x2p+0 33") == 0
+            || wcscmp (result, L"0x3p-1 33") == 0
+            || wcscmp (result, L"0x6p-2 33") == 0
+            || wcscmp (result, L"0xcp-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 1.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.1La %d", 1.51L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.8p+0 33") == 0
+            || wcscmp (result, L"0x3.0p-1 33") == 0
+            || wcscmp (result, L"0x6.1p-2 33") == 0
+            || wcscmp (result, L"0xc.1p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 2.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2La %d", 1.51L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.83p+0 33") == 0
+            || wcscmp (result, L"0x3.05p-1 33") == 0
+            || wcscmp (result, L"0x6.0ap-2 33") == 0
+            || wcscmp (result, L"0xc.14p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding with precision 3.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.3La %d", 1.51L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.829p+0 33") == 0
+            || wcscmp (result, L"0x3.052p-1 33") == 0
+            || wcscmp (result, L"0x6.0a4p-2 33") == 0
+            || wcscmp (result, L"0xc.148p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding can turn a ...FFF into a ...000.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.3La %d", 1.49999L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.800p+0 33") == 0
+            || wcscmp (result, L"0x3.000p-1 33") == 0
+            || wcscmp (result, L"0x6.000p-2 33") == 0
+            || wcscmp (result, L"0xc.000p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Rounding can turn a ...FFF into a ...000.
+       This shows a Mac OS X 10.3.9 (Darwin 7.9) bug and a
+       glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.1La %d", 1.999L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.0p+1 33") == 0
+            || wcscmp (result, L"0x2.0p+0 33") == 0
+            || wcscmp (result, L"0x4.0p-1 33") == 0
+            || wcscmp (result, L"0x8.0p-2 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  0x1.cp+0 33") == 0
+            || wcscmp (result, L"  0x3.8p-1 33") == 0
+            || wcscmp (result, L"    0x7p-2 33") == 0
+            || wcscmp (result, L"    0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*La %d", 10, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  0x1.cp+0 33") == 0
+            || wcscmp (result, L"  0x3.8p-1 33") == 0
+            || wcscmp (result, L"    0x7p-2 33") == 0
+            || wcscmp (result, L"    0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*La %d", -10, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.cp+0   33") == 0
+            || wcscmp (result, L"0x3.8p-1   33") == 0
+            || wcscmp (result, L"0x7p-2     33") == 0
+            || wcscmp (result, L"0xep-3     33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.10La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.c000000000p+0 33") == 0
+            || wcscmp (result, L"0x3.8000000000p-1 33") == 0
+            || wcscmp (result, L"0x7.0000000000p-2 33") == 0
+            || wcscmp (result, L"0xe.0000000000p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Large precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.50La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
+            || wcscmp (result, L"0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
+            || wcscmp (result, L"0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
+            || wcscmp (result, L"0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.cp+0   33") == 0
+            || wcscmp (result, L"0x3.8p-1   33") == 0
+            || wcscmp (result, L"0x7p-2     33") == 0
+            || wcscmp (result, L"0xep-3     33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+0x1.cp+0 33") == 0
+            || wcscmp (result, L"+0x3.8p-1 33") == 0
+            || wcscmp (result, L"+0x7p-2 33") == 0
+            || wcscmp (result, L"+0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 0x1.cp+0 33") == 0
+            || wcscmp (result, L" 0x3.8p-1 33") == 0
+            || wcscmp (result, L" 0x7p-2 33") == 0
+            || wcscmp (result, L" 0xep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.cp+0 33") == 0
+            || wcscmp (result, L"0x3.8p-1 33") == 0
+            || wcscmp (result, L"0x7.p-2 33") == 0
+            || wcscmp (result, L"0xe.p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#La %d", 1.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1.p+0 33") == 0
+            || wcscmp (result, L"0x2.p-1 33") == 0
+            || wcscmp (result, L"0x4.p-2 33") == 0
+            || wcscmp (result, L"0x8.p-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%010La %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x001.cp+0 33") == 0
+            || wcscmp (result, L"0x003.8p-1 33") == 0
+            || wcscmp (result, L"0x00007p-2 33") == 0
+            || wcscmp (result, L"0x0000ep-3 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%010La %d", Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    /* "0000000inf 33" is not a valid result; see
+       <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
+    ASSERT (wcscmp (result, L"       inf 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050La %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    /* "0000000nan 33" is not a valid result; see
+       <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the %f format directive.  */
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", 12.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", 1234567.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234567.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small and large positive numbers.  */
+    static struct { double value; const wchar_t *string; } data[] =
+      {
+        { 1.234321234321234e-37, L"0.000000" },
+        { 1.234321234321234e-36, L"0.000000" },
+        { 1.234321234321234e-35, L"0.000000" },
+        { 1.234321234321234e-34, L"0.000000" },
+        { 1.234321234321234e-33, L"0.000000" },
+        { 1.234321234321234e-32, L"0.000000" },
+        { 1.234321234321234e-31, L"0.000000" },
+        { 1.234321234321234e-30, L"0.000000" },
+        { 1.234321234321234e-29, L"0.000000" },
+        { 1.234321234321234e-28, L"0.000000" },
+        { 1.234321234321234e-27, L"0.000000" },
+        { 1.234321234321234e-26, L"0.000000" },
+        { 1.234321234321234e-25, L"0.000000" },
+        { 1.234321234321234e-24, L"0.000000" },
+        { 1.234321234321234e-23, L"0.000000" },
+        { 1.234321234321234e-22, L"0.000000" },
+        { 1.234321234321234e-21, L"0.000000" },
+        { 1.234321234321234e-20, L"0.000000" },
+        { 1.234321234321234e-19, L"0.000000" },
+        { 1.234321234321234e-18, L"0.000000" },
+        { 1.234321234321234e-17, L"0.000000" },
+        { 1.234321234321234e-16, L"0.000000" },
+        { 1.234321234321234e-15, L"0.000000" },
+        { 1.234321234321234e-14, L"0.000000" },
+        { 1.234321234321234e-13, L"0.000000" },
+        { 1.234321234321234e-12, L"0.000000" },
+        { 1.234321234321234e-11, L"0.000000" },
+        { 1.234321234321234e-10, L"0.000000" },
+        { 1.234321234321234e-9, L"0.000000" },
+        { 1.234321234321234e-8, L"0.000000" },
+        { 1.234321234321234e-7, L"0.000000" },
+        { 1.234321234321234e-6, L"0.000001" },
+        { 1.234321234321234e-5, L"0.000012" },
+        { 1.234321234321234e-4, L"0.000123" },
+        { 1.234321234321234e-3, L"0.001234" },
+        { 1.234321234321234e-2, L"0.012343" },
+        { 1.234321234321234e-1, L"0.123432" },
+        { 1.234321234321234, L"1.234321" },
+        { 1.234321234321234e1, L"12.343212" },
+        { 1.234321234321234e2, L"123.432123" },
+        { 1.234321234321234e3, L"1234.321234" },
+        { 1.234321234321234e4, L"12343.212343" },
+        { 1.234321234321234e5, L"123432.123432" },
+        { 1.234321234321234e6, L"1234321.234321" },
+        { 1.234321234321234e7, L"12343212.343212" },
+        { 1.234321234321234e8, L"123432123.432123" },
+        { 1.234321234321234e9, L"1234321234.321234" },
+        { 1.234321234321234e10, L"12343212343.2123**" },
+        { 1.234321234321234e11, L"123432123432.123***" },
+        { 1.234321234321234e12, L"1234321234321.23****" },
+        { 1.234321234321234e13, L"12343212343212.3*****" },
+        { 1.234321234321234e14, L"123432123432123.******" },
+        { 1.234321234321234e15, L"1234321234321234.000000" },
+        { 1.234321234321234e16, L"123432123432123**.000000" },
+        { 1.234321234321234e17, L"123432123432123***.000000" },
+        { 1.234321234321234e18, L"123432123432123****.000000" },
+        { 1.234321234321234e19, L"123432123432123*****.000000" },
+        { 1.234321234321234e20, L"123432123432123******.000000" },
+        { 1.234321234321234e21, L"123432123432123*******.000000" },
+        { 1.234321234321234e22, L"123432123432123********.000000" },
+        { 1.234321234321234e23, L"123432123432123*********.000000" },
+        { 1.234321234321234e24, L"123432123432123**********.000000" },
+        { 1.234321234321234e25, L"123432123432123***********.000000" },
+        { 1.234321234321234e26, L"123432123432123************.000000" },
+        { 1.234321234321234e27, L"123432123432123*************.000000" },
+        { 1.234321234321234e28, L"123432123432123**************.000000" },
+        { 1.234321234321234e29, L"123432123432123***************.000000" },
+        { 1.234321234321234e30, L"123432123432123****************.000000" },
+        { 1.234321234321234e31, L"123432123432123*****************.000000" },
+        { 1.234321234321234e32, L"123432123432123******************.000000" },
+        { 1.234321234321234e33, L"123432123432123*******************.000000" },
+        { 1.234321234321234e34, L"123432123432123********************.000000" },
+        { 1.234321234321234e35, L"123432123432123*********************.000000" },
+        { 1.234321234321234e36, L"123432123432123**********************.000000" }
+      };
+    size_t k;
+    for (k = 0; k < SIZEOF (data); k++)
+      {
+        size_t length;
+        wchar_t *result =
+          my_asnwprintf (NULL, &length, L"%f", data[k].value);
+        ASSERT (result != NULL);
+        ASSERT (wcsmatch (data[k].string, result));
+        ASSERT (length == wcslen (result));
+        free (result);
+      }
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", -0.03125, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0.031250 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", 0.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", minus_zerod, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0
+            || wcscmp (result, L"infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0
+            || wcscmp (result, L"-infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%f %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10f %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*f %d", 10, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*f %d", -10, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10f %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+f %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% f %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#f %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.f %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"2. 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015f %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"00001234.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015f %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -inf 33") == 0
+            || wcscmp (result, L"      -infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050f %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.f %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2f %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"999.95 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2f %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1000.00 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", 12.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", 1234567.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234567.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small and large positive numbers.  */
+    static struct { long double value; const wchar_t *string; } data[] =
+      {
+        { 1.234321234321234e-37L, L"0.000000" },
+        { 1.234321234321234e-36L, L"0.000000" },
+        { 1.234321234321234e-35L, L"0.000000" },
+        { 1.234321234321234e-34L, L"0.000000" },
+        { 1.234321234321234e-33L, L"0.000000" },
+        { 1.234321234321234e-32L, L"0.000000" },
+        { 1.234321234321234e-31L, L"0.000000" },
+        { 1.234321234321234e-30L, L"0.000000" },
+        { 1.234321234321234e-29L, L"0.000000" },
+        { 1.234321234321234e-28L, L"0.000000" },
+        { 1.234321234321234e-27L, L"0.000000" },
+        { 1.234321234321234e-26L, L"0.000000" },
+        { 1.234321234321234e-25L, L"0.000000" },
+        { 1.234321234321234e-24L, L"0.000000" },
+        { 1.234321234321234e-23L, L"0.000000" },
+        { 1.234321234321234e-22L, L"0.000000" },
+        { 1.234321234321234e-21L, L"0.000000" },
+        { 1.234321234321234e-20L, L"0.000000" },
+        { 1.234321234321234e-19L, L"0.000000" },
+        { 1.234321234321234e-18L, L"0.000000" },
+        { 1.234321234321234e-17L, L"0.000000" },
+        { 1.234321234321234e-16L, L"0.000000" },
+        { 1.234321234321234e-15L, L"0.000000" },
+        { 1.234321234321234e-14L, L"0.000000" },
+        { 1.234321234321234e-13L, L"0.000000" },
+        { 1.234321234321234e-12L, L"0.000000" },
+        { 1.234321234321234e-11L, L"0.000000" },
+        { 1.234321234321234e-10L, L"0.000000" },
+        { 1.234321234321234e-9L, L"0.000000" },
+        { 1.234321234321234e-8L, L"0.000000" },
+        { 1.234321234321234e-7L, L"0.000000" },
+        { 1.234321234321234e-6L, L"0.000001" },
+        { 1.234321234321234e-5L, L"0.000012" },
+        { 1.234321234321234e-4L, L"0.000123" },
+        { 1.234321234321234e-3L, L"0.001234" },
+        { 1.234321234321234e-2L, L"0.012343" },
+        { 1.234321234321234e-1L, L"0.123432" },
+        { 1.234321234321234L, L"1.234321" },
+        { 1.234321234321234e1L, L"12.343212" },
+        { 1.234321234321234e2L, L"123.432123" },
+        { 1.234321234321234e3L, L"1234.321234" },
+        { 1.234321234321234e4L, L"12343.212343" },
+        { 1.234321234321234e5L, L"123432.123432" },
+        { 1.234321234321234e6L, L"1234321.234321" },
+        { 1.234321234321234e7L, L"12343212.343212" },
+        { 1.234321234321234e8L, L"123432123.432123" },
+        { 1.234321234321234e9L, L"1234321234.321234" },
+        { 1.234321234321234e10L, L"12343212343.2123**" },
+        { 1.234321234321234e11L, L"123432123432.123***" },
+        { 1.234321234321234e12L, L"1234321234321.23****" },
+        { 1.234321234321234e13L, L"12343212343212.3*****" },
+        { 1.234321234321234e14L, L"123432123432123.******" },
+        { 1.234321234321234e15L, L"1234321234321234.000000" },
+        { 1.234321234321234e16L, L"123432123432123**.000000" },
+        { 1.234321234321234e17L, L"123432123432123***.000000" },
+        { 1.234321234321234e18L, L"123432123432123****.000000" },
+        { 1.234321234321234e19L, L"123432123432123*****.000000" },
+        { 1.234321234321234e20L, L"123432123432123******.000000" },
+        { 1.234321234321234e21L, L"123432123432123*******.000000" },
+        { 1.234321234321234e22L, L"123432123432123********.000000" },
+        { 1.234321234321234e23L, L"123432123432123*********.000000" },
+        { 1.234321234321234e24L, L"123432123432123**********.000000" },
+        { 1.234321234321234e25L, L"123432123432123***********.000000" },
+        { 1.234321234321234e26L, L"123432123432123************.000000" },
+        { 1.234321234321234e27L, L"123432123432123*************.000000" },
+        { 1.234321234321234e28L, L"123432123432123**************.000000" },
+        { 1.234321234321234e29L, L"123432123432123***************.000000" },
+        { 1.234321234321234e30L, L"123432123432123****************.000000" },
+        { 1.234321234321234e31L, L"123432123432123*****************.000000" },
+        { 1.234321234321234e32L, L"123432123432123******************.000000" },
+        { 1.234321234321234e33L, L"123432123432123*******************.000000" },
+        { 1.234321234321234e34L, L"123432123432123********************.000000" },
+        { 1.234321234321234e35L, L"123432123432123*********************.000000" },
+        { 1.234321234321234e36L, L"123432123432123**********************.000000" }
+      };
+    size_t k;
+    for (k = 0; k < SIZEOF (data); k++)
+      {
+        size_t length;
+        wchar_t *result =
+          my_asnwprintf (NULL, &length, L"%Lf", data[k].value);
+        ASSERT (result != NULL);
+        ASSERT (wcsmatch (data[k].string, result));
+        ASSERT (length == wcslen (result));
+        free (result);
+      }
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", -0.03125L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0.031250 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", 0.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", minus_zerol, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0
+            || wcscmp (result, L"infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0
+            || wcscmp (result, L"-infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+  /* asnwprintf should print something for noncanonical values.  */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lf %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+#endif
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10Lf %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*Lf %d", 10, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"  1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*Lf %d", -10, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10Lf %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+Lf %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% Lf %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#Lf %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.Lf %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"2. 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015Lf %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"00001234.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015Lf %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -inf 33") == 0
+            || wcscmp (result, L"      -infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050Lf %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.Lf %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2Lf %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"999.95 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2Lf %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1000.00 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the %F format directive.  */
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", 12.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", 1234567.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234567.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", -0.03125, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0.031250 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", 0.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", minus_zerod, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"INF 33") == 0
+            || wcscmp (result, L"INFINITY 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-INF 33") == 0
+            || wcscmp (result, L"-INFINITY 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%F %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 1)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015F %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"00001234.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015F %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -INF 33") == 0
+            || wcscmp (result, L"      -INFINITY 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.F %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2F %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"999.95 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2F %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1000.00 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", 12.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12.750000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", 1234567.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234567.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", -0.03125L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0.031250 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", 0.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", minus_zerol, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"INF 33") == 0
+            || wcscmp (result, L"INFINITY 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-INF 33") == 0
+            || wcscmp (result, L"-INFINITY 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%LF %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 1)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015LF %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"00001234.000000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015LF %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -INF 33") == 0
+            || wcscmp (result, L"      -INFINITY 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.LF %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2LF %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"999.95 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.2LF %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1000.00 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the %e format directive.  */
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", 12.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.275000e+01 33") == 0
+            || wcscmp (result, L"1.275000e+001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", 1234567.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.234567e+06 33") == 0
+            || wcscmp (result, L"1.234567e+006 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small and large positive numbers.  */
+    static struct { double value; const wchar_t *string; } data[] =
+      {
+        { 1.234321234321234e-37, L"1.234321e-37" },
+        { 1.234321234321234e-36, L"1.234321e-36" },
+        { 1.234321234321234e-35, L"1.234321e-35" },
+        { 1.234321234321234e-34, L"1.234321e-34" },
+        { 1.234321234321234e-33, L"1.234321e-33" },
+        { 1.234321234321234e-32, L"1.234321e-32" },
+        { 1.234321234321234e-31, L"1.234321e-31" },
+        { 1.234321234321234e-30, L"1.234321e-30" },
+        { 1.234321234321234e-29, L"1.234321e-29" },
+        { 1.234321234321234e-28, L"1.234321e-28" },
+        { 1.234321234321234e-27, L"1.234321e-27" },
+        { 1.234321234321234e-26, L"1.234321e-26" },
+        { 1.234321234321234e-25, L"1.234321e-25" },
+        { 1.234321234321234e-24, L"1.234321e-24" },
+        { 1.234321234321234e-23, L"1.234321e-23" },
+        { 1.234321234321234e-22, L"1.234321e-22" },
+        { 1.234321234321234e-21, L"1.234321e-21" },
+        { 1.234321234321234e-20, L"1.234321e-20" },
+        { 1.234321234321234e-19, L"1.234321e-19" },
+        { 1.234321234321234e-18, L"1.234321e-18" },
+        { 1.234321234321234e-17, L"1.234321e-17" },
+        { 1.234321234321234e-16, L"1.234321e-16" },
+        { 1.234321234321234e-15, L"1.234321e-15" },
+        { 1.234321234321234e-14, L"1.234321e-14" },
+        { 1.234321234321234e-13, L"1.234321e-13" },
+        { 1.234321234321234e-12, L"1.234321e-12" },
+        { 1.234321234321234e-11, L"1.234321e-11" },
+        { 1.234321234321234e-10, L"1.234321e-10" },
+        { 1.234321234321234e-9, L"1.234321e-09" },
+        { 1.234321234321234e-8, L"1.234321e-08" },
+        { 1.234321234321234e-7, L"1.234321e-07" },
+        { 1.234321234321234e-6, L"1.234321e-06" },
+        { 1.234321234321234e-5, L"1.234321e-05" },
+        { 1.234321234321234e-4, L"1.234321e-04" },
+        { 1.234321234321234e-3, L"1.234321e-03" },
+        { 1.234321234321234e-2, L"1.234321e-02" },
+        { 1.234321234321234e-1, L"1.234321e-01" },
+        { 1.234321234321234, L"1.234321e+00" },
+        { 1.234321234321234e1, L"1.234321e+01" },
+        { 1.234321234321234e2, L"1.234321e+02" },
+        { 1.234321234321234e3, L"1.234321e+03" },
+        { 1.234321234321234e4, L"1.234321e+04" },
+        { 1.234321234321234e5, L"1.234321e+05" },
+        { 1.234321234321234e6, L"1.234321e+06" },
+        { 1.234321234321234e7, L"1.234321e+07" },
+        { 1.234321234321234e8, L"1.234321e+08" },
+        { 1.234321234321234e9, L"1.234321e+09" },
+        { 1.234321234321234e10, L"1.234321e+10" },
+        { 1.234321234321234e11, L"1.234321e+11" },
+        { 1.234321234321234e12, L"1.234321e+12" },
+        { 1.234321234321234e13, L"1.234321e+13" },
+        { 1.234321234321234e14, L"1.234321e+14" },
+        { 1.234321234321234e15, L"1.234321e+15" },
+        { 1.234321234321234e16, L"1.234321e+16" },
+        { 1.234321234321234e17, L"1.234321e+17" },
+        { 1.234321234321234e18, L"1.234321e+18" },
+        { 1.234321234321234e19, L"1.234321e+19" },
+        { 1.234321234321234e20, L"1.234321e+20" },
+        { 1.234321234321234e21, L"1.234321e+21" },
+        { 1.234321234321234e22, L"1.234321e+22" },
+        { 1.234321234321234e23, L"1.234321e+23" },
+        { 1.234321234321234e24, L"1.234321e+24" },
+        { 1.234321234321234e25, L"1.234321e+25" },
+        { 1.234321234321234e26, L"1.234321e+26" },
+        { 1.234321234321234e27, L"1.234321e+27" },
+        { 1.234321234321234e28, L"1.234321e+28" },
+        { 1.234321234321234e29, L"1.234321e+29" },
+        { 1.234321234321234e30, L"1.234321e+30" },
+        { 1.234321234321234e31, L"1.234321e+31" },
+        { 1.234321234321234e32, L"1.234321e+32" },
+        { 1.234321234321234e33, L"1.234321e+33" },
+        { 1.234321234321234e34, L"1.234321e+34" },
+        { 1.234321234321234e35, L"1.234321e+35" },
+        { 1.234321234321234e36, L"1.234321e+36" }
+      };
+    size_t k;
+    for (k = 0; k < SIZEOF (data); k++)
+      {
+        size_t length;
+        wchar_t *result =
+          my_asnwprintf (NULL, &length, L"%e", data[k].value);
+        const wchar_t *expected = data[k].string;
+        ASSERT (result != NULL);
+        ASSERT (wcscmp (result, expected) == 0
+                /* Some implementations produce exponents with 3 digits.  */
+                || (wcslen (result) == wcslen (expected) + 1
+                    && wmemcmp (result, expected, wcslen (expected) - 2) == 0
+                    && result[wcslen (expected) - 2] == '0'
+                    && wcscmp (result + wcslen (expected) - 1,
+                               expected + wcslen (expected) - 2)
+                       == 0));
+        ASSERT (length == wcslen (result));
+        free (result);
+      }
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", -0.03125, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-3.125000e-02 33") == 0
+            || wcscmp (result, L"-3.125000e-002 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", 0.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0.000000e+00 33") == 0
+            || wcscmp (result, L"0.000000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", minus_zerod, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0.000000e+00 33") == 0
+              || wcscmp (result, L"-0.000000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0
+            || wcscmp (result, L"infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0
+            || wcscmp (result, L"-infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%e %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%15e %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"   1.750000e+00 33") == 0
+            || wcscmp (result, L"  1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*e %d", 15, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"   1.750000e+00 33") == 0
+            || wcscmp (result, L"  1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*e %d", -15, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000e+00    33") == 0
+            || wcscmp (result, L"1.750000e+000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-15e %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000e+00    33") == 0
+            || wcscmp (result, L"1.750000e+000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+e %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+1.750000e+00 33") == 0
+            || wcscmp (result, L"+1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% e %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 1.750000e+00 33") == 0
+            || wcscmp (result, L" 1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#e %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000e+00 33") == 0
+            || wcscmp (result, L"1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.e %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"2.e+00 33") == 0
+            || wcscmp (result, L"2.e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.e %d", 9.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.e+01 33") == 0
+            || wcscmp (result, L"1.e+001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015e %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0001.234000e+03 33") == 0
+            || wcscmp (result, L"001.234000e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015e %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -inf 33") == 0
+            || wcscmp (result, L"      -infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050e %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.e %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1e+03 33") == 0
+            || wcscmp (result, L"1e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4e %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"9.9995e+02 33") == 0
+            || wcscmp (result, L"9.9995e+002 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4e %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.0000e+03 33") == 0
+            || wcscmp (result, L"1.0000e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", 12.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.275000e+01 33") == 0
+            || wcscmp (result, L"1.275000e+001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", 1234567.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.234567e+06 33") == 0
+            || wcscmp (result, L"1.234567e+006 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small and large positive numbers.  */
+    static struct { long double value; const wchar_t *string; } data[] =
+      {
+        { 1.234321234321234e-37L, L"1.234321e-37" },
+        { 1.234321234321234e-36L, L"1.234321e-36" },
+        { 1.234321234321234e-35L, L"1.234321e-35" },
+        { 1.234321234321234e-34L, L"1.234321e-34" },
+        { 1.234321234321234e-33L, L"1.234321e-33" },
+        { 1.234321234321234e-32L, L"1.234321e-32" },
+        { 1.234321234321234e-31L, L"1.234321e-31" },
+        { 1.234321234321234e-30L, L"1.234321e-30" },
+        { 1.234321234321234e-29L, L"1.234321e-29" },
+        { 1.234321234321234e-28L, L"1.234321e-28" },
+        { 1.234321234321234e-27L, L"1.234321e-27" },
+        { 1.234321234321234e-26L, L"1.234321e-26" },
+        { 1.234321234321234e-25L, L"1.234321e-25" },
+        { 1.234321234321234e-24L, L"1.234321e-24" },
+        { 1.234321234321234e-23L, L"1.234321e-23" },
+        { 1.234321234321234e-22L, L"1.234321e-22" },
+        { 1.234321234321234e-21L, L"1.234321e-21" },
+        { 1.234321234321234e-20L, L"1.234321e-20" },
+        { 1.234321234321234e-19L, L"1.234321e-19" },
+        { 1.234321234321234e-18L, L"1.234321e-18" },
+        { 1.234321234321234e-17L, L"1.234321e-17" },
+        { 1.234321234321234e-16L, L"1.234321e-16" },
+        { 1.234321234321234e-15L, L"1.234321e-15" },
+        { 1.234321234321234e-14L, L"1.234321e-14" },
+        { 1.234321234321234e-13L, L"1.234321e-13" },
+        { 1.234321234321234e-12L, L"1.234321e-12" },
+        { 1.234321234321234e-11L, L"1.234321e-11" },
+        { 1.234321234321234e-10L, L"1.234321e-10" },
+        { 1.234321234321234e-9L, L"1.234321e-09" },
+        { 1.234321234321234e-8L, L"1.234321e-08" },
+        { 1.234321234321234e-7L, L"1.234321e-07" },
+        { 1.234321234321234e-6L, L"1.234321e-06" },
+        { 1.234321234321234e-5L, L"1.234321e-05" },
+        { 1.234321234321234e-4L, L"1.234321e-04" },
+        { 1.234321234321234e-3L, L"1.234321e-03" },
+        { 1.234321234321234e-2L, L"1.234321e-02" },
+        { 1.234321234321234e-1L, L"1.234321e-01" },
+        { 1.234321234321234L, L"1.234321e+00" },
+        { 1.234321234321234e1L, L"1.234321e+01" },
+        { 1.234321234321234e2L, L"1.234321e+02" },
+        { 1.234321234321234e3L, L"1.234321e+03" },
+        { 1.234321234321234e4L, L"1.234321e+04" },
+        { 1.234321234321234e5L, L"1.234321e+05" },
+        { 1.234321234321234e6L, L"1.234321e+06" },
+        { 1.234321234321234e7L, L"1.234321e+07" },
+        { 1.234321234321234e8L, L"1.234321e+08" },
+        { 1.234321234321234e9L, L"1.234321e+09" },
+        { 1.234321234321234e10L, L"1.234321e+10" },
+        { 1.234321234321234e11L, L"1.234321e+11" },
+        { 1.234321234321234e12L, L"1.234321e+12" },
+        { 1.234321234321234e13L, L"1.234321e+13" },
+        { 1.234321234321234e14L, L"1.234321e+14" },
+        { 1.234321234321234e15L, L"1.234321e+15" },
+        { 1.234321234321234e16L, L"1.234321e+16" },
+        { 1.234321234321234e17L, L"1.234321e+17" },
+        { 1.234321234321234e18L, L"1.234321e+18" },
+        { 1.234321234321234e19L, L"1.234321e+19" },
+        { 1.234321234321234e20L, L"1.234321e+20" },
+        { 1.234321234321234e21L, L"1.234321e+21" },
+        { 1.234321234321234e22L, L"1.234321e+22" },
+        { 1.234321234321234e23L, L"1.234321e+23" },
+        { 1.234321234321234e24L, L"1.234321e+24" },
+        { 1.234321234321234e25L, L"1.234321e+25" },
+        { 1.234321234321234e26L, L"1.234321e+26" },
+        { 1.234321234321234e27L, L"1.234321e+27" },
+        { 1.234321234321234e28L, L"1.234321e+28" },
+        { 1.234321234321234e29L, L"1.234321e+29" },
+        { 1.234321234321234e30L, L"1.234321e+30" },
+        { 1.234321234321234e31L, L"1.234321e+31" },
+        { 1.234321234321234e32L, L"1.234321e+32" },
+        { 1.234321234321234e33L, L"1.234321e+33" },
+        { 1.234321234321234e34L, L"1.234321e+34" },
+        { 1.234321234321234e35L, L"1.234321e+35" },
+        { 1.234321234321234e36L, L"1.234321e+36" }
+      };
+    size_t k;
+    for (k = 0; k < SIZEOF (data); k++)
+      {
+        size_t length;
+        wchar_t *result =
+          my_asnwprintf (NULL, &length, L"%Le", data[k].value);
+        const wchar_t *expected = data[k].string;
+        ASSERT (result != NULL);
+        ASSERT (wcscmp (result, expected) == 0
+                /* Some implementations produce exponents with 3 digits.  */
+                || (wcslen (result) == wcslen (expected) + 1
+                    && wmemcmp (result, expected, wcslen (expected) - 2) == 0
+                    && result[wcslen (expected) - 2] == '0'
+                    && wcscmp (result + wcslen (expected) - 1,
+                               expected + wcslen (expected) - 2)
+                       == 0));
+        ASSERT (length == wcslen (result));
+        free (result);
+      }
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", -0.03125L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-3.125000e-02 33") == 0
+            || wcscmp (result, L"-3.125000e-002 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", 0.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0.000000e+00 33") == 0
+            || wcscmp (result, L"0.000000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", minus_zerol, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0.000000e+00 33") == 0
+              || wcscmp (result, L"-0.000000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0
+            || wcscmp (result, L"infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0
+            || wcscmp (result, L"-infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  /* asnwprintf should print something even for noncanonical values.  */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Le %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+#endif
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%15Le %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"   1.750000e+00 33") == 0
+            || wcscmp (result, L"  1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*Le %d", 15, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"   1.750000e+00 33") == 0
+            || wcscmp (result, L"  1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*Le %d", -15, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000e+00    33") == 0
+            || wcscmp (result, L"1.750000e+000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-15Le %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000e+00    33") == 0
+            || wcscmp (result, L"1.750000e+000   33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+Le %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+1.750000e+00 33") == 0
+            || wcscmp (result, L"+1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% Le %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 1.750000e+00 33") == 0
+            || wcscmp (result, L" 1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#Le %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.750000e+00 33") == 0
+            || wcscmp (result, L"1.750000e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.Le %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"2.e+00 33") == 0
+            || wcscmp (result, L"2.e+000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.Le %d", 9.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.e+01 33") == 0
+            || wcscmp (result, L"1.e+001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015Le %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0001.234000e+03 33") == 0
+            || wcscmp (result, L"001.234000e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015Le %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -inf 33") == 0
+            || wcscmp (result, L"      -infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050Le %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.Le %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1e+03 33") == 0
+            || wcscmp (result, L"1e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4Le %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"9.9995e+02 33") == 0
+            || wcscmp (result, L"9.9995e+002 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4Le %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.0000e+03 33") == 0
+            || wcscmp (result, L"1.0000e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the %g format directive.  */
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", 12.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", 1234567.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.23457e+06 33") == 0
+            || wcscmp (result, L"1.23457e+006 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small and large positive numbers.  */
+    static struct { double value; const wchar_t *string; } data[] =
+      {
+        { 1.234321234321234e-37, L"1.23432e-37" },
+        { 1.234321234321234e-36, L"1.23432e-36" },
+        { 1.234321234321234e-35, L"1.23432e-35" },
+        { 1.234321234321234e-34, L"1.23432e-34" },
+        { 1.234321234321234e-33, L"1.23432e-33" },
+        { 1.234321234321234e-32, L"1.23432e-32" },
+        { 1.234321234321234e-31, L"1.23432e-31" },
+        { 1.234321234321234e-30, L"1.23432e-30" },
+        { 1.234321234321234e-29, L"1.23432e-29" },
+        { 1.234321234321234e-28, L"1.23432e-28" },
+        { 1.234321234321234e-27, L"1.23432e-27" },
+        { 1.234321234321234e-26, L"1.23432e-26" },
+        { 1.234321234321234e-25, L"1.23432e-25" },
+        { 1.234321234321234e-24, L"1.23432e-24" },
+        { 1.234321234321234e-23, L"1.23432e-23" },
+        { 1.234321234321234e-22, L"1.23432e-22" },
+        { 1.234321234321234e-21, L"1.23432e-21" },
+        { 1.234321234321234e-20, L"1.23432e-20" },
+        { 1.234321234321234e-19, L"1.23432e-19" },
+        { 1.234321234321234e-18, L"1.23432e-18" },
+        { 1.234321234321234e-17, L"1.23432e-17" },
+        { 1.234321234321234e-16, L"1.23432e-16" },
+        { 1.234321234321234e-15, L"1.23432e-15" },
+        { 1.234321234321234e-14, L"1.23432e-14" },
+        { 1.234321234321234e-13, L"1.23432e-13" },
+        { 1.234321234321234e-12, L"1.23432e-12" },
+        { 1.234321234321234e-11, L"1.23432e-11" },
+        { 1.234321234321234e-10, L"1.23432e-10" },
+        { 1.234321234321234e-9, L"1.23432e-09" },
+        { 1.234321234321234e-8, L"1.23432e-08" },
+        { 1.234321234321234e-7, L"1.23432e-07" },
+        { 1.234321234321234e-6, L"1.23432e-06" },
+        { 1.234321234321234e-5, L"1.23432e-05" },
+        { 1.234321234321234e-4, L"0.000123432" },
+        { 1.234321234321234e-3, L"0.00123432" },
+        { 1.234321234321234e-2, L"0.0123432" },
+        { 1.234321234321234e-1, L"0.123432" },
+        { 1.234321234321234, L"1.23432" },
+        { 1.234321234321234e1, L"12.3432" },
+        { 1.234321234321234e2, L"123.432" },
+        { 1.234321234321234e3, L"1234.32" },
+        { 1.234321234321234e4, L"12343.2" },
+        { 1.234321234321234e5, L"123432" },
+        { 1.234321234321234e6, L"1.23432e+06" },
+        { 1.234321234321234e7, L"1.23432e+07" },
+        { 1.234321234321234e8, L"1.23432e+08" },
+        { 1.234321234321234e9, L"1.23432e+09" },
+        { 1.234321234321234e10, L"1.23432e+10" },
+        { 1.234321234321234e11, L"1.23432e+11" },
+        { 1.234321234321234e12, L"1.23432e+12" },
+        { 1.234321234321234e13, L"1.23432e+13" },
+        { 1.234321234321234e14, L"1.23432e+14" },
+        { 1.234321234321234e15, L"1.23432e+15" },
+        { 1.234321234321234e16, L"1.23432e+16" },
+        { 1.234321234321234e17, L"1.23432e+17" },
+        { 1.234321234321234e18, L"1.23432e+18" },
+        { 1.234321234321234e19, L"1.23432e+19" },
+        { 1.234321234321234e20, L"1.23432e+20" },
+        { 1.234321234321234e21, L"1.23432e+21" },
+        { 1.234321234321234e22, L"1.23432e+22" },
+        { 1.234321234321234e23, L"1.23432e+23" },
+        { 1.234321234321234e24, L"1.23432e+24" },
+        { 1.234321234321234e25, L"1.23432e+25" },
+        { 1.234321234321234e26, L"1.23432e+26" },
+        { 1.234321234321234e27, L"1.23432e+27" },
+        { 1.234321234321234e28, L"1.23432e+28" },
+        { 1.234321234321234e29, L"1.23432e+29" },
+        { 1.234321234321234e30, L"1.23432e+30" },
+        { 1.234321234321234e31, L"1.23432e+31" },
+        { 1.234321234321234e32, L"1.23432e+32" },
+        { 1.234321234321234e33, L"1.23432e+33" },
+        { 1.234321234321234e34, L"1.23432e+34" },
+        { 1.234321234321234e35, L"1.23432e+35" },
+        { 1.234321234321234e36, L"1.23432e+36" }
+      };
+    size_t k;
+    for (k = 0; k < SIZEOF (data); k++)
+      {
+        size_t length;
+        wchar_t *result =
+          my_asnwprintf (NULL, &length, L"%g", data[k].value);
+        const wchar_t *expected = data[k].string;
+        ASSERT (result != NULL);
+        ASSERT (wcscmp (result, expected) == 0
+                /* Some implementations produce exponents with 3 digits.  */
+                || (expected[wcslen (expected) - 4] == 'e'
+                    && wcslen (result) == wcslen (expected) + 1
+                    && wmemcmp (result, expected, wcslen (expected) - 2) == 0
+                    && result[wcslen (expected) - 2] == '0'
+                    && wcscmp (result + wcslen (expected) - 1,
+                               expected + wcslen (expected) - 2)
+                       == 0));
+        ASSERT (length == wcslen (result));
+        free (result);
+      }
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", -0.03125, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0.03125 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", 0.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", minus_zerod, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0
+            || wcscmp (result, L"infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0
+            || wcscmp (result, L"-infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%g %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10g %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"      1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*g %d", 10, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"      1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*g %d", -10, 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.75       33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10g %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.75       33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+g %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% g %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#g %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.75000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.g %d", 1.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"2. 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.g %d", 9.75, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.e+01 33") == 0
+            || wcscmp (result, L"1.e+001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%010g %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0000001234 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015g %d", - Infinityd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -inf 33") == 0
+            || wcscmp (result, L"      -infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050g %d", NaNd (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.g %d", 1234.0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1e+03 33") == 0
+            || wcscmp (result, L"1e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.5g %d", 999.951, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"999.95 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.5g %d", 999.996, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", 12.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"12.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A larger positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", 1234567.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.23457e+06 33") == 0
+            || wcscmp (result, L"1.23457e+006 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Small and large positive numbers.  */
+    static struct { long double value; const wchar_t *string; } data[] =
+      {
+        { 1.234321234321234e-37L, L"1.23432e-37" },
+        { 1.234321234321234e-36L, L"1.23432e-36" },
+        { 1.234321234321234e-35L, L"1.23432e-35" },
+        { 1.234321234321234e-34L, L"1.23432e-34" },
+        { 1.234321234321234e-33L, L"1.23432e-33" },
+        { 1.234321234321234e-32L, L"1.23432e-32" },
+        { 1.234321234321234e-31L, L"1.23432e-31" },
+        { 1.234321234321234e-30L, L"1.23432e-30" },
+        { 1.234321234321234e-29L, L"1.23432e-29" },
+        { 1.234321234321234e-28L, L"1.23432e-28" },
+        { 1.234321234321234e-27L, L"1.23432e-27" },
+        { 1.234321234321234e-26L, L"1.23432e-26" },
+        { 1.234321234321234e-25L, L"1.23432e-25" },
+        { 1.234321234321234e-24L, L"1.23432e-24" },
+        { 1.234321234321234e-23L, L"1.23432e-23" },
+        { 1.234321234321234e-22L, L"1.23432e-22" },
+        { 1.234321234321234e-21L, L"1.23432e-21" },
+        { 1.234321234321234e-20L, L"1.23432e-20" },
+        { 1.234321234321234e-19L, L"1.23432e-19" },
+        { 1.234321234321234e-18L, L"1.23432e-18" },
+        { 1.234321234321234e-17L, L"1.23432e-17" },
+        { 1.234321234321234e-16L, L"1.23432e-16" },
+        { 1.234321234321234e-15L, L"1.23432e-15" },
+        { 1.234321234321234e-14L, L"1.23432e-14" },
+        { 1.234321234321234e-13L, L"1.23432e-13" },
+        { 1.234321234321234e-12L, L"1.23432e-12" },
+        { 1.234321234321234e-11L, L"1.23432e-11" },
+        { 1.234321234321234e-10L, L"1.23432e-10" },
+        { 1.234321234321234e-9L, L"1.23432e-09" },
+        { 1.234321234321234e-8L, L"1.23432e-08" },
+        { 1.234321234321234e-7L, L"1.23432e-07" },
+        { 1.234321234321234e-6L, L"1.23432e-06" },
+        { 1.234321234321234e-5L, L"1.23432e-05" },
+        { 1.234321234321234e-4L, L"0.000123432" },
+        { 1.234321234321234e-3L, L"0.00123432" },
+        { 1.234321234321234e-2L, L"0.0123432" },
+        { 1.234321234321234e-1L, L"0.123432" },
+        { 1.234321234321234L, L"1.23432" },
+        { 1.234321234321234e1L, L"12.3432" },
+        { 1.234321234321234e2L, L"123.432" },
+        { 1.234321234321234e3L, L"1234.32" },
+        { 1.234321234321234e4L, L"12343.2" },
+        { 1.234321234321234e5L, L"123432" },
+        { 1.234321234321234e6L, L"1.23432e+06" },
+        { 1.234321234321234e7L, L"1.23432e+07" },
+        { 1.234321234321234e8L, L"1.23432e+08" },
+        { 1.234321234321234e9L, L"1.23432e+09" },
+        { 1.234321234321234e10L, L"1.23432e+10" },
+        { 1.234321234321234e11L, L"1.23432e+11" },
+        { 1.234321234321234e12L, L"1.23432e+12" },
+        { 1.234321234321234e13L, L"1.23432e+13" },
+        { 1.234321234321234e14L, L"1.23432e+14" },
+        { 1.234321234321234e15L, L"1.23432e+15" },
+        { 1.234321234321234e16L, L"1.23432e+16" },
+        { 1.234321234321234e17L, L"1.23432e+17" },
+        { 1.234321234321234e18L, L"1.23432e+18" },
+        { 1.234321234321234e19L, L"1.23432e+19" },
+        { 1.234321234321234e20L, L"1.23432e+20" },
+        { 1.234321234321234e21L, L"1.23432e+21" },
+        { 1.234321234321234e22L, L"1.23432e+22" },
+        { 1.234321234321234e23L, L"1.23432e+23" },
+        { 1.234321234321234e24L, L"1.23432e+24" },
+        { 1.234321234321234e25L, L"1.23432e+25" },
+        { 1.234321234321234e26L, L"1.23432e+26" },
+        { 1.234321234321234e27L, L"1.23432e+27" },
+        { 1.234321234321234e28L, L"1.23432e+28" },
+        { 1.234321234321234e29L, L"1.23432e+29" },
+        { 1.234321234321234e30L, L"1.23432e+30" },
+        { 1.234321234321234e31L, L"1.23432e+31" },
+        { 1.234321234321234e32L, L"1.23432e+32" },
+        { 1.234321234321234e33L, L"1.23432e+33" },
+        { 1.234321234321234e34L, L"1.23432e+34" },
+        { 1.234321234321234e35L, L"1.23432e+35" },
+        { 1.234321234321234e36L, L"1.23432e+36" }
+      };
+    size_t k;
+    for (k = 0; k < SIZEOF (data); k++)
+      {
+        size_t length;
+        wchar_t *result =
+          my_asnwprintf (NULL, &length, L"%Lg", data[k].value);
+        const wchar_t *expected = data[k].string;
+        ASSERT (result != NULL);
+        ASSERT (wcscmp (result, expected) == 0
+                /* Some implementations produce exponents with 3 digits.  */
+                || (expected[wcslen (expected) - 4] == 'e'
+                    && wcslen (result) == wcslen (expected) + 1
+                    && wmemcmp (result, expected, wcslen (expected) - 2) == 0
+                    && result[wcslen (expected) - 2] == '0'
+                    && wcscmp (result + wcslen (expected) - 1,
+                               expected + wcslen (expected) - 2)
+                       == 0));
+        ASSERT (length == wcslen (result));
+        free (result);
+      }
+  }
+
+  { /* A negative number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", -0.03125L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-0.03125 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", 0.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", minus_zerol, 33, 44, 55);
+    ASSERT (result != NULL);
+    if (have_minus_zero ())
+      ASSERT (wcscmp (result, L"-0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Positive infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"inf 33") == 0
+            || wcscmp (result, L"infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative infinity.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"-inf 33") == 0
+            || wcscmp (result, L"-infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+  { /* Quiet NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+  {
+    /* Signalling NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) >= 3 + 3
+            && wcsisnan (result, 0, wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+  /* asnwprintf should print something for noncanonical values.  */
+  { /* Pseudo-NaN.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Infinity.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Zero.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Unnormalized number.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+  { /* Pseudo-Denormal.  */
+    static union { unsigned int word[4]; long double value; } x =
+      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Lg %d", x.value, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (length == wcslen (result));
+    ASSERT (3 < length && wcscmp (result + length - 3, L" 33") == 0);
+    free (result);
+  }
+#endif
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10Lg %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"      1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*Lg %d", 10, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"      1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*Lg %d", -10, 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.75       33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10Lg %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.75       33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SHOWSIGN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%+Lg %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"+1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_SPACE.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"% Lg %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L" 1.75 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#Lg %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.75000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.Lg %d", 1.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"2. 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.Lg %d", 9.75L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1.e+01 33") == 0
+            || wcscmp (result, L"1.e+001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with finite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%010Lg %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0000001234 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with infinite number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%015Lg %d", - Infinityl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"           -inf 33") == 0
+            || wcscmp (result, L"      -infinity 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ZERO with NaN.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%050Lg %d", NaNl (), 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcslen (result) == 50 + 3
+            && wcsisnan (result, wcsspn (result, L" "), wcslen (result) - 3, 0)
+            && wcscmp (result + wcslen (result) - 3, L" 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.Lg %d", 1234.0L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1e+03 33") == 0
+            || wcscmp (result, L"1e+003 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with no rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.5Lg %d", 999.951L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"999.95 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Precision with rounding.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.5Lg %d", 999.996L, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1000 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the %n format directive.  */
+
+  {
+    int count = -1;
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%d %n", 123, &count, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"123 ") == 0);
+    ASSERT (length == wcslen (result));
+    ASSERT (count == 4);
+    free (result);
+  }
+
+  /* Test the support of the POSIX/XSI format strings with positions.  */
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%2$d %1$d", 33, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"55 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the grouping flag.  */
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%'d %d", 1234567, 99);
+    ASSERT (result != NULL);
+    ASSERT (result[wcslen (result) - 1] == '9');
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the left-adjust flag.  */
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"a%*sc", -3, "b");
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"ab  c") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"a%-*sc", 3, "b");
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"ab  c") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"a%-*sc", -3, "b");
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"ab  c") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of large precision.  */
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4000d %d", 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (wcscmp (result + 4000 - 7, L"1234567 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.*d %d", 4000, 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (wcscmp (result + 4000 - 7, L"1234567 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4000d %d", -1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    ASSERT (result[0] == '-');
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[1 + i] == '0');
+    ASSERT (wcscmp (result + 1 + 4000 - 7, L"1234567 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4000u %d", 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (wcscmp (result + 4000 - 7, L"1234567 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4000o %d", 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 7; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (wcscmp (result + 4000 - 7, L"4553207 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4000x %d", 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    for (i = 0; i < 4000 - 6; i++)
+      ASSERT (result[i] == '0');
+    ASSERT (wcscmp (result + 4000 - 6, L"12d687 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#.4000x %d", 1234567, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    ASSERT (result[0] == '0');
+    ASSERT (result[1] == 'x');
+    for (i = 0; i < 4000 - 6; i++)
+      ASSERT (result[2 + i] == '0');
+    ASSERT (wcscmp (result + 2 + 4000 - 6, L"12d687 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.4000f %d", 1.0, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    ASSERT (result[0] == '1');
+    ASSERT (result[1] == '.');
+    for (i = 0; i < 4000; i++)
+      ASSERT (result[2 + i] == '0');
+    ASSERT (wcscmp (result + 2 + 4000, L" 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%.511f %d", 1.0, 99);
+    size_t i;
+    ASSERT (result != NULL);
+    ASSERT (result[0] == '1');
+    ASSERT (result[1] == '.');
+    for (i = 0; i < 511; i++)
+      ASSERT (result[2 + i] == '0');
+    ASSERT (wcscmp (result + 2 + 511, L" 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  {
+    char input[5000];
+    size_t length;
+    wchar_t *result;
+    wchar_t winput[5000];
+    size_t i;
+
+    for (i = 0; i < sizeof (input) - 1; i++)
+      input[i] = 'a' + ((1000000 / (i + 1)) % 26);
+    input[i] = '\0';
+    result = my_asnwprintf (NULL, &length, L"%.4000s %d", input, 99);
+    ASSERT (result != NULL);
+    for (i = 0; i < sizeof (input); i++)
+      winput[i] = (wchar_t) input[i];
+    ASSERT (wmemcmp (result, winput, 4000) == 0);
+    ASSERT (wcscmp (result + 4000, L" 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test the support of the %s format directive.  */
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10s %d", "xyz", 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"       xyz 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*s %d", 10, "xyz", 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"       xyz 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*s %d", -10, "xyz", 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"xyz        33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10s %d", "xyz", 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"xyz        33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+#if HAVE_WCHAR_T
+  static wchar_t L_xyz[4] = { 'x', 'y', 'z', 0 };
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10ls %d", L_xyz, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"       xyz 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*ls %d", 10, L_xyz, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"       xyz 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*ls %d", -10, L_xyz, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"xyz        33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10ls %d", L_xyz, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"xyz        33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#endif
+
+  /* To verify that these tests succeed, it is necessary to run them under
+     a tool that checks against invalid memory accesses, such as ElectricFence
+     or "valgrind --tool=memcheck".  */
+  {
+    size_t i;
+
+    for (i = 1; i <= 8; i++)
+      {
+        char *block;
+        size_t length;
+        wchar_t *result;
+        wchar_t *wblock;
+        size_t j;
+
+        block = (char *) malloc (i);
+        memcpy (block, "abcdefgh", i);
+        result = my_asnwprintf (NULL, &length, L"%.*s", (int) i, block);
+        ASSERT (result != NULL);
+        wblock = (wchar_t *) malloc (i * sizeof (wchar_t));
+        for (j = 0; j < i; j++)
+          wblock[j] = (wchar_t) block[j];
+        ASSERT (wmemcmp (result, wblock, i) == 0);
+        ASSERT (result[i] == '\0');
+        ASSERT (length == wcslen (result));
+        free (result);
+        free (block);
+      }
+  }
+#if HAVE_WCHAR_T
+  {
+    size_t i;
+
+    for (i = 1; i <= 8; i++)
+      {
+        wchar_t *block;
+        size_t j;
+        size_t length;
+        wchar_t *result;
+
+        block = (wchar_t *) malloc (i * sizeof (wchar_t));
+        for (j = 0; j < i; j++)
+          block[j] = "abcdefgh"[j];
+        result = my_asnwprintf (NULL, &length, L"%.*ls", (int) i, block);
+        ASSERT (result != NULL);
+        ASSERT (wmemcmp (result, L"abcdefgh", i) == 0);
+        ASSERT (result[i] == '\0');
+        ASSERT (length == wcslen (result));
+        free (result);
+        free (block);
+      }
+  }
+#endif
+
+#if HAVE_WCHAR_T
+  /* Test that converting an invalid wchar_t[] to char[] fails with EILSEQ.  */
+  {
+    static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 };
+    size_t length;
+    wchar_t *result = my_asnwprintf (NULL, &length, L"%ls %d", input, 99);
+    if (result == NULL)
+      ASSERT (errno == EILSEQ);
+    else
+      free (result);
+  }
+  {
+    static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 };
+    size_t length;
+    wchar_t *result = my_asnwprintf (NULL, &length, L"%3ls %d", input, 99);
+    if (result == NULL)
+      ASSERT (errno == EILSEQ);
+    else
+      free (result);
+  }
+  {
+    static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 };
+    size_t length;
+    wchar_t *result = my_asnwprintf (NULL, &length, L"%.1ls %d", input, 99);
+    if (result == NULL)
+      ASSERT (errno == EILSEQ);
+    else
+      free (result);
+  }
+  {
+    static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 };
+    size_t length;
+    wchar_t *result = my_asnwprintf (NULL, &length, L"%3.1ls %d", input, 99);
+    if (result == NULL)
+      ASSERT (errno == EILSEQ);
+    else
+      free (result);
+  }
+#endif
+
+  /* Test the support of the %c format directive.  */
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length,
+                     L"%10c %d", (unsigned char) 'x', 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"         x 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length,
+                     L"%*c %d", 10, (unsigned char) 'x', 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"         x 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length,
+                     L"%*c %d", -10, (unsigned char) 'x', 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"x          33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length,
+                     L"%-10c %d", (unsigned char) 'x', 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"x          33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+#if HAVE_WCHAR_T
+  static wint_t L_x = (wchar_t) 'x';
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%10lc %d", L_x, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"         x 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*lc %d", 10, L_x, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"         x 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*lc %d", -10, L_x, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"x          33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-10lc %d", L_x, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"x          33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#endif
+
+#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
+  /* Test that the 'I' flag is supported.  */
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Id %d", 1234567, 99);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"1234567 99") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+#endif
+}
+
+static wchar_t *
+my_asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...)
+{
+  va_list args;
+  wchar_t *ret;
+
+  va_start (args, format);
+  ret = vasnwprintf (resultbuf, lengthp, format, args);
+  va_end (args);
+  return ret;
+}
+
+static void
+test_vasnwprintf ()
+{
+  test_function (my_asnwprintf);
+}
+
+static void
+test_asnwprintf ()
+{
+  test_function (asnwprintf);
+}
+
+int
+main (int argc, char *argv[])
+{
+  test_vasnwprintf ();
+  test_asnwprintf ();
+  return 0;
+}
diff --git a/tests/test-vasnwprintf-posix2.c b/tests/test-vasnwprintf-posix2.c
new file mode 100644
index 0000000000..29027b2626
--- /dev/null
+++ b/tests/test-vasnwprintf-posix2.c
@@ -0,0 +1,64 @@
+/* Test of POSIX compatible vasnwprintf() and asnwprintf() functions.
+   Copyright (C) 2007-2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+#include "vasnwprintf.h"
+
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  /* configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Test that a locale dependent decimal point is used.  */
+  {
+    size_t length;
+    wchar_t *result = asnwprintf (NULL, &length, L"%.1a", 1.0);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1,0p+0") == 0
+            || wcscmp (result, L"0x2,0p-1") == 0
+            || wcscmp (result, L"0x4,0p-2") == 0
+            || wcscmp (result, L"0x8,0p-3") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  /* Test that a locale dependent decimal point is used.  */
+  {
+    size_t length;
+    wchar_t *result = asnwprintf (NULL, &length, L"%.1La", 1.0L);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0x1,0p+0") == 0
+            || wcscmp (result, L"0x2,0p-1") == 0
+            || wcscmp (result, L"0x4,0p-2") == 0
+            || wcscmp (result, L"0x8,0p-3") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  return 0;
+}
diff --git a/tests/test-vasnwprintf-posix2.sh b/tests/test-vasnwprintf-posix2.sh
new file mode 100644
index 0000000000..7a5a36476c
--- /dev/null
+++ b/tests/test-vasnwprintf-posix2.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# Test whether a french locale is installed.
+: "${LOCALE_FR=fr_FR}"
+: "${LOCALE_FR_UTF8=fr_FR.UTF-8}"
+if test $LOCALE_FR != none; then
+  testlocale=$LOCALE_FR
+else
+  if test $LOCALE_FR_UTF8 != none; then
+    testlocale=$LOCALE_FR_UTF8
+  else
+    if test -f /usr/bin/localedef; then
+      echo "Skipping test: no french locale is installed"
+    else
+      echo "Skipping test: no french locale is supported"
+    fi
+    exit 77
+  fi
+fi
+
+LC_ALL=$testlocale \
+${CHECKER} ./test-vasnwprintf-posix2${EXEEXT}
diff --git a/tests/test-vasnwprintf-posix3.c b/tests/test-vasnwprintf-posix3.c
new file mode 100644
index 0000000000..0e6ce29914
--- /dev/null
+++ b/tests/test-vasnwprintf-posix3.c
@@ -0,0 +1,100 @@
+/* Test of POSIX compatible vasnwprintf() and asnwprintf() functions.
+   Copyright (C) 2010-2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
+
+#include <config.h>
+
+#include "vasnwprintf.h"
+
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "macros.h"
+
+/* glibc >= 2.2 supports the 'I' flag, and in glibc >= 2.2.3 the fa_IR
+   locale defines the 'outdigits' to be U+06F0..U+06F9.
+   So we test for glibc >= 2.3.  */
+#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__
+
+static void
+test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *, ...))
+{
+  /* Test that the 'I' flag is supported.  */
+  {
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%Id %d", 1234567, 99);
+    static const wchar_t expected[] = /* "۱۲۳۴۵۶۷ 99" */
+      {
+        0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7, L' ',
+        L'9', L'9', L'\0'
+      };
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, expected) == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+}
+
+static wchar_t *
+my_asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...)
+{
+  va_list args;
+  wchar_t *ret;
+
+  va_start (args, format);
+  ret = vasnwprintf (resultbuf, lengthp, format, args);
+  va_end (args);
+  return ret;
+}
+
+static void
+test_vasnwprintf ()
+{
+  test_function (my_asnwprintf);
+}
+
+static void
+test_asnwprintf ()
+{
+  test_function (asnwprintf);
+}
+
+#endif
+
+int
+main (int argc, char *argv[])
+{
+#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__
+  /* Select a locale with Arabic 'outdigits'.  */
+  if (setlocale (LC_ALL, "fa_IR.UTF-8") == NULL)
+    {
+      fprintf (stderr, "Skipping test: no Iranian locale is installed\n");
+      return 77;
+    }
+
+  test_vasnwprintf ();
+  test_asnwprintf ();
+
+  return 0;
+#else
+  fprintf (stderr, "Skipping test: not a glibc >= 2.3 system\n");
+  return 77;
+#endif
+}
-- 
2.34.1


[-- Attachment #7: 0006-vasnprintf-vasnwprintf-Include-all-necessary-workaro.patch --]
[-- Type: text/x-patch, Size: 7134 bytes --]

From 6cac6f014973dce669f9fa50cce7540eda711050 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 17 Mar 2023 12:58:57 +0100
Subject: [PATCH 6/6] vasnprintf, vasnwprintf: Include all necessary
 workarounds in libintl.

* lib/vasnprintf.c: Remove IN_LIBINTL special-casing.
---
 ChangeLog        |  5 +++++
 lib/vasnprintf.c | 30 +++++++++++++++---------------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 411d04e042..816190dbc9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-03-17  Bruno Haible  <bruno@clisp.org>
+
+	vasnprintf, vasnwprintf: Include all necessary workarounds in libintl.
+	* lib/vasnprintf.c: Remove IN_LIBINTL special-casing.
+
 2023-03-17  Bruno Haible  <bruno@clisp.org>
 
 	vasnwprintf-posix: Add tests.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 4354fbe67c..f0575979ea 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -103,29 +103,29 @@
 
 #include "attribute.h"
 
-#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE
 # include <math.h>
 # include "float+.h"
 #endif
 
-#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
 # include <math.h>
 # include "isnand-nolibm.h"
 #endif
 
-#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
 # include <math.h>
 # include "isnanl-nolibm.h"
 # include "fpucw.h"
 #endif
 
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE
 # include <math.h>
 # include "isnand-nolibm.h"
 # include "printf-frexp.h"
 #endif
 
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE
 # include <math.h>
 # include "isnanl-nolibm.h"
 # include "printf-frexpl.h"
@@ -241,7 +241,7 @@ local_strnlen (const char *string, size_t maxlen)
 # endif
 #endif
 
-#if (((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
+#if (((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
 # if HAVE_WCSLEN
 #  define local_wcslen wcslen
 # else
@@ -283,7 +283,7 @@ local_wcsnlen (const wchar_t *s, size_t maxlen)
 # endif
 #endif
 
-#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T) || (ENABLE_WCHAR_FALLBACK && HAVE_WINT_T)) && !WIDE_CHAR_VERSION
+#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T) || (ENABLE_WCHAR_FALLBACK && HAVE_WINT_T)) && !WIDE_CHAR_VERSION
 # if ENABLE_WCHAR_FALLBACK
 static size_t
 wctomb_fallback (char *s, wchar_t wc)
@@ -351,7 +351,7 @@ local_wctomb (char *s, wchar_t wc)
 # endif
 #endif
 
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
 /* Determine the decimal-point character according to the current locale.  */
 # ifndef decimal_point_char_defined
 #  define decimal_point_char_defined 1
@@ -378,7 +378,7 @@ decimal_point_char (void)
 # endif
 #endif
 
-#if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE && !defined IN_LIBINTL
+#if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE
 
 /* Equivalent to !isfinite(x) || x == 0, but does not require libm.  */
 static int
@@ -389,7 +389,7 @@ is_infinite_or_zero (double x)
 
 #endif
 
-#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
+#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE
 
 /* Equivalent to !isfinite(x) || x == 0, but does not require libm.  */
 static int
@@ -400,7 +400,7 @@ is_infinite_or_zerol (long double x)
 
 #endif
 
-#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE
 
 /* Converting 'long double' to decimal without rare rounding bugs requires
    real bignums.  We use the naming conventions of GNU gmp, but vastly simpler
@@ -2394,7 +2394,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   }
               }
 #endif
-#if (!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T
+#if (!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T
             else if (dp->conversion == 's'
 # if WIDE_CHAR_VERSION
                      && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
@@ -3043,7 +3043,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 }
               }
 #endif
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE
             else if ((dp->conversion == 'a' || dp->conversion == 'A')
 # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
                      && (0
@@ -3533,7 +3533,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 length += count;
               }
 #endif
-#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+#if NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE
             else if ((dp->conversion == 'f' || dp->conversion == 'F'
                       || dp->conversion == 'e' || dp->conversion == 'E'
                       || dp->conversion == 'g' || dp->conversion == 'G'
@@ -5716,7 +5716,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
     errno = ENOMEM;
     goto fail_with_errno;
 
-#if ENABLE_UNISTDIO || ((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T)
+#if ENABLE_UNISTDIO || ((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T)
   fail_with_EILSEQ:
     errno = EILSEQ;
     goto fail_with_errno;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-17 12:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-17 12:15 new modules vasnwprintf, vasnwprintf-posix Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).