2 dnl @synopsis FC_FUNC_VSNPRINTF
4 dnl Check whether there is a reasonably sane vsnprintf() function installed.
5 dnl "Reasonably sane" in this context means never clobbering memory beyond
6 dnl the buffer supplied, and having a sensible return value. It is
7 dnl explicitly allowed not to NUL-terminate the return value, however.
10 dnl @author Gaute Strokkenes <gs234@cam.ac.uk>
12 AC_DEFUN([FC_FUNC_VSNPRINTF],
13 [AC_CACHE_CHECK([for working vsnprintf],
14 [ac_cv_func_working_vsnprintf],
15 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
28 r = vsnprintf(buffer, 5, s, args);
31 /* -1 is pre-C99, 7 is C99. */
33 if (r != -1 && r != 7)
36 /* We deliberately do not care if the result is NUL-terminated or
37 not, since this is easy to work around like this. */
41 /* Simple sanity check. */
43 if (strcmp(buffer, "1234"))
57 }]])],[ac_cv_func_working_vsnprintf=yes],[ac_cv_func_working_vsnprintf=no],[ac_cv_func_working_vsnprintf=no])])
58 dnl Note that the default is to be pessimistic in the case of cross compilation.
59 dnl If you know that the target has a sensible vsnprintf(), you can get around this
60 dnl by setting ac_func_vsnprintf to yes, as described in the Autoconf manual.
61 if test $ac_cv_func_working_vsnprintf = yes; then
62 AC_DEFINE([HAVE_WORKING_VSNPRINTF], [1],
63 [Define if you have a version of the 'vsnprintf' function
64 that honours the size argument and has a proper return value.])