Merge 3ba2b7d192
into fdd38a3f8a
This commit is contained in:
commit
d4484dda88
40
src/physfs.c
40
src/physfs.c
|
@ -48,6 +48,7 @@ typedef struct __PHYSFS_DIRHANDLE__
|
||||||
size_t rootlen; /* subdirectory of archiver to use as root of archive (NULL for actual root) */
|
size_t rootlen; /* subdirectory of archiver to use as root of archive (NULL for actual root) */
|
||||||
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
|
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
|
||||||
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */
|
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */
|
||||||
|
int priority;
|
||||||
} DirHandle;
|
} DirHandle;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1796,7 +1797,7 @@ int PHYSFS_setRoot(const char *archive, const char *subdir)
|
||||||
|
|
||||||
|
|
||||||
static int doMount(PHYSFS_Io *io, const char *fname,
|
static int doMount(PHYSFS_Io *io, const char *fname,
|
||||||
const char *mountPoint, int appendToPath)
|
const char *mountPoint, int priority)
|
||||||
{
|
{
|
||||||
DirHandle *dh;
|
DirHandle *dh;
|
||||||
DirHandle *prev = NULL;
|
DirHandle *prev = NULL;
|
||||||
|
@ -1814,23 +1815,24 @@ static int doMount(PHYSFS_Io *io, const char *fname,
|
||||||
/* already in search path? */
|
/* already in search path? */
|
||||||
if ((i->dirName != NULL) && (strcmp(fname, i->dirName) == 0))
|
if ((i->dirName != NULL) && (strcmp(fname, i->dirName) == 0))
|
||||||
BAIL_MUTEX_ERRPASS(stateLock, 1);
|
BAIL_MUTEX_ERRPASS(stateLock, 1);
|
||||||
prev = i;
|
if ((priority < 0) || ((priority > 0) && (i->priority <= priority)))
|
||||||
|
prev = i;
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
dh = createDirHandle(io, fname, mountPoint, 0);
|
dh = createDirHandle(io, fname, mountPoint, 0);
|
||||||
BAIL_IF_MUTEX_ERRPASS(!dh, stateLock, 0);
|
BAIL_IF_MUTEX_ERRPASS(!dh, stateLock, 0);
|
||||||
|
|
||||||
if (appendToPath)
|
dh->priority = priority;
|
||||||
{
|
|
||||||
if (prev == NULL)
|
if (prev == NULL)
|
||||||
searchPath = dh;
|
|
||||||
else
|
|
||||||
prev->next = dh;
|
|
||||||
} /* if */
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
dh->next = searchPath;
|
dh->next = searchPath;
|
||||||
searchPath = dh;
|
searchPath = dh;
|
||||||
|
} /* if */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dh->next = prev->next;
|
||||||
|
prev->next = dh;
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
|
@ -1839,18 +1841,18 @@ static int doMount(PHYSFS_Io *io, const char *fname,
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname,
|
int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname,
|
||||||
const char *mountPoint, int appendToPath)
|
const char *mountPoint, int priority)
|
||||||
{
|
{
|
||||||
BAIL_IF(!io, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!io, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
BAIL_IF(!fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!fname, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
BAIL_IF(io->version != 0, PHYSFS_ERR_UNSUPPORTED, 0);
|
BAIL_IF(io->version != 0, PHYSFS_ERR_UNSUPPORTED, 0);
|
||||||
return doMount(io, fname, mountPoint, appendToPath);
|
return doMount(io, fname, mountPoint, priority);
|
||||||
} /* PHYSFS_mountIo */
|
} /* PHYSFS_mountIo */
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *),
|
int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *),
|
||||||
const char *fname, const char *mountPoint,
|
const char *fname, const char *mountPoint,
|
||||||
int appendToPath)
|
int priority)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
PHYSFS_Io *io = NULL;
|
PHYSFS_Io *io = NULL;
|
||||||
|
@ -1860,7 +1862,7 @@ int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *),
|
||||||
|
|
||||||
io = __PHYSFS_createMemoryIo(buf, len, del);
|
io = __PHYSFS_createMemoryIo(buf, len, del);
|
||||||
BAIL_IF_ERRPASS(!io, 0);
|
BAIL_IF_ERRPASS(!io, 0);
|
||||||
retval = doMount(io, fname, mountPoint, appendToPath);
|
retval = doMount(io, fname, mountPoint, priority);
|
||||||
if (!retval)
|
if (!retval)
|
||||||
{
|
{
|
||||||
/* docs say not to call (del) in case of failure, so cheat. */
|
/* docs say not to call (del) in case of failure, so cheat. */
|
||||||
|
@ -1874,7 +1876,7 @@ int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *),
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname,
|
int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname,
|
||||||
const char *mountPoint, int appendToPath)
|
const char *mountPoint, int priority)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
PHYSFS_Io *io = NULL;
|
PHYSFS_Io *io = NULL;
|
||||||
|
@ -1884,7 +1886,7 @@ int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname,
|
||||||
|
|
||||||
io = __PHYSFS_createHandleIo(file);
|
io = __PHYSFS_createHandleIo(file);
|
||||||
BAIL_IF_ERRPASS(!io, 0);
|
BAIL_IF_ERRPASS(!io, 0);
|
||||||
retval = doMount(io, fname, mountPoint, appendToPath);
|
retval = doMount(io, fname, mountPoint, priority);
|
||||||
if (!retval)
|
if (!retval)
|
||||||
{
|
{
|
||||||
/* docs say not to destruct in case of failure, so cheat. */
|
/* docs say not to destruct in case of failure, so cheat. */
|
||||||
|
@ -1896,16 +1898,16 @@ int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname,
|
||||||
} /* PHYSFS_mountHandle */
|
} /* PHYSFS_mountHandle */
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
|
int PHYSFS_mount(const char *newDir, const char *mountPoint, int priority)
|
||||||
{
|
{
|
||||||
BAIL_IF(!newDir, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
BAIL_IF(!newDir, PHYSFS_ERR_INVALID_ARGUMENT, 0);
|
||||||
return doMount(NULL, newDir, mountPoint, appendToPath);
|
return doMount(NULL, newDir, mountPoint, priority);
|
||||||
} /* PHYSFS_mount */
|
} /* PHYSFS_mount */
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
|
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
|
||||||
{
|
{
|
||||||
return PHYSFS_mount(newDir, NULL, appendToPath);
|
return PHYSFS_mount(newDir, NULL, appendToPath ? -1 : 0);
|
||||||
} /* PHYSFS_addToSearchPath */
|
} /* PHYSFS_addToSearchPath */
|
||||||
|
|
||||||
|
|
||||||
|
|
25
src/physfs.h
25
src/physfs.h
|
@ -2186,7 +2186,7 @@ PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
|
* \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int priority)
|
||||||
* \brief Add an archive or directory to the search path.
|
* \brief Add an archive or directory to the search path.
|
||||||
*
|
*
|
||||||
* If this is a duplicate, the entry is not added again, even though the
|
* If this is a duplicate, the entry is not added again, even though the
|
||||||
|
@ -2220,7 +2220,8 @@ PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
|
||||||
* \param mountPoint Location in the interpolated tree that this archive
|
* \param mountPoint Location in the interpolated tree that this archive
|
||||||
* will be "mounted", in platform-independent notation.
|
* will be "mounted", in platform-independent notation.
|
||||||
* NULL or "" is equivalent to "/".
|
* NULL or "" is equivalent to "/".
|
||||||
* \param appendToPath nonzero to append to search path, zero to prepend.
|
* \param priority Archive priority. Positive inserts archive AFTER others
|
||||||
|
* with the same priority; negative appends, zero prepends.
|
||||||
* \return nonzero if added to path, zero on failure (bogus archive, dir
|
* \return nonzero if added to path, zero on failure (bogus archive, dir
|
||||||
* missing, etc). Use PHYSFS_getLastErrorCode() to obtain
|
* missing, etc). Use PHYSFS_getLastErrorCode() to obtain
|
||||||
* the specific error.
|
* the specific error.
|
||||||
|
@ -2232,7 +2233,7 @@ PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
|
||||||
*/
|
*/
|
||||||
PHYSFS_DECL int PHYSFS_mount(const char *newDir,
|
PHYSFS_DECL int PHYSFS_mount(const char *newDir,
|
||||||
const char *mountPoint,
|
const char *mountPoint,
|
||||||
int appendToPath);
|
int priority);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int PHYSFS_getMountPoint(const char *dir)
|
* \fn int PHYSFS_getMountPoint(const char *dir)
|
||||||
|
@ -3228,7 +3229,7 @@ typedef struct PHYSFS_Io
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir, const char *mountPoint, int appendToPath)
|
* \fn int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir, const char *mountPoint, int priority)
|
||||||
* \brief Add an archive, built on a PHYSFS_Io, to the search path.
|
* \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
|
* \warning Unless you have some special, low-level need, you should be using
|
||||||
|
@ -3258,7 +3259,7 @@ typedef struct PHYSFS_Io
|
||||||
* \param mountPoint Location in the interpolated tree that this archive
|
* \param mountPoint Location in the interpolated tree that this archive
|
||||||
* will be "mounted", in platform-independent notation.
|
* will be "mounted", in platform-independent notation.
|
||||||
* NULL or "" is equivalent to "/".
|
* NULL or "" is equivalent to "/".
|
||||||
* \param appendToPath nonzero to append to search path, zero to prepend.
|
* \param priority Archive priority; see PHYSFS_mount.
|
||||||
* \return nonzero if added to path, zero on failure (bogus archive, stream
|
* \return nonzero if added to path, zero on failure (bogus archive, stream
|
||||||
* i/o issue, etc). Use PHYSFS_getLastErrorCode() to obtain
|
* i/o issue, etc). Use PHYSFS_getLastErrorCode() to obtain
|
||||||
* the specific error.
|
* the specific error.
|
||||||
|
@ -3268,11 +3269,11 @@ typedef struct PHYSFS_Io
|
||||||
* \sa PHYSFS_getMountPoint
|
* \sa PHYSFS_getMountPoint
|
||||||
*/
|
*/
|
||||||
PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir,
|
PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir,
|
||||||
const char *mountPoint, int appendToPath);
|
const char *mountPoint, int priority);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *), const char *newDir, const char *mountPoint, int appendToPath)
|
* \fn int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *), const char *newDir, const char *mountPoint, int priority)
|
||||||
* \brief Add an archive, contained in a memory buffer, to the search path.
|
* \brief Add an archive, contained in a memory buffer, to the search path.
|
||||||
*
|
*
|
||||||
* \warning Unless you have some special, low-level need, you should be using
|
* \warning Unless you have some special, low-level need, you should be using
|
||||||
|
@ -3306,7 +3307,7 @@ PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir,
|
||||||
* \param mountPoint Location in the interpolated tree that this archive
|
* \param mountPoint Location in the interpolated tree that this archive
|
||||||
* will be "mounted", in platform-independent notation.
|
* will be "mounted", in platform-independent notation.
|
||||||
* NULL or "" is equivalent to "/".
|
* NULL or "" is equivalent to "/".
|
||||||
* \param appendToPath nonzero to append to search path, zero to prepend.
|
* \param priority Archive priority; see PHYSFS_mount.
|
||||||
* \return nonzero if added to path, zero on failure (bogus archive, etc).
|
* \return nonzero if added to path, zero on failure (bogus archive, etc).
|
||||||
* Use PHYSFS_getLastErrorCode() to obtain the specific error.
|
* Use PHYSFS_getLastErrorCode() to obtain the specific error.
|
||||||
*
|
*
|
||||||
|
@ -3316,11 +3317,11 @@ PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir,
|
||||||
*/
|
*/
|
||||||
PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len,
|
PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len,
|
||||||
void (*del)(void *), const char *newDir,
|
void (*del)(void *), const char *newDir,
|
||||||
const char *mountPoint, int appendToPath);
|
const char *mountPoint, int priority);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir, const char *mountPoint, int appendToPath)
|
* \fn int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir, const char *mountPoint, int priority)
|
||||||
* \brief Add an archive, contained in a PHYSFS_File handle, to the search path.
|
* \brief Add an archive, contained in a PHYSFS_File handle, to the search path.
|
||||||
*
|
*
|
||||||
* \warning Unless you have some special, low-level need, you should be using
|
* \warning Unless you have some special, low-level need, you should be using
|
||||||
|
@ -3364,7 +3365,7 @@ PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len,
|
||||||
* \param mountPoint Location in the interpolated tree that this archive
|
* \param mountPoint Location in the interpolated tree that this archive
|
||||||
* will be "mounted", in platform-independent notation.
|
* will be "mounted", in platform-independent notation.
|
||||||
* NULL or "" is equivalent to "/".
|
* NULL or "" is equivalent to "/".
|
||||||
* \param appendToPath nonzero to append to search path, zero to prepend.
|
* \param priority Archive priority; see PHYSFS_mount.
|
||||||
* \return nonzero if added to path, zero on failure (bogus archive, etc).
|
* \return nonzero if added to path, zero on failure (bogus archive, etc).
|
||||||
* Use PHYSFS_getLastErrorCode() to obtain the specific error.
|
* Use PHYSFS_getLastErrorCode() to obtain the specific error.
|
||||||
*
|
*
|
||||||
|
@ -3373,7 +3374,7 @@ PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len,
|
||||||
* \sa PHYSFS_getMountPoint
|
* \sa PHYSFS_getMountPoint
|
||||||
*/
|
*/
|
||||||
PHYSFS_DECL int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir,
|
PHYSFS_DECL int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir,
|
||||||
const char *mountPoint, int appendToPath);
|
const char *mountPoint, int priority);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue