From cf83e2bdb40c0520e0e641e22d13c92a9d0135fd Mon Sep 17 00:00:00 2001 From: mquinson Date: Fri, 11 Dec 2009 10:38:52 +0000 Subject: [PATCH] Install a configure-generated header file containing whether the system have getline and asprintf git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6880 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- acmacro/ac_func_asprintf.m4 | 65 ------------------------------------- configure.ac | 37 +++++++++++++++++---- include/Makefile.am | 3 +- include/xbt/str.h | 26 --------------- src/xbt/xbt_str.c | 5 +-- 5 files changed, 33 insertions(+), 103 deletions(-) delete mode 100644 acmacro/ac_func_asprintf.m4 diff --git a/acmacro/ac_func_asprintf.m4 b/acmacro/ac_func_asprintf.m4 deleted file mode 100644 index 2599ef9fa7..0000000000 --- a/acmacro/ac_func_asprintf.m4 +++ /dev/null @@ -1,65 +0,0 @@ -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 fccc942d2c..96f482d3a2 100644 --- a/configure.ac +++ b/configure.ac @@ -66,16 +66,38 @@ AC_CHECK_FUNCS([gettimeofday usleep \ sysconf\ readv\ popen\ - signal\ - getline]) - + signal]) + +dnl GNU systems before POSIX2008 need the _GNU_SOURCE definition to find getline (and simgrid does pass this) +AC_MSG_CHECKING(a usable getline) +AC_COMPILE_IFELSE([ + #define _GNU_SOURCE + #include + int main(void){ + FILE * fp; + char * line = NULL; + size_t len = 0; + getline(&line, &len, fp); + } + ],[ + AC_MSG_RESULT(found) + ],[ + AC_SUBST(need_getline, ["#define SIMGRID_NEED_GETLINE 1 /* enable the getline replacement*/"]) + AC_DEFINE(SIMGRID_NEED_GETLINE, 1, enable the getline replacement) + AC_MSG_RESULT(not found (activating internal implementation)) + ]) + # 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) -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)) +AC_CHECK_FUNC( asprintf, :,[ + AC_DEFINE(NEED_ASPRINTF, 1, enable the asprintf replacement) + AC_SUBST(need_asprintf, ["#define SIMGRID_NEED_ASPRINTF 1 /* enable the asprintf replacement */"]) + ]) +AC_CHECK_FUNC( vasprintf, :,[ + AC_DEFINE(NEED_VASPRINTF, 1, enable the vasprintf replacement) + AC_SUBST(need_vasprintf, ["#define SIMGRID_NEED_VASPRINTF 1 /*enable the vasprintf replacement */"]) + ]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -490,6 +512,7 @@ SG_CONFIGURE_PART(Generating files...) AC_CONFIG_FILES([ Makefile include/Makefile + include/simgrid_config.h src/Makefile src/context_sysv_config.h ]) diff --git a/include/Makefile.am b/include/Makefile.am index 692ab60ecb..acc1b95445 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -4,8 +4,9 @@ # You can redistribute and/or modify it under the terms of the # GNU LGPL (v2.1) licence. +EXTRA_DIST=simgrid_config.h.in -include_HEADERS = gras.h xbt.h +include_HEADERS = gras.h xbt.h simgrid_config.h nobase_include_HEADERS = \ xbt/misc.h \ xbt/sysdep.h \ diff --git a/include/xbt/str.h b/include/xbt/str.h index e866e52551..bf324d4983 100644 --- a/include/xbt/str.h +++ b/include/xbt/str.h @@ -27,33 +27,7 @@ SG_BEGIN_DECL() * asprintf()), while some other are a bit more exotic. * @{ */ -/* snprintf related functions */ -/** @brief print to allocated string (reimplemented when not provided by the system) - * - * The functions asprintf() and vasprintf() are analogues of - * sprintf() and vsprintf(), except that they allocate a string large - * enough to hold the output including the terminating null byte, and - * return a pointer to it via the first parameter. This pointer - * should be passed to free(3) to release the allocated storage when - * it is no longer needed. - */ -XBT_PUBLIC(int) asprintf(char **ptr, const char *fmt, /*args */ - ...) _XBT_GNUC_PRINTF(2, 3); -/** @brief print to allocated string (reimplemented when not provided by the system) - * - * See asprintf() - */ -XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap); -/** @brief print to allocated string - * - * Works just like asprintf(), but returns a pointer to the newly created string - */ -XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2); -/* the gettext function. It gets redefined here only if not yet available */ -#if !defined(__USE_GNU) || defined(DOXYGEN) -//XBT_PUBLIC(long) getline(char **lineptr, size_t * n, FILE * stream); -#endif /* Trim related functions */ XBT_PUBLIC(void) xbt_str_rtrim(char *s, const char *char_list); diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 231ca6e7d9..9646fbcfa4 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -508,10 +508,7 @@ char *xbt_str_join(xbt_dynar_t dyn, const char *sep) return res; } -#if !defined(HAVE_GETLINE) || defined(DOXYGEN) -/* prototype here, just in case */ -long getline(char **buf, size_t * n, FILE * stream); - +#if defined(SIMGRID_NEED_GETLINE) || defined(DOXYGEN) /** @brief Get a single line from the stream (reimplementation of the GNU getline) * * This is a redefinition of the GNU getline function, used on platforms where it does not exists. -- 2.20.1