misc/physfs/extras/physfslualoader.c
author unc0rr
Sat, 17 Nov 2012 00:15:30 +0400
branchphysfslayer
changeset 8040 448d61778ca7
parent 8034 fc032c0f7b23
child 8073 5a289ef40fdb
permissions -rw-r--r--
Keeping bruteforce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8040
448d61778ca7 Keeping bruteforce
unc0rr
parents: 8034
diff changeset
     1
#include <lua.h>
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     2
#include <physfs.h>
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     3
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     4
#define BUFSIZE 1024
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     5
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     6
void * physfsReaderBuffer;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     7
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     8
const char * physfsReader(lua_State *L, PHYSFS_File *f, size_t *size)
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
     9
{
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    10
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    11
    if(PHYSFS_eof(f))
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    12
    {
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    13
        return NULL;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    14
    }
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    15
    else
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    16
    {
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    17
        *size = PHYSFS_readBytes(f, physfsReaderBuffer, BUFSIZE);
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    18
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    19
        if(*size == 0)
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    20
            return NULL;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    21
        else
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    22
            return physfsReaderBuffer;
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    23
    }
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents:
diff changeset
    24
}