From: mquinson Date: Fri, 11 Dec 2009 08:57:14 +0000 (+0000) Subject: also activate our asprintf internal implementation if there is one in libc, but a... X-Git-Tag: SVN~847 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b799df7cc12d5618c96b0b1cb53c348bc810c0a6?hp=e96a26bb1ef3e4651e20e51431289aa7dff90aae also activate our asprintf internal implementation if there is one in libc, but a broken one. Say hello to ubuntu ;) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6879 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/acmacro/ac_func_asprintf.m4 b/acmacro/ac_func_asprintf.m4 new file mode 100644 index 0000000000..2599ef9fa7 --- /dev/null +++ b/acmacro/ac_func_asprintf.m4 @@ -0,0 +1,65 @@ +dnl @synopsis AC_FUNC_ASPRINTF +dnl +dnl Checks for a compilable asprintf. + +dnl Define NEED_ASPRINTF (to 1) if no working asprintf is found +dnl Define NEED_VASPRINTF (to 1) if no working vasprintf is found +dnl +dnl Note: the mentioned replacement is freely available and +dnl may be used in any project regardless of it's licence (just like +dnl the autoconf special exemption). +dnl +dnl @category C +dnl @author Martin Quinson +dnl @version 2009-12-11 +dnl @license AllPermissive + +AC_DEFUN([AC_FUNC_ASPRINTF], +[AC_CHECK_FUNCS(asprintf vasprintf) +AC_MSG_CHECKING(for working asprintf) +AC_CACHE_VAL(ac_cv_have_working_asprintf, +[AC_TRY_RUN( +[#include + +int main(void) +{ + char *buff; + int i = asprintf(&buff, "%s","toto"); + if (strcmp (buff, "toto")) exit (2); + if (i != 4) exit (3); + exit(0); +}], ac_cv_have_working_asprintf=yes, ac_cv_have_working_asprintf=no, ac_cv_have_working_asprintf=cross)]) +AC_MSG_RESULT([$ac_cv_have_working_asprintf]) +AC_MSG_CHECKING(for working vasprintf) +AC_CACHE_VAL(ac_cv_have_working_vasprintf, +[AC_TRY_RUN( +[#include +#include + +int my_vasprintf (char **buf, const char *tmpl, ...) +{ + int i; + va_list args; + va_start (args, tmpl); + i = vasprintf (buf, tmpl, args); + va_end (args); + return i; +} + +int main(void) +{ + char *buff; + int i = my_vasprintf(&buff, "%s","toto"); + if (strcmp (buff, "toto")) exit (2); + if (i != 4) exit (3); + exit(0); +}], ac_cv_have_working_vasprintf=yes, ac_cv_have_working_vasprintf=no, ac_cv_have_working_vasprintf=cross)]) +AC_MSG_RESULT([$ac_cv_have_working_vasprintf]) +if test x$ac_cv_have_working_asprintf$ac_cv_have_working_vasprintf != "xyesyes"; then +# AC_LIBOBJ(asprintf) + AC_MSG_WARN([Replacing missing/broken (v)asprintf() with internal version.]) + AC_DEFINE(NEED_ASPRINTF, 1, enable the asprintf replacement) + AC_DEFINE(NEED_VASPRINTF, 1, enable the vasprintf replacement) +AC_DEFINE(PREFER_PORTABLE_ASPRINTF, 1, "enable replacement (v)asprintf if system (v)asprintf is broken") +fi]) + \ No newline at end of file diff --git a/configure.ac b/configure.ac index bdce7aad86..fccc942d2c 100644 --- a/configure.ac +++ b/configure.ac @@ -71,9 +71,11 @@ AC_CHECK_FUNCS([gettimeofday usleep \ # check for a working snprintf (or use xbt/snprintf.c, which comes from http://www.ijs.si/software/snprintf/) AC_FUNC_SNPRINTF +# check for a working asprintf (or activate our replacement) +AC_FUNC_ASPRINTF # check for asprintf function familly (or request the replacements from xbt/snprintf.c) -AC_CHECK_FUNC( asprintf, :, AC_DEFINE(NEED_ASPRINTF, 1, enable the asprintf replacement)) -AC_CHECK_FUNC( vasprintf, :, AC_DEFINE(NEED_VASPRINTF, 1, enable the vasprintf replacement)) +dnl A C_CHECK_FUNC( asprintf, :, AC_DEFINE(NEED_ASPRINTF, 1, enable the asprintf replacement)) +dnl A C_CHECK_FUNC( vasprintf, :, AC_DEFINE(NEED_VASPRINTF, 1, enable the vasprintf replacement)) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST