Make PHYSFS_exists() work with mounts from PHYSFS_mountIo(io, NULL, ...)
authorRyan C. Gordon <icculus@icculus.org>
Mon, 14 Aug 2017 03:06:42 -0400
changeset 1574 87100b3836cd
parent 1573 6eec1a358f3d
child 1575 be0a87101943
Make PHYSFS_exists() work with mounts from PHYSFS_mountIo(io, NULL, ...)

(Actually, from any mount function that accepts a bogus/NULL filename.)
src/physfs.c
--- a/src/physfs.c	Mon Aug 14 02:46:07 2017 -0400
+++ b/src/physfs.c	Mon Aug 14 03:06:42 2017 -0400
@@ -2170,9 +2170,9 @@
 } /* PHYSFS_delete */
 
 
-const char *PHYSFS_getRealDir(const char *_fname)
+static DirHandle *getRealDirHandle(const char *_fname)
 {
-    const char *retval = NULL;
+    DirHandle *retval = NULL;
     char *fname = NULL;
     size_t len;
 
@@ -2189,7 +2189,7 @@
             char *arcfname = fname;
             if (partOfMountPoint(i, arcfname))
             {
-                retval = i->dirName;
+                retval = i;
                 break;
             } /* if */
             else if (verifyPath(i, &arcfname, 0))
@@ -2197,7 +2197,7 @@
                 PHYSFS_Stat statbuf;
                 if (i->funcs->stat(i->opaque, arcfname, &statbuf))
                 {
-                    retval = i->dirName;
+                    retval = i;
                     break;
                 } /* if */
             } /* if */
@@ -2207,6 +2207,12 @@
 
     __PHYSFS_smallFree(fname);
     return retval;
+} /* getRealDirHandle */
+
+const char *PHYSFS_getRealDir(const char *fname)
+{
+    DirHandle *dh = getRealDirHandle(fname);
+    return dh ? dh->dirName : NULL;
 } /* PHYSFS_getRealDir */
 
 
@@ -2482,7 +2488,7 @@
 
 int PHYSFS_exists(const char *fname)
 {
-    return (PHYSFS_getRealDir(fname) != NULL);
+    return (getRealDirHandle(fname) != NULL);
 } /* PHYSFS_exists */