Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use _strdup is strdup is not available
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 14:26:15 +0000 (16:26 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 14:26:15 +0000 (16:26 +0200)
Thank you, Windows.

buildtools/Cmake/CompleteInFiles.cmake
include/simgrid_config.h.in
include/xbt/sysdep.h

index e3d4bd8..7310817 100644 (file)
@@ -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(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(
 
 #Check if __thread is defined
 execute_process(
index 49f6a3a..1f853ca 100644 (file)
@@ -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@
 
 /* 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 */
 SG_END_DECL()
 #endif /* SIMGRID_PUBLIC_CONFIG_H */
index fae839c..26897c4 100644 (file)
@@ -74,7 +74,16 @@ char *xbt_strdup(const char *s)
 {
   char *res = NULL;
   if (s) {
 {
   char *res = NULL;
   if (s) {
+# if defined(SIMGRID_HAVE_STRDUP)
     res = strdup(s);
     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)");
   }
     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__  */
   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)
 #  define xbt_malloc(n)    malloc(n)
 #  define xbt_malloc0(n)   calloc(n,1)
 #  define xbt_realloc(p,s) realloc(p,s)