From: Gabriel Corona Date: Tue, 9 Jun 2015 14:26:15 +0000 (+0200) Subject: Use _strdup is strdup is not available X-Git-Tag: v3_12~633^2~3 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4ef5edef3b76faa2a25e2d9a4940389b28385969 Use _strdup is strdup is not available Thank you, Windows. --- diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index e3d4bd8fb7..73108175fb 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -177,6 +177,8 @@ CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF) CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT) CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP) CHECK_FUNCTION_EXISTS(process_vm_readv HAVE_PROCESS_VM_READV) +CHECK_FUNCTION_EXISTS(strdup SIMGRID_HAVE_STRDUP) +CHECK_FUNCTION_EXISTS(_strdup SIMGRID_HAVE__STRDUP) #Check if __thread is defined execute_process( diff --git a/include/simgrid_config.h.in b/include/simgrid_config.h.in index 49f6a3a98f..1f853ca4df 100644 --- a/include/simgrid_config.h.in +++ b/include/simgrid_config.h.in @@ -136,5 +136,8 @@ 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 fae839c089..26897c40c8 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -74,7 +74,16 @@ char *xbt_strdup(const char *s) { char *res = NULL; if (s) { +# if defined(SIMGRID_HAVE_STRDUP) 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 if (!res) xbt_die("memory allocation error (strdup returned NULL)"); } @@ -134,7 +143,13 @@ void *xbt_realloc(void *p, size_t s) return res; } #else /* non __GNUC__ */ -# define xbt_strdup(s) strdup(s) +# if defined(SIMGRID_HAVE_STRDUP) +# define xbt_strdup(s) strdup(s) +# elif defined(SIMGRID_HAVE__STRDUP +# define xbt_strdup(s) _strdup(s) +# else +# error Missing strdup +# endif # define xbt_malloc(n) malloc(n) # define xbt_malloc0(n) calloc(n,1) # define xbt_realloc(p,s) realloc(p,s)