Skip to content

Commit

Permalink
Removed PHYSFS_Archiver's isArchive() method.
Browse files Browse the repository at this point in the history
It was redundant with openArchive().
  • Loading branch information
icculus committed Aug 24, 2010
1 parent c92f303 commit fc680aa
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 122 deletions.
12 changes: 1 addition & 11 deletions src/archiver_dir.c
Expand Up @@ -63,23 +63,14 @@ static int DIR_fileClose(fvoid *opaque)
} /* DIR_fileClose */


static int DIR_isArchive(const char *filename, int forWriting)
{
/* directories ARE archives in this driver... */
return __PHYSFS_platformIsDirectory(filename);
} /* DIR_isArchive */


static void *DIR_openArchive(const char *name, int forWriting)
{
const char *dirsep = PHYSFS_getDirSeparator();
char *retval = NULL;
size_t namelen = strlen(name);
size_t seplen = strlen(dirsep);

/* !!! FIXME: when is this not called right before openArchive? */
BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
ERR_UNSUPPORTED_ARCHIVE, 0);
BAIL_IF_MACRO(!__PHYSFS_platformIsDirectory(name), ERR_NOT_AN_ARCHIVE, NULL);

retval = allocator.Malloc(namelen + seplen + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
Expand Down Expand Up @@ -246,7 +237,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
{
&__PHYSFS_ArchiveInfo_DIR,
DIR_isArchive, /* isArchive() method */
DIR_openArchive, /* openArchive() method */
DIR_enumerateFiles, /* enumerateFiles() method */
DIR_exists, /* exists() method */
Expand Down
14 changes: 0 additions & 14 deletions src/archiver_grp.c
Expand Up @@ -179,19 +179,6 @@ static int grp_open(const char *filename, int forWriting,
} /* grp_open */


static int GRP_isArchive(const char *filename, int forWriting)
{
void *fh;
PHYSFS_uint32 fileCount;
int retval = grp_open(filename, forWriting, &fh, &fileCount);

if (fh != NULL)
__PHYSFS_platformClose(fh);

return retval;
} /* GRP_isArchive */


static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
{
if (one != two)
Expand Down Expand Up @@ -451,7 +438,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
{
&__PHYSFS_ArchiveInfo_GRP,
GRP_isArchive, /* isArchive() method */
GRP_openArchive, /* openArchive() method */
GRP_enumerateFiles, /* enumerateFiles() method */
GRP_exists, /* exists() method */
Expand Down
16 changes: 1 addition & 15 deletions src/archiver_hog.c
Expand Up @@ -216,19 +216,6 @@ static int hog_open(const char *filename, int forWriting,
} /* hog_open */


static int HOG_isArchive(const char *filename, int forWriting)
{
void *fh;
PHYSFS_uint32 fileCount;
int retval = hog_open(filename, forWriting, &fh, &fileCount);

if (fh != NULL)
__PHYSFS_platformClose(fh);

return retval;
} /* HOG_isArchive */


static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
{
if (one != two)
Expand Down Expand Up @@ -304,7 +291,7 @@ static void *HOG_openArchive(const char *name, int forWriting)
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));

BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
memset(info, '\0', sizeof (HOGinfo));
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
Expand Down Expand Up @@ -486,7 +473,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG =
const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
{
&__PHYSFS_ArchiveInfo_HOG,
HOG_isArchive, /* isArchive() method */
HOG_openArchive, /* openArchive() method */
HOG_enumerateFiles, /* enumerateFiles() method */
HOG_exists, /* exists() method */
Expand Down
12 changes: 6 additions & 6 deletions src/archiver_iso9660.c
Expand Up @@ -483,13 +483,12 @@ static int iso_read_ext_attributes(ISO9660Handle *handle, int block,
* Archive management functions
******************************************************************************/

static int ISO9660_isArchive(const char *filename, int forWriting)
/* !!! FIXME: don't open/close file here, merge with openArchive(). */
static int isIso(const char *filename)
{
char magicnumber[6] = {0,0,0,0,0,0};
void *in;

BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);

in = __PHYSFS_platformOpenRead(filename);
BAIL_IF_MACRO(in == NULL, NULL, 0);

Expand All @@ -510,15 +509,17 @@ static int ISO9660_isArchive(const char *filename, int forWriting)
__PHYSFS_platformClose(in);

return (strcmp(magicnumber, "CD001") == 0);
} /* ISO9660_isArchive */
} /* isIso */


static void *ISO9660_openArchive(const char *filename, int forWriting)
{
ISO9660Handle *handle;
int founddescriptor = 0;
int foundjoliet = 0;
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);

BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
BAIL_IF_MACRO(!isIso(filename), ERR_UNSUPPORTED_ARCHIVE, NULL);

handle = allocator.Malloc(sizeof(ISO9660Handle));
GOTO_IF_MACRO(!handle, ERR_OUT_OF_MEMORY, errorcleanup);
Expand Down Expand Up @@ -985,7 +986,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ISO9660 =
const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660 =
{
&__PHYSFS_ArchiveInfo_ISO9660,
ISO9660_isArchive, /* isArchive() method */
ISO9660_openArchive, /* openArchive() method */
ISO9660_enumerateFiles, /* enumerateFiles() method */
ISO9660_exists, /* exists() method */
Expand Down
10 changes: 4 additions & 6 deletions src/archiver_lzma.c
Expand Up @@ -430,13 +430,12 @@ static int LZMA_fileClose(fvoid *opaque)
} /* LZMA_fileClose */


static int LZMA_isArchive(const char *filename, int forWriting)
/* !!! FIXME: don't open/close file here, merge with openArchive(). */
static int isLzma(const char *filename)
{
PHYSFS_uint8 sig[k7zSignatureSize];
void *in;

BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);

in = __PHYSFS_platformOpenRead(filename);
BAIL_IF_MACRO(in == NULL, NULL, 0);

Expand All @@ -451,7 +450,7 @@ static int LZMA_isArchive(const char *filename, int forWriting)

/* Test whether sig is the 7z signature */
return TestSignatureCandidate(sig);
} /* LZMA_isArchive */
} /* isLzma */


static void *LZMA_openArchive(const char *name, int forWriting)
Expand All @@ -460,7 +459,7 @@ static void *LZMA_openArchive(const char *name, int forWriting)
LZMAarchive *archive = NULL;

BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
BAIL_IF_MACRO(!LZMA_isArchive(name,forWriting), ERR_UNSUPPORTED_ARCHIVE, 0);
BAIL_IF_MACRO(!isLzma(name), ERR_UNSUPPORTED_ARCHIVE, NULL);

archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL);
Expand Down Expand Up @@ -721,7 +720,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA =
const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
{
&__PHYSFS_ArchiveInfo_LZMA,
LZMA_isArchive, /* isArchive() method */
LZMA_openArchive, /* openArchive() method */
LZMA_enumerateFiles, /* enumerateFiles() method */
LZMA_exists, /* exists() method */
Expand Down
14 changes: 0 additions & 14 deletions src/archiver_mvl.c
Expand Up @@ -176,19 +176,6 @@ static int mvl_open(const char *filename, int forWriting,
} /* mvl_open */


static int MVL_isArchive(const char *filename, int forWriting)
{
void *fh;
PHYSFS_uint32 fileCount;
int retval = mvl_open(filename, forWriting, &fh, &fileCount);

if (fh != NULL)
__PHYSFS_platformClose(fh);

return retval;
} /* MVL_isArchive */


static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
{
if (one != two)
Expand Down Expand Up @@ -446,7 +433,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL =
const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
{
&__PHYSFS_ArchiveInfo_MVL,
MVL_isArchive, /* isArchive() method */
MVL_openArchive, /* openArchive() method */
MVL_enumerateFiles, /* enumerateFiles() method */
MVL_exists, /* exists() method */
Expand Down
14 changes: 0 additions & 14 deletions src/archiver_qpak.c
Expand Up @@ -204,19 +204,6 @@ static int qpak_open(const char *filename, int forWriting,
} /* qpak_open */


static int QPAK_isArchive(const char *filename, int forWriting)
{
void *fh;
PHYSFS_uint32 fileCount;
int retval = qpak_open(filename, forWriting, &fh, &fileCount);

if (fh != NULL)
__PHYSFS_platformClose(fh);

return retval;
} /* QPAK_isArchive */


static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
{
if (one != two)
Expand Down Expand Up @@ -607,7 +594,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
{
&__PHYSFS_ArchiveInfo_QPAK,
QPAK_isArchive, /* isArchive() method */
QPAK_openArchive, /* openArchive() method */
QPAK_enumerateFiles, /* enumerateFiles() method */
QPAK_exists, /* exists() method */
Expand Down
14 changes: 0 additions & 14 deletions src/archiver_wad.c
Expand Up @@ -203,19 +203,6 @@ static int wad_open(const char *filename, int forWriting,
} /* wad_open */


static int WAD_isArchive(const char *filename, int forWriting)
{
void *fh;
PHYSFS_uint32 fileCount,offset;
int retval = wad_open(filename, forWriting, &fh, &fileCount,&offset);

if (fh != NULL)
__PHYSFS_platformClose(fh);

return retval;
} /* WAD_isArchive */


static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
{
if (one != two)
Expand Down Expand Up @@ -505,7 +492,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD =
const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
{
&__PHYSFS_ArchiveInfo_WAD,
WAD_isArchive, /* isArchive() method */
WAD_openArchive, /* openArchive() method */
WAD_enumerateFiles, /* enumerateFiles() method */
WAD_exists, /* exists() method */
Expand Down
7 changes: 4 additions & 3 deletions src/archiver_zip.c
Expand Up @@ -450,7 +450,8 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(void *in, PHYSFS_sint64 *len)
} /* zip_find_end_of_central_dir */


static int ZIP_isArchive(const char *filename, int forWriting)
/* !!! FIXME: don't open/close file here, merge with openArchive(). */
static int isZip(const char *filename)
{
PHYSFS_uint32 sig;
int retval = 0;
Expand Down Expand Up @@ -479,7 +480,7 @@ static int ZIP_isArchive(const char *filename, int forWriting)

__PHYSFS_platformClose(in);
return retval;
} /* ZIP_isArchive */
} /* isZip */


static void zip_free_entries(ZIPentry *entries, PHYSFS_uint32 max)
Expand Down Expand Up @@ -1084,6 +1085,7 @@ static void *ZIP_openArchive(const char *name, int forWriting)
PHYSFS_uint32 cent_dir_ofs;

BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
BAIL_IF_MACRO(!isZip(name), NULL, NULL);

if ((in = __PHYSFS_platformOpenRead(name)) == NULL)
goto zip_openarchive_failed;
Expand Down Expand Up @@ -1432,7 +1434,6 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP =
const PHYSFS_Archiver __PHYSFS_Archiver_ZIP =
{
&__PHYSFS_ArchiveInfo_ZIP,
ZIP_isArchive, /* isArchive() method */
ZIP_openArchive, /* openArchive() method */
ZIP_enumerateFiles, /* enumerateFiles() method */
ZIP_exists, /* exists() method */
Expand Down
31 changes: 16 additions & 15 deletions src/physfs.c
Expand Up @@ -103,7 +103,6 @@ static const PHYSFS_ArchiveInfo *supported_types[] =

static const PHYSFS_Archiver *archivers[] =
{
&__PHYSFS_Archiver_DIR,
#if (defined PHYSFS_SUPPORTS_ZIP)
&__PHYSFS_Archiver_ZIP,
#endif
Expand Down Expand Up @@ -401,22 +400,19 @@ static DirHandle *tryOpenDir(const PHYSFS_Archiver *funcs,
const char *d, int forWriting)
{
DirHandle *retval = NULL;
if (funcs->isArchive(d, forWriting))
void *opaque = funcs->openArchive(d, forWriting);
if (opaque != NULL)
{
void *opaque = funcs->openArchive(d, forWriting);
if (opaque != NULL)
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
if (retval == NULL)
funcs->dirClose(opaque);
else
{
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
if (retval == NULL)
funcs->dirClose(opaque);
else
{
memset(retval, '\0', sizeof (DirHandle));
retval->mountPoint = NULL;
retval->funcs = funcs;
retval->opaque = opaque;
} /* else */
} /* if */
memset(retval, '\0', sizeof (DirHandle));
retval->mountPoint = NULL;
retval->funcs = funcs;
retval->opaque = opaque;
} /* else */
} /* if */

return retval;
Expand All @@ -431,6 +427,11 @@ static DirHandle *openDirectory(const char *d, int forWriting)

BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);

/* DIR gets first shot (unlike the rest, it doesn't deal with files). */
retval = tryOpenDir(&__PHYSFS_Archiver_DIR, d, forWriting);
if (retval != NULL)
return retval;

ext = find_filename_extension(d);
if (ext != NULL)
{
Expand Down
10 changes: 0 additions & 10 deletions src/physfs_internal.h
Expand Up @@ -740,16 +740,6 @@ typedef struct
* continue to call other methods based on that.
*/


/*
* Returns non-zero if (filename) is a valid archive that this
* driver can handle. This filename is in platform-dependent
* notation. forWriting is non-zero if this is to be used for
* the write directory, and zero if this is to be used for an
* element of the search path.
*/
int (*isArchive)(const char *filename, int forWriting);

/*
* Open a dirhandle for dir/archive (name).
* This filename is in platform-dependent notation.
Expand Down

0 comments on commit fc680aa

Please sign in to comment.