archivers/hog.c
changeset 691 71d9affe0d8a
parent 678 73a2641375a0
child 754 e7cd7411eadf
equal deleted inserted replaced
690:c34d1027aad0 691:71d9affe0d8a
    76 
    76 
    77 
    77 
    78 static void HOG_dirClose(dvoid *opaque)
    78 static void HOG_dirClose(dvoid *opaque)
    79 {
    79 {
    80     HOGinfo *info = ((HOGinfo *) opaque);
    80     HOGinfo *info = ((HOGinfo *) opaque);
    81     free(info->filename);
    81     allocator.Free(info->filename);
    82     free(info->entries);
    82     allocator.Free(info->entries);
    83     free(info);
    83     allocator.Free(info);
    84 } /* HOG_dirClose */
    84 } /* HOG_dirClose */
    85 
    85 
    86 
    86 
    87 static PHYSFS_sint64 HOG_read(fvoid *opaque, void *buffer,
    87 static PHYSFS_sint64 HOG_read(fvoid *opaque, void *buffer,
    88                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
    88                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
   150 
   150 
   151 static int HOG_fileClose(fvoid *opaque)
   151 static int HOG_fileClose(fvoid *opaque)
   152 {
   152 {
   153     HOGfileinfo *finfo = (HOGfileinfo *) opaque;
   153     HOGfileinfo *finfo = (HOGfileinfo *) opaque;
   154     BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
   154     BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
   155     free(finfo);
   155     allocator.Free(finfo);
   156     return(1);
   156     return(1);
   157 } /* HOG_fileClose */
   157 } /* HOG_fileClose */
   158 
   158 
   159 
   159 
   160 static int hog_open(const char *filename, int forWriting,
   160 static int hog_open(const char *filename, int forWriting,
   254     PHYSFS_uint32 fileCount;
   254     PHYSFS_uint32 fileCount;
   255     HOGentry *entry;
   255     HOGentry *entry;
   256 
   256 
   257     BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
   257     BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
   258     info->entryCount = fileCount;
   258     info->entryCount = fileCount;
   259     info->entries = (HOGentry *) malloc(sizeof (HOGentry) * fileCount);
   259     info->entries = (HOGentry *) allocator.Malloc(sizeof(HOGentry)*fileCount);
   260     if (info->entries == NULL)
   260     if (info->entries == NULL)
   261     {
   261     {
   262         __PHYSFS_platformClose(fh);
   262         __PHYSFS_platformClose(fh);
   263         BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
   263         BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
   264     } /* if */
   264     } /* if */
   302 
   302 
   303 
   303 
   304 static void *HOG_openArchive(const char *name, int forWriting)
   304 static void *HOG_openArchive(const char *name, int forWriting)
   305 {
   305 {
   306     PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
   306     PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
   307     HOGinfo *info = malloc(sizeof (HOGinfo));
   307     HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));
   308 
   308 
   309     BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
   309     BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
   310     memset(info, '\0', sizeof (HOGinfo));
   310     memset(info, '\0', sizeof (HOGinfo));
   311     info->filename = (char *) malloc(strlen(name) + 1);
   311     info->filename = (char *) allocator.Malloc(strlen(name) + 1);
   312     GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
   312     GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
   313 
   313 
   314     if (!hog_load_entries(name, forWriting, info))
   314     if (!hog_load_entries(name, forWriting, info))
   315         goto HOG_openArchive_failed;
   315         goto HOG_openArchive_failed;
   316 
   316 
   321 
   321 
   322 HOG_openArchive_failed:
   322 HOG_openArchive_failed:
   323     if (info != NULL)
   323     if (info != NULL)
   324     {
   324     {
   325         if (info->filename != NULL)
   325         if (info->filename != NULL)
   326             free(info->filename);
   326             allocator.Free(info->filename);
   327         if (info->entries != NULL)
   327         if (info->entries != NULL)
   328             free(info->entries);
   328             allocator.Free(info->entries);
   329         free(info);
   329         allocator.Free(info);
   330     } /* if */
   330     } /* if */
   331 
   331 
   332     return(NULL);
   332     return(NULL);
   333 } /* HOG_openArchive */
   333 } /* HOG_openArchive */
   334 
   334 
   427 
   427 
   428     entry = hog_find_entry(info, fnm);
   428     entry = hog_find_entry(info, fnm);
   429     *fileExists = (entry != NULL);
   429     *fileExists = (entry != NULL);
   430     BAIL_IF_MACRO(entry == NULL, NULL, NULL);
   430     BAIL_IF_MACRO(entry == NULL, NULL, NULL);
   431 
   431 
   432     finfo = (HOGfileinfo *) malloc(sizeof (HOGfileinfo));
   432     finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo));
   433     BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
   433     BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
   434 
   434 
   435     finfo->handle = __PHYSFS_platformOpenRead(info->filename);
   435     finfo->handle = __PHYSFS_platformOpenRead(info->filename);
   436     if ( (finfo->handle == NULL) ||
   436     if ( (finfo->handle == NULL) ||
   437          (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
   437          (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
   438     {
   438     {
   439         free(finfo);
   439         allocator.Free(finfo);
   440         return(NULL);
   440         return(NULL);
   441     } /* if */
   441     } /* if */
   442 
   442 
   443     finfo->curPos = 0;
   443     finfo->curPos = 0;
   444     finfo->entry = entry;
   444     finfo->entry = entry;