]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Make fgets always return the null string on error.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 28 Jan 2008 01:02:56 +0000 (01:02 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 28 Jan 2008 01:02:56 +0000 (01:02 +0000)
Add code to FS_Open to fix bad paths (replaces \ with /). The code is nasty and #ifdefed out - #define FS_FIX_PATHS to use it.

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

fs.c
prvm_cmds.c

diff --git a/fs.c b/fs.c
index 8fd5d619958b7f2f15a42cbb1040955e20c6b1c7..8571aed1c7cae7ee291eeff9a23913b6d8609a14 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1819,6 +1819,19 @@ Open a file. The syntax is the same as fopen
 */
 qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking)
 {
+#ifdef FS_FIX_PATHS
+       char fixedFileName[MAX_QPATH];
+       char *d = fixedFileName;
+       // try to fix common mistakes (\ instead of /)
+       for( ; *filepath ; filepath++, d++ )
+               if( *filepath != '\\' )
+                       *d = *filepath;
+               else
+                       *d = '/';
+       *d = '\0';
+       filepath = fixedFileName;
+#endif
+
        if (FS_CheckNastyPath(filepath, false))
        {
                Con_Printf("FS_Open(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
index bfa74e5cdf1c4ca27e1054e010cd28bff516c427..236ffc468ed67aab336232aa0b4e6e5092ef7dbb 100644 (file)
@@ -1596,6 +1596,9 @@ void VM_fgets(void)
 
        VM_SAFEPARMCOUNT(1,VM_fgets);
 
+       // set the return value regardless of any possible errors
+       PRVM_G_INT(OFS_RETURN) = OFS_NULL;
+
        filenum = (int)PRVM_G_FLOAT(OFS_PARM0);
        if (filenum < 0 || filenum >= PRVM_MAX_OPENFILES)
        {
@@ -1628,8 +1631,6 @@ void VM_fgets(void)
                Con_Printf("fgets: %s: %s\n", PRVM_NAME, string);
        if (c >= 0 || end)
                PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(string);
-       else
-               PRVM_G_INT(OFS_RETURN) = OFS_NULL;
 }
 
 /*