changeset 14003:f82a977dcf0b

vsnprintf: make more consistent with snprintf; doc fixes * doc/posix-functions/snprintf.texi (snprintf): The workaround for the byte count return problem was promoted from the snprintf-posix to the snprintf module. * doc/posix-functions/vsnprintf.texi (vsnprintf): Likewise. * m4/vsnprintf.m4 (gl_FUNC_VSNPRINTF): Also check gl_SNPRINTF_RETVAL_C99, for consistency with gl_FUNC_SNPRINTF. * tests/test-snprintf.c (main): Check the byte count returned. * tests/test-vsnprintf.c (main): Likewise.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 23 Dec 2010 23:32:55 -0800
parents b9abed08d82e
children 054a6361f124
files ChangeLog doc/posix-functions/snprintf.texi doc/posix-functions/vsnprintf.texi m4/vsnprintf.m4 tests/test-snprintf.c tests/test-vsnprintf.c
diffstat 6 files changed, 33 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2010-12-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+	vsnprintf: make more consistent with snprintf; doc fixes
+
+	* doc/posix-functions/snprintf.texi (snprintf): The workaround for
+	the byte count return problem was promoted from the snprintf-posix
+	to the snprintf module.
+	* doc/posix-functions/vsnprintf.texi (vsnprintf): Likewise.
+	* m4/vsnprintf.m4 (gl_FUNC_VSNPRINTF): Also check
+	gl_SNPRINTF_RETVAL_C99, for consistency with gl_FUNC_SNPRINTF.
+	* tests/test-snprintf.c (main): Check the byte count returned.
+	* tests/test-vsnprintf.c (main): Likewise.
+
 2010-12-23  Eric Blake  <eblake@redhat.com>
 
 	sigpipe: relax to LGPLv2+, since it did not have any LGPLv3+ parts
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -12,6 +12,9 @@
 This function is missing on some platforms:
 IRIX 5.3, OSF/1 4.0, Solaris 2.5.1.
 @item
+This function does not return a byte count as specified in C99 on some platforms:
+HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw.
+@item
 This function overwrites memory even when a size argument of 1 is passed on some
 platforms:
 Linux libc5.
@@ -72,9 +75,6 @@
 This function does not truncate the result as specified in C99 on some platforms:
 mingw.
 @item
-This function does not return a byte count as specified in C99 on some platforms:
-HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw.
-@item
 This function does not fully support the @samp{n} directive on some platforms:
 HP-UX 11, mingw.
 @item
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -15,6 +15,9 @@
 This function overwrites memory even when a size argument of 1 is passed on some
 platforms:
 Linux libc5.
+@item
+This function does not return a byte count as specified in C99 on some platforms:
+HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{vsnprintf-posix}:
@@ -72,9 +75,6 @@
 This function does not truncate the result as specified in C99 on some platforms:
 mingw.
 @item
-This function does not return a byte count as specified in C99 on some platforms:
-HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw.
-@item
 This function does not fully support the @samp{n} directive on some platforms:
 HP-UX 11, mingw.
 @item
--- a/m4/vsnprintf.m4
+++ b/m4/vsnprintf.m4
@@ -13,7 +13,12 @@
     gl_SNPRINTF_SIZE1
     case "$gl_cv_func_snprintf_size1" in
       *yes)
-        gl_cv_func_vsnprintf_usable=yes
+        gl_SNPRINTF_RETVAL_C99
+        case "$gl_cv_func_snprintf_retval_c99" in
+          *yes)
+            gl_cv_func_vsnprintf_usable=yes
+            ;;
+        esac
         ;;
     esac
   fi
--- a/tests/test-snprintf.c
+++ b/tests/test-snprintf.c
@@ -34,15 +34,16 @@
   int size;
   int retval;
 
+  retval = snprintf (NULL, 0, "%d", 12345);
+  ASSERT (retval == 5);
+
   for (size = 0; size <= 8; size++)
     {
       memcpy (buf, "DEADBEEF", 8);
       retval = snprintf (buf, size, "%d", 12345);
+      ASSERT (retval == 5);
       if (size < 6)
         {
-#if CHECK_SNPRINTF_POSIX
-          ASSERT (retval < 0 || retval >= size);
-#endif
           if (size > 0)
             {
               ASSERT (memcmp (buf, "12345", size - 1) == 0);
@@ -55,7 +56,6 @@
         }
       else
         {
-          ASSERT (retval == 5);
           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
         }
     }
--- a/tests/test-vsnprintf.c
+++ b/tests/test-vsnprintf.c
@@ -47,15 +47,16 @@
   int size;
   int retval;
 
+  retval = my_snprintf (NULL, 0, "%d", 12345);
+  ASSERT (retval == 5);
+
   for (size = 0; size <= 8; size++)
     {
       memcpy (buf, "DEADBEEF", 8);
       retval = my_snprintf (buf, size, "%d", 12345);
+      ASSERT (retval == 5);
       if (size < 6)
         {
-#if CHECK_VSNPRINTF_POSIX
-          ASSERT (retval < 0 || retval >= size);
-#endif
           if (size > 0)
             {
               ASSERT (memcmp (buf, "12345", size - 1) == 0);
@@ -68,7 +69,6 @@
         }
       else
         {
-          ASSERT (retval == 5);
           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
         }
     }