]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Q_mkdir: create parent directories first
authordivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Sun, 22 Mar 2009 11:54:48 +0000 (11:54 +0000)
committerdivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Sun, 22 Mar 2009 11:54:48 +0000 (11:54 +0000)
git-svn-id: svn://svn.icculus.org/netradiant/trunk@225 61c419a2-8eb2-4b30-bcec-8cead039b335

tools/quake3/common/cmdlib.c

index cb3e9d0c8c4236d8a039c713b26560c66ec2ed66..4eb9592c8bcc8aa5dad81fd3dd34ec341e4693e9 100644 (file)
@@ -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));
 }