misc/physfs/extras/physfslualoader.c
author unc0rr
Tue, 20 Nov 2012 23:09:17 +0400
changeset 8077 2ea5cde93abc
parent 8074 768427321cab
child 8119 257ffa847aa2
permissions -rw-r--r--
Fix build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8074
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
     1
#include "lua.h"
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
     2
#include "physfs.h"
8034
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
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
     6
void *physfsReaderBuffer;
8034
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
}
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    25
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    26
void physfsReaderSetBuffer(void *buffer)
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    27
{
5a289ef40fdb physfs compilation on windows
koda
parents: 8040
diff changeset
    28
    physfsReaderBuffer = buffer;
8074
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
    29
}
768427321cab thou shall not use system headers for crossplatformness
koda
parents: 8073
diff changeset
    30