]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
on Unix, avoid actually creating config.cfg when testing gamedirs
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 31 Aug 2011 05:42:35 +0000 (05:42 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 31 Aug 2011 05:42:35 +0000 (05:42 +0000)
We can use access() with W_OK | X_OK on the directory instead there

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11315 d7cf8633-e32d-0410-b094-e92efae38249

fs.c

diff --git a/fs.c b/fs.c
index d810ff541f1b6e497dc6489150dd1f38415d4c57..4288ab5dd1c20378928cd2edd9c80b6942b68a63 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1881,19 +1881,34 @@ int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t userdirsiz
        if (userdirmode == USERDIRMODE_NOHOME && strcmp(gamedirname1, "id1"))
                return 0; // don't bother checking if the basedir folder is writable, it's annoying...  unless it is Quake on Windows where NOHOME is the default preferred and we have to check for an error case
 #endif
+
        // see if we can write to this path (note: won't create path)
-#if _MSC_VER >= 1400
+#ifdef WIN32
+# if _MSC_VER >= 1400
        _sopen_s(&fd, va("%s%s/config.cfg", userdir, gamedirname1), O_WRONLY | O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE); // note: no O_TRUNC here!
-#else
+# else
        fd = open (va("%s%s/config.cfg", userdir, gamedirname1), O_WRONLY | O_CREAT, 0666); // note: no O_TRUNC here!
+# endif
+       if(fd >= 0)
+               close(fd);
+#else
+       // on Unix, we don't need to ACTUALLY attempt to open the file
+       if(access(va("%s%s/", userdir, gamedirname1), W_OK | X_OK) >= 0)
+               fd = 1;
+       else
+               fd = 0;
 #endif
        if(fd >= 0)
        {
-               close(fd);
                return 1; // good choice - the path exists and is writable
        }
        else
-               return 0; // probably good - failed to write but maybe we need to create path
+       {
+               if (userdirmode == USERDIRMODE_NOHOME)
+                       return -1; // path usually already exists, we lack permissions
+               else
+                       return 0; // probably good - failed to write but maybe we need to create path
+       }
 }
 
 /*