Browse Source

Add dirname on msvc, thanks Jerome Robert

Samuel Thibault 10 years ago
parent
commit
7fc0d70afb
1 changed files with 18 additions and 1 deletions
  1. 18 1
      src/common/utils.c

+ 18 - 1
src/common/utils.c

@@ -18,7 +18,6 @@
 #include <starpu.h>
 #include <common/config.h>
 #include <common/utils.h>
-#include <libgen.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -29,6 +28,24 @@
 #define mkdir(path, mode) mkdir(path)
 #endif
 
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+#include <direct.h>
+static char * dirname(char * path)
+{
+   char drive[_MAX_DRIVE];
+   char dir[_MAX_DIR];
+   /* Remove trailing slash */
+   while (strlen(path) > 0 && (*(path+strlen(path)-1) == '/' || *(path+strlen(p
+th)-1) == '\\'))
+      *(path+strlen(path)-1) = '\0';
+   _splitpath(path, drive, dir, NULL, NULL);
+   _makepath(path, drive, dir, NULL, NULL);
+   return path;
+}
+#else
+#include <libgen.h>
+#endif
+
 /* Function with behaviour like `mkdir -p'. This function was adapted from
  * http://niallohiggins.com/2009/01/08/mkpath-mkdir-p-alike-in-c-for-unix/ */