From 220f76a18ac3dc194f5dc7a53781f646e4fa4de6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Thu, 26 Feb 2009 12:54:20 +0100
Subject: [PATCH] Fix *printf behaviour regarding the %ls directive.

---
 ChangeLog                                |  33 ++++++
 doc/glibc-functions/obstack_printf.texi  |   3 +
 doc/glibc-functions/obstack_vprintf.texi |   3 +
 doc/posix-functions/fprintf.texi         |   3 +
 doc/posix-functions/printf.texi          |   3 +
 doc/posix-functions/snprintf.texi        |   3 +
 doc/posix-functions/sprintf.texi         |   3 +
 doc/posix-functions/vfprintf.texi        |   3 +
 doc/posix-functions/vprintf.texi         |   3 +
 doc/posix-functions/vsnprintf.texi       |   3 +
 doc/posix-functions/vsprintf.texi        |   3 +
 lib/vasnprintf.c                         |   4 +-
 m4/dprintf-posix.m4                      |  26 ++--
 m4/fprintf-posix.m4                      |  28 +++--
 m4/obstack-printf-posix.m4               |  28 +++--
 m4/printf.m4                             | 144 +++++++++++++++--------
 m4/snprintf-posix.m4                     |  38 +++---
 m4/sprintf-posix.m4                      |  28 +++--
 m4/vasnprintf-posix.m4                   |  32 +++--
 m4/vasnprintf.m4                         |  18 ++-
 m4/vasprintf-posix.m4                    |  32 +++--
 m4/vdprintf-posix.m4                     |  26 ++--
 m4/vfprintf-posix.m4                     |  26 ++--
 m4/vsnprintf-posix.m4                    |  38 +++---
 m4/vsprintf-posix.m4                     |  28 +++--
 25 files changed, 375 insertions(+), 184 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a126ab88c7..9919aa0ba5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2009-02-26  Bruno Haible  <bruno@clisp.org>
+
+	Fix *printf behaviour regarding the %ls directive.
+	* m4/printf.m4 (gl_PRINTF_DIRECTIVE_LS): New macro.
+	* lib/vasnprintf.c (local_wcslen, VASNPRINTF): Handle
+	NEED_PRINTF_DIRECTIVE_LS.
+	* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_DIRECTIVE_LS): New macro.
+	(gl_PREREQ_VASNPRINTF_WITH_EXTRAS): Invoke it.
+	* m4/fprintf-posix.m4 (gl_FUNC_FPRINTF_POSIX): Invoke
+	gl_PREREQ_VASNPRINTF_DIRECTIVE_LS and test its result. Invoke
+	gl_PREREQ_VASNPRINTF_DIRECTIVE_LS.
+	* m4/dprintf-posix.m4 (gl_FUNC_DPRINTF_POSIX): Likewise.
+	* m4/obstack-printf-posix.m4 (gl_FUNC_OBSTACK_PRINTF_POSIX): Likewise.
+	* m4/snprintf-posix.m4 (gl_FUNC_SNPRINTF_POSIX): Likewise.
+	* m4/sprintf-posix.m4 (gl_FUNC_SPRINTF_POSIX): Likewise.
+	* m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Likewise.
+	* m4/vasprintf-posix.m4 (gl_FUNC_VASPRINTF_POSIX): Likewise.
+	* m4/vdprintf-posix.m4 (gl_FUNC_VDPRINTF_POSIX): Likewise.
+	* m4/vfprintf-posix.m4 (gl_FUNC_VFPRINTF_POSIX): Likewise.
+	* m4/vsnprintf-posix.m4 (gl_FUNC_VSNPRINTF_POSIX): Likewise.
+	* m4/vsprintf-posix.m4 (gl_FUNC_VSPRINTF_POSIX): Likewise.
+	* doc/posix-functions/fprintf.texi: Update.
+	* doc/posix-functions/printf.texi: Update.
+	* doc/posix-functions/snprintf.texi: Update.
+	* doc/posix-functions/sprintf.texi: Update.
+	* doc/posix-functions/vfprintf.texi: Update.
+	* doc/posix-functions/vprintf.texi: Update.
+	* doc/posix-functions/vsnprintf.texi: Update.
+	* doc/posix-functions/vsprintf.texi: Update.
+	* doc/glibc-functions/obstack_printf.texi: Update.
+	* doc/glibc-functions/obstack_vprintf.texi: Update.
+	Reported by Eric Blake.
+
 2009-02-25  Bruno Haible  <bruno@clisp.org>
 
 	* m4/mbrtowc.m4 (gl_MBRTOWC_NUL_RETVAL): Update guess for Solaris 8
