From 562547d19b88ca771061280e43c4c97143e43463 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 23 Dec 2010 23:32:55 -0800 Subject: [PATCH] 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. --- ChangeLog | 13 +++++++++++++ doc/posix-functions/snprintf.texi | 6 +++--- doc/posix-functions/vsnprintf.texi | 6 +++--- m4/vsnprintf.m4 | 7 ++++++- tests/test-snprintf.c | 8 ++++---- tests/test-vsnprintf.c | 8 ++++---- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 128931a16..f53bcb4c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-12-23 Paul Eggert + + 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 sigpipe: relax to LGPLv2+, since it did not have any LGPLv3+ parts diff --git a/doc/posix-functions/snprintf.texi b/doc/posix-functions/snprintf.texi index 23fa5e7f4..5d19ccf11 100644 --- a/doc/posix-functions/snprintf.texi +++ b/doc/posix-functions/snprintf.texi @@ -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 diff --git a/doc/posix-functions/vsnprintf.texi b/doc/posix-functions/vsnprintf.texi index 8f6d90376..38266a01e 100644 --- a/doc/posix-functions/vsnprintf.texi +++ b/doc/posix-functions/vsnprintf.texi @@ -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 diff --git a/m4/vsnprintf.m4 b/m4/vsnprintf.m4 index ed189c238..17109a7a2 100644 --- a/m4/vsnprintf.m4 +++ b/m4/vsnprintf.m4 @@ -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 diff --git a/tests/test-snprintf.c b/tests/test-snprintf.c index 62a411bf9..e408d481f 100644 --- a/tests/test-snprintf.c +++ b/tests/test-snprintf.c @@ -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); } } diff --git a/tests/test-vsnprintf.c b/tests/test-vsnprintf.c index 1bfa5540f..7234da31c 100644 --- a/tests/test-vsnprintf.c +++ b/tests/test-vsnprintf.c @@ -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); } } -- 2.11.0