Skip to content
Permalink
Browse files
Removed isDirectory, isSymLink and exists methods from internal code.
Use the PhysFS stat() interface instead.
  • Loading branch information
icculus committed Sep 5, 2010
1 parent 2219123 commit 7f0e7105a74c4521c4ca2343b9005754d0274db5
@@ -18,13 +18,17 @@

static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
{
PHYSFS_Stat statbuf;
const char *dirsep = PHYSFS_getDirSeparator();
char *retval = NULL;
const size_t namelen = strlen(name);
const size_t seplen = strlen(dirsep);
int exists = 0;

assert(io == NULL); /* shouldn't create an Io for these. */
BAIL_IF_MACRO(!__PHYSFS_platformIsDirectory(name), ERR_NOT_AN_ARCHIVE, NULL);
BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &exists, &statbuf), NULL, NULL);
if ((!exists) || (statbuf.filetype != PHYSFS_FILETYPE_DIRECTORY))
BAIL_MACRO(ERR_NOT_AN_ARCHIVE, NULL);

retval = allocator.Malloc(namelen + seplen + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
@@ -55,46 +59,6 @@ static void DIR_enumerateFiles(dvoid *opaque, const char *dname,
} /* DIR_enumerateFiles */


static int DIR_exists(dvoid *opaque, const char *name)
{
char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval;

BAIL_IF_MACRO(f == NULL, NULL, 0);
retval = __PHYSFS_platformExists(f);
allocator.Free(f);
return retval;
} /* DIR_exists */


static int DIR_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
char *d = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval = 0;

BAIL_IF_MACRO(d == NULL, NULL, 0);
*fileExists = __PHYSFS_platformExists(d);
if (*fileExists)
retval = __PHYSFS_platformIsDirectory(d);
allocator.Free(d);
return retval;
} /* DIR_isDirectory */


static int DIR_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval = 0;

BAIL_IF_MACRO(f == NULL, NULL, 0);
*fileExists = __PHYSFS_platformExists(f);
if (*fileExists)
retval = __PHYSFS_platformIsSymLink(f);
allocator.Free(f);
return retval;
} /* DIR_isSymLink */


static PHYSFS_Io *doOpen(dvoid *opaque, const char *name,
const int mode, int *fileExists)
{
@@ -113,7 +77,8 @@ static PHYSFS_Io *doOpen(dvoid *opaque, const char *name,
allocator.Free(f);
if (io == NULL)
{
*fileExists = __PHYSFS_platformExists(f);
PHYSFS_Stat statbuf;
__PHYSFS_platformStat(f, fileExists, &statbuf);
return NULL;
} /* if */

@@ -197,9 +162,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
&__PHYSFS_ArchiveInfo_DIR,
DIR_openArchive, /* openArchive() method */
DIR_enumerateFiles, /* enumerateFiles() method */
DIR_exists, /* exists() method */
DIR_isDirectory, /* isDirectory() method */
DIR_isSymLink, /* isSymLink() method */
DIR_openRead, /* openRead() method */
DIR_openWrite, /* openWrite() method */
DIR_openAppend, /* openAppend() method */
@@ -319,26 +319,6 @@ static GRPentry *grp_find_entry(const GRPinfo *info, const char *name)
} /* grp_find_entry */


static int GRP_exists(dvoid *opaque, const char *name)
{
return (grp_find_entry((GRPinfo *) opaque, name) != NULL);
} /* GRP_exists */


static int GRP_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = GRP_exists(opaque, name);
return 0; /* never directories in a groupfile. */
} /* GRP_isDirectory */


static int GRP_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = GRP_exists(opaque, name);
return 0; /* never symlinks in a groupfile. */
} /* GRP_isSymLink */


static PHYSFS_Io *GRP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
{
PHYSFS_Io *retval = NULL;
@@ -443,9 +423,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
&__PHYSFS_ArchiveInfo_GRP,
GRP_openArchive, /* openArchive() method */
GRP_enumerateFiles, /* enumerateFiles() method */
GRP_exists, /* exists() method */
GRP_isDirectory, /* isDirectory() method */
GRP_isSymLink, /* isSymLink() method */
GRP_openRead, /* openRead() method */
GRP_openWrite, /* openWrite() method */
GRP_openAppend, /* openAppend() method */
@@ -335,26 +335,6 @@ static HOGentry *hog_find_entry(const HOGinfo *info, const char *name)
} /* hog_find_entry */


