archivers/hog.c
changeset 650 298b8bb26775
parent 648 5c993684b8f2
child 657 dad3b5c307a9
--- a/archivers/hog.c	Sun Sep 26 12:56:23 2004 +0000
+++ b/archivers/hog.c	Sun Sep 26 13:00:59 2004 +0000
@@ -75,30 +75,30 @@
 } 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 @@
 };
 
 
-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 @@
     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 @@
 } /* 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 @@
 } /* 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 @@
 } /* 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 */
 
 
-static LinkedStringList *HOG_enumerateFiles(void *opaque,
+static LinkedStringList *HOG_enumerateFiles(dvoid *opaque,
                                             const char *dirname,
                                             int omitSymLinks)
 {
@@ -457,27 +451,27 @@
 } /* 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 @@
 } /* 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 @@
     *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 */