]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/cmdlib.c
fix some more warnings
[xonotic/netradiant.git] / tools / quake3 / common / cmdlib.c
index cb3e9d0c8c4236d8a039c713b26560c66ec2ed66..5168d233f38846dc7014351cc8200f83ab496af1 100644 (file)
@@ -193,7 +193,7 @@ void SetQdirFromPath( const char *path )
       }
                        strncpy (qdir, path, c+len+count-path);
                        Sys_Printf ("qdir: %s\n", qdir);
-                       for ( i = 0; i < strlen( qdir ); i++ )
+                       for ( i = 0; i < (int) strlen( qdir ); i++ )
                        {
                                if ( qdir[i] == '\\' ) 
                                        qdir[i] = '/';
@@ -206,7 +206,7 @@ void SetQdirFromPath( const char *path )
                                {
                                        strncpy (gamedir, path, c+1-path);
 
-                                       for ( i = 0; i < strlen( gamedir ); i++ )
+                                       for ( i = 0; i < (int) strlen( gamedir ); i++ )
                                        {
                                                if ( gamedir[i] == '\\' ) 
                                                        gamedir[i] = '/';
@@ -250,9 +250,7 @@ char *ExpandArg (const char *path)
 char *ExpandPath (const char *path)
 {
        static char full[1024];
-       if (!qdir)
-               Error ("ExpandPath called without qdir set");
-       if (path[0] == '/' || path[0] == '\\' || path[1] == ':') {
+       if (!*qdir || path[0] == '/' || path[0] == '\\' || path[1] == ':') {
                strcpy( full, path );
                return full;
        }
@@ -263,8 +261,8 @@ char *ExpandPath (const char *path)
 char *ExpandGamePath (const char *path)
 {
        static char full[1024];
-       if (!qdir)
-               Error ("ExpandGamePath called without qdir set");
+       if (!*gamedir)
+               Error ("ExpandGamePath called without gamedir set");
        if (path[0] == '/' || path[0] == '\\' || path[1] == ':') {
                strcpy( full, path );
                return full;
@@ -338,7 +336,7 @@ void Q_getwd (char *out)
    strcat (out, "\\");
 #else
    // Gef: Changed from getwd() to getcwd() to avoid potential buffer overflow
-   getcwd (out, 256);
+   if(!getcwd (out, 256)) *out = 0;
    strcat (out, "/");
 #endif
    while ( out[i] != 0 )
@@ -352,13 +350,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));
 }