From: divverent Date: Sun, 22 Mar 2009 11:54:48 +0000 (+0000) Subject: Q_mkdir: create parent directories first X-Git-Tag: svn-r421~195 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b222e12c366d5c513aa8d76a52ceb1bab17b382b;p=xonotic%2Fnetradiant.git Q_mkdir: create parent directories first git-svn-id: svn://svn.icculus.org/netradiant/trunk@225 61c419a2-8eb2-4b30-bcec-8cead039b335 --- diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index cb3e9d0c..4eb9592c 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -352,13 +352,41 @@ void Q_getwd (char *out) void Q_mkdir (const char *path) { + char parentbuf[256]; + const char *p = NULL; + int retry = 2; + while(retry--) + { #ifdef WIN32 - if (_mkdir (path) != -1) - return; + const char *q = NULL; + if (_mkdir (path) != -1) + return; + if(errno == ENOENT) + { + p = strrchr(path, '/'); + q = strrchr(path, '\\'); + if(q && (!p || q < p)) + p = q; + } #else - if (mkdir (path, 0777) != -1) - return; + if (mkdir (path, 0777) != -1) + return; + if(errno == ENOENT) + p = strrchr(path, '/'); #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) Error ("mkdir %s: %s",path, strerror(errno)); }