diff --git a/doc/glibc-functions/obstack_printf.texi b/doc/glibc-functions/obstack_printf.texi
index 6fa083031e..83d4c6ce69 100644
--- a/doc/glibc-functions/obstack_printf.texi
+++ b/doc/glibc-functions/obstack_printf.texi
@@ -35,6 +35,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/glibc-functions/obstack_vprintf.texi b/doc/glibc-functions/obstack_vprintf.texi
index 0dc9f8e2ec..ef0d6f5272 100644
--- a/doc/glibc-functions/obstack_vprintf.texi
+++ b/doc/glibc-functions/obstack_vprintf.texi
@@ -35,6 +35,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi
index 9214e01df8..0af41ae876 100644
--- a/doc/posix-functions/fprintf.texi
+++ b/doc/posix-functions/fprintf.texi
@@ -29,6 +29,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi
index 56bce47f80..da57b21051 100644
--- a/doc/posix-functions/printf.texi
+++ b/doc/posix-functions/printf.texi
@@ -29,6 +29,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/snprintf.texi b/doc/posix-functions/snprintf.texi
index 492b4ca0b1..a0ab770b0e 100644
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -40,6 +40,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/sprintf.texi b/doc/posix-functions/sprintf.texi
index 7865c53589..756feec5f6 100644
--- a/doc/posix-functions/sprintf.texi
+++ b/doc/posix-functions/sprintf.texi
@@ -29,6 +29,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/vfprintf.texi b/doc/posix-functions/vfprintf.texi
index 75460bed1e..90d9fa11d5 100644
--- a/doc/posix-functions/vfprintf.texi
+++ b/doc/posix-functions/vfprintf.texi
@@ -29,6 +29,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi
index 83ea92db35..f3462bc34e 100644
--- a/doc/posix-functions/vprintf.texi
+++ b/doc/posix-functions/vprintf.texi
@@ -29,6 +29,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/vsnprintf.texi b/doc/posix-functions/vsnprintf.texi
index 5dddf6608e..294c6eafa9 100644
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -40,6 +40,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/doc/posix-functions/vsprintf.texi b/doc/posix-functions/vsprintf.texi
index 247415fd1e..beda4a8deb 100644
--- a/doc/posix-functions/vsprintf.texi
+++ b/doc/posix-functions/vsprintf.texi
@@ -29,6 +29,9 @@ This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9,
 Cygwin 1.5.x, mingw, BeOS.
 @item
+This function does not support the @samp{ls} directive on some platforms:
+OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.
+@item
 This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, BeOS.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 31cb46bd5a..672b098131 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -210,7 +210,7 @@ local_strnlen (const char *string, size_t maxlen)
 # endif
 #endif
 
-#if !USE_SNPRINTF && HAVE_WCHAR_T && (WIDE_CHAR_VERSION || DCHAR_IS_TCHAR)
+#if (!USE_SNPRINTF || NEED_PRINTF_DIRECTIVE_LS) && HAVE_WCHAR_T && (WIDE_CHAR_VERSION || DCHAR_IS_TCHAR)
 # if HAVE_WCSLEN
 #  define local_wcslen wcslen
 # else
@@ -2103,7 +2103,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 		  }
 	      }
 #endif
-#if !USE_SNPRINTF && HAVE_WCHAR_T
+#if (!USE_SNPRINTF || NEED_PRINTF_DIRECTIVE_LS) && HAVE_WCHAR_T
 	    else if (dp->conversion == 's'
 # if WIDE_CHAR_VERSION
 		     && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
diff --git a/m4/dprintf-posix.m4 b/m4/dprintf-posix.m4
index 8c24c3c73b..7bce0a6648 100644
--- a/m4/dprintf-posix.m4
+++ b/m4/dprintf-posix.m4
@@ -1,4 +1,4 @@
-# dprintf-posix.m4 serial 1
+# dprintf-posix.m4 serial 2
 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -36,21 +37,25 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX],
                           *yes)
                             case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_positions" in
+                                case "$gl_cv_func_printf_directive_ls" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_grouping" in
+                                    case "$gl_cv_func_printf_positions" in
                                       *yes)
-                                        case "$gl_cv_func_printf_flag_leftadjust" in
+                                        case "$gl_cv_func_printf_flag_grouping" in
                                           *yes)
-                                            case "$gl_cv_func_printf_flag_zero" in
+                                            case "$gl_cv_func_printf_flag_leftadjust" in
                                               *yes)
-                                                case "$gl_cv_func_printf_precision" in
+                                                case "$gl_cv_func_printf_flag_zero" in
                                                   *yes)
-                                                    case "$gl_cv_func_printf_enomem" in
+                                                    case "$gl_cv_func_printf_precision" in
                                                       *yes)
-                                                        # dprintf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_dprintf_posix=yes
+                                                        case "$gl_cv_func_printf_enomem" in
+                                                          *yes)
+                                                            # dprintf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_dprintf_posix=yes
+                                                            ;;
+                                                        esac
                                                         ;;
                                                     esac
                                                     ;;
