Esempio n. 1
0
File: hog.c Progetto: UIKit0/paragui
static int hog_open(const char *filename, int forWriting,
                    void **fh, PHYSFS_uint32 *count)
{
    PHYSFS_uint8 buf[13];
    PHYSFS_uint32 size;
    PHYSFS_sint64 pos;

    *count = 0;

    *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, 3, 1) != 1)
        goto openHog_failed;

    if (memcmp(buf, "DHF", 3) != 0)
    {
        __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
        goto openHog_failed;
    } /* if */

    while( 1 )
    {
        if (__PHYSFS_platformRead(*fh, buf, 13, 1) != 1)
            break;             //eof here is ok

        if (__PHYSFS_platformRead(*fh, &size, 4, 1) != 1)
            goto openHog_failed;

        size = PHYSFS_swapULE32(size);

        (*count)++;

        // Skip over entry
        pos = __PHYSFS_platformTell(*fh);
        if (pos == -1)
            goto openHog_failed;
        if (!__PHYSFS_platformSeek(*fh, pos + size))
            goto openHog_failed;
    }

    // Rewind to start of entries
    if (!__PHYSFS_platformSeek(*fh, 3))
        goto openHog_failed;

    return(1);

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

    *count = -1;
    *fh = NULL;
    return(0);
} /* hog_open */
Esempio n. 2
0
File: os2.c Progetto: UIKit0/paragui
int __PHYSFS_platformEOF(void *opaque)
{
    PHYSFS_sint64 len, pos;

    len = __PHYSFS_platformFileLength(opaque);
    BAIL_IF_MACRO(len == -1, NULL, 1);  /* (*shrug*) */
    pos = __PHYSFS_platformTell(opaque);
    BAIL_IF_MACRO(pos == -1, NULL, 1);  /* (*shrug*) */

    return(pos >= len);
} /* __PHYSFS_platformEOF */
Esempio n. 3
0
File: hog.c Progetto: 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 */
Esempio n. 4
0
int __PHYSFS_platformEOF(void *opaque)
{
    PHYSFS_sint64 FilePosition;
    int retval = 0;

    /* Get the current position in the file */
    if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
    {
        /* Non-zero if EOF is equal to the file length */
        retval = FilePosition == __PHYSFS_platformFileLength(opaque);
    } /* if */

    return(retval);
} /* __PHYSFS_platformEOF */
Esempio n. 5
0
int __PHYSFS_platformEOF(void *opaque)
{
	const PHYSFS_sint64 FileLength = __PHYSFS_platformFileLength(opaque);
	PHYSFS_sint64 FilePosition;
	int retval = 0;

	if (FileLength == 0)
		return 1;  /* we're definitely at EOF. */

				   /* Get the current position in the file */
	if ((FilePosition = __PHYSFS_platformTell(opaque)) != -1)
	{
		/* Non-zero if EOF is equal to the file length */
		retval = (FilePosition == FileLength);
	} /* if */

	return(retval);
} /* __PHYSFS_platformEOF */
Esempio n. 6
0
File: posix.c Progetto: jcubic/ToME
int __PHYSFS_platformEOF(void *opaque)
{
    PHYSFS_sint64 pos = __PHYSFS_platformTell(opaque);
    PHYSFS_sint64 len = __PHYSFS_platformFileLength(opaque);
    return(pos >= len);
} /* __PHYSFS_platformEOF */
Esempio n. 7
0
File: dir.c Progetto: leonlee/tome
static PHYSFS_sint64 DIR_tell(fvoid *opaque)
{
    return(__PHYSFS_platformTell(opaque));
} /* DIR_tell */
Esempio n. 8
0
File: dir.c Progetto: UIKit0/paragui
static PHYSFS_sint64 DIR_tell(FileHandle *handle)
{
    return(__PHYSFS_platformTell(handle->opaque));
} /* DIR_tell */