From c1969d0595c20c5b91e12c8af21b7efdf32c72d3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 22 Aug 2010 03:43:22 -0400 Subject: [PATCH] Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSearchPath. --- extras/physfs-swig.i | 1 + src/physfs.c | 16 ++++++++---- src/physfs.h | 60 +++++++++++++++++++++++++++++++++++--------- test/test_physfs.c | 5 ++-- 4 files changed, 63 insertions(+), 19 deletions(-) diff --git a/extras/physfs-swig.i b/extras/physfs-swig.i index 354c6a59..f6b57638 100644 --- a/extras/physfs-swig.i +++ b/extras/physfs-swig.i @@ -88,6 +88,7 @@ %rename(stat) PHYSFS_stat; %rename(readBytes) PHYSFS_readBytes; %rename(writeBytes) PHYSFS_writeBytes; +%rename(unmount) PHYSFS_unmount; #endif %include "../src/physfs.h" diff --git a/src/physfs.c b/src/physfs.c index 1ea8bbe3..a9176b40 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -1003,6 +1003,12 @@ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) int PHYSFS_removeFromSearchPath(const char *oldDir) +{ + return PHYSFS_unmount(oldDir); +} /* PHYSFS_removeFromSearchPath */ + + +int PHYSFS_unmount(const char *oldDir) { DirHandle *i; DirHandle *prev = NULL; @@ -1030,7 +1036,7 @@ int PHYSFS_removeFromSearchPath(const char *oldDir) } /* for */ BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0); -} /* PHYSFS_removeFromSearchPath */ +} /* PHYSFS_unmount */ char **PHYSFS_getSearchPath(void) @@ -1081,7 +1087,7 @@ static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep, if (str != NULL) { sprintf(str, "%s%s%s", d, dirsep, i); - PHYSFS_addToSearchPath(str, archivesFirst == 0); + PHYSFS_mount(str, NULL, archivesFirst == 0); __PHYSFS_smallFree(str); } /* if */ } /* setSaneCfgAddPath */ @@ -1133,11 +1139,11 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName, } /* if */ /* Put write dir first in search path... */ - PHYSFS_addToSearchPath(str, 0); + PHYSFS_mount(str, NULL, 0); __PHYSFS_smallFree(str); /* Put base path on search path... */ - PHYSFS_addToSearchPath(basedir, 1); + PHYSFS_mount(basedir, NULL, 1); /* handle CD-ROMs... */ if (includeCdRoms) @@ -1145,7 +1151,7 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName, char **cds = PHYSFS_getCdRomDirs(); char **i; for (i = cds; *i != NULL; i++) - PHYSFS_addToSearchPath(*i, 1); + PHYSFS_mount(*i, NULL, 1); PHYSFS_freeList(cds); } /* if */ diff --git a/src/physfs.h b/src/physfs.h index d4b28ce7..28d25b3a 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -800,8 +800,14 @@ PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir); * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) * \brief Add an archive or directory to the search path. * - * This is a legacy call in PhysicsFS 2.0, equivalent to: - * PHYSFS_mount(newDir, NULL, appendToPath); + * \deprecated As of PhysicsFS 2.0, use PHYSFS_mount() instead. This + * function just wraps it anyhow. + * + * This function is equivalent to: + * + * \code + * PHYSFS_mount(newDir, NULL, appendToPath); + * \endcode * * You must use this and not PHYSFS_mount if binary compatibility with * PhysicsFS 1.0 is important (which it may not be for many people). @@ -810,27 +816,35 @@ PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir); * \sa PHYSFS_removeFromSearchPath * \sa PHYSFS_getSearchPath */ -PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath); - +PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) + PHYSFS_DEPRECATED; /** * \fn int PHYSFS_removeFromSearchPath(const char *oldDir) * \brief Remove a directory or archive from the search path. * - * This must be a (case-sensitive) match to a dir or archive already in the - * search path, specified in platform-dependent notation. + * \deprecated As of PhysicsFS 2.1, use PHYSFS_unmount() instead. This + * function just wraps it anyhow. There's no functional difference + * except the vocabulary changed from "adding to the search path" + * to "mounting" when that functionality was extended, and thus + * the preferred way to accomplish this function's work is now + * called "unmounting." * - * This call will fail (and fail to remove from the path) if the element still - * has files open in it. + * This function is equivalent to: * - * \param oldDir dir/archive to remove. - * \return nonzero on success, zero on failure. - * Specifics of the error can be gleaned from PHYSFS_getLastError(). + * \code + * PHYSFS_unmount(oldDir); + * \endcode + * + * You must use this and not PHYSFS_unmount if binary compatibility with + * PhysicsFS 1.0 is important (which it may not be for many people). * * \sa PHYSFS_addToSearchPath * \sa PHYSFS_getSearchPath + * \sa PHYSFS_unmount */ -PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir); +PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir) + PHYSFS_DEPRECATED; /** @@ -2475,6 +2489,28 @@ PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst, /* Everything above this line is part of the PhysicsFS 2.0 API. */ +/** + * \fn int PHYSFS_unmount(const char *oldDir) + * \brief Remove a directory or archive from the search path. + * + * This is functionally equivalent to PHYSFS_removeFromSearchPath(), but that + * function is deprecated to keep the vocabulary paired with PHYSFS_mount(). + * + * This must be a (case-sensitive) match to a dir or archive already in the + * search path, specified in platform-dependent notation. + * + * This call will fail (and fail to remove from the path) if the element still + * has files open in it. + * + * \param oldDir dir/archive to remove. + * \return nonzero on success, zero on failure. + * Specifics of the error can be gleaned from PHYSFS_getLastError(). + * + * \sa PHYSFS_getSearchPath + * \sa PHYSFS_mount + */ +PHYSFS_DECL int PHYSFS_unmount(const char *oldDir); + /** * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void) * \brief Discover the current allocator. diff --git a/test/test_physfs.c b/test/test_physfs.c index 39e8a6d0..e744d40b 100644 --- a/test/test_physfs.c +++ b/test/test_physfs.c @@ -119,7 +119,7 @@ static int cmd_addarchive(char *args) /*printf("[%s], [%d]\n", args, appending);*/ - if (PHYSFS_addToSearchPath(args, appending)) + if (PHYSFS_mount(args, NULL, appending)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); @@ -189,7 +189,7 @@ static int cmd_removearchive(char *args) args[strlen(args) - 1] = '\0'; } /* if */ - if (PHYSFS_removeFromSearchPath(args)) + if (PHYSFS_unmount(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); @@ -1024,6 +1024,7 @@ static const command_info commands[] = { "addarchive", cmd_addarchive, 2, " " }, { "mount", cmd_mount, 3, " " }, { "removearchive", cmd_removearchive, 1, "" }, + { "unmount", cmd_removearchive, 1, "" }, { "enumerate", cmd_enumerate, 1, "" }, { "ls", cmd_enumerate, 1, "" }, { "getlasterror", cmd_getlasterror, 0, NULL },