From a7f59172b83910f9e2dc17c116f70530f46cf6a1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 27 Nov 2011 19:03:11 +0300 Subject: Fix recursive directory creation for windows. --- src/utils/mkdir.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp index 84c205b33..dc2ab63ef 100644 --- a/src/utils/mkdir.cpp +++ b/src/utils/mkdir.cpp @@ -43,6 +43,7 @@ int mkdir_r(const char *pathname) { char tmp[PATH_MAX]; + char tmp2[PATH_MAX]; char *p; if (strlen(pathname) >= PATH_MAX - 2) @@ -72,9 +73,13 @@ int mkdir_r(const char *pathname) continue; } + strcpy(tmp2, tmp); + char *p2 = tmp2 + strlen(tmp2) - 1; + if (*p2 == '/' || *p2 == '\\') + *p2 = 0; // check if the name already exists, but not as directory struct stat statbuf; - if (!stat(tmp, &statbuf)) + if (!stat(tmp2, &statbuf)) { if (S_ISDIR(statbuf.st_mode)) { @@ -85,13 +90,12 @@ int mkdir_r(const char *pathname) return -1; } - if (!CreateDirectory(tmp, 0)) + if (!CreateDirectory(tmp2, 0)) { // hack, hack. just assume that x: might be a drive // letter, and try again - if (!(strlen(tmp) == 2 && - !strcmp(tmp + 1, ":"))) - return -1; + if (!(strlen(tmp2) == 2 && !strcmp(tmp2 + 1, ":"))) + return -1; } #ifdef M_MKDIR_TEST_ -- cgit v1.2.3-60-g2f50