Skip to content

Commit

Permalink
Bunch of tedious corrections, optimizations, and cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 21, 2002
1 parent b772eed commit 1f5b571
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 190 deletions.
76 changes: 56 additions & 20 deletions archivers/dir.c
Expand Up @@ -24,6 +24,10 @@ static PHYSFS_sint64 DIR_read(FileHandle *handle, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static PHYSFS_sint64 DIR_write(FileHandle *handle, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static PHYSFS_sint64 DIR_dummyRead(FileHandle *handle, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static PHYSFS_sint64 DIR_dummyWrite(FileHandle *handle, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static int DIR_eof(FileHandle *handle);
static PHYSFS_sint64 DIR_tell(FileHandle *handle);
static int DIR_seek(FileHandle *handle, PHYSFS_uint64 offset);
Expand All @@ -35,10 +39,10 @@ static LinkedStringList *DIR_enumerateFiles(DirHandle *h,
const char *dname,
int omitSymLinks);
static int DIR_exists(DirHandle *h, const char *name);
static int DIR_isDirectory(DirHandle *h, const char *name);
static int DIR_isSymLink(DirHandle *h, const char *name);
static FileHandle *DIR_openRead(DirHandle *h, const char *filename);
static PHYSFS_sint64 DIR_getLastModTime(DirHandle *h, const char *name);
static int DIR_isDirectory(DirHandle *h, const char *name, int *fileExists);
static int DIR_isSymLink(DirHandle *h, const char *name, int *fileExists);
static FileHandle *DIR_openRead(DirHandle *h, const char *fnm, int *exist);
static PHYSFS_sint64 DIR_getLastModTime(DirHandle *h, const char *f, int *e);
static FileHandle *DIR_openWrite(DirHandle *h, const char *filename);
static FileHandle *DIR_openAppend(DirHandle *h, const char *filename);
static int DIR_remove(DirHandle *h, const char *name);
Expand All @@ -58,7 +62,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
static const FileFunctions __PHYSFS_FileFunctions_DIR =
{
DIR_read, /* read() method */
NULL, /* write() method */
DIR_dummyWrite, /* write() method */
DIR_eof, /* eof() method */
DIR_tell, /* tell() method */
DIR_seek, /* seek() method */
Expand All @@ -69,7 +73,7 @@ static const FileFunctions __PHYSFS_FileFunctions_DIR =

static const FileFunctions __PHYSFS_FileFunctions_DIRW =
{
NULL, /* read() method */
DIR_dummyRead, /* read() method */
DIR_write, /* write() method */
DIR_eof, /* eof() method */
DIR_tell, /* tell() method */
Expand Down Expand Up @@ -116,6 +120,20 @@ static PHYSFS_sint64 DIR_write(FileHandle *handle, const void *buffer,
} /* DIR_write */


static PHYSFS_sint64 DIR_dummyRead(FileHandle *handle, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
} /* DIR_dummyRead */


static PHYSFS_sint64 DIR_dummyWrite(FileHandle *handle, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
} /* DIR_dummyWrite */


static int DIR_eof(FileHandle *handle)
{
return(__PHYSFS_platformEOF(handle->opaque));
Expand Down Expand Up @@ -217,52 +235,70 @@ static int DIR_exists(DirHandle *h, const char *name)
} /* DIR_exists */


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

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


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

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


static PHYSFS_sint64 DIR_getLastModTime(DirHandle *h, const char *name)
static PHYSFS_sint64 DIR_getLastModTime(DirHandle *h,
const char *name,
int *fileExists)
{
char *d = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, NULL);
PHYSFS_sint64 retval;
PHYSFS_sint64 retval = -1;

BAIL_IF_MACRO(d == NULL, NULL, 0);
retval = __PHYSFS_platformGetLastModTime(d);
*fileExists = __PHYSFS_platformExists(d);
if (*fileExists)
retval = __PHYSFS_platformGetLastModTime(d);
free(d);
return(retval);
} /* DIR_getLastModTime */


static FileHandle *doOpen(DirHandle *h, const char *name,
void *(*openFunc)(const char *filename),
const FileFunctions *fileFuncs)
int *fileExists, const FileFunctions *fileFuncs)
{
char *f = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, NULL);
void *rc;
FileHandle *retval;

BAIL_IF_MACRO(f == NULL, NULL, NULL);

if (fileExists != NULL)
{
*fileExists = __PHYSFS_platformExists(f);
if (!(*fileExists))
{
free(f);
return(NULL);
} /* if */
} /* if */

retval = (FileHandle *) malloc(sizeof (FileHandle));
if (!retval)
{
Expand All @@ -287,23 +323,23 @@ static FileHandle *doOpen(DirHandle *h, const char *name,
} /* doOpen */


static FileHandle *DIR_openRead(DirHandle *h, const char *filename)
static FileHandle *DIR_openRead(DirHandle *h, const char *fnm, int *exist)
{
return(doOpen(h, filename, __PHYSFS_platformOpenRead,
return(doOpen(h, fnm, __PHYSFS_platformOpenRead, exist,
&__PHYSFS_FileFunctions_DIR));
} /* DIR_openRead */


static FileHandle *DIR_openWrite(DirHandle *h, const char *filename)
{
return(doOpen(h, filename, __PHYSFS_platformOpenWrite,
return(doOpen(h, filename, __PHYSFS_platformOpenWrite, NULL,
&__PHYSFS_FileFunctions_DIRW));
} /* DIR_openWrite */


static FileHandle *DIR_openAppend(DirHandle *h, const char *filename)
{
return(doOpen(h, filename, __PHYSFS_platformOpenAppend,
return(doOpen(h, filename, __PHYSFS_platformOpenAppend, NULL,
&__PHYSFS_FileFunctions_DIRW));
} /* DIR_openAppend */

Expand Down
80 changes: 62 additions & 18 deletions archivers/grp.c
Expand Up @@ -67,6 +67,8 @@ typedef struct
static void GRP_dirClose(DirHandle *h);
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static PHYSFS_sint64 GRP_write(FileHandle *handle, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static int GRP_eof(FileHandle *handle);
static PHYSFS_sint64 GRP_tell(FileHandle *handle);
static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset);
Expand All @@ -78,10 +80,14 @@ static LinkedStringList *GRP_enumerateFiles(DirHandle *h,
const char *dirname,
int omitSymLinks);
static int GRP_exists(DirHandle *h, const char *name);
static int GRP_isDirectory(DirHandle *h, const char *name);
static int GRP_isSymLink(DirHandle *h, const char *name);
static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name);
static FileHandle *GRP_openRead(DirHandle *h, const char *name);
static int GRP_isDirectory(DirHandle *h, const char *name, int *fileExists);
static int GRP_isSymLink(DirHandle *h, const char *name, int *fileExists);
static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *n, int *e);
static FileHandle *GRP_openRead(DirHandle *h, const char *name, int *exist);
static FileHandle *GRP_openWrite(DirHandle *h, const char *name);
static FileHandle *GRP_openAppend(DirHandle *h, const char *name);
static int GRP_remove(DirHandle *h, const char *name);
static int GRP_mkdir(DirHandle *h, const char *name);

const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
{
Expand All @@ -95,7 +101,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
static const FileFunctions __PHYSFS_FileFunctions_GRP =
{
GRP_read, /* read() method */
NULL, /* write() method */
GRP_write, /* write() method */
GRP_eof, /* eof() method */
GRP_tell, /* tell() method */
GRP_seek, /* seek() method */
Expand All @@ -115,10 +121,10 @@ const DirFunctions __PHYSFS_DirFunctions_GRP =
GRP_isSymLink, /* isSymLink() method */
GRP_getLastModTime, /* getLastModTime() method */
GRP_openRead, /* openRead() method */
NULL, /* openWrite() method */
NULL, /* openAppend() method */
NULL, /* remove() method */
NULL, /* mkdir() method */
GRP_openWrite, /* openWrite() method */
GRP_openAppend, /* openAppend() method */
GRP_remove, /* remove() method */
GRP_mkdir, /* mkdir() method */
GRP_dirClose /* dirClose() method */
};

Expand Down Expand Up @@ -154,6 +160,13 @@ static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
} /* GRP_read */


static PHYSFS_sint64 GRP_write(FileHandle *handle, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
} /* GRP_write */


static int GRP_eof(FileHandle *handle)
{
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
Expand Down Expand Up @@ -427,37 +440,44 @@ static int GRP_exists(DirHandle *h, const char *name)
} /* GRP_exists */


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


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


static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name)
static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h,
const char *name,
int *fileExists)
{
GRPinfo *info = ((GRPinfo *) h->opaque);
if (grp_find_entry(info, name) == NULL)
return(-1); /* no such entry. */
PHYSFS_sint64 retval = -1;

/* Just return the time of the GRP itself in the physical filesystem. */
return(((GRPinfo *) h->opaque)->last_mod_time);
*fileExists = (grp_find_entry(info, name) != NULL);
if (*fileExists) /* use time of GRP itself in the physical filesystem. */
retval = ((GRPinfo *) h->opaque)->last_mod_time;

return(retval);
} /* GRP_getLastModTime */


static FileHandle *GRP_openRead(DirHandle *h, const char *name)
static FileHandle *GRP_openRead(DirHandle *h, const char *fnm, int *fileExists)
{
GRPinfo *info = ((GRPinfo *) h->opaque);
FileHandle *retval;
GRPfileinfo *finfo;
GRPentry *entry;

entry = grp_find_entry(info, name);
entry = grp_find_entry(info, fnm);
*fileExists = (entry != NULL);
BAIL_IF_MACRO(entry == NULL, NULL, NULL);

retval = (FileHandle *) malloc(sizeof (FileHandle));
Expand Down Expand Up @@ -486,6 +506,30 @@ static FileHandle *GRP_openRead(DirHandle *h, const char *name)
return(retval);
} /* GRP_openRead */


static FileHandle *GRP_openWrite(DirHandle *h, const char *name)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
} /* GRP_openWrite */


static FileHandle *GRP_openAppend(DirHandle *h, const char *name)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
} /* GRP_openAppend */


static int GRP_remove(DirHandle *h, const char *name)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* GRP_remove */


static int GRP_mkdir(DirHandle *h, const char *name)
{
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
} /* GRP_mkdir */

#endif /* defined PHYSFS_SUPPORTS_GRP */

/* end of grp.c ... */
Expand Down

0 comments on commit 1f5b571

Please sign in to comment.