+2011-07-05 Eric Blake <eblake@redhat.com>
+
+ snprintf: guarantee %1$d, for libintl
+ * m4/snprintf.m4 (gl_FUNC_SNPRINTF): Require %1$d support.
+ * m4/vsnprintf.m4 (gl_FUNC_VSNPRINTF): Likewise.
+ * doc/posix-functions/snprintf.texi (snprintf): Update.
+ * doc/posix-functions/vsnprintf.texi (vsnprintf): Likewise.
+ * tests/test-snprintf.c (main): Enhance test.
+ * tests/test-vsnprintf.c (main): Likewise.
+
2011-07-05 Jim Meyering <meyering@redhat.com>
maint: exempt stdio-read.c and stdio-write.c from the cppi check
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:
+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.
+@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.
+Linux libc5, BeOS.
@end itemize
Portability problems fixed by Gnulib module @code{snprintf-posix}:
on some platforms:
Solaris 11 2010-11.
@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.
-@item
This function doesn't support the @code{'} flag on some platforms:
NetBSD 3.0, Cygwin 1.5.24, mingw.
@item
This function does not fully support the @samp{n} directive on some platforms:
HP-UX 11, mingw.
@item
-This function overwrites memory when a size = 1 argument is passed on some
-platforms:
-BeOS.
-@item
This function overwrites memory even when a zero size argument is passed on some
platforms:
OSF/1 5.1.
This function is missing on some platforms:
IRIX 5.3, OSF/1 4.0, Solaris 2.5.1.
@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.
+@item
This function overwrites memory even when a size argument of 1 is passed on some
platforms:
-Linux libc5.
+Linux libc5, BeOS.
@item
-This function does not return a byte count as specified in C99 on some platforms:
+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
on some platforms:
Solaris 11 2010-11.
@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.
-@item
This function doesn't support the @code{'} flag on some platforms:
NetBSD 3.0, Cygwin 1.5.24, mingw.
@item
This function does not fully support the @samp{n} directive on some platforms:
HP-UX 11, mingw.
@item
-This function overwrites memory when a size = 1 argument is passed on some
-platforms:
-BeOS.
-@item
This function overwrites memory even when a zero size argument is passed on some
platforms:
HP-UX 11, OSF/1 5.1.
-# snprintf.m4 serial 5
+# snprintf.m4 serial 6
dnl Copyright (C) 2002-2004, 2007-2011 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.
+dnl Libintl 0.17 will replace snprintf only if it does not support %1$s,
+dnl but defers to any gnulib snprintf replacements. Therefore, gnulib
+dnl must guarantee that the decision for replacing snprintf is a superset
+dnl of the reasons checked by libintl.
AC_DEFUN([gl_FUNC_SNPRINTF],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
gl_SNPRINTF_RETVAL_C99
case "$gl_cv_func_snprintf_retval_c99" in
*yes)
- gl_cv_func_snprintf_usable=yes
+ gl_PRINTF_POSITIONS
+ case "$gl_cv_func_printf_positions" in
+ *yes)
+ gl_cv_func_snprintf_usable=yes
+ ;;
+ esac
;;
esac
;;
-# vsnprintf.m4 serial 5
+# vsnprintf.m4 serial 6
dnl Copyright (C) 2002-2004, 2007-2011 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.
+dnl Libintl 0.17 will replace vsnprintf only if it does not support %1$s,
+dnl but defers to any gnulib vsnprintf replacements. Therefore, gnulib
+dnl must guarantee that the decision for replacing vsnprintf is a superset
+dnl of the reasons checked by libintl.
AC_DEFUN([gl_FUNC_VSNPRINTF],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
gl_SNPRINTF_RETVAL_C99
case "$gl_cv_func_snprintf_retval_c99" in
*yes)
- gl_cv_func_vsnprintf_usable=yes
+ gl_PRINTF_POSITIONS
+ case "$gl_cv_func_printf_positions" in
+ *yes)
+ gl_cv_func_vsnprintf_usable=yes
+ ;;
+ esac
;;
esac
;;
}
}
+ /* Test the support of the POSIX/XSI format strings with positions. */
+ {
+ char result[100];
+ int retval = snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
+ ASSERT (strcmp (result, "55 33") == 0);
+ ASSERT (retval == strlen (result));
+ }
+
return 0;
}
}
}
+ /* Test the support of the POSIX/XSI format strings with positions. */
+ {
+ char result[100];
+ int retval = my_snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
+ ASSERT (strcmp (result, "55 33") == 0);
+ ASSERT (retval == strlen (result));
+ }
+
return 0;
}