Make CreateDirectory create directories recursively

stable-5.2
Günther Brammer 2009-06-06 17:20:17 +02:00
parent 4d047ed20f
commit 18167243b2
2 changed files with 18 additions and 5 deletions

View File

@ -679,7 +679,7 @@ void C4ConfigGeneral::DeterminePaths(BOOL forceWorkingDirectory)
#ifdef C4ENGINE
// Create user path if it doesn't already exist
if (!DirectoryExists(UserDataPath))
CreateDirectory(UserDataPath, NULL); // currently no error handling here; also: no recursive directory creation
CreateDirectory(UserDataPath, NULL);
#endif
}

View File

@ -562,10 +562,23 @@ bool SetWorkingDirectory(const char *path)
#ifndef _WIN32
// CreateDirectory: true on success
bool CreateDirectory(const char * pathname, void*) {
// mkdir: false on success
return !mkdir(pathname,S_IREAD | S_IWRITE | S_IEXEC);
}
bool CreateDirectory(const char * pathname, void*)
{
int r = mkdir(pathname,S_IREAD | S_IWRITE | S_IEXEC);
if (r && errno == ENOENT)
{
StdCopyStrBuf parent(pathname);
char * slash = strrchr(parent.getMData(), '/');
if (slash)
{
*slash = 0;
CreateDirectory(parent.getData());
return !mkdir(pathname,S_IREAD | S_IWRITE | S_IEXEC);
}
}
// mkdir: 0 on success
return !r;
}
#endif
bool DirectoryExists(const char *szFilename)