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.
This commit is contained in:
parent
73044892fa
commit
90031c81f3
|
@ -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.
|
||||
|
|
177
archivers/dir.c
177
archivers/dir.c
|
@ -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 =
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
|
130
archivers/grp.c
130
archivers/grp.c
|
@ -61,30 +61,30 @@ typedef struct
|
|||
} GRPfileinfo;
|
||||
|
||||
|
||||
static void GRP_dirClose(void *opaque);
|
||||
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 GRP_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 GRP_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 GRP_write(fvoid *opaque, 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);
|
||||
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle);
|
||||
static int GRP_fileClose(FileHandle *handle);
|
||||
static int GRP_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 GRP_tell(fvoid *opaque);
|
||||
static int GRP_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 GRP_fileLength(fvoid *opaque);
|
||||
static int GRP_fileClose(fvoid *opaque);
|
||||
static int GRP_isArchive(const char *filename, int forWriting);
|
||||
static void *GRP_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *GRP_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *GRP_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int GRP_exists(void *opaque, const char *name);
|
||||
static int GRP_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int GRP_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 GRP_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *GRP_openRead(void *opaque, const char *name, int *exist);
|
||||
static FileHandle *GRP_openWrite(void *opaque, const char *name);
|
||||
static FileHandle *GRP_openAppend(void *opaque, const char *name);
|
||||
static int GRP_remove(void *opaque, const char *name);
|
||||
static int GRP_mkdir(void *opaque, const char *name);
|
||||
static int GRP_exists(dvoid *opaque, const char *name);
|
||||
static int GRP_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int GRP_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 GRP_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *GRP_openRead(dvoid *opaque, const char *name, int *exist);
|
||||
static fvoid *GRP_openWrite(dvoid *opaque, const char *name);
|
||||
static fvoid *GRP_openAppend(dvoid *opaque, const char *name);
|
||||
static int GRP_remove(dvoid *opaque, const char *name);
|
||||
static int GRP_mkdir(dvoid *opaque, const char *name);
|
||||
static void GRP_dirClose(dvoid *opaque);
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
|
||||
{
|
||||
|
@ -95,19 +95,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
|
|||
};
|
||||
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_GRP =
|
||||
{
|
||||
GRP_read, /* read() method */
|
||||
GRP_write, /* write() method */
|
||||
GRP_eof, /* eof() method */
|
||||
GRP_tell, /* tell() method */
|
||||
GRP_seek, /* seek() method */
|
||||
GRP_fileLength, /* fileLength() method */
|
||||
GRP_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_GRP =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_GRP,
|
||||
GRP_isArchive, /* isArchive() method */
|
||||
|
@ -122,12 +110,19 @@ const DirFunctions __PHYSFS_DirFunctions_GRP =
|
|||
GRP_openAppend, /* openAppend() method */
|
||||
GRP_remove, /* remove() method */
|
||||
GRP_mkdir, /* mkdir() method */
|
||||
GRP_dirClose /* dirClose() method */
|
||||
GRP_dirClose, /* dirClose() method */
|
||||
GRP_read, /* read() method */
|
||||
GRP_write, /* write() method */
|
||||
GRP_eof, /* eof() method */
|
||||
GRP_tell, /* tell() method */
|
||||
GRP_seek, /* seek() method */
|
||||
GRP_fileLength, /* fileLength() method */
|
||||
GRP_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void GRP_dirClose(void *opaque)
|
||||
static void GRP_dirClose(dvoid *opaque)
|
||||
{
|
||||
GRPinfo *info = ((GRPinfo *) opaque);
|
||||
free(info->filename);
|
||||
|
@ -136,10 +131,10 @@ static void GRP_dirClose(void *opaque)
|
|||
} /* GRP_dirClose */
|
||||
|
||||
|
||||
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 GRP_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
||||
GRPentry *entry = finfo->entry;
|
||||
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
|
||||
PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
|
||||
|
@ -156,30 +151,30 @@ static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
|
|||
} /* GRP_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 GRP_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 GRP_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* GRP_write */
|
||||
|
||||
|
||||
static int GRP_eof(FileHandle *handle)
|
||||
static int GRP_eof(fvoid *opaque)
|
||||
{
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
||||
GRPentry *entry = finfo->entry;
|
||||
return(finfo->curPos >= entry->size);
|
||||
} /* GRP_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 GRP_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 GRP_tell(fvoid *opaque)
|
||||
{
|
||||
return(((GRPfileinfo *) (handle->opaque))->curPos);
|
||||
return(((GRPfileinfo *) opaque)->curPos);
|
||||
} /* GRP_tell */
|
||||
|
||||
|
||||
static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int GRP_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
||||
GRPentry *entry = finfo->entry;
|
||||
int rc;
|
||||
|
||||
|
@ -193,19 +188,18 @@ static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* GRP_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 GRP_fileLength(fvoid *opaque)
|
||||
{
|
||||
GRPfileinfo *finfo = ((GRPfileinfo *) handle->opaque);
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
||||
return((PHYSFS_sint64) finfo->entry->size);
|
||||
} /* GRP_fileLength */
|
||||
|
||||
|
||||
static int GRP_fileClose(FileHandle *handle)
|
||||
static int GRP_fileClose(fvoid *opaque)
|
||||
{
|
||||
GRPfileinfo *finfo = ((GRPfileinfo *) handle->opaque);
|
||||
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* GRP_fileClose */
|
||||
|
||||
|
@ -365,11 +359,11 @@ GRP_openArchive_failed:
|
|||
} /* GRP_openArchive */
|
||||
|
||||
|
||||
static LinkedStringList *GRP_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *GRP_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
GRPinfo *info = ((GRPinfo *) opaque);
|
||||
GRPinfo *info = (GRPinfo *) opaque;
|
||||
GRPentry *entry = info->entries;
|
||||
LinkedStringList *retval = NULL, *p = NULL;
|
||||
PHYSFS_uint32 max = info->entryCount;
|
||||
|
@ -418,31 +412,31 @@ static GRPentry *grp_find_entry(GRPinfo *info, const char *name)
|
|||
} /* grp_find_entry */
|
||||
|
||||
|
||||
static int GRP_exists(void *opaque, const char *name)
|
||||
static int GRP_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
return(grp_find_entry(((GRPinfo *) opaque), name) != NULL);
|
||||
return(grp_find_entry((GRPinfo *) opaque, name) != NULL);
|
||||
} /* GRP_exists */
|
||||
|
||||
|
||||
static int GRP_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
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(void *opaque, const char *name, int *fileExists)
|
||||
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_sint64 GRP_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 GRP_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
GRPinfo *info = ((GRPinfo *) opaque);
|
||||
GRPinfo *info = (GRPinfo *) opaque;
|
||||
PHYSFS_sint64 retval = -1;
|
||||
|
||||
*fileExists = (grp_find_entry(info, name) != NULL);
|
||||
|
@ -453,10 +447,9 @@ static PHYSFS_sint64 GRP_getLastModTime(void *opaque,
|
|||
} /* GRP_getLastModTime */
|
||||
|
||||
|
||||
static FileHandle *GRP_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *GRP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
GRPinfo *info = ((GRPinfo *) opaque);
|
||||
FileHandle *retval;
|
||||
GRPinfo *info = (GRPinfo *) opaque;
|
||||
GRPfileinfo *finfo;
|
||||
GRPentry *entry;
|
||||
|
||||
|
@ -464,51 +457,42 @@ static FileHandle *GRP_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
*fileExists = (entry != NULL);
|
||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||
|
||||
retval = (FileHandle *) malloc(sizeof (FileHandle));
|
||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo));
|
||||
if (finfo == NULL)
|
||||
{
|
||||
free(retval);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
|
||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||
if ( (finfo->handle == NULL) ||
|
||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||
{
|
||||
free(finfo);
|
||||
free(retval);
|
||||
return(NULL);
|
||||
} /* if */
|
||||
|
||||
finfo->curPos = 0;
|
||||
finfo->entry = entry;
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_GRP;
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* GRP_openRead */
|
||||
|
||||
|
||||
static FileHandle *GRP_openWrite(void *opaque, const char *name)
|
||||
static fvoid *GRP_openWrite(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* GRP_openWrite */
|
||||
|
||||
|
||||
static FileHandle *GRP_openAppend(void *opaque, const char *name)
|
||||
static fvoid *GRP_openAppend(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* GRP_openAppend */
|
||||
|
||||
|
||||
static int GRP_remove(void *opaque, const char *name)
|
||||
static int GRP_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* GRP_remove */
|
||||
|
||||
|
||||
static int GRP_mkdir(void *opaque, const char *name)
|
||||
static int GRP_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* GRP_mkdir */
|
||||
|
|
122
archivers/hog.c
122
archivers/hog.c
|
@ -75,30 +75,30 @@ typedef struct
|
|||
} HOGfileinfo;
|
||||
|
||||
|
||||
static void HOG_dirClose(void *opaque);
|
||||
static PHYSFS_sint64 HOG_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 HOG_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 HOG_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 HOG_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static int HOG_eof(FileHandle *handle);
|
||||
static PHYSFS_sint64 HOG_tell(FileHandle *handle);
|
||||
static int HOG_seek(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 HOG_fileLength(FileHandle *handle);
|
||||
static int HOG_fileClose(FileHandle *handle);
|
||||
static int HOG_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 HOG_tell(fvoid *opaque);
|
||||
static int HOG_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 HOG_fileLength(fvoid *opaque);
|
||||
static int HOG_fileClose(fvoid *opaque);
|
||||
static int HOG_isArchive(const char *filename, int forWriting);
|
||||
static void *HOG_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *HOG_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *HOG_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int HOG_exists(void *opaque, const char *name);
|
||||
static int HOG_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int HOG_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 HOG_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *HOG_openRead(void *opaque, const char *name, int *exist);
|
||||
static FileHandle *HOG_openWrite(void *opaque, const char *name);
|
||||
static FileHandle *HOG_openAppend(void *opaque, const char *name);
|
||||
static int HOG_remove(void *opaque, const char *name);
|
||||
static int HOG_mkdir(void *opaque, const char *name);
|
||||
static int HOG_exists(dvoid *opaque, const char *name);
|
||||
static int HOG_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int HOG_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 HOG_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *HOG_openRead(dvoid *opaque, const char *name, int *exist);
|
||||
static fvoid *HOG_openWrite(dvoid *opaque, const char *name);
|
||||
static fvoid *HOG_openAppend(dvoid *opaque, const char *name);
|
||||
static int HOG_remove(dvoid *opaque, const char *name);
|
||||
static int HOG_mkdir(dvoid *opaque, const char *name);
|
||||
static void HOG_dirClose(dvoid *opaque);
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG =
|
||||
{
|
||||
|
@ -109,19 +109,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG =
|
|||
};
|
||||
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_HOG =
|
||||
{
|
||||
HOG_read, /* read() method */
|
||||
HOG_write, /* write() method */
|
||||
HOG_eof, /* eof() method */
|
||||
HOG_tell, /* tell() method */
|
||||
HOG_seek, /* seek() method */
|
||||
HOG_fileLength, /* fileLength() method */
|
||||
HOG_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_HOG =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_HOG,
|
||||
HOG_isArchive, /* isArchive() method */
|
||||
|
@ -136,12 +124,19 @@ const DirFunctions __PHYSFS_DirFunctions_HOG =
|
|||
HOG_openAppend, /* openAppend() method */
|
||||
HOG_remove, /* remove() method */
|
||||
HOG_mkdir, /* mkdir() method */
|
||||
HOG_dirClose /* dirClose() method */
|
||||
HOG_dirClose, /* dirClose() method */
|
||||
HOG_read, /* read() method */
|
||||
HOG_write, /* write() method */
|
||||
HOG_eof, /* eof() method */
|
||||
HOG_tell, /* tell() method */
|
||||
HOG_seek, /* seek() method */
|
||||
HOG_fileLength, /* fileLength() method */
|
||||
HOG_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void HOG_dirClose(void *opaque)
|
||||
static void HOG_dirClose(dvoid *opaque)
|
||||
{
|
||||
HOGinfo *info = ((HOGinfo *) opaque);
|
||||
free(info->filename);
|
||||
|
@ -150,10 +145,10 @@ static void HOG_dirClose(void *opaque)
|
|||
} /* HOG_dirClose */
|
||||
|
||||
|
||||
static PHYSFS_sint64 HOG_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 HOG_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) (handle->opaque);
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
||||
HOGentry *entry = finfo->entry;
|
||||
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
|
||||
PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
|
||||
|
@ -170,30 +165,30 @@ static PHYSFS_sint64 HOG_read(FileHandle *handle, void *buffer,
|
|||
} /* HOG_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 HOG_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 HOG_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* HOG_write */
|
||||
|
||||
|
||||
static int HOG_eof(FileHandle *handle)
|
||||
static int HOG_eof(fvoid *opaque)
|
||||
{
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) (handle->opaque);
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
||||
HOGentry *entry = finfo->entry;
|
||||
return(finfo->curPos >= entry->size);
|
||||
} /* HOG_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 HOG_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 HOG_tell(fvoid *opaque)
|
||||
{
|
||||
return(((HOGfileinfo *) (handle->opaque))->curPos);
|
||||
return(((HOGfileinfo *) opaque)->curPos);
|
||||
} /* HOG_tell */
|
||||
|
||||
|
||||
static int HOG_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int HOG_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) (handle->opaque);
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
||||
HOGentry *entry = finfo->entry;
|
||||
int rc;
|
||||
|
||||
|
@ -207,19 +202,18 @@ static int HOG_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* HOG_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 HOG_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 HOG_fileLength(fvoid *opaque)
|
||||
{
|
||||
HOGfileinfo *finfo = ((HOGfileinfo *) handle->opaque);
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
||||
return((PHYSFS_sint64) finfo->entry->size);
|
||||
} /* HOG_fileLength */
|
||||
|
||||
|
||||
static int HOG_fileClose(FileHandle *handle)
|
||||
static int HOG_fileClose(fvoid *opaque)
|
||||
{
|
||||
HOGfileinfo *finfo = ((HOGfileinfo *) handle->opaque);
|
||||
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* HOG_fileClose */
|
||||
|
||||
|
@ -404,7 +398,7 @@ HOG_openArchive_failed:
|
|||
} /* HOG_openArchive */
|
||||
|
||||
|
||||
static LinkedStringList *HOG_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *HOG_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
|
@ -457,27 +451,27 @@ static HOGentry *hog_find_entry(HOGinfo *info, const char *name)
|
|||
} /* hog_find_entry */
|
||||
|
||||
|
||||
static int HOG_exists(void *opaque, const char *name)
|
||||
static int HOG_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
return(hog_find_entry(((HOGinfo *) opaque), name) != NULL);
|
||||
} /* HOG_exists */
|
||||
|
||||
|
||||
static int HOG_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
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(void *opaque, const char *name, int *fileExists)
|
||||
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_sint64 HOG_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 HOG_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
|
@ -492,10 +486,9 @@ static PHYSFS_sint64 HOG_getLastModTime(void *opaque,
|
|||
} /* HOG_getLastModTime */
|
||||
|
||||
|
||||
static FileHandle *HOG_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
HOGinfo *info = ((HOGinfo *) opaque);
|
||||
FileHandle *retval;
|
||||
HOGfileinfo *finfo;
|
||||
HOGentry *entry;
|
||||
|
||||
|
@ -503,51 +496,42 @@ static FileHandle *HOG_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
*fileExists = (entry != NULL);
|
||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||
|
||||
retval = (FileHandle *) malloc(sizeof (FileHandle));
|
||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
finfo = (HOGfileinfo *) malloc(sizeof (HOGfileinfo));
|
||||
if (finfo == NULL)
|
||||
{
|
||||
free(retval);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
|
||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||
if ( (finfo->handle == NULL) ||
|
||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||
{
|
||||
free(finfo);
|
||||
free(retval);
|
||||
return(NULL);
|
||||
} /* if */
|
||||
|
||||
finfo->curPos = 0;
|
||||
finfo->entry = entry;
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_HOG;
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* HOG_openRead */
|
||||
|
||||
|
||||
static FileHandle *HOG_openWrite(void *opaque, const char *name)
|
||||
static fvoid *HOG_openWrite(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* HOG_openWrite */
|
||||
|
||||
|
||||
static FileHandle *HOG_openAppend(void *opaque, const char *name)
|
||||
static fvoid *HOG_openAppend(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* HOG_openAppend */
|
||||
|
||||
|
||||
static int HOG_remove(void *opaque, const char *name)
|
||||
static int HOG_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* HOG_remove */
|
||||
|
||||
|
||||
static int HOG_mkdir(void *opaque, const char *name)
|
||||
static int HOG_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* HOG_mkdir */
|
||||
|
|
128
archivers/mix.c
128
archivers/mix.c
|
@ -80,30 +80,30 @@ typedef struct
|
|||
void *handle; /* filehandle */
|
||||
} MIXfileinfo;
|
||||
|
||||
static void MIX_dirClose(void *opaque);
|
||||
static PHYSFS_sint64 MIX_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 MIX_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 MIX_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 MIX_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static int MIX_eof(FileHandle *handle);
|
||||
static PHYSFS_sint64 MIX_tell(FileHandle *handle);
|
||||
static int MIX_seek(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 MIX_fileLength(FileHandle *handle);
|
||||
static int MIX_fileClose(FileHandle *handle);
|
||||
static int MIX_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 MIX_tell(fvoid *opaque);
|
||||
static int MIX_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 MIX_fileLength(fvoid *opaque);
|
||||
static int MIX_fileClose(fvoid *opaque);
|
||||
static int MIX_isArchive(const char *filename, int forWriting);
|
||||
static void *MIX_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *MIX_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *MIX_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int MIX_exists(void *opaque, const char *name);
|
||||
static int MIX_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int MIX_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 MIX_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *MIX_openRead(void *opaque, const char *name, int *exist);
|
||||
static FileHandle *MIX_openWrite(void *opaque, const char *name);
|
||||
static FileHandle *MIX_openAppend(void *opaque, const char *name);
|
||||
static int MIX_remove(void *opaque, const char *name);
|
||||
static int MIX_mkdir(void *opaque, const char *name);
|
||||
static int MIX_exists(dvoid *opaque, const char *name);
|
||||
static int MIX_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int MIX_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 MIX_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *MIX_openRead(dvoid *opaque, const char *name, int *exist);
|
||||
static fvoid *MIX_openWrite(dvoid *opaque, const char *name);
|
||||
static fvoid *MIX_openAppend(dvoid *opaque, const char *name);
|
||||
static int MIX_remove(dvoid *opaque, const char *name);
|
||||
static int MIX_mkdir(dvoid *opaque, const char *name);
|
||||
static void MIX_dirClose(dvoid *opaque);
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MIX =
|
||||
{
|
||||
|
@ -114,19 +114,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MIX =
|
|||
};
|
||||
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_MIX =
|
||||
{
|
||||
MIX_read, /* read() method */
|
||||
MIX_write, /* write() method */
|
||||
MIX_eof, /* eof() method */
|
||||
MIX_tell, /* tell() method */
|
||||
MIX_seek, /* seek() method */
|
||||
MIX_fileLength, /* fileLength() method */
|
||||
MIX_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_MIX =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_MIX =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_MIX,
|
||||
MIX_isArchive, /* isArchive() method */
|
||||
|
@ -141,9 +129,17 @@ const DirFunctions __PHYSFS_DirFunctions_MIX =
|
|||
MIX_openAppend, /* openAppend() method */
|
||||
MIX_remove, /* remove() method */
|
||||
MIX_mkdir, /* mkdir() method */
|
||||
MIX_dirClose /* dirClose() method */
|
||||
MIX_dirClose, /* dirClose() method */
|
||||
MIX_read, /* read() method */
|
||||
MIX_write, /* write() method */
|
||||
MIX_eof, /* eof() method */
|
||||
MIX_tell, /* tell() method */
|
||||
MIX_seek, /* seek() method */
|
||||
MIX_fileLength, /* fileLength() method */
|
||||
MIX_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
static PHYSFS_uint32 MIX_hash(const char *name)
|
||||
{
|
||||
PHYSFS_uint32 id = 0;
|
||||
|
@ -176,7 +172,7 @@ static PHYSFS_uint32 MIX_hash(const char *name)
|
|||
} /* MIX_hash */
|
||||
|
||||
|
||||
static void MIX_dirClose(void *opaque)
|
||||
static void MIX_dirClose(dvoid *opaque)
|
||||
{
|
||||
MIXinfo *info = ((MIXinfo *) opaque);
|
||||
free(info->entry);
|
||||
|
@ -184,10 +180,10 @@ static void MIX_dirClose(void *opaque)
|
|||
} /* MIX_dirClose */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MIX_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 MIX_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
MIXfileinfo *finfo = (MIXfileinfo*)handle->opaque;
|
||||
MIXfileinfo *finfo = (MIXfileinfo *) opaque;
|
||||
MIXentry *entry = finfo->entry;
|
||||
PHYSFS_uint32 read;
|
||||
|
||||
|
@ -208,29 +204,29 @@ static PHYSFS_sint64 MIX_read(FileHandle *handle, void *buffer,
|
|||
} /* MIX_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MIX_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 MIX_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* MIX_write */
|
||||
|
||||
|
||||
static int MIX_eof(FileHandle *handle)
|
||||
static int MIX_eof(fvoid *opaque)
|
||||
{
|
||||
MIXfileinfo *fifo = (MIXfileinfo *) handle->opaque;
|
||||
MIXfileinfo *fifo = (MIXfileinfo *) opaque;
|
||||
return(fifo->cur_pos >= fifo->size);
|
||||
} /* MIX_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MIX_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 MIX_tell(fvoid *opaque)
|
||||
{
|
||||
return(((MIXfileinfo *) (handle->opaque))->cur_pos);
|
||||
return(((MIXfileinfo *) opaque)->cur_pos);
|
||||
} /* MIX_tell */
|
||||
|
||||
|
||||
static int MIX_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int MIX_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
MIXfileinfo *h = (MIXfileinfo *) (handle->opaque);
|
||||
MIXfileinfo *h = (MIXfileinfo *) opaque;
|
||||
|
||||
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
|
||||
BAIL_IF_MACRO(offset >= h->size, ERR_PAST_EOF, 0);
|
||||
|
@ -239,25 +235,24 @@ static int MIX_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* MIX_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MIX_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 MIX_fileLength(fvoid *opaque)
|
||||
{
|
||||
return (((MIXfileinfo *) (handle->opaque))->size);
|
||||
return (((MIXfileinfo *) opaque)->size);
|
||||
} /* MIX_fileLength */
|
||||
|
||||
|
||||
static int MIX_fileClose(FileHandle *handle)
|
||||
static int MIX_fileClose(fvoid *opaque)
|
||||
{
|
||||
MIXfileinfo *finfo = (MIXfileinfo *) handle->opaque;
|
||||
MIXfileinfo *finfo = (MIXfileinfo *) opaque;
|
||||
__PHYSFS_platformClose(finfo->handle);
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* MIX_fileClose */
|
||||
|
||||
|
||||
static int MIX_isArchive(const char *filename, int forWriting)
|
||||
{
|
||||
/* TODO:
|
||||
/* !!! FIXME:
|
||||
write a simple detection routine for MIX files.
|
||||
Unfortunaly MIX files have no ID in the header.
|
||||
*/
|
||||
|
@ -359,7 +354,7 @@ MIX_openArchive_failed:
|
|||
} /* MIX_openArchive */
|
||||
|
||||
|
||||
static LinkedStringList *MIX_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *MIX_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
|
@ -399,27 +394,27 @@ static MIXentry *MIX_find_entry(MIXinfo *info, const char *name)
|
|||
} /* MIX_find_entry */
|
||||
|
||||
|
||||
static int MIX_exists(void *opaque, const char *name)
|
||||
static int MIX_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
return(MIX_find_entry(((MIXinfo *) opaque), name) != NULL);
|
||||
} /* MIX_exists */
|
||||
|
||||
|
||||
static int MIX_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
static int MIX_isDirectory(dvoid *opaque, const char *name, int *fileExists)
|
||||
{
|
||||
*fileExists = MIX_exists(opaque, name);
|
||||
return(0); /* never directories in a MIX */
|
||||
} /* MIX_isDirectory */
|
||||
|
||||
|
||||
static int MIX_isSymLink(void *opaque, const char *name, int *fileExists)
|
||||
static int MIX_isSymLink(dvoid *opaque, const char *name, int *fileExists)
|
||||
{
|
||||
*fileExists = MIX_exists(opaque, name);
|
||||
return(0); /* never symlinks in a MIX. */
|
||||
} /* MIX_isSymLink */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MIX_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 MIX_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
|
@ -427,9 +422,8 @@ static PHYSFS_sint64 MIX_getLastModTime(void *opaque,
|
|||
} /* MIX_getLastModTime */
|
||||
|
||||
|
||||
static FileHandle *MIX_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *MIX_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
FileHandle *retval;
|
||||
MIXinfo *info = ((MIXinfo*) opaque);
|
||||
MIXfileinfo *finfo;
|
||||
MIXentry *entry;
|
||||
|
@ -441,56 +435,44 @@ static FileHandle *MIX_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
/* allocate a MIX handle */
|
||||
finfo = (MIXfileinfo *) malloc(sizeof (MIXfileinfo));
|
||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
|
||||
/* allocate a filehandle */
|
||||
retval = (FileHandle*) malloc(sizeof (FileHandle));
|
||||
if (!retval)
|
||||
{
|
||||
free(finfo);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
|
||||
/* open the archive */
|
||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||
if(!finfo->handle)
|
||||
{
|
||||
free(finfo);
|
||||
free(retval);
|
||||
return(NULL);
|
||||
};
|
||||
} /* if */
|
||||
|
||||
/* setup structures */
|
||||
finfo->cur_pos = 0;
|
||||
finfo->info = info;
|
||||
finfo->entry = entry;
|
||||
finfo->size = entry->end_offset - entry->start_offset;
|
||||
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_MIX;
|
||||
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* MIX_openRead */
|
||||
|
||||
|
||||
static FileHandle *MIX_openWrite(void *opaque, const char *name)
|
||||
static fvoid *MIX_openWrite(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* MIX_openWrite */
|
||||
|
||||
|
||||
static FileHandle *MIX_openAppend(void *opaque, const char *name)
|
||||
static fvoid *MIX_openAppend(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* MIX_openAppend */
|
||||
|
||||
|
||||
static int MIX_remove(void *opaque, const char *name)
|
||||
static int MIX_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* MIX_remove */
|
||||
|
||||
|
||||
static int MIX_mkdir(void *opaque, const char *name)
|
||||
static int MIX_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* MIX_mkdir */
|
||||
|
|
122
archivers/mvl.c
122
archivers/mvl.c
|
@ -64,30 +64,30 @@ typedef struct
|
|||
} MVLfileinfo;
|
||||
|
||||
|
||||
static void MVL_dirClose(void *opaque);
|
||||
static PHYSFS_sint64 MVL_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 MVL_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 MVL_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 MVL_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static int MVL_eof(FileHandle *handle);
|
||||
static PHYSFS_sint64 MVL_tell(FileHandle *handle);
|
||||
static int MVL_seek(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 MVL_fileLength(FileHandle *handle);
|
||||
static int MVL_fileClose(FileHandle *handle);
|
||||
static int MVL_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 MVL_tell(fvoid *opaque);
|
||||
static int MVL_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 MVL_fileLength(fvoid *opaque);
|
||||
static int MVL_fileClose(fvoid *opaque);
|
||||
static int MVL_isArchive(const char *filename, int forWriting);
|
||||
static void *MVL_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *MVL_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *MVL_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int MVL_exists(void *opaque, const char *name);
|
||||
static int MVL_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int MVL_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 MVL_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *MVL_openRead(void *opaque, const char *name, int *exist);
|
||||
static FileHandle *MVL_openWrite(void *opaque, const char *name);
|
||||
static FileHandle *MVL_openAppend(void *opaque, const char *name);
|
||||
static int MVL_remove(void *opaque, const char *name);
|
||||
static int MVL_mkdir(void *opaque, const char *name);
|
||||
static int MVL_exists(dvoid *opaque, const char *name);
|
||||
static int MVL_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int MVL_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 MVL_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *MVL_openRead(dvoid *opaque, const char *name, int *exist);
|
||||
static fvoid *MVL_openWrite(dvoid *opaque, const char *name);
|
||||
static fvoid *MVL_openAppend(dvoid *opaque, const char *name);
|
||||
static int MVL_remove(dvoid *opaque, const char *name);
|
||||
static int MVL_mkdir(dvoid *opaque, const char *name);
|
||||
static void MVL_dirClose(dvoid *opaque);
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL =
|
||||
{
|
||||
|
@ -98,19 +98,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL =
|
|||
};
|
||||
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_MVL =
|
||||
{
|
||||
MVL_read, /* read() method */
|
||||
MVL_write, /* write() method */
|
||||
MVL_eof, /* eof() method */
|
||||
MVL_tell, /* tell() method */
|
||||
MVL_seek, /* seek() method */
|
||||
MVL_fileLength, /* fileLength() method */
|
||||
MVL_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_MVL =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_MVL,
|
||||
MVL_isArchive, /* isArchive() method */
|
||||
|
@ -125,12 +113,19 @@ const DirFunctions __PHYSFS_DirFunctions_MVL =
|
|||
MVL_openAppend, /* openAppend() method */
|
||||
MVL_remove, /* remove() method */
|
||||
MVL_mkdir, /* mkdir() method */
|
||||
MVL_dirClose /* dirClose() method */
|
||||
MVL_dirClose, /* dirClose() method */
|
||||
MVL_read, /* read() method */
|
||||
MVL_write, /* write() method */
|
||||
MVL_eof, /* eof() method */
|
||||
MVL_tell, /* tell() method */
|
||||
MVL_seek, /* seek() method */
|
||||
MVL_fileLength, /* fileLength() method */
|
||||
MVL_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void MVL_dirClose(void *opaque)
|
||||
static void MVL_dirClose(dvoid *opaque)
|
||||
{
|
||||
MVLinfo *info = ((MVLinfo *) opaque);
|
||||
free(info->filename);
|
||||
|
@ -139,10 +134,10 @@ static void MVL_dirClose(void *opaque)
|
|||
} /* MVL_dirClose */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MVL_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 MVL_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) (handle->opaque);
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
||||
MVLentry *entry = finfo->entry;
|
||||
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
|
||||
PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
|
||||
|
@ -159,30 +154,30 @@ static PHYSFS_sint64 MVL_read(FileHandle *handle, void *buffer,
|
|||
} /* MVL_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MVL_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 MVL_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* MVL_write */
|
||||
|
||||
|
||||
static int MVL_eof(FileHandle *handle)
|
||||
static int MVL_eof(fvoid *opaque)
|
||||
{
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) (handle->opaque);
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
||||
MVLentry *entry = finfo->entry;
|
||||
return(finfo->curPos >= entry->size);
|
||||
} /* MVL_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MVL_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 MVL_tell(fvoid *opaque)
|
||||
{
|
||||
return(((MVLfileinfo *) (handle->opaque))->curPos);
|
||||
return(((MVLfileinfo *) opaque)->curPos);
|
||||
} /* MVL_tell */
|
||||
|
||||
|
||||
static int MVL_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int MVL_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) (handle->opaque);
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
||||
MVLentry *entry = finfo->entry;
|
||||
int rc;
|
||||
|
||||
|
@ -196,19 +191,18 @@ static int MVL_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* MVL_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 MVL_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 MVL_fileLength(fvoid *opaque)
|
||||
{
|
||||
MVLfileinfo *finfo = ((MVLfileinfo *) handle->opaque);
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
||||
return((PHYSFS_sint64) finfo->entry->size);
|
||||
} /* MVL_fileLength */
|
||||
|
||||
|
||||
static int MVL_fileClose(FileHandle *handle)
|
||||
static int MVL_fileClose(fvoid *opaque)
|
||||
{
|
||||
MVLfileinfo *finfo = ((MVLfileinfo *) handle->opaque);
|
||||
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* MVL_fileClose */
|
||||
|
||||
|
@ -362,7 +356,7 @@ MVL_openArchive_failed:
|
|||
} /* MVL_openArchive */
|
||||
|
||||
|
||||
static LinkedStringList *MVL_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *MVL_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
|
@ -415,27 +409,27 @@ static MVLentry *mvl_find_entry(MVLinfo *info, const char *name)
|
|||
} /* mvl_find_entry */
|
||||
|
||||
|
||||
static int MVL_exists(void *opaque, const char *name)
|
||||
static int MVL_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
return(mvl_find_entry(((MVLinfo *) opaque), name) != NULL);
|
||||
} /* MVL_exists */
|
||||
|
||||
|
||||
static int MVL_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
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(void *opaque, const char *name, int *fileExists)
|
||||
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_sint64 MVL_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 MVL_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
|
@ -450,10 +444,9 @@ static PHYSFS_sint64 MVL_getLastModTime(void *opaque,
|
|||
} /* MVL_getLastModTime */
|
||||
|
||||
|
||||
static FileHandle *MVL_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *MVL_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
MVLinfo *info = ((MVLinfo *) opaque);
|
||||
FileHandle *retval;
|
||||
MVLfileinfo *finfo;
|
||||
MVLentry *entry;
|
||||
|
||||
|
@ -461,51 +454,42 @@ static FileHandle *MVL_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
*fileExists = (entry != NULL);
|
||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||
|
||||
retval = (FileHandle *) malloc(sizeof (FileHandle));
|
||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
finfo = (MVLfileinfo *) malloc(sizeof (MVLfileinfo));
|
||||
if (finfo == NULL)
|
||||
{
|
||||
free(retval);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
|
||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||
if ( (finfo->handle == NULL) ||
|
||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||
{
|
||||
free(finfo);
|
||||
free(retval);
|
||||
return(NULL);
|
||||
} /* if */
|
||||
|
||||
finfo->curPos = 0;
|
||||
finfo->entry = entry;
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_MVL;
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* MVL_openRead */
|
||||
|
||||
|
||||
static FileHandle *MVL_openWrite(void *opaque, const char *name)
|
||||
static fvoid *MVL_openWrite(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* MVL_openWrite */
|
||||
|
||||
|
||||
static FileHandle *MVL_openAppend(void *opaque, const char *name)
|
||||
static fvoid *MVL_openAppend(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* MVL_openAppend */
|
||||
|
||||
|
||||
static int MVL_remove(void *opaque, const char *name)
|
||||
static int MVL_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* MVL_remove */
|
||||
|
||||
|
||||
static int MVL_mkdir(void *opaque, const char *name)
|
||||
static int MVL_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* MVL_mkdir */
|
||||
|
|
122
archivers/qpak.c
122
archivers/qpak.c
|
@ -78,30 +78,30 @@ typedef struct
|
|||
#define QPAK_SIGNATURE 0x4b434150 /* "PACK" in ASCII. */
|
||||
|
||||
|
||||
static void QPAK_dirClose(void *opaque);
|
||||
static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 QPAK_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 QPAK_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static int QPAK_eof(FileHandle *handle);
|
||||
static PHYSFS_sint64 QPAK_tell(FileHandle *handle);
|
||||
static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle);
|
||||
static int QPAK_fileClose(FileHandle *handle);
|
||||
static int QPAK_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 QPAK_tell(fvoid *opaque);
|
||||
static int QPAK_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 QPAK_fileLength(fvoid *opaque);
|
||||
static int QPAK_fileClose(fvoid *opaque);
|
||||
static int QPAK_isArchive(const char *filename, int forWriting);
|
||||
static void *QPAK_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *QPAK_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *QPAK_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int QPAK_exists(void *opaque, const char *name);
|
||||
static int QPAK_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int QPAK_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 QPAK_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *QPAK_openRead(void *opaque, const char *name, int *exist);
|
||||
static FileHandle *QPAK_openWrite(void *opaque, const char *name);
|
||||
static FileHandle *QPAK_openAppend(void *opaque, const char *name);
|
||||
static int QPAK_remove(void *opaque, const char *name);
|
||||
static int QPAK_mkdir(void *opaque, const char *name);
|
||||
static int QPAK_exists(dvoid *opaque, const char *name);
|
||||
static int QPAK_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int QPAK_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 QPAK_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *QPAK_openRead(dvoid *opaque, const char *name, int *exist);
|
||||
static fvoid *QPAK_openWrite(dvoid *opaque, const char *name);
|
||||
static fvoid *QPAK_openAppend(dvoid *opaque, const char *name);
|
||||
static int QPAK_remove(dvoid *opaque, const char *name);
|
||||
static int QPAK_mkdir(dvoid *opaque, const char *name);
|
||||
static void QPAK_dirClose(dvoid *opaque);
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
|
||||
{
|
||||
|
@ -112,19 +112,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
|
|||
};
|
||||
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_QPAK =
|
||||
{
|
||||
QPAK_read, /* read() method */
|
||||
QPAK_write, /* write() method */
|
||||
QPAK_eof, /* eof() method */
|
||||
QPAK_tell, /* tell() method */
|
||||
QPAK_seek, /* seek() method */
|
||||
QPAK_fileLength, /* fileLength() method */
|
||||
QPAK_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_QPAK =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_QPAK,
|
||||
QPAK_isArchive, /* isArchive() method */
|
||||
|
@ -139,12 +127,19 @@ const DirFunctions __PHYSFS_DirFunctions_QPAK =
|
|||
QPAK_openAppend, /* openAppend() method */
|
||||
QPAK_remove, /* remove() method */
|
||||
QPAK_mkdir, /* mkdir() method */
|
||||
QPAK_dirClose /* dirClose() method */
|
||||
QPAK_dirClose, /* dirClose() method */
|
||||
QPAK_read, /* read() method */
|
||||
QPAK_write, /* write() method */
|
||||
QPAK_eof, /* eof() method */
|
||||
QPAK_tell, /* tell() method */
|
||||
QPAK_seek, /* seek() method */
|
||||
QPAK_fileLength, /* fileLength() method */
|
||||
QPAK_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void QPAK_dirClose(void *opaque)
|
||||
static void QPAK_dirClose(dvoid *opaque)
|
||||
{
|
||||
QPAKinfo *info = ((QPAKinfo *) opaque);
|
||||
free(info->filename);
|
||||
|
@ -153,10 +148,10 @@ static void QPAK_dirClose(void *opaque)
|
|||
} /* QPAK_dirClose */
|
||||
|
||||
|
||||
static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 QPAK_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
||||
QPAKentry *entry = finfo->entry;
|
||||
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
|
||||
PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
|
||||
|
@ -173,30 +168,30 @@ static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
|
|||
} /* QPAK_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 QPAK_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* QPAK_write */
|
||||
|
||||
|
||||
static int QPAK_eof(FileHandle *handle)
|
||||
static int QPAK_eof(fvoid *opaque)
|
||||
{
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
||||
QPAKentry *entry = finfo->entry;
|
||||
return(finfo->curPos >= entry->size);
|
||||
} /* QPAK_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 QPAK_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 QPAK_tell(fvoid *opaque)
|
||||
{
|
||||
return(((QPAKfileinfo *) (handle->opaque))->curPos);
|
||||
return(((QPAKfileinfo *) opaque)->curPos);
|
||||
} /* QPAK_tell */
|
||||
|
||||
|
||||
static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int QPAK_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
||||
QPAKentry *entry = finfo->entry;
|
||||
int rc;
|
||||
|
||||
|
@ -210,19 +205,18 @@ static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* QPAK_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 QPAK_fileLength(fvoid *opaque)
|
||||
{
|
||||
QPAKfileinfo *finfo = ((QPAKfileinfo *) handle->opaque);
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
||||
return((PHYSFS_sint64) finfo->entry->size);
|
||||
} /* QPAK_fileLength */
|
||||
|
||||
|
||||
static int QPAK_fileClose(FileHandle *handle)
|
||||
static int QPAK_fileClose(fvoid *opaque)
|
||||
{
|
||||
QPAKfileinfo *finfo = ((QPAKfileinfo *) handle->opaque);
|
||||
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* QPAK_fileClose */
|
||||
|
||||
|
@ -449,7 +443,7 @@ static PHYSFS_sint32 qpak_find_start_of_dir(QPAKinfo *info, const char *path,
|
|||
} /* qpak_find_start_of_dir */
|
||||
|
||||
|
||||
static LinkedStringList *QPAK_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *QPAK_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
|
@ -544,7 +538,7 @@ static QPAKentry *qpak_find_entry(QPAKinfo *info, const char *path, int *isDir)
|
|||
} /* qpak_find_entry */
|
||||
|
||||
|
||||
static int QPAK_exists(void *opaque, const char *name)
|
||||
static int QPAK_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
int isDir;
|
||||
QPAKinfo *info = (QPAKinfo *) opaque;
|
||||
|
@ -553,7 +547,7 @@ static int QPAK_exists(void *opaque, const char *name)
|
|||
} /* QPAK_exists */
|
||||
|
||||
|
||||
static int QPAK_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
static int QPAK_isDirectory(dvoid *opaque, const char *name, int *fileExists)
|
||||
{
|
||||
QPAKinfo *info = (QPAKinfo *) opaque;
|
||||
int isDir;
|
||||
|
@ -567,14 +561,14 @@ static int QPAK_isDirectory(void *opaque, const char *name, int *fileExists)
|
|||
} /* QPAK_isDirectory */
|
||||
|
||||
|
||||
static int QPAK_isSymLink(void *opaque, const char *name, int *fileExists)
|
||||
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_sint64 QPAK_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 QPAK_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
|
@ -591,10 +585,9 @@ static PHYSFS_sint64 QPAK_getLastModTime(void *opaque,
|
|||
} /* QPAK_getLastModTime */
|
||||
|
||||
|
||||
static FileHandle *QPAK_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
QPAKinfo *info = ((QPAKinfo *) opaque);
|
||||
FileHandle *retval;
|
||||
QPAKfileinfo *finfo;
|
||||
QPAKentry *entry;
|
||||
int isDir;
|
||||
|
@ -604,51 +597,42 @@ static FileHandle *QPAK_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
|
||||
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
|
||||
|
||||
retval = (FileHandle *) malloc(sizeof (FileHandle));
|
||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
finfo = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo));
|
||||
if (finfo == NULL)
|
||||
{
|
||||
free(retval);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
|
||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||
if ( (finfo->handle == NULL) ||
|
||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||
{
|
||||
free(finfo);
|
||||
free(retval);
|
||||
return(NULL);
|
||||
} /* if */
|
||||
|
||||
finfo->curPos = 0;
|
||||
finfo->entry = entry;
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_QPAK;
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* QPAK_openRead */
|
||||
|
||||
|
||||
static FileHandle *QPAK_openWrite(void *opaque, const char *name)
|
||||
static fvoid *QPAK_openWrite(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* QPAK_openWrite */
|
||||
|
||||
|
||||
static FileHandle *QPAK_openAppend(void *opaque, const char *name)
|
||||
static fvoid *QPAK_openAppend(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* QPAK_openAppend */
|
||||
|
||||
|
||||
static int QPAK_remove(void *opaque, const char *name)
|
||||
static int QPAK_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* QPAK_remove */
|
||||
|
||||
|
||||
static int QPAK_mkdir(void *opaque, const char *name)
|
||||
static int QPAK_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* QPAK_mkdir */
|
||||
|
|
122
archivers/wad.c
122
archivers/wad.c
|
@ -80,30 +80,30 @@ typedef struct
|
|||
} WADfileinfo;
|
||||
|
||||
|
||||
static void WAD_dirClose(void *opaque);
|
||||
static PHYSFS_sint64 WAD_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 WAD_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 WAD_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 WAD_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static int WAD_eof(FileHandle *handle);
|
||||
static PHYSFS_sint64 WAD_tell(FileHandle *handle);
|
||||
static int WAD_seek(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 WAD_fileLength(FileHandle *handle);
|
||||
static int WAD_fileClose(FileHandle *handle);
|
||||
static int WAD_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 WAD_tell(fvoid *opaque);
|
||||
static int WAD_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 WAD_fileLength(fvoid *opaque);
|
||||
static int WAD_fileClose(fvoid *opaque);
|
||||
static int WAD_isArchive(const char *filename, int forWriting);
|
||||
static void *WAD_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *WAD_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *WAD_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int WAD_exists(void *opaque, const char *name);
|
||||
static int WAD_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int WAD_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 WAD_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *WAD_openRead(void *opaque, const char *name, int *exist);
|
||||
static FileHandle *WAD_openWrite(void *opaque, const char *name);
|
||||
static FileHandle *WAD_openAppend(void *opaque, const char *name);
|
||||
static int WAD_remove(void *opaque, const char *name);
|
||||
static int WAD_mkdir(void *opaque, const char *name);
|
||||
static int WAD_exists(dvoid *opaque, const char *name);
|
||||
static int WAD_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int WAD_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 WAD_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *WAD_openRead(dvoid *opaque, const char *name, int *exist);
|
||||
static fvoid *WAD_openWrite(dvoid *opaque, const char *name);
|
||||
static fvoid *WAD_openAppend(dvoid *opaque, const char *name);
|
||||
static int WAD_remove(dvoid *opaque, const char *name);
|
||||
static int WAD_mkdir(dvoid *opaque, const char *name);
|
||||
static void WAD_dirClose(dvoid *opaque);
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD =
|
||||
{
|
||||
|
@ -114,19 +114,7 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD =
|
|||
};
|
||||
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_WAD =
|
||||
{
|
||||
WAD_read, /* read() method */
|
||||
WAD_write, /* write() method */
|
||||
WAD_eof, /* eof() method */
|
||||
WAD_tell, /* tell() method */
|
||||
WAD_seek, /* seek() method */
|
||||
WAD_fileLength, /* fileLength() method */
|
||||
WAD_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_WAD =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_WAD,
|
||||
WAD_isArchive, /* isArchive() method */
|
||||
|
@ -141,12 +129,19 @@ const DirFunctions __PHYSFS_DirFunctions_WAD =
|
|||
WAD_openAppend, /* openAppend() method */
|
||||
WAD_remove, /* remove() method */
|
||||
WAD_mkdir, /* mkdir() method */
|
||||
WAD_dirClose /* dirClose() method */
|
||||
WAD_dirClose, /* dirClose() method */
|
||||
WAD_read, /* read() method */
|
||||
WAD_write, /* write() method */
|
||||
WAD_eof, /* eof() method */
|
||||
WAD_tell, /* tell() method */
|
||||
WAD_seek, /* seek() method */
|
||||
WAD_fileLength, /* fileLength() method */
|
||||
WAD_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void WAD_dirClose(void *opaque)
|
||||
static void WAD_dirClose(dvoid *opaque)
|
||||
{
|
||||
WADinfo *info = ((WADinfo *) opaque);
|
||||
free(info->filename);
|
||||
|
@ -155,10 +150,10 @@ static void WAD_dirClose(void *opaque)
|
|||
} /* WAD_dirClose */
|
||||
|
||||
|
||||
static PHYSFS_sint64 WAD_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 WAD_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
WADfileinfo *finfo = (WADfileinfo *) (handle->opaque);
|
||||
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
||||
WADentry *entry = finfo->entry;
|
||||
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
|
||||
PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
|
||||
|
@ -175,30 +170,30 @@ static PHYSFS_sint64 WAD_read(FileHandle *handle, void *buffer,
|
|||
} /* WAD_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 WAD_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 WAD_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* WAD_write */
|
||||
|
||||
|
||||
static int WAD_eof(FileHandle *handle)
|
||||
static int WAD_eof(fvoid *opaque)
|
||||
{
|
||||
WADfileinfo *finfo = (WADfileinfo *) (handle->opaque);
|
||||
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
||||
WADentry *entry = finfo->entry;
|
||||
return(finfo->curPos >= entry->size);
|
||||
} /* WAD_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 WAD_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 WAD_tell(fvoid *opaque)
|
||||
{
|
||||
return(((WADfileinfo *) (handle->opaque))->curPos);
|
||||
return(((WADfileinfo *) opaque)->curPos);
|
||||
} /* WAD_tell */
|
||||
|
||||
|
||||
static int WAD_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int WAD_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
WADfileinfo *finfo = (WADfileinfo *) (handle->opaque);
|
||||
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
||||
WADentry *entry = finfo->entry;
|
||||
int rc;
|
||||
|
||||
|
@ -212,19 +207,18 @@ static int WAD_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* WAD_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 WAD_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 WAD_fileLength(fvoid *opaque)
|
||||
{
|
||||
WADfileinfo *finfo = ((WADfileinfo *) handle->opaque);
|
||||
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
||||
return((PHYSFS_sint64) finfo->entry->size);
|
||||
} /* WAD_fileLength */
|
||||
|
||||
|
||||
static int WAD_fileClose(FileHandle *handle)
|
||||
static int WAD_fileClose(fvoid *opaque)
|
||||
{
|
||||
WADfileinfo *finfo = ((WADfileinfo *) handle->opaque);
|
||||
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* WAD_fileClose */
|
||||
|
||||
|
@ -392,7 +386,7 @@ WAD_openArchive_failed:
|
|||
} /* WAD_openArchive */
|
||||
|
||||
|
||||
static LinkedStringList *WAD_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *WAD_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
|
@ -458,13 +452,13 @@ static WADentry *wad_find_entry(WADinfo *info, const char *name)
|
|||
} /* wad_find_entry */
|
||||
|
||||
|
||||
static int WAD_exists(void *opaque, const char *name)
|
||||
static int WAD_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
return(wad_find_entry(((WADinfo *) opaque), name) != NULL);
|
||||
} /* WAD_exists */
|
||||
|
||||
|
||||
static int WAD_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
static int WAD_isDirectory(dvoid *opaque, const char *name, int *fileExists)
|
||||
{
|
||||
WADentry *entry = wad_find_entry(((WADinfo *) opaque), name);
|
||||
if (entry != NULL)
|
||||
|
@ -494,14 +488,14 @@ static int WAD_isDirectory(void *opaque, const char *name, int *fileExists)
|
|||
} /* WAD_isDirectory */
|
||||
|
||||
|
||||
static int WAD_isSymLink(void *opaque, const char *name, int *fileExists)
|
||||
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_sint64 WAD_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 WAD_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
|
@ -516,10 +510,9 @@ static PHYSFS_sint64 WAD_getLastModTime(void *opaque,
|
|||
} /* WAD_getLastModTime */
|
||||
|
||||
|
||||
static FileHandle *WAD_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *WAD_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
WADinfo *info = ((WADinfo *) opaque);
|
||||
FileHandle *retval;
|
||||
WADfileinfo *finfo;
|
||||
WADentry *entry;
|
||||
|
||||
|
@ -527,51 +520,42 @@ static FileHandle *WAD_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
*fileExists = (entry != NULL);
|
||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||
|
||||
retval = (FileHandle *) malloc(sizeof (FileHandle));
|
||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
finfo = (WADfileinfo *) malloc(sizeof (WADfileinfo));
|
||||
if (finfo == NULL)
|
||||
{
|
||||
free(retval);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||
|
||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||
if ( (finfo->handle == NULL) ||
|
||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||
{
|
||||
free(finfo);
|
||||
free(retval);
|
||||
return(NULL);
|
||||
} /* if */
|
||||
|
||||
finfo->curPos = 0;
|
||||
finfo->entry = entry;
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_WAD;
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* WAD_openRead */
|
||||
|
||||
|
||||
static FileHandle *WAD_openWrite(void *opaque, const char *name)
|
||||
static fvoid *WAD_openWrite(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* WAD_openWrite */
|
||||
|
||||
|
||||
static FileHandle *WAD_openAppend(void *opaque, const char *name)
|
||||
static fvoid *WAD_openAppend(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* WAD_openAppend */
|
||||
|
||||
|
||||
static int WAD_remove(void *opaque, const char *name)
|
||||
static int WAD_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* WAD_remove */
|
||||
|
||||
|
||||
static int WAD_mkdir(void *opaque, const char *name)
|
||||
static int WAD_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* WAD_mkdir */
|
||||
|
|
129
archivers/zip.c
129
archivers/zip.c
|
@ -116,31 +116,31 @@ typedef struct
|
|||
#define UNIX_FILETYPE_SYMLINK 0120000
|
||||
|
||||
|
||||
static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buffer,
|
||||
static PHYSFS_sint64 ZIP_read(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static PHYSFS_sint64 ZIP_write(FileHandle *handle, const void *buffer,
|
||||
static PHYSFS_sint64 ZIP_write(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
static int ZIP_eof(FileHandle *handle);
|
||||
static PHYSFS_sint64 ZIP_tell(FileHandle *handle);
|
||||
static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 ZIP_fileLength(FileHandle *handle);
|
||||
static int ZIP_fileClose(FileHandle *handle);
|
||||
static int ZIP_eof(fvoid *opaque);
|
||||
static PHYSFS_sint64 ZIP_tell(fvoid *opaque);
|
||||
static int ZIP_seek(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
static PHYSFS_sint64 ZIP_fileLength(fvoid *opaque);
|
||||
static int ZIP_fileClose(fvoid *opaque);
|
||||
static int ZIP_isArchive(const char *filename, int forWriting);
|
||||
static void *ZIP_openArchive(const char *name, int forWriting);
|
||||
static LinkedStringList *ZIP_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *ZIP_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
static int ZIP_exists(void *opaque, const char *name);
|
||||
static int ZIP_isDirectory(void *opaque, const char *name, int *fileExists);
|
||||
static int ZIP_isSymLink(void *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 ZIP_getLastModTime(void *opaque, const char *n, int *e);
|
||||
static FileHandle *ZIP_openRead(void *opaque, const char *filename, int *e);
|
||||
static FileHandle *ZIP_openWrite(void *opaque, const char *filename);
|
||||
static FileHandle *ZIP_openAppend(void *opaque, const char *filename);
|
||||
static void ZIP_dirClose(void *opaque);
|
||||
static int ZIP_exists(dvoid *opaque, const char *name);
|
||||
static int ZIP_isDirectory(dvoid *opaque, const char *name, int *fileExists);
|
||||
static int ZIP_isSymLink(dvoid *opaque, const char *name, int *fileExists);
|
||||
static PHYSFS_sint64 ZIP_getLastModTime(dvoid *opaque, const char *n, int *e);
|
||||
static fvoid *ZIP_openRead(dvoid *opaque, const char *filename, int *e);
|
||||
static fvoid *ZIP_openWrite(dvoid *opaque, const char *filename);
|
||||
static fvoid *ZIP_openAppend(dvoid *opaque, const char *filename);
|
||||
static void ZIP_dirClose(dvoid *opaque);
|
||||
static int zip_resolve(void *in, ZIPinfo *info, ZIPentry *entry);
|
||||
static int ZIP_remove(void *opaque, const char *name);
|
||||
static int ZIP_mkdir(void *opaque, const char *name);
|
||||
static int ZIP_remove(dvoid *opaque, const char *name);
|
||||
static int ZIP_mkdir(dvoid *opaque, const char *name);
|
||||
|
||||
|
||||
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP =
|
||||
|
@ -151,19 +151,8 @@ const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP =
|
|||
"http://icculus.org/physfs/",
|
||||
};
|
||||
|
||||
static const FileFunctions __PHYSFS_FileFunctions_ZIP =
|
||||
{
|
||||
ZIP_read, /* read() method */
|
||||
ZIP_write, /* write() method */
|
||||
ZIP_eof, /* eof() method */
|
||||
ZIP_tell, /* tell() method */
|
||||
ZIP_seek, /* seek() method */
|
||||
ZIP_fileLength, /* fileLength() method */
|
||||
ZIP_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
const DirFunctions __PHYSFS_DirFunctions_ZIP =
|
||||
const PHYSFS_Archiver __PHYSFS_Archiver_ZIP =
|
||||
{
|
||||
&__PHYSFS_ArchiveInfo_ZIP,
|
||||
ZIP_isArchive, /* isArchive() method */
|
||||
|
@ -178,7 +167,14 @@ const DirFunctions __PHYSFS_DirFunctions_ZIP =
|
|||
ZIP_openAppend, /* openAppend() method */
|
||||
ZIP_remove, /* remove() method */
|
||||
ZIP_mkdir, /* mkdir() method */
|
||||
ZIP_dirClose /* dirClose() method */
|
||||
ZIP_dirClose, /* dirClose() method */
|
||||
ZIP_read, /* read() method */
|
||||
ZIP_write, /* write() method */
|
||||
ZIP_eof, /* eof() method */
|
||||
ZIP_tell, /* tell() method */
|
||||
ZIP_seek, /* seek() method */
|
||||
ZIP_fileLength, /* fileLength() method */
|
||||
ZIP_fileClose /* fileClose() method */
|
||||
};
|
||||
|
||||
|
||||
|
@ -188,7 +184,7 @@ const DirFunctions __PHYSFS_DirFunctions_ZIP =
|
|||
*/
|
||||
static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
|
||||
{
|
||||
return(((PHYSFS_allocator *) opaque)->malloc(items * size));
|
||||
return(((PHYSFS_Allocator *) opaque)->malloc(items * size));
|
||||
} /* zlibPhysfsAlloc */
|
||||
|
||||
/*
|
||||
|
@ -196,7 +192,7 @@ static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
|
|||
*/
|
||||
static void zlibPhysfsFree(voidpf opaque, voidpf address)
|
||||
{
|
||||
((PHYSFS_allocator *) opaque)->free(address);
|
||||
((PHYSFS_Allocator *) opaque)->free(address);
|
||||
} /* zlibPhysfsFree */
|
||||
|
||||
|
||||
|
@ -269,10 +265,10 @@ static int readui16(void *in, PHYSFS_uint16 *val)
|
|||
} /* readui16 */
|
||||
|
||||
|
||||
static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buf,
|
||||
static PHYSFS_sint64 ZIP_read(fvoid *opaque, void *buf,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque);
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque;
|
||||
ZIPentry *entry = finfo->entry;
|
||||
PHYSFS_sint64 retval = 0;
|
||||
PHYSFS_sint64 maxread = ((PHYSFS_sint64) objSize) * objCount;
|
||||
|
@ -343,29 +339,29 @@ static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buf,
|
|||
} /* ZIP_read */
|
||||
|
||||
|
||||
static PHYSFS_sint64 ZIP_write(FileHandle *handle, const void *buf,
|
||||
static PHYSFS_sint64 ZIP_write(fvoid *opaque, const void *buf,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
|
||||
} /* ZIP_write */
|
||||
|
||||
|
||||
static int ZIP_eof(FileHandle *handle)
|
||||
static int ZIP_eof(fvoid *opaque)
|
||||
{
|
||||
ZIPfileinfo *finfo = ((ZIPfileinfo *) (handle->opaque));
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque;
|
||||
return(finfo->uncompressed_position >= finfo->entry->uncompressed_size);
|
||||
} /* ZIP_eof */
|
||||
|
||||
|
||||
static PHYSFS_sint64 ZIP_tell(FileHandle *handle)
|
||||
static PHYSFS_sint64 ZIP_tell(fvoid *opaque)
|
||||
{
|
||||
return(((ZIPfileinfo *) (handle->opaque))->uncompressed_position);
|
||||
return(((ZIPfileinfo *) opaque)->uncompressed_position);
|
||||
} /* ZIP_tell */
|
||||
|
||||
|
||||
static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
||||
static int ZIP_seek(fvoid *opaque, PHYSFS_uint64 offset)
|
||||
{
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque);
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque;
|
||||
ZIPentry *entry = finfo->entry;
|
||||
void *in = finfo->handle;
|
||||
|
||||
|
@ -411,7 +407,7 @@ static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
if (maxread > sizeof (buf))
|
||||
maxread = sizeof (buf);
|
||||
|
||||
if (ZIP_read(handle, buf, maxread, 1) != 1)
|
||||
if (ZIP_read(finfo, buf, maxread, 1) != 1)
|
||||
return(0);
|
||||
} /* while */
|
||||
} /* else */
|
||||
|
@ -420,16 +416,16 @@ static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset)
|
|||
} /* ZIP_seek */
|
||||
|
||||
|
||||
static PHYSFS_sint64 ZIP_fileLength(FileHandle *handle)
|
||||
static PHYSFS_sint64 ZIP_fileLength(fvoid *opaque)
|
||||
{
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque);
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque;
|
||||
return(finfo->entry->uncompressed_size);
|
||||
} /* ZIP_fileLength */
|
||||
|
||||
|
||||
static int ZIP_fileClose(FileHandle *handle)
|
||||
static int ZIP_fileClose(fvoid *opaque)
|
||||
{
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque);
|
||||
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque;
|
||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||
|
||||
if (finfo->entry->compression_method != COMPMETH_NONE)
|
||||
|
@ -439,7 +435,6 @@ static int ZIP_fileClose(FileHandle *handle)
|
|||
free(finfo->buffer);
|
||||
|
||||
free(finfo);
|
||||
free(handle);
|
||||
return(1);
|
||||
} /* ZIP_fileClose */
|
||||
|
||||
|
@ -1240,7 +1235,7 @@ static PHYSFS_sint32 zip_find_start_of_dir(ZIPinfo *info, const char *path,
|
|||
} /* zip_find_start_of_dir */
|
||||
|
||||
|
||||
static LinkedStringList *ZIP_enumerateFiles(void *opaque,
|
||||
static LinkedStringList *ZIP_enumerateFiles(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks)
|
||||
{
|
||||
|
@ -1287,7 +1282,7 @@ static LinkedStringList *ZIP_enumerateFiles(void *opaque,
|
|||
} /* ZIP_enumerateFiles */
|
||||
|
||||
|
||||
static int ZIP_exists(void *opaque, const char *name)
|
||||
static int ZIP_exists(dvoid *opaque, const char *name)
|
||||
{
|
||||
int isDir;
|
||||
ZIPinfo *info = (ZIPinfo *) opaque;
|
||||
|
@ -1296,7 +1291,7 @@ static int ZIP_exists(void *opaque, const char *name)
|
|||
} /* ZIP_exists */
|
||||
|
||||
|
||||
static PHYSFS_sint64 ZIP_getLastModTime(void *opaque,
|
||||
static PHYSFS_sint64 ZIP_getLastModTime(dvoid *opaque,
|
||||
const char *name,
|
||||
int *fileExists)
|
||||
{
|
||||
|
@ -1313,7 +1308,7 @@ static PHYSFS_sint64 ZIP_getLastModTime(void *opaque,
|
|||
} /* ZIP_getLastModTime */
|
||||
|
||||
|
||||
static int ZIP_isDirectory(void *opaque, const char *name, int *fileExists)
|
||||
static int ZIP_isDirectory(dvoid *opaque, const char *name, int *fileExists)
|
||||
{
|
||||
ZIPinfo *info = (ZIPinfo *) opaque;
|
||||
int isDir;
|
||||
|
@ -1344,7 +1339,7 @@ static int ZIP_isDirectory(void *opaque, const char *name, int *fileExists)
|
|||
} /* ZIP_isDirectory */
|
||||
|
||||
|
||||
static int ZIP_isSymLink(void *opaque, const char *name, int *fileExists)
|
||||
static int ZIP_isSymLink(dvoid *opaque, const char *name, int *fileExists)
|
||||
{
|
||||
int isDir;
|
||||
ZIPentry *entry = zip_find_entry((ZIPinfo *) opaque, name, &isDir);
|
||||
|
@ -1378,11 +1373,10 @@ static void *zip_get_file_handle(const char *fn, ZIPinfo *inf, ZIPentry *entry)
|
|||
} /* zip_get_file_handle */
|
||||
|
||||
|
||||
static FileHandle *ZIP_openRead(void *opaque, const char *fnm, int *fileExists)
|
||||
static fvoid *ZIP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||
{
|
||||
ZIPinfo *info = (ZIPinfo *) opaque;
|
||||
ZIPentry *entry = zip_find_entry(info, fnm, NULL);
|
||||
FileHandle *retval = NULL;
|
||||
ZIPfileinfo *finfo = NULL;
|
||||
void *in;
|
||||
|
||||
|
@ -1392,18 +1386,13 @@ static FileHandle *ZIP_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
in = zip_get_file_handle(info->archiveName, info, entry);
|
||||
BAIL_IF_MACRO(in == NULL, NULL, NULL);
|
||||
|
||||
if ( ((retval = (FileHandle *) malloc(sizeof (FileHandle))) == NULL) ||
|
||||
((finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo))) == NULL) )
|
||||
finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo));
|
||||
if (finfo == NULL)
|
||||
{
|
||||
if (retval)
|
||||
free(retval);
|
||||
__PHYSFS_platformClose(in);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
|
||||
retval->opaque = (void *) finfo;
|
||||
retval->funcs = &__PHYSFS_FileFunctions_ZIP;
|
||||
|
||||
memset(finfo, '\0', sizeof (ZIPfileinfo));
|
||||
finfo->handle = in;
|
||||
finfo->entry = ((entry->symlink != NULL) ? entry->symlink : entry);
|
||||
|
@ -1412,35 +1401,35 @@ static FileHandle *ZIP_openRead(void *opaque, const char *fnm, int *fileExists)
|
|||
{
|
||||
if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK)
|
||||
{
|
||||
ZIP_fileClose(retval);
|
||||
ZIP_fileClose(finfo);
|
||||
return(NULL);
|
||||
} /* if */
|
||||
|
||||
finfo->buffer = (PHYSFS_uint8 *) malloc(ZIP_READBUFSIZE);
|
||||
if (finfo->buffer == NULL)
|
||||
{
|
||||
ZIP_fileClose(retval);
|
||||
ZIP_fileClose(finfo);
|
||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||
} /* if */
|
||||
} /* if */
|
||||
|
||||
return(retval);
|
||||
return(finfo);
|
||||
} /* ZIP_openRead */
|
||||
|
||||
|
||||
static FileHandle *ZIP_openWrite(void *opaque, const char *filename)
|
||||
static fvoid *ZIP_openWrite(dvoid *opaque, const char *filename)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* ZIP_openWrite */
|
||||
|
||||
|
||||
static FileHandle *ZIP_openAppend(void *opaque, const char *filename)
|
||||
static fvoid *ZIP_openAppend(dvoid *opaque, const char *filename)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
|
||||
} /* ZIP_openAppend */
|
||||
|
||||
|
||||
static void ZIP_dirClose(void *opaque)
|
||||
static void ZIP_dirClose(dvoid *opaque)
|
||||
{
|
||||
ZIPinfo *zi = (ZIPinfo *) (opaque);
|
||||
zip_free_entries(zi->entries, zi->entryCount);
|
||||
|
@ -1449,13 +1438,13 @@ static void ZIP_dirClose(void *opaque)
|
|||
} /* ZIP_dirClose */
|
||||
|
||||
|
||||
static int ZIP_remove(void *opaque, const char *name)
|
||||
static int ZIP_remove(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* ZIP_remove */
|
||||
|
||||
|
||||
static int ZIP_mkdir(void *opaque, const char *name)
|
||||
static int ZIP_mkdir(dvoid *opaque, const char *name)
|
||||
{
|
||||
BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
|
||||
} /* ZIP_mkdir */
|
||||
|
|
6
physfs.h
6
physfs.h
|
@ -1842,11 +1842,11 @@ typedef struct
|
|||
void *(*malloc)(size_t);
|
||||
void *(*realloc)(void *, size_t);
|
||||
void (*free)(void *);
|
||||
} PHYSFS_allocator;
|
||||
} PHYSFS_Allocator;
|
||||
|
||||
|
||||
/**
|
||||
* \fn int PHYSFS_setAllocator(PHYSFS_allocator *allocator)
|
||||
* \fn int PHYSFS_setAllocator(PHYSFS_Allocator *allocator)
|
||||
* \brief Hook your own allocation routines into PhysicsFS.
|
||||
*
|
||||
* (This is for limited, hardcore use. If you don't immediately see a need
|
||||
|
@ -1870,7 +1870,7 @@ typedef struct
|
|||
* \return zero on failure, non-zero on success. This call only fails
|
||||
* when used between PHYSFS_init() and PHYSFS_deinit() calls.
|
||||
*/
|
||||
__EXPORT__ int PHYSFS_setAllocator(PHYSFS_allocator *allocator);
|
||||
__EXPORT__ int PHYSFS_setAllocator(PHYSFS_Allocator *allocator);
|
||||
|
||||
|
||||
/* Everything above this line is part of the PhysicsFS 2.0 API. */
|
||||
|
|
|
@ -931,113 +931,32 @@ typedef struct __PHYSFS_LINKEDSTRINGLIST__
|
|||
} LinkedStringList;
|
||||
|
||||
|
||||
typedef struct __PHYSFS_FILEHANDLE__
|
||||
/* !!! FIXME: find something better than "dvoid" and "fvoid" ... */
|
||||
/* Opaque data for file and dir handlers... */
|
||||
typedef void dvoid;
|
||||
typedef void fvoid;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*
|
||||
* This is reserved for the driver to store information.
|
||||
* Basic info about this archiver...
|
||||
*/
|
||||
void *opaque;
|
||||
|
||||
/*
|
||||
* Non-zero if file opened for reading, zero if write/append.
|
||||
*/
|
||||
PHYSFS_uint8 forReading;
|
||||
|
||||
/*
|
||||
* This is the buffer, if one is set (NULL otherwise). Don't touch.
|
||||
*/
|
||||
PHYSFS_uint8 *buffer;
|
||||
|
||||
/*
|
||||
* This is the buffer size, if one is set (0 otherwise). Don't touch.
|
||||
*/
|
||||
PHYSFS_uint32 bufsize;
|
||||
|
||||
/*
|
||||
* This is the buffer fill size. Don't touch.
|
||||
*/
|
||||
PHYSFS_uint32 buffill;
|
||||
|
||||
/*
|
||||
* This is the buffer position. Don't touch.
|
||||
*/
|
||||
PHYSFS_uint32 bufpos;
|
||||
|
||||
/*
|
||||
* This should be the DirHandle that created this FileHandle.
|
||||
*/
|
||||
const struct __PHYSFS_DIRHANDLE__ *dirHandle;
|
||||
|
||||
/*
|
||||
* Pointer to the file i/o functions for this filehandle.
|
||||
*/
|
||||
const struct __PHYSFS_FILEFUNCTIONS__ *funcs;
|
||||
} FileHandle;
|
||||
|
||||
|
||||
typedef struct __PHYSFS_FILEFUNCTIONS__
|
||||
{
|
||||
/*
|
||||
* Read more from the file.
|
||||
* Returns number of objects of (objSize) bytes read from file, -1
|
||||
* if complete failure.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
PHYSFS_sint64 (*read)(FileHandle *handle, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
|
||||
/*
|
||||
* Write more to the file. Archives don't have to implement this.
|
||||
* (Set it to NULL if not implemented).
|
||||
* Returns number of objects of (objSize) bytes written to file, -1
|
||||
* if complete failure.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
PHYSFS_sint64 (*write)(FileHandle *handle, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
|
||||
/*
|
||||
* Returns non-zero if at end of file.
|
||||
*/
|
||||
int (*eof)(FileHandle *handle);
|
||||
|
||||
/*
|
||||
* Returns byte offset from start of file.
|
||||
*/
|
||||
PHYSFS_sint64 (*tell)(FileHandle *handle);
|
||||
|
||||
/*
|
||||
* Move read/write pointer to byte offset from start of file.
|
||||
* Returns non-zero on success, zero on error.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
int (*seek)(FileHandle *handle, PHYSFS_uint64 offset);
|
||||
|
||||
/*
|
||||
* Return number of bytes available in the file, or -1 if you
|
||||
* aren't able to determine.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
PHYSFS_sint64 (*fileLength)(FileHandle *handle);
|
||||
|
||||
/*
|
||||
* Close the file, and free the FileHandle structure (including "opaque").
|
||||
* returns non-zero on success, zero if can't close file.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
int (*fileClose)(FileHandle *handle);
|
||||
} FileFunctions;
|
||||
|
||||
|
||||
/*
|
||||
* Symlinks should always be followed; PhysicsFS will use
|
||||
* DirFunctions->isSymLink() and make a judgement on whether to
|
||||
* continue to call other methods based on that.
|
||||
*/
|
||||
typedef struct __PHYSFS_DIRFUNCTIONS__
|
||||
{
|
||||
const PHYSFS_ArchiveInfo *info;
|
||||
|
||||
|
||||
/*
|
||||
* DIRECTORY ROUTINES:
|
||||
* These functions are for dir handles. Generate a handle with the
|
||||
* openArchive() method, then pass it as the "opaque" dvoid to the
|
||||
* others.
|
||||
*
|
||||
* Symlinks should always be followed; PhysicsFS will use the
|
||||
* isSymLink() method and make a judgement on whether to
|
||||
* 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
|
||||
|
@ -1067,7 +986,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* If you have a memory failure, return as much as you can.
|
||||
* This dirname is in platform-independent notation.
|
||||
*/
|
||||
LinkedStringList *(*enumerateFiles)(void *opaque,
|
||||
LinkedStringList *(*enumerateFiles)(dvoid *opaque,
|
||||
const char *dirname,
|
||||
int omitSymLinks);
|
||||
|
||||
|
@ -1077,7 +996,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* This filename is in platform-independent notation.
|
||||
* You should not follow symlinks.
|
||||
*/
|
||||
int (*exists)(void *opaque, const char *name);
|
||||
int (*exists)(dvoid *opaque, const char *name);
|
||||
|
||||
/*
|
||||
* Returns non-zero if filename is really a directory.
|
||||
|
@ -1089,7 +1008,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* non-zero if the file existed (even if it's a broken symlink!),
|
||||
* zero if it did not.
|
||||
*/
|
||||
int (*isDirectory)(void *opaque, const char *name, int *fileExists);
|
||||
int (*isDirectory)(dvoid *opaque, const char *name, int *fileExists);
|
||||
|
||||
/*
|
||||
* Returns non-zero if filename is really a symlink.
|
||||
|
@ -1099,7 +1018,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* non-zero if the file existed (even if it's a broken symlink!),
|
||||
* zero if it did not.
|
||||
*/
|
||||
int (*isSymLink)(void *opaque, const char *name, int *fileExists);
|
||||
int (*isSymLink)(dvoid *opaque, const char *name, int *fileExists);
|
||||
|
||||
/*
|
||||
* Retrieve the last modification time (mtime) of a file.
|
||||
|
@ -1111,46 +1030,50 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* non-zero if the file existed (even if it's a broken symlink!),
|
||||
* zero if it did not.
|
||||
*/
|
||||
PHYSFS_sint64 (*getLastModTime)(void *opaque, const char *fnm, int *exist);
|
||||
PHYSFS_sint64 (*getLastModTime)(dvoid *opaque, const char *fnm, int *exist);
|
||||
|
||||
/*
|
||||
* Open file for reading, and return a FileHandle.
|
||||
* Open file for reading.
|
||||
* This filename is in platform-independent notation.
|
||||
* If you can't handle multiple opens of the same file,
|
||||
* you can opt to fail for the second call.
|
||||
* Fail if the file does not exist.
|
||||
* Returns NULL on failure, and calls __PHYSFS_setError().
|
||||
* 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 *fileExists to
|
||||
* non-zero if the file existed (even if it's a broken symlink!),
|
||||
* zero if it did not.
|
||||
*/
|
||||
FileHandle *(*openRead)(void *opaque, const char *fname, int *fileExists);
|
||||
fvoid *(*openRead)(dvoid *opaque, const char *fname, int *fileExists);
|
||||
|
||||
/*
|
||||
* Open file for writing, and return a FileHandle.
|
||||
* Open file for writing.
|
||||
* If the file does not exist, it should be created. If it exists,
|
||||
* it should be truncated to zero bytes. The writing
|
||||
* offset should be the start of the file.
|
||||
* This filename is in platform-independent notation.
|
||||
* This method may be NULL.
|
||||
* If you can't handle multiple opens of the same file,
|
||||
* you can opt to fail for the second call.
|
||||
* Returns NULL on failure, and calls __PHYSFS_setError().
|
||||
* Returns non-NULL on success. The pointer returned will be
|
||||
* passed as the "opaque" parameter for later file calls.
|
||||
*/
|
||||
FileHandle *(*openWrite)(void *opaque, const char *filename);
|
||||
fvoid *(*openWrite)(dvoid *opaque, const char *filename);
|
||||
|
||||
/*
|
||||
* Open file for appending, and return a FileHandle.
|
||||
* Open file for appending.
|
||||
* If the file does not exist, it should be created. The writing
|
||||
* offset should be the end of the file.
|
||||
* This filename is in platform-independent notation.
|
||||
* This method may be NULL.
|
||||
* If you can't handle multiple opens of the same file,
|
||||
* you can opt to fail for the second call.
|
||||
* Returns NULL on failure, and calls __PHYSFS_setError().
|
||||
* Returns non-NULL on success. The pointer returned will be
|
||||
* passed as the "opaque" parameter for later file calls.
|
||||
*/
|
||||
FileHandle *(*openAppend)(void *opaque, const char *filename);
|
||||
fvoid *(*openAppend)(dvoid *opaque, const char *filename);
|
||||
|
||||
/*
|
||||
* Delete a file in the archive/directory.
|
||||
|
@ -1159,7 +1082,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* This method may be NULL.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
int (*remove)(void *opaque, const char *filename);
|
||||
int (*remove)(dvoid *opaque, const char *filename);
|
||||
|
||||
/*
|
||||
* Create a directory in the archive/directory.
|
||||
|
@ -1171,7 +1094,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* This method may be NULL.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
int (*mkdir)(void *opaque, const char *filename);
|
||||
int (*mkdir)(dvoid *opaque, const char *filename);
|
||||
|
||||
/*
|
||||
* Close directories/archives, and free any associated memory,
|
||||
|
@ -1179,8 +1102,67 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
|
|||
* that it won't be called if there are still files open from
|
||||
* this archive.
|
||||
*/
|
||||
void (*dirClose)(void *opaque);
|
||||
} DirFunctions;
|
||||
void (*dirClose)(dvoid *opaque);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* FILE ROUTINES:
|
||||
* These functions are for file handles generated by the open*() methods.
|
||||
* They are distinguished by taking a "fvoid" instead of a "dvoid" for
|
||||
* the opaque handle.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Read more from the file.
|
||||
* Returns number of objects of (objSize) bytes read from file, -1
|
||||
* if complete failure.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
PHYSFS_sint64 (*read)(fvoid *opaque, void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
|
||||
/*
|
||||
* Write more to the file. Archives don't have to implement this.
|
||||
* (Set it to NULL if not implemented).
|
||||
* Returns number of objects of (objSize) bytes written to file, -1
|
||||
* if complete failure.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
PHYSFS_sint64 (*write)(fvoid *opaque, const void *buffer,
|
||||
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
|
||||
|
||||
/*
|
||||
* Returns non-zero if at end of file.
|
||||
*/
|
||||
int (*eof)(fvoid *opaque);
|
||||
|
||||
/*
|
||||
* Returns byte offset from start of file.
|
||||
*/
|
||||
PHYSFS_sint64 (*tell)(fvoid *opaque);
|
||||
|
||||
/*
|
||||
* Move read/write pointer to byte offset from start of file.
|
||||
* Returns non-zero on success, zero on error.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
int (*seek)(fvoid *opaque, PHYSFS_uint64 offset);
|
||||
|
||||
/*
|
||||
* Return number of bytes available in the file, or -1 if you
|
||||
* aren't able to determine.
|
||||
* On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
PHYSFS_sint64 (*fileLength)(fvoid *opaque);
|
||||
|
||||
/*
|
||||
* Close the file, and free associated resources, including (opaque)
|
||||
* if applicable. Returns non-zero on success, zero if can't close
|
||||
* file. On failure, call __PHYSFS_setError().
|
||||
*/
|
||||
int (*fileClose)(fvoid *opaque);
|
||||
} PHYSFS_Archiver;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -1272,7 +1254,7 @@ void __PHYSFS_sort(void *entries, PHYSFS_uint32 max,
|
|||
/*
|
||||
* Get the current allocator. Not valid before PHYSFS_init is called!
|
||||
*/
|
||||
PHYSFS_allocator *__PHYSFS_getAllocator(void);
|
||||
PHYSFS_Allocator *__PHYSFS_getAllocator(void);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -1571,9 +1553,9 @@ void __PHYSFS_platformTimeslice(void);
|
|||
|
||||
/*
|
||||
* Enumerate a directory of files. This follows the rules for the
|
||||
* DirFunctions->enumerateFiles() method (see above), except that the
|
||||
* PHYSFS_Archiver->enumerateFiles() method (see above), except that the
|
||||
* (dirName) that is passed to this function is converted to
|
||||
* platform-DEPENDENT notation by the caller. The DirFunctions version
|
||||
* platform-DEPENDENT notation by the caller. The PHYSFS_Archiver version
|
||||
* uses platform-independent notation. Note that ".", "..", and other
|
||||
* metaentries should always be ignored.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue