From: divverent Date: Wed, 31 Aug 2011 05:42:35 +0000 (+0000) Subject: on Unix, avoid actually creating config.cfg when testing gamedirs X-Git-Tag: xonotic-v0.6.0~163^2~237 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=770f8f858d35fed1abd6d8e138645ee9c37776cf;p=xonotic%2Fdarkplaces.git on Unix, avoid actually creating config.cfg when testing gamedirs 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 --- diff --git a/fs.c b/fs.c index d810ff54..4288ab5d 100644 --- 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 + } } /*