@@ -84,6 +89,7 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX],
     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
diff --git a/m4/fprintf-posix.m4 b/m4/fprintf-posix.m4
index 323cef265f..a4978ed34c 100644
--- a/m4/fprintf-posix.m4
+++ b/m4/fprintf-posix.m4
@@ -1,4 +1,4 @@
-# fprintf-posix.m4 serial 13
+# fprintf-posix.m4 serial 14
 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -34,23 +35,27 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
                         *yes)
                           case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_positions" in
+                              case "$gl_cv_func_printf_directive_ls" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_grouping" in
+                                  case "$gl_cv_func_printf_positions" in
                                     *yes)
-                                      case "$gl_cv_func_printf_flag_leftadjust" in
+                                      case "$gl_cv_func_printf_flag_grouping" in
                                         *yes)
-                                          case "$gl_cv_func_printf_flag_zero" in
+                                          case "$gl_cv_func_printf_flag_leftadjust" in
                                             *yes)
-                                              case "$gl_cv_func_printf_precision" in
+                                              case "$gl_cv_func_printf_flag_zero" in
                                                 *yes)
-                                                  case "$gl_cv_func_printf_enomem" in
+                                                  case "$gl_cv_func_printf_precision" in
                                                     *yes)
-                                                      # fprintf exists and is
-                                                      # already POSIX compliant.
-                                                      gl_cv_func_fprintf_posix=yes
+                                                      case "$gl_cv_func_printf_enomem" in
+                                                        *yes)
+                                                          # fprintf exists and is
+                                                          # already POSIX compliant.
+                                                          gl_cv_func_fprintf_posix=yes
+                                                          ;;
+                                                      esac
                                                       ;;
-                                                   esac
+                                                  esac
                                                   ;;
                                               esac
                                               ;;
@@ -81,6 +86,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
     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
diff --git a/m4/obstack-printf-posix.m4 b/m4/obstack-printf-posix.m4
index 8768e67467..328298fcc5 100644
--- a/m4/obstack-printf-posix.m4
+++ b/m4/obstack-printf-posix.m4
@@ -1,5 +1,5 @@
-# obstack-printf-posix.m4 serial 2
-dnl Copyright (C) 2008 Free Software Foundation, Inc.
+# obstack-printf-posix.m4 serial 3
+dnl Copyright (C) 2008-2009 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.
@@ -16,6 +16,7 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -39,21 +40,25 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX],
                           *yes)
                             case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_positions" in
+                                case "$gl_cv_func_printf_directive_ls" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_grouping" in
+                                    case "$gl_cv_func_printf_positions" in
                                       *yes)
-                                        case "$gl_cv_func_printf_flag_leftadjust" in
+                                        case "$gl_cv_func_printf_flag_grouping" in
                                           *yes)
-                                            case "$gl_cv_func_printf_flag_zero" in
+                                            case "$gl_cv_func_printf_flag_leftadjust" in
                                               *yes)
-                                                case "$gl_cv_func_printf_precision" in
+                                                case "$gl_cv_func_printf_flag_zero" in
                                                   *yes)
-                                                    case "$gl_cv_func_printf_enomem" in
+                                                    case "$gl_cv_func_printf_precision" in
                                                       *yes)
-                                                        # obstack_printf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_obstack_printf_posix=yes
+                                                        case "$gl_cv_func_printf_enomem" in
+                                                          *yes)
+                                                            # obstack_printf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_obstack_printf_posix=yes
+                                                            ;;
+                                                        esac
                                                         ;;
                                                     esac
                                                     ;;
@@ -87,6 +92,7 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX],
     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
diff --git a/m4/printf.m4 b/m4/printf.m4
index a1d4dadd7b..383374bb02 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 28
+# printf.m4 serial 29
 dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -612,6 +612,49 @@ changequote([,])dnl
     ])
 ])
 
+dnl Test whether the *printf family of functions supports the %ls format
+dnl directive.
+dnl Result is gl_cv_func_printf_directive_ls.
+
+AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether printf supports the 'ls' directive],
+    [gl_cv_func_printf_directive_ls],
+    [
+      AC_TRY_RUN([
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+   included before <wchar.h>.  */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+#include <string.h>
+static wchar_t wstring[] = { 'a', 'b', 'c', 0 };
+int main ()
+{
+  char buf[100];
+  buf[0] = '\0';
+  sprintf (buf, "%ls", wstring);
+  return strcmp (buf, "abc") != 0;
+}], [gl_cv_func_printf_directive_ls=yes], [gl_cv_func_printf_directive_ls=no],
+      [
+changequote(,)dnl
+       case "$host_os" in
+         openbsd*)        gl_cv_func_printf_directive_ls="guessing no";;
+         solaris2.[1-6]*) gl_cv_func_printf_directive_ls="guessing no";;
+         irix*)           gl_cv_func_printf_directive_ls="guessing no";;
+         beos* | haiku*)  gl_cv_func_printf_directive_ls="guessing no";;
+         *)               gl_cv_func_printf_directive_ls="guessing yes";;
+       esac
+changequote([,])dnl
+      ])
+    ])
+])
+
 dnl Test whether the *printf family of functions supports POSIX/XSI format
 dnl strings with positions. (POSIX:2001)
 dnl Result is gl_cv_func_printf_positions.
@@ -1261,18 +1304,19 @@ dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
 dnl 5 = gl_PRINTF_DIRECTIVE_A
 dnl 6 = gl_PRINTF_DIRECTIVE_F
 dnl 7 = gl_PRINTF_DIRECTIVE_N
-dnl 8 = gl_PRINTF_POSITIONS
-dnl 9 = gl_PRINTF_FLAG_GROUPING
-dnl 10 = gl_PRINTF_FLAG_LEFTADJUST
-dnl 11 = gl_PRINTF_FLAG_ZERO
-dnl 12 = gl_PRINTF_PRECISION
-dnl 13 = gl_PRINTF_ENOMEM
-dnl 14 = gl_SNPRINTF_PRESENCE
-dnl 15 = gl_SNPRINTF_TRUNCATION_C99
-dnl 16 = gl_SNPRINTF_RETVAL_C99
-dnl 17 = gl_SNPRINTF_DIRECTIVE_N
-dnl 18 = gl_SNPRINTF_SIZE1
-dnl 19 = gl_VSNPRINTF_ZEROSIZE_C99
+dnl 8 = gl_PRINTF_DIRECTIVE_LS
+dnl 9 = gl_PRINTF_POSITIONS
+dnl 10 = gl_PRINTF_FLAG_GROUPING
+dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
+dnl 12 = gl_PRINTF_FLAG_ZERO
+dnl 13 = gl_PRINTF_PRECISION
+dnl 14 = gl_PRINTF_ENOMEM
+dnl 15 = gl_SNPRINTF_PRESENCE
+dnl 16 = gl_SNPRINTF_TRUNCATION_C99
+dnl 17 = gl_SNPRINTF_RETVAL_C99
+dnl 18 = gl_SNPRINTF_DIRECTIVE_N
+dnl 19 = gl_SNPRINTF_SIZE1
+dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
 dnl
 dnl 1 = checking whether printf supports size specifiers as in C99...
 dnl 2 = checking whether printf supports 'long double' arguments...
@@ -1281,42 +1325,44 @@ dnl 4 = checking whether printf supports infinite 'long double' arguments...
 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
 dnl 6 = checking whether printf supports the 'F' directive...
 dnl 7 = checking whether printf supports the 'n' directive...
-dnl 8 = checking whether printf supports POSIX/XSI format strings with positions...
-dnl 9 = checking whether printf supports the grouping flag...
-dnl 10 = checking whether printf supports the left-adjust flag correctly...
-dnl 11 = checking whether printf supports the zero flag correctly...
-dnl 12 = checking whether printf supports large precisions...
-dnl 13 = checking whether printf survives out-of-memory conditions...
-dnl 14 = checking for snprintf...
-dnl 15 = checking whether snprintf truncates the result as in C99...
-dnl 16 = checking whether snprintf returns a byte count as in C99...
-dnl 17 = checking whether snprintf fully supports the 'n' directive...
-dnl 18 = checking whether snprintf respects a size of 1...
-dnl 19 = checking whether vsnprintf respects a zero size as in C99...
+dnl 8 = checking whether printf supports the 'ls' directive...
+dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
+dnl 10 = checking whether printf supports the grouping flag...
+dnl 11 = checking whether printf supports the left-adjust flag correctly...
+dnl 12 = checking whether printf supports the zero flag correctly...
+dnl 13 = checking whether printf supports large precisions...
+dnl 14 = checking whether printf survives out-of-memory conditions...
+dnl 15 = checking for snprintf...
+dnl 16 = checking whether snprintf truncates the result as in C99...
+dnl 17 = checking whether snprintf returns a byte count as in C99...
+dnl 18 = checking whether snprintf fully supports the 'n' directive...
+dnl 19 = checking whether snprintf respects a size of 1...
+dnl 20 = checking whether vsnprintf respects a zero size as in C99...
 dnl
 dnl . = yes, # = no.
 dnl
-dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
-dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
-dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .
-dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  .  #  .  #  .  .  .  .  .  .
-dnl   MacOS X 10.3.9                 .  .  .  .  #  .  .  .  .  .  #  .  #  .  .  .  .  .  .
-dnl   OpenBSD 3.9, 4.0               .  .  #  #  #  #  .  .  #  .  #  .  #  .  .  .  .  .  .
-dnl   Cygwin 2007 (= Cygwin 1.5.24)  .  .  .  .  #  #  .  .  .  ?  #  ?  ?  .  .  .  .  .  .
-dnl   Cygwin 2006 (= Cygwin 1.5.19)  #  .  .  .  #  #  .  .  #  ?  #  ?  ?  .  .  .  .  .  .
-dnl   Solaris 10                     .  .  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  .  .  .  #  .  .  #  #  #  #  #  #
-dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  .  .  .  .
-dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  #  .  .  .  .  #  #  .  .
-dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  #  .  .  .  .  #  #  .  #
-dnl   HP-UX 10.20                    #  .  .  .  #  #  .  .  .  #  #  .  .  .  .  #  #  ?  #
-dnl   IRIX 6.5                       #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  #  .  .  .
-dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  .  #  .  .  .  .  #  .  .  #
-dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  #  .  .  #  #  #  #  #  #
-dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
-dnl   NetBSD 3.0                     .  .  .  .  #  #  .  #  #  ?  #  .  #  .  .  .  .  .  .
-dnl   Haiku                          .  .  .  #  #  #  .  .  .  .  .  .  ?  .  .  .  .  .  .
-dnl   BeOS                           #  #  .  #  #  #  .  #  .  ?  .  #  ?  .  .  .  .  .  .
-dnl   mingw                          #  #  #  #  #  #  .  #  #  .  #  #  ?  .  #  #  #  .  .
+dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
+dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
+dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
+dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
+dnl   MacOS X 10.3.9                 .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
+dnl   OpenBSD 3.9, 4.0               .  .  #  #  #  #  .  #  .  #  .  #  .  #  .  .  .  .  .  .
+dnl   Cygwin 2007 (= Cygwin 1.5.24)  .  .  .  .  #  #  .  .  .  .  ?  #  ?  ?  .  .  .  .  .  .
+dnl   Cygwin 2006 (= Cygwin 1.5.19)  #  .  .  .  #  #  .  ?  .  #  ?  #  ?  ?  .  .  .  .  .  .
+dnl   Solaris 10                     .  .  #  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   Solaris 7 ... 9                #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   Solaris 2.6                    #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  #  .  .  .  #  .  .  #  #  #  #  #  #
+dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  .  #  .  .  .  .  #  #  .  .
+dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  .  #  .  .  .  .  #  #  .  #
+dnl   HP-UX 10.20                    #  .  .  .  #  #  .  ?  .  .  #  #  .  .  .  .  #  #  ?  #
+dnl   IRIX 6.5                       #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  #  .  .  .
+dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  #
+dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  .  #  .  .  #  #  #  #  #  #
+dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  ?  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
+dnl   NetBSD 3.0                     .  .  .  .  #  #  .  ?  #  #  ?  #  .  #  .  .  .  .  .  .
+dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  .  .  .  .  .  .
+dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  .  .  .  .  .  .
+dnl   mingw                          #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .
diff --git a/m4/snprintf-posix.m4 b/m4/snprintf-posix.m4
index 5225f634af..88e52f396b 100644
--- a/m4/snprintf-posix.m4
+++ b/m4/snprintf-posix.m4
@@ -1,5 +1,5 @@
-# snprintf-posix.m4 serial 13
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# snprintf-posix.m4 serial 14
+dnl Copyright (C) 2007-2009 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.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -41,31 +42,35 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
                           *yes)
                             case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_positions" in
+                                case "$gl_cv_func_printf_directive_ls" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_grouping" in
+                                    case "$gl_cv_func_printf_positions" in
                                       *yes)
-                                        case "$gl_cv_func_printf_flag_leftadjust" in
+                                        case "$gl_cv_func_printf_flag_grouping" in
                                           *yes)
-                                            case "$gl_cv_func_printf_flag_zero" in
+                                            case "$gl_cv_func_printf_flag_leftadjust" in
                                               *yes)
-                                                case "$gl_cv_func_printf_precision" in
+                                                case "$gl_cv_func_printf_flag_zero" in
                                                   *yes)
-                                                    case "$gl_cv_func_printf_enomem" in
+                                                    case "$gl_cv_func_printf_precision" in
                                                       *yes)
-                                                        case "$gl_cv_func_snprintf_truncation_c99" in
+                                                        case "$gl_cv_func_printf_enomem" in
                                                           *yes)
-                                                            case "$gl_cv_func_snprintf_retval_c99" in
+                                                            case "$gl_cv_func_snprintf_truncation_c99" in
                                                               *yes)
-                                                                case "$gl_cv_func_snprintf_directive_n" in
+                                                                case "$gl_cv_func_snprintf_retval_c99" in
                                                                   *yes)
-                                                                    case "$gl_cv_func_snprintf_size1" in
+                                                                    case "$gl_cv_func_snprintf_directive_n" in
                                                                       *yes)
