Added PHYSFS_mountIo().
authorRyan C. Gordon <icculus@icculus.org>
Sun, 29 Aug 2010 20:56:35 -0400
changeset 1119 028559924db4
parent 1118 2e09fc635fdd
child 1120 67e5e23425a0
Added PHYSFS_mountIo().
src/physfs.c
src/physfs.h
--- a/src/physfs.c	Mon Aug 30 03:01:57 2010 -0400
+++ b/src/physfs.c	Sun Aug 29 20:56:35 2010 -0400
@@ -1095,27 +1095,30 @@
 } /* PHYSFS_setWriteDir */
 
 
-int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
+static int doMount(PHYSFS_Io *io, const char *fname,
+                   const char *mountPoint, int appendToPath)
 {
     DirHandle *dh;
     DirHandle *prev = NULL;
     DirHandle *i;
 
-    BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0);
-
     if (mountPoint == NULL)
         mountPoint = "/";
 
     __PHYSFS_platformGrabMutex(stateLock);
 
-    for (i = searchPath; i != NULL; i = i->next)
+    if (fname != NULL)
     {
-        /* already in search path? */
-        BAIL_IF_MACRO_MUTEX(strcmp(newDir, i->dirName)==0, NULL, stateLock, 1);
-        prev = i;
-    } /* for */
-
-    dh = createDirHandle(NULL, newDir, mountPoint, 0);
+        for (i = searchPath; i != NULL; i = i->next)
+        {
+            /* already in search path? */
+            if ((i->dirName != NULL) && (strcmp(fname, i->dirName) == 0))
+                BAIL_MACRO_MUTEX(NULL, stateLock, 1);
+            prev = i;
+        } /* for */
+    } /* if */
+
+    dh = createDirHandle(io, fname, mountPoint, 0);
     BAIL_IF_MACRO_MUTEX(dh == NULL, NULL, stateLock, 0);
 
     if (appendToPath)
@@ -1133,6 +1136,21 @@
 
     __PHYSFS_platformReleaseMutex(stateLock);
     return 1;
+} /* doMount */
+
+
+int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname,
+                   const char *mountPoint, int appendToPath)
+{
+    BAIL_IF_MACRO(io == NULL, ERR_INVALID_ARGUMENT, 0);
+    return doMount(io, fname, mountPoint, appendToPath);
+} /* PHYSFS_mountIo */
+
+
+int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
+{
+    BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0);
+    return doMount(NULL, newDir, mountPoint, appendToPath);
 } /* PHYSFS_mount */
 
 
--- a/src/physfs.h	Mon Aug 30 03:01:57 2010 -0400
+++ b/src/physfs.h	Sun Aug 29 20:56:35 2010 -0400
@@ -2896,6 +2896,47 @@
     void *opaque;
 } PHYSFS_Io;
 
+
+/**
+ * \fn int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname, const char *mountPoint, int appendToPath)
+ * \brief Add an archive, built on a PHYSFS_Io, to the search path.
+ *
+ * \warning Unless you have some special, low-level need, you should be using
+ *          PHYSFS_mount() instead of this.
+ *
+ * This function operates just like PHYSFS_mount(), but takes a PHYSFS_Io
+ *  instead of a pathname. Behind the scenes, PHYSFS_mount() calls this
+ *  function with a physical-filesystem-based PHYSFS_Io.
+ *
+ * (filename) is only used here to optimize archiver selection (if you name it
+ *  XXXXX.zip, we might try the ZIP archiver first, for example). It doesn't
+ *  need to refer to a real file at all, and can even be NULL. If the filename
+ *  isn't helpful, the system will try every archiver until one works or none
+ *  of them do.
+ *
+ * (io) must remain until the archive is unmounted. When the archive is
+ *  unmounted, the system will call (io)->destroy(io), which will give you
+ *  a chance to free your resources.
+ *
+ * If this function fails, (io)->destroy(io) is not called.
+ *
+ *   \param io i/o instance for archive to add to the path.
+ *   \param fname Filename that can represent this stream. Can be NULL.
+ *   \param mountPoint Location in the interpolated tree that this archive
+ *                     will be "mounted", in platform-independent notation.
+ *                     NULL or "" is equivalent to "/".
+ *   \param appendToPath nonzero to append to search path, zero to prepend.
+ *  \return nonzero if added to path, zero on failure (bogus archive, stream
+ *                   i/o issue, etc). Specifics of the error can be
+ *                   gleaned from PHYSFS_getLastError().
+ *
+ * \sa PHYSFS_unmount
+ * \sa PHYSFS_getSearchPath
+ * \sa PHYSFS_getMountPoint
+ */
+PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname,
+                               const char *mountPoint, int appendToPath);
+
 /* Everything above this line is part of the PhysicsFS 2.1 API. */