diff options
Diffstat (limited to 'devtools/create_project/create_project.cpp')
-rw-r--r-- | devtools/create_project/create_project.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index ad3160d778..026cbe07a4 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -59,6 +59,7 @@ #include <sys/param.h> #include <sys/stat.h> #include <dirent.h> +#include <errno.h> #endif namespace { @@ -1121,6 +1122,32 @@ FileList listDirectory(const std::string &dir) { return result; } +void createDirectory(const std::string &dir) { +#if defined(_WIN32) || defined(WIN32) + if (!CreateDirectory(dir.c_str(), NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) { + error("Could not create folder \"" + dir + "\""); + } + } +#else + if (mkdir(dir.c_str(), 0777) == -1) { + if (errno == EEXIST) { + // Try to open as a folder (might be a file / symbolic link) + DIR *dirp = opendir(dir.c_str()); + if (dirp == NULL) { + error("Could not create folder \"" + dir + "\""); + } else { + // The folder exists, just close the stream and return + closedir(dirp); + } + } else { + error("Could not create folder \"" + dir + "\""); + } + } +#endif + +} + /** * Scans the specified directory against files, which should be included * in the project files. It will not include files present in the exclude list. |