Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Did the same thing to FileHandles than I did to DirHandles, but this
triggered massive tweaking in physfs.c. A lot of code got little
cleanups, which was nice. Less malloc pressure, too, since opening a
file used to allocate a ton of crap and mush it together...now it's
basically down to one structure and the instance data in whatever
archiver.
  • Loading branch information
icculus committed Sep 26, 2004
1 parent 7304489 commit 90031c8
Show file tree
Hide file tree
Showing 12 changed files with 802 additions and 993 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,12 @@
* CHANGELOG.
*/

09262004 - Did the same thing to FileHandles than I did to DirHandles, but
this triggered massive tweaking in physfs.c. A lot of code got
little cleanups, which was nice. Less malloc pressure, too, since
opening a file used to allocate a ton of crap and mush it
together...now it's basically down to one structure and the
instance data in whatever archiver.
09252004 - Cleaned up archiver interface to not deal with DirHandles anymore,
which simplifies things, removes some responsibility and code
duplication from the archivers, and trims some malloc pressure.
Expand Down
177 changes: 61 additions & 116 deletions archivers/dir.c
Expand Up @@ -18,34 +18,30 @@
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"

static PHYSFS_sint64 DIR_read(FileHandle *handle, void *buffer,
static PHYSFS_sint64 DIR_read(fvoid *opaque, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
static PHYSFS_sint64 DIR_write(FileHandle *handle, const void *buffer,
static PHYSFS_sint64 DIR_write(fvoid *opaque, 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);
static PHYSFS_sint64 DIR_fileLength(FileHandle *handle);
static int DIR_fileClose(FileHandle *handle);
static int DIR_eof(fvoid *opaque);
static PHYSFS_sint64 DIR_tell(fvoid *opaque);
static int DIR_seek(fvoid *opaque, PHYSFS_uint64 offset);
static PHYSFS_sint64 DIR_fileLength(fvoid *opaque);
static int DIR_fileClose(fvoid *opaque);
static int DIR_isArchive(const char *filename, int forWriting);
static void *DIR_openArchive(const char *name, int forWriting);
static LinkedStringList *DIR_enumerateFiles(void *opaque,
static LinkedStringList *DIR_enumerateFiles(dvoid *opaque,
const char *dname,
int omitSymLinks);
static int DIR_exists(void *opaque, const char *name);
static int DIR_isDirectory(void *opaque, const char *name, int *fileExists);
static int DIR_isSymLink(void *opaque, const char *name, int *fileExists);
static FileHandle *DIR_openRead(void *opaque, const char *fnm, int *exist);
static PHYSFS_sint64 DIR_getLastModTime(void *opaque, const char *f, int *e);
static FileHandle *DIR_openWrite(void *opaque, const char *filename);
static FileHandle *DIR_openAppend(void *opaque, const char *filename);
static int DIR_remove(void *opaque, const char *name);
static int DIR_mkdir(void *opaque, const char *name);
static void DIR_dirClose(void *opaque);
static int DIR_exists(dvoid *opaque, const char *name);
static int DIR_isDirectory(dvoid *opaque, const char *name, int *fileExists);
static int DIR_isSymLink(dvoid *opaque, const char *name, int *fileExists);
static fvoid *DIR_openRead(dvoid *opaque, const char *fnm, int *exist);
static PHYSFS_sint64 DIR_getLastModTime(dvoid *opaque, const char *f, int *e);
static fvoid *DIR_openWrite(dvoid *opaque, const char *filename);
static fvoid *DIR_openAppend(dvoid *opaque, const char *filename);
static int DIR_remove(dvoid *opaque, const char *name);
static int DIR_mkdir(dvoid *opaque, const char *name);
static void DIR_dirClose(dvoid *opaque);


const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
Expand All @@ -57,31 +53,8 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
};


static const FileFunctions __PHYSFS_FileFunctions_DIR =
{
DIR_read, /* read() method */
DIR_dummyWrite, /* write() method */
DIR_eof, /* eof() method */
DIR_tell, /* tell() method */
DIR_seek, /* seek() method */
DIR_fileLength, /* fileLength() method */
DIR_fileClose /* fileClose() method */
};


static const FileFunctions __PHYSFS_FileFunctions_DIRW =
{
DIR_dummyRead, /* read() method */
DIR_write, /* write() method */
DIR_eof, /* eof() method */
DIR_tell, /* tell() method */
DIR_seek, /* seek() method */
DIR_fileLength, /* fileLength() method */
DIR_fileClose /* fileClose() method */
};


const DirFunctions __PHYSFS_DirFunctions_DIR =
const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
{
&__PHYSFS_ArchiveInfo_DIR,
DIR_isArchive, /* isArchive() method */
Expand All @@ -96,76 +69,68 @@ const DirFunctions __PHYSFS_DirFunctions_DIR =
DIR_openAppend, /* openAppend() method */
DIR_remove, /* remove() method */
DIR_mkdir, /* mkdir() method */
DIR_dirClose /* dirClose() method */
DIR_dirClose, /* dirClose() method */
DIR_read, /* read() method */
DIR_write, /* write() method */
DIR_eof, /* eof() method */
DIR_tell, /* tell() method */
DIR_seek, /* seek() method */
DIR_fileLength, /* fileLength() method */
DIR_fileClose /* fileClose() method */
};


static PHYSFS_sint64 DIR_read(FileHandle *handle, void *buffer,
static PHYSFS_sint64 DIR_read(fvoid *opaque, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
{
PHYSFS_sint64 retval;
retval = __PHYSFS_platformRead(handle->opaque, buffer, objSize, objCount);
retval = __PHYSFS_platformRead(opaque, buffer, objSize, objCount);
return(retval);
} /* DIR_read */


static PHYSFS_sint64 DIR_write(FileHandle *handle, const void *buffer,
static PHYSFS_sint64 DIR_write(fvoid *opaque, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
{
PHYSFS_sint64 retval;
retval = __PHYSFS_platformWrite(handle->opaque, buffer, objSize, objCount);
retval = __PHYSFS_platformWrite(opaque, buffer, objSize, objCount);
return(retval);
} /* DIR_write */


static PHYSFS_sint64 DIR_dummyRead(FileHandle *handle, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
static int DIR_eof(fvoid *opaque)
{
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));
return(__PHYSFS_platformEOF(opaque));
} /* DIR_eof */


static PHYSFS_sint64 DIR_tell(FileHandle *handle)
static PHYSFS_sint64 DIR_tell(fvoid *opaque)
{
return(__PHYSFS_platformTell(handle->opaque));
return(__PHYSFS_platformTell(opaque));
} /* DIR_tell */


static int DIR_seek(FileHandle *handle, PHYSFS_uint64 offset)
static int DIR_seek(fvoid *opaque, PHYSFS_uint64 offset)
{
return(__PHYSFS_platformSeek(handle->opaque, offset));
return(__PHYSFS_platformSeek(opaque, offset));
} /* DIR_seek */


static PHYSFS_sint64 DIR_fileLength(FileHandle *handle)
static PHYSFS_sint64 DIR_fileLength(fvoid *opaque)
{
return(__PHYSFS_platformFileLength(handle->opaque));
return(__PHYSFS_platformFileLength(opaque));
} /* DIR_fileLength */


static int DIR_fileClose(FileHandle *handle)
static int DIR_fileClose(fvoid *opaque)
{
/*
* we manually flush the buffer, since that's the place a close will
* most likely fail, but that will leave the file handle in an undefined
* state if it fails. Flush failures we can recover from.
*/
BAIL_IF_MACRO(!__PHYSFS_platformFlush(handle->opaque), NULL, 0);
BAIL_IF_MACRO(!__PHYSFS_platformClose(handle->opaque), NULL, 0);
free(handle);
BAIL_IF_MACRO(!__PHYSFS_platformFlush(opaque), NULL, 0);
BAIL_IF_MACRO(!__PHYSFS_platformClose(opaque), NULL, 0);
return(1);
} /* DIR_fileClose */

Expand Down Expand Up @@ -200,7 +165,7 @@ static void *DIR_openArchive(const char *name, int forWriting)
} /* DIR_openArchive */


static LinkedStringList *DIR_enumerateFiles(void *opaque,
static LinkedStringList *DIR_enumerateFiles(dvoid *opaque,
const char *dname,
int omitSymLinks)
{
Expand All @@ -214,7 +179,7 @@ static LinkedStringList *DIR_enumerateFiles(void *opaque,
} /* DIR_enumerateFiles */


static int DIR_exists(void *opaque, const char *name)
static int DIR_exists(dvoid *opaque, const char *name)
{
char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval;
Expand All @@ -226,7 +191,7 @@ static int DIR_exists(void *opaque, const char *name)
} /* DIR_exists */


static int DIR_isDirectory(void *opaque, const char *name, int *fileExists)
static int DIR_isDirectory(dvoid *opaque, const char *name, int *fileExists)
{
char *d = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval = 0;
Expand All @@ -240,7 +205,7 @@ static int DIR_isDirectory(void *opaque, const char *name, int *fileExists)
} /* DIR_isDirectory */


static int DIR_isSymLink(void *opaque, const char *name, int *fileExists)
static int DIR_isSymLink(dvoid *opaque, const char *name, int *fileExists)
{
char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval = 0;
Expand All @@ -254,7 +219,7 @@ static int DIR_isSymLink(void *opaque, const char *name, int *fileExists)
} /* DIR_isSymLink */


static PHYSFS_sint64 DIR_getLastModTime(void *opaque,
static PHYSFS_sint64 DIR_getLastModTime(dvoid *opaque,
const char *name,
int *fileExists)
{
Expand All @@ -270,13 +235,12 @@ static PHYSFS_sint64 DIR_getLastModTime(void *opaque,
} /* DIR_getLastModTime */


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

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

Expand All @@ -290,51 +254,32 @@ static FileHandle *doOpen(void *opaque, const char *name,
} /* if */
} /* if */

retval = (FileHandle *) malloc(sizeof (FileHandle));
if (!retval)
{
free(f);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */

rc = openFunc(f);
free(f);

if (!rc)
{
free(retval);
return(NULL);
} /* if */

retval->opaque = (void *) rc;
retval->funcs = fileFuncs;

return(retval);
return((fvoid *) rc);
} /* doOpen */


static FileHandle *DIR_openRead(void *opaque, const char *fnm, int *exist)
static fvoid *DIR_openRead(dvoid *opaque, const char *fnm, int *exist)
{
return(doOpen(opaque, fnm, __PHYSFS_platformOpenRead, exist,
&__PHYSFS_FileFunctions_DIR));
return(doOpen(opaque, fnm, __PHYSFS_platformOpenRead, exist));
} /* DIR_openRead */


static FileHandle *DIR_openWrite(void *opaque, const char *filename)
static fvoid *DIR_openWrite(dvoid *opaque, const char *filename)
{
return(doOpen(opaque, filename, __PHYSFS_platformOpenWrite, NULL,
&__PHYSFS_FileFunctions_DIRW));
return(doOpen(opaque, filename, __PHYSFS_platformOpenWrite, NULL));
} /* DIR_openWrite */


static FileHandle *DIR_openAppend(void *opaque, const char *filename)
static fvoid *DIR_openAppend(dvoid *opaque, const char *filename)
{
return(doOpen(opaque, filename, __PHYSFS_platformOpenAppend, NULL,
&__PHYSFS_FileFunctions_DIRW));
return(doOpen(opaque, filename, __PHYSFS_platformOpenAppend, NULL));
} /* DIR_openAppend */


static int DIR_remove(void *opaque, const char *name)
static int DIR_remove(dvoid *opaque, const char *name)
{
char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval;
Expand All @@ -346,7 +291,7 @@ static int DIR_remove(void *opaque, const char *name)
} /* DIR_remove */


static int DIR_mkdir(void *opaque, const char *name)
static int DIR_mkdir(dvoid *opaque, const char *name)
{
char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL);
int retval;
Expand All @@ -358,7 +303,7 @@ static int DIR_mkdir(void *opaque, const char *name)
} /* DIR_mkdir */


static void DIR_dirClose(void *opaque)
static void DIR_dirClose(dvoid *opaque)
{
free(opaque);
} /* DIR_dirClose */
Expand Down

0 comments on commit 90031c8

Please sign in to comment.