-                                                                        case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                                        case "$gl_cv_func_snprintf_size1" in
                                                                           *yes)
-                                                                            # snprintf exists and is
-                                                                            # already POSIX compliant.
-                                                                            gl_cv_func_snprintf_posix=yes
+                                                                            case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                                              *yes)
+                                                                                # snprintf exists and is
+                                                                                # already POSIX compliant.
+                                                                                gl_cv_func_snprintf_posix=yes
+                                                                                ;;
+                                                                            esac
                                                                             ;;
                                                                         esac
                                                                         ;;
@@ -109,6 +114,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
     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
diff --git a/m4/sprintf-posix.m4 b/m4/sprintf-posix.m4
index a35060caca..3c43bfb1b8 100644
--- a/m4/sprintf-posix.m4
+++ b/m4/sprintf-posix.m4
@@ -1,5 +1,5 @@
-# sprintf-posix.m4 serial 11
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# sprintf-posix.m4 serial 12
+dnl Copyright (C) 2007-2009 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.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -34,21 +35,25 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
                         *yes)
                           case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_positions" in
+                              case "$gl_cv_func_printf_directive_ls" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_grouping" in
+                                  case "$gl_cv_func_printf_positions" in
                                     *yes)
-                                      case "$gl_cv_func_printf_flag_leftadjust" in
+                                      case "$gl_cv_func_printf_flag_grouping" in
                                         *yes)
-                                          case "$gl_cv_func_printf_flag_zero" in
+                                          case "$gl_cv_func_printf_flag_leftadjust" in
                                             *yes)
-                                              case "$gl_cv_func_printf_precision" in
+                                              case "$gl_cv_func_printf_flag_zero" in
                                                 *yes)
-                                                  case "$gl_cv_func_printf_enomem" in
+                                                  case "$gl_cv_func_printf_precision" in
                                                     *yes)
-                                                      # sprintf exists and is
-                                                      # already POSIX compliant.
-                                                      gl_cv_func_sprintf_posix=yes
+                                                      case "$gl_cv_func_printf_enomem" in
+                                                        *yes)
+                                                          # sprintf exists and is
+                                                          # already POSIX compliant.
+                                                          gl_cv_func_sprintf_posix=yes
+                                                          ;;
+                                                      esac
                                                       ;;
                                                   esac
                                                   ;;
@@ -81,6 +86,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
     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
diff --git a/m4/vasnprintf-posix.m4 b/m4/vasnprintf-posix.m4
index 078d2651f3..f32a3ae38c 100644
--- a/m4/vasnprintf-posix.m4
+++ b/m4/vasnprintf-posix.m4
@@ -1,5 +1,5 @@
-# vasnprintf-posix.m4 serial 12
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# vasnprintf-posix.m4 serial 13
+dnl Copyright (C) 2007-2009 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.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -35,23 +36,27 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
                         *yes)
                           case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_positions" in
+                              case "$gl_cv_func_printf_directive_ls" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_grouping" in
+                                  case "$gl_cv_func_printf_positions" in
                                     *yes)
-                                      case "$gl_cv_func_printf_flag_leftadjust" in
+                                      case "$gl_cv_func_printf_flag_grouping" in
                                         *yes)
-                                          case "$gl_cv_func_printf_flag_zero" in
+                                          case "$gl_cv_func_printf_flag_leftadjust" in
                                             *yes)
-                                              case "$gl_cv_func_printf_precision" in
+                                              case "$gl_cv_func_printf_flag_zero" in
                                                 *yes)
-                                                  case "$gl_cv_func_printf_enomem" in
+                                                  case "$gl_cv_func_printf_precision" in
                                                     *yes)
-                                                      if test $ac_cv_func_vasnprintf = yes; then
-                                                        # vasnprintf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_vasnprintf_posix=yes
-                                                      fi
+                                                      case "$gl_cv_func_printf_enomem" in
+                                                        *yes)
+                                                          if test $ac_cv_func_vasnprintf = yes; then
+                                                            # vasnprintf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_vasnprintf_posix=yes
+                                                          fi
+                                                          ;;
+                                                      esac
                                                       ;;
                                                   esac
                                                   ;;
@@ -84,6 +89,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
     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
diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4
index 0aeb157e7f..01e8772f11 100644
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 27
+# vasnprintf.m4 serial 28
 dnl Copyright (C) 2002-2004, 2006-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -150,6 +150,21 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
   esac
 ])
 
+# Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
+[
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+  case "$gl_cv_func_printf_directive_ls" in
+    *yes)
+      ;;
+    *)
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1],
+        [Define if the vasnprintf implementation needs special code for
+         the 'ls' directive.])
+      ;;
+  esac
+])
+
 # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
 [
@@ -247,6 +262,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
   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
diff --git a/m4/vasprintf-posix.m4 b/m4/vasprintf-posix.m4
index 0bee9e47e1..7ea6daa336 100644
--- a/m4/vasprintf-posix.m4
+++ b/m4/vasprintf-posix.m4
@@ -1,5 +1,5 @@
-# vasprintf-posix.m4 serial 12
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# vasprintf-posix.m4 serial 13
+dnl Copyright (C) 2007-2009 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.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -35,23 +36,27 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
                         *yes)
                           case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_positions" in
+                              case "$gl_cv_func_printf_directive_ls" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_grouping" in
+                                  case "$gl_cv_func_printf_positions" in
                                     *yes)
-                                      case "$gl_cv_func_printf_flag_leftadjust" in
+                                      case "$gl_cv_func_printf_flag_grouping" in
                                         *yes)
-                                          case "$gl_cv_func_printf_flag_zero" in
+                                          case "$gl_cv_func_printf_flag_leftadjust" in
                                             *yes)
-                                              case "$gl_cv_func_printf_precision" in
+                                              case "$gl_cv_func_printf_flag_zero" in
                                                 *yes)
-                                                  case "$gl_cv_func_printf_enomem" in
+                                                  case "$gl_cv_func_printf_precision" in
                                                     *yes)
-                                                      if test $ac_cv_func_vasprintf = yes; then
-                                                        # vasprintf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_vasprintf_posix=yes
-                                                      fi
+                                                      case "$gl_cv_func_printf_enomem" in
+                                                        *yes)
+                                                          if test $ac_cv_func_vasprintf = yes; then
+                                                            # vasprintf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_vasprintf_posix=yes
+                                                          fi
+                                                          ;;
+                                                      esac
                                                       ;;
                                                   esac
                                                   ;;
@@ -84,6 +89,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
     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
diff --git a/m4/vdprintf-posix.m4 b/m4/vdprintf-posix.m4
index 70536b4b50..6c1d62d20c 100644
--- a/m4/vdprintf-posix.m4
+++ b/m4/vdprintf-posix.m4
@@ -1,4 +1,4 @@
-# vdprintf-posix.m4 serial 1
+# vdprintf-posix.m4 serial 2
 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -36,21 +37,25 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX],
                           *yes)
                             case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_positions" in
+                                case "$gl_cv_func_printf_directive_ls" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_grouping" in
+                                    case "$gl_cv_func_printf_positions" in
                                       *yes)
-                                        case "$gl_cv_func_printf_flag_leftadjust" in
+                                        case "$gl_cv_func_printf_flag_grouping" in
                                           *yes)
-                                            case "$gl_cv_func_printf_flag_zero" in
+                                            case "$gl_cv_func_printf_flag_leftadjust" in
                                               *yes)
-                                                case "$gl_cv_func_printf_precision" in
+                                                case "$gl_cv_func_printf_flag_zero" in
                                                   *yes)
-                                                    case "$gl_cv_func_printf_enomem" in
+                                                    case "$gl_cv_func_printf_precision" in
                                                       *yes)
-                                                        # vdprintf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_vdprintf_posix=yes
+                                                        case "$gl_cv_func_printf_enomem" in
+                                                          *yes)
+                                                            # vdprintf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_vdprintf_posix=yes
+                                                            ;;
+                                                        esac
                                                         ;;
                                                     esac
                                                     ;;
@@ -84,6 +89,7 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX],
     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
diff --git a/m4/vfprintf-posix.m4 b/m4/vfprintf-posix.m4
index f795b72558..9f6317ab05 100644
--- a/m4/vfprintf-posix.m4
+++ b/m4/vfprintf-posix.m4
@@ -1,4 +1,4 @@
-# vfprintf-posix.m4 serial 13
+# vfprintf-posix.m4 serial 14
 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -34,21 +35,25 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
                         *yes)
                           case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_positions" in
+                              case "$gl_cv_func_printf_directive_ls" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_grouping" in
+                                  case "$gl_cv_func_printf_positions" in
                                     *yes)
-                                      case "$gl_cv_func_printf_flag_leftadjust" in
+                                      case "$gl_cv_func_printf_flag_grouping" in
                                         *yes)
-                                          case "$gl_cv_func_printf_flag_zero" in
+                                          case "$gl_cv_func_printf_flag_leftadjust" in
                                             *yes)
-                                              case "$gl_cv_func_printf_precision" in
+                                              case "$gl_cv_func_printf_flag_zero" in
                                                 *yes)
-                                                  case "$gl_cv_func_printf_enomem" in
+                                                  case "$gl_cv_func_printf_precision" in
                                                     *yes)
