Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleaned out "exists" nonsense in openRead() API.
  • Loading branch information
icculus committed Nov 30, 2012
1 parent 697c31e commit 36b542e
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/archiver_dir.c
Expand Up @@ -103,9 +103,8 @@ static PHYSFS_Io *doOpen(void *opaque, const char *name, const int mode)
} /* doOpen */


static PHYSFS_Io *DIR_openRead(void *opaque, const char *filename, int *exists)
static PHYSFS_Io *DIR_openRead(void *opaque, const char *filename)
{
// !!! FIXME: exists
return doOpen(opaque, filename, 'r');
} /* DIR_openRead */

Expand Down
3 changes: 1 addition & 2 deletions src/archiver_iso9660.c
Expand Up @@ -764,8 +764,7 @@ static int iso_file_open_foreign(ISO9660Handle *handle,
} /* iso_file_open_foreign */


static PHYSFS_Io *ISO9660_openRead(void *opaque, const char *filename,
int *exists)
static PHYSFS_Io *ISO9660_openRead(void *opaque, const char *filename)
{
PHYSFS_Io *retval = NULL;
ISO9660Handle *handle = (ISO9660Handle*) opaque;
Expand Down
4 changes: 1 addition & 3 deletions src/archiver_lzma.c
Expand Up @@ -575,14 +575,12 @@ static void LZMA_enumerateFiles(void *opaque, const char *dname,
} /* LZMA_enumerateFiles */


static PHYSFS_Io *LZMA_openRead(void *opaque, const char *name,
int *fileExists)
static PHYSFS_Io *LZMA_openRead(void *opaque, const char *name)
{
LZMAarchive *archive = (LZMAarchive *) opaque;
LZMAfile *file = lzma_find_file(archive, name);
PHYSFS_Io *io = NULL;

*fileExists = (file != NULL);
BAIL_IF_MACRO(file == NULL, PHYSFS_ERR_NOT_FOUND, NULL);
BAIL_IF_MACRO(file->folder == NULL, PHYSFS_ERR_NOT_A_FILE, NULL);

Expand Down
5 changes: 2 additions & 3 deletions src/archiver_unpacked.c
Expand Up @@ -344,15 +344,14 @@ static UNPKentry *findEntry(const UNPKinfo *info, const char *path, int *isDir)
} /* findEntry */


PHYSFS_Io *UNPK_openRead(void *opaque, const char *fnm, int *fileExists)
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name)
{
PHYSFS_Io *retval = NULL;
UNPKinfo *info = (UNPKinfo *) opaque;
UNPKfileinfo *finfo = NULL;
int isdir = 0;
UNPKentry *entry = findEntry(info, fnm, &isdir);
UNPKentry *entry = findEntry(info, name, &isdir);

*fileExists = (entry != NULL);
GOTO_IF_MACRO(isdir, PHYSFS_ERR_NOT_A_FILE, UNPK_openRead_failed);
GOTO_IF_MACRO(!entry, ERRPASS, UNPK_openRead_failed);

Expand Down
6 changes: 2 additions & 4 deletions src/archiver_zip.c
Expand Up @@ -1557,15 +1557,13 @@ static PHYSFS_Io *zip_get_io(PHYSFS_Io *io, ZIPinfo *inf, ZIPentry *entry)
} /* zip_get_io */


static PHYSFS_Io *ZIP_openRead(void *opaque, const char *fnm,
int *fileExists)
static PHYSFS_Io *ZIP_openRead(void *opaque, const char *filename)
{
PHYSFS_Io *retval = NULL;
ZIPinfo *info = (ZIPinfo *) opaque;
ZIPentry *entry = zip_find_entry(info, fnm, NULL);
ZIPentry *entry = zip_find_entry(info, filename, NULL);
ZIPfileinfo *finfo = NULL;

*fileExists = (entry != NULL);
BAIL_IF_MACRO(!entry, ERRPASS, NULL);

retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Expand Down
5 changes: 2 additions & 3 deletions src/physfs.c
Expand Up @@ -2452,20 +2452,19 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname)

if (sanitizePlatformIndependentPath(_fname, fname))
{
int fileExists = 0;
DirHandle *i = NULL;
PHYSFS_Io *io = NULL;

__PHYSFS_platformGrabMutex(stateLock);

GOTO_IF_MACRO(!searchPath, PHYSFS_ERR_NOT_FOUND, openReadEnd);

for (i = searchPath; (i != NULL) && (!fileExists); i = i->next)
for (i = searchPath; i != NULL; i = i->next)
{
char *arcfname = fname;
if (verifyPath(i, &arcfname, 0))
{
io = i->funcs->openRead(i->opaque, arcfname, &fileExists);
io = i->funcs->openRead(i->opaque, arcfname);
if (io)
break;
} /* if */
Expand Down
7 changes: 1 addition & 6 deletions src/physfs.h
Expand Up @@ -3426,13 +3426,8 @@ typedef struct PHYSFS_Archiver
* Returns NULL on failure, and calls PHYSFS_setErrorCode().
* Returns non-NULL on success. The pointer returned will be
* passed as the "opaque" parameter for later file calls.
*
* Regardless of success or failure, please set *exists to
* non-zero if the file existed (even if it's a broken symlink!),
* zero if it did not.
*/
// !!! FIXME: get rid of the exists nonsense, check error code instead.
PHYSFS_Io *(*openRead)(void *opaque, const char *fnm, int *exists);
PHYSFS_Io *(*openRead)(void *opaque, const char *fnm);

/**
* Open file for writing.
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_internal.h
Expand Up @@ -293,7 +293,7 @@ void *UNPK_openArchive(PHYSFS_Io *io,UNPKentry *e,const PHYSFS_uint32 n);
void UNPK_enumerateFiles(void *opaque, const char *dname,
PHYSFS_EnumFilesCallback cb,
const char *origdir, void *callbackdata);
PHYSFS_Io *UNPK_openRead(void *opaque, const char *fnm, int *fileExists);
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name);
PHYSFS_Io *UNPK_openWrite(void *opaque, const char *name);
PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name);
int UNPK_remove(void *opaque, const char *name);
Expand Down

0 comments on commit 36b542e

Please sign in to comment.