コード例 #1
0
ファイル: dir.c プロジェクト: Gokulakrishnansr/cdogs-sdl
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(opaque), NULL, 0);
    BAIL_IF_MACRO(!__PHYSFS_platformClose(opaque), NULL, 0);
    return(1);
} /* DIR_fileClose */
コード例 #2
0
ファイル: lzma.c プロジェクト: EgoIncarnate/Infinity
static void *LZMA_openArchive(const char *name, int forWriting)
{
    PHYSFS_uint64 len;
    LZMAarchive *archive = NULL;
    ISzAlloc allocImp;
    ISzAlloc allocTempImp;

    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
    BAIL_IF_MACRO(!LZMA_isArchive(name,forWriting), ERR_UNSUPPORTED_ARCHIVE, 0);

    archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
    BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL);

    archive->firstEntry = NULL;
    archive->lastEntry = NULL;

    if ((archive->stream.File = __PHYSFS_platformOpenRead(name)) == NULL)
    {
        allocator.Free(archive);
        return NULL;
    } /* if */

    /* Prepare structs for 7z */
    archive->stream.InStream.Read = SzFileReadImp;
    archive->stream.InStream.Seek = SzFileSeekImp;

    allocImp.Alloc = SzAllocPhysicsFS;
    allocImp.Free = SzFreePhysicsFS;

    allocTempImp.Alloc = SzAllocPhysicsFS;
    allocTempImp.Free = SzFreePhysicsFS;

    InitCrcTable();
    SzArDbExInit(&archive->db);
    if (lzma_err(SzArchiveOpen(&archive->stream.InStream, &archive->db,
                               &allocImp, &allocTempImp)) != SZ_OK)
    {
        __PHYSFS_platformClose(archive->stream.File);
        allocator.Free(archive);
        return NULL;
    } /* if */

    len = archive->db.Database.NumFolders * sizeof (LZMAfolder);
    archive->folder = (LZMAfolder *) allocator.Malloc(len);
    BAIL_IF_MACRO(archive->folder == NULL, ERR_OUT_OF_MEMORY, NULL);

    /*
     * Init with 0 so we know when a folder is already cached
     * Values will be set by LZMA_read()
     */
    memset(archive->folder, 0, (size_t) len);

    return(archive);
} /* LZMA_openArchive */
コード例 #3
0
static int MVL_isArchive(const char *filename, int forWriting)
{
    void *fh;
    PHYSFS_uint32 fileCount;
    int retval = mvl_open(filename, forWriting, &fh, &fileCount);

    if (fh != NULL)
        __PHYSFS_platformClose(fh);

    return retval;
} /* MVL_isArchive */
コード例 #4
0
ファイル: hha.c プロジェクト: C4-sic/codetastrophe
static int HHA_isArchive(const char *filename, int forWriting)
{
    void *fh;
    PHYSFS_uint32 nameSize;
    PHYSFS_uint32 fileCount;
    int retval = hha_open(filename, forWriting, &fh, &nameSize, &fileCount);

    if (fh != NULL)
        __PHYSFS_platformClose(fh);

    return(retval);
} /* HHA_isArchive */
コード例 #5
0
ファイル: hha.c プロジェクト: C4-sic/codetastrophe
static int HHA_fileClose(fvoid *opaque)
{
    HHAfileinfo *finfo = (HHAfileinfo *) opaque;
    BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
    
    if (finfo->entry->compress == HHA_COMPRESS_ZLIB)
        inflateEnd(&finfo->zlib_stream);

    if (finfo->buffer != NULL)
        allocator.Free(finfo->buffer);
    
    allocator.Free(finfo);
    return(1);
} /* HHA_fileClose */
コード例 #6
0
ファイル: zip.c プロジェクト: BackupTheBerlios/netpanzer-svn
static int ZIP_fileClose(fvoid *opaque)
{
    ZIPfileinfo *finfo = (ZIPfileinfo *) opaque;
    BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);

    if (finfo->entry->compression_method != COMPMETH_NONE)
        inflateEnd(&finfo->stream);

    if (finfo->buffer != NULL)
        allocator.Free(finfo->buffer);

    allocator.Free(finfo);
    return(1);
} /* ZIP_fileClose */
コード例 #7
0
ファイル: hog.c プロジェクト: UIKit0/paragui
static int hog_load_entries(const char *name, int forWriting, HOGinfo *info)
{
    void *fh = NULL;
    PHYSFS_uint32 fileCount;
    HOGentry *entry;

    BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
    info->entryCount = fileCount;
    info->entries = (HOGentry *) malloc(sizeof (HOGentry) * fileCount);
    if (info->entries == NULL)
    {
        __PHYSFS_platformClose(fh);
        BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
    } /* if */

    for (entry = info->entries; fileCount > 0; fileCount--, entry++)
    {
        if (__PHYSFS_platformRead(fh, &entry->name, 13, 1) != 1)
        {
            __PHYSFS_platformClose(fh);
            return(0);
        } /* if */

        if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1)
        {
            __PHYSFS_platformClose(fh);
            return(0);
        } /* if */

        entry->size = PHYSFS_swapULE32(entry->size);
        entry->startPos = __PHYSFS_platformTell(fh);
        if (entry->startPos == -1)
        {
            __PHYSFS_platformClose(fh);
            return(0);
        }

        // Skip over entry
        if (!__PHYSFS_platformSeek(fh, entry->startPos + entry->size))
        {
            __PHYSFS_platformClose(fh);
            return(0);
        }
    } /* for */

    __PHYSFS_platformClose(fh);

    __PHYSFS_sort(info->entries, info->entryCount,
                  hog_entry_cmp, hog_entry_swap);
    return(1);
} /* hog_load_entries */
コード例 #8
0
ファイル: lzma.c プロジェクト: EgoIncarnate/Infinity
static void LZMA_dirClose(dvoid *opaque)
{
    LZMAarchive *archive = (LZMAarchive *) opaque;
    LZMAentry *entry = archive->firstEntry;
    LZMAentry *tmpEntry = entry;

    while (entry != NULL)
    {
        tmpEntry = entry->next;
        LZMA_fileClose(entry);
        entry = tmpEntry;
    } /* while */

    SzArDbExFree(&archive->db, SzFreePhysicsFS);
    __PHYSFS_platformClose(archive->stream.File);

    /* Free the cache which might have been allocated by LZMA_read() */
    allocator.Free(archive->folder);
    allocator.Free(archive);
} /* LZMA_dirClose */
コード例 #9
0
ファイル: hha.c プロジェクト: C4-sic/codetastrophe
static int hha_open(const char *filename, int forWriting,
                    void **fh, PHYSFS_uint32 *filenameSize, PHYSFS_uint32 *count)
{
    PHYSFS_uint32 magic[2];

    *fh = NULL;
    
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
    
    *fh = __PHYSFS_platformOpenRead(filename);
    BAIL_IF_MACRO(*fh == NULL, NULL, 0);
    
    if (__PHYSFS_platformRead(*fh, magic, sizeof(PHYSFS_uint32), 2) != 2)
        goto openHHA_failed;

    magic[0] = PHYSFS_swapULE32(magic[0]);
    magic[1] = PHYSFS_swapULE32(magic[1]);
    if (!(magic[0] == HHA_FILE_MAGIC && magic[1] == HHA_FILE_VERSION))
    {
        __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
        goto openHHA_failed;
    } /* if */
    
    if (__PHYSFS_platformRead(*fh, filenameSize, sizeof (PHYSFS_uint32), 1) != 1)
        goto openHHA_failed;
    *filenameSize = PHYSFS_swapULE32(*filenameSize);
    if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1)
        goto openHHA_failed;
    *count = PHYSFS_swapULE32(*count);

    return(1);

openHHA_failed:
    if (*fh != NULL)
        __PHYSFS_platformClose(*fh);

    *filenameSize = -1;
    *count = -1;
    *fh = NULL;
    return(0);
} /* HHA_open */
コード例 #10
0
ファイル: lzma.c プロジェクト: EgoIncarnate/Infinity
static int LZMA_isArchive(const char *filename, int forWriting)
{
    PHYSFS_uint8 sig[k7zSignatureSize];
    PHYSFS_uint8 res;
    void *in;

    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);

    in = __PHYSFS_platformOpenRead(filename);
    BAIL_IF_MACRO(in == NULL, NULL, 0);

    if (__PHYSFS_platformRead(in, sig, k7zSignatureSize, 1) != 1)
        BAIL_MACRO(NULL, 0);

    /* Test whether sig is the 7z signature */
    res = TestSignatureCandidate(sig);

    __PHYSFS_platformClose(in);

    return res;
} /* LZMA_isArchive */
コード例 #11
0
static int wad_open(const char *filename, int forWriting,
                    void **fh, PHYSFS_uint32 *count,PHYSFS_uint32 *offset)
{
    PHYSFS_uint8 buf[4];

    *fh = NULL;
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);

    *fh = __PHYSFS_platformOpenRead(filename);
    BAIL_IF_MACRO(*fh == NULL, NULL, 0);
    
    if (__PHYSFS_platformRead(*fh, buf, 4, 1) != 1)
        goto openWad_failed;

    if (memcmp(buf, "IWAD", 4) != 0 && memcmp(buf, "PWAD", 4) != 0)
    {
        __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
        goto openWad_failed;
    } /* if */

    if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1)
        goto openWad_failed;

    *count = PHYSFS_swapULE32(*count);

    if (__PHYSFS_platformRead(*fh, offset, sizeof (PHYSFS_uint32), 1) != 1)
        goto openWad_failed;

    *offset = PHYSFS_swapULE32(*offset);

    return 1;

openWad_failed:
    if (*fh != NULL)
        __PHYSFS_platformClose(*fh);

    *count = -1;
    *fh = NULL;
    return 0;
} /* wad_open */