Work around a *printf bug with %ls on Solaris.
authorBruno Haible <bruno@clisp.org>
Fri, 27 Feb 2009 01:14:00 +0000 (02:14 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 27 Feb 2009 01:15:26 +0000 (02:15 +0100)
12 files changed:
ChangeLog
doc/glibc-functions/obstack_printf.texi
doc/glibc-functions/obstack_vprintf.texi
doc/posix-functions/fprintf.texi
doc/posix-functions/printf.texi
doc/posix-functions/snprintf.texi
doc/posix-functions/sprintf.texi
doc/posix-functions/vfprintf.texi
doc/posix-functions/vprintf.texi
doc/posix-functions/vsnprintf.texi
doc/posix-functions/vsprintf.texi
m4/printf.m4

index a34e3f835cf99aa5dc37ffe10908e558ea77cb79..583fa8f13ef01652a5280ab0d12a908296452332 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2009-02-26  Eric Blake  <ebb9@byu.net>
+            Bruno Haible  <bruno@clisp.org>
+
+       Work around a *printf bug with %ls on Solaris.
+       * m4/printf.m4 (gl_PRINTF_DIRECTIVE_LS): Also test whether, when a
+       precision is specified, sprintf stops converting the wide string
+       argument when the number of bytes that have been produced by this
+       conversion equals or exceeds the precision.
+       * 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.
+
 2009-02-26  Eric Blake  <ebb9@byu.net>
 
        stdlib: favor compiler check of random.h
index 83d4c6ce69d25c7fdbf20987f7e707d3a07dce27..7a5726486f4430d651a4242c2d1d8d063930cf98 100644 (file)
@@ -38,6 +38,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index ef0d6f5272b4ad1e208f1c15a9954b9f0e563efb..8556f74b7b6bd30cc8cd3dadee6c9f274dd7a8d5 100644 (file)
@@ -38,6 +38,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index 0af41ae8764805508b87b115d6633fc80b8124b0..0434e4422e4b79c73e0030fe18698de53af56974 100644 (file)
@@ -32,6 +32,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index da57b21051b4b58c295971bb73d4580549c82faf..1783ad22626e7be55a38ca2fe9d5da7a171e5041 100644 (file)
@@ -32,6 +32,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index a0ab770b0ef632c60aa2713f70880bf46695c44e..d8ecbcccd651ac542de8e6463e867894e96eb5cd 100644 (file)
@@ -43,6 +43,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index 756feec5f6df93e308dac2fa64aa4eaa53e2388d..003fb44b853fd2b5836eed8eabf895220c14cf80 100644 (file)
@@ -32,6 +32,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index 90d9fa11d52dbad926e0af5a0f35a93f914a4827..37c2d11b1f38b6faf1010db0b5d066ad18f082e4 100644 (file)
@@ -32,6 +32,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index f3462bc34e4f9f81420aa12dd2d6e4e2047e1320..453117245f86af7c4bd06aeedbde8441ccf8a1b3 100644 (file)
@@ -32,6 +32,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index 294c6eafa9120597b3105fc829c4084016cd2a61..f09e0543ac6e9cc65c5f220317cfb3a2b41d3c12 100644 (file)
@@ -43,6 +43,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index beda4a8deb17edc5942acec2f51a6d0acb5b9d4f..d477b4b3f48390d0118f13bddb837a637524a247 100644 (file)
@@ -32,6 +32,10 @@ Cygwin 1.5.x, mingw, BeOS.
 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 precisions in the @samp{ls} directive correctly
+on some platforms:
+Solaris 10.
+@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.
index f3e201b52992e6acd242f90185c917d03992fc8a..4207ace49f3972687b86130c00f0cda9d427c527 100644 (file)
@@ -1,4 +1,4 @@
-# printf.m4 serial 30
+# printf.m4 serial 31
 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,
@@ -626,7 +626,10 @@ changequote([,])dnl
 ])
 
 dnl Test whether the *printf family of functions supports the %ls format
-dnl directive.
+dnl directive and in particular, when a precision is specified, whether
+dnl the functions stop converting the wide string argument when the number
+dnl of bytes that have been produced by this conversion equals or exceeds
+dnl the precision.
 dnl Result is gl_cv_func_printf_directive_ls.
 
 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
@@ -646,19 +649,40 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
 #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;
+  /* Test whether %ls works at all.
+     This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku.  */
+  {
+    static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
+    buf[0] = '\0';
+    if (sprintf (buf, "%ls", wstring) < 0
+        || strcmp (buf, "abc") != 0)
+      return 1;
+  }
+  /* Test whether precisions in %ls are supported as specified in ISO C 99
+     section 7.19.6.1:
+       "If a precision is specified, no more than that many bytes are written
+        (including shift sequences, if any), and the array shall contain a
+        null wide character if, to equal the multibyte character sequence
+        length given by the precision, the function would need to access a
+        wide character one past the end of the array."
+     This test fails on Solaris 10.  */
+  {
+    static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
+    buf[0] = '\0';
+    if (sprintf (buf, "%.2ls", wstring) < 0
+        || strcmp (buf, "ab") != 0)
+      return 1;
+  }
+  return 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";;
+         solaris*)        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";;
@@ -1362,9 +1386,8 @@ 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 10                     .  .  #  #  #  .  .  #  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  .  .  .  .
 dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  #  .  .  .  #  .  .  #  #  #  #  #  #
 dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
 dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .