Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
returns successful for duplicates, but doesn't add them a second time.
This commit is contained in:
parent
2b66e50d49
commit
c83a82497c
45
physfs.c
45
physfs.c
|
@ -522,22 +522,26 @@ int PHYSFS_setWriteDir(const char *newDir)
|
||||||
|
|
||||||
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
|
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
|
||||||
{
|
{
|
||||||
DirInfo *di = buildDirInfo(newDir, 0);
|
DirInfo *di;
|
||||||
|
DirInfo *i = searchPath;
|
||||||
|
DirInfo *prev = NULL;
|
||||||
|
|
||||||
|
while (i != NULL)
|
||||||
|
{
|
||||||
|
if (strcmp(newDir, i->dirName) == 0) /* already in search path. */
|
||||||
|
return(1);
|
||||||
|
|
||||||
|
prev = i;
|
||||||
|
i = i->next;
|
||||||
|
} /* while */
|
||||||
|
|
||||||
|
di = buildDirInfo(newDir, 0);
|
||||||
|
|
||||||
BAIL_IF_MACRO(di == NULL, NULL, 0);
|
BAIL_IF_MACRO(di == NULL, NULL, 0);
|
||||||
|
|
||||||
if (appendToPath)
|
if (appendToPath)
|
||||||
{
|
{
|
||||||
DirInfo *i = searchPath;
|
|
||||||
DirInfo *prev = NULL;
|
|
||||||
|
|
||||||
di->next = NULL;
|
di->next = NULL;
|
||||||
while (i != NULL)
|
|
||||||
{
|
|
||||||
prev = i;
|
|
||||||
i = i->next;
|
|
||||||
} /* while */
|
|
||||||
|
|
||||||
if (prev == NULL)
|
if (prev == NULL)
|
||||||
searchPath = di;
|
searchPath = di;
|
||||||
else
|
else
|
||||||
|
@ -1147,7 +1151,6 @@ PHYSFS_file *PHYSFS_openAppend(const char *filename)
|
||||||
|
|
||||||
PHYSFS_file *PHYSFS_openRead(const char *fname)
|
PHYSFS_file *PHYSFS_openRead(const char *fname)
|
||||||
{
|
{
|
||||||
PHYSFS_file *retval = NULL;
|
|
||||||
FileHandle *rc = NULL;
|
FileHandle *rc = NULL;
|
||||||
FileHandleList *list;
|
FileHandleList *list;
|
||||||
DirInfo *i;
|
DirInfo *i;
|
||||||
|
@ -1155,9 +1158,6 @@ PHYSFS_file *PHYSFS_openRead(const char *fname)
|
||||||
while (*fname == '/')
|
while (*fname == '/')
|
||||||
fname++;
|
fname++;
|
||||||
|
|
||||||
list = (FileHandleList *) malloc(sizeof (FileHandleList));
|
|
||||||
BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
|
|
||||||
|
|
||||||
for (i = searchPath; i != NULL; i = i->next)
|
for (i = searchPath; i != NULL; i = i->next)
|
||||||
{
|
{
|
||||||
DirHandle *h = i->dirHandle;
|
DirHandle *h = i->dirHandle;
|
||||||
|
@ -1170,16 +1170,15 @@ PHYSFS_file *PHYSFS_openRead(const char *fname)
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
if (rc == NULL)
|
if (rc == NULL)
|
||||||
free(list);
|
return(NULL);
|
||||||
else
|
|
||||||
{
|
|
||||||
list->handle.opaque = (void *) rc;
|
|
||||||
list->next = openReadList;
|
|
||||||
openReadList = list;
|
|
||||||
retval = &(list->handle);
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
return(retval);
|
list = (FileHandleList *) malloc(sizeof (FileHandleList));
|
||||||
|
BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
list->handle.opaque = (void *) rc;
|
||||||
|
list->next = openReadList;
|
||||||
|
openReadList = list;
|
||||||
|
|
||||||
|
return(&(list->handle));
|
||||||
} /* PHYSFS_openRead */
|
} /* PHYSFS_openRead */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue