Q_mkdir: create parent directories first
git-svn-id: svn://svn.icculus.org/netradiant/trunk@225 61c419a2-8eb2-4b30-bcec-8cead039b335
This commit is contained in:
parent
4a5b039ba1
commit
b222e12c36
|
|
@ -351,14 +351,42 @@ void Q_getwd (char *out)
|
||||||
|
|
||||||
|
|
||||||
void Q_mkdir (const char *path)
|
void Q_mkdir (const char *path)
|
||||||
|
{
|
||||||
|
char parentbuf[256];
|
||||||
|
const char *p = NULL;
|
||||||
|
int retry = 2;
|
||||||
|
while(retry--)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
const char *q = NULL;
|
||||||
if (_mkdir (path) != -1)
|
if (_mkdir (path) != -1)
|
||||||
return;
|
return;
|
||||||
|
if(errno == ENOENT)
|
||||||
|
{
|
||||||
|
p = strrchr(path, '/');
|
||||||
|
q = strrchr(path, '\\');
|
||||||
|
if(q && (!p || q < p))
|
||||||
|
p = q;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (mkdir (path, 0777) != -1)
|
if (mkdir (path, 0777) != -1)
|
||||||
return;
|
return;
|
||||||
|
if(errno == ENOENT)
|
||||||
|
p = strrchr(path, '/');
|
||||||
#endif
|
#endif
|
||||||
|
if(p)
|
||||||
|
{
|
||||||
|
strncpy(parentbuf, path, sizeof(parentbuf));
|
||||||
|
if((int) (p - path) < (int) sizeof(parentbuf))
|
||||||
|
{
|
||||||
|
parentbuf[p - path] = 0;
|
||||||
|
Sys_Printf ("mkdir: %s: creating parent %s first\n", path, parentbuf);
|
||||||
|
Q_mkdir(parentbuf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (errno != EEXIST)
|
if (errno != EEXIST)
|
||||||
Error ("mkdir %s: %s",path, strerror(errno));
|
Error ("mkdir %s: %s",path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user