vsnprintf: make more consistent with snprintf; doc fixes
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 24 Dec 2010 07:32:55 +0000 (23:32 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 24 Dec 2010 07:33:30 +0000 (23:33 -0800)
* 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.

ChangeLog
doc/posix-functions/snprintf.texi
doc/posix-functions/vsnprintf.texi
m4/vsnprintf.m4
tests/test-snprintf.c
tests/test-vsnprintf.c

index 128931a..f53bcb4 100644 (file)
--- 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
index 23fa5e7..5d19ccf 100644 (file)
@@ -12,6 +12,9 @@ Portability problems fixed by either Gnulib module @code{snprintf} or @code{snpr
 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 @@ MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0.
 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
index 8f6d903..38266a0 100644 (file)
@@ -15,6 +15,9 @@ IRIX 5.3, OSF/1 4.0, Solaris 2.5.1.
 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 @@ MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0.
 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
index ed189c2..17109a7 100644 (file)
@@ -13,7 +13,12 @@ AC_DEFUN([gl_FUNC_VSNPRINTF],
     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
index 62a411b..e408d48 100644 (file)
@@ -34,15 +34,16 @@ main (int argc, char *argv[])
   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 @@ main (int argc, char *argv[])
         }
       else
         {
-          ASSERT (retval == 5);
           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
         }
     }
index 1bfa554..7234da3 100644 (file)
@@ -47,15 +47,16 @@ main (int argc, char *argv[])
   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 @@ main (int argc, char *argv[])
         }
       else
         {
-          ASSERT (retval == 5);
           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
         }
     }