From 66b73d0944f57b9ffe3cf47ebf16f51f969f793f Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 9 Jun 2015 19:02:12 +0200 Subject: [PATCH] Fix strdup/_strdup detection strdup() is not standard C/C++. On Windows, noth _strdup() and _strdup() are available in C. However, strdup() is not available in C++ (ar at least in standard C++ mode?). The result is that cmake dtects that strdup() is available but the C++ compiler fails to compile code using it. We just use _strdup() on Windows. --- include/simgrid_config.h.in | 3 --- include/xbt/sysdep.h | 17 +++++------------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/include/simgrid_config.h.in b/include/simgrid_config.h.in index 1f853ca4df..49f6a3a98f 100644 --- a/include/simgrid_config.h.in +++ b/include/simgrid_config.h.in @@ -136,8 +136,5 @@ XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2); /* If Model-Checking support was requested */ #cmakedefine HAVE_MC @HAVE_MC@ -#cmakedefine SIMGRID_HAVE_STRDUP @SIMGRID_HAVE_STRDUP@ -#cmakedefine SIMGRID_HAVE__STRDUP @SIMGRID_HAVE__STRDUP@ - SG_END_DECL() #endif /* SIMGRID_PUBLIC_CONFIG_H */ diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 26897c40c8..f464edd0a9 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -74,16 +74,11 @@ char *xbt_strdup(const char *s) { char *res = NULL; if (s) { -# if defined(SIMGRID_HAVE_STRDUP) +# if !defined(_XBT_WIN32) res = strdup(s); -# elif defined(SIMGRID_HAVE__STRDUP) - res = _strdup(s); # else - size_t len = strlen(s); - res = malloc(len + 1); - if (res) - memcpy(res, s, len + 1); -# endif + res = _strdup(s); +# endif if (!res) xbt_die("memory allocation error (strdup returned NULL)"); } @@ -143,12 +138,10 @@ void *xbt_realloc(void *p, size_t s) return res; } #else /* non __GNUC__ */ -# if defined(SIMGRID_HAVE_STRDUP) +# if !defined(_XBT_WIN32) # define xbt_strdup(s) strdup(s) -# elif defined(SIMGRID_HAVE__STRDUP -# define xbt_strdup(s) _strdup(s) # else -# error Missing strdup +# define xbt_strdup(s) _strdup(s) # endif # define xbt_malloc(n) malloc(n) # define xbt_malloc0(n) calloc(n,1) -- 2.20.1