summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils/mkdir.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp
index 223abe71..43f5264e 100644
--- a/src/utils/mkdir.cpp
+++ b/src/utils/mkdir.cpp
@@ -24,10 +24,10 @@
#if defined WIN32
#include <windows.h>
-#else
-#include <sys/stat.h>
#endif
+#include <sys/stat.h>
+
#ifdef _MKDIR_TEST_
// compile with -D_MKDIR_TEST_ to get a standalone binary
#include <cstdio>
@@ -67,12 +67,24 @@ int mkdir_r(const char *pathname) {
*p = '/';
continue;
}
+
+ // check if the name already exists, but not as directory
+ struct stat statbuf;
+ if (!stat(tmp, &statbuf))
+ {
+ if (S_ISDIR(statbuf.st_mode))
+ {
+ *p = '/';
+ continue;
+ }
+ else
+ return -1;
+ }
+
#if defined WIN32
- if (!CreateDirectory(tmp, 0) &&
- GetLastError() != ERROR_ALREADY_EXISTS)
+ if (!CreateDirectory(tmp, 0))
#else
- if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) &&
- errno != EEXIST)
+ if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
#endif
{
#if defined WIN32