-                                                      # vfprintf exists and is
-                                                      # already POSIX compliant.
-                                                      gl_cv_func_vfprintf_posix=yes
+                                                      case "$gl_cv_func_printf_enomem" in
+                                                        *yes)
+                                                          # vfprintf exists and is
+                                                          # already POSIX compliant.
+                                                          gl_cv_func_vfprintf_posix=yes
+                                                          ;;
+                                                      esac
                                                       ;;
                                                   esac
                                                   ;;
@@ -81,6 +86,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
     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
diff --git a/m4/vsnprintf-posix.m4 b/m4/vsnprintf-posix.m4
index 17b8d433e1..7967e780c5 100644
--- a/m4/vsnprintf-posix.m4
+++ b/m4/vsnprintf-posix.m4
@@ -1,5 +1,5 @@
-# vsnprintf-posix.m4 serial 13
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# vsnprintf-posix.m4 serial 14
+dnl Copyright (C) 2007-2009 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.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -42,31 +43,35 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
                           *yes)
                             case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_positions" in
+                                case "$gl_cv_func_printf_directive_ls" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_grouping" in
+                                    case "$gl_cv_func_printf_positions" in
                                       *yes)
-                                        case "$gl_cv_func_printf_flag_leftadjust" in
+                                        case "$gl_cv_func_printf_flag_grouping" in
                                           *yes)
-                                            case "$gl_cv_func_printf_flag_zero" in
+                                            case "$gl_cv_func_printf_flag_leftadjust" in
                                               *yes)
-                                                case "$gl_cv_func_printf_precision" in
+                                                case "$gl_cv_func_printf_flag_zero" in
                                                   *yes)
-                                                    case "$gl_cv_func_printf_enomem" in
+                                                    case "$gl_cv_func_printf_precision" in
                                                       *yes)
-                                                        case "$gl_cv_func_snprintf_truncation_c99" in
+                                                        case "$gl_cv_func_printf_enomem" in
                                                           *yes)
-                                                            case "$gl_cv_func_snprintf_retval_c99" in
+                                                            case "$gl_cv_func_snprintf_truncation_c99" in
                                                               *yes)
-                                                                case "$gl_cv_func_snprintf_directive_n" in
+                                                                case "$gl_cv_func_snprintf_retval_c99" in
                                                                   *yes)
-                                                                    case "$gl_cv_func_snprintf_size1" in
+                                                                    case "$gl_cv_func_snprintf_directive_n" in
                                                                       *yes)
-                                                                        case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                                        case "$gl_cv_func_snprintf_size1" in
                                                                           *yes)
-                                                                            # vsnprintf exists and is
-                                                                            # already POSIX compliant.
-                                                                            gl_cv_func_vsnprintf_posix=yes
+                                                                            case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                                              *yes)
+                                                                                # vsnprintf exists and is
+                                                                                # already POSIX compliant.
+                                                                                gl_cv_func_vsnprintf_posix=yes
+                                                                                ;;
+                                                                            esac
                                                                             ;;
                                                                         esac
                                                                         ;;
@@ -110,6 +115,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
     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
diff --git a/m4/vsprintf-posix.m4 b/m4/vsprintf-posix.m4
index a31b72baa6..19eb402fa9 100644
--- a/m4/vsprintf-posix.m4
+++ b/m4/vsprintf-posix.m4
@@ -1,5 +1,5 @@
-# vsprintf-posix.m4 serial 11
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# vsprintf-posix.m4 serial 12
+dnl Copyright (C) 2007-2009 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.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
   AC_REQUIRE([gl_PRINTF_POSITIONS])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -34,21 +35,25 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
                         *yes)
                           case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_positions" in
+                              case "$gl_cv_func_printf_directive_ls" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_grouping" in
+                                  case "$gl_cv_func_printf_positions" in
                                     *yes)
-                                      case "$gl_cv_func_printf_flag_leftadjust" in
+                                      case "$gl_cv_func_printf_flag_grouping" in
                                         *yes)
-                                          case "$gl_cv_func_printf_flag_zero" in
+                                          case "$gl_cv_func_printf_flag_leftadjust" in
                                             *yes)
-                                              case "$gl_cv_func_printf_precision" in
+                                              case "$gl_cv_func_printf_flag_zero" in
                                                 *yes)
-                                                  case "$gl_cv_func_printf_enomem" in
+                                                  case "$gl_cv_func_printf_precision" in
                                                     *yes)
-                                                      # vsprintf exists and is
-                                                      # already POSIX compliant.
-                                                      gl_cv_func_vsprintf_posix=yes
+                                                      case "$gl_cv_func_printf_enomem" in
+                                                        *yes)
+                                                          # vsprintf exists and is
+                                                          # already POSIX compliant.
+                                                          gl_cv_func_vsprintf_posix=yes
+                                                          ;;
+                                                      esac
                                                       ;;
                                                   esac
                                                   ;;
@@ -81,6 +86,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
     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
-- 
2.39.5