static int HOG_exists(dvoid *opaque, const char *name)
{
return (hog_find_entry((HOGinfo *) opaque, name) != NULL);
} /* HOG_exists */


static int HOG_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = HOG_exists(opaque, name);
return 0; /* never directories in a groupfile. */
} /* HOG_isDirectory */


static int HOG_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = HOG_exists(opaque, name);
return 0; /* never symlinks in a groupfile. */
} /* HOG_isSymLink */


static PHYSFS_Io *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists)
{
PHYSFS_Io *retval = NULL;
@@ -459,9 +439,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
&__PHYSFS_ArchiveInfo_HOG,
HOG_openArchive, /* openArchive() method */
HOG_enumerateFiles, /* enumerateFiles() method */
HOG_exists, /* exists() method */
HOG_isDirectory, /* isDirectory() method */
HOG_isSymLink, /* isSymLink() method */
HOG_openRead, /* openRead() method */
HOG_openWrite, /* openWrite() method */
HOG_openAppend, /* openAppend() method */
@@ -875,16 +875,6 @@ static void ISO9660_enumerateFiles(dvoid *opaque, const char *dname,
} /* ISO9660_enumerateFiles */


static int ISO9660_exists(dvoid *opaque, const char *name)
{
ISO9660Handle *handle = (ISO9660Handle*) opaque;
ISO9660FileDescriptor descriptor;
int exists = 0;
BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor, &exists), NULL, -1);
return exists;
} /* ISO9660_exists */


static int ISO9660_stat(dvoid *opaque, const char *name, int *exists,
PHYSFS_Stat *stat)
{
@@ -928,22 +918,6 @@ static int ISO9660_stat(dvoid *opaque, const char *name, int *exists,
} /* ISO9660_stat */


static int ISO9660_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
ISO9660Handle *handle = (ISO9660Handle*) opaque;
ISO9660FileDescriptor descriptor;
BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor, fileExists), NULL, 0);
return descriptor.flags.directory;
} /* ISO9660_isDirectory */


static int ISO9660_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = ISO9660_exists(opaque, name);
return 0;
} /* ISO9660_isSymLink */


/*******************************************************************************
* Not supported functions
******************************************************************************/
@@ -986,9 +960,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660 =
&__PHYSFS_ArchiveInfo_ISO9660,
ISO9660_openArchive, /* openArchive() method */
ISO9660_enumerateFiles, /* enumerateFiles() method */
ISO9660_exists, /* exists() method */
ISO9660_isDirectory, /* isDirectory() method */
ISO9660_isSymLink, /* isSymLink() method */
ISO9660_openRead, /* openRead() method */
ISO9660_openWrite, /* openWrite() method */
ISO9660_openAppend, /* openAppend() method */
@@ -581,30 +581,6 @@ static void LZMA_enumerateFiles(dvoid *opaque, const char *dname,
} /* LZMA_enumerateFiles */


static int LZMA_exists(dvoid *opaque, const char *name)
{
LZMAarchive *archive = (LZMAarchive *) opaque;
return (lzma_find_file(archive, name) != NULL);
} /* LZMA_exists */


static int LZMA_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
LZMAarchive *archive = (LZMAarchive *) opaque;
LZMAfile *file = lzma_find_file(archive, name);

*fileExists = (file != NULL);

return ((file == NULL) ? 0 : file->item->IsDirectory);
} /* LZMA_isDirectory */


static int LZMA_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* LZMA_isSymLink */


static PHYSFS_Io *LZMA_openRead(dvoid *opaque, const char *name, int *fileExists)
{
LZMAarchive *archive = (LZMAarchive *) opaque;
@@ -719,9 +695,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
&__PHYSFS_ArchiveInfo_LZMA,
LZMA_openArchive, /* openArchive() method */
LZMA_enumerateFiles, /* enumerateFiles() method */
LZMA_exists, /* exists() method */
LZMA_isDirectory, /* isDirectory() method */
LZMA_isSymLink, /* isSymLink() method */
LZMA_openRead, /* openRead() method */
LZMA_openWrite, /* openWrite() method */
LZMA_openAppend, /* openAppend() method */
@@ -316,26 +316,6 @@ static MVLentry *mvl_find_entry(const MVLinfo *info, const char *name)
} /* mvl_find_entry */


static int MVL_exists(dvoid *opaque, const char *name)
{
return (mvl_find_entry((MVLinfo *) opaque, name) != NULL);
} /* MVL_exists */


static int MVL_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = MVL_exists(opaque, name);
return 0; /* never directories in a groupfile. */
} /* MVL_isDirectory */


static int MVL_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = MVL_exists(opaque, name);
return 0; /* never symlinks in a groupfile. */
} /* MVL_isSymLink */


static PHYSFS_Io *MVL_openRead(dvoid *opaque, const char *fnm, int *fileExists)
{
PHYSFS_Io *retval = NULL;
@@ -440,9 +420,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
&__PHYSFS_ArchiveInfo_MVL,
MVL_openArchive, /* openArchive() method */
MVL_enumerateFiles, /* enumerateFiles() method */
MVL_exists, /* exists() method */
MVL_isDirectory, /* isDirectory() method */
MVL_isSymLink, /* isSymLink() method */
MVL_openRead, /* openRead() method */
MVL_openWrite, /* openWrite() method */
MVL_openAppend, /* openAppend() method */
@@ -451,36 +451,6 @@ static QPAKentry *qpak_find_entry(const QPAKinfo *info, const char *path,
} /* qpak_find_entry */


static int QPAK_exists(dvoid *opaque, const char *name)
{
int isDir;
QPAKinfo *info = (QPAKinfo *) opaque;
QPAKentry *entry = qpak_find_entry(info, name, &isDir);
return ((entry != NULL) || (isDir));
} /* QPAK_exists */


static int QPAK_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
QPAKinfo *info = (QPAKinfo *) opaque;
int isDir;
QPAKentry *entry = qpak_find_entry(info, name, &isDir);

*fileExists = ((isDir) || (entry != NULL));
if (isDir)
return 1; /* definitely a dir. */

BAIL_MACRO(ERR_NO_SUCH_FILE, 0);
} /* QPAK_isDirectory */


static int QPAK_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = QPAK_exists(opaque, name);
return 0; /* never symlinks in a quake pak. */
} /* QPAK_isSymLink */


static PHYSFS_Io *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists)
{
PHYSFS_Io *io = NULL;
@@ -595,9 +565,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
&__PHYSFS_ArchiveInfo_QPAK,
QPAK_openArchive, /* openArchive() method */
QPAK_enumerateFiles, /* enumerateFiles() method */
QPAK_exists, /* exists() method */
QPAK_isDirectory, /* isDirectory() method */
QPAK_isSymLink, /* isSymLink() method */
QPAK_openRead, /* openRead() method */
QPAK_openWrite, /* openWrite() method */
QPAK_openAppend, /* openAppend() method */
@@ -336,47 +336,6 @@ static WADentry *wad_find_entry(const WADinfo *info, const char *name)
} /* wad_find_entry */


static int WAD_exists(dvoid *opaque, const char *name)
{
return (wad_find_entry((WADinfo *) opaque, name) != NULL);
} /* WAD_exists */


static int WAD_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
WADentry *entry = wad_find_entry(((WADinfo *) opaque), name);
const int exists = (entry != NULL);
*fileExists = exists;
if (exists)
{
char *n;

/* Can't be a directory if it's a subdirectory. */
if (strchr(entry->name, '/') != NULL)
return 0;

/* !!! FIXME: this isn't really something we should do. */
/* !!! FIXME: I probably broke enumeration up there, too. */
/* Check if it matches "MAP??" or "E?M?" ... */
n = entry->name;
if ((n[0] == 'E' && n[2] == 'M') ||
(n[0] == 'M' && n[1] == 'A' && n[2] == 'P' && n[6] == 0))
{
return 1;
} /* if */
} /* if */

return 0;
} /* WAD_isDirectory */


static int WAD_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
*fileExists = WAD_exists(opaque, name);
return 0; /* never symlinks in a wad. */
} /* WAD_isSymLink */


static PHYSFS_Io *WAD_openRead(dvoid *opaque, const char *fnm, int *fileExists)
{
PHYSFS_Io *retval = NULL;
@@ -481,9 +440,6 @@ const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
&__PHYSFS_ArchiveInfo_WAD,
WAD_openArchive, /* openArchive() method */
WAD_enumerateFiles, /* enumerateFiles() method */
WAD_exists, /* exists() method */
WAD_isDirectory, /* isDirectory() method */
WAD_isSymLink, /* isSymLink() method */
WAD_openRead, /* openRead() method */
WAD_openWrite, /* openWrite() method */
WAD_openAppend, /* openAppend() method */

0 comments on commit 7f0e710

Please sign in to comment.