Skip to content

Commit

Permalink
Added PHYSFS_mountIo().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 30, 2010
1 parent 4bc5ed1 commit 8cd320b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/physfs.c
Expand Up @@ -1095,27 +1095,30 @@ int PHYSFS_setWriteDir(const char *newDir)
} /* 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 */
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(NULL, newDir, mountPoint, 0);
dh = createDirHandle(io, fname, mountPoint, 0);
BAIL_IF_MACRO_MUTEX(dh == NULL, NULL, stateLock, 0);

if (appendToPath)
Expand All @@ -1133,6 +1136,21 @@ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)

__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 */


Expand Down
41 changes: 41 additions & 0 deletions src/physfs.h
Expand Up @@ -2896,6 +2896,47 @@ typedef struct PHYSFS_Io
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. */


Expand Down

0 comments on commit 8cd320b

Please sign